gvsig-projects-pool / org.gvsig.busquedacatastral / trunk / org.gvsig.busquedacatastral / org.gvsig.busquedacatastral.app / org.gvsig.busquedacatastral.app.mainplugin / src / main / java / org / gvsig / busquedacatastral / app / mainplugin / BusquedaCatastralExtension.java @ 435
History | View | Annotate | Download (11.9 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2016 gvSIG Association
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.busquedacatastral.app.mainplugin; |
24 |
|
25 |
import java.awt.Color; |
26 |
import java.awt.event.ActionEvent; |
27 |
import java.awt.event.ActionListener; |
28 |
import java.io.File; |
29 |
|
30 |
import javax.swing.JOptionPane; |
31 |
|
32 |
import org.apache.commons.lang3.StringUtils; |
33 |
import org.cresques.cts.IProjection; |
34 |
|
35 |
import org.gvsig.andami.IconThemeHelper; |
36 |
import org.gvsig.andami.Utilities; |
37 |
import org.gvsig.andami.plugins.Extension; |
38 |
import org.gvsig.app.ApplicationLocator; |
39 |
import org.gvsig.app.ApplicationManager; |
40 |
import org.gvsig.app.project.documents.view.ViewDocument; |
41 |
import org.gvsig.app.project.documents.view.gui.IView; |
42 |
import org.gvsig.busquedacatastral.lib.api.BusquedaCatastralLocator; |
43 |
import org.gvsig.busquedacatastral.lib.api.BusquedaCatastralManager; |
44 |
import org.gvsig.busquedacatastral.lib.api.ReferenciaCatastral; |
45 |
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralException; |
46 |
import org.gvsig.busquedacatastral.lib.api.exceptions.BusquedaCatastralRemoteServiceException; |
47 |
import org.gvsig.busquedacatastral.lib.impl.ws.CallejeroCatastroWSLocator; |
48 |
import org.gvsig.busquedacatastral.swing.api.BusquedaCatastralConsultaCatastralPanel; |
49 |
import org.gvsig.busquedacatastral.swing.api.BusquedaCatastralSwingLocator; |
50 |
import org.gvsig.busquedacatastral.swing.api.exceptions.BusquedaCatastralCreatingPanelException; |
51 |
import org.gvsig.busquedacatastral.swing.api.exceptions.BusquedaCatastralObtainingDataException; |
52 |
import org.gvsig.busquedacatastral.swing.api.exceptions.BusquedaCatastralObtainingPointException; |
53 |
import org.gvsig.fmap.geom.Geometry; |
54 |
import org.gvsig.fmap.geom.GeometryLocator; |
55 |
import org.gvsig.fmap.geom.GeometryManager; |
56 |
import org.gvsig.fmap.geom.primitive.Envelope; |
57 |
import org.gvsig.fmap.geom.primitive.Point; |
58 |
import org.gvsig.fmap.mapcontext.MapContext; |
59 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
60 |
import org.gvsig.fmap.mapcontext.ViewPort; |
61 |
import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer; |
62 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
63 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
64 |
import org.gvsig.symbology.SymbologyLocator; |
65 |
import org.gvsig.symbology.SymbologyManager; |
66 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.ISimpleTextSymbol; |
67 |
import org.gvsig.tools.ToolsLocator; |
68 |
import org.gvsig.tools.dynobject.DynObject; |
69 |
import org.gvsig.tools.i18n.I18nManager; |
70 |
import org.gvsig.tools.locator.LocatorException; |
71 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
72 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
73 |
|
74 |
import org.slf4j.Logger; |
75 |
import org.slf4j.LoggerFactory; |
76 |
|
77 |
|
78 |
|
79 |
/**
|
80 |
* Extension for catastral data searchs
|
81 |
* @author dmartinez (dmartinez@disid.com)
|
82 |
*/
|
83 |
public class BusquedaCatastralExtension extends Extension { |
84 |
private Logger logger = LoggerFactory.getLogger(BusquedaCatastralExtension.class); |
85 |
|
86 |
private static final String CACHEFOLDERNAME="BusquedaCatastral"; |
87 |
|
88 |
public static final String SHOW_POINT_BUSQUEDACATASTRAL_ID = "ShowPointBusquedaCatastral"; |
89 |
|
90 |
public void initialize() { |
91 |
IconThemeHelper.registerIcon(null, "view-navigation-busqueda-catastral", this); |
92 |
BusquedaCatastralLocator.getManager().setCacheFolder(new File(Utilities.TEMPDIRECTORYPATH, CACHEFOLDERNAME)); |
93 |
} |
94 |
|
95 |
public void postInitialize() { |
96 |
|
97 |
} |
98 |
|
99 |
public void execute(String actionCommand) { |
100 |
final WindowManager winManager = ToolsSwingLocator.getWindowManager();
|
101 |
final I18nManager i18nManager = ToolsLocator.getI18nManager();
|
102 |
|
103 |
if (StringUtils.equalsIgnoreCase(actionCommand, "busqueda-catastral")) { |
104 |
//Create GUI to query catastro
|
105 |
BusquedaCatastralConsultaCatastralPanel panel; |
106 |
try {
|
107 |
panel = BusquedaCatastralSwingLocator.getManager().createConsultaCatastralPanel(); |
108 |
} catch (BusquedaCatastralRemoteServiceException e) {
|
109 |
logger.error("Error creating panel", e);
|
110 |
JOptionPane.showMessageDialog(
|
111 |
null,
|
112 |
new StringBuilder().append(i18nManager.getTranslation("_error_accesing_catastral_server")), |
113 |
i18nManager.getTranslation("error"), JOptionPane.ERROR_MESSAGE); |
114 |
return;
|
115 |
} catch (Exception e) { |
116 |
logger.error("Error creating panel", e);
|
117 |
JOptionPane.showMessageDialog(
|
118 |
null,
|
119 |
new StringBuilder().append(i18nManager.getTranslation("_error_creating_panel")) |
120 |
.append(":").append(e.getLocalizedMessage()),
|
121 |
i18nManager.getTranslation("error"), JOptionPane.ERROR_MESSAGE); |
122 |
return;
|
123 |
} |
124 |
panel.addActionListener(new ActionListener() { |
125 |
|
126 |
public void actionPerformed(ActionEvent event) { |
127 |
BusquedaCatastralConsultaCatastralPanel panel = (BusquedaCatastralConsultaCatastralPanel) event.getSource(); |
128 |
if (panel.isSelectedAction(BusquedaCatastralConsultaCatastralPanel.PanelAction.CANCEL)) {
|
129 |
return;
|
130 |
}else if(panel.isSelectedAction(BusquedaCatastralConsultaCatastralPanel.PanelAction.FOCUSTOPOINT)){ |
131 |
Point selectedPoint;
|
132 |
ReferenciaCatastral selectedRefCatastral; |
133 |
try {
|
134 |
selectedPoint = panel.getPoint(getActiveViewProjection()); |
135 |
selectedRefCatastral=panel.getSelectedReferenciaCatastral(); |
136 |
} catch (BusquedaCatastralObtainingPointException e) {
|
137 |
logger.error("Error obtaining point", e);
|
138 |
JOptionPane.showMessageDialog(
|
139 |
null,
|
140 |
new StringBuilder().append(i18nManager.getTranslation("_error_obtaining_point")) |
141 |
.append(":").append(e.getLocalizedMessage()),
|
142 |
i18nManager.getTranslation("error"), JOptionPane.ERROR_MESSAGE); |
143 |
return;
|
144 |
} |
145 |
focusToPoint(selectedPoint); |
146 |
showPoint(selectedPoint,selectedRefCatastral.getRC()); |
147 |
}else if(panel.isSelectedAction(BusquedaCatastralConsultaCatastralPanel.PanelAction.DELETEPOINTS)){ |
148 |
deletePoints(); |
149 |
}else if(panel.isSelectedAction(BusquedaCatastralConsultaCatastralPanel.PanelAction.SHOWDATA)){ |
150 |
try {
|
151 |
DynObject datosCatastrales=panel.getDatosCatastrales(); |
152 |
} catch (BusquedaCatastralObtainingDataException e) {
|
153 |
logger.error("Error obtaining datos catastrales", e);
|
154 |
JOptionPane.showMessageDialog(
|
155 |
null,
|
156 |
new StringBuilder().append(i18nManager.getTranslation("_error_obtaining_data")) |
157 |
.append(":").append(e.getLocalizedMessage()),
|
158 |
i18nManager.getTranslation("error"), JOptionPane.ERROR_MESSAGE); |
159 |
return;
|
160 |
} |
161 |
//TODO Mostrar los datos obtenidos
|
162 |
} |
163 |
} |
164 |
}); |
165 |
|
166 |
winManager.showWindow(panel.asJComponent(), i18nManager.getTranslation("_busqueda_catastral"),
|
167 |
WindowManager.MODE.WINDOW); |
168 |
|
169 |
} |
170 |
} |
171 |
|
172 |
|
173 |
|
174 |
public boolean isEnabled() { |
175 |
//It needs an active view with a valid viewport
|
176 |
IView view = getActiveView(); |
177 |
if (view != null) { |
178 |
ViewPort viewPort = view.getMapControl().getViewPort(); |
179 |
Envelope viewPortEnvelope = viewPort.getEnvelope(); |
180 |
if(viewPortEnvelope == null || viewPortEnvelope.isEmpty()){ |
181 |
return false; |
182 |
} |
183 |
return true; |
184 |
} |
185 |
return false; |
186 |
} |
187 |
|
188 |
public boolean isVisible() { |
189 |
//It needs an active view
|
190 |
IView view = getActiveView(); |
191 |
if (view != null) { |
192 |
return true; |
193 |
} |
194 |
return false; |
195 |
} |
196 |
|
197 |
|
198 |
private IView getActiveView() {
|
199 |
ApplicationManager application = ApplicationLocator.getManager(); |
200 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
201 |
return view;
|
202 |
} |
203 |
|
204 |
private IProjection getActiveViewProjection(){
|
205 |
if (getActiveView()!=null){ |
206 |
return getActiveView().getMapControl().getViewPort().getProjection();
|
207 |
}else{
|
208 |
return null; |
209 |
} |
210 |
} |
211 |
|
212 |
/**
|
213 |
* Focus the view centered in a selected Point
|
214 |
* @param focusPoint
|
215 |
*/
|
216 |
private void focusToPoint(Point focusPoint){ |
217 |
IView activeView = getActiveView(); |
218 |
if (activeView!=null){ |
219 |
ViewPort viewPort =activeView.getMapControl().getViewPort(); |
220 |
MapContext mapContext = activeView.getMapControl().getMapContext(); |
221 |
Envelope envelope = viewPort.getAdjustedEnvelope(); |
222 |
envelope.centerTo(focusPoint); |
223 |
mapContext.zoomToEnvelope(envelope); |
224 |
} |
225 |
} |
226 |
|
227 |
|
228 |
/**
|
229 |
* Show the m in the point p on the graphicLayer
|
230 |
*
|
231 |
* @param m
|
232 |
* @param ct
|
233 |
*/
|
234 |
private void showPoint(Point p, String refCatastral) { |
235 |
IView activeView = getActiveView(); |
236 |
if (activeView!=null){ |
237 |
ViewPort viewPort =activeView.getMapControl().getViewPort(); |
238 |
MapContext mapContext = activeView.getMapControl().getMapContext(); |
239 |
GraphicLayer graphics = mapContext.getGraphicsLayer(); |
240 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
241 |
SymbolManager symbolManager = MapContextLocator.getSymbolManager(); |
242 |
|
243 |
ISymbol markerSymbol = symbolManager.createSymbol(Geometry.TYPES.POINT, Color.RED);
|
244 |
ISimpleTextSymbol textSymbol = getTextSymbol(); |
245 |
textSymbol.setColor(Color.RED);
|
246 |
textSymbol.setText(refCatastral); |
247 |
int idMarkerSymbol = graphics.addSymbol(markerSymbol);
|
248 |
int idTextSymbol = graphics.addSymbol(textSymbol);
|
249 |
Point clonedPoint = (Point) p.cloneGeometry(); |
250 |
graphics.addGraphic(SHOW_POINT_BUSQUEDACATASTRAL_ID, clonedPoint, idTextSymbol); |
251 |
graphics.addGraphic(SHOW_POINT_BUSQUEDACATASTRAL_ID, clonedPoint, idMarkerSymbol); |
252 |
mapContext.invalidate(); |
253 |
} |
254 |
} |
255 |
|
256 |
/*
|
257 |
* Creates a text symbol to be used
|
258 |
*/
|
259 |
private ISimpleTextSymbol getTextSymbol(){
|
260 |
SymbologyManager symbologyManager = SymbologyLocator.getSymbologyManager(); |
261 |
ISimpleTextSymbol textSymbol = symbologyManager.createSimpleTextSymbol(); |
262 |
textSymbol.setFontSize(10);
|
263 |
return textSymbol;
|
264 |
} |
265 |
|
266 |
private void deletePoints(){ |
267 |
IView activeView = getActiveView(); |
268 |
if (activeView!=null){ |
269 |
ViewPort viewPort =activeView.getMapControl().getViewPort(); |
270 |
MapContext mapContext = activeView.getMapControl().getMapContext(); |
271 |
GraphicLayer graphics = mapContext.getGraphicsLayer(); |
272 |
graphics.removeGraphics(SHOW_POINT_BUSQUEDACATASTRAL_ID); |
273 |
mapContext.invalidate(); |
274 |
} |
275 |
|
276 |
} |
277 |
|
278 |
} |