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.BorderLayout;
19  import java.awt.Frame;
20  import java.awt.event.ActionEvent;
21  import java.awt.event.ActionListener;
22  
23  import javax.swing.JButton;
24  import javax.swing.JDialog;
25  import javax.swing.JPanel;
26  
27  import p3j.gui.panels.matrices.EditMatrixPanel;
28  import p3j.misc.gui.GUI;
29  import p3j.pppm.parameters.ParameterAssignment;
30  
31  import com.jgoodies.forms.builder.ButtonBarBuilder2;
32  import com.jgoodies.forms.layout.ColumnSpec;
33  
34  /**
35   * Dialog for editing a matrix.
36   * 
37   * Created on January 07, 2007
38   * 
39   * @author Christina Bohk
40   * @author Roland Ewald
41   * 
42   */
43  public class EditMatrixDialog extends JDialog {
44  
45  	/** Serialization ID. */
46  	private static final long serialVersionUID = 3054321149647892680L;
47  
48  	/** Width of the dialog. */
49  	public static final int DIALOG_WIDTH = 600;
50  
51  	/** Height of the dialog. */
52  	public static final int DIALOG_HEIGHT = 480;
53  
54  	/** Central panel. */
55  	private EditMatrixPanel contentPanel;
56  
57  	/**
58  	 * Default constructor.
59  	 * 
60  	 * @param owner
61  	 *          the owner of this dialog
62  	 * @param pAssign
63  	 *          the matrix to be edited
64  	 */
65  	public EditMatrixDialog(Frame owner, ParameterAssignment pAssign) {
66  		super(owner, "Edit Matrix:" + pAssign.getName(), true);
67  		setSize(DIALOG_WIDTH, DIALOG_HEIGHT);
68  		GUI.centerOnScreen(this);
69  		contentPanel = new EditMatrixPanel(pAssign);
70  		initialize();
71  	}
72  
73  	/**
74  	 * This method initializes this dialog.
75  	 */
76  	private void initialize() {
77  
78  		JButton okButton = new JButton("OK");
79  		okButton.addActionListener(new ActionListener() {
80  			@Override
81  			public void actionPerformed(ActionEvent e) {
82  				setVisible(false);
83  			}
84  		});
85  
86  		JPanel panel = new JPanel(GUI.getStdBorderLayout());
87  		panel.add(contentPanel, BorderLayout.CENTER);
88  
89  		ButtonBarBuilder2 bBuilder = new ButtonBarBuilder2();
90  		bBuilder.addButton(okButton);
91  		bBuilder.getLayout().setColumnSpec(1, ColumnSpec.decode("right:pref:grow"));
92  		panel.add(bBuilder.getPanel(), BorderLayout.SOUTH);
93  		this.setContentPane(panel);
94  	}
95  }