Statistics
| Revision:

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

History | View | Annotate | Download (7.82 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.BorderLayout;
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.JLabel;
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.MathUtils;
34
import org.gvsig.rastertools.geolocation.listener.GeoLocationPanelListener;
35

    
36
import com.iver.andami.PluginServices;
37
import com.iver.cit.gvsig.fmap.ViewPort;
38

    
39
/**
40
 * Panel de geolocalizaci?n. Este muestra las esquinas superior derecha e 
41
 * inferior izquierda.
42
 * 
43
 * @version 12/12/2007
44
 * @author Nacho Brodin (nachobrodin@gmail.com)
45
 *
46
 */
47
public class GeoLocationOpeningRasterCornersPanel extends GeolocationBaseClassPanel {
48
        private static final long          serialVersionUID = -7797379892312214949L;
49
        private DataInputContainer               ulx = null;
50
        private DataInputContainer               uly = null;
51
        private DataInputContainer               lrx = null;
52
        private DataInputContainer               lry = null;
53
                
54
        private JPanel                                   coordsULPanel = null;
55
        private JPanel                                   coordsLRPanel = null;
56

    
57
        private GeoLocationPanelListener   listener = null;
58
        
59
        private String                     pathToImages = "images/";
60

    
61
        
62
        /**
63
         * Constructor
64
         */
65
        public GeoLocationOpeningRasterCornersPanel(GeoLocationPanelListener list) {
66
                this.listener = list;
67
                GridBagLayout gl = new GridBagLayout();
68
                this.setLayout(gl);
69
                setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this, "geolocation"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
70
                ulx = new DataInputContainer();
71
                ulx.setLabelText(PluginServices.getText(this,"ux"));
72
                ulx.addValueChangedListener(listener);
73
                ulx.addKeyListener(listener);
74
                
75
                uly = new DataInputContainer();
76
                uly.setLabelText(PluginServices.getText(this,"uy"));
77
                uly.addValueChangedListener(listener);
78
                uly.addKeyListener(listener);
79
                
80
                lrx = new DataInputContainer();
81
                lrx.setLabelText(PluginServices.getText(this,"ux"));
82
                lrx.addValueChangedListener(listener);
83
                lrx.addKeyListener(listener);
84
                                
85
                lry = new DataInputContainer();
86
                lry.setLabelText(PluginServices.getText(this,"uy"));
87
                lry.addValueChangedListener(listener);
88
                lry.addKeyListener(listener);
89
                
90
                GridLayout l = new GridLayout(2, 1);
91
                l.setVgap(2);
92
                
93
                coordsULPanel = new JPanel(l);
94
                coordsLRPanel = new JPanel(l);
95
                
96
                init();
97
        }
98
        
99
        /**
100
         * Inicializaci?n de los componentes gr?ficos del panel.
101
         */
102
        private void init() {                
103
                JPanel p1 = new JPanel(new BorderLayout());
104
                p1.add(getIcoUL(), BorderLayout.WEST);
105
                p1.add(ulx, BorderLayout.CENTER);
106
                
107
                JPanel p2 = new JPanel(new BorderLayout());
108
                p2.add(getIcoUL(), BorderLayout.WEST);
109
                p2.add(uly, BorderLayout.CENTER);
110
                
111
                coordsULPanel.add(p1);
112
                coordsULPanel.add(p2);
113
                
114
                JPanel p3 = new JPanel(new BorderLayout());
115
                p3.add(getIcoLR(), BorderLayout.WEST);
116
                p3.add(lrx, BorderLayout.CENTER);
117
                
118
                JPanel p4 = new JPanel(new BorderLayout());
119
                p4.add(getIcoLR(), BorderLayout.WEST);
120
                p4.add(lry, BorderLayout.CENTER);
121
                
122
                coordsLRPanel.add(p3);
123
                coordsLRPanel.add(p4);
124
                
125
                GridBagConstraints gbc = new GridBagConstraints();
126
                
127
                gbc.fill = GridBagConstraints.HORIZONTAL;
128
                gbc.weightx = 1.0;
129
                
130
                gbc.gridx = 0;
131
                gbc.gridy = 0;
132
                gbc.insets = new java.awt.Insets(1, 1, 1, 1);
133
                this.add(coordsULPanel, gbc);
134
                
135
                gbc.gridy = 1;
136
                this.add(coordsLRPanel, gbc);                
137
        }
138
        
139
        /**
140
         * Asigna la capa raster del raster seleccionado en el TOC en base 
141
         * al cual se asigna la georreferenciaci?n al dialogo.
142
         * @param lyr
143
         */
144
        public void setParams(FLyrRasterSE lyr, ViewPort vp) {
145
                setLayer(lyr);
146
                setViewPort(vp);
147
                loadTransform(lyr.getAffineTransform());
148
        }
149
        
150
        /**
151
         * Obtiene el JLabel con el icono de la esquina superior
152
         * @return JLabel
153
         */
154
        private JLabel getIcoUL(){
155
                return new JLabel(new ImageIcon(getClass().getResource(pathToImages + "upleft.png")));
156
        }
157

    
158
        /**
159
         * Obtiene el JLabel con el icono de la esquina inferior
160
         * @return JLabel
161
         */
162
        private JLabel getIcoLR(){
163
                return new JLabel(new ImageIcon(getClass().getResource(pathToImages + "downright.png")));
164
        }
165
        
166
        /**
167
         * Carga los par?metros en el dialogo a partir de la capa
168
         * @param lyr Capa raster
169
         */
170
        public void loadTransform(AffineTransform at) {
171
                listener.setEnableValueChangeEvent(false);
172
                setUlx(String.valueOf(MathUtils.format(at.getTranslateX(), tailValue)));
173
                setUly(String.valueOf(MathUtils.format(at.getTranslateY(), tailValue)));
174
                setLrx(String.valueOf(MathUtils.format(at.getTranslateX() + (at.getScaleX() * getLayer().getPxWidth()), tailValue)));
175
                setLry(String.valueOf(MathUtils.format(at.getTranslateY() + (at.getScaleY()  * getLayer().getPxHeight()), tailValue)));                
176
                listener.setEnableValueChangeEvent(true);
177
        }
178

    
179
        /**
180
         * Asigna la coordenada superior izquierda
181
         * @param ulx 
182
         */
183
        public void setUlx(String ulx) {
184
                this.ulx.setValue(ulx);
185
        }
186

    
187
        /**
188
         * Asigna la coordenada superior derecha
189
         * @param ulx 
190
         */
191
        public void setUly(String uly) {
192
                this.uly.setValue(uly);
193
        }
194
        
195
        /**
196
         * Asigna la coordenada inferior derecha
197
         * @param lrx
198
         */
199
        public void setLrx(String lrx) {
200
                this.lrx.setValue(lrx);
201
        }
202

    
203
        /**
204
         * Asigna la coordenada superior derecha
205
         * @param lrx 
206
         */
207
        public void setLry(String lry) {
208
                this.lry.setValue(lry);
209
        }
210
        
211
        /**
212
         * Obtiene la X de la coordenada superior izquierda
213
         * @return
214
         */
215
        public DataInputContainer getUlx() {
216
                return ulx;
217
        }
218

    
219
        /**
220
         * Obtiene la Y de la coordenada superior izquierda
221
         * @return
222
         */
223
        public DataInputContainer getUly() {
224
                return uly;
225
        }
226

    
227
        /*
228
         * (non-Javadoc)
229
         * @see org.gvsig.rastertools.geolocation.ui.GeolocationBaseClassPanel#getPsx()
230
         */
231
        public DataInputContainer getPsx() {
232
                DataInputContainer d = new DataInputContainer();
233
                try {
234
                        double dUlx = Double.valueOf(ulx.getValue()).doubleValue();
235
                        double dLrx = Double.valueOf(lrx.getValue()).doubleValue();
236
                        d.setValue(String.valueOf((dLrx - dUlx) / getLayer().getPxWidth()));
237
                } catch (NumberFormatException e) {
238
                        d.setValue("1");
239
                }
240
                return d;
241
        }
242

    
243
        /*
244
         * (non-Javadoc)
245
         * @see org.gvsig.rastertools.geolocation.ui.GeolocationBaseClassPanel#getPsy()
246
         */
247
        public DataInputContainer getPsy() {
248
                DataInputContainer d = new DataInputContainer();
249
                try {
250
                        double dUly = Double.valueOf(uly.getValue()).doubleValue();
251
                        double dLry = Double.valueOf(lry.getValue()).doubleValue();
252
                        d.setValue(String.valueOf((dLry - dUly) / getLayer().getPxHeight()));
253
                } catch (NumberFormatException e) {
254
                        d.setValue("1");
255
                }
256
                return d;
257
        }
258

    
259
        /*
260
         * (non-Javadoc)
261
         * @see org.gvsig.rastertools.geolocation.ui.GeolocationBaseClassPanel#getRotx()
262
         */
263
        public DataInputContainer getRotx() {
264
                DataInputContainer d = new DataInputContainer();
265
                d.setValue("0");
266
                return d;
267
        }
268

    
269
        /*
270
         * (non-Javadoc)
271
         * @see org.gvsig.rastertools.geolocation.ui.GeolocationBaseClassPanel#getRoty()
272
         */
273
        public DataInputContainer getRoty() {
274
                DataInputContainer d = new DataInputContainer();
275
                d.setValue("0");
276
                return d;
277
        }
278

    
279
}