root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / View.java @ 1669
History | View | Annotate | Download (13.2 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 |
|
50 |
import javax.swing.JPanel; |
51 |
import javax.swing.JScrollPane; |
52 |
import javax.swing.JSplitPane; |
53 |
|
54 |
import org.cresques.cts.IProjection; |
55 |
|
56 |
import com.iver.andami.PluginServices; |
57 |
import com.iver.andami.messages.NotificationManager; |
58 |
import com.iver.andami.ui.mdiManager.SingletonView; |
59 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
60 |
import com.iver.andami.ui.mdiManager.ViewListener; |
61 |
import com.iver.cit.gvsig.fmap.ColorEvent; |
62 |
import com.iver.cit.gvsig.fmap.ExtentEvent; |
63 |
import com.iver.cit.gvsig.fmap.FMap; |
64 |
import com.iver.cit.gvsig.fmap.MapControl; |
65 |
import com.iver.cit.gvsig.fmap.ViewPortListener; |
66 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
67 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
68 |
import com.iver.cit.gvsig.fmap.tools.CompoundBehavior; |
69 |
import com.iver.cit.gvsig.fmap.tools.ZoomOutRightButtonListener; |
70 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PolygonBehavior; |
71 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
72 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PolylineBehavior; |
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.RectangleBehavior; |
77 |
import com.iver.cit.gvsig.gui.thememanager.FThemeManagerWindow; |
78 |
import com.iver.cit.gvsig.gui.toc.TOC; |
79 |
import com.iver.cit.gvsig.gui.toolListeners.AreaListener; |
80 |
import com.iver.cit.gvsig.gui.toolListeners.InfoListener; |
81 |
import com.iver.cit.gvsig.gui.toolListeners.LinkListener; |
82 |
import com.iver.cit.gvsig.gui.toolListeners.MeasureListener; |
83 |
import com.iver.cit.gvsig.gui.toolListeners.PanListener; |
84 |
import com.iver.cit.gvsig.gui.toolListeners.PointSelectListener; |
85 |
import com.iver.cit.gvsig.gui.toolListeners.RectangleSelectListener; |
86 |
import com.iver.cit.gvsig.gui.toolListeners.StatusBarListener; |
87 |
import com.iver.cit.gvsig.gui.toolListeners.ZoomInListener; |
88 |
import com.iver.cit.gvsig.gui.toolListeners.ZoomOutListener; |
89 |
import com.iver.cit.gvsig.project.ProjectView; |
90 |
import com.iver.utiles.exceptionHandling.ExceptionListener; |
91 |
|
92 |
|
93 |
/**
|
94 |
* DOCUMENT ME!
|
95 |
*
|
96 |
* @author vcn
|
97 |
*/
|
98 |
public class View extends JPanel implements com.iver.andami.ui.mdiManager.View, |
99 |
SingletonView,ViewListener, IView{ |
100 |
|
101 |
/** DOCUMENT ME! */
|
102 |
private MapControl m_MapControl;
|
103 |
private MapOverview m_MapLoc;
|
104 |
|
105 |
/** DOCUMENT ME! */
|
106 |
private FThemePropertiesDialog m_Themeproperties;
|
107 |
private FThemeManagerWindow fThemeManagerWindow;
|
108 |
private JScrollPane jscrollTOC; |
109 |
private TOC m_TOC;
|
110 |
private ProjectView modelo;
|
111 |
private Table table = null; |
112 |
private ViewExceptionListener mapControlExceptionListener = new ViewExceptionListener(); |
113 |
|
114 |
/**
|
115 |
* Creates a new View object.
|
116 |
*/
|
117 |
public View() { |
118 |
//this.setName(Utilities.getMessage(this, "Vista")+ " : "+modelo.getName());
|
119 |
this.setPreferredSize(new Dimension(500, 300)); |
120 |
initComponents(); |
121 |
} |
122 |
|
123 |
/**
|
124 |
* DOCUMENT ME!
|
125 |
*
|
126 |
* @return DOCUMENT ME!
|
127 |
*/
|
128 |
public ProjectView getModel() {
|
129 |
return modelo;
|
130 |
} |
131 |
|
132 |
/**
|
133 |
* DOCUMENT ME!
|
134 |
*
|
135 |
* @param model DOCUMENT ME!
|
136 |
*/
|
137 |
public void setModel(ProjectView model) { |
138 |
this.modelo = model;
|
139 |
|
140 |
//Se registra como listener de cambios en FMap
|
141 |
FMap fmap = modelo.getMapContext(); |
142 |
|
143 |
//Se configura el mapControl
|
144 |
m_MapControl.setMapContext(fmap); |
145 |
m_TOC.setMapContext(fmap); |
146 |
m_MapControl.setBackground(new Color(255, 255, 255)); |
147 |
if (modelo.getMapOverViewContext()!=null){ |
148 |
m_MapLoc.setModel(modelo.getMapOverViewContext()); |
149 |
} |
150 |
model.addPropertyChangeListener(new PropertyChangeListener() { |
151 |
public void propertyChange(PropertyChangeEvent evt) { |
152 |
if (evt.getPropertyName().equals("name")){ |
153 |
PluginServices.getMDIManager().getViewInfo(View.this).setTitle("Vista: " + (String)evt.getNewValue()); |
154 |
} |
155 |
} |
156 |
}); |
157 |
if (m_MapControl.getViewPort() != null){ |
158 |
m_MapControl.getViewPort().addViewPortListener(new ViewPortListener() {
|
159 |
public void extentChanged(ExtentEvent e) { |
160 |
if (PluginServices.getMainFrame() != null){ |
161 |
PluginServices.getMainFrame().getStatusBar().setMessage("6", "1:"+m_MapControl.getMapContext().getScaleView()); |
162 |
PluginServices.getMainFrame().getStatusBar().setMessage("7", getMapControl().getViewPort().getProjection().getAbrev());
|
163 |
} |
164 |
} |
165 |
|
166 |
public void backColorChanged(ColorEvent e) { |
167 |
} |
168 |
}); |
169 |
} |
170 |
} |
171 |
/**
|
172 |
* DOCUMENT ME!
|
173 |
*/
|
174 |
public void openThemeProperties() { |
175 |
FMap fmap = modelo.getMapContext(); |
176 |
FLayer[] actives = fmap.getLayers().getActives();
|
177 |
|
178 |
for (int i = 0; i < actives.length; i++){ |
179 |
m_Themeproperties = new FThemePropertiesDialog(actives[i], modelo);
|
180 |
PluginServices.getMDIManager().addView(m_Themeproperties); |
181 |
} |
182 |
} |
183 |
|
184 |
/**
|
185 |
* M?todo provisional para abrir el di?logo de propiedades del tema seg?n
|
186 |
* el pliego.
|
187 |
* @param mapa
|
188 |
*/
|
189 |
public void openPliegoThemeProperties() { |
190 |
FMap fMap = modelo.getMapContext(); |
191 |
FLayer[] actives = fMap.getLayers().getActives();
|
192 |
if (actives.length==1) { |
193 |
System.out.println("openPliegoThemeProperties(): Una sola capa. Abrimos el panel para la capa " + actives[0]); |
194 |
fThemeManagerWindow = new FThemeManagerWindow();
|
195 |
try {
|
196 |
fThemeManagerWindow.setMapContext(fMap); |
197 |
} catch (com.iver.cit.gvsig.fmap.DriverException e1) {
|
198 |
e1.printStackTrace(); |
199 |
} |
200 |
PluginServices.getMDIManager().addView(fThemeManagerWindow); |
201 |
} else {
|
202 |
for (int i = 0; i < actives.length; i++){ |
203 |
System.out.println("openPliegoThemeProperties(): Muchas capas. Abrimos el panel para la capa " + actives[i]); |
204 |
fThemeManagerWindow = new FThemeManagerWindow(actives[i], fMap);
|
205 |
PluginServices.getMDIManager().addView(fThemeManagerWindow); |
206 |
} |
207 |
} |
208 |
} |
209 |
|
210 |
/**
|
211 |
* DOCUMENT ME!
|
212 |
*/
|
213 |
private void initComponents() { //GEN-BEGIN:initComponents |
214 |
m_MapControl = new MapControl();
|
215 |
m_MapControl.addExceptionListener(mapControlExceptionListener); |
216 |
// modelo.setMapContext(m_MapControl.getMapContext());
|
217 |
|
218 |
// m_MapControl.setAcceptEvents(true); Lo comento porque ya se hace en el setModel
|
219 |
m_TOC = new TOC();
|
220 |
|
221 |
JSplitPane tempMainSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); |
222 |
tempMainSplit.setPreferredSize(new Dimension(500, 300)); |
223 |
|
224 |
// Ponemos el localizador
|
225 |
m_MapLoc = new MapOverview(m_MapControl);
|
226 |
m_MapLoc.setPreferredSize(new Dimension(150, 200)); |
227 |
JSplitPane tempSplitToc = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
228 |
|
229 |
tempSplitToc.setTopComponent((TOC) m_TOC); |
230 |
tempSplitToc.setBottomComponent(m_MapLoc); |
231 |
tempSplitToc.setResizeWeight(0.7);
|
232 |
|
233 |
// tempSplitToc.resetToPreferredSizes();
|
234 |
tempMainSplit.setLeftComponent(tempSplitToc); |
235 |
|
236 |
m_TOC.setVisible(true);
|
237 |
|
238 |
// m_TOC.setPreferredSize(new Dimension(150,50));
|
239 |
tempMainSplit.setRightComponent(m_MapControl); |
240 |
this.setLayout(new BorderLayout()); |
241 |
this.add(tempMainSplit, BorderLayout.CENTER); |
242 |
|
243 |
//Listener de eventos de movimiento que pone las coordenadas del rat?n en la barra de estado
|
244 |
StatusBarListener sbl = new StatusBarListener(m_MapControl);
|
245 |
|
246 |
// Zoom out (pinchas y el mapa se centra y te muestra m?s).
|
247 |
// No es dibujando un rect?ngulo, es solo pinchando.
|
248 |
|
249 |
ZoomOutListener zol = new ZoomOutListener(m_MapControl);
|
250 |
m_MapControl.addMapTool("zoomOut", new Behavior[]{new PointBehavior(zol), new MouseMovementBehavior(sbl)}); |
251 |
|
252 |
// pan
|
253 |
|
254 |
PanListener pl = new PanListener(m_MapControl);
|
255 |
m_MapControl.addMapTool("pan", new Behavior[]{new MoveBehavior(pl), new MouseMovementBehavior(sbl)}); |
256 |
|
257 |
// Medir
|
258 |
|
259 |
MeasureListener mli = new MeasureListener(m_MapControl);
|
260 |
m_MapControl.addMapTool("medicion", new Behavior[]{new PolylineBehavior(mli), new MouseMovementBehavior(sbl)}); |
261 |
|
262 |
// Area
|
263 |
|
264 |
AreaListener ali = new AreaListener(m_MapControl);
|
265 |
m_MapControl.addMapTool("area", new Behavior[]{new PolygonBehavior(ali), new MouseMovementBehavior(sbl)}); |
266 |
|
267 |
//Seleccion por punto
|
268 |
PointSelectListener psl = new PointSelectListener(m_MapControl);
|
269 |
m_MapControl.addMapTool("pointSelection", new Behavior[]{new PointBehavior(psl), new MouseMovementBehavior(sbl)}); |
270 |
|
271 |
//Info por punto
|
272 |
InfoListener il = new InfoListener(m_MapControl);
|
273 |
m_MapControl.addMapTool("info", new Behavior[]{new PointBehavior(il), new MouseMovementBehavior(sbl)}); |
274 |
|
275 |
// Link por punto
|
276 |
LinkListener ll = new LinkListener(m_MapControl);
|
277 |
m_MapControl.addMapTool("link", new Behavior[]{new PointBehavior(ll), new MouseMovementBehavior(sbl)}); |
278 |
|
279 |
//Selecci?n por rect?ngulo
|
280 |
RectangleSelectListener rsl = new RectangleSelectListener(m_MapControl);
|
281 |
m_MapControl.addMapTool("rectSelection", new Behavior[]{new RectangleBehavior(rsl), new MouseMovementBehavior(sbl)}); |
282 |
|
283 |
// Zoom por rect?ngulo
|
284 |
ZoomOutRightButtonListener zoil = new ZoomOutRightButtonListener(m_MapControl);
|
285 |
ZoomInListener zil = new ZoomInListener(m_MapControl);
|
286 |
m_MapControl.addMapTool("zoomIn", new Behavior[]{new RectangleBehavior(zil), |
287 |
new PointBehavior(zoil), new MouseMovementBehavior(sbl)}); |
288 |
|
289 |
m_MapControl.setTool("zoomIn"); // Por defecto |
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().getMapUnits()]); |
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 |
} |