svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / View.java @ 3718
History | View | Annotate | Download (15.6 KB)
1 |
/* 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; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Color; |
45 |
import java.awt.Dimension; |
46 |
import java.awt.image.BufferedImage; |
47 |
import java.beans.PropertyChangeEvent; |
48 |
import java.beans.PropertyChangeListener; |
49 |
import java.util.HashMap; |
50 |
import java.util.Iterator; |
51 |
|
52 |
import javax.swing.FocusManager; |
53 |
import javax.swing.JPanel; |
54 |
import javax.swing.JSplitPane; |
55 |
|
56 |
import org.cresques.cts.IProjection; |
57 |
|
58 |
import com.iver.andami.PluginServices; |
59 |
import com.iver.andami.messages.NotificationManager; |
60 |
import com.iver.andami.ui.mdiManager.SingletonView; |
61 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
62 |
import com.iver.andami.ui.mdiManager.ViewListener; |
63 |
import com.iver.cit.gvsig.fmap.ColorEvent; |
64 |
import com.iver.cit.gvsig.fmap.ExtentEvent; |
65 |
import com.iver.cit.gvsig.fmap.FMap; |
66 |
import com.iver.cit.gvsig.fmap.MapControl; |
67 |
import com.iver.cit.gvsig.fmap.ViewPortListener; |
68 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
69 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
70 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
71 |
import com.iver.cit.gvsig.fmap.tools.ZoomOutRightButtonListener; |
72 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
73 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior; |
74 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MoveBehavior; |
75 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior; |
76 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PolygonBehavior; |
77 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PolylineBehavior; |
78 |
import com.iver.cit.gvsig.fmap.tools.Behavior.RectangleBehavior; |
79 |
import com.iver.cit.gvsig.gui.toc.TOC; |
80 |
import com.iver.cit.gvsig.gui.toolListeners.AreaListener; |
81 |
import com.iver.cit.gvsig.gui.toolListeners.InfoListener; |
82 |
import com.iver.cit.gvsig.gui.toolListeners.LinkListener; |
83 |
import com.iver.cit.gvsig.gui.toolListeners.MeasureListener; |
84 |
import com.iver.cit.gvsig.gui.toolListeners.PanListener; |
85 |
import com.iver.cit.gvsig.gui.toolListeners.PointSelectListener; |
86 |
import com.iver.cit.gvsig.gui.toolListeners.RectangleSelectListener; |
87 |
import com.iver.cit.gvsig.gui.toolListeners.SaveRasterListener; |
88 |
import com.iver.cit.gvsig.gui.toolListeners.SelectImageListener; |
89 |
import com.iver.cit.gvsig.gui.toolListeners.StatusBarListener; |
90 |
import com.iver.cit.gvsig.gui.toolListeners.ZoomInListener; |
91 |
import com.iver.cit.gvsig.gui.toolListeners.ZoomOutListener; |
92 |
import com.iver.cit.gvsig.gui.toolListeners.ZoomPixelCursorListener; |
93 |
import com.iver.cit.gvsig.project.ProjectView; |
94 |
import com.iver.utiles.console.JConsole; |
95 |
import com.iver.utiles.console.ResponseListener; |
96 |
import com.iver.utiles.exceptionHandling.ExceptionListener; |
97 |
|
98 |
|
99 |
/**
|
100 |
* DOCUMENT ME!
|
101 |
*
|
102 |
* @author vcn
|
103 |
*/
|
104 |
public class View extends JPanel implements com.iver.andami.ui.mdiManager.View, |
105 |
SingletonView,ViewListener, IView{ |
106 |
|
107 |
/** DOCUMENT ME! */
|
108 |
private MapControl m_MapControl;
|
109 |
private MapOverview m_MapLoc;
|
110 |
|
111 |
/** DOCUMENT ME! */
|
112 |
private TOC m_TOC;
|
113 |
private ProjectView modelo;
|
114 |
private ViewExceptionListener mapControlExceptionListener = new ViewExceptionListener(); |
115 |
private JConsole console;
|
116 |
private ResponseAdapter consoleResponseAdapter = new ResponseAdapter(); |
117 |
/**
|
118 |
* Creates a new View object.
|
119 |
*/
|
120 |
public View() { |
121 |
//this.setName(Utilities.getMessage(this, "Vista")+ " : "+modelo.getName());
|
122 |
// this.setPreferredSize(new Dimension(500, 300));
|
123 |
initComponents(); |
124 |
hideConsole(); |
125 |
} |
126 |
|
127 |
/**
|
128 |
* DOCUMENT ME!
|
129 |
*
|
130 |
* @return DOCUMENT ME!
|
131 |
*/
|
132 |
public ProjectView getModel() {
|
133 |
return modelo;
|
134 |
} |
135 |
|
136 |
/**
|
137 |
* DOCUMENT ME!
|
138 |
*
|
139 |
* @param model DOCUMENT ME!
|
140 |
*/
|
141 |
public void setModel(ProjectView model) { |
142 |
this.modelo = model;
|
143 |
//Se registra como listener de cambios en FMap
|
144 |
FMap fmap = modelo.getMapContext(); |
145 |
|
146 |
FLayers layers=fmap.getLayers(); |
147 |
for (int i=0;i<layers.getLayersCount();i++){ |
148 |
if (layers.getLayer(i).isEditing() && layers.getLayer(i) instanceof FLyrVect){ |
149 |
this.showConsole();
|
150 |
} |
151 |
} |
152 |
|
153 |
//Se configura el mapControl
|
154 |
m_MapControl.setMapContext(fmap); |
155 |
m_TOC.setMapContext(fmap); |
156 |
m_MapControl.setBackground(new Color(255, 255, 255)); |
157 |
if (modelo.getMapOverViewContext()!=null){ |
158 |
m_MapLoc.setModel(modelo.getMapOverViewContext()); |
159 |
} |
160 |
model.addPropertyChangeListener(new PropertyChangeListener() { |
161 |
public void propertyChange(PropertyChangeEvent evt) { |
162 |
if (evt.getPropertyName().equals("name")){ |
163 |
PluginServices.getMDIManager().getViewInfo(View.this).setTitle("Vista: " + (String)evt.getNewValue()); |
164 |
} |
165 |
} |
166 |
}); |
167 |
if (m_MapControl.getViewPort() != null){ |
168 |
m_MapControl.getViewPort().addViewPortListener(new ViewPortListener() {
|
169 |
public void extentChanged(ExtentEvent e) { |
170 |
if (PluginServices.getMainFrame() != null){ |
171 |
PluginServices.getMainFrame().getStatusBar().setMessage("6", "1:"+m_MapControl.getMapContext().getScaleView()); |
172 |
PluginServices.getMainFrame().getStatusBar().setMessage("7", getMapControl().getViewPort().getProjection().getAbrev());
|
173 |
} |
174 |
} |
175 |
|
176 |
public void backColorChanged(ColorEvent e) { |
177 |
} |
178 |
}); |
179 |
} |
180 |
} |
181 |
public JConsole getConsolePanel(){
|
182 |
if (console==null){ |
183 |
console=new JConsole();
|
184 |
} |
185 |
return console;
|
186 |
} |
187 |
|
188 |
|
189 |
public void addConsoleListener(String prefix, ResponseListener listener) { |
190 |
consoleResponseAdapter.putSpaceListener(prefix, listener); |
191 |
|
192 |
} |
193 |
|
194 |
public void removeConsoleListener(ResponseListener listener) { |
195 |
consoleResponseAdapter.deleteListener(listener); |
196 |
|
197 |
} |
198 |
|
199 |
public void focusConsole(String text) { |
200 |
getConsolePanel().addResponseText(text); |
201 |
FocusManager fm=FocusManager.getCurrentManager(); |
202 |
fm.focusNextComponent(getConsolePanel()); |
203 |
|
204 |
} |
205 |
|
206 |
public void hideConsole() { |
207 |
removeAll(); |
208 |
//JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
|
209 |
JSplitPane tempMainSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); |
210 |
tempMainSplit.setPreferredSize(new Dimension(500, 300)); |
211 |
JSplitPane tempSplitToc = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
212 |
|
213 |
tempSplitToc.setTopComponent((TOC) m_TOC); |
214 |
tempSplitToc.setBottomComponent(m_MapLoc); |
215 |
tempSplitToc.setResizeWeight(0.7);
|
216 |
tempMainSplit.setLeftComponent(tempSplitToc); |
217 |
|
218 |
m_TOC.setVisible(true);
|
219 |
tempMainSplit.setRightComponent(m_MapControl); |
220 |
//split.setBottomComponent(getConsolePanel());
|
221 |
//split.setTopComponent(tempMainSplit);
|
222 |
// split.setResizeWeight(0.9);
|
223 |
this.setLayout(new BorderLayout()); |
224 |
this.add(tempMainSplit, BorderLayout.CENTER); |
225 |
|
226 |
} |
227 |
|
228 |
public void showConsole() { |
229 |
removeAll(); |
230 |
JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
231 |
JSplitPane tempMainSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); |
232 |
tempMainSplit.setPreferredSize(new Dimension(500, 300)); |
233 |
JSplitPane tempSplitToc = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
234 |
|
235 |
tempSplitToc.setTopComponent((TOC) m_TOC); |
236 |
tempSplitToc.setBottomComponent(m_MapLoc); |
237 |
tempSplitToc.setResizeWeight(0.7);
|
238 |
tempMainSplit.setLeftComponent(tempSplitToc); |
239 |
|
240 |
m_TOC.setVisible(true);
|
241 |
tempMainSplit.setRightComponent(m_MapControl); |
242 |
split.setBottomComponent(getConsolePanel()); |
243 |
split.setTopComponent(tempMainSplit); |
244 |
split.setResizeWeight(0.9);
|
245 |
this.setLayout(new BorderLayout()); |
246 |
this.add(split, BorderLayout.CENTER); |
247 |
|
248 |
} |
249 |
private class ResponseAdapter implements ResponseListener{ |
250 |
|
251 |
private HashMap spaceListener = new HashMap(); |
252 |
|
253 |
public void putSpaceListener(String namespace, ResponseListener listener){ |
254 |
spaceListener.put(namespace, listener); |
255 |
} |
256 |
|
257 |
/**
|
258 |
* @see com.iver.utiles.console.ResponseListener#acceptResponse(java.lang.String)
|
259 |
*/
|
260 |
public void acceptResponse(String response) { |
261 |
boolean nameSpace = false; |
262 |
int n = -1; |
263 |
if (response != null){ |
264 |
if ((n = response.indexOf(':')) != -1){ |
265 |
nameSpace = true;
|
266 |
} |
267 |
} |
268 |
|
269 |
if (nameSpace){
|
270 |
ResponseListener listener = (ResponseListener) spaceListener.get(response.substring(0, n));
|
271 |
if (listener != null) |
272 |
listener.acceptResponse(response.substring(n+1));
|
273 |
}else{
|
274 |
Iterator i = spaceListener.values().iterator();
|
275 |
while (i.hasNext()) {
|
276 |
ResponseListener listener = (ResponseListener) i.next(); |
277 |
listener.acceptResponse(response); |
278 |
} |
279 |
} |
280 |
} |
281 |
|
282 |
/**
|
283 |
* @param listener
|
284 |
*/
|
285 |
public void deleteListener(ResponseListener listener) { |
286 |
Iterator i = spaceListener.keySet().iterator();
|
287 |
while (i.hasNext()) {
|
288 |
String namespace = (String) i.next(); |
289 |
ResponseListener l = (ResponseListener) spaceListener.get(namespace); |
290 |
if (l == listener){
|
291 |
spaceListener.remove(namespace); |
292 |
} |
293 |
} |
294 |
} |
295 |
|
296 |
} |
297 |
|
298 |
|
299 |
|
300 |
|
301 |
/**
|
302 |
* DOCUMENT ME!
|
303 |
*/
|
304 |
private void initComponents() { // GEN-BEGIN:initComponents |
305 |
m_MapControl = new MapControl(); // Default is paintEnabled = false. |
306 |
// Remember to activate it
|
307 |
m_MapControl.addExceptionListener(mapControlExceptionListener); |
308 |
// modelo.setMapContext(m_MapControl.getMapContext());
|
309 |
|
310 |
// m_MapControl.setAcceptEvents(true); Lo comento porque ya se hace en el setModel
|
311 |
m_TOC = new TOC();
|
312 |
|
313 |
|
314 |
// Ponemos el localizador
|
315 |
m_MapLoc = new MapOverview(m_MapControl);
|
316 |
m_MapLoc.setPreferredSize(new Dimension(150, 200)); |
317 |
hideConsole(); |
318 |
|
319 |
|
320 |
|
321 |
|
322 |
//Listener de eventos de movimiento que pone las coordenadas del rat?n en la barra de estado
|
323 |
StatusBarListener sbl = new StatusBarListener(m_MapControl);
|
324 |
|
325 |
// Zoom out (pinchas y el mapa se centra y te muestra m?s).
|
326 |
// No es dibujando un rect?ngulo, es solo pinchando.
|
327 |
|
328 |
ZoomOutListener zol = new ZoomOutListener(m_MapControl);
|
329 |
m_MapControl.addMapTool("zoomOut", new Behavior[]{new PointBehavior(zol), new MouseMovementBehavior(sbl)}); |
330 |
|
331 |
// pan
|
332 |
|
333 |
PanListener pl = new PanListener(m_MapControl);
|
334 |
m_MapControl.addMapTool("pan", new Behavior[]{new MoveBehavior(pl), new MouseMovementBehavior(sbl)}); |
335 |
|
336 |
// Medir
|
337 |
|
338 |
MeasureListener mli = new MeasureListener(m_MapControl);
|
339 |
m_MapControl.addMapTool("medicion", new Behavior[]{new PolylineBehavior(mli), new MouseMovementBehavior(sbl)}); |
340 |
|
341 |
// Area
|
342 |
|
343 |
AreaListener ali = new AreaListener(m_MapControl);
|
344 |
m_MapControl.addMapTool("area", new Behavior[]{new PolygonBehavior(ali), new MouseMovementBehavior(sbl)}); |
345 |
|
346 |
//Seleccion por punto
|
347 |
PointSelectListener psl = new PointSelectListener(m_MapControl);
|
348 |
m_MapControl.addMapTool("pointSelection", new Behavior[]{new PointBehavior(psl), new MouseMovementBehavior(sbl)}); |
349 |
|
350 |
//Info por punto
|
351 |
InfoListener il = new InfoListener(m_MapControl);
|
352 |
m_MapControl.addMapTool("info", new Behavior[]{new PointBehavior(il), new MouseMovementBehavior(sbl)}); |
353 |
|
354 |
// Link por punto
|
355 |
LinkListener ll = new LinkListener(m_MapControl);
|
356 |
m_MapControl.addMapTool("link", new Behavior[]{new PointBehavior(ll), new MouseMovementBehavior(sbl)}); |
357 |
|
358 |
//Selecci?n por rect?ngulo
|
359 |
RectangleSelectListener rsl = new RectangleSelectListener(m_MapControl);
|
360 |
m_MapControl.addMapTool("rectSelection", new Behavior[]{new RectangleBehavior(rsl), new MouseMovementBehavior(sbl)}); |
361 |
|
362 |
// Zoom por rect?ngulo
|
363 |
ZoomOutRightButtonListener zoil = new ZoomOutRightButtonListener(m_MapControl);
|
364 |
ZoomInListener zil = new ZoomInListener(m_MapControl);
|
365 |
m_MapControl.addMapTool("zoomIn", new Behavior[]{new RectangleBehavior(zil), |
366 |
new PointBehavior(zoil), new MouseMovementBehavior(sbl)}); |
367 |
|
368 |
//Salvar a Raster
|
369 |
SaveRasterListener srl = new SaveRasterListener(m_MapControl);
|
370 |
m_MapControl.addMapTool("saveRaster", new Behavior[]{ |
371 |
new RectangleBehavior(srl), new MouseMovementBehavior(sbl)}); |
372 |
|
373 |
SelectImageListener sil = new SelectImageListener(m_MapControl);
|
374 |
m_MapControl.addMapTool("selectImage", new Behavior[]{ |
375 |
new PointBehavior(sil), new MouseMovementBehavior(sbl)}); |
376 |
|
377 |
ZoomPixelCursorListener zp = new ZoomPixelCursorListener(m_MapControl);
|
378 |
m_MapControl.addMapTool("zoom_pixel_cursor", new Behavior[]{new PointBehavior(zp), new MouseMovementBehavior(sbl)}); |
379 |
|
380 |
m_MapControl.setTool("zoomIn"); // Por defecto |
381 |
// m_MapControl.setPaintEnabled(true);
|
382 |
} |
383 |
|
384 |
/**
|
385 |
* DOCUMENT ME!
|
386 |
*/
|
387 |
/*public void openPropertiesWindow() {
|
388 |
}
|
389 |
*/
|
390 |
/**
|
391 |
* DOCUMENT ME!
|
392 |
*/
|
393 |
/* public void openQueryWindow() {
|
394 |
}
|
395 |
*/
|
396 |
/**
|
397 |
* DOCUMENT ME!
|
398 |
*
|
399 |
* @return DOCUMENT ME!
|
400 |
*/
|
401 |
public MapOverview getMapOverview() {
|
402 |
return m_MapLoc;
|
403 |
} |
404 |
|
405 |
/**
|
406 |
* DOCUMENT ME!
|
407 |
*
|
408 |
* @return DOCUMENT ME!
|
409 |
*/
|
410 |
public MapControl getMapControl() {
|
411 |
return m_MapControl;
|
412 |
} |
413 |
|
414 |
/**
|
415 |
* DOCUMENT ME!
|
416 |
*
|
417 |
* @return DOCUMENT ME!
|
418 |
*/
|
419 |
public TOC getTOC() {
|
420 |
return m_TOC;
|
421 |
} |
422 |
|
423 |
/**
|
424 |
* DOCUMENT ME!
|
425 |
*/
|
426 |
public void repaintMap() { |
427 |
m_MapControl.drawMap(false);
|
428 |
} |
429 |
|
430 |
/* (non-Javadoc)
|
431 |
* @see com.iver.mdiApp.ui.MDIManager.SingletonView#getModel()
|
432 |
*/
|
433 |
public Object getViewModel() { |
434 |
return modelo;
|
435 |
} |
436 |
|
437 |
/**
|
438 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
439 |
*/
|
440 |
public ViewInfo getViewInfo() {
|
441 |
ViewInfo m_viewInfo = new ViewInfo(ViewInfo.ICONIFIABLE | ViewInfo.RESIZABLE |
|
442 |
ViewInfo.MAXIMIZABLE); |
443 |
|
444 |
m_viewInfo.setWidth(500);
|
445 |
m_viewInfo.setHeight(300);
|
446 |
m_viewInfo.setTitle(PluginServices.getText(this, "Vista") + " : " + |
447 |
modelo.getName()); |
448 |
|
449 |
return m_viewInfo;
|
450 |
|
451 |
} |
452 |
|
453 |
/**
|
454 |
* @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
|
455 |
*/
|
456 |
public void viewActivated() { |
457 |
PluginServices.getMainFrame().getStatusBar().setMessage("1",
|
458 |
FConstant.NAMES[getMapControl().getMapContext().getViewPort().getDistanceUnits()]); |
459 |
PluginServices.getMainFrame().getStatusBar().setMessage("6", "1:"+m_MapControl.getMapContext().getScaleView()); |
460 |
PluginServices.getMainFrame().getStatusBar().setMessage("7", getMapControl().getViewPort().getProjection().getAbrev());
|
461 |
} |
462 |
|
463 |
/**
|
464 |
* @return
|
465 |
*/
|
466 |
public BufferedImage getImage() { |
467 |
return m_MapControl.getImage();
|
468 |
} |
469 |
|
470 |
public void setProjection(IProjection proj) |
471 |
{ |
472 |
getMapControl().setProjection(proj); |
473 |
} |
474 |
public IProjection getProjection()
|
475 |
{ |
476 |
return getMapControl().getProjection();
|
477 |
} |
478 |
|
479 |
public class ViewExceptionListener implements ExceptionListener { |
480 |
|
481 |
/**
|
482 |
* @see com.iver.cit.gvsig.fmap.ExceptionListener#exceptionThrown(java.lang.Throwable)
|
483 |
*/
|
484 |
public void exceptionThrown(Throwable t) { |
485 |
NotificationManager.addError(t.getMessage(), t); |
486 |
} |
487 |
|
488 |
} |
489 |
|
490 |
/**
|
491 |
* @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
|
492 |
*/
|
493 |
public void viewClosed() { |
494 |
///PluginServices.getMainFrame().getStatusBar().setMessage("1","");
|
495 |
} |
496 |
|
497 |
} |