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