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