svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / geolocation / ui / GeoLocationPanel.java @ 14135
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.FlowLayout; |
23 |
import java.awt.GridBagConstraints; |
24 |
import java.awt.GridBagLayout; |
25 |
import java.awt.GridLayout; |
26 |
import java.awt.geom.AffineTransform; |
27 |
|
28 |
import javax.swing.ImageIcon; |
29 |
import javax.swing.JButton; |
30 |
import javax.swing.JPanel; |
31 |
|
32 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
33 |
import org.gvsig.gui.beans.datainput.DataInputContainer; |
34 |
import org.gvsig.raster.util.Historical; |
35 |
import org.gvsig.raster.util.MathUtils; |
36 |
import org.gvsig.rastertools.geolocation.listener.GeoLocationPanelListener; |
37 |
|
38 |
import com.iver.andami.PluginServices; |
39 |
import com.iver.cit.gvsig.fmap.MapControl; |
40 |
|
41 |
/**
|
42 |
* Panel de geolocalizaci?n. Este muestra los par?metros de la matriz de transformaci?n
|
43 |
* que est? aplicandose en esos momentos al raster. Los par?metros son variados en
|
44 |
* tiempo real a medida que modificamos la georreferenciaci?n con las herramientas.
|
45 |
*
|
46 |
* @version 30/07/2007
|
47 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
48 |
*
|
49 |
*/
|
50 |
public class GeoLocationPanel extends JPanel { |
51 |
private static final long serialVersionUID = -7797379892312214949L; |
52 |
private DataInputContainer ulx = null; |
53 |
private DataInputContainer uly = null; |
54 |
private DataInputContainer psx = null; |
55 |
private DataInputContainer psy = null; |
56 |
private DataInputContainer rotx = null; |
57 |
private DataInputContainer roty = null; |
58 |
private JButton first = null; |
59 |
private JButton save = null; |
60 |
private JButton back = null; |
61 |
private JButton next = null; |
62 |
private JButton apply = null; |
63 |
private JButton reset = null; |
64 |
|
65 |
private JPanel coordsPanel = null; |
66 |
private JPanel paramsPanel = null; |
67 |
private JPanel buttonsPanel = null; |
68 |
private GeoLocationPanelListener listener = null; |
69 |
private FLyrRasterSE lyr = null; |
70 |
/**
|
71 |
* N?mero de decimales a mostrar
|
72 |
*/
|
73 |
private int tailValue = 2; |
74 |
private MapControl mapCtrl = null; |
75 |
private boolean geolocModify = false; |
76 |
|
77 |
/**
|
78 |
* Constructor
|
79 |
*/
|
80 |
public GeoLocationPanel() {
|
81 |
ImageIcon backIcon = null; |
82 |
ImageIcon nextIcon = null; |
83 |
ImageIcon saveIcon = null; |
84 |
ImageIcon firstIcon = null; |
85 |
ImageIcon resetIcon = null; |
86 |
try {
|
87 |
backIcon = new ImageIcon(getClass().getClassLoader().getResource("images/back.png")); |
88 |
nextIcon = new ImageIcon(getClass().getClassLoader().getResource("images/next.png")); |
89 |
saveIcon = new ImageIcon(getClass().getClassLoader().getResource("images/save.png")); |
90 |
firstIcon = new ImageIcon(getClass().getClassLoader().getResource("images/undo.png")); |
91 |
resetIcon = new ImageIcon(getClass().getClassLoader().getResource("images/reset.png")); |
92 |
} catch(NullPointerException e) { |
93 |
|
94 |
} |
95 |
|
96 |
listener = new GeoLocationPanelListener(this); |
97 |
|
98 |
GridBagLayout gl = new GridBagLayout(); |
99 |
this.setLayout(gl);
|
100 |
setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this, "geolocation"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
101 |
ulx = new DataInputContainer();
|
102 |
ulx.setLabelText(PluginServices.getText(this,"ux")); |
103 |
uly = new DataInputContainer();
|
104 |
uly.setLabelText(PluginServices.getText(this,"uy")); |
105 |
psx = new DataInputContainer();
|
106 |
psx.setLabelText(PluginServices.getText(this,"px")); |
107 |
psy = new DataInputContainer();
|
108 |
psy.setLabelText(PluginServices.getText(this,"py")); |
109 |
rotx = new DataInputContainer();
|
110 |
rotx.setLabelText(PluginServices.getText(this,"rx")); |
111 |
roty = new DataInputContainer();
|
112 |
roty.setLabelText(PluginServices.getText(this,"ry")); |
113 |
|
114 |
first = new JButton(firstIcon); |
115 |
save = new JButton(saveIcon); |
116 |
back = new JButton(backIcon); |
117 |
next = new JButton(nextIcon); |
118 |
apply = new JButton(PluginServices.getText(this,"apply")); |
119 |
reset = new JButton(resetIcon); |
120 |
|
121 |
save.setToolTipText(PluginServices.getText(this,"salvar_transf")); |
122 |
back.setToolTipText(PluginServices.getText(this,"back_transf")); |
123 |
next.setToolTipText(PluginServices.getText(this,"next_transf")); |
124 |
apply.setToolTipText(PluginServices.getText(this,"aplicar_transf")); |
125 |
first.setToolTipText(PluginServices.getText(this,"first_transf")); |
126 |
reset.setToolTipText(PluginServices.getText(this,"reset_transf")); |
127 |
|
128 |
save.setPreferredSize(new Dimension(28, 24)); |
129 |
first.setPreferredSize(new Dimension(28, 24)); |
130 |
back.setPreferredSize(new Dimension(28, 24)); |
131 |
next.setPreferredSize(new Dimension(28, 24)); |
132 |
apply.setPreferredSize(new Dimension(64,24)); |
133 |
reset.setPreferredSize(new Dimension(28,24)); |
134 |
|
135 |
first.addActionListener(listener); |
136 |
save.addActionListener(listener); |
137 |
back.addActionListener(listener); |
138 |
next.addActionListener(listener); |
139 |
apply.addActionListener(listener); |
140 |
reset.addActionListener(listener); |
141 |
|
142 |
save.setEnabled(false);
|
143 |
back.setEnabled(false);
|
144 |
next.setEnabled(false);
|
145 |
first.setEnabled(false);
|
146 |
reset.setEnabled(true);
|
147 |
|
148 |
coordsPanel = new JPanel(); |
149 |
GridLayout l = new GridLayout(2, 1); |
150 |
l.setVgap(2);
|
151 |
coordsPanel.setLayout(l); |
152 |
|
153 |
paramsPanel = new JPanel(); |
154 |
GridLayout l1 = new GridLayout(2, 2); |
155 |
l1.setVgap(2);
|
156 |
paramsPanel.setLayout(l1); |
157 |
|
158 |
buttonsPanel = new JPanel(); |
159 |
FlowLayout ly = new FlowLayout(); |
160 |
ly.setVgap(0);
|
161 |
ly.setAlignment(FlowLayout.RIGHT);
|
162 |
buttonsPanel.setLayout(ly); |
163 |
|
164 |
init(); |
165 |
} |
166 |
|
167 |
private void init() { |
168 |
coordsPanel.add(ulx); |
169 |
coordsPanel.add(uly); |
170 |
paramsPanel.add(psx); |
171 |
paramsPanel.add(psy); |
172 |
paramsPanel.add(rotx); |
173 |
paramsPanel.add(roty); |
174 |
buttonsPanel.add(reset); |
175 |
buttonsPanel.add(back); |
176 |
buttonsPanel.add(next); |
177 |
buttonsPanel.add(first); |
178 |
buttonsPanel.add(save); |
179 |
buttonsPanel.add(apply); |
180 |
|
181 |
|
182 |
GridBagConstraints gbc = new GridBagConstraints(); |
183 |
gbc.gridx = 0;
|
184 |
gbc.gridy = 0;
|
185 |
gbc.fill = java.awt.GridBagConstraints.HORIZONTAL; |
186 |
gbc.weightx = 1.0;
|
187 |
gbc.insets = new java.awt.Insets(1, 1, 1, 1); |
188 |
GridBagConstraints gbc1 = new GridBagConstraints(); |
189 |
gbc1.gridx = 0;
|
190 |
gbc1.gridy = 1;
|
191 |
gbc1.fill = java.awt.GridBagConstraints.HORIZONTAL; |
192 |
gbc1.weightx = 1.0;
|
193 |
gbc1.insets = new java.awt.Insets(1, 1, 1, 1); |
194 |
GridBagConstraints gbc2 = new GridBagConstraints(); |
195 |
gbc2.gridx = 0;
|
196 |
gbc2.gridy = 2;
|
197 |
gbc2.fill = java.awt.GridBagConstraints.HORIZONTAL; |
198 |
gbc2.weightx = 1.0;
|
199 |
gbc2.insets = new java.awt.Insets(1, 1, 1, 1); |
200 |
this.add(coordsPanel, gbc);
|
201 |
this.add(paramsPanel, gbc1);
|
202 |
this.add(buttonsPanel, gbc2);
|
203 |
} |
204 |
|
205 |
/**
|
206 |
* Activa o desactiva los botones de transformaci?n anterior y siguiente dependiendo
|
207 |
* del estado de la lista de transformaciones.
|
208 |
* @return
|
209 |
*/
|
210 |
public void activeButtons() { |
211 |
Historical affineTransformHist = lyr.getAffineTransformHistorical(); |
212 |
if(!affineTransformHist.existNext())
|
213 |
next.setEnabled(false);
|
214 |
else
|
215 |
next.setEnabled(true);
|
216 |
if(!affineTransformHist.existBack())
|
217 |
back.setEnabled(false);
|
218 |
else
|
219 |
back.setEnabled(true);
|
220 |
if(affineTransformHist.getElementsCount() <= 1) |
221 |
first.setEnabled(false);
|
222 |
else
|
223 |
first.setEnabled(true);
|
224 |
if(affineTransformHist.getElementsCount() == 0) |
225 |
save.setEnabled(false);
|
226 |
else
|
227 |
save.setEnabled(true);
|
228 |
} |
229 |
|
230 |
/**
|
231 |
* Obtiene el MapControl
|
232 |
* @return MapControl
|
233 |
*/
|
234 |
public MapControl getMapCtrl() {
|
235 |
return mapCtrl;
|
236 |
} |
237 |
|
238 |
/**
|
239 |
* Asigna el MapControl
|
240 |
* @param mapCtrl
|
241 |
*/
|
242 |
public void setMapCtrl(MapControl mapCtrl) { |
243 |
this.mapCtrl = mapCtrl;
|
244 |
} |
245 |
|
246 |
/**
|
247 |
* Obtiene la capa raster asociada
|
248 |
* @return
|
249 |
*/
|
250 |
public FLyrRasterSE getLayer() {
|
251 |
return this.lyr; |
252 |
} |
253 |
|
254 |
/**
|
255 |
* Asigna la capa raster del raster seleccionado en el TOC en base
|
256 |
* al cual se asigna la georreferenciaci?n al dialogo.
|
257 |
* @param lyr
|
258 |
*/
|
259 |
public void setLayer(FLyrRasterSE lyr) { |
260 |
this.lyr = lyr;
|
261 |
loadTransform(lyr.getAffineTransform()); |
262 |
} |
263 |
|
264 |
/**
|
265 |
* Carga los par?metros en el dialogo a partir de la capa
|
266 |
* @param lyr Capa raster
|
267 |
*/
|
268 |
public void loadTransform(AffineTransform at) { |
269 |
setUlx(String.valueOf(MathUtils.format(at.getTranslateX(), tailValue)));
|
270 |
setUly(String.valueOf(MathUtils.format(at.getTranslateY(), tailValue)));
|
271 |
setPsx(String.valueOf(MathUtils.format(at.getScaleX(), tailValue)));
|
272 |
setPsy(String.valueOf(MathUtils.format(at.getScaleY(), tailValue)));
|
273 |
setRotx(String.valueOf(MathUtils.format(at.getShearX(), tailValue)));
|
274 |
setRoty(String.valueOf(MathUtils.format(at.getShearY(), tailValue)));
|
275 |
} |
276 |
|
277 |
/**
|
278 |
* Asigna el tama?o de pixel en X
|
279 |
* @param psx
|
280 |
*/
|
281 |
public void setPsx(String psx) { |
282 |
this.psx.setValue(psx);
|
283 |
} |
284 |
|
285 |
/**
|
286 |
* Asigna el tama?o de pixel en Y
|
287 |
* @param psy
|
288 |
*/
|
289 |
public void setPsy(String psy) { |
290 |
this.psy.setValue(psy);
|
291 |
} |
292 |
|
293 |
/**
|
294 |
* Asigna la rotaci?n en X
|
295 |
* @param rotx
|
296 |
*/
|
297 |
public void setRotx(String rotx) { |
298 |
this.rotx.setValue(rotx);
|
299 |
} |
300 |
|
301 |
/**
|
302 |
* Asigna la rotaci?n en Y
|
303 |
* @param roty
|
304 |
*/
|
305 |
public void setRoty(String roty) { |
306 |
this.roty.setValue(roty);
|
307 |
} |
308 |
|
309 |
/**
|
310 |
* Asigna la coordenada superior izquierda
|
311 |
* @param ulx
|
312 |
*/
|
313 |
public void setUlx(String ulx) { |
314 |
this.ulx.setValue(ulx);
|
315 |
} |
316 |
|
317 |
/**
|
318 |
* Asigna la coordenada superior derecha
|
319 |
* @param ulx
|
320 |
*/
|
321 |
public void setUly(String uly) { |
322 |
this.uly.setValue(uly);
|
323 |
} |
324 |
|
325 |
/**
|
326 |
* Obtiene el bot?n de aplicar
|
327 |
* @return JButton
|
328 |
*/
|
329 |
public JButton getApplyButton() { |
330 |
return apply;
|
331 |
} |
332 |
|
333 |
/**
|
334 |
* Obtiene el bot?n de atr?s
|
335 |
* @return JButton
|
336 |
*/
|
337 |
public JButton getBackButton() { |
338 |
return back;
|
339 |
} |
340 |
|
341 |
/**
|
342 |
* Obtiene el bot?n de ir a la primera transformaci?n
|
343 |
* @return JButton
|
344 |
*/
|
345 |
public JButton getFirstButton() { |
346 |
return first;
|
347 |
} |
348 |
|
349 |
/**
|
350 |
* Obtiene el bot?n de salvar
|
351 |
* @return JButton
|
352 |
*/
|
353 |
public JButton getSaveButton() { |
354 |
return save;
|
355 |
} |
356 |
|
357 |
/**
|
358 |
* Obtiene el bot?n de reset
|
359 |
* @return JButton
|
360 |
*/
|
361 |
public JButton getResetButton() { |
362 |
return reset;
|
363 |
} |
364 |
|
365 |
/**
|
366 |
* Obtiene el bot?n de siguiente transformaci?n
|
367 |
* @return JButton
|
368 |
*/
|
369 |
public JButton getNextButton() { |
370 |
return next;
|
371 |
} |
372 |
|
373 |
/**
|
374 |
* Obtiene el tama?o de pixel en X
|
375 |
* @return
|
376 |
*/
|
377 |
public DataInputContainer getPsx() {
|
378 |
return psx;
|
379 |
} |
380 |
|
381 |
/**
|
382 |
* Obtiene el tama?o de pixel en Y
|
383 |
* @return
|
384 |
*/
|
385 |
public DataInputContainer getPsy() {
|
386 |
return psy;
|
387 |
} |
388 |
|
389 |
/**
|
390 |
* Obtiene la rotaci?n en X
|
391 |
* @return
|
392 |
*/
|
393 |
public DataInputContainer getRotx() {
|
394 |
return rotx;
|
395 |
} |
396 |
|
397 |
/**
|
398 |
* Obtiene la rotaci?n en Y
|
399 |
* @return
|
400 |
*/
|
401 |
public DataInputContainer getRoty() {
|
402 |
return roty;
|
403 |
} |
404 |
|
405 |
/**
|
406 |
* Obtiene la X de la coordenada superior izquierda
|
407 |
* @return
|
408 |
*/
|
409 |
public DataInputContainer getUlx() {
|
410 |
return ulx;
|
411 |
} |
412 |
|
413 |
/**
|
414 |
* Obtiene la Y de la coordenada superior izquierda
|
415 |
* @return
|
416 |
*/
|
417 |
public DataInputContainer getUly() {
|
418 |
return uly;
|
419 |
} |
420 |
|
421 |
/**
|
422 |
* Asigna el flag que dice si se ha modificado la georreferenciaci?n
|
423 |
* y a?n no se ha salvado
|
424 |
* @return true si se ha modificado y false si no se ha hecho
|
425 |
*/
|
426 |
public void setModify(boolean modif) { |
427 |
geolocModify = modif; |
428 |
} |
429 |
|
430 |
/**
|
431 |
* Obtiene el flag que dice si se ha modificado la georreferenciaci?n
|
432 |
* y a?n no se ha salvado
|
433 |
* @return true si se ha modificado y false si no se ha hecho
|
434 |
*/
|
435 |
public boolean getModify() { |
436 |
return geolocModify;
|
437 |
} |
438 |
|
439 |
/**
|
440 |
* Obtiene el historico de transformaciones
|
441 |
* @return Historical
|
442 |
*/
|
443 |
public Historical getHistorical() {
|
444 |
return lyr.getAffineTransformHistorical();
|
445 |
} |
446 |
|
447 |
} |