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