View Javadoc

1   /*
2    * Copyright (c) 2006 Stiftung Deutsches Elektronen-Synchroton,
3    * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY.
4    *
5    * THIS SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "../AS IS" BASIS.
6    * WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
7    * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR PARTICULAR PURPOSE AND
8    * NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
9    * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10   * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
11   * THE USE OR OTHER DEALINGS IN THE SOFTWARE. SHOULD THE SOFTWARE PROVE DEFECTIVE
12   * IN ANY RESPECT, THE USER ASSUMES THE COST OF ANY NECESSARY SERVICING, REPAIR OR
13   * CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
14   * NO USE OF ANY SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
15   * DESY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
16   * OR MODIFICATIONS.
17   * THE FULL LICENSE SPECIFYING FOR THE SOFTWARE THE REDISTRIBUTION, MODIFICATION,
18   * USAGE AND OTHER RIGHTS AND OBLIGATIONS IS INCLUDED WITH THE DISTRIBUTION OF THIS
19   * PROJECT IN THE FILE LICENSE.HTML. IF THE LICENSE IS NOT INCLUDED YOU MAY FIND A COPY
20   * AT HTTP://WWW.DESY.DE/LEGAL/LICENSE.HTM
21   */
22  
23  package de.desy.acop.displayers.selector;
24  
25  import java.awt.Dimension;
26  import java.awt.GridBagConstraints;
27  import java.awt.GridBagLayout;
28  import java.awt.Insets;
29  
30  import javax.swing.JComboBox;
31  import javax.swing.JLabel;
32  import javax.swing.JPanel;
33  import javax.swing.JTextField;
34  
35  import de.desy.acop.displayers.table.AcopTableParameters;
36  import de.desy.acop.displayers.table.TableColumnType;
37  
38  /**
39   * <code>TableCustomizerPanel</code> is a customization panel for 
40   * <code>AcopTableParameters</code>. Panel has user interface which enable
41   * selecting various properties which are part of the table parameters.
42   * 
43   * @author <a href="mailto:jaka.bobnar@cosylab.com">Jaka Bobnar</a>
44   * @version $Id: Templates.xml,v 1.10 2004/01/13 16:17:13 jbobnar Exp $
45   * @see AcopTableParameters
46   *
47   */
48  public class TableCustomizerPanel extends MultipleDisplayerAbstractSettingsPanel<AcopTableParameters>{
49  
50  	private static final long serialVersionUID = -4547732237651600499L;
51  	private JComboBox tableCustomizerCombo;
52  	private JLabel tableCustomizerLabel;
53  	
54  	private JTextField tableColumnNameField;
55  	private JLabel tableColumnNameLabel;
56  	
57  	private JPanel propertiesPanel;
58  	
59  	/**
60  	 * Constructs new TableCustomizerPanel.
61  	 *
62  	 */
63  	public TableCustomizerPanel() {
64  		super();
65  		initialize();
66  	}
67  	
68  	private void initialize() {
69  		setLayout(new GridBagLayout());
70  		add(getPropertiesPanel(), new GridBagConstraints(0,0,1,1,1,1,GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(0,0,0,0),0,0));
71  	}
72  	
73  	private JPanel getPropertiesPanel() {
74  		if (propertiesPanel == null) {
75  			propertiesPanel = new JPanel(new GridBagLayout());
76  			tableCustomizerLabel = new JLabel("Type of data");
77  			tableCustomizerLabel.setPreferredSize(new Dimension(100,21));
78  			tableCustomizerLabel.setMinimumSize(new Dimension(100,21));
79  			tableCustomizerLabel.setMaximumSize(new Dimension(100,21));
80  			propertiesPanel.add(tableCustomizerLabel, new GridBagConstraints(0,0,1,1,1,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
81  			propertiesPanel.add(getTableCustomizerCombo(), new GridBagConstraints(1,0,2,1,1,0,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
82  			
83  			tableColumnNameLabel = new JLabel("Name of column");
84  			tableColumnNameLabel.setPreferredSize(new Dimension(100,21));
85  			tableColumnNameLabel.setMinimumSize(new Dimension(100,21));
86  			tableColumnNameLabel.setMaximumSize(new Dimension(100,21));
87  			propertiesPanel.add(tableColumnNameLabel, new GridBagConstraints(0,1,1,1,1,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
88  			propertiesPanel.add(getTableColumnNameField(), new GridBagConstraints(1,1,2,1,1,0,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(1,1,1,1),0,0));
89  		
90  		}
91  		return propertiesPanel;
92  	}
93  	
94  	private JTextField getTableColumnNameField() {
95  		if (tableColumnNameField == null) {
96  			tableColumnNameField = new JTextField();
97  			tableColumnNameField.setPreferredSize(new Dimension(150,21));
98  			tableColumnNameField.setMinimumSize(new Dimension(150,21));
99  			tableColumnNameField.setMaximumSize(new Dimension(150,21));
100 		}
101 		return tableColumnNameField;
102 	}
103 	
104 	private JComboBox getTableCustomizerCombo() {
105 		if (tableCustomizerCombo == null) {
106 			tableCustomizerCombo = new JComboBox(TableColumnType.values());
107 			tableCustomizerCombo.setPreferredSize(new Dimension(150,21));
108 			tableCustomizerCombo.setMinimumSize(new Dimension(150,21));
109 			tableCustomizerCombo.setMaximumSize(new Dimension(150,21));
110 			tableCustomizerCombo.setSelectedItem(null);
111 		}
112 		return tableCustomizerCombo;
113 	}
114 	
115 	/**
116 	 * Returns the selected type.
117 	 * @return the type
118 	 */
119 	public TableColumnType getType() {
120 		if (getTableCustomizerCombo().getSelectedItem() != null) {
121 			return (TableColumnType) getTableCustomizerCombo().getSelectedItem();
122 		} else {
123 			return TableColumnType.VALUE;
124 		}
125 	}
126 	
127 	/**
128 	 * Sets the selected type. 
129 	 * @param type
130 	 */
131 	public void setType(TableColumnType type) {
132 		getTableCustomizerCombo().setSelectedItem(type);
133 	}
134 	
135 	/**
136 	 * Sets the name for the column.
137 	 * @param name column name
138 	 */
139 	public void setName(String name) {
140 		if (name == null) {
141 			name = "";
142 		}
143 		getTableColumnNameField().setText(name);
144 		getTableColumnNameField().setToolTipText(name);
145 	}
146 
147 	/**
148 	 * Returns the name for the column.
149 	 * 
150 	 * @return column name
151 	 */
152 	public String getName() {
153 		return getTableColumnNameField().getText();
154 	}
155 		
156 	/*
157 	 * (non-Javadoc)
158 	 * @see de.desy.acop.displayers.selector.MultipleDisplayerAbstractSettingsPanel#setParameters(de.desy.acop.displayers.tools.AcopDisplayerParameters)
159 	 */
160 	@Override
161 	public void setParameters(AcopTableParameters parameters) {
162 		if (parameters == null) {
163 			getTableCustomizerCombo().setSelectedItem(null);
164 			setName("");
165 		} else {
166 			getTableCustomizerCombo().setSelectedItem(parameters.getColumnType());
167 			setName(parameters.getName());
168 		}
169 	}
170 
171 	
172 }