svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / View.java @ 775
History | View | Annotate | Download (14.3 KB)
1 |
package com.iver.cit.gvsig.gui; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Color; |
5 |
import java.awt.Dimension; |
6 |
import java.awt.Point; |
7 |
import java.awt.image.BufferedImage; |
8 |
import java.beans.PropertyChangeEvent; |
9 |
import java.beans.PropertyChangeListener; |
10 |
|
11 |
import javax.swing.JPanel; |
12 |
import javax.swing.JScrollPane; |
13 |
import javax.swing.JSplitPane; |
14 |
|
15 |
import com.iver.andami.PluginServices; |
16 |
import com.iver.andami.Utilities; |
17 |
import com.iver.andami.messages.NotificationManager; |
18 |
import com.iver.andami.ui.mdiManager.SingletonView; |
19 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
20 |
import com.iver.cit.gvsig.fmap.ExceptionListener; |
21 |
import com.iver.cit.gvsig.fmap.FMap; |
22 |
import com.iver.cit.gvsig.fmap.MapOverview; |
23 |
import com.iver.cit.gvsig.fmap.NewMapControl; |
24 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
25 |
import com.iver.cit.gvsig.fmap.tools.AreaListenerImpl; |
26 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
27 |
import com.iver.cit.gvsig.fmap.tools.MeasureListenerImpl; |
28 |
import com.iver.cit.gvsig.fmap.tools.PanListenerImpl; |
29 |
import com.iver.cit.gvsig.fmap.tools.PointSelectionListener; |
30 |
import com.iver.cit.gvsig.fmap.tools.RectangleSelectionListener; |
31 |
import com.iver.cit.gvsig.fmap.tools.ZoomInListenerImpl; |
32 |
import com.iver.cit.gvsig.fmap.tools.ZoomOutListenerImpl; |
33 |
import com.iver.cit.gvsig.fmap.tools.Behavior.AreaMapTool; |
34 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MeasureMapTool; |
35 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MoveMapTool; |
36 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PointMapTool; |
37 |
import com.iver.cit.gvsig.fmap.tools.Behavior.RectangleMapTool; |
38 |
import com.iver.cit.gvsig.gui.toc.TOC; |
39 |
import com.iver.cit.gvsig.gui.toolListeners.AreaListener; |
40 |
import com.iver.cit.gvsig.gui.toolListeners.InfoListener; |
41 |
import com.iver.cit.gvsig.gui.toolListeners.LinkListener; |
42 |
import com.iver.cit.gvsig.gui.toolListeners.MeasureListener; |
43 |
import com.iver.cit.gvsig.project.castor.ProjectView; |
44 |
|
45 |
|
46 |
/**
|
47 |
* DOCUMENT ME!
|
48 |
*
|
49 |
* @author vcn
|
50 |
*/
|
51 |
public class View extends JPanel implements com.iver.andami.ui.mdiManager.View, |
52 |
SingletonView, IView { |
53 |
|
54 |
/** DOCUMENT ME! */
|
55 |
private NewMapControl m_MapControl;
|
56 |
private MapOverview m_MapLoc;
|
57 |
|
58 |
/** DOCUMENT ME! */
|
59 |
private FThemePropertiesDialog m_Themeproperties;
|
60 |
private JScrollPane jscrollTOC; |
61 |
private TOC m_TOC;
|
62 |
private ProjectView modelo;
|
63 |
|
64 |
// private FLyrVect layerSelected;
|
65 |
private String m_selectedField = null; |
66 |
private int m_typeLink=0; |
67 |
private String m_extLink; |
68 |
private Table table = null; |
69 |
private ViewExceptionListener mapControlExceptionListener = new ViewExceptionListener(); |
70 |
|
71 |
/**
|
72 |
* Creates a new View object.
|
73 |
*/
|
74 |
public View() { |
75 |
//this.setName(Utilities.getMessage(this, "Vista")+ " : "+modelo.getName());
|
76 |
this.setPreferredSize(new Dimension(500, 300)); |
77 |
initComponents(); |
78 |
//TODO Poner la herramienta por defecto
|
79 |
// m_MapControl.setTool(MapControl.ZOOM_MAS);
|
80 |
} |
81 |
|
82 |
/**
|
83 |
* DOCUMENT ME!
|
84 |
*
|
85 |
* @return DOCUMENT ME!
|
86 |
*/
|
87 |
public ProjectView getModel() {
|
88 |
return modelo;
|
89 |
} |
90 |
|
91 |
/**
|
92 |
* DOCUMENT ME!
|
93 |
*
|
94 |
* @param model DOCUMENT ME!
|
95 |
*/
|
96 |
public void setModel(ProjectView model) { |
97 |
this.modelo = model;
|
98 |
|
99 |
//Se registra como listener de cambios en FMap
|
100 |
FMap fmap = modelo.getMapContext(); |
101 |
|
102 |
//Se configura el mapControl
|
103 |
m_MapControl.setMapContext(fmap); |
104 |
m_TOC.setMapContext(fmap); |
105 |
m_MapControl.setBackground(new Color(255, 255, 255)); |
106 |
|
107 |
model.addPropertyChangeListener(new PropertyChangeListener() { |
108 |
public void propertyChange(PropertyChangeEvent evt) { |
109 |
if (evt.getPropertyName().equals("name")){ |
110 |
PluginServices.getMDIManager().getViewInfo(View.this).setTitle("Vista: " + (String)evt.getNewValue()); |
111 |
} |
112 |
} |
113 |
}); |
114 |
/// m_TOC.refresh();
|
115 |
|
116 |
} |
117 |
|
118 |
/**
|
119 |
* DOCUMENT ME!
|
120 |
*
|
121 |
* @param pScreen DOCUMENT ME!
|
122 |
*/
|
123 |
private void info(Point pScreen) { |
124 |
/*
|
125 |
* TODO Definir el di?logo de informaci?n com?n
|
126 |
* para todas las capas y abrirlo desde aqu?
|
127 |
*/
|
128 |
/*
|
129 |
// OJO:
|
130 |
// El queryByPoint de las capas WMS pide el punto en coordenadas de PANTALLA,
|
131 |
// y el queryByPoint del resto de capas en coordenadas de mundo real.
|
132 |
Point2D pReal = m_MapControl.getMapContext().getViewPort().toMapPoint(pScreen);
|
133 |
|
134 |
ArrayList sel = m_TOC.getSelectedLayers();
|
135 |
|
136 |
// Denro de queryByPoint tenemos que separar los registros que vienen asociados a una
|
137 |
// capa o a otra. Supongo que lo correcto ser?a que montaramos un XML y usar el visor
|
138 |
// de XML que ha empezado Fernando.
|
139 |
// String strResul = m_MapControl.queryByPoint(pScreen,m_MapControl.toMapDistance(3),"");
|
140 |
FInfoDialog dlg = new FInfoDialog();
|
141 |
dlg.clearAll();
|
142 |
dlg.setViewModel(modelo);
|
143 |
|
144 |
FInfoDialogXML dlgXML = new FInfoDialogXML();
|
145 |
MultipleXMLContent xmlModel = new MultipleXMLContent();
|
146 |
|
147 |
// if (strResul == "" ) return;
|
148 |
String strResul;
|
149 |
|
150 |
boolean algunWMS = false;
|
151 |
boolean algunNoWMS = false;
|
152 |
|
153 |
for (int i = 0; i < m_TOC.getSelectedLayers().size(); i++) {
|
154 |
IFLayer laCapa = (IFLayer) m_TOC.getSelectedLayers().get(i);
|
155 |
|
156 |
if (laCapa instanceof FLyrWMS) {
|
157 |
algunWMS = true;
|
158 |
strResul = laCapa.QueryByPoint(pScreen,
|
159 |
m_MapControl.toMapDistance(3), "");
|
160 |
xmlModel.addXML(strResul);
|
161 |
} else {
|
162 |
algunNoWMS = true;
|
163 |
strResul = laCapa.QueryByPoint(pReal,
|
164 |
m_MapControl.toMapDistance(3), "");
|
165 |
|
166 |
String[] arraySplit = null;
|
167 |
arraySplit = strResul.split("\n");
|
168 |
|
169 |
if (arraySplit.length > 1) {
|
170 |
// System.out.println("LWS: strResul="+strResul);
|
171 |
String descrip = "";
|
172 |
|
173 |
if (laCapa.getParentLayer() != null) {
|
174 |
descrip = laCapa.getParentLayer().getName() + "_";
|
175 |
}
|
176 |
|
177 |
dlg.addLayerInfo(descrip + laCapa.getName(), strResul);
|
178 |
}
|
179 |
}
|
180 |
}
|
181 |
|
182 |
if (algunNoWMS) {
|
183 |
dlg = (FInfoDialog) App.instance.getMDIContext().addView(dlg);
|
184 |
}
|
185 |
|
186 |
if (algunWMS) {
|
187 |
try {
|
188 |
dlgXML.setModel(xmlModel);
|
189 |
dlgXML = (FInfoDialogXML) App.instance.getMDIContext().addView(dlgXML);
|
190 |
} catch (SAXException e) {
|
191 |
if (App.instance != null) {
|
192 |
App.instance.getNm().addError("No se reconoce el formato", e);
|
193 |
} else {
|
194 |
}
|
195 |
}
|
196 |
}
|
197 |
|
198 |
dlg.refresh();
|
199 |
*/
|
200 |
} |
201 |
|
202 |
/**
|
203 |
* DOCUMENT ME!
|
204 |
*
|
205 |
* @param pScreen DOCUMENT ME!
|
206 |
*/
|
207 |
private void showLink(Point pScreen) { |
208 |
//TODO implementar bien
|
209 |
/*
|
210 |
Point2D pReal = m_MapControl.getMapContext().getViewPort().toMapPoint(pScreen);
|
211 |
ArrayList sel = m_TOC.getSelectedLayers();
|
212 |
|
213 |
String strResul = m_MapControl.getMapContext().queryByPoint(pScreen,
|
214 |
m_MapControl.getMapContext().getViewPort().toMapDistance(3));
|
215 |
System.err.println("strResul = " + strResul);
|
216 |
|
217 |
URL url = Abrir.class.getClassLoader().getResource("images/" +
|
218 |
strResul.trim());
|
219 |
|
220 |
if (url == null) {
|
221 |
JOptionPane.showMessageDialog((Component) null,
|
222 |
"Fichero " + strResul + " no encontrado.", "Error",
|
223 |
JOptionPane.ERROR_MESSAGE);
|
224 |
} else {
|
225 |
ImageIcon image = new ImageIcon(url);
|
226 |
|
227 |
FImageView imageview = new FImageView(image, strResul);
|
228 |
App.instance.getMDIContext().addView(imageview);
|
229 |
}
|
230 |
*/
|
231 |
} |
232 |
|
233 |
/**
|
234 |
* Se selecciona el nombre del campo para realizar cuando se quiera el link.
|
235 |
*
|
236 |
* @param s nombre del campo.
|
237 |
*/
|
238 |
public void setSelectedField(String s) { |
239 |
m_selectedField = s; |
240 |
} |
241 |
/**
|
242 |
* Se selecciona el tipo de fichero para realizar cuando se quiera el link.
|
243 |
*
|
244 |
* @param s nombre del campo.
|
245 |
*/
|
246 |
public void setTypeFile(int i){ |
247 |
m_typeLink=i; |
248 |
} |
249 |
/**
|
250 |
* Se selecciona la extensi?n para realizar cuando se quiera el link.
|
251 |
*
|
252 |
* @param s nombre del campo.
|
253 |
*/
|
254 |
public void setExtension(String s){ |
255 |
m_extLink=s; |
256 |
} |
257 |
/**
|
258 |
* DOCUMENT ME!
|
259 |
*
|
260 |
* @return DOCUMENT ME!
|
261 |
*/
|
262 |
public String getSelectedField() { |
263 |
return m_selectedField;
|
264 |
} |
265 |
/**
|
266 |
* DOCUMENT ME!
|
267 |
*
|
268 |
* @return DOCUMENT ME!
|
269 |
*/
|
270 |
public int getTypeFile() { |
271 |
return m_typeLink;
|
272 |
} |
273 |
/**
|
274 |
* DOCUMENT ME!
|
275 |
*
|
276 |
* @return DOCUMENT ME!
|
277 |
*/
|
278 |
public String getExtLink() { |
279 |
return m_extLink;
|
280 |
} |
281 |
|
282 |
/**
|
283 |
* DOCUMENT ME!
|
284 |
*/
|
285 |
public void openThemeProperties() { |
286 |
FMap fmap = modelo.getMapContext(); |
287 |
FLayer[] actives = fmap.getLayers().getActives();
|
288 |
|
289 |
for (int i = 0; i < actives.length; i++){ |
290 |
m_Themeproperties = new FThemePropertiesDialog(actives[i], this); |
291 |
PluginServices.getMDIManager().addView(m_Themeproperties); |
292 |
} |
293 |
} |
294 |
|
295 |
/**
|
296 |
* DOCUMENT ME!
|
297 |
*/
|
298 |
private void initComponents() { //GEN-BEGIN:initComponents |
299 |
m_MapControl = new NewMapControl();
|
300 |
m_MapControl.addExceptionListener(mapControlExceptionListener); |
301 |
// modelo.setMapContext(m_MapControl.getMapContext());
|
302 |
|
303 |
// m_MapControl.setAcceptEvents(true); Lo comento porque ya se hace en el setModel
|
304 |
m_TOC = new TOC();
|
305 |
|
306 |
JSplitPane tempMainSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); |
307 |
tempMainSplit.setPreferredSize(new Dimension(500, 300)); |
308 |
|
309 |
// Ponemos el localizador
|
310 |
m_MapLoc = new MapOverview(m_MapControl);
|
311 |
m_MapLoc.setPreferredSize(new Dimension(150, 200)); |
312 |
|
313 |
JSplitPane tempSplitToc = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
314 |
|
315 |
tempSplitToc.setTopComponent((TOC) m_TOC); |
316 |
tempSplitToc.setBottomComponent(m_MapLoc); |
317 |
tempSplitToc.setResizeWeight(0.7);
|
318 |
|
319 |
// tempSplitToc.resetToPreferredSizes();
|
320 |
tempMainSplit.setLeftComponent(tempSplitToc); |
321 |
|
322 |
m_TOC.setVisible(true);
|
323 |
|
324 |
// m_TOC.setPreferredSize(new Dimension(150,50));
|
325 |
tempMainSplit.setRightComponent(m_MapControl); |
326 |
this.setLayout(new BorderLayout()); |
327 |
this.add(tempMainSplit, BorderLayout.CENTER); |
328 |
|
329 |
// Zoom out (pinchas y el mapa se centra y te muestra m?s).
|
330 |
// No es dibujando un rect?ngulo, es solo pinchando.
|
331 |
m_MapControl.addMapTool("point", new PointMapTool()); |
332 |
|
333 |
ZoomOutListenerImpl zoli = new ZoomOutListenerImpl(m_MapControl);
|
334 |
m_MapControl.addTool("zoomOut", "point", zoli); |
335 |
|
336 |
// pan
|
337 |
m_MapControl.addMapTool("pan", new MoveMapTool()); |
338 |
|
339 |
PanListenerImpl pli = new PanListenerImpl(m_MapControl);
|
340 |
m_MapControl.addTool("pan", "pan", pli); |
341 |
|
342 |
// Medir
|
343 |
m_MapControl.addMapTool("medicion", new MeasureMapTool()); |
344 |
|
345 |
MeasureListener mli = new MeasureListener(m_MapControl);
|
346 |
m_MapControl.addTool("medicion", "medicion", mli); |
347 |
|
348 |
// Area
|
349 |
m_MapControl.addMapTool("area", new AreaMapTool()); |
350 |
|
351 |
AreaListener ali = new AreaListener(m_MapControl);
|
352 |
m_MapControl.addTool("area", "area", ali); |
353 |
|
354 |
//Seleccion por punto
|
355 |
PointSelectionListener psl = new PointSelectionListener(m_MapControl);
|
356 |
m_MapControl.addTool("pointSelection", "point", psl); |
357 |
|
358 |
//Info por punto
|
359 |
m_MapControl.addMapTool("info", new PointMapTool()); |
360 |
InfoListener il = new InfoListener(m_MapControl);
|
361 |
//il.setModel(modelo);
|
362 |
m_MapControl.addTool("info", "info", il); |
363 |
|
364 |
// Link por punto
|
365 |
m_MapControl.addMapTool("link", new PointMapTool()); |
366 |
LinkListener ll = new LinkListener(m_MapControl);
|
367 |
m_MapControl.addTool("link", "link", ll); |
368 |
|
369 |
//Selecci?n por rect?ngulo
|
370 |
m_MapControl.addMapTool("rectangle",
|
371 |
new RectangleMapTool());
|
372 |
RectangleSelectionListener rsl = new RectangleSelectionListener(m_MapControl);
|
373 |
m_MapControl.addTool("rectSelection", "rectangle", rsl); |
374 |
|
375 |
|
376 |
// Zoom por rect?ngulo
|
377 |
ZoomInListenerImpl zili = new ZoomInListenerImpl(m_MapControl);
|
378 |
m_MapControl.addTool("zoomIn", "rectangle", zili); |
379 |
|
380 |
m_MapControl.setTool("zoomIn"); // Por defecto |
381 |
} |
382 |
|
383 |
/**
|
384 |
* DOCUMENT ME!
|
385 |
*/
|
386 |
public void openPropertiesWindow() { |
387 |
} |
388 |
|
389 |
/**
|
390 |
* DOCUMENT ME!
|
391 |
*/
|
392 |
public void openQueryWindow() { |
393 |
} |
394 |
|
395 |
/**
|
396 |
* DOCUMENT ME!
|
397 |
*
|
398 |
* @return DOCUMENT ME!
|
399 |
*/
|
400 |
public MapOverview getMapOverview() {
|
401 |
return m_MapLoc;
|
402 |
} |
403 |
|
404 |
/**
|
405 |
* DOCUMENT ME!
|
406 |
*
|
407 |
* @return DOCUMENT ME!
|
408 |
*/
|
409 |
public NewMapControl getMapControl() {
|
410 |
return m_MapControl;
|
411 |
} |
412 |
|
413 |
/**
|
414 |
* DOCUMENT ME!
|
415 |
*
|
416 |
* @return DOCUMENT ME!
|
417 |
*/
|
418 |
public TOC getTOC() {
|
419 |
return m_TOC;
|
420 |
} |
421 |
|
422 |
/**
|
423 |
* DOCUMENT ME!
|
424 |
*
|
425 |
* @return DOCUMENT ME!
|
426 |
*/
|
427 |
public String getViewName() { |
428 |
return ""; |
429 |
} |
430 |
|
431 |
/**
|
432 |
* DOCUMENT ME!
|
433 |
*
|
434 |
* @param viewName DOCUMENT ME!
|
435 |
*/
|
436 |
public void setViewName(String viewName) { |
437 |
} |
438 |
|
439 |
/**
|
440 |
* DOCUMENT ME!
|
441 |
*/
|
442 |
public void repaintMap() { |
443 |
m_MapControl.drawMap(); |
444 |
} |
445 |
|
446 |
/* (non-Javadoc)
|
447 |
* @see com.iver.mdiApp.ui.MDIManager.SingletonView#getModel()
|
448 |
*/
|
449 |
public Object getViewModel() { |
450 |
return modelo;
|
451 |
} |
452 |
|
453 |
/**
|
454 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
455 |
*/
|
456 |
public ViewInfo getViewInfo() {
|
457 |
ViewInfo m_viewInfo = new ViewInfo(ViewInfo.ICONIFIABLE | ViewInfo.RESIZABLE |
|
458 |
ViewInfo.MAXIMIZABLE); |
459 |
|
460 |
m_viewInfo.setWidth(500);
|
461 |
m_viewInfo.setHeight(300);
|
462 |
m_viewInfo.setTitle(PluginServices.getText(this, "Vista") + " : " + |
463 |
modelo.getName()); |
464 |
|
465 |
return m_viewInfo;
|
466 |
|
467 |
} |
468 |
|
469 |
/**
|
470 |
* @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
|
471 |
*/
|
472 |
public void viewActivated() { |
473 |
// getMapControl().status = MapControl.DESACTUALIZADO;
|
474 |
// getMapControl().repaint();
|
475 |
} |
476 |
|
477 |
/**
|
478 |
* @return
|
479 |
*/
|
480 |
public BufferedImage getImage() { |
481 |
return m_MapControl.getImage();
|
482 |
} |
483 |
|
484 |
public class ViewExceptionListener implements ExceptionListener { |
485 |
|
486 |
/**
|
487 |
* @see com.iver.cit.gvsig.fmap.ExceptionListener#exceptionThrown(java.lang.Throwable)
|
488 |
*/
|
489 |
public void exceptionThrown(Throwable t) { |
490 |
NotificationManager.addError(t.getMessage(), t); |
491 |
} |
492 |
|
493 |
} |
494 |
} |