gvsig-raster / org.gvsig.raster.georeferencing / trunk / org.gvsig.raster.georeferencing / org.gvsig.raster.georeferencing.app / org.gvsig.raster.georeferencing.app.georeferencingclient / src / main / java / org / gvsig / raster / georeferencing / app / georeferencingclient / listener / ViewDialogListener.java @ 1730
History | View | Annotate | Download (9.72 KB)
1 |
/* 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.georeferencing.app.georeferencingclient.listener; |
23 |
|
24 |
import java.awt.geom.Point2D; |
25 |
import java.awt.geom.Rectangle2D; |
26 |
|
27 |
import org.gvsig.fmap.dal.coverage.datastruct.GeoPoint; |
28 |
import org.gvsig.raster.georeferencing.app.georeferencingclient.Georeferencing; |
29 |
import org.gvsig.raster.georeferencing.swing.GeoreferencingSwingLibrary; |
30 |
import org.gvsig.raster.georeferencing.swing.exception.InvalidRequestException; |
31 |
import org.gvsig.raster.georeferencing.swing.impl.GeoreferencingSwingImplLibrary; |
32 |
import org.gvsig.raster.georeferencing.swing.impl.layer.GCPsGraphicLayer; |
33 |
import org.gvsig.raster.georeferencing.swing.impl.layer.GPGraphic; |
34 |
import org.gvsig.raster.georeferencing.swing.impl.layer.ZoomCursorGraphicLayer; |
35 |
import org.gvsig.raster.georeferencing.swing.impl.tool.PanTool; |
36 |
import org.gvsig.raster.georeferencing.swing.impl.tool.SelectCoordOnViewTool; |
37 |
import org.gvsig.raster.georeferencing.swing.impl.tool.ZoomRectangleTool; |
38 |
import org.gvsig.raster.georeferencing.swing.view.ToolEvent; |
39 |
import org.gvsig.raster.georeferencing.swing.view.ToolListener; |
40 |
import org.gvsig.raster.georeferencing.swing.view.ViewEvent; |
41 |
import org.gvsig.raster.georeferencing.swing.view.ViewListener; |
42 |
import org.gvsig.raster.tools.app.basic.RasterToolsUtil; |
43 |
|
44 |
/**
|
45 |
* Listener for views. This listener catches the events of the views
|
46 |
* such as enable tools or whether the zoom has changed.
|
47 |
*
|
48 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
49 |
*/
|
50 |
public class ViewDialogListener implements ViewListener, ToolListener { |
51 |
private Georeferencing app = null; |
52 |
|
53 |
public ViewDialogListener(Georeferencing app) {
|
54 |
this.app = app;
|
55 |
} |
56 |
|
57 |
public void addingTool(ViewEvent ev) { |
58 |
|
59 |
} |
60 |
|
61 |
public void endDraw(ViewEvent ev) { |
62 |
|
63 |
} |
64 |
|
65 |
public void startDraw(ViewEvent ev) { |
66 |
|
67 |
} |
68 |
|
69 |
/**
|
70 |
* Cuando cambia el zoom de alguna vista hay que recalcular la posici?n
|
71 |
* del cursor de zoom
|
72 |
*/
|
73 |
public void zoomViewChanged(ViewEvent ev) { |
74 |
Rectangle2D ext = null; |
75 |
try {
|
76 |
if(app.getZoomRasterRequestManager() != null) { |
77 |
ext = app.getViewRaster().getCursorAdjustedWorldCoordinates(app.getZoomRaster().getCanvasWidth(), app.getZoomRaster().getCanvasHeight()); |
78 |
app.getZoomRasterRequestManager().request(ext); |
79 |
} |
80 |
if(app.getDataModel().getType() == Georeferencing.WITH_MAP && app.getZoomMapRequestManager() != null) { |
81 |
ext = app.getViewMap().getCursorAdjustedWorldCoordinates(app.getZoomMap().getCanvasWidth(), app.getZoomMap().getCanvasHeight()); |
82 |
app.getZoomMapRequestManager().request(ext); |
83 |
} |
84 |
}catch(InvalidRequestException ex) {
|
85 |
GeoreferencingSwingImplLibrary.messageBoxError("error_set_view", null, ex); |
86 |
} |
87 |
} |
88 |
|
89 |
/**
|
90 |
* Controla los eventos de finalizaci?n de la capa con el
|
91 |
* cursor gr?fico que controla el ?rea de la miniimagen asociada y
|
92 |
* la terminaci?n de la operaci?n de mover punto
|
93 |
*/
|
94 |
public void endAction(ToolEvent ev) { |
95 |
if(!Georeferencing.enableTableEvent)
|
96 |
return;
|
97 |
Georeferencing.enableTableEvent = false;
|
98 |
|
99 |
try {
|
100 |
//-----------------
|
101 |
//Operaci?n de zoom
|
102 |
if(ev.getSource() instanceof ZoomCursorGraphicLayer) { |
103 |
try {
|
104 |
Rectangle2D ext = null; |
105 |
if(app.getViewRaster() != null) { |
106 |
ext = app.getViewRaster().getCursorAdjustedWorldCoordinates(app.getZoomRaster().getCanvasWidth(), app.getZoomRaster().getCanvasHeight()); |
107 |
app.getZoomRasterRequestManager().request(ext); |
108 |
} |
109 |
if(app.getViewMap() != null) { |
110 |
ext = app.getViewMap().getCursorAdjustedWorldCoordinates(app.getZoomMap().getCanvasWidth(), app.getZoomMap().getCanvasHeight()); |
111 |
app.getZoomMapRequestManager().request(ext); |
112 |
} |
113 |
} catch (InvalidRequestException e1) {
|
114 |
GeoreferencingSwingImplLibrary.messageBoxError("error_setview_preview", null, e1); |
115 |
} |
116 |
} |
117 |
|
118 |
//-----------
|
119 |
//Arrastrar y seleccionar punto
|
120 |
if(ev.getSource() instanceof GCPsGraphicLayer) { |
121 |
//buttonsListener.setEnableTableEvent(false);
|
122 |
//Se redibujan, se obtienen las coordenadas del punto y se actualiza la tabla
|
123 |
if(app.getSyncViews() != null) |
124 |
app.getSyncViews().redrawPoints(); |
125 |
GPGraphic gPoint = ((GCPsGraphicLayer)ev.getSource()).getLastPoint(); |
126 |
Point2D pRaster = gPoint.getGeoPoint().getPixelPoint();
|
127 |
Point2D pMap = gPoint.getGeoPoint().getMapPoint();
|
128 |
try {
|
129 |
app.getTableWrapper().updatePoint(new Double(pMap.getX()), |
130 |
new Double(pMap.getY()), |
131 |
new Double(pRaster.getX()), |
132 |
new Double(pRaster.getY()), |
133 |
gPoint.getGeoPoint().getNumber()); |
134 |
app.getTableWrapper().getTable().getJTable().setRowSelectionInterval(gPoint.getGeoPoint().getNumber(), gPoint.getGeoPoint().getNumber()); |
135 |
} catch (ArrayIndexOutOfBoundsException e) { |
136 |
RasterToolsUtil.messageBoxError("no_rows_selected", app.getTableWrapper().getTable(), e);
|
137 |
} |
138 |
if(app.getDataModel().isCenterView())
|
139 |
app.getSyncViews().centerToPoint(gPoint.getGeoPoint().getNumber()); |
140 |
//buttonsListener.setEnableTableEvent(true);
|
141 |
} |
142 |
|
143 |
//------------------
|
144 |
//Mover punto
|
145 |
if(ev.getSource() instanceof SelectCoordOnViewTool) { |
146 |
try {
|
147 |
//Se obtiene el punto seleccionado, se actualiza la tabla y se redibujan
|
148 |
int nPoint = app.getDataModel().getGCPList().getSelectedPoint();//app.getTableWrapper().getTable().getSelectedRows()[0]; |
149 |
GeoPoint gp = app.getSyncViews().getPointByNumber(nPoint); |
150 |
|
151 |
if(((SelectCoordOnViewTool)ev.getSource()).getParentView() == app.getViewRaster() ||
|
152 |
((SelectCoordOnViewTool)ev.getSource()).getParentView() == app.getZoomRaster()) { |
153 |
Point2D[] p = (Point2D[])((SelectCoordOnViewTool)ev.getSource()).getResult(); |
154 |
app.getTableWrapper().updateRasterPoint(new Double(p[1].getX()), new Double(p[1].getY()), nPoint); |
155 |
if(gp != null) { |
156 |
gp.setPixelPoint(p[1]);
|
157 |
app.getSyncViews().redrawPoints(); |
158 |
} |
159 |
} |
160 |
if(((SelectCoordOnViewTool)ev.getSource()).getParentView() == app.getViewMap() ||
|
161 |
((SelectCoordOnViewTool)ev.getSource()).getParentView() == app.getZoomMap()) { |
162 |
Point2D[] p = (Point2D[])((SelectCoordOnViewTool)ev.getSource()).getResult(); |
163 |
app.getTableWrapper().updateMapPoint(new Double(p[1].getX()), new Double(p[1].getY()), nPoint); |
164 |
if(gp != null) { |
165 |
gp.setMapPoint(p[1]);
|
166 |
app.getSyncViews().redrawPoints(); |
167 |
} |
168 |
} |
169 |
if(app.getDataModel().isCenterView())
|
170 |
app.getSyncViews().centerToPoint(nPoint); |
171 |
} catch (ArrayIndexOutOfBoundsException e) { |
172 |
RasterToolsUtil.messageBoxError("no_rows_selected", app.getTableWrapper().getTable(), e);
|
173 |
} |
174 |
} |
175 |
|
176 |
} finally {
|
177 |
Georeferencing.enableTableEvent = true;
|
178 |
} |
179 |
} |
180 |
|
181 |
public void offTool(ToolEvent ev) { |
182 |
if(!Georeferencing.enableTableEvent)
|
183 |
return;
|
184 |
Georeferencing.enableTableEvent = false;
|
185 |
|
186 |
try {
|
187 |
|
188 |
if(ev.getSource() instanceof PanTool) { |
189 |
if(ev.getParentView() != null) |
190 |
ev.getParentView().disableTool(GeoreferencingSwingLibrary.PAN_TOOL); |
191 |
} |
192 |
|
193 |
if(ev.getSource() instanceof ZoomRectangleTool) { |
194 |
if(ev.getParentView() != null) |
195 |
ev.getParentView().disableTool(GeoreferencingSwingLibrary.ZOOM_RECTANGLE_TOOL); |
196 |
} |
197 |
|
198 |
//Selecci?n de punto
|
199 |
if(ev.getSource() instanceof SelectCoordOnViewTool) { |
200 |
if(app.getSyncViews() != null) |
201 |
app.getSyncViews().disableTool(GeoreferencingSwingLibrary.MOVE_POINT_TOOL); |
202 |
} |
203 |
|
204 |
} finally {
|
205 |
Georeferencing.enableTableEvent = true;
|
206 |
} |
207 |
} |
208 |
|
209 |
/**
|
210 |
* <P>
|
211 |
* Controla las prioridades de eventos sobre la vista en las herramientas y capas de selecci?n.
|
212 |
* Esto es necesario para que no se mezclen eventos entre capas.
|
213 |
* <P></P>
|
214 |
* Prioridades:
|
215 |
* </P>
|
216 |
* <UL>
|
217 |
* <LI>Capa de ZoomCursorGraphicLayer</LI>
|
218 |
* <LI>Capa de GCPsGraphicLayer</LI>
|
219 |
* <LI>Tool de selecci?n de zoom rectangulo</LI>
|
220 |
* <LI>Tool de selecci?n de puntos</LI>
|
221 |
* </UL>
|
222 |
*
|
223 |
*
|
224 |
*/
|
225 |
public void onTool(ToolEvent ev) { |
226 |
if(!Georeferencing.enableTableEvent)
|
227 |
return;
|
228 |
Georeferencing.enableTableEvent = false;
|
229 |
|
230 |
try {
|
231 |
|
232 |
//---------------------------
|
233 |
//Selecci?n de desplazamiento
|
234 |
if(ev.getSource() instanceof PanTool) { |
235 |
if(ev.getParentView() != null) |
236 |
ev.getParentView().disableTool(GeoreferencingSwingLibrary.ZOOM_RECTANGLE_TOOL); |
237 |
if(app.getSyncViews() != null) { |
238 |
app.getSyncViews().disableTool(GeoreferencingSwingLibrary.MOVE_POINT_TOOL); |
239 |
app.getSyncViews().disableTool(GeoreferencingSwingLibrary.DRAG_POINT_TOOL); |
240 |
} |
241 |
} |
242 |
|
243 |
if(ev.getSource() instanceof ZoomRectangleTool) { |
244 |
if(ev.getParentView() != null) |
245 |
ev.getParentView().disableTool(GeoreferencingSwingLibrary.PAN_TOOL); |
246 |
if(app.getSyncViews() != null) { |
247 |
app.getSyncViews().disableTool(GeoreferencingSwingLibrary.MOVE_POINT_TOOL); |
248 |
app.getSyncViews().disableTool(GeoreferencingSwingLibrary.DRAG_POINT_TOOL); |
249 |
} |
250 |
} |
251 |
|
252 |
//------------------
|
253 |
//Mover punto seleccionado
|
254 |
if(ev.getSource() instanceof SelectCoordOnViewTool) { |
255 |
if(ev.getParentView() != null) |
256 |
ev.getParentView().disableAllTools(); |
257 |
if(app.getSyncViews() != null) |
258 |
app.getSyncViews().disableTool(GeoreferencingSwingLibrary.DRAG_POINT_TOOL); |
259 |
} |
260 |
|
261 |
} finally {
|
262 |
Georeferencing.enableTableEvent = true;
|
263 |
} |
264 |
} |
265 |
|
266 |
} |