root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / View.java @ 1062
History | View | Annotate | Download (10.8 KB)
1 |
package com.iver.cit.gvsig.gui; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Color; |
5 |
import java.awt.Dimension; |
6 |
import java.awt.image.BufferedImage; |
7 |
import java.beans.PropertyChangeEvent; |
8 |
import java.beans.PropertyChangeListener; |
9 |
|
10 |
import javax.swing.JPanel; |
11 |
import javax.swing.JScrollPane; |
12 |
import javax.swing.JSplitPane; |
13 |
|
14 |
import org.cresques.cts.IProjection; |
15 |
|
16 |
import com.iver.andami.PluginServices; |
17 |
import com.iver.andami.messages.NotificationManager; |
18 |
import com.iver.andami.ui.mdiManager.SingletonView; |
19 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
20 |
import com.iver.andami.ui.mdiManager.ViewListener; |
21 |
import com.iver.cit.gvsig.fmap.ColorEvent; |
22 |
import com.iver.cit.gvsig.fmap.ExtentEvent; |
23 |
import com.iver.cit.gvsig.fmap.FMap; |
24 |
import com.iver.cit.gvsig.fmap.NewMapControl; |
25 |
import com.iver.cit.gvsig.fmap.ViewPortListener; |
26 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
27 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
28 |
import com.iver.cit.gvsig.fmap.tools.CompoundBehavior; |
29 |
import com.iver.cit.gvsig.fmap.tools.ZoomOutIzqListener; |
30 |
import com.iver.cit.gvsig.fmap.tools.Behavior.AreaMapTool; |
31 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MapTool; |
32 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MeasureMapTool; |
33 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementMapTool; |
34 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MoveMapTool; |
35 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PointMapTool; |
36 |
import com.iver.cit.gvsig.fmap.tools.Behavior.RectangleMapTool; |
37 |
import com.iver.cit.gvsig.gui.toc.TOC; |
38 |
import com.iver.cit.gvsig.gui.toolListeners.AreaListener; |
39 |
import com.iver.cit.gvsig.gui.toolListeners.InfoListener; |
40 |
import com.iver.cit.gvsig.gui.toolListeners.LinkListener; |
41 |
import com.iver.cit.gvsig.gui.toolListeners.MeasureListener; |
42 |
import com.iver.cit.gvsig.gui.toolListeners.PanListener; |
43 |
import com.iver.cit.gvsig.gui.toolListeners.PointSelectListener; |
44 |
import com.iver.cit.gvsig.gui.toolListeners.RectangleSelectListener; |
45 |
import com.iver.cit.gvsig.gui.toolListeners.StatusBarListener; |
46 |
import com.iver.cit.gvsig.gui.toolListeners.ZoomInListener; |
47 |
import com.iver.cit.gvsig.gui.toolListeners.ZoomOutListener; |
48 |
import com.iver.cit.gvsig.project.castor.ProjectView; |
49 |
import com.iver.utiles.exceptionHandling.ExceptionListener; |
50 |
|
51 |
|
52 |
/**
|
53 |
* DOCUMENT ME!
|
54 |
*
|
55 |
* @author vcn
|
56 |
*/
|
57 |
public class View extends JPanel implements com.iver.andami.ui.mdiManager.View, |
58 |
SingletonView,ViewListener, IView { |
59 |
|
60 |
/** DOCUMENT ME! */
|
61 |
private NewMapControl m_MapControl;
|
62 |
private MapOverview m_MapLoc;
|
63 |
|
64 |
/** DOCUMENT ME! */
|
65 |
private FThemePropertiesDialog m_Themeproperties;
|
66 |
private JScrollPane jscrollTOC; |
67 |
private TOC m_TOC;
|
68 |
private ProjectView modelo;
|
69 |
private Table table = null; |
70 |
private ViewExceptionListener mapControlExceptionListener = new ViewExceptionListener(); |
71 |
|
72 |
/**
|
73 |
* Creates a new View object.
|
74 |
*/
|
75 |
public View() { |
76 |
//this.setName(Utilities.getMessage(this, "Vista")+ " : "+modelo.getName());
|
77 |
this.setPreferredSize(new Dimension(500, 300)); |
78 |
initComponents(); |
79 |
} |
80 |
|
81 |
/**
|
82 |
* DOCUMENT ME!
|
83 |
*
|
84 |
* @return DOCUMENT ME!
|
85 |
*/
|
86 |
public ProjectView getModel() {
|
87 |
return modelo;
|
88 |
} |
89 |
|
90 |
/**
|
91 |
* DOCUMENT ME!
|
92 |
*
|
93 |
* @param model DOCUMENT ME!
|
94 |
*/
|
95 |
public void setModel(ProjectView model) { |
96 |
this.modelo = model;
|
97 |
|
98 |
//Se registra como listener de cambios en FMap
|
99 |
FMap fmap = modelo.getMapContext(); |
100 |
|
101 |
//Se configura el mapControl
|
102 |
m_MapControl.setMapContext(fmap); |
103 |
m_TOC.setMapContext(fmap); |
104 |
m_MapControl.setBackground(new Color(255, 255, 255)); |
105 |
if (modelo.getMapOverViewContext()!=null){ |
106 |
m_MapLoc.setModel(modelo.getMapOverViewContext()); |
107 |
} |
108 |
model.addPropertyChangeListener(new PropertyChangeListener() { |
109 |
public void propertyChange(PropertyChangeEvent evt) { |
110 |
if (evt.getPropertyName().equals("name")){ |
111 |
PluginServices.getMDIManager().getViewInfo(View.this).setTitle("Vista: " + (String)evt.getNewValue()); |
112 |
} |
113 |
} |
114 |
}); |
115 |
|
116 |
if (m_MapControl.getViewPort() != null){ |
117 |
m_MapControl.getViewPort().addExtentListener(new ViewPortListener() {
|
118 |
/**
|
119 |
* @see com.iver.cit.gvsig.fmap.ViewPortListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
|
120 |
*/
|
121 |
public void extentChanged(ExtentEvent e) { |
122 |
if (PluginServices.getMainFrame() != null) |
123 |
PluginServices.getMainFrame().getStatusBar().setMessage("4","1:"+m_MapControl.getMapContext().getScaleView()); |
124 |
} |
125 |
|
126 |
/**
|
127 |
* @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
|
128 |
*/
|
129 |
public void backColorChanged(ColorEvent e) { |
130 |
} |
131 |
}); |
132 |
} |
133 |
} |
134 |
/**
|
135 |
* DOCUMENT ME!
|
136 |
*/
|
137 |
public void openThemeProperties() { |
138 |
FMap fmap = modelo.getMapContext(); |
139 |
FLayer[] actives = fmap.getLayers().getActives();
|
140 |
|
141 |
for (int i = 0; i < actives.length; i++){ |
142 |
m_Themeproperties = new FThemePropertiesDialog(actives[i], modelo);
|
143 |
PluginServices.getMDIManager().addView(m_Themeproperties); |
144 |
} |
145 |
} |
146 |
|
147 |
/**
|
148 |
* DOCUMENT ME!
|
149 |
*/
|
150 |
private void initComponents() { //GEN-BEGIN:initComponents |
151 |
m_MapControl = new NewMapControl();
|
152 |
m_MapControl.addExceptionListener(mapControlExceptionListener); |
153 |
// modelo.setMapContext(m_MapControl.getMapContext());
|
154 |
|
155 |
// m_MapControl.setAcceptEvents(true); Lo comento porque ya se hace en el setModel
|
156 |
m_TOC = new TOC();
|
157 |
|
158 |
JSplitPane tempMainSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); |
159 |
tempMainSplit.setPreferredSize(new Dimension(500, 300)); |
160 |
|
161 |
// Ponemos el localizador
|
162 |
m_MapLoc = new MapOverview(m_MapControl);
|
163 |
m_MapLoc.setPreferredSize(new Dimension(150, 200)); |
164 |
JSplitPane tempSplitToc = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
165 |
|
166 |
tempSplitToc.setTopComponent((TOC) m_TOC); |
167 |
tempSplitToc.setBottomComponent(m_MapLoc); |
168 |
tempSplitToc.setResizeWeight(0.7);
|
169 |
|
170 |
// tempSplitToc.resetToPreferredSizes();
|
171 |
tempMainSplit.setLeftComponent(tempSplitToc); |
172 |
|
173 |
m_TOC.setVisible(true);
|
174 |
|
175 |
// m_TOC.setPreferredSize(new Dimension(150,50));
|
176 |
tempMainSplit.setRightComponent(m_MapControl); |
177 |
this.setLayout(new BorderLayout()); |
178 |
this.add(tempMainSplit, BorderLayout.CENTER); |
179 |
|
180 |
//Listener de eventos de movimiento que pone las coordenadas del rat?n en la barra de estado
|
181 |
StatusBarListener sbl = new StatusBarListener(m_MapControl);
|
182 |
|
183 |
// Zoom out (pinchas y el mapa se centra y te muestra m?s).
|
184 |
// No es dibujando un rect?ngulo, es solo pinchando.
|
185 |
|
186 |
ZoomOutListener zol = new ZoomOutListener(m_MapControl);
|
187 |
m_MapControl.addMapTool("zoomOut", new MapTool[]{new PointMapTool(zol), new MouseMovementMapTool(sbl)}); |
188 |
|
189 |
// pan
|
190 |
|
191 |
PanListener pl = new PanListener(m_MapControl);
|
192 |
m_MapControl.addMapTool("pan", new MapTool[]{new MoveMapTool(pl), new MouseMovementMapTool(sbl)}); |
193 |
|
194 |
// Medir
|
195 |
|
196 |
MeasureListener mli = new MeasureListener(m_MapControl);
|
197 |
m_MapControl.addMapTool("medicion", new MapTool[]{new MeasureMapTool(mli), new MouseMovementMapTool(sbl)}); |
198 |
|
199 |
// Area
|
200 |
|
201 |
AreaListener ali = new AreaListener(m_MapControl);
|
202 |
m_MapControl.addMapTool("area", new MapTool[]{new AreaMapTool(ali), new MouseMovementMapTool(sbl)}); |
203 |
|
204 |
//Seleccion por punto
|
205 |
PointSelectListener psl = new PointSelectListener(m_MapControl);
|
206 |
m_MapControl.addMapTool("pointSelection", new MapTool[]{new PointMapTool(psl), new MouseMovementMapTool(sbl)}); |
207 |
|
208 |
//Info por punto
|
209 |
InfoListener il = new InfoListener(m_MapControl);
|
210 |
m_MapControl.addMapTool("info", new MapTool[]{new PointMapTool(il), new MouseMovementMapTool(sbl)}); |
211 |
|
212 |
// Link por punto
|
213 |
LinkListener ll = new LinkListener(m_MapControl);
|
214 |
m_MapControl.addMapTool("link", new MapTool[]{new PointMapTool(ll), new MouseMovementMapTool(sbl)}); |
215 |
|
216 |
//Selecci?n por rect?ngulo
|
217 |
RectangleSelectListener rsl = new RectangleSelectListener(m_MapControl);
|
218 |
m_MapControl.addMapTool("rectSelection", new MapTool[]{new RectangleMapTool(rsl), new MouseMovementMapTool(sbl)}); |
219 |
|
220 |
// Zoom por rect?ngulo
|
221 |
ZoomOutIzqListener zoil = new ZoomOutIzqListener(m_MapControl);
|
222 |
ZoomInListener zil = new ZoomInListener(m_MapControl);
|
223 |
m_MapControl.addMapTool("zoomIn", new MapTool[]{new RectangleMapTool(zil), |
224 |
new PointMapTool(zoil), new MouseMovementMapTool(sbl)}); |
225 |
|
226 |
m_MapControl.setTool("zoomIn"); // Por defecto |
227 |
} |
228 |
|
229 |
/**
|
230 |
* DOCUMENT ME!
|
231 |
*/
|
232 |
/*public void openPropertiesWindow() {
|
233 |
}
|
234 |
*/
|
235 |
/**
|
236 |
* DOCUMENT ME!
|
237 |
*/
|
238 |
/* public void openQueryWindow() {
|
239 |
}
|
240 |
*/
|
241 |
/**
|
242 |
* DOCUMENT ME!
|
243 |
*
|
244 |
* @return DOCUMENT ME!
|
245 |
*/
|
246 |
public MapOverview getMapOverview() {
|
247 |
return m_MapLoc;
|
248 |
} |
249 |
|
250 |
/**
|
251 |
* DOCUMENT ME!
|
252 |
*
|
253 |
* @return DOCUMENT ME!
|
254 |
*/
|
255 |
public NewMapControl getMapControl() {
|
256 |
return m_MapControl;
|
257 |
} |
258 |
|
259 |
/**
|
260 |
* DOCUMENT ME!
|
261 |
*
|
262 |
* @return DOCUMENT ME!
|
263 |
*/
|
264 |
public TOC getTOC() {
|
265 |
return m_TOC;
|
266 |
} |
267 |
|
268 |
/**
|
269 |
* DOCUMENT ME!
|
270 |
*/
|
271 |
public void repaintMap() { |
272 |
m_MapControl.drawMap(); |
273 |
} |
274 |
|
275 |
/* (non-Javadoc)
|
276 |
* @see com.iver.mdiApp.ui.MDIManager.SingletonView#getModel()
|
277 |
*/
|
278 |
public Object getViewModel() { |
279 |
return modelo;
|
280 |
} |
281 |
|
282 |
/**
|
283 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
284 |
*/
|
285 |
public ViewInfo getViewInfo() {
|
286 |
ViewInfo m_viewInfo = new ViewInfo(ViewInfo.ICONIFIABLE | ViewInfo.RESIZABLE |
|
287 |
ViewInfo.MAXIMIZABLE); |
288 |
|
289 |
m_viewInfo.setWidth(500);
|
290 |
m_viewInfo.setHeight(300);
|
291 |
m_viewInfo.setTitle(PluginServices.getText(this, "Vista") + " : " + |
292 |
modelo.getName()); |
293 |
|
294 |
return m_viewInfo;
|
295 |
|
296 |
} |
297 |
|
298 |
/**
|
299 |
* @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
|
300 |
*/
|
301 |
public void viewActivated() { |
302 |
PluginServices.getMainFrame().getStatusBar().setMessage("1",
|
303 |
FConstant.NAMES[getMapControl().getMapContext().getViewPort().getMapUnits()]); |
304 |
System.out.println("---------- 1 "+ FConstant.NAMES[getMapControl().getMapContext().getViewPort().getDistanceUnits()]); |
305 |
} |
306 |
|
307 |
/**
|
308 |
* @return
|
309 |
*/
|
310 |
public BufferedImage getImage() { |
311 |
return m_MapControl.getImage();
|
312 |
} |
313 |
|
314 |
public void setProjection(IProjection proj) |
315 |
{ |
316 |
getMapControl().setProjection(proj); |
317 |
} |
318 |
public IProjection getProjection()
|
319 |
{ |
320 |
return getMapControl().getProjection();
|
321 |
} |
322 |
|
323 |
public class ViewExceptionListener implements ExceptionListener { |
324 |
|
325 |
/**
|
326 |
* @see com.iver.cit.gvsig.fmap.ExceptionListener#exceptionThrown(java.lang.Throwable)
|
327 |
*/
|
328 |
public void exceptionThrown(Throwable t) { |
329 |
NotificationManager.addError(t.getMessage(), t); |
330 |
} |
331 |
|
332 |
} |
333 |
|
334 |
/**
|
335 |
* @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
|
336 |
*/
|
337 |
public void viewClosed() { |
338 |
///PluginServices.getMainFrame().getStatusBar().setMessage("1","");
|
339 |
} |
340 |
|
341 |
} |