1 | /* |
---|
2 | * $Id: DataGroupPropertyPanel.java,v 1.2 2003/08/22 23:02:33 dwd Exp $ |
---|
3 | * |
---|
4 | * This software is provided by NOAA for full, free and open release. It is |
---|
5 | * understood by the recipient/user that NOAA assumes no liability for any |
---|
6 | * errors contained in the code. Although this software is released without |
---|
7 | * conditions or restrictions in its use, it is expected that appropriate |
---|
8 | * credit be given to its author and to the National Oceanic and Atmospheric |
---|
9 | * Administration should the software be included by the recipient as an |
---|
10 | * element in other product development. |
---|
11 | */ |
---|
12 | |
---|
13 | package gov.noaa.pmel.sgt.beans; |
---|
14 | |
---|
15 | import javax.swing.*; |
---|
16 | import java.util.StringTokenizer; |
---|
17 | import java.util.Vector; |
---|
18 | import java.util.Iterator; |
---|
19 | |
---|
20 | import gov.noaa.pmel.sgt.PlainAxis; |
---|
21 | import gov.noaa.pmel.sgt.LinearTransform; |
---|
22 | import gov.noaa.pmel.sgt.TimeAxis; |
---|
23 | import gov.noaa.pmel.sgt.LogAxis; |
---|
24 | import gov.noaa.pmel.sgt.LogTransform; |
---|
25 | import java.awt.event.ActionEvent; |
---|
26 | import java.awt.event.ActionListener; |
---|
27 | import javax.swing.event.ChangeEvent; |
---|
28 | import javax.swing.event.ChangeListener; |
---|
29 | import java.awt.event.FocusEvent; |
---|
30 | import java.awt.event.FocusListener; |
---|
31 | |
---|
32 | import gov.noaa.pmel.util.SoTRange; |
---|
33 | import gov.noaa.pmel.util.GeoDate; |
---|
34 | import gov.noaa.pmel.util.IllegalTimeValue; |
---|
35 | |
---|
36 | /** |
---|
37 | * @author Donald Denbo |
---|
38 | * @version $Revision: 1.2 $, $Date: 2003/08/22 23:02:33 $ |
---|
39 | * @since 3.0 |
---|
40 | **/ |
---|
41 | class DataGroupPropertyPanel extends PropertyPanel |
---|
42 | implements ActionListener, ChangeListener, FocusListener { |
---|
43 | private boolean expert_ = false; |
---|
44 | private String[] pNames_ = {"Id", "Margin", "Zoomable", "Z AutoScale", "Z Auto Levels", "Z User Range"}; |
---|
45 | private JComponent[] comps_ = new JComponent[pNames_.length]; |
---|
46 | private DataGroup dataGroup_ = null; |
---|
47 | private boolean suppressEvent_ = false; |
---|
48 | private int zAutoScale, zUserRange, zAutoLevels; |
---|
49 | |
---|
50 | public DataGroupPropertyPanel(DataGroup dg, boolean expert) { |
---|
51 | super(); |
---|
52 | dataGroup_ = dg; |
---|
53 | dataGroup_.addChangeListener(this); |
---|
54 | expert_ = expert; |
---|
55 | create(); |
---|
56 | } |
---|
57 | |
---|
58 | public void setDataGroup(DataGroup dg, boolean expert) { |
---|
59 | if(dataGroup_ != null) dataGroup_.removeChangeListener(this); |
---|
60 | dataGroup_ = dg; |
---|
61 | dataGroup_.addChangeListener(this); |
---|
62 | expert_ = expert; |
---|
63 | reset(); |
---|
64 | } |
---|
65 | |
---|
66 | void update() { |
---|
67 | int i = -1; |
---|
68 | suppressEvent_ = true; |
---|
69 | int item = -1; |
---|
70 | ((JTextField)comps_[++i]).setText(dataGroup_.getId()); |
---|
71 | ((JLabel)comps_[++i]).setText(dataGroup_.getMargin().toString()); |
---|
72 | ((JCheckBox)comps_[++i]).setSelected(dataGroup_.isZoomable()); |
---|
73 | // |
---|
74 | // z stuff |
---|
75 | // |
---|
76 | ((JCheckBox)comps_[++i]).setSelected(dataGroup_.isZAutoScale()); |
---|
77 | ((JTextField)comps_[++i]).setText(format(dataGroup_.getNumberAutoContourLevels())); |
---|
78 | ((JTextField)comps_[++i]).setText(format(dataGroup_.getZRangeU(), false)); |
---|
79 | // |
---|
80 | setFieldsEnabled(); |
---|
81 | // |
---|
82 | suppressEvent_ = false; |
---|
83 | } |
---|
84 | |
---|
85 | void create() { |
---|
86 | int i = -1; |
---|
87 | int item = -1; |
---|
88 | comps_[++i] = createTextField(dataGroup_.getId(), pNames_[i], this, !dataGroup_.isInstantiated()); |
---|
89 | comps_[++i] = createLabel(dataGroup_.getMargin().toString()); |
---|
90 | comps_[++i] = createCheckBox(dataGroup_.isZoomable(), pNames_[i], this); |
---|
91 | // |
---|
92 | // z stuff |
---|
93 | // |
---|
94 | comps_[++i] = createCheckBox(dataGroup_.isZAutoScale(), pNames_[i], this); |
---|
95 | zAutoScale = i; |
---|
96 | comps_[++i] = createTextField(format(dataGroup_.getNumberAutoContourLevels()), pNames_[i], this, true); |
---|
97 | zAutoLevels = i; |
---|
98 | comps_[++i] = createTextField(format(dataGroup_.getZRangeU(), false), pNames_[i], this, true); |
---|
99 | zUserRange = i; |
---|
100 | // |
---|
101 | setFieldsEnabled(); |
---|
102 | // |
---|
103 | for(i=0; i < comps_.length; i++) { |
---|
104 | addProperty(i+1, pNames_[i], comps_[i], false); |
---|
105 | } |
---|
106 | addProperty(comps_.length + 1, " ", new JLabel(" "), true); |
---|
107 | } |
---|
108 | |
---|
109 | void resetFields() { |
---|
110 | for(int i=0; i < comps_.length; i++) { |
---|
111 | if(comps_[i] instanceof JTextField) { |
---|
112 | ((JTextField)comps_[i]).removeActionListener(this); |
---|
113 | ((JTextField)comps_[i]).removeFocusListener(this); |
---|
114 | } else if(comps_[i] instanceof JCheckBox) { |
---|
115 | ((JCheckBox)comps_[i]).removeActionListener(this); |
---|
116 | ((JCheckBox)comps_[i]).removeFocusListener(this); |
---|
117 | } else if(comps_[i] instanceof JComboBox) { |
---|
118 | ((JComboBox)comps_[i]).removeActionListener(this); |
---|
119 | ((JComboBox)comps_[i]).removeFocusListener(this); |
---|
120 | } else if(comps_[i] instanceof JButton) { |
---|
121 | ((JButton)comps_[i]).removeActionListener(this); |
---|
122 | ((JButton)comps_[i]).removeFocusListener(this); |
---|
123 | } |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | private void setFieldsEnabled() { |
---|
128 | ((JTextField)comps_[zUserRange]).setEnabled(!((JCheckBox)comps_[zAutoScale]).isSelected()); |
---|
129 | ((JTextField)comps_[zAutoLevels]).setEnabled(((JCheckBox)comps_[zAutoScale]).isSelected()); |
---|
130 | } |
---|
131 | |
---|
132 | private void processEvent(Object obj, String command) { |
---|
133 | String str = null; |
---|
134 | SoTRange range = null; |
---|
135 | if(command.equals("Id")) { |
---|
136 | String oldId = dataGroup_.getId(); |
---|
137 | dataGroup_.getPanelHolder().getDataGroups().remove(oldId); |
---|
138 | dataGroup_.setId(((JTextField)obj).getText()); |
---|
139 | dataGroup_.getPanelHolder().getDataGroups().put(dataGroup_.getId(), dataGroup_); |
---|
140 | } else if(command.equals("Zoomable")) { |
---|
141 | dataGroup_.setZoomable(((JCheckBox)obj).isSelected()); |
---|
142 | } else if(command.equals("Z AutoScale")) { |
---|
143 | dataGroup_.setZAutoScale(((JCheckBox)obj).isSelected()); |
---|
144 | } else if(command.equals("Z Auto Levels")) { |
---|
145 | dataGroup_.setNumberAutoContourLevels(Integer.parseInt(((JTextField)obj).getText())); |
---|
146 | } else if(command.equals("Z User Range")) { |
---|
147 | range = parseRange(((JTextField)obj).getText(), false); |
---|
148 | if(range != null) dataGroup_.setZRangeU(range); |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | public void actionPerformed(ActionEvent e) { |
---|
153 | if(suppressEvent_) return; |
---|
154 | Object obj = e.getSource(); |
---|
155 | // String str = null; |
---|
156 | String command = e.getActionCommand(); |
---|
157 | processEvent(obj, command); |
---|
158 | setFieldsEnabled(); |
---|
159 | // System.out.println(e.paramString() + ",rslt=" + str); |
---|
160 | } |
---|
161 | |
---|
162 | |
---|
163 | public void stateChanged(ChangeEvent e) { |
---|
164 | update(); |
---|
165 | } |
---|
166 | |
---|
167 | public void focusGained(FocusEvent e) { |
---|
168 | // Object obj = e.getSource(); |
---|
169 | // System.out.println("DataGroupPropertyPanel.focusGained: " + obj.toString()); |
---|
170 | } |
---|
171 | |
---|
172 | public void focusLost(FocusEvent e) { |
---|
173 | Object obj = e.getSource(); |
---|
174 | if(obj instanceof JTextField) { |
---|
175 | JTextField tf = (JTextField)obj; |
---|
176 | String name = tf.getName(); |
---|
177 | processEvent(obj, name); |
---|
178 | } |
---|
179 | } |
---|
180 | |
---|
181 | /* SoTRange parseRange(String value, boolean isTime) { |
---|
182 | StringTokenizer tok = new StringTokenizer(value, ",\t\n\r\f"); |
---|
183 | if(tok.countTokens() != 3) { |
---|
184 | JOptionPane.showMessageDialog(this, "Three values required", "Illegal Response", JOptionPane.ERROR_MESSAGE); |
---|
185 | return null; |
---|
186 | } |
---|
187 | SoTRange range = null; |
---|
188 | double start = Double.parseDouble(tok.nextToken().trim()); |
---|
189 | double end = Double.parseDouble(tok.nextToken().trim()); |
---|
190 | double delta = Double.parseDouble(tok.nextToken().trim()); |
---|
191 | range = new SoTRange.Double(start, end, delta); |
---|
192 | return range; |
---|
193 | } */ |
---|
194 | |
---|
195 | public void setExpert(boolean expert) { |
---|
196 | boolean save = expert_; |
---|
197 | expert_ = expert; |
---|
198 | if(expert_ != save) reset(); |
---|
199 | } |
---|
200 | |
---|
201 | public boolean isExpert() { |
---|
202 | return expert_; |
---|
203 | } |
---|
204 | } |
---|