svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / toolListeners / GeorefPointSelectorListener.java @ 3195
History | View | Annotate | Download (4.65 KB)
1 | 3091 | nacho | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 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 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | package com.iver.cit.gvsig.gui.toolListeners; |
||
42 | |||
43 | import java.awt.Component; |
||
44 | import java.awt.geom.Point2D; |
||
45 | |||
46 | import javax.swing.JOptionPane; |
||
47 | |||
48 | import com.iver.andami.PluginServices; |
||
49 | import com.iver.cit.gvsig.fmap.DriverException; |
||
50 | import com.iver.cit.gvsig.fmap.ViewPort; |
||
51 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
52 | import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster; |
||
53 | import com.iver.cit.gvsig.fmap.layers.FLyrPoints; |
||
54 | import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
||
55 | import com.iver.cit.gvsig.fmap.tools.GeorefPointerListenerImpl; |
||
56 | import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
||
57 | import com.iver.cit.gvsig.gui.View; |
||
58 | import com.iver.cit.gvsig.gui.Dialogs.GeoreferencingDialog; |
||
59 | import com.iver.cit.gvsig.gui.Panels.SelectFilePanel; |
||
60 | import com.iver.cit.gvsig.gui.Panels.SelectPointsPanel; |
||
61 | |||
62 | |||
63 | /**
|
||
64 | * <p>Extensi?n de la clase GeorefPointerListenerImpl de FMap para poder llamar a m?todos de
|
||
65 | * andami o de gvSIG.</p>
|
||
66 | * <p>Este listener salva puntos clickeados desde una vista sobre una capa de puntos.</p>
|
||
67 | *
|
||
68 | * @author Nacho Brodin (brodin_ign@gva.es)
|
||
69 | */
|
||
70 | public class GeorefPointSelectorListener extends GeorefPointerListenerImpl { |
||
71 | |||
72 | private GeoreferencingDialog dialog = null; |
||
73 | private View theView = null; |
||
74 | 3192 | nacho | |
75 | 3091 | nacho | /**
|
76 | * true si se va a seleccionar el primer punto y false si se selecciona el segundo.
|
||
77 | *
|
||
78 | */
|
||
79 | public static boolean firstPoint = true; |
||
80 | |||
81 | |||
82 | /**
|
||
83 | * Posici?n del punto a ser seleccionado.
|
||
84 | */
|
||
85 | public static int posPoint = -1; |
||
86 | |||
87 | /**
|
||
88 | * Constructor
|
||
89 | *
|
||
90 | * @param mapCtrl
|
||
91 | */
|
||
92 | public GeorefPointSelectorListener(GeoreferencingDialog dialog) {
|
||
93 | super();
|
||
94 | this.dialog = dialog;
|
||
95 | } |
||
96 | |||
97 | /**
|
||
98 | * Captura de puntos sobre una capa FlyrPoint
|
||
99 | *
|
||
100 | * @param event Evento de un punto sobre la vista
|
||
101 | *
|
||
102 | * @throws BehaviorException
|
||
103 | */
|
||
104 | public void point(PointEvent event) throws BehaviorException { |
||
105 | super.point(event);
|
||
106 | |||
107 | 3102 | nacho | try{
|
108 | theView = (View)PluginServices.getMDIManager().getActiveView();
|
||
109 | }catch(ClassCastException exc){ |
||
110 | return;
|
||
111 | } |
||
112 | 3091 | nacho | //Obtenemos la capa de puntos y la capa de georaster
|
113 | 3192 | nacho | |
114 | if(dialog.getLyrPoints() == null || dialog.getLyrGeoRaster() == null){ |
||
115 | 3091 | nacho | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
116 | PluginServices.getText(this, "error_capa_puntos")); |
||
117 | return;
|
||
118 | } |
||
119 | |||
120 | ViewPort viewPort = theView.getMapControl().getMapContext().getViewPort(); |
||
121 | Point2D wcPoint = viewPort.toMapPoint(event.getPoint());
|
||
122 | |||
123 | if(firstPoint){
|
||
124 | 3192 | nacho | if(dialog.getLyrPoints() != null){ |
125 | 3091 | nacho | |
126 | 3192 | nacho | Point2D pixelImg = dialog.getLyrGeoRaster().world2Img(wcPoint);
|
127 | 3091 | nacho | if(pixelImg == null){ |
128 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
||
129 | PluginServices.getText(this, "fuera_de_extent")); |
||
130 | return;
|
||
131 | } |
||
132 | |||
133 | int n = Integer.valueOf(dialog.getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue(); |
||
134 | 3192 | nacho | dialog.getLyrGeoRaster().updateData(n, |
135 | pixelImg, |
||
136 | null,
|
||
137 | dialog, |
||
138 | 3195 | nacho | theView); |
139 | 3091 | nacho | |
140 | firstPoint = false;
|
||
141 | } |
||
142 | }else{
|
||
143 | |||
144 | //Deseleccionamos la herramienta de marcado de puntos
|
||
145 | 3192 | nacho | theView.getMapControl().setTool(dialog.getLyrPoints().getLastTool()); |
146 | 3102 | nacho | |
147 | 3091 | nacho | |
148 | int n = Integer.valueOf(dialog.getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedItem().toString()).intValue(); |
||
149 | 3192 | nacho | dialog.getLyrGeoRaster().updateData(n, |
150 | null,
|
||
151 | wcPoint, |
||
152 | dialog, |
||
153 | 3195 | nacho | theView); |
154 | 3102 | nacho | dialog.getConectorPanel().getAdjustGeorefPanel().getZoomLeft().draw(); |
155 | 3091 | nacho | firstPoint = true;
|
156 | } |
||
157 | |||
158 | } |
||
159 | } |