View Javadoc

1   /*
2    * Copyright 2006 - 2012 Christina Bohk and Roland Ewald
3    *  
4    * Licensed under the Apache License, Version 2.0 (the "License"); 
5    * you may not use this file except in compliance with the License. 
6    * You may obtain a copy of the License at 
7    *  
8    *  http://www.apache.org/licenses/LICENSE-2.0
9    *  
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License. 
15   */
16  package p3j.gui.dialogs;
17  
18  import java.awt.event.ActionEvent;
19  import java.awt.event.ActionListener;
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import javax.swing.JButton;
24  import javax.swing.JDialog;
25  
26  /**
27   * Super class of all dialogs with a certain size and some default buttons.
28   * 
29   * @author Christina Bohk
30   * @author Roland Ewald
31   */
32  public abstract class ProjectionDialog extends JDialog {
33  
34    /** The Constant serialVersionUID. */
35    private static final long serialVersionUID = -4217198597804149925L;
36  
37    /** The height of the dialog. */
38    protected static final int DIALOG_HEIGHT = 150;
39  
40    /** The width of the dialog. */
41    protected static final int DIALOG_WIDTH = 600;
42  
43    /** The OK button. */
44    private final JButton okButton = new JButton("OK");
45    {
46      okButton.addActionListener(new ActionListener() {
47        @Override
48        public void actionPerformed(ActionEvent e) {
49          okAction();
50        }
51      });
52    }
53  
54    /** The cancel button. */
55    private final JButton cancelButton = new JButton("Cancel");
56    {
57      getCancelButton().addActionListener(new ActionListener() {
58        @Override
59        public void actionPerformed(ActionEvent e) {
60          setVisible(false);
61        }
62      });
63    }
64    /** The buttons. */
65    private final List<JButton> buttons = new ArrayList<JButton>();
66    {
67      getButtons().add(getOkButton());
68      getButtons().add(getCancelButton());
69    }
70  
71    /**
72     * Override to add behavior for the OK button.
73     */
74    protected abstract void okAction();
75  
76    public List<JButton> getButtons() {
77      return buttons;
78    }
79  
80    public JButton getOkButton() {
81      return okButton;
82    }
83  
84    public JButton getCancelButton() {
85      return cancelButton;
86    }
87  }