Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / geolocation / ui / GeoLocationPanel.java @ 15765

History | View | Annotate | Download (11.8 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.rastertools.geolocation.ui;
20

    
21
import java.awt.Dimension;
22
import java.awt.GridBagConstraints;
23
import java.awt.GridBagLayout;
24
import java.awt.GridLayout;
25
import java.awt.geom.AffineTransform;
26

    
27
import javax.swing.ImageIcon;
28
import javax.swing.JButton;
29
import javax.swing.JPanel;
30

    
31
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
32
import org.gvsig.gui.beans.datainput.DataInputContainer;
33
import org.gvsig.raster.util.Historical;
34
import org.gvsig.raster.util.MathUtils;
35
import org.gvsig.rastertools.geolocation.listener.GeoLocationPanelListener;
36

    
37
import com.iver.andami.PluginServices;
38
import com.iver.cit.gvsig.fmap.MapControl;
39

    
40
/**
41
 * Panel de geolocalizaci?n. Este muestra los par?metros de la matriz de transformaci?n
42
 * que est? aplicandose en esos momentos al raster. Los par?metros son variados en 
43
 * tiempo real a medida que modificamos la georreferenciaci?n con las herramientas.
44
 * 
45
 * @version 30/07/2007
46
 * @author Nacho Brodin (nachobrodin@gmail.com)
47
 *
48
 */
49
public class GeoLocationPanel extends JPanel {
50
        private static final long         serialVersionUID = -7797379892312214949L;
51
        private DataInputContainer               ulx = null;
52
        private DataInputContainer               uly = null;
53
        private DataInputContainer               psx = null;
54
        private DataInputContainer               psy = null;
55
        private DataInputContainer               rotx = null;
56
        private DataInputContainer               roty = null;
57
        private JButton                    first = null;
58
        private JButton                    save = null;
59
        private JButton                    back = null;
60
        private JButton                    next = null;
61
        private JButton                    apply = null;
62
        private JButton                    reset = null;
63
        
64
        private JPanel                                   coordsPanel = null;
65
        private JPanel                                   paramsPanel = null;
66
        private JPanel                                   buttonsPanel = null;
67
        private GeoLocationPanelListener   listener = null;
68
        private FLyrRasterSE               lyr = null;
69
        /**
70
     * N?mero de decimales a mostrar
71
     */
72
    private int                        tailValue = 2;
73
    private MapControl                 mapCtrl = null;
74
    private boolean                    geolocModify = false;
75
        
76
        /**
77
         * Constructor
78
         */
79
        public GeoLocationPanel() {
80
                ImageIcon backIcon = null;
81
                ImageIcon nextIcon = null;
82
                ImageIcon saveIcon = null;
83
                ImageIcon firstIcon = null;
84
                ImageIcon resetIcon = null;
85
                try {
86
                        backIcon = PluginServices.getIconTheme().get("back-icon");
87
                        nextIcon = PluginServices.getIconTheme().get("next-icon");
88
                        saveIcon = PluginServices.getIconTheme().get("save-icon"); 
89
                        firstIcon = PluginServices.getIconTheme().get("undo-icon");
90
                        resetIcon = PluginServices.getIconTheme().get("reset-icon");
91
                } catch(NullPointerException e) {
92
                        
93
                }
94
                
95
                listener = new GeoLocationPanelListener(this);
96
                
97
                GridBagLayout gl = new GridBagLayout();
98
                this.setLayout(gl);
99
                setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this, "geolocation"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
100
                ulx = new DataInputContainer();
101
                ulx.setLabelText(PluginServices.getText(this,"ux"));
102
                ulx.addValueChangedListener(listener);
103
                
104
                uly = new DataInputContainer();
105
                uly.setLabelText(PluginServices.getText(this,"uy"));
106
                uly.addValueChangedListener(listener);
107
                
108
                psx = new DataInputContainer();
109
                psx.setLabelText(PluginServices.getText(this,"px"));
110
                psx.addValueChangedListener(listener);
111
                
112
                psy = new DataInputContainer();
113
                psy.setLabelText(PluginServices.getText(this,"py"));
114
                psy.addValueChangedListener(listener);
115
                
116
                rotx = new DataInputContainer();
117
                rotx.setLabelText(PluginServices.getText(this,"rx"));
118
                rotx.addValueChangedListener(listener);
119
                
120
                roty = new DataInputContainer();
121
                roty.setLabelText(PluginServices.getText(this,"ry"));
122
                roty.addValueChangedListener(listener);
123
                
124
                first = new JButton(firstIcon);
125
                save = new JButton(saveIcon);
126
                back = new JButton(backIcon);
127
                next = new JButton(nextIcon);
128
                apply = new JButton(PluginServices.getText(this,"apply"));
129
                reset = new JButton(resetIcon);
130
                
131
                save.setToolTipText(PluginServices.getText(this,"salvar_transf"));
132
                back.setToolTipText(PluginServices.getText(this,"back_transf"));
133
                next.setToolTipText(PluginServices.getText(this,"next_transf"));
134
                apply.setToolTipText(PluginServices.getText(this,"aplicar_transf"));
135
                first.setToolTipText(PluginServices.getText(this,"first_transf"));
136
                reset.setToolTipText(PluginServices.getText(this,"reset_transf"));
137
                
138
                save.setPreferredSize(new Dimension(28, 24));
139
                first.setPreferredSize(new Dimension(28, 24));
140
                back.setPreferredSize(new Dimension(28, 24));
141
                next.setPreferredSize(new Dimension(28, 24));
142
                apply.setPreferredSize(new Dimension(64,24));
143
                reset.setPreferredSize(new Dimension(28,24));
144
                
145
                first.addActionListener(listener);
146
                save.addActionListener(listener);
147
                back.addActionListener(listener);
148
                next.addActionListener(listener);
149
                apply.addActionListener(listener);
150
                reset.addActionListener(listener);
151
                
152
                save.setEnabled(false);
153
                back.setEnabled(false);
154
                next.setEnabled(false);
155
                first.setEnabled(false);
156
                reset.setEnabled(true);
157
                
158
                coordsPanel = new JPanel();
159
                GridLayout l = new GridLayout(2, 1);
160
                l.setVgap(2);
161
                coordsPanel.setLayout(l);
162
                
163
                paramsPanel = new JPanel();
164
                GridLayout l1 = new GridLayout(2, 2);
165
                l1.setVgap(2);
166
                paramsPanel.setLayout(l1);
167

    
168
                getButtonsPanel();
169
                
170
                init();
171
        }
172
        
173
        private void init() {
174
                coordsPanel.add(ulx);
175
                coordsPanel.add(uly);
176
                paramsPanel.add(psx);
177
                paramsPanel.add(psy);
178
                paramsPanel.add(rotx);
179
                paramsPanel.add(roty);
180
                
181
                GridBagConstraints gbc = new GridBagConstraints();
182
                gbc.insets = new java.awt.Insets(0, 0, 0, 2);
183
                buttonsPanel.add(reset, gbc);
184
                buttonsPanel.add(back, gbc);
185
                buttonsPanel.add(next, gbc);
186
                buttonsPanel.add(first, gbc);
187
                buttonsPanel.add(save, gbc);
188
                buttonsPanel.add(apply, gbc);
189
                
190
                gbc.gridx = 0;
191
                gbc.gridy = 0;
192
                gbc.fill = GridBagConstraints.HORIZONTAL;
193
                gbc.weightx = 1.0;
194
                gbc.insets = new java.awt.Insets(1, 1, 1, 1);
195
                this.add(coordsPanel, gbc);
196
                
197
                gbc.gridy = 1;
198
                this.add(paramsPanel, gbc);
199
                
200
                gbc.gridy = 2;
201
                this.add(buttonsPanel, gbc);
202
        }
203
        
204
        /**
205
         * Obtiene el panel con los botones
206
         * @return JPanel
207
         */
208
        public JPanel getButtonsPanel() {
209
                if(buttonsPanel == null) {
210
                        buttonsPanel = new JPanel();
211
                        buttonsPanel.setLayout(new GridBagLayout());
212
                }
213
                return buttonsPanel;
214
        }
215

    
216
        /**
217
         * Activa o desactiva los botones de transformaci?n anterior y siguiente dependiendo
218
         * del estado de la lista de transformaciones.
219
         * @return
220
         */
221
        public void activeButtons() {
222
                Historical affineTransformHist = lyr.getAffineTransformHistorical();
223
                if(!affineTransformHist.existNext())
224
                        next.setEnabled(false);
225
                else
226
                        next.setEnabled(true);
227
                if(!affineTransformHist.existBack())
228
                        back.setEnabled(false);
229
                else
230
                        back.setEnabled(true);
231
                if(affineTransformHist.getElementsCount() <= 1)
232
                        first.setEnabled(false);
233
                else
234
                        first.setEnabled(true);
235
                if(affineTransformHist.getElementsCount() == 0)
236
                        save.setEnabled(false);
237
                else
238
                        save.setEnabled(true);
239
        }
240
        
241
        /**
242
         * Obtiene el MapControl
243
         * @return MapControl
244
         */
245
        public MapControl getMapCtrl() {
246
                return mapCtrl;
247
        }
248
        
249
        /**
250
         * Asigna el MapControl
251
         * @param mapCtrl
252
         */
253
        public void setMapCtrl(MapControl mapCtrl) {
254
                this.mapCtrl = mapCtrl;
255
        }
256
        
257
        /**
258
         * Obtiene la capa raster asociada
259
         * @return
260
         */
261
        public FLyrRasterSE getLayer() {
262
                return this.lyr;
263
        }
264
        
265
        /**
266
         * Asigna la capa raster del raster seleccionado en el TOC en base 
267
         * al cual se asigna la georreferenciaci?n al dialogo.
268
         * @param lyr
269
         */
270
        public void setLayer(FLyrRasterSE lyr) {
271
                this.lyr = lyr;
272
                loadTransform(lyr.getAffineTransform());
273
        }
274

    
275
        /**
276
         * Carga los par?metros en el dialogo a partir de la capa
277
         * @param lyr Capa raster
278
         */
279
        public void loadTransform(AffineTransform at) {
280
                listener.setEnableValueChangeEvent(false);
281
                setUlx(String.valueOf(MathUtils.format(at.getTranslateX(), tailValue)));
282
                setUly(String.valueOf(MathUtils.format(at.getTranslateY(), tailValue)));
283
                setPsx(String.valueOf(MathUtils.format(at.getScaleX(), tailValue)));
284
                setPsy(String.valueOf(MathUtils.format(at.getScaleY(), tailValue)));
285
                setRotx(String.valueOf(MathUtils.format(at.getShearX(), tailValue)));
286
                setRoty(String.valueOf(MathUtils.format(at.getShearY(), tailValue)));
287
                listener.setEnableValueChangeEvent(true);
288
        }
289
        
290
        /**
291
         * Asigna el tama?o de pixel en X
292
         * @param psx
293
         */
294
        public void setPsx(String psx) {
295
                this.psx.setValue(psx);
296
        }
297

    
298
        /**
299
         * Asigna el tama?o de pixel en Y
300
         * @param psy
301
         */
302
        public void setPsy(String psy) {
303
                this.psy.setValue(psy);
304
        }
305

    
306
        /**
307
         * Asigna la rotaci?n en X
308
         * @param rotx
309
         */
310
        public void setRotx(String rotx) {
311
                this.rotx.setValue(rotx);
312
        }
313

    
314
        /**
315
         * Asigna la rotaci?n en Y
316
         * @param roty
317
         */
318
        public void setRoty(String roty) {
319
                this.roty.setValue(roty);
320
        }
321

    
322
        /**
323
         * Asigna la coordenada superior izquierda
324
         * @param ulx 
325
         */
326
        public void setUlx(String ulx) {
327
                this.ulx.setValue(ulx);
328
        }
329

    
330
        /**
331
         * Asigna la coordenada superior derecha
332
         * @param ulx 
333
         */
334
        public void setUly(String uly) {
335
                this.uly.setValue(uly);
336
        }
337

    
338
        /**
339
         * Obtiene el bot?n de aplicar
340
         * @return JButton
341
         */
342
        public JButton getApplyButton() {
343
                return apply;
344
        }
345

    
346
        /**
347
         * Obtiene el bot?n de atr?s
348
         * @return JButton
349
         */
350
        public JButton getBackButton() {
351
                return back;
352
        }
353

    
354
        /**
355
         * Obtiene el bot?n de ir a la primera transformaci?n
356
         * @return JButton
357
         */
358
        public JButton getFirstButton() {
359
                return first;
360
        }
361

    
362
        /**
363
     * Obtiene el bot?n de salvar
364
         * @return JButton
365
         */
366
        public JButton getSaveButton() {
367
                return save;
368
        }
369
        
370
        /**
371
     * Obtiene el bot?n de reset
372
         * @return JButton
373
         */
374
        public JButton getResetButton() {
375
                return reset;
376
        }
377
        
378
        /**
379
         * Obtiene el bot?n de siguiente transformaci?n
380
         * @return JButton
381
         */
382
        public JButton getNextButton() {
383
                return next;
384
        }
385

    
386
        /**
387
         * Obtiene el tama?o de pixel en X
388
         * @return
389
         */
390
        public DataInputContainer getPsx() {
391
                return psx;
392
        }
393

    
394
        /**
395
         * Obtiene el tama?o de pixel en Y
396
         * @return
397
         */
398
        public DataInputContainer getPsy() {
399
                return psy;
400
        }
401

    
402
        /**
403
         * Obtiene la rotaci?n en X
404
         * @return
405
         */
406
        public DataInputContainer getRotx() {
407
                return rotx;
408
        }
409

    
410
        /**
411
         * Obtiene la rotaci?n en Y
412
         * @return
413
         */
414
        public DataInputContainer getRoty() {
415
                return roty;
416
        }
417

    
418
        /**
419
         * Obtiene la X de la coordenada superior izquierda
420
         * @return
421
         */
422
        public DataInputContainer getUlx() {
423
                return ulx;
424
        }
425

    
426
        /**
427
         * Obtiene la Y de la coordenada superior izquierda
428
         * @return
429
         */
430
        public DataInputContainer getUly() {
431
                return uly;
432
        }
433
        
434
        /**
435
         * Asigna el flag que dice si se ha modificado la georreferenciaci?n
436
         * y a?n no se ha salvado
437
         * @return true si se ha modificado y false si no se ha hecho
438
         */
439
        public void setModify(boolean modif) {
440
                geolocModify = modif;
441
        }
442
        
443
        /**
444
         * Obtiene el flag que dice si se ha modificado la georreferenciaci?n
445
         * y a?n no se ha salvado
446
         * @return true si se ha modificado y false si no se ha hecho
447
         */
448
        public boolean getModify() {
449
                return geolocModify;
450
        }
451
        
452
        /**
453
         * Obtiene el historico de transformaciones
454
         * @return Historical
455
         */
456
        public Historical getHistorical() {
457
                return lyr.getAffineTransformHistorical();
458
        }
459
}