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