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