Statistics
| Revision:

gvsig-raster / 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 @ 1172

History | View | Annotate | Download (11.2 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.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
}