gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / geolocation / ui / GeoLocationOpeningRasterCornersPanel.java @ 2818
History | View | Annotate | Download (8.28 KB)
1 | 2480 | nbrodin | /* 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.geolocation.ui; |
||
23 | |||
24 | import java.awt.BorderLayout; |
||
25 | import java.awt.GridBagConstraints; |
||
26 | import java.awt.GridBagLayout; |
||
27 | import java.awt.GridLayout; |
||
28 | import java.awt.geom.AffineTransform; |
||
29 | |||
30 | import javax.swing.ImageIcon; |
||
31 | import javax.swing.JLabel; |
||
32 | import javax.swing.JPanel; |
||
33 | |||
34 | import org.gvsig.andami.PluginServices; |
||
35 | import org.gvsig.fmap.dal.coverage.RasterLocator; |
||
36 | import org.gvsig.fmap.dal.coverage.util.MathUtils; |
||
37 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
38 | import org.gvsig.gui.beans.datainput.DataInputContainer; |
||
39 | import org.gvsig.raster.fmap.layers.FLyrRaster; |
||
40 | import org.gvsig.raster.tools.app.basic.tool.geolocation.listener.GeoLocationPanelListener; |
||
41 | |||
42 | |||
43 | /**
|
||
44 | * Panel de geolocalizaci?n. Este muestra las esquinas superior derecha e
|
||
45 | * inferior izquierda.
|
||
46 | *
|
||
47 | * @version 12/12/2007
|
||
48 | * @author Nacho Brodin (nachobrodin@gmail.com)
|
||
49 | *
|
||
50 | */
|
||
51 | public class GeoLocationOpeningRasterCornersPanel extends GeolocationBaseClassPanel { |
||
52 | private static final long serialVersionUID = -7797379892312214949L; |
||
53 | private DataInputContainer ulx = null; |
||
54 | private DataInputContainer uly = null; |
||
55 | private DataInputContainer lrx = null; |
||
56 | private DataInputContainer lry = null; |
||
57 | |||
58 | private JPanel coordsULPanel = null; |
||
59 | private JPanel coordsLRPanel = null; |
||
60 | |||
61 | private String pathToImages = "images/"; |
||
62 | |||
63 | |||
64 | /**
|
||
65 | * Constructor
|
||
66 | */
|
||
67 | public GeoLocationOpeningRasterCornersPanel(GeoLocationPanelListener list) {
|
||
68 | this.listener = list;
|
||
69 | GridBagLayout gl = new GridBagLayout(); |
||
70 | this.setLayout(gl);
|
||
71 | setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this, "geolocation"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
||
72 | ulx = new DataInputContainer();
|
||
73 | ulx.setLabelText(PluginServices.getText(this,"ux")); |
||
74 | ulx.addValueChangedListener(listener); |
||
75 | ulx.addKeyListener(listener); |
||
76 | |||
77 | uly = new DataInputContainer();
|
||
78 | uly.setLabelText(PluginServices.getText(this,"uy")); |
||
79 | uly.addValueChangedListener(listener); |
||
80 | uly.addKeyListener(listener); |
||
81 | |||
82 | lrx = new DataInputContainer();
|
||
83 | lrx.setLabelText(PluginServices.getText(this,"ux")); |
||
84 | lrx.addValueChangedListener(listener); |
||
85 | lrx.addKeyListener(listener); |
||
86 | |||
87 | lry = new DataInputContainer();
|
||
88 | lry.setLabelText(PluginServices.getText(this,"uy")); |
||
89 | lry.addValueChangedListener(listener); |
||
90 | lry.addKeyListener(listener); |
||
91 | |||
92 | GridLayout l = new GridLayout(2, 1); |
||
93 | l.setVgap(2);
|
||
94 | |||
95 | coordsULPanel = new JPanel(l); |
||
96 | coordsLRPanel = new JPanel(l); |
||
97 | |||
98 | init(); |
||
99 | } |
||
100 | |||
101 | /**
|
||
102 | * Inicializaci?n de los componentes gr?ficos del panel.
|
||
103 | */
|
||
104 | private void init() { |
||
105 | JPanel p1 = new JPanel(new BorderLayout()); |
||
106 | p1.add(getIcoUL(), BorderLayout.WEST);
|
||
107 | p1.add(ulx, BorderLayout.CENTER);
|
||
108 | |||
109 | JPanel p2 = new JPanel(new BorderLayout()); |
||
110 | p2.add(getIcoUL(), BorderLayout.WEST);
|
||
111 | p2.add(uly, BorderLayout.CENTER);
|
||
112 | |||
113 | coordsULPanel.add(p1); |
||
114 | coordsULPanel.add(p2); |
||
115 | |||
116 | JPanel p3 = new JPanel(new BorderLayout()); |
||
117 | p3.add(getIcoLR(), BorderLayout.WEST);
|
||
118 | p3.add(lrx, BorderLayout.CENTER);
|
||
119 | |||
120 | JPanel p4 = new JPanel(new BorderLayout()); |
||
121 | p4.add(getIcoLR(), BorderLayout.WEST);
|
||
122 | p4.add(lry, BorderLayout.CENTER);
|
||
123 | |||
124 | coordsLRPanel.add(p3); |
||
125 | coordsLRPanel.add(p4); |
||
126 | |||
127 | GridBagConstraints gbc = new GridBagConstraints(); |
||
128 | |||
129 | gbc.fill = GridBagConstraints.HORIZONTAL;
|
||
130 | gbc.weightx = 1.0;
|
||
131 | |||
132 | gbc.gridx = 0;
|
||
133 | gbc.gridy = 0;
|
||
134 | gbc.insets = new java.awt.Insets(1, 1, 1, 1); |
||
135 | this.add(coordsULPanel, gbc);
|
||
136 | |||
137 | gbc.gridy = 1;
|
||
138 | this.add(coordsLRPanel, gbc);
|
||
139 | } |
||
140 | |||
141 | /**
|
||
142 | * Asigna la capa raster del raster seleccionado en el TOC en base
|
||
143 | * al cual se asigna la georreferenciaci?n al dialogo.
|
||
144 | * @param lyr
|
||
145 | */
|
||
146 | public void setParams(FLyrRaster lyr, ViewPort vp) { |
||
147 | setLayer(lyr); |
||
148 | setViewPort(vp); |
||
149 | loadTransform(lyr.getAffineTransform()); |
||
150 | } |
||
151 | |||
152 | /**
|
||
153 | * Obtiene el JLabel con el icono de la esquina superior
|
||
154 | * @return JLabel
|
||
155 | */
|
||
156 | private JLabel getIcoUL() { |
||
157 | ImageIcon icon = null; |
||
158 | try {
|
||
159 | icon = new ImageIcon(getClass().getResource(pathToImages + "upleft.png")); |
||
160 | } catch (NullPointerException e) { |
||
161 | |||
162 | } |
||
163 | if(icon != null) |
||
164 | return new JLabel(icon); |
||
165 | else
|
||
166 | return new JLabel("UL"); |
||
167 | } |
||
168 | |||
169 | /**
|
||
170 | * Obtiene el JLabel con el icono de la esquina inferior
|
||
171 | * @return JLabel
|
||
172 | */
|
||
173 | private JLabel getIcoLR() { |
||
174 | ImageIcon icon = null; |
||
175 | try {
|
||
176 | icon = new ImageIcon(getClass().getResource(pathToImages + "downright.png")); |
||
177 | } catch (NullPointerException e) { |
||
178 | |||
179 | } |
||
180 | if(icon != null) |
||
181 | return new JLabel(icon); |
||
182 | else
|
||
183 | return new JLabel("LR"); |
||
184 | } |
||
185 | |||
186 | /**
|
||
187 | * Carga los par?metros en el dialogo a partir de la capa
|
||
188 | * @param lyr Capa raster
|
||
189 | */
|
||
190 | public void loadTransform(AffineTransform at) { |
||
191 | listener.setEnableValueChangeEvent(false);
|
||
192 | MathUtils math = RasterLocator.getManager().getMathUtils(); |
||
193 | setUlx(String.valueOf(math.format(at.getTranslateX(), tailValue)));
|
||
194 | setUly(String.valueOf(math.format(at.getTranslateY(), tailValue)));
|
||
195 | setLrx(String.valueOf(math.format(at.getTranslateX() + (at.getScaleX() * getLayer().getDataStore().getWidth()), tailValue)));
|
||
196 | setLry(String.valueOf(math.format(at.getTranslateY() + (at.getScaleY() * getLayer().getDataStore().getHeight()), tailValue)));
|
||
197 | listener.setEnableValueChangeEvent(true);
|
||
198 | } |
||
199 | |||
200 | /**
|
||
201 | * Asigna la coordenada superior izquierda
|
||
202 | * @param ulx
|
||
203 | */
|
||
204 | public void setUlx(String ulx) { |
||
205 | this.ulx.setValue(ulx);
|
||
206 | } |
||
207 | |||
208 | /**
|
||
209 | * Asigna la coordenada superior derecha
|
||
210 | * @param ulx
|
||
211 | */
|
||
212 | public void setUly(String uly) { |
||
213 | this.uly.setValue(uly);
|
||
214 | } |
||
215 | |||
216 | /**
|
||
217 | * Asigna la coordenada inferior derecha
|
||
218 | * @param lrx
|
||
219 | */
|
||
220 | public void setLrx(String lrx) { |
||
221 | this.lrx.setValue(lrx);
|
||
222 | } |
||
223 | |||
224 | /**
|
||
225 | * Asigna la coordenada superior derecha
|
||
226 | * @param lrx
|
||
227 | */
|
||
228 | public void setLry(String lry) { |
||
229 | this.lry.setValue(lry);
|
||
230 | } |
||
231 | |||
232 | /**
|
||
233 | * Obtiene la X de la coordenada superior izquierda
|
||
234 | * @return
|
||
235 | */
|
||
236 | public DataInputContainer getUlx() {
|
||
237 | return ulx;
|
||
238 | } |
||
239 | |||
240 | /**
|
||
241 | * Obtiene la Y de la coordenada superior izquierda
|
||
242 | * @return
|
||
243 | */
|
||
244 | public DataInputContainer getUly() {
|
||
245 | return uly;
|
||
246 | } |
||
247 | |||
248 | /*
|
||
249 | * (non-Javadoc)
|
||
250 | * @see org.gvsig.rastertools.geolocation.ui.GeolocationBaseClassPanel#getPsx()
|
||
251 | */
|
||
252 | public DataInputContainer getPsx() {
|
||
253 | DataInputContainer d = new DataInputContainer();
|
||
254 | try {
|
||
255 | double dUlx = Double.valueOf(ulx.getValue()).doubleValue(); |
||
256 | double dLrx = Double.valueOf(lrx.getValue()).doubleValue(); |
||
257 | d.setValue(String.valueOf((dLrx - dUlx) / getLayer().getDataStore().getWidth()));
|
||
258 | } catch (NumberFormatException e) { |
||
259 | d.setValue("1");
|
||
260 | } |
||
261 | return d;
|
||
262 | } |
||
263 | |||
264 | /*
|
||
265 | * (non-Javadoc)
|
||
266 | * @see org.gvsig.rastertools.geolocation.ui.GeolocationBaseClassPanel#getPsy()
|
||
267 | */
|
||
268 | public DataInputContainer getPsy() {
|
||
269 | DataInputContainer d = new DataInputContainer();
|
||
270 | try {
|
||
271 | double dUly = Double.valueOf(uly.getValue()).doubleValue(); |
||
272 | double dLry = Double.valueOf(lry.getValue()).doubleValue(); |
||
273 | d.setValue(String.valueOf((dLry - dUly) / getLayer().getDataStore().getHeight()));
|
||
274 | } catch (NumberFormatException e) { |
||
275 | d.setValue("1");
|
||
276 | } |
||
277 | return d;
|
||
278 | } |
||
279 | |||
280 | /*
|
||
281 | * (non-Javadoc)
|
||
282 | * @see org.gvsig.rastertools.geolocation.ui.GeolocationBaseClassPanel#getRotx()
|
||
283 | */
|
||
284 | public DataInputContainer getRotx() {
|
||
285 | DataInputContainer d = new DataInputContainer();
|
||
286 | d.setValue("0");
|
||
287 | return d;
|
||
288 | } |
||
289 | |||
290 | /*
|
||
291 | * (non-Javadoc)
|
||
292 | * @see org.gvsig.rastertools.geolocation.ui.GeolocationBaseClassPanel#getRoty()
|
||
293 | */
|
||
294 | public DataInputContainer getRoty() {
|
||
295 | DataInputContainer d = new DataInputContainer();
|
||
296 | d.setValue("0");
|
||
297 | return d;
|
||
298 | } |
||
299 | |||
300 | } |