Revision 1193
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/tool/infobypoint/gui/ButtonsPanel.java | ||
---|---|---|
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.tools.app.basic.tool.infobypoint.gui; |
|
23 |
|
|
24 |
import java.awt.Color; |
|
25 |
import java.awt.Dimension; |
|
26 |
import java.awt.FlowLayout; |
|
27 |
import java.awt.event.ActionEvent; |
|
28 |
import java.awt.event.ActionListener; |
|
29 |
|
|
30 |
import javax.swing.BorderFactory; |
|
31 |
import javax.swing.Icon; |
|
32 |
import javax.swing.ImageIcon; |
|
33 |
import javax.swing.JButton; |
|
34 |
import javax.swing.JPanel; |
|
35 |
|
|
36 |
import org.gvsig.andami.IconThemeHelper; |
|
37 |
|
|
38 |
/** |
|
39 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
40 |
*/ |
|
41 |
public class ButtonsPanel extends JPanel implements ActionListener { |
|
42 |
private static final long serialVersionUID = 1L; |
|
43 |
private static int BUTTON_SIZE = 26; |
|
44 |
private JButton extendedButton = null; |
|
45 |
private Icon icon1 = null; |
|
46 |
private Icon icon2 = null; |
|
47 |
|
|
48 |
public ButtonsPanel() { |
|
49 |
try { |
|
50 |
icon1 = IconThemeHelper.getImageIcon("forward-icon"); |
|
51 |
icon2 = IconThemeHelper.getImageIcon("backward-icon"); |
|
52 |
if(icon1 == null) |
|
53 |
icon1 = new ImageIcon(System.getProperty("user.dir") + "/src/main/resources/images/forward.png", ""); |
|
54 |
if(icon2 == null) |
|
55 |
icon2 = new ImageIcon(System.getProperty("user.dir") + "/src/main/resources/images/backward.png", ""); |
|
56 |
} catch (NullPointerException e) { |
|
57 |
} |
|
58 |
init(); |
|
59 |
} |
|
60 |
|
|
61 |
private void init() { |
|
62 |
FlowLayout ly = new FlowLayout(); |
|
63 |
setLayout(ly); |
|
64 |
//ly.setHgap(2); |
|
65 |
ly.setVgap(2); |
|
66 |
ly.setAlignment(FlowLayout.RIGHT); |
|
67 |
setBorder(BorderFactory.createLineBorder(Color.blue)); |
|
68 |
add(getExtendedButton()); |
|
69 |
/*setLayout(new GridBagLayout()); |
|
70 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
71 |
gbc.gridx = 0; |
|
72 |
gbc.weightx = 1; |
|
73 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
74 |
gbc.insets = new java.awt.Insets(1, 1, 1, 4); |
|
75 |
add(new JPanel(), gbc); |
|
76 |
|
|
77 |
gbc.gridx = 1; |
|
78 |
gbc.anchor = GridBagConstraints.EAST; |
|
79 |
gbc.fill = GridBagConstraints.NONE; |
|
80 |
gbc.weightx = 0; |
|
81 |
add(getExtendedButton(), gbc);*/ |
|
82 |
} |
|
83 |
|
|
84 |
public JButton getExtendedButton() { |
|
85 |
if(extendedButton == null) { |
|
86 |
extendedButton = new JButton(icon1); |
|
87 |
extendedButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); |
|
88 |
extendedButton.addActionListener(this); |
|
89 |
} |
|
90 |
return extendedButton; |
|
91 |
} |
|
92 |
|
|
93 |
public void actionPerformed(ActionEvent e) { |
|
94 |
if(e.getSource() == getExtendedButton()) { |
|
95 |
if(getExtendedButton().getIcon() == icon1) |
|
96 |
getExtendedButton().setIcon(icon2); |
|
97 |
else |
|
98 |
getExtendedButton().setIcon(icon1); |
|
99 |
} |
|
100 |
|
|
101 |
} |
|
102 |
} |
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/tool/infobypoint/gui/InfoByPointPanel.java | ||
---|---|---|
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.tools.app.basic.tool.infobypoint.gui; |
|
23 |
|
|
24 |
import java.awt.Dimension; |
|
25 |
import java.awt.GridBagConstraints; |
|
26 |
import java.awt.GridBagLayout; |
|
27 |
import java.awt.event.ActionEvent; |
|
28 |
import java.awt.event.ActionListener; |
|
29 |
import java.text.DecimalFormat; |
|
30 |
import java.util.HashMap; |
|
31 |
|
|
32 |
import javax.swing.BorderFactory; |
|
33 |
import javax.swing.DefaultListModel; |
|
34 |
import javax.swing.JComboBox; |
|
35 |
import javax.swing.JLabel; |
|
36 |
import javax.swing.JList; |
|
37 |
import javax.swing.JPanel; |
|
38 |
import javax.swing.JScrollPane; |
|
39 |
import javax.swing.JTextField; |
|
40 |
|
|
41 |
public class InfoByPointPanel extends JPanel implements ActionListener { |
|
42 |
private static final long serialVersionUID = 1L; |
|
43 |
private HashMap<String, String> |
|
44 |
tr = null; |
|
45 |
private JList jListBandValues = null; |
|
46 |
private JLabel jLabelHSLPoint = null; |
|
47 |
private JLabel jLabelCMKYPoint = null; |
|
48 |
private JLabel jLabelRGBPoint = null; |
|
49 |
private JLabel jLabelPixelPoint = null; |
|
50 |
private JLabel jLabelViewPoint = null; |
|
51 |
private JLabel jLabelLatitudePoint = null; |
|
52 |
private JLabel jLabelLongitudPoint = null; |
|
53 |
private JLabel jLabelNumberOfBands = null; |
|
54 |
private JTextField jTextBoxLayerSelected = null; |
|
55 |
private JComboBox jComboListLayer = null; |
|
56 |
|
|
57 |
private JPanel jPanelLayerNames = null; |
|
58 |
private JPanel jPanelCoordinates = null; |
|
59 |
private JPanel jPanelColors = null; |
|
60 |
private JPanel jPanelBands = null; |
|
61 |
private InfoByPointDataModel dataModel = null; |
|
62 |
|
|
63 |
public InfoByPointPanel(HashMap<String, String> translations, InfoByPointDataModel dataModel) { |
|
64 |
tr = translations; |
|
65 |
if(tr == null || tr.get("layer_list") == null) { |
|
66 |
tr = new HashMap<String, String>(); |
|
67 |
tr.put("layer_list", "layer_list"); |
|
68 |
tr.put("band_values", "band_values"); |
|
69 |
tr.put("pixel_point", "pixel_point"); |
|
70 |
tr.put("view_point", "view_point"); |
|
71 |
tr.put("world_point", "world_point"); |
|
72 |
tr.put("bands", "bands"); |
|
73 |
tr.put("colors", "colors"); |
|
74 |
tr.put("coords", "coords"); |
|
75 |
tr.put("lat", "lat"); |
|
76 |
tr.put("long", "long"); |
|
77 |
} |
|
78 |
this.dataModel = dataModel; |
|
79 |
init(); |
|
80 |
} |
|
81 |
|
|
82 |
private void init() { |
|
83 |
setLayout(new GridBagLayout()); |
|
84 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
85 |
gbc.gridx = 0; |
|
86 |
gbc.gridy = 0; |
|
87 |
//gbc.anchor = GridBagConstraints.WEST; |
|
88 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
89 |
gbc.weightx = 1; |
|
90 |
gbc.insets = new java.awt.Insets(1, 2, 1, 2); |
|
91 |
add(getJPanelLayerNames(), gbc); |
|
92 |
|
|
93 |
gbc.gridy = 3; |
|
94 |
add(getJPanelCoordinates(), gbc); |
|
95 |
|
|
96 |
gbc.gridy = 4; |
|
97 |
//gbc.fill = GridBagConstraints.BOTH; |
|
98 |
//gbc.weighty = 1; |
|
99 |
add(getJPanelBands(), gbc); |
|
100 |
|
|
101 |
gbc.gridy = 5; |
|
102 |
//gbc.weighty = 0; |
|
103 |
//gbc.fill = GridBagConstraints.HORIZONTAL; |
|
104 |
add(getJPanelColors(), gbc); |
|
105 |
} |
|
106 |
|
|
107 |
public JPanel getJPanelLayerNames() { |
|
108 |
if(jPanelLayerNames == null) { |
|
109 |
jPanelLayerNames = new JPanel(); |
|
110 |
jPanelLayerNames.setBorder(BorderFactory.createTitledBorder(tr.get("layer_list"))); |
|
111 |
jPanelLayerNames.setLayout(new GridBagLayout()); |
|
112 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
113 |
gbc.gridx = 0; |
|
114 |
gbc.gridy = 0; |
|
115 |
gbc.anchor = GridBagConstraints.WEST; |
|
116 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
117 |
gbc.weightx = 1; |
|
118 |
gbc.insets = new java.awt.Insets(1, 2, 2, 2); |
|
119 |
|
|
120 |
jPanelLayerNames.add(getJComboListLayer(), gbc); |
|
121 |
//gbc.gridy = 1; |
|
122 |
//jPanelLayerNames.add(getJTextBoxLayerSelected(), gbc); |
|
123 |
} |
|
124 |
return jPanelLayerNames; |
|
125 |
} |
|
126 |
|
|
127 |
public JPanel getJPanelBands() { |
|
128 |
if(jPanelBands == null) { |
|
129 |
jPanelBands = new JPanel(); |
|
130 |
jPanelBands.setBorder(BorderFactory.createTitledBorder(tr.get("bands"))); |
|
131 |
jPanelBands.setLayout(new GridBagLayout()); |
|
132 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
133 |
gbc.gridx = 0; |
|
134 |
gbc.gridy = 0; |
|
135 |
gbc.anchor = GridBagConstraints.WEST; |
|
136 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
137 |
gbc.weightx = 1; |
|
138 |
gbc.insets = new java.awt.Insets(1, 2, 1, 2); |
|
139 |
|
|
140 |
jPanelBands.add(getJLabelNumberOfBands(), gbc); |
|
141 |
gbc.gridy = 1; |
|
142 |
//gbc.gridheight = 2; |
|
143 |
//gbc.fill = GridBagConstraints.BOTH; |
|
144 |
//gbc.weighty = 1; |
|
145 |
JScrollPane listScroller = new JScrollPane(getJListValues()); |
|
146 |
listScroller.setPreferredSize(new Dimension(0, 35)); |
|
147 |
jPanelBands.add(listScroller, gbc); |
|
148 |
} |
|
149 |
return jPanelBands; |
|
150 |
} |
|
151 |
|
|
152 |
public JPanel getJPanelColors() { |
|
153 |
if(jPanelColors == null) { |
|
154 |
jPanelColors = new JPanel(); |
|
155 |
jPanelColors.setBorder(BorderFactory.createTitledBorder(tr.get("colors"))); |
|
156 |
jPanelColors.setLayout(new GridBagLayout()); |
|
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 |
jPanelColors.add(getJLabelRGBPoint(), gbc); |
|
166 |
gbc.gridy = 1; |
|
167 |
jPanelColors.add(getJLabelCMKYPoint(), gbc); |
|
168 |
gbc.gridy = 2; |
|
169 |
jPanelColors.add(getJLabelHSLPoint(), gbc); |
|
170 |
} |
|
171 |
return jPanelColors; |
|
172 |
} |
|
173 |
|
|
174 |
public JPanel getJPanelCoordinates() { |
|
175 |
if(jPanelCoordinates == null) { |
|
176 |
jPanelCoordinates = new JPanel(); |
|
177 |
jPanelCoordinates.setLayout(new GridBagLayout()); |
|
178 |
jPanelCoordinates.setBorder(BorderFactory.createTitledBorder(tr.get("coords"))); |
|
179 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
180 |
gbc.gridx = 0; |
|
181 |
gbc.gridy = 0; |
|
182 |
gbc.anchor = GridBagConstraints.WEST; |
|
183 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
184 |
gbc.weightx = 1; |
|
185 |
gbc.insets = new java.awt.Insets(1, 2, 2, 2); |
|
186 |
|
|
187 |
gbc.gridy = 1; |
|
188 |
jPanelCoordinates.add(getJLabelLatitudePoint(), gbc); |
|
189 |
gbc.gridy = 2; |
|
190 |
jPanelCoordinates.add(getJLabelLongitudPoint(), gbc); |
|
191 |
gbc.gridy = 3; |
|
192 |
jPanelCoordinates.add(getJLabelViewPoint(), gbc); |
|
193 |
gbc.gridy = 4; |
|
194 |
jPanelCoordinates.add(getJLabelPixelPoint(), gbc); |
|
195 |
} |
|
196 |
return jPanelCoordinates; |
|
197 |
} |
|
198 |
|
|
199 |
private JList getJListValues() { |
|
200 |
if(jListBandValues == null) { |
|
201 |
jListBandValues = new JList(); |
|
202 |
//jListBandValues.setPreferredSize(new Dimension(0, 35)); |
|
203 |
} |
|
204 |
return jListBandValues; |
|
205 |
} |
|
206 |
|
|
207 |
private JLabel getJLabelHSLPoint() { |
|
208 |
if(jLabelHSLPoint == null) |
|
209 |
jLabelHSLPoint = new JLabel("HSL: "); |
|
210 |
return jLabelHSLPoint; |
|
211 |
} |
|
212 |
|
|
213 |
private JLabel getJLabelCMKYPoint() { |
|
214 |
if(jLabelCMKYPoint == null) |
|
215 |
jLabelCMKYPoint = new JLabel("CMYK: "); |
|
216 |
return jLabelCMKYPoint; |
|
217 |
} |
|
218 |
|
|
219 |
private JLabel getJLabelRGBPoint() { |
|
220 |
if(jLabelRGBPoint == null) |
|
221 |
jLabelRGBPoint = new JLabel("RGB: " ); |
|
222 |
return jLabelRGBPoint; |
|
223 |
} |
|
224 |
|
|
225 |
private JLabel getJLabelPixelPoint() { |
|
226 |
if(jLabelPixelPoint == null) |
|
227 |
jLabelPixelPoint = new JLabel(); |
|
228 |
return jLabelPixelPoint; |
|
229 |
} |
|
230 |
|
|
231 |
private JLabel getJLabelViewPoint() { |
|
232 |
if(jLabelViewPoint == null) |
|
233 |
jLabelViewPoint = new JLabel(); |
|
234 |
return jLabelViewPoint; |
|
235 |
} |
|
236 |
|
|
237 |
private JLabel getJLabelLatitudePoint() { |
|
238 |
if(jLabelLatitudePoint == null) |
|
239 |
jLabelLatitudePoint = new JLabel(); |
|
240 |
return jLabelLatitudePoint; |
|
241 |
} |
|
242 |
|
|
243 |
private JLabel getJLabelLongitudPoint() { |
|
244 |
if(jLabelLongitudPoint == null) |
|
245 |
jLabelLongitudPoint = new JLabel(); |
|
246 |
return jLabelLongitudPoint; |
|
247 |
} |
|
248 |
|
|
249 |
private JLabel getJLabelNumberOfBands() { |
|
250 |
if(jLabelNumberOfBands == null) |
|
251 |
jLabelNumberOfBands = new JLabel(); |
|
252 |
return jLabelNumberOfBands; |
|
253 |
} |
|
254 |
|
|
255 |
@SuppressWarnings("unused") |
|
256 |
private JTextField getJTextBoxLayerSelected() { |
|
257 |
if(jTextBoxLayerSelected == null) |
|
258 |
jTextBoxLayerSelected = new JTextField(); |
|
259 |
return jTextBoxLayerSelected; |
|
260 |
} |
|
261 |
|
|
262 |
private JComboBox getJComboListLayer() { |
|
263 |
if(jComboListLayer == null) { |
|
264 |
jComboListLayer = new JComboBox(); |
|
265 |
jComboListLayer.addActionListener(this); |
|
266 |
} |
|
267 |
return jComboListLayer; |
|
268 |
} |
|
269 |
|
|
270 |
public void updateDataModel() { |
|
271 |
Double nanObj = new Double(Double.NaN); |
|
272 |
DecimalFormat df2 = new DecimalFormat("#.##"); |
|
273 |
DecimalFormat df4 = new DecimalFormat("#.####"); |
|
274 |
getJLabelNumberOfBands().setText(tr.get("bands") + ": " + dataModel.bands); |
|
275 |
|
|
276 |
String y = (!new Double(dataModel.worldPoint.getY()).equals(nanObj)) ? df2.format(dataModel.worldPoint.getY()) : "NaN"; |
|
277 |
getJLabelLatitudePoint().setText(tr.get("lat") + ": " + y); |
|
278 |
|
|
279 |
String x = (!new Double(dataModel.worldPoint.getY()).equals(nanObj)) ? df2.format(dataModel.worldPoint.getX()) : "NaN"; |
|
280 |
getJLabelLongitudPoint().setText(tr.get("long") + ": " + x); |
|
281 |
|
|
282 |
y = (!new Double(dataModel.viewPoint.getY()).equals(nanObj)) ? df2.format(dataModel.viewPoint.getY()) : "NaN"; |
|
283 |
x = (!new Double(dataModel.viewPoint.getY()).equals(nanObj)) ? df2.format(dataModel.viewPoint.getX()) : "NaN"; |
|
284 |
getJLabelViewPoint().setText(tr.get("view_point") + ": (" + x + ", " + y + ")"); |
|
285 |
|
|
286 |
y = (!new Double(dataModel.pixelPoint.getY()).equals(nanObj)) ? df2.format(dataModel.pixelPoint.getY()) : "NaN"; |
|
287 |
x = (!new Double(dataModel.pixelPoint.getY()).equals(nanObj)) ? df2.format(dataModel.pixelPoint.getX()) : "NaN"; |
|
288 |
getJLabelPixelPoint().setText(tr.get("pixel_point") + ": (" + x + ", " + y + ")"); |
|
289 |
|
|
290 |
getJLabelRGBPoint().setText("RGB: " + dataModel.rgb[0] + ", " + |
|
291 |
dataModel.rgb[1] + ", " + |
|
292 |
dataModel.rgb[2]); |
|
293 |
getJLabelHSLPoint().setText("HSL: " + df4.format(dataModel.hsl[0]) + ", " + |
|
294 |
df4.format(dataModel.hsl[1]) + ", " + |
|
295 |
df4.format(dataModel.hsl[2])); |
|
296 |
getJLabelCMKYPoint().setText("CMYK: " + df4.format(dataModel.cmyk[0]) + ", " + |
|
297 |
df4.format(dataModel.cmyk[1]) + ", " + |
|
298 |
df4.format(dataModel.cmyk[2]) + ", " + |
|
299 |
df4.format(dataModel.cmyk[3])); |
|
300 |
|
|
301 |
getJComboListLayer().removeAllItems(); |
|
302 |
for (int i = 0; i < dataModel.layers.size(); i++) { |
|
303 |
getJComboListLayer().addItem(dataModel.getFormatedLayerName(i)); |
|
304 |
} |
|
305 |
|
|
306 |
/*if(dataModel.layers.size() > 0) |
|
307 |
getJTextBoxLayerSelected().setText(dataModel.layers.get(0)); |
|
308 |
*/ |
|
309 |
DefaultListModel listModel = null; |
|
310 |
if(getJListValues().getModel() == null || !(getJListValues().getModel() instanceof DefaultListModel)) |
|
311 |
listModel = new DefaultListModel(); |
|
312 |
else |
|
313 |
listModel = (DefaultListModel)getJListValues().getModel(); |
|
314 |
listModel.clear(); |
|
315 |
for (int i = 0; i < dataModel.bandsValues.size(); i++) { |
|
316 |
listModel.addElement("B" + i + ": " + dataModel.bandsValues.get(i)); |
|
317 |
} |
|
318 |
if(getJListValues().getModel() == null || !(getJListValues().getModel() instanceof DefaultListModel)) |
|
319 |
getJListValues().setModel(listModel); |
|
320 |
} |
|
321 |
|
|
322 |
public void actionPerformed(ActionEvent e) { |
|
323 |
/*if(e.getSource() == getJComboListLayer()) { |
|
324 |
if(getJComboListLayer().getSelectedIndex() != -1) |
|
325 |
getJTextBoxLayerSelected().setText(dataModel.layers.get(getJComboListLayer().getSelectedIndex())); |
|
326 |
}*/ |
|
327 |
} |
|
328 |
|
|
329 |
} |
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/tool/infobypoint/gui/MainInfoByPointPanel.java | ||
---|---|---|
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.tools.app.basic.tool.infobypoint.gui; |
|
23 |
|
|
24 |
import java.awt.Color; |
|
25 |
import java.awt.Dimension; |
|
26 |
import java.awt.GridBagConstraints; |
|
27 |
import java.awt.GridBagLayout; |
|
28 |
import java.util.HashMap; |
|
29 |
import java.util.Observable; |
|
30 |
import java.util.Observer; |
|
31 |
|
|
32 |
import javax.swing.BorderFactory; |
|
33 |
import javax.swing.JPanel; |
|
34 |
|
|
35 |
/** |
|
36 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
37 |
*/ |
|
38 |
public class MainInfoByPointPanel extends JPanel implements Observer { |
|
39 |
private static final long serialVersionUID = 1L; |
|
40 |
private HashMap<String, String> tr = null; |
|
41 |
private InfoByPointDataModel dataModel = null; |
|
42 |
private PixelInspectorPanel pixelInspectorPanel = null; |
|
43 |
private InfoByPointPanel infoByPointPanel = null; |
|
44 |
private ButtonsPanel buttonsPanel = null; |
|
45 |
private boolean extended = false; |
|
46 |
|
|
47 |
public MainInfoByPointPanel(HashMap<String, String> translations, boolean extended) { |
|
48 |
tr = translations; |
|
49 |
if(tr == null || tr.get("layer_list") == null) { |
|
50 |
tr = new HashMap<String, String>(); |
|
51 |
tr.put("layer_list", "layer_list"); |
|
52 |
tr.put("band_values", "band_values"); |
|
53 |
tr.put("pixel_point", "pixel_point"); |
|
54 |
tr.put("view_point", "view_point"); |
|
55 |
tr.put("world_point", "world_point"); |
|
56 |
tr.put("bands", "bands"); |
|
57 |
tr.put("colors", "colors"); |
|
58 |
tr.put("coords", "coords"); |
|
59 |
tr.put("lat", "lat"); |
|
60 |
tr.put("long", "long"); |
|
61 |
} |
|
62 |
this.extended = extended; |
|
63 |
init(); |
|
64 |
} |
|
65 |
|
|
66 |
private void init() { |
|
67 |
setLayout(new GridBagLayout()); |
|
68 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
69 |
gbc.gridx = 0; |
|
70 |
gbc.gridy = 0; |
|
71 |
gbc.gridwidth = 1; |
|
72 |
gbc.gridheight = 1; |
|
73 |
if(!extended) { |
|
74 |
gbc.fill = GridBagConstraints.BOTH; |
|
75 |
gbc.weightx = 1; |
|
76 |
gbc.weighty = 1; |
|
77 |
} else { |
|
78 |
gbc.anchor = GridBagConstraints.WEST; |
|
79 |
gbc.fill = GridBagConstraints.VERTICAL; |
|
80 |
gbc.weighty = 1; |
|
81 |
} |
|
82 |
gbc.insets = new java.awt.Insets(2, 2, 2, 2); |
|
83 |
add(getPixelInspectorPanel(), gbc); |
|
84 |
|
|
85 |
if(!extended) { |
|
86 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
87 |
gbc.weightx = 1; |
|
88 |
gbc.weighty = 0; |
|
89 |
} else { |
|
90 |
gbc.fill = GridBagConstraints.NONE; |
|
91 |
gbc.weighty = 0; |
|
92 |
} |
|
93 |
|
|
94 |
gbc.gridx = 0; |
|
95 |
gbc.gridy = 1; |
|
96 |
add(getinfoByPointPanel(), gbc); |
|
97 |
|
|
98 |
if(extended) { |
|
99 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
100 |
gbc.gridx = 0; |
|
101 |
gbc.gridy = 2; |
|
102 |
add(getButtonsPanel(), gbc); |
|
103 |
|
|
104 |
gbc.gridx = 1; |
|
105 |
gbc.gridy = 0; |
|
106 |
gbc.gridheight = 3; |
|
107 |
gbc.fill = GridBagConstraints.BOTH; |
|
108 |
gbc.weightx = 1; |
|
109 |
gbc.weighty = 1; |
|
110 |
JPanel p = new JPanel(); |
|
111 |
p.setPreferredSize(new Dimension(500, 400)); |
|
112 |
p.setBorder(BorderFactory.createLineBorder(Color.red)); |
|
113 |
add(p, gbc); |
|
114 |
} |
|
115 |
} |
|
116 |
|
|
117 |
public InfoByPointDataModel getInfoByPointDataModel() { |
|
118 |
if(dataModel == null) |
|
119 |
dataModel = new InfoByPointDataModel(); |
|
120 |
return dataModel; |
|
121 |
} |
|
122 |
|
|
123 |
public PixelInspectorPanel getPixelInspectorPanel() { |
|
124 |
if(pixelInspectorPanel == null) |
|
125 |
pixelInspectorPanel = new PixelInspectorPanel(tr); |
|
126 |
return pixelInspectorPanel; |
|
127 |
} |
|
128 |
|
|
129 |
public InfoByPointPanel getinfoByPointPanel() { |
|
130 |
if(infoByPointPanel == null) |
|
131 |
infoByPointPanel = new InfoByPointPanel(tr, getInfoByPointDataModel()); |
|
132 |
return infoByPointPanel; |
|
133 |
} |
|
134 |
|
|
135 |
public ButtonsPanel getButtonsPanel() { |
|
136 |
if(buttonsPanel == null) |
|
137 |
buttonsPanel = new ButtonsPanel(); |
|
138 |
return buttonsPanel; |
|
139 |
} |
|
140 |
|
|
141 |
public void update(Observable o, Object arg) { |
|
142 |
getinfoByPointPanel().updateDataModel(); |
|
143 |
} |
|
144 |
} |
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/tool/infobypoint/gui/PixelInspectorPanel.java | ||
---|---|---|
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.tools.app.basic.tool.infobypoint.gui; |
|
23 |
|
|
24 |
import java.awt.Color; |
|
25 |
import java.awt.Graphics; |
|
26 |
import java.awt.Graphics2D; |
|
27 |
import java.awt.event.ActionEvent; |
|
28 |
import java.awt.event.ActionListener; |
|
29 |
import java.awt.event.MouseEvent; |
|
30 |
import java.awt.event.MouseListener; |
|
31 |
import java.awt.geom.AffineTransform; |
|
32 |
import java.awt.image.BufferedImage; |
|
33 |
import java.util.HashMap; |
|
34 |
|
|
35 |
import javax.swing.JCheckBoxMenuItem; |
|
36 |
import javax.swing.JMenuItem; |
|
37 |
import javax.swing.JPanel; |
|
38 |
import javax.swing.JPopupMenu; |
|
39 |
import javax.swing.event.PopupMenuEvent; |
|
40 |
import javax.swing.event.PopupMenuListener; |
|
41 |
|
|
42 |
import org.gvsig.raster.tools.app.basic.tool.pixelincrease.PixelInspector; |
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
/** |
|
47 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
48 |
*/ |
|
49 |
public class PixelInspectorPanel extends JPanel implements MouseListener, PixelInspector { |
|
50 |
final private static long serialVersionUID = -3370601314380922368L; |
|
51 |
private JPopupMenu menu = null; |
|
52 |
/** |
|
53 |
* Ancho y alto de la ventana |
|
54 |
*/ |
|
55 |
private int w = 0; |
|
56 |
private int h = 0; |
|
57 |
/** |
|
58 |
* Posici?n de la ventana en X y en Y |
|
59 |
*/ |
|
60 |
//private int posWindowX = 0; |
|
61 |
//private int posWindowY = 0; |
|
62 |
/** |
|
63 |
* Escala del zoom |
|
64 |
*/ |
|
65 |
private int scale = 8; |
|
66 |
/** |
|
67 |
* Vista asociada al inspector de pixels |
|
68 |
*/ |
|
69 |
public BufferedImage img = null; |
|
70 |
/** |
|
71 |
* Posici?n en X e Y donde se comienza a dibujar dentro del inspector de pixeles |
|
72 |
*/ |
|
73 |
private int posX = 0; |
|
74 |
private int posY = 0; |
|
75 |
/** |
|
76 |
* Posici?n del pixel en X e Y en relaci?n a las coordenadas del buffer de la vista |
|
77 |
*/ |
|
78 |
public int pixX = 0; |
|
79 |
public int pixY = 0; |
|
80 |
/** |
|
81 |
* Valores RGB del pixel seleccionado |
|
82 |
*/ |
|
83 |
int red = 0, green = 0, blue = 0; |
|
84 |
private boolean clear = false; |
|
85 |
private Color color = Color.red; |
|
86 |
private JCheckBoxMenuItem[] entry = new JCheckBoxMenuItem[6]; |
|
87 |
private HashMap<String, String> |
|
88 |
tr = null; |
|
89 |
/** |
|
90 |
* Constructor de la ventana de dialogo para gvSIG. |
|
91 |
*/ |
|
92 |
public PixelInspectorPanel(HashMap<String, String> translations) { |
|
93 |
tr = translations; |
|
94 |
if(tr == null || tr.get("layer_list") == null) { |
|
95 |
tr = new HashMap<String, String>(); |
|
96 |
tr.put("green", "green"); |
|
97 |
tr.put("red", "red"); |
|
98 |
tr.put("blue", "blue"); |
|
99 |
} |
|
100 |
|
|
101 |
addMouseListener(this); |
|
102 |
|
|
103 |
initMenu(); |
|
104 |
} |
|
105 |
|
|
106 |
/* |
|
107 |
* (non-Javadoc) |
|
108 |
* @see org.gvsig.raster.tools.app.basic.tool.pixelincrease.PixelInspector#setViewCoordinates(int, int) |
|
109 |
*/ |
|
110 |
public void setViewCoordinates(int pixX, int pixY) { |
|
111 |
this.pixX = pixX; |
|
112 |
this.pixY = pixY; |
|
113 |
} |
|
114 |
|
|
115 |
/** |
|
116 |
* |
|
117 |
* @param clear |
|
118 |
*/ |
|
119 |
public void setClear(boolean clear) { |
|
120 |
this.clear = clear; |
|
121 |
} |
|
122 |
|
|
123 |
/** |
|
124 |
* Inicializa el men? contextual con las opciones de selecci?n del |
|
125 |
* zoom. |
|
126 |
*/ |
|
127 |
private void initMenu() { |
|
128 |
menu = new JPopupMenu(); |
|
129 |
PopupMenuListener lis = new PopupMenuListener() { |
|
130 |
public void popupMenuCanceled( PopupMenuEvent evt ) { |
|
131 |
clear = true; |
|
132 |
repaint(); |
|
133 |
} |
|
134 |
|
|
135 |
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { |
|
136 |
} |
|
137 |
|
|
138 |
public void popupMenuWillBecomeVisible(PopupMenuEvent e) { |
|
139 |
} |
|
140 |
}; |
|
141 |
menu.addPopupMenuListener(lis); |
|
142 |
|
|
143 |
ActionListener al = new ActionListener() { |
|
144 |
public void actionPerformed( ActionEvent evt ){ |
|
145 |
String txt = ((JMenuItem)evt.getSource()).getText(); |
|
146 |
if(txt.compareTo("X4") == 0) { |
|
147 |
scale = 4; |
|
148 |
for (int i = 1; i <= 3; i++) |
|
149 |
entry[i].setSelected(false); |
|
150 |
entry[0].setSelected(true); |
|
151 |
} |
|
152 |
if(txt.compareTo("X8") == 0) { |
|
153 |
scale = 8; |
|
154 |
entry[0].setSelected(false); |
|
155 |
entry[1].setSelected(true); |
|
156 |
entry[2].setSelected(false); |
|
157 |
entry[3].setSelected(false); |
|
158 |
} |
|
159 |
if(txt.compareTo("X16") == 0) { |
|
160 |
scale = 16; |
|
161 |
entry[0].setSelected(false); |
|
162 |
entry[1].setSelected(false); |
|
163 |
entry[2].setSelected(true); |
|
164 |
entry[3].setSelected(false); |
|
165 |
} |
|
166 |
if(txt.compareTo("X32") == 0) { |
|
167 |
scale = 32; |
|
168 |
for (int i = 0; i < 3; i++) |
|
169 |
entry[i].setSelected(false); |
|
170 |
entry[3].setSelected(true); |
|
171 |
} |
|
172 |
if(txt.compareTo(tr.get("green")) == 0) { |
|
173 |
color = Color.GREEN; |
|
174 |
entry[4].setSelected(false); |
|
175 |
entry[5].setSelected(true); |
|
176 |
} |
|
177 |
if(txt.compareTo(tr.get("red")) == 0) { |
|
178 |
color = Color.RED; |
|
179 |
entry[4].setSelected(true); |
|
180 |
entry[5].setSelected(false); |
|
181 |
} |
|
182 |
} |
|
183 |
}; |
|
184 |
|
|
185 |
entry[0] = new JCheckBoxMenuItem( "X4" ); |
|
186 |
entry[0].addActionListener( al ); |
|
187 |
menu.add(entry[0]); |
|
188 |
entry[1] = new JCheckBoxMenuItem( "X8" ); |
|
189 |
entry[1].setSelected(true); |
|
190 |
entry[1].addActionListener( al ); |
|
191 |
menu.add(entry[1]); |
|
192 |
entry[2] = new JCheckBoxMenuItem( "X16" ); |
|
193 |
entry[2].addActionListener( al ); |
|
194 |
menu.add(entry[2]); |
|
195 |
entry[3] = new JCheckBoxMenuItem( "X32" ); |
|
196 |
entry[3].addActionListener( al ); |
|
197 |
menu.add(entry[3]); |
|
198 |
entry[4] = new JCheckBoxMenuItem(tr.get("red") ); |
|
199 |
entry[4].addActionListener( al ); |
|
200 |
entry[4].setSelected(true); |
|
201 |
menu.add(entry[4]); |
|
202 |
entry[5] = new JCheckBoxMenuItem(tr.get("green") ); |
|
203 |
entry[5].addActionListener( al ); |
|
204 |
menu.add(entry[5]); |
|
205 |
} |
|
206 |
|
|
207 |
/** |
|
208 |
* Obtiene el buffer de la vista activa y lo dibuja sobre el panel |
|
209 |
* con los datos de escala y desplazamiento seleccionados. |
|
210 |
*/ |
|
211 |
protected void paintComponent(Graphics g) { |
|
212 |
w = getVisibleRect().width; |
|
213 |
h = getVisibleRect().height; |
|
214 |
|
|
215 |
if(clear) { |
|
216 |
g.setColor(Color.BLACK); |
|
217 |
g.fillRect(0, 0, w, h); |
|
218 |
return; |
|
219 |
} |
|
220 |
|
|
221 |
if(img != null) { |
|
222 |
int sizeCrux = 10; |
|
223 |
|
|
224 |
//Obtenemos valores RGB del Image |
|
225 |
int value = 0; |
|
226 |
try { |
|
227 |
value = img.getRGB(pixX, pixY); |
|
228 |
} catch (ArrayIndexOutOfBoundsException e) { |
|
229 |
|
|
230 |
} |
|
231 |
red = ((value & 0x00ff0000) >> 16); |
|
232 |
green = ((value & 0x0000ff00) >> 8); |
|
233 |
blue = (value & 0x000000ff); |
|
234 |
|
|
235 |
//Dibujamos el graphics con el zoom |
|
236 |
g.setColor(Color.BLACK); |
|
237 |
g.fillRect(0, 0, w, h); |
|
238 |
((Graphics2D)g).scale(scale, scale); |
|
239 |
g.drawImage(img, posX, posY , this); |
|
240 |
((Graphics2D)g).setTransform(new AffineTransform()); |
|
241 |
|
|
242 |
//Dibujamos la informaci?n RGB y la cruz |
|
243 |
g.setXORMode(Color.WHITE); |
|
244 |
g.setColor(color); |
|
245 |
int middleW = w >> 1; |
|
246 |
int middleH = h >> 1; |
|
247 |
g.drawLine(middleW - sizeCrux, middleH, middleW + sizeCrux, middleH); |
|
248 |
g.drawLine(middleW, middleH - sizeCrux, middleW , middleH + sizeCrux); |
|
249 |
//g.drawString(red + "," + green + "," + blue, w - 85, h - 3); |
|
250 |
} |
|
251 |
} |
|
252 |
|
|
253 |
/** |
|
254 |
* Asigna el zoom de la vista sobre el inspector de pixels |
|
255 |
* @param scale Escala |
|
256 |
*/ |
|
257 |
public void setScale(int scale) { |
|
258 |
this.scale = scale; |
|
259 |
} |
|
260 |
|
|
261 |
/** |
|
262 |
* Asigna la posici?n en X del control donde se empieza a dibujar |
|
263 |
* @param posX posici?n X del Graphics donde se empieza a dibujar |
|
264 |
*/ |
|
265 |
public void setPosX(int posX) { |
|
266 |
this.posX = posX; |
|
267 |
} |
|
268 |
|
|
269 |
/** |
|
270 |
* Asigna la posici?n en Y del control donde se empieza a dibujar |
|
271 |
* @param posY posici?n Y del Graphics donde se empieza a dibujar |
|
272 |
*/ |
|
273 |
public void setPosY(int posY) { |
|
274 |
this.posY = posY; |
|
275 |
} |
|
276 |
|
|
277 |
/** |
|
278 |
* Obtiene el factor de escala |
|
279 |
* @return |
|
280 |
*/ |
|
281 |
public int getScale() { |
|
282 |
return scale; |
|
283 |
} |
|
284 |
|
|
285 |
/** |
|
286 |
* Obtiene la vista asociada al inspector de pixeles |
|
287 |
* @return IView |
|
288 |
*/ |
|
289 |
public BufferedImage getDataBuffer() { |
|
290 |
return img; |
|
291 |
} |
|
292 |
|
|
293 |
/** |
|
294 |
* Asigna la vista asociada al inspector de pixeles |
|
295 |
* @param IView |
|
296 |
*/ |
|
297 |
public void setDataBuffer(BufferedImage img) { |
|
298 |
this.img = img; |
|
299 |
} |
|
300 |
|
|
301 |
/* |
|
302 |
* (non-Javadoc) |
|
303 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) |
|
304 |
*/ |
|
305 |
public void mouseClicked(MouseEvent e) { |
|
306 |
clear = true; |
|
307 |
repaint(); |
|
308 |
} |
|
309 |
|
|
310 |
/* |
|
311 |
* (non-Javadoc) |
|
312 |
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent) |
|
313 |
*/ |
|
314 |
public void mouseEntered(MouseEvent e) { |
|
315 |
clear = true; |
|
316 |
repaint(); |
|
317 |
} |
|
318 |
|
|
319 |
/* |
|
320 |
* (non-Javadoc) |
|
321 |
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent) |
|
322 |
*/ |
|
323 |
public void mouseExited(MouseEvent e) { |
|
324 |
clear = true; |
|
325 |
repaint(); |
|
326 |
} |
|
327 |
|
|
328 |
/* |
|
329 |
* (non-Javadoc) |
|
330 |
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) |
|
331 |
*/ |
|
332 |
public void mousePressed(MouseEvent e) { |
|
333 |
if(e.getButton() == MouseEvent.BUTTON3) { |
|
334 |
menu.show( e.getComponent(), e.getX(), e.getY() ); |
|
335 |
clear = true; |
|
336 |
repaint(); |
|
337 |
} |
|
338 |
} |
|
339 |
|
|
340 |
/* |
|
341 |
* (non-Javadoc) |
|
342 |
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) |
|
343 |
*/ |
|
344 |
public void mouseReleased(MouseEvent e) { |
|
345 |
} |
|
346 |
|
|
347 |
} |
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/tool/infobypoint/gui/PixelViewInfoPanel.java | ||
---|---|---|
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.tools.app.basic.tool.infobypoint.gui; |
|
23 |
|
|
24 |
import java.awt.GridBagConstraints; |
|
25 |
import java.awt.GridBagLayout; |
|
26 |
import java.text.DecimalFormat; |
|
27 |
import java.util.HashMap; |
|
28 |
|
|
29 |
import javax.swing.BorderFactory; |
|
30 |
import javax.swing.DefaultListModel; |
|
31 |
import javax.swing.JLabel; |
|
32 |
import javax.swing.JList; |
|
33 |
import javax.swing.JPanel; |
|
34 |
import javax.swing.JScrollPane; |
|
35 |
|
|
36 |
public class PixelViewInfoPanel extends JPanel { |
|
37 |
private static final long serialVersionUID = 1L; |
|
38 |
private HashMap<String, String> |
|
39 |
tr = null; |
|
40 |
private JList jListBandValues = null; |
|
41 |
private JLabel jLabelHSLPoint = null; |
|
42 |
private JLabel jLabelCMKYPoint = null; |
|
43 |
private JLabel jLabelRGBPoint = null; |
|
44 |
private JLabel jLabelPixelPoint = null; |
|
45 |
private JLabel jLabelViewPoint = null; |
|
46 |
private JLabel jLabelLatitudePoint = null; |
|
47 |
private JLabel jLabelLongitudPoint = null; |
|
48 |
private JLabel jLabelNumberOfBands = null; |
|
49 |
|
|
50 |
private JPanel jPanelCoordinates = null; |
|
51 |
private JPanel jPanelColors = null; |
|
52 |
private JPanel jPanelBands = null; |
|
53 |
private InfoByPointDataModel dataModel = null; |
|
54 |
|
|
55 |
public PixelViewInfoPanel(HashMap<String, String> translations, InfoByPointDataModel dataModel) { |
|
56 |
tr = translations; |
|
57 |
if(tr == null || tr.get("layer_list") == null) { |
|
58 |
tr = new HashMap<String, String>(); |
|
59 |
tr.put("layer_list", "layer_list"); |
|
60 |
tr.put("band_values", "band_values"); |
|
61 |
tr.put("pixel_point", "pixel_point"); |
|
62 |
tr.put("view_point", "view_point"); |
|
63 |
tr.put("world_point", "world_point"); |
|
64 |
tr.put("bands", "bands"); |
|
65 |
tr.put("colors", "colors"); |
|
66 |
tr.put("coords", "coords"); |
|
67 |
tr.put("lat", "lat"); |
|
68 |
tr.put("long", "long"); |
|
69 |
} |
|
70 |
this.dataModel = dataModel; |
|
71 |
init(); |
|
72 |
} |
|
73 |
|
|
74 |
private void init() { |
|
75 |
setLayout(new GridBagLayout()); |
|
76 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
77 |
gbc.gridx = 0; |
|
78 |
gbc.gridy = 0; |
|
79 |
gbc.anchor = GridBagConstraints.WEST; |
|
80 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
81 |
gbc.weightx = 1; |
|
82 |
gbc.insets = new java.awt.Insets(1, 2, 1, 2); |
|
83 |
add(getJPanelCoordinates(), gbc); |
|
84 |
|
|
85 |
gbc.gridy = 1; |
|
86 |
gbc.fill = GridBagConstraints.BOTH; |
|
87 |
gbc.weighty = 1; |
|
88 |
add(getJPanelBands(), gbc); |
|
89 |
|
|
90 |
gbc.gridy = 2; |
|
91 |
gbc.weighty = 0; |
|
92 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
93 |
add(getJPanelColors(), gbc); |
|
94 |
} |
|
95 |
|
|
96 |
public JPanel getJPanelBands() { |
|
97 |
if(jPanelBands == null) { |
|
98 |
jPanelBands = new JPanel(); |
|
99 |
jPanelBands.setBorder(BorderFactory.createTitledBorder(tr.get("bands"))); |
|
100 |
jPanelBands.setLayout(new GridBagLayout()); |
|
101 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
102 |
gbc.gridx = 0; |
|
103 |
gbc.gridy = 0; |
|
104 |
gbc.anchor = GridBagConstraints.WEST; |
|
105 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
106 |
gbc.weightx = 1; |
|
107 |
gbc.insets = new java.awt.Insets(1, 2, 1, 2); |
|
108 |
|
|
109 |
jPanelBands.add(getJLabelNumberOfBands(), gbc); |
|
110 |
gbc.gridy = 1; |
|
111 |
gbc.gridheight = 2; |
|
112 |
gbc.fill = GridBagConstraints.BOTH; |
|
113 |
gbc.weighty = 1; |
|
114 |
JScrollPane listScroller = new JScrollPane(getJListValues()); |
|
115 |
jPanelBands.add(listScroller, gbc); |
|
116 |
} |
|
117 |
return jPanelBands; |
|
118 |
} |
|
119 |
|
|
120 |
public JPanel getJPanelColors() { |
|
121 |
if(jPanelColors == null) { |
|
122 |
jPanelColors = new JPanel(); |
|
123 |
jPanelColors.setBorder(BorderFactory.createTitledBorder(tr.get("colors"))); |
|
124 |
jPanelColors.setLayout(new GridBagLayout()); |
|
125 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
126 |
gbc.gridx = 0; |
|
127 |
gbc.gridy = 0; |
|
128 |
gbc.anchor = GridBagConstraints.WEST; |
|
129 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
130 |
gbc.weightx = 1; |
|
131 |
gbc.insets = new java.awt.Insets(1, 2, 2, 2); |
|
132 |
|
|
133 |
jPanelColors.add(getJLabelRGBPoint(), gbc); |
|
134 |
gbc.gridy = 1; |
|
135 |
jPanelColors.add(getJLabelCMKYPoint(), gbc); |
|
136 |
gbc.gridy = 2; |
|
137 |
jPanelColors.add(getJLabelHSLPoint(), gbc); |
|
138 |
} |
|
139 |
return jPanelColors; |
|
140 |
} |
|
141 |
|
|
142 |
public JPanel getJPanelCoordinates() { |
|
143 |
if(jPanelCoordinates == null) { |
|
144 |
jPanelCoordinates = new JPanel(); |
|
145 |
jPanelCoordinates.setLayout(new GridBagLayout()); |
|
146 |
jPanelCoordinates.setBorder(BorderFactory.createTitledBorder(tr.get("coords"))); |
|
147 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
148 |
gbc.gridx = 0; |
|
149 |
gbc.gridy = 0; |
|
150 |
gbc.anchor = GridBagConstraints.WEST; |
|
151 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
152 |
gbc.weightx = 1; |
|
153 |
gbc.insets = new java.awt.Insets(1, 2, 2, 2); |
|
154 |
|
|
155 |
gbc.gridy = 1; |
|
156 |
jPanelCoordinates.add(getJLabelLatitudePoint(), gbc); |
|
157 |
gbc.gridy = 2; |
|
158 |
jPanelCoordinates.add(getJLabelLongitudPoint(), gbc); |
|
159 |
gbc.gridy = 3; |
|
160 |
jPanelCoordinates.add(getJLabelViewPoint(), gbc); |
|
161 |
gbc.gridy = 4; |
|
162 |
jPanelCoordinates.add(getJLabelPixelPoint(), gbc); |
|
163 |
} |
|
164 |
return jPanelCoordinates; |
|
165 |
} |
|
166 |
|
|
167 |
private JList getJListValues() { |
|
168 |
if(jListBandValues == null) { |
|
169 |
jListBandValues = new JList(); |
|
170 |
} |
|
171 |
return jListBandValues; |
|
172 |
} |
|
173 |
|
|
174 |
private JLabel getJLabelHSLPoint() { |
|
175 |
if(jLabelHSLPoint == null) |
|
176 |
jLabelHSLPoint = new JLabel("HSL: "); |
|
177 |
return jLabelHSLPoint; |
|
178 |
} |
|
179 |
|
|
180 |
private JLabel getJLabelCMKYPoint() { |
|
181 |
if(jLabelCMKYPoint == null) |
|
182 |
jLabelCMKYPoint = new JLabel("CMYK: "); |
|
183 |
return jLabelCMKYPoint; |
|
184 |
} |
|
185 |
|
|
186 |
private JLabel getJLabelRGBPoint() { |
|
187 |
if(jLabelRGBPoint == null) |
|
188 |
jLabelRGBPoint = new JLabel("RGB: " ); |
|
189 |
return jLabelRGBPoint; |
|
190 |
} |
|
191 |
|
|
192 |
private JLabel getJLabelPixelPoint() { |
|
193 |
if(jLabelPixelPoint == null) |
|
194 |
jLabelPixelPoint = new JLabel(); |
|
195 |
return jLabelPixelPoint; |
|
196 |
} |
|
197 |
|
|
198 |
private JLabel getJLabelViewPoint() { |
|
199 |
if(jLabelViewPoint == null) |
|
200 |
jLabelViewPoint = new JLabel(); |
|
201 |
return jLabelViewPoint; |
|
202 |
} |
|
203 |
|
|
204 |
private JLabel getJLabelLatitudePoint() { |
|
205 |
if(jLabelLatitudePoint == null) |
|
206 |
jLabelLatitudePoint = new JLabel(); |
|
207 |
return jLabelLatitudePoint; |
|
208 |
} |
|
209 |
|
|
210 |
private JLabel getJLabelLongitudPoint() { |
|
211 |
if(jLabelLongitudPoint == null) |
|
212 |
jLabelLongitudPoint = new JLabel(); |
|
213 |
return jLabelLongitudPoint; |
|
214 |
} |
|
215 |
|
|
216 |
private JLabel getJLabelNumberOfBands() { |
|
217 |
if(jLabelNumberOfBands == null) |
|
218 |
jLabelNumberOfBands = new JLabel(); |
|
219 |
return jLabelNumberOfBands; |
|
220 |
} |
|
221 |
|
|
222 |
public void updateDataModel() { |
|
223 |
Double nanObj = new Double(Double.NaN); |
|
224 |
DecimalFormat df2 = new DecimalFormat("#.##"); |
|
225 |
DecimalFormat df4 = new DecimalFormat("#.####"); |
|
226 |
getJLabelNumberOfBands().setText(tr.get("bands") + ": " + dataModel.bands); |
|
227 |
|
|
228 |
String y = (!new Double(dataModel.worldPoint.getY()).equals(nanObj)) ? df2.format(dataModel.worldPoint.getY()) : "NaN"; |
|
229 |
getJLabelLatitudePoint().setText(tr.get("lat") + ": " + y); |
|
230 |
|
|
231 |
String x = (!new Double(dataModel.worldPoint.getY()).equals(nanObj)) ? df2.format(dataModel.worldPoint.getX()) : "NaN"; |
|
232 |
getJLabelLongitudPoint().setText(tr.get("long") + ": " + x); |
|
233 |
|
|
234 |
y = (!new Double(dataModel.viewPoint.getY()).equals(nanObj)) ? df2.format(dataModel.viewPoint.getY()) : "NaN"; |
|
235 |
x = (!new Double(dataModel.viewPoint.getY()).equals(nanObj)) ? df2.format(dataModel.viewPoint.getX()) : "NaN"; |
|
236 |
getJLabelViewPoint().setText(tr.get("view_point") + ": (" + x + ", " + y + ")"); |
|
237 |
|
|
238 |
y = (!new Double(dataModel.pixelPoint.getY()).equals(nanObj)) ? df2.format(dataModel.pixelPoint.getY()) : "NaN"; |
|
239 |
x = (!new Double(dataModel.pixelPoint.getY()).equals(nanObj)) ? df2.format(dataModel.pixelPoint.getX()) : "NaN"; |
|
240 |
getJLabelPixelPoint().setText(tr.get("pixel_point") + ": (" + x + ", " + y + ")"); |
|
241 |
|
|
242 |
getJLabelRGBPoint().setText("RGB: " + dataModel.rgb[0] + ", " + |
|
243 |
dataModel.rgb[1] + ", " + |
|
244 |
dataModel.rgb[2]); |
|
245 |
getJLabelHSLPoint().setText("HSL: " + df4.format(dataModel.hsl[0]) + ", " + |
|
246 |
df4.format(dataModel.hsl[1]) + ", " + |
|
247 |
df4.format(dataModel.hsl[2])); |
|
248 |
getJLabelCMKYPoint().setText("CMYK: " + df4.format(dataModel.cmyk[0]) + ", " + |
|
249 |
df4.format(dataModel.cmyk[1]) + ", " + |
|
250 |
df4.format(dataModel.cmyk[2]) + ", " + |
|
251 |
df4.format(dataModel.cmyk[3])); |
|
252 |
|
|
253 |
DefaultListModel listModel = null; |
|
254 |
if(getJListValues().getModel() == null || !(getJListValues().getModel() instanceof DefaultListModel)) |
|
255 |
listModel = new DefaultListModel(); |
|
256 |
else |
|
257 |
listModel = (DefaultListModel)getJListValues().getModel(); |
|
258 |
listModel.clear(); |
|
259 |
for (int i = 0; i < dataModel.bandsValues.size(); i++) { |
|
260 |
listModel.addElement("B" + i + ": " + dataModel.bandsValues.get(i)); |
|
261 |
} |
|
262 |
if(getJListValues().getModel() == null || !(getJListValues().getModel() instanceof DefaultListModel)) |
|
263 |
getJListValues().setModel(listModel); |
|
264 |
} |
|
265 |
} |
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.basic/src/main/java/org/gvsig/raster/tools/app/basic/tool/infobypoint/gui/InfoByPointDataModel.java | ||
---|---|---|
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.tools.app.basic.tool.infobypoint.gui; |
|
23 |
|
|
24 |
import java.awt.geom.Point2D; |
|
25 |
import java.util.ArrayList; |
|
26 |
import java.util.List; |
|
27 |
import java.util.Observable; |
|
28 |
|
|
29 |
public class InfoByPointDataModel extends Observable { |
|
30 |
private static final int LONG_STRING = 26; |
|
31 |
public int bands = 0; |
|
32 |
public List<Double> bandsValues = new ArrayList<Double>(); |
|
33 |
public Point2D pixelPoint = new Point2D.Double(); |
|
34 |
public Point2D worldPoint = new Point2D.Double(); |
|
35 |
public Point2D viewPoint = new Point2D.Double(); |
|
36 |
public int[] rgb = new int[3]; |
|
37 |
public double[] cmyk = new double[4]; |
|
38 |
public double[] hsl = new double[3]; |
|
39 |
public List<String> layers = null; |
|
40 |
|
|
41 |
public InfoByPointDataModel() { |
|
42 |
setARGB(0, 0, 0); |
|
43 |
setCMYK(new double[]{0, 0, 0, 0}); |
|
44 |
setHSL(0, 0, 0); |
|
45 |
setBandValues(new double[]{Double.NaN}); |
|
46 |
setNumberOfBands(0); |
|
47 |
setPixelPoint(-1, -1); |
|
48 |
setViewPoint(Double.NaN, Double.NaN); |
|
49 |
setWorldPoint(Double.NaN, Double.NaN); |
|
50 |
List<String> list = new ArrayList<String>(); |
|
51 |
list.add("..."); |
|
52 |
setLayerList(list); |
|
53 |
} |
|
54 |
|
|
55 |
public void setBandValues(double[] list) { |
|
56 |
bandsValues.clear(); |
|
57 |
for (int i = 0; i < list.length; i++) { |
|
58 |
bandsValues.add(list[i]); |
|
59 |
} |
|
60 |
} |
|
61 |
|
|
62 |
public void setNumberOfBands(int n) { |
|
63 |
this.bands = n; |
|
64 |
} |
|
65 |
|
|
66 |
public void setLayerList(List<String> list) { |
|
67 |
layers = list; |
|
68 |
} |
|
69 |
|
|
70 |
public void setARGB(int r, int g, int b) { |
|
71 |
rgb[0] = r; |
|
72 |
rgb[1] = g; |
|
73 |
rgb[2] = b; |
|
74 |
} |
|
75 |
|
|
76 |
public void setCMYK(double[] cmyk) { |
|
77 |
this.cmyk = cmyk; |
|
78 |
} |
|
79 |
|
|
80 |
public void setHSL(double h, double s, double l) { |
|
81 |
hsl[0] = h; |
|
82 |
hsl[1] = s; |
|
83 |
hsl[2] = l; |
|
84 |
} |
|
85 |
|
|
86 |
public void setPixelPoint(double x, double y) { |
|
87 |
pixelPoint.setLocation(x, y); |
|
88 |
} |
|
89 |
|
|
90 |
public void setWorldPoint(double x, double y) { |
|
91 |
worldPoint.setLocation(x, y); |
|
92 |
} |
|
93 |
|
|
94 |
public void setViewPoint(double x, double y) { |
|
95 |
viewPoint.setLocation(x, y); |
|
96 |
} |
|
97 |
|
|
98 |
public String getFormatedLayerName(int i) { |
|
99 |
if(LONG_STRING < layers.get(i).length()) |
|
100 |
return "..." + layers.get(i).substring(layers.get(i).length() - LONG_STRING, layers.get(i).length()); |
|
101 |
return layers.get(i); |
|
102 |
} |
|
103 |
|
|
104 |
public void notifyObservers() { |
|
105 |
setChanged(); |
|
106 |
super.notifyObservers(); |
|
107 |
} |
|
108 |
} |
Also available in: Unified diff