gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.swing / org.gvsig.raster.swing.impl / src / main / java / org / gvsig / raster / swing / impl / infobypoint / InfoByPointPanel.java @ 1194
History | View | Annotate | Download (10.5 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.swing.impl.infobypoint; |
23 |
|
24 |
import java.awt.BorderLayout; |
25 |
import java.awt.Dimension; |
26 |
import java.awt.GridBagConstraints; |
27 |
import java.awt.GridBagLayout; |
28 |
import java.awt.event.ActionEvent; |
29 |
import java.awt.event.ActionListener; |
30 |
import java.text.DecimalFormat; |
31 |
import java.util.HashMap; |
32 |
|
33 |
import javax.swing.BorderFactory; |
34 |
import javax.swing.DefaultListModel; |
35 |
import javax.swing.JComboBox; |
36 |
import javax.swing.JLabel; |
37 |
import javax.swing.JList; |
38 |
import javax.swing.JPanel; |
39 |
import javax.swing.JScrollPane; |
40 |
import javax.swing.JTextField; |
41 |
|
42 |
import org.gvsig.raster.swing.infobypoint.InfoByPointDataModel; |
43 |
|
44 |
public class InfoByPointPanel extends JPanel implements ActionListener { |
45 |
private static final long serialVersionUID = 1L; |
46 |
private HashMap<String, String> |
47 |
tr = null;
|
48 |
private JList jListBandValues = null; |
49 |
private JLabel jLabelHSLPoint = null; |
50 |
private JLabel jLabelCMKYPoint = null; |
51 |
private JLabel jLabelRGBPoint = null; |
52 |
private JLabel jLabelPixelPoint = null; |
53 |
private JLabel jLabelViewPoint = null; |
54 |
private JLabel jLabelLatitudePoint = null; |
55 |
private JLabel jLabelLongitudPoint = null; |
56 |
private JLabel jLabelNumberOfBands = null; |
57 |
private JTextField jTextBoxLayerSelected = null; |
58 |
private JComboBox jComboListLayer = null; |
59 |
|
60 |
private JPanel jPanelLayerNames = null; |
61 |
private JPanel jPanelCoordinates = null; |
62 |
private JPanel jPanelColors = null; |
63 |
private JPanel jPanelBands = null; |
64 |
private DefaultInfoByPointDataModel
|
65 |
dataModel = null;
|
66 |
|
67 |
public InfoByPointPanel(HashMap<String, String> translations, InfoByPointDataModel dataModel) { |
68 |
tr = translations; |
69 |
if(tr == null || tr.get("layer_list") == null) { |
70 |
tr = new HashMap<String, String>(); |
71 |
tr.put("layer_list", "layer_list"); |
72 |
tr.put("band_values", "band_values"); |
73 |
tr.put("pixel_point", "pixel_point"); |
74 |
tr.put("view_point", "view_point"); |
75 |
tr.put("world_point", "world_point"); |
76 |
tr.put("bands", "bands"); |
77 |
tr.put("colors", "colors"); |
78 |
tr.put("coords", "coords"); |
79 |
tr.put("lat", "lat"); |
80 |
tr.put("long", "long"); |
81 |
} |
82 |
this.dataModel = (DefaultInfoByPointDataModel)dataModel;
|
83 |
init(); |
84 |
} |
85 |
|
86 |
private void init() { |
87 |
setLayout(new GridBagLayout()); |
88 |
GridBagConstraints gbc = new GridBagConstraints(); |
89 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
90 |
gbc.weightx = 1;
|
91 |
gbc.insets = new java.awt.Insets(1, 2, 1, 2); |
92 |
add(getJPanelLayerNames(), gbc); |
93 |
|
94 |
gbc.gridy = 1;
|
95 |
add(getJPanelCoordinates(), gbc); |
96 |
|
97 |
gbc.gridy = 2;
|
98 |
add(getJPanelBands(), gbc); |
99 |
|
100 |
gbc.gridy = 3;
|
101 |
add(getJPanelColors(), gbc); |
102 |
} |
103 |
|
104 |
public JPanel getJPanelLayerNames() { |
105 |
if(jPanelLayerNames == null) { |
106 |
jPanelLayerNames = new JPanel(); |
107 |
jPanelLayerNames.setBorder(BorderFactory.createTitledBorder(tr.get("layer_list"))); |
108 |
jPanelLayerNames.setLayout(new BorderLayout()); |
109 |
|
110 |
jPanelLayerNames.add(getJComboListLayer(), BorderLayout.CENTER);
|
111 |
} |
112 |
return jPanelLayerNames;
|
113 |
} |
114 |
|
115 |
public JPanel getJPanelBands() { |
116 |
if(jPanelBands == null) { |
117 |
jPanelBands = new JPanel(); |
118 |
jPanelBands.setBorder(BorderFactory.createTitledBorder(tr.get("bands"))); |
119 |
jPanelBands.setLayout(new BorderLayout()); |
120 |
jPanelBands.add(getJLabelNumberOfBands(), BorderLayout.NORTH);
|
121 |
JScrollPane listScroller = new JScrollPane(getJListValues()); |
122 |
//listScroller.setMinimumSize(new Dimension(0, 35));
|
123 |
//listScroller.setMaximumSize(new Dimension(0, 35));
|
124 |
//listScroller.setPreferredSize(new Dimension(0, 35));
|
125 |
jPanelBands.add(listScroller, BorderLayout.CENTER);
|
126 |
} |
127 |
return jPanelBands;
|
128 |
} |
129 |
|
130 |
public JPanel getJPanelColors() { |
131 |
if(jPanelColors == null) { |
132 |
jPanelColors = new JPanel(); |
133 |
jPanelColors.setBorder(BorderFactory.createTitledBorder(tr.get("colors"))); |
134 |
jPanelColors.setLayout(new GridBagLayout()); |
135 |
GridBagConstraints gbc = new GridBagConstraints(); |
136 |
gbc.gridx = 0;
|
137 |
gbc.gridy = 0;
|
138 |
gbc.anchor = GridBagConstraints.WEST;
|
139 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
140 |
gbc.weightx = 1;
|
141 |
gbc.insets = new java.awt.Insets(1, 2, 2, 2); |
142 |
|
143 |
jPanelColors.add(getJLabelRGBPoint(), gbc); |
144 |
gbc.gridy = 1;
|
145 |
jPanelColors.add(getJLabelCMKYPoint(), gbc); |
146 |
gbc.gridy = 2;
|
147 |
jPanelColors.add(getJLabelHSLPoint(), gbc); |
148 |
} |
149 |
return jPanelColors;
|
150 |
} |
151 |
|
152 |
public JPanel getJPanelCoordinates() { |
153 |
if(jPanelCoordinates == null) { |
154 |
jPanelCoordinates = new JPanel(); |
155 |
jPanelCoordinates.setLayout(new GridBagLayout()); |
156 |
jPanelCoordinates.setBorder(BorderFactory.createTitledBorder(tr.get("coords"))); |
157 |
GridBagConstraints gbc = new GridBagConstraints(); |
158 |
gbc.gridx = 0;
|
159 |
gbc.gridy = 0;
|
160 |
gbc.anchor = GridBagConstraints.WEST;
|
161 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
162 |
gbc.weightx = 1;
|
163 |
gbc.insets = new java.awt.Insets(1, 2, 2, 2); |
164 |
|
165 |
gbc.gridy = 1;
|
166 |
jPanelCoordinates.add(getJLabelLatitudePoint(), gbc); |
167 |
gbc.gridy = 2;
|
168 |
jPanelCoordinates.add(getJLabelLongitudPoint(), gbc); |
169 |
gbc.gridy = 3;
|
170 |
jPanelCoordinates.add(getJLabelViewPoint(), gbc); |
171 |
gbc.gridy = 4;
|
172 |
jPanelCoordinates.add(getJLabelPixelPoint(), gbc); |
173 |
} |
174 |
return jPanelCoordinates;
|
175 |
} |
176 |
|
177 |
private JList getJListValues() { |
178 |
if(jListBandValues == null) { |
179 |
jListBandValues = new JList(); |
180 |
//jListBandValues.setPreferredSize(new Dimension(0, 35));
|
181 |
} |
182 |
return jListBandValues;
|
183 |
} |
184 |
|
185 |
private JLabel getJLabelHSLPoint() { |
186 |
if(jLabelHSLPoint == null) |
187 |
jLabelHSLPoint = new JLabel("HSL: "); |
188 |
return jLabelHSLPoint;
|
189 |
} |
190 |
|
191 |
private JLabel getJLabelCMKYPoint() { |
192 |
if(jLabelCMKYPoint == null) |
193 |
jLabelCMKYPoint = new JLabel("CMYK: "); |
194 |
return jLabelCMKYPoint;
|
195 |
} |
196 |
|
197 |
private JLabel getJLabelRGBPoint() { |
198 |
if(jLabelRGBPoint == null) |
199 |
jLabelRGBPoint = new JLabel("RGB: " ); |
200 |
return jLabelRGBPoint;
|
201 |
} |
202 |
|
203 |
private JLabel getJLabelPixelPoint() { |
204 |
if(jLabelPixelPoint == null) |
205 |
jLabelPixelPoint = new JLabel(); |
206 |
return jLabelPixelPoint;
|
207 |
} |
208 |
|
209 |
private JLabel getJLabelViewPoint() { |
210 |
if(jLabelViewPoint == null) |
211 |
jLabelViewPoint = new JLabel(); |
212 |
return jLabelViewPoint;
|
213 |
} |
214 |
|
215 |
private JLabel getJLabelLatitudePoint() { |
216 |
if(jLabelLatitudePoint == null) |
217 |
jLabelLatitudePoint = new JLabel(); |
218 |
return jLabelLatitudePoint;
|
219 |
} |
220 |
|
221 |
private JLabel getJLabelLongitudPoint() { |
222 |
if(jLabelLongitudPoint == null) |
223 |
jLabelLongitudPoint = new JLabel(); |
224 |
return jLabelLongitudPoint;
|
225 |
} |
226 |
|
227 |
private JLabel getJLabelNumberOfBands() { |
228 |
if(jLabelNumberOfBands == null) |
229 |
jLabelNumberOfBands = new JLabel(); |
230 |
return jLabelNumberOfBands;
|
231 |
} |
232 |
|
233 |
@SuppressWarnings("unused") |
234 |
private JTextField getJTextBoxLayerSelected() { |
235 |
if(jTextBoxLayerSelected == null) |
236 |
jTextBoxLayerSelected = new JTextField(); |
237 |
return jTextBoxLayerSelected;
|
238 |
} |
239 |
|
240 |
private JComboBox getJComboListLayer() { |
241 |
if(jComboListLayer == null) { |
242 |
jComboListLayer = new JComboBox(); |
243 |
jComboListLayer.addActionListener(this);
|
244 |
} |
245 |
return jComboListLayer;
|
246 |
} |
247 |
|
248 |
public void updateDataModel() { |
249 |
Double nanObj = new Double(Double.NaN); |
250 |
DecimalFormat df2 = new DecimalFormat("#.##"); |
251 |
DecimalFormat df4 = new DecimalFormat("#.####"); |
252 |
getJLabelNumberOfBands().setText(tr.get("bands") + ": " + dataModel.bands); |
253 |
|
254 |
String y = (!new Double(dataModel.worldPoint.getY()).equals(nanObj)) ? df2.format(dataModel.worldPoint.getY()) : "NaN"; |
255 |
getJLabelLatitudePoint().setText(tr.get("lat") + ": " + y); |
256 |
|
257 |
String x = (!new Double(dataModel.worldPoint.getY()).equals(nanObj)) ? df2.format(dataModel.worldPoint.getX()) : "NaN"; |
258 |
getJLabelLongitudPoint().setText(tr.get("long") + ": " + x); |
259 |
|
260 |
y = (!new Double(dataModel.viewPoint.getY()).equals(nanObj)) ? df2.format(dataModel.viewPoint.getY()) : "NaN"; |
261 |
x = (!new Double(dataModel.viewPoint.getY()).equals(nanObj)) ? df2.format(dataModel.viewPoint.getX()) : "NaN"; |
262 |
getJLabelViewPoint().setText(tr.get("view_point") + ": (" + x + ", " + y + ")"); |
263 |
|
264 |
y = (!new Double(dataModel.pixelPoint.getY()).equals(nanObj)) ? df2.format(dataModel.pixelPoint.getY()) : "NaN"; |
265 |
x = (!new Double(dataModel.pixelPoint.getY()).equals(nanObj)) ? df2.format(dataModel.pixelPoint.getX()) : "NaN"; |
266 |
getJLabelPixelPoint().setText(tr.get("pixel_point") + ": (" + x + ", " + y + ")"); |
267 |
|
268 |
getJLabelRGBPoint().setText("RGB: " + dataModel.rgb[0] + ", " + |
269 |
dataModel.rgb[1] + ", " + |
270 |
dataModel.rgb[2]);
|
271 |
getJLabelHSLPoint().setText("HSL: " + df4.format(dataModel.hsl[0]) + ", " + |
272 |
df4.format(dataModel.hsl[1]) + ", " + |
273 |
df4.format(dataModel.hsl[2]));
|
274 |
getJLabelCMKYPoint().setText("CMYK: " + df4.format(dataModel.cmyk[0]) + ", " + |
275 |
df4.format(dataModel.cmyk[1]) + ", " + |
276 |
df4.format(dataModel.cmyk[2]) + ", " + |
277 |
df4.format(dataModel.cmyk[3]));
|
278 |
|
279 |
getJComboListLayer().removeAllItems(); |
280 |
for (int i = 0; i < dataModel.layers.size(); i++) { |
281 |
getJComboListLayer().addItem(dataModel.getFormatedLayerName(i)); |
282 |
} |
283 |
|
284 |
DefaultListModel listModel = null; |
285 |
if(getJListValues().getModel() == null || !(getJListValues().getModel() instanceof DefaultListModel)) |
286 |
listModel = new DefaultListModel(); |
287 |
else
|
288 |
listModel = (DefaultListModel)getJListValues().getModel();
|
289 |
listModel.clear(); |
290 |
for (int i = 0; i < dataModel.bandsValues.size(); i++) { |
291 |
listModel.addElement("B" + i + ": " + dataModel.bandsValues.get(i)); |
292 |
} |
293 |
if(getJListValues().getModel() == null || !(getJListValues().getModel() instanceof DefaultListModel)) |
294 |
getJListValues().setModel(listModel); |
295 |
} |
296 |
|
297 |
public void actionPerformed(ActionEvent e) { |
298 |
/*if(e.getSource() == getJComboListLayer()) {
|
299 |
if(getJComboListLayer().getSelectedIndex() != -1)
|
300 |
getJTextBoxLayerSelected().setText(dataModel.layers.get(getJComboListLayer().getSelectedIndex()));
|
301 |
}*/
|
302 |
} |
303 |
|
304 |
} |