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