root / tags / gvSIGv0_6_1RELEASE / applications / appgvSIG / src / com / iver / cit / gvsig / gui / View.java @ 5222
History | View | Annotate | Download (13.8 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.Component; |
46 |
import java.awt.Dimension; |
47 |
import java.awt.image.BufferedImage; |
48 |
import java.beans.PropertyChangeEvent; |
49 |
import java.beans.PropertyChangeListener; |
50 |
|
51 |
|
52 |
import javax.swing.JOptionPane; |
53 |
import javax.swing.JPanel; |
54 |
import javax.swing.JScrollPane; |
55 |
import javax.swing.JSplitPane; |
56 |
|
57 |
import org.cresques.cts.IProjection; |
58 |
|
59 |
import com.iver.andami.PluginServices; |
60 |
import com.iver.andami.messages.NotificationManager; |
61 |
import com.iver.andami.ui.mdiManager.MDIManager; |
62 |
import com.iver.andami.ui.mdiManager.SingletonView; |
63 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
64 |
import com.iver.andami.ui.mdiManager.ViewListener; |
65 |
import com.iver.cit.gvsig.fmap.ColorEvent; |
66 |
import com.iver.cit.gvsig.fmap.ErrorEvent; |
67 |
import com.iver.cit.gvsig.fmap.ErrorListener; |
68 |
import com.iver.cit.gvsig.fmap.ExtentEvent; |
69 |
import com.iver.cit.gvsig.fmap.FMap; |
70 |
import com.iver.cit.gvsig.fmap.MapControl; |
71 |
import com.iver.cit.gvsig.fmap.ViewPortListener; |
72 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
73 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
74 |
import com.iver.cit.gvsig.fmap.tools.ZoomOutRightButtonListener; |
75 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
76 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior; |
77 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MoveBehavior; |
78 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior; |
79 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PolygonBehavior; |
80 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PolylineBehavior; |
81 |
import com.iver.cit.gvsig.fmap.tools.Behavior.RectangleBehavior; |
82 |
import com.iver.cit.gvsig.gui.thememanager.FThemeManagerWindow; |
83 |
import com.iver.cit.gvsig.gui.toc.TOC; |
84 |
import com.iver.cit.gvsig.gui.toolListeners.AreaListener; |
85 |
import com.iver.cit.gvsig.gui.toolListeners.InfoListener; |
86 |
import com.iver.cit.gvsig.gui.toolListeners.LinkListener; |
87 |
import com.iver.cit.gvsig.gui.toolListeners.MeasureListener; |
88 |
import com.iver.cit.gvsig.gui.toolListeners.PanListener; |
89 |
import com.iver.cit.gvsig.gui.toolListeners.PointSelectListener; |
90 |
import com.iver.cit.gvsig.gui.toolListeners.RectangleSelectListener; |
91 |
import com.iver.cit.gvsig.gui.toolListeners.SaveRasterListener; |
92 |
import com.iver.cit.gvsig.gui.toolListeners.SelectImageListener; |
93 |
import com.iver.cit.gvsig.gui.toolListeners.StatusBarListener; |
94 |
import com.iver.cit.gvsig.gui.toolListeners.ZoomInListener; |
95 |
import com.iver.cit.gvsig.gui.toolListeners.ZoomOutListener; |
96 |
import com.iver.cit.gvsig.gui.toolListeners.ZoomPixelCursorListener; |
97 |
import com.iver.cit.gvsig.project.ProjectView; |
98 |
import com.iver.utiles.exceptionHandling.ExceptionListener; |
99 |
|
100 |
|
101 |
/**
|
102 |
* DOCUMENT ME!
|
103 |
*
|
104 |
* @author vcn
|
105 |
*/
|
106 |
public class View extends JPanel implements com.iver.andami.ui.mdiManager.View, |
107 |
SingletonView,ViewListener, IView{ |
108 |
|
109 |
/** DOCUMENT ME! */
|
110 |
private MapControl m_MapControl;
|
111 |
private MapOverview m_MapLoc;
|
112 |
|
113 |
|
114 |
// store the properties of the window
|
115 |
private ViewInfo m_viewInfo = null; |
116 |
|
117 |
/** DOCUMENT ME! */
|
118 |
private FThemePropertiesDialog m_Themeproperties;
|
119 |
private FThemeManagerWindow fThemeManagerWindow;
|
120 |
private JScrollPane jscrollTOC; |
121 |
private TOC m_TOC;
|
122 |
private ProjectView modelo;
|
123 |
private Table table = null; |
124 |
private ViewExceptionListener mapControlExceptionListener = new ViewExceptionListener(); |
125 |
|
126 |
private class MyError implements ErrorListener |
127 |
{ |
128 |
|
129 |
public void errorThrown(ErrorEvent e) { |
130 |
|
131 |
System.err.println("View#ErrorListener: " + e.getMessage()); |
132 |
|
133 |
JOptionPane.showMessageDialog(
|
134 |
(Component)PluginServices.getMainFrame(),
|
135 |
PluginServices.getText(this,"fallo_capas")+" : \n"+ e.getMessage() |
136 |
); |
137 |
|
138 |
} |
139 |
|
140 |
} |
141 |
|
142 |
/**
|
143 |
/**
|
144 |
* Creates a new View object.
|
145 |
*/
|
146 |
public View() { |
147 |
//this.setName(Utilities.getMessage(this, "Vista")+ " : "+modelo.getName());
|
148 |
// this.setPreferredSize(new Dimension(500, 300));
|
149 |
initComponents(); |
150 |
} |
151 |
|
152 |
/**
|
153 |
* DOCUMENT ME!
|
154 |
*
|
155 |
* @return DOCUMENT ME!
|
156 |
*/
|
157 |
public ProjectView getModel() {
|
158 |
return modelo;
|
159 |
} |
160 |
|
161 |
/**
|
162 |
* DOCUMENT ME!
|
163 |
*
|
164 |
* @param model DOCUMENT ME!
|
165 |
*/
|
166 |
public void setModel(ProjectView model) { |
167 |
this.modelo = model;
|
168 |
//Se registra como listener de cambios en FMap
|
169 |
FMap fmap = modelo.getMapContext(); |
170 |
|
171 |
fmap.addErrorListener(new MyError());
|
172 |
|
173 |
model.setAndamiView(this);
|
174 |
|
175 |
//Se configura el mapControl
|
176 |
m_MapControl.setMapContext(fmap); |
177 |
m_TOC.setMapContext(fmap); |
178 |
m_MapControl.setBackground(new Color(255, 255, 255)); |
179 |
if (modelo.getMapOverViewContext()!=null){ |
180 |
m_MapLoc.setModel(modelo.getMapOverViewContext()); |
181 |
} |
182 |
model.addPropertyChangeListener(new PropertyChangeListener() { |
183 |
public void propertyChange(PropertyChangeEvent evt) { |
184 |
if (evt.getPropertyName().equals("name")){ |
185 |
PluginServices.getMDIManager().getViewInfo(View.this).setTitle("Vista: " + (String)evt.getNewValue()); |
186 |
} |
187 |
} |
188 |
}); |
189 |
if (m_MapControl.getViewPort() != null){ |
190 |
m_MapControl.getViewPort().addViewPortListener(new ViewPortListener() {
|
191 |
public void extentChanged(ExtentEvent e) { |
192 |
if (PluginServices.getMainFrame() != null){ |
193 |
PluginServices.getMainFrame().getStatusBar().setMessage("6", "1:"+m_MapControl.getMapContext().getScaleView()); |
194 |
PluginServices.getMainFrame().getStatusBar().setMessage("7", getMapControl().getViewPort().getProjection().getAbrev());
|
195 |
} |
196 |
} |
197 |
|
198 |
public void backColorChanged(ColorEvent e) { |
199 |
} |
200 |
}); |
201 |
} |
202 |
} |
203 |
|
204 |
/**
|
205 |
* DOCUMENT ME!
|
206 |
*/
|
207 |
private void initComponents() { //GEN-BEGIN:initComponents |
208 |
m_MapControl = new MapControl(); //Default is paintEnabled = false. Remember to activate it |
209 |
m_MapControl.addExceptionListener(mapControlExceptionListener); |
210 |
// modelo.setMapContext(m_MapControl.getMapContext());
|
211 |
|
212 |
// m_MapControl.setAcceptEvents(true); Lo comento porque ya se hace en el setModel
|
213 |
m_TOC = new TOC();
|
214 |
|
215 |
JSplitPane tempMainSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); |
216 |
tempMainSplit.setPreferredSize(new Dimension(500, 300)); |
217 |
|
218 |
// Ponemos el localizador
|
219 |
m_MapLoc = new MapOverview(m_MapControl);
|
220 |
m_MapLoc.setPreferredSize(new Dimension(150, 200)); |
221 |
JSplitPane tempSplitToc = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
222 |
|
223 |
tempSplitToc.setTopComponent((TOC) m_TOC); |
224 |
tempSplitToc.setBottomComponent(m_MapLoc); |
225 |
tempSplitToc.setResizeWeight(0.7);
|
226 |
|
227 |
// tempSplitToc.resetToPreferredSizes();
|
228 |
tempMainSplit.setLeftComponent(tempSplitToc); |
229 |
|
230 |
m_TOC.setVisible(true);
|
231 |
|
232 |
// m_TOC.setPreferredSize(new Dimension(150,50));
|
233 |
tempMainSplit.setRightComponent(m_MapControl); |
234 |
this.setLayout(new BorderLayout()); |
235 |
this.add(tempMainSplit, BorderLayout.CENTER); |
236 |
|
237 |
//Listener de eventos de movimiento que pone las coordenadas del rat?n en la barra de estado
|
238 |
StatusBarListener sbl = new StatusBarListener(m_MapControl);
|
239 |
|
240 |
// Zoom out (pinchas y el mapa se centra y te muestra m?s).
|
241 |
// No es dibujando un rect?ngulo, es solo pinchando.
|
242 |
|
243 |
ZoomOutListener zol = new ZoomOutListener(m_MapControl);
|
244 |
m_MapControl.addMapTool("zoomOut", new Behavior[]{new PointBehavior(zol), new MouseMovementBehavior(sbl)}); |
245 |
|
246 |
// pan
|
247 |
|
248 |
PanListener pl = new PanListener(m_MapControl);
|
249 |
m_MapControl.addMapTool("pan", new Behavior[]{new MoveBehavior(pl), new MouseMovementBehavior(sbl)}); |
250 |
|
251 |
// Medir
|
252 |
|
253 |
MeasureListener mli = new MeasureListener(m_MapControl);
|
254 |
m_MapControl.addMapTool("medicion", new Behavior[]{new PolylineBehavior(mli), new MouseMovementBehavior(sbl)}); |
255 |
|
256 |
// Area
|
257 |
|
258 |
AreaListener ali = new AreaListener(m_MapControl);
|
259 |
m_MapControl.addMapTool("area", new Behavior[]{new PolygonBehavior(ali), new MouseMovementBehavior(sbl)}); |
260 |
|
261 |
//Seleccion por punto
|
262 |
PointSelectListener psl = new PointSelectListener(m_MapControl);
|
263 |
m_MapControl.addMapTool("pointSelection", new Behavior[]{new PointBehavior(psl), new MouseMovementBehavior(sbl)}); |
264 |
|
265 |
//Info por punto
|
266 |
InfoListener il = new InfoListener(m_MapControl);
|
267 |
m_MapControl.addMapTool("info", new Behavior[]{new PointBehavior(il), new MouseMovementBehavior(sbl)}); |
268 |
|
269 |
// Link por punto
|
270 |
LinkListener ll = new LinkListener(m_MapControl);
|
271 |
m_MapControl.addMapTool("link", new Behavior[]{new PointBehavior(ll), new MouseMovementBehavior(sbl)}); |
272 |
|
273 |
//Selecci?n por rect?ngulo
|
274 |
RectangleSelectListener rsl = new RectangleSelectListener(m_MapControl);
|
275 |
m_MapControl.addMapTool("rectSelection", new Behavior[]{new RectangleBehavior(rsl), new MouseMovementBehavior(sbl)}); |
276 |
|
277 |
// Zoom por rect?ngulo
|
278 |
ZoomOutRightButtonListener zoil = new ZoomOutRightButtonListener(m_MapControl);
|
279 |
ZoomInListener zil = new ZoomInListener(m_MapControl);
|
280 |
m_MapControl.addMapTool("zoomIn", new Behavior[]{new RectangleBehavior(zil), |
281 |
new PointBehavior(zoil), new MouseMovementBehavior(sbl)}); |
282 |
|
283 |
//Salvar a Raster
|
284 |
SaveRasterListener srl = new SaveRasterListener(m_MapControl);
|
285 |
m_MapControl.addMapTool("saveRaster", new Behavior[]{ |
286 |
new RectangleBehavior(srl), new MouseMovementBehavior(sbl)}); |
287 |
|
288 |
SelectImageListener sil = new SelectImageListener(m_MapControl);
|
289 |
m_MapControl.addMapTool("selectImage", new Behavior[]{ |
290 |
new PointBehavior(sil), new MouseMovementBehavior(sbl)}); |
291 |
|
292 |
ZoomPixelCursorListener zp = new ZoomPixelCursorListener(m_MapControl);
|
293 |
m_MapControl.addMapTool("zoom_pixel_cursor", new Behavior[]{new PointBehavior(zp), new MouseMovementBehavior(sbl)}); |
294 |
|
295 |
m_MapControl.setTool("zoomIn"); // Por defecto |
296 |
// m_MapControl.setPaintEnabled(true);
|
297 |
} |
298 |
|
299 |
/**
|
300 |
* DOCUMENT ME!
|
301 |
*/
|
302 |
/*public void openPropertiesWindow() {
|
303 |
}
|
304 |
*/
|
305 |
/**
|
306 |
* DOCUMENT ME!
|
307 |
*/
|
308 |
/* public void openQueryWindow() {
|
309 |
}
|
310 |
*/
|
311 |
/**
|
312 |
* DOCUMENT ME!
|
313 |
*
|
314 |
* @return DOCUMENT ME!
|
315 |
*/
|
316 |
public MapOverview getMapOverview() {
|
317 |
return m_MapLoc;
|
318 |
} |
319 |
|
320 |
/**
|
321 |
* DOCUMENT ME!
|
322 |
*
|
323 |
* @return DOCUMENT ME!
|
324 |
*/
|
325 |
public MapControl getMapControl() {
|
326 |
return m_MapControl;
|
327 |
} |
328 |
|
329 |
/**
|
330 |
* DOCUMENT ME!
|
331 |
*
|
332 |
* @return DOCUMENT ME!
|
333 |
*/
|
334 |
public TOC getTOC() {
|
335 |
return m_TOC;
|
336 |
} |
337 |
|
338 |
/**
|
339 |
* DOCUMENT ME!
|
340 |
*/
|
341 |
public void repaintMap() { |
342 |
m_MapControl.drawMap(false);
|
343 |
} |
344 |
|
345 |
/* (non-Javadoc)
|
346 |
* @see com.iver.mdiApp.ui.MDIManager.SingletonView#getModel()
|
347 |
*/
|
348 |
public Object getViewModel() { |
349 |
return modelo;
|
350 |
} |
351 |
|
352 |
/**
|
353 |
* This method is used to get <strong>an initial</strong> ViewInfo object
|
354 |
* for this View. It is not intended to retrieve the ViewInfo object in a
|
355 |
* later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
|
356 |
* to retrieve the ViewInfo object at any time after the creation of the
|
357 |
* object.
|
358 |
*
|
359 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
360 |
*/
|
361 |
public ViewInfo getViewInfo() {
|
362 |
if (m_viewInfo == null) |
363 |
{ |
364 |
m_viewInfo = new ViewInfo(ViewInfo.ICONIFIABLE | ViewInfo.RESIZABLE |
|
365 |
ViewInfo.MAXIMIZABLE); |
366 |
|
367 |
m_viewInfo.setWidth(500);
|
368 |
m_viewInfo.setHeight(300);
|
369 |
m_viewInfo.setTitle(PluginServices.getText(this, "Vista") + " : " + |
370 |
modelo.getName()); |
371 |
} |
372 |
return m_viewInfo;
|
373 |
} |
374 |
|
375 |
/**
|
376 |
* @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
|
377 |
*/
|
378 |
public void viewActivated() { |
379 |
PluginServices.getMainFrame().getStatusBar().setMessage("1",
|
380 |
FConstant.NAMES[getMapControl().getMapContext().getViewPort().getDistanceUnits()]); |
381 |
PluginServices.getMainFrame().getStatusBar().setMessage("6", "1:"+m_MapControl.getMapContext().getScaleView()); |
382 |
PluginServices.getMainFrame().getStatusBar().setMessage("7", getMapControl().getViewPort().getProjection().getAbrev());
|
383 |
} |
384 |
|
385 |
/**
|
386 |
* @return
|
387 |
*/
|
388 |
public BufferedImage getImage() { |
389 |
return m_MapControl.getImage();
|
390 |
} |
391 |
|
392 |
public void setProjection(IProjection proj) |
393 |
{ |
394 |
getMapControl().setProjection(proj); |
395 |
} |
396 |
public IProjection getProjection()
|
397 |
{ |
398 |
return getMapControl().getProjection();
|
399 |
} |
400 |
|
401 |
public class ViewExceptionListener implements ExceptionListener { |
402 |
|
403 |
/**
|
404 |
* @see com.iver.cit.gvsig.fmap.ExceptionListener#exceptionThrown(java.lang.Throwable)
|
405 |
*/
|
406 |
public void exceptionThrown(Throwable t) { |
407 |
NotificationManager.addError(t.getMessage(), t); |
408 |
} |
409 |
|
410 |
} |
411 |
|
412 |
/**
|
413 |
* @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
|
414 |
*/
|
415 |
public void viewClosed() { |
416 |
///PluginServices.getMainFrame().getStatusBar().setMessage("1","");
|
417 |
} |
418 |
|
419 |
} |