root / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / view / ViewDialog.java @ 18530
History | View | Annotate | Download (9.41 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.georeferencing.view; |
20 |
|
21 |
import java.awt.BorderLayout; |
22 |
import java.awt.geom.Point2D; |
23 |
import java.awt.geom.Rectangle2D; |
24 |
import java.awt.image.BufferedImage; |
25 |
|
26 |
import org.gvsig.georeferencing.ui.zoom.IExtensionRequest; |
27 |
import org.gvsig.georeferencing.ui.zoom.IGraphicLayer; |
28 |
import org.gvsig.georeferencing.ui.zoom.ViewControl; |
29 |
import org.gvsig.georeferencing.ui.zoom.ViewListener; |
30 |
import org.gvsig.georeferencing.ui.zoom.layers.ZoomCursorGraphicLayer; |
31 |
import org.gvsig.georeferencing.ui.zoom.tools.ToolListener; |
32 |
|
33 |
import com.iver.andami.PluginServices; |
34 |
import com.iver.andami.ui.mdiManager.IWindow; |
35 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
36 |
|
37 |
/**
|
38 |
* Panel que contiene el panel con la vista a georreferenciar
|
39 |
*
|
40 |
* 22/12/2007
|
41 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
42 |
*/
|
43 |
public class ViewDialog extends BaseZoomView implements IWindow { |
44 |
private static final long serialVersionUID = 1L; |
45 |
private ZoomCursorGraphicLayer zoomCursorGraphic = null; |
46 |
private ToolListener zoomCursorGraphicListener = null; |
47 |
private int w = 640; |
48 |
private int h = 100; |
49 |
private int posX = 0; |
50 |
private int posY = 0; |
51 |
|
52 |
/**
|
53 |
* Constructor.
|
54 |
* Crea la composici?n de controles de zoom.
|
55 |
* @param posX Posici?n en X
|
56 |
* @param posY Posici?n en Y
|
57 |
* @param w Tama?o en pixeles de ancho
|
58 |
* @param h Tama?o en pixeles de alto
|
59 |
*/
|
60 |
public ViewDialog(int posX, int posY, int w, int h, ToolListener zoomCursorGraphicListener) { |
61 |
setPosition(posX, posY); |
62 |
setWindowsSize(w, h); |
63 |
this.zoomCursorGraphicListener = zoomCursorGraphicListener;
|
64 |
init(); |
65 |
} |
66 |
|
67 |
/**
|
68 |
* Asigna el listener de eventos de la vista
|
69 |
* @param listener
|
70 |
*/
|
71 |
public void setViewListener(ViewListener listener) { |
72 |
getControl().setViewListener(listener); |
73 |
} |
74 |
|
75 |
/**
|
76 |
* Asigna la posici?n de la ventana
|
77 |
* @param posX Posici?n en X
|
78 |
* @param posY Posici?n en Y
|
79 |
*/
|
80 |
public void setPosition(int posX, int posY) { |
81 |
this.posX = posX;
|
82 |
this.posY = posY;
|
83 |
} |
84 |
|
85 |
/**
|
86 |
* Asigna el tama?o de la ventana
|
87 |
* @param w Tama?o en pixeles de ancho
|
88 |
* @param h Tama?o en pixeles de alto
|
89 |
*/
|
90 |
public void setWindowsSize(int w, int h) { |
91 |
this.w = w;
|
92 |
this.h = h;
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* Asigna el valor para el flag minxMaxyUL. Este flag informa de que la esquina
|
97 |
* superior izquierda corresponde con el valor de m?nimo X y m?ximo Y. En caso
|
98 |
* de ser false esta esquina ser?a de m?nimo X y m?nimo Y.
|
99 |
* @param v
|
100 |
*/
|
101 |
public void setMinxMaxyUL(boolean v) { |
102 |
getCanvas().setMinxMaxyUL(v); |
103 |
} |
104 |
|
105 |
/**
|
106 |
* Asigna un nuevo centro de visualizaci?n. Vuelve a realizar la petici?n
|
107 |
* @param center
|
108 |
*/
|
109 |
public void setCenter(Point2D center) { |
110 |
//TODO: Calcular las coordenadas del cursor gr?fico
|
111 |
getControl().setCenter(center); |
112 |
} |
113 |
|
114 |
/**
|
115 |
* Inicializaci?n de los componentes gr?ficos
|
116 |
*/
|
117 |
private void init() { |
118 |
setLayout(new BorderLayout()); |
119 |
add(getControl(), BorderLayout.CENTER);
|
120 |
getZoomCursorGraphicLayer(); |
121 |
} |
122 |
|
123 |
/**
|
124 |
* Asigna los par?metros de dibujado para el raster
|
125 |
* @param img Buffer con un ?rea de datos
|
126 |
* @param ext Rectangle2D del ?rea de datos dada
|
127 |
* @param pixelSize Tama?o de pixel
|
128 |
* @param center Punto del ?rea de datos donde se quiere centrar el dibujado del buffer
|
129 |
*/
|
130 |
public void setDrawParams(BufferedImage img, Rectangle2D ext, double pixelSize, Point2D center) { |
131 |
getControl().setDrawParams(img, ext, pixelSize, center) ; |
132 |
} |
133 |
|
134 |
/**
|
135 |
* Obtiene el panel de control de zoom de coordenadas pixel
|
136 |
* @return
|
137 |
*/
|
138 |
public ViewControl getControl() {
|
139 |
if(zoomPixelControl == null) |
140 |
zoomPixelControl = new ViewControl(ViewControl.RIGHT_CONTROL);
|
141 |
return zoomPixelControl;
|
142 |
} |
143 |
|
144 |
/**
|
145 |
* Registra un objeto IExtensionRequest para que no se aplique un escalado sobre
|
146 |
* el buffer pasado por par?metro. Alternativamente a la aplicaci?n de este escalado
|
147 |
* se ejecutar? el m?todo request del interfaz para que el cliente pueda pasar un
|
148 |
* nuevo buffer con escala 1:1 y con la extensi?n correspondiente al zoom.
|
149 |
* @param er
|
150 |
*/
|
151 |
public void setExtensionRequest(IExtensionRequest er) { |
152 |
zoomPixelControl.setExtensionRequest(er); |
153 |
} |
154 |
|
155 |
/*
|
156 |
* (non-Javadoc)
|
157 |
* @see org.gvsig.rastertools.georeferencing.view.BaseZoomView#addGraphicLayer(org.gvsig.rastertools.georeferencing.ui.zoom.IGraphicLayer)
|
158 |
*/
|
159 |
public void addGraphicLayer(IGraphicLayer graphicLayer) { |
160 |
getControl().setGraphicLayer(graphicLayer); |
161 |
} |
162 |
|
163 |
/**
|
164 |
* Obtiene el la capa gr?fica con la ventana de zoom
|
165 |
* @return
|
166 |
*/
|
167 |
public ZoomCursorGraphicLayer getZoomCursorGraphicLayer() {
|
168 |
if(zoomCursorGraphic == null) { |
169 |
zoomCursorGraphic = new ZoomCursorGraphicLayer(w / 2, h / 2, 12, 6, zoomCursorGraphicListener); |
170 |
zoomCursorGraphic.setCanvas(getControl().getCanvas()); |
171 |
getControl().setGraphicLayer(zoomCursorGraphic); |
172 |
} |
173 |
return zoomCursorGraphic;
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* Asigna la posici?n del cursor en el canvas
|
178 |
* @param x Posici?n en X
|
179 |
* @param y Posici?n en Y
|
180 |
*/
|
181 |
public void setCursorPosition(int x, int y) { |
182 |
getZoomCursorGraphicLayer().setCursorPosition(x, y); |
183 |
} |
184 |
|
185 |
/**
|
186 |
* Asigna el tama?o del cursor en pixeles del canvas
|
187 |
* @param w Ancho
|
188 |
* @param h Alto
|
189 |
*/
|
190 |
public void setCursorSize(int w, int h) { |
191 |
getZoomCursorGraphicLayer().setCursorSize(w, h); |
192 |
} |
193 |
|
194 |
/**
|
195 |
* Activa o desactiva el mostrado de informaci?n
|
196 |
* @param showInfo
|
197 |
*/
|
198 |
public void setShowInfo(boolean show) { |
199 |
zoomPixelControl.getCanvas().setShowInfo(show); |
200 |
} |
201 |
|
202 |
/**
|
203 |
* Obtiene las coordenadas de la ventana de zoom. Las coordenadas son devueltas
|
204 |
* en referencia a las coordenadas del mundo.
|
205 |
* @return
|
206 |
*/
|
207 |
public Rectangle2D getCursorWorldCoordinates() { |
208 |
Rectangle2D r = getZoomCursorGraphicLayer().getCursorViewCoordinates();
|
209 |
Point2D p1 = zoomPixelControl.getCanvas().viewCoordsToWorld(new Point2D.Double(r.getX(), r.getY())); |
210 |
Point2D p2 = zoomPixelControl.getCanvas().viewCoordsToWorld(new Point2D.Double(r.getX() + r.getWidth(), r.getY() + r.getHeight())); |
211 |
return new Rectangle2D.Double( Math.min(p1.getX(), p2.getX()), |
212 |
Math.max(p1.getY(), p2.getY()),
|
213 |
Math.abs(p2.getX() - p1.getX()),
|
214 |
Math.abs(p2.getY() - p1.getY()));
|
215 |
} |
216 |
|
217 |
/**
|
218 |
* Obtiene las coordenadas de la ventana de zoom. Las coordenadas son devueltas
|
219 |
* en referencia a las coordenadas del mundo. Esta llamada ajusta el tama?o de la ventana a la
|
220 |
* proporci?n pasada por par?metro. Es decir, si pasamos una proporci?n en la que el ancho es 3 veces
|
221 |
* mayor que el alto se ajustar? el zoom a esta proporci?n ya que presupone que la ventana de
|
222 |
* destino del zoom va a tener esas proporciones.
|
223 |
* @return
|
224 |
*/
|
225 |
public Rectangle2D getCursorAdjustedWorldCoordinates(int wWindow, int hWindow) { |
226 |
Rectangle2D r = getZoomCursorGraphicLayer().getCursorViewCoordinates();
|
227 |
|
228 |
double x = r.getX(), y = r.getY(), w = r.getWidth(), h = r.getHeight();
|
229 |
if(wWindow < hWindow) { //Si la de destino es m?s alta que ancha |
230 |
if((r.getWidth() / r.getHeight()) >= (wWindow / hWindow)) {
|
231 |
h = (hWindow * r.getWidth()) / wWindow; |
232 |
y = r.getCenterY() - (h / 2);
|
233 |
} else {
|
234 |
w = (wWindow * r.getHeight()) / hWindow; |
235 |
x = r.getCenterX() - (w / 2);
|
236 |
} |
237 |
} else { //Si la de destino es m?s ancha que alta |
238 |
if((r.getWidth() / r.getHeight()) <= (wWindow / hWindow)) {
|
239 |
w = (wWindow * r.getHeight()) / hWindow; |
240 |
x = r.getCenterX() - (w / 2);
|
241 |
} else {
|
242 |
h = (hWindow * r.getWidth()) / wWindow; |
243 |
y = r.getCenterY() - (h / 2);
|
244 |
} |
245 |
} |
246 |
if(zoomPixelControl.getCanvas().getMinxMaxyUL())
|
247 |
r = new Rectangle2D.Double(x, y + h, w, h); |
248 |
else
|
249 |
r = new Rectangle2D.Double(x, y - h, w, h); |
250 |
Point2D p1 = zoomPixelControl.getCanvas().viewCoordsToWorld(new Point2D.Double(r.getX(), r.getY())); |
251 |
Point2D p2 = zoomPixelControl.getCanvas().viewCoordsToWorld(new Point2D.Double(r.getX() + r.getWidth(), r.getY() + r.getHeight())); |
252 |
return new Rectangle2D.Double( Math.min(p1.getX(), p2.getX()), |
253 |
Math.max(p1.getY(), p2.getY()),
|
254 |
Math.abs(p2.getX() - p1.getX()),
|
255 |
Math.abs(p2.getY() - p1.getY()));
|
256 |
} |
257 |
|
258 |
/**
|
259 |
* Obtiene el extent del canvas en coordenadas del mundo real
|
260 |
* @return Rectangle2D
|
261 |
*/
|
262 |
public Rectangle2D getViewExtent() { |
263 |
return zoomPixelControl.getCanvas().getExtent();
|
264 |
} |
265 |
|
266 |
/*
|
267 |
* (non-Javadoc)
|
268 |
* @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
|
269 |
*/
|
270 |
public WindowInfo getWindowInfo() {
|
271 |
WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE);
|
272 |
//if (getClippingPanel().getFLayer() != null)
|
273 |
//m_viewinfo.setAdditionalInfo(getClippingPanel().getFLayer().getName());
|
274 |
m_viewinfo.setTitle(PluginServices.getText(this, "view_panel")); |
275 |
m_viewinfo.setX(posX); |
276 |
m_viewinfo.setY(posY); |
277 |
m_viewinfo.setHeight(h); |
278 |
m_viewinfo.setWidth(w); |
279 |
return m_viewinfo;
|
280 |
} |
281 |
} |
282 |
|