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  	/** The cancel button. */
47  	private final JButton cancelButton = new JButton("Cancel");
48  	{
49  		cancelButton.addActionListener(new ActionListener() {
50  			@Override
51  			public void actionPerformed(ActionEvent e) {
52  				setVisible(false);
53  			}
54  		});
55  	}
56  	/** The buttons. */
57  	private final List<JButton> buttons = new ArrayList<JButton>();
58  	{
59  		getButtons().add(getOkButton());
60  		getButtons().add(cancelButton);
61  	}
62  
63  	/**
64  	 * Instantiates a new projection dialog.
65  	 */
66  	public ProjectionDialog() {
67  		addOKButtonAction();
68  	}
69  
70  	/**
71  	 * Adds the OK button action.
72  	 */
73  	protected abstract void addOKButtonAction();
74  
75  	public List<JButton> getButtons() {
76  		return buttons;
77  	}
78  
79  	public JButton getOkButton() {
80  		return okButton;
81  	}
82  }