svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / View.java @ 899
History | View | Annotate | Download (11 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.JComponent; |
11 |
import javax.swing.JPanel; |
12 |
import javax.swing.JScrollPane; |
13 |
import javax.swing.JSplitPane; |
14 |
|
15 |
import com.iver.andami.PluginServices; |
16 |
import com.iver.andami.messages.NotificationManager; |
17 |
import com.iver.andami.ui.mdiManager.SingletonView; |
18 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
19 |
import com.iver.andami.ui.mdiManager.ViewListener; |
20 |
import com.iver.cit.gvsig.fmap.FMap; |
21 |
import com.iver.cit.gvsig.fmap.NewMapControl; |
22 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
23 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
24 |
import com.iver.cit.gvsig.fmap.layers.LayerEvent; |
25 |
import com.iver.cit.gvsig.fmap.layers.LayerListener; |
26 |
import com.iver.cit.gvsig.fmap.tools.Behavior.AreaMapTool; |
27 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MeasureMapTool; |
28 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MoveMapTool; |
29 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PointMapTool; |
30 |
import com.iver.cit.gvsig.fmap.tools.Behavior.RectangleMapTool; |
31 |
import com.iver.cit.gvsig.gui.toc.TOC; |
32 |
import com.iver.cit.gvsig.gui.toolListeners.AreaListener; |
33 |
import com.iver.cit.gvsig.gui.toolListeners.InfoListener; |
34 |
import com.iver.cit.gvsig.gui.toolListeners.LinkListener; |
35 |
import com.iver.cit.gvsig.gui.toolListeners.MeasureListener; |
36 |
import com.iver.cit.gvsig.gui.toolListeners.PanListener; |
37 |
import com.iver.cit.gvsig.gui.toolListeners.PointSelectListener; |
38 |
import com.iver.cit.gvsig.gui.toolListeners.RectangleSelectListener; |
39 |
import com.iver.cit.gvsig.gui.toolListeners.ZoomInListener; |
40 |
import com.iver.cit.gvsig.gui.toolListeners.ZoomOutListener; |
41 |
import com.iver.cit.gvsig.project.castor.ProjectView; |
42 |
import com.iver.utiles.exceptionHandling.ExceptionListener; |
43 |
|
44 |
|
45 |
/**
|
46 |
* DOCUMENT ME!
|
47 |
*
|
48 |
* @author vcn
|
49 |
*/
|
50 |
public class View extends JPanel implements com.iver.andami.ui.mdiManager.View,ViewListener, |
51 |
SingletonView, IView { |
52 |
|
53 |
/** DOCUMENT ME! */
|
54 |
private NewMapControl m_MapControl;
|
55 |
private MapOverview m_MapLoc;
|
56 |
|
57 |
/** DOCUMENT ME! */
|
58 |
private FThemePropertiesDialog m_Themeproperties;
|
59 |
private JScrollPane jscrollTOC; |
60 |
private TOC m_TOC;
|
61 |
private ProjectView modelo;
|
62 |
|
63 |
// private FLyrVect layerSelected;
|
64 |
private String m_selectedField = null; |
65 |
private int m_typeLink=0; |
66 |
private String m_extLink; |
67 |
private Table table = null; |
68 |
private ViewExceptionListener mapControlExceptionListener = new ViewExceptionListener(); |
69 |
|
70 |
/**
|
71 |
* Creates a new View object.
|
72 |
*/
|
73 |
public View() { |
74 |
//this.setName(Utilities.getMessage(this, "Vista")+ " : "+modelo.getName());
|
75 |
this.setPreferredSize(new Dimension(500, 300)); |
76 |
initComponents(); |
77 |
//TODO Poner la herramienta por defecto
|
78 |
// m_MapControl.setTool(MapControl.ZOOM_MAS);
|
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 |
m_MapLoc.setModel(modelo.getMapOverViewContext()); |
106 |
model.addPropertyChangeListener(new PropertyChangeListener() { |
107 |
public void propertyChange(PropertyChangeEvent evt) { |
108 |
if (evt.getPropertyName().equals("name")){ |
109 |
PluginServices.getMDIManager().getViewInfo(View.this).setTitle("Vista: " + (String)evt.getNewValue()); |
110 |
} |
111 |
} |
112 |
}); |
113 |
/// m_TOC.refresh();
|
114 |
|
115 |
} |
116 |
|
117 |
/**
|
118 |
* Se selecciona el nombre del campo para realizar cuando se quiera el link.
|
119 |
*
|
120 |
* @param s nombre del campo.
|
121 |
*/
|
122 |
public void setSelectedField(String s) { |
123 |
m_selectedField = s; |
124 |
} |
125 |
/**
|
126 |
* Se selecciona el tipo de fichero para realizar cuando se quiera el link.
|
127 |
*
|
128 |
* @param s nombre del campo.
|
129 |
*/
|
130 |
public void setTypeFile(int i){ |
131 |
m_typeLink=i; |
132 |
} |
133 |
/**
|
134 |
* Se selecciona la extensi?n para realizar cuando se quiera el link.
|
135 |
*
|
136 |
* @param s nombre del campo.
|
137 |
*/
|
138 |
public void setExtension(String s){ |
139 |
m_extLink=s; |
140 |
} |
141 |
/**
|
142 |
* DOCUMENT ME!
|
143 |
*
|
144 |
* @return DOCUMENT ME!
|
145 |
*/
|
146 |
public String getSelectedField() { |
147 |
return m_selectedField;
|
148 |
} |
149 |
/**
|
150 |
* DOCUMENT ME!
|
151 |
*
|
152 |
* @return DOCUMENT ME!
|
153 |
*/
|
154 |
public int getTypeFile() { |
155 |
return m_typeLink;
|
156 |
} |
157 |
/**
|
158 |
* DOCUMENT ME!
|
159 |
*
|
160 |
* @return DOCUMENT ME!
|
161 |
*/
|
162 |
public String getExtLink() { |
163 |
return m_extLink;
|
164 |
} |
165 |
|
166 |
/**
|
167 |
* DOCUMENT ME!
|
168 |
*/
|
169 |
public void openThemeProperties() { |
170 |
FMap fmap = modelo.getMapContext(); |
171 |
FLayer[] actives = fmap.getLayers().getActives();
|
172 |
|
173 |
for (int i = 0; i < actives.length; i++){ |
174 |
m_Themeproperties = new FThemePropertiesDialog(actives[i], this); |
175 |
PluginServices.getMDIManager().addView(m_Themeproperties); |
176 |
} |
177 |
} |
178 |
|
179 |
/**
|
180 |
* DOCUMENT ME!
|
181 |
*/
|
182 |
private void initComponents() { //GEN-BEGIN:initComponents |
183 |
m_MapControl = new NewMapControl();
|
184 |
m_MapControl.addExceptionListener(mapControlExceptionListener); |
185 |
// modelo.setMapContext(m_MapControl.getMapContext());
|
186 |
|
187 |
// m_MapControl.setAcceptEvents(true); Lo comento porque ya se hace en el setModel
|
188 |
m_TOC = new TOC();
|
189 |
|
190 |
JSplitPane tempMainSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); |
191 |
tempMainSplit.setPreferredSize(new Dimension(500, 300)); |
192 |
|
193 |
// Ponemos el localizador
|
194 |
m_MapLoc = new MapOverview(m_MapControl);
|
195 |
m_MapLoc.setPreferredSize(new Dimension(150, 200)); |
196 |
JSplitPane tempSplitToc = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
197 |
|
198 |
tempSplitToc.setTopComponent((TOC) m_TOC); |
199 |
tempSplitToc.setBottomComponent(m_MapLoc); |
200 |
tempSplitToc.setResizeWeight(0.7);
|
201 |
|
202 |
// tempSplitToc.resetToPreferredSizes();
|
203 |
tempMainSplit.setLeftComponent(tempSplitToc); |
204 |
|
205 |
m_TOC.setVisible(true);
|
206 |
|
207 |
// m_TOC.setPreferredSize(new Dimension(150,50));
|
208 |
tempMainSplit.setRightComponent(m_MapControl); |
209 |
this.setLayout(new BorderLayout()); |
210 |
this.add(tempMainSplit, BorderLayout.CENTER); |
211 |
|
212 |
// Zoom out (pinchas y el mapa se centra y te muestra m?s).
|
213 |
// No es dibujando un rect?ngulo, es solo pinchando.
|
214 |
m_MapControl.addMapTool("point", new PointMapTool()); |
215 |
|
216 |
ZoomOutListener zol = new ZoomOutListener(m_MapControl);
|
217 |
m_MapControl.addTool("zoomOut", "point", zol); |
218 |
|
219 |
// pan
|
220 |
m_MapControl.addMapTool("pan", new MoveMapTool()); |
221 |
|
222 |
PanListener pl = new PanListener(m_MapControl);
|
223 |
m_MapControl.addTool("pan", "pan", pl); |
224 |
|
225 |
// Medir
|
226 |
m_MapControl.addMapTool("medicion", new MeasureMapTool()); |
227 |
|
228 |
MeasureListener mli = new MeasureListener(m_MapControl);
|
229 |
m_MapControl.addTool("medicion", "medicion", mli); |
230 |
|
231 |
// Area
|
232 |
m_MapControl.addMapTool("area", new AreaMapTool()); |
233 |
|
234 |
AreaListener ali = new AreaListener(m_MapControl);
|
235 |
m_MapControl.addTool("area", "area", ali); |
236 |
|
237 |
//Seleccion por punto
|
238 |
PointSelectListener psl = new PointSelectListener(m_MapControl);
|
239 |
m_MapControl.addTool("pointSelection", "point", psl); |
240 |
|
241 |
//Info por punto
|
242 |
m_MapControl.addMapTool("info", new PointMapTool()); |
243 |
InfoListener il = new InfoListener(m_MapControl);
|
244 |
//il.setModel(modelo);
|
245 |
m_MapControl.addTool("info", "info", il); |
246 |
|
247 |
// Link por punto
|
248 |
m_MapControl.addMapTool("link", new PointMapTool()); |
249 |
LinkListener ll = new LinkListener(m_MapControl);
|
250 |
m_MapControl.addTool("link", "link", ll); |
251 |
|
252 |
//Selecci?n por rect?ngulo
|
253 |
m_MapControl.addMapTool("rectangle",
|
254 |
new RectangleMapTool());
|
255 |
RectangleSelectListener rsl = new RectangleSelectListener(m_MapControl);
|
256 |
m_MapControl.addTool("rectSelection", "rectangle", rsl); |
257 |
|
258 |
|
259 |
// Zoom por rect?ngulo
|
260 |
ZoomInListener zil = new ZoomInListener(m_MapControl);
|
261 |
m_MapControl.addTool("zoomIn", "rectangle", zil); |
262 |
|
263 |
m_MapControl.setTool("zoomIn"); // Por defecto |
264 |
} |
265 |
|
266 |
/**
|
267 |
* DOCUMENT ME!
|
268 |
*/
|
269 |
public void openPropertiesWindow() { |
270 |
} |
271 |
|
272 |
/**
|
273 |
* DOCUMENT ME!
|
274 |
*/
|
275 |
public void openQueryWindow() { |
276 |
} |
277 |
|
278 |
/**
|
279 |
* DOCUMENT ME!
|
280 |
*
|
281 |
* @return DOCUMENT ME!
|
282 |
*/
|
283 |
public MapOverview getMapOverview() {
|
284 |
return m_MapLoc;
|
285 |
} |
286 |
|
287 |
/**
|
288 |
* DOCUMENT ME!
|
289 |
*
|
290 |
* @return DOCUMENT ME!
|
291 |
*/
|
292 |
public NewMapControl getMapControl() {
|
293 |
return m_MapControl;
|
294 |
} |
295 |
|
296 |
/**
|
297 |
* DOCUMENT ME!
|
298 |
*
|
299 |
* @return DOCUMENT ME!
|
300 |
*/
|
301 |
public TOC getTOC() {
|
302 |
return m_TOC;
|
303 |
} |
304 |
|
305 |
/**
|
306 |
* DOCUMENT ME!
|
307 |
*
|
308 |
* @return DOCUMENT ME!
|
309 |
*/
|
310 |
public String getViewName() { |
311 |
return ""; |
312 |
} |
313 |
|
314 |
/**
|
315 |
* DOCUMENT ME!
|
316 |
*
|
317 |
* @param viewName DOCUMENT ME!
|
318 |
*/
|
319 |
public void setViewName(String viewName) { |
320 |
} |
321 |
|
322 |
/**
|
323 |
* DOCUMENT ME!
|
324 |
*/
|
325 |
public void repaintMap() { |
326 |
m_MapControl.drawMap(); |
327 |
} |
328 |
|
329 |
/* (non-Javadoc)
|
330 |
* @see com.iver.mdiApp.ui.MDIManager.SingletonView#getModel()
|
331 |
*/
|
332 |
public Object getViewModel() { |
333 |
return modelo;
|
334 |
} |
335 |
|
336 |
/**
|
337 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
338 |
*/
|
339 |
public ViewInfo getViewInfo() {
|
340 |
ViewInfo m_viewInfo = new ViewInfo(ViewInfo.ICONIFIABLE | ViewInfo.RESIZABLE |
|
341 |
ViewInfo.MAXIMIZABLE); |
342 |
|
343 |
m_viewInfo.setWidth(500);
|
344 |
m_viewInfo.setHeight(300);
|
345 |
m_viewInfo.setTitle(PluginServices.getText(this, "Vista") + " : " + |
346 |
modelo.getName()); |
347 |
|
348 |
return m_viewInfo;
|
349 |
|
350 |
} |
351 |
|
352 |
/**
|
353 |
* @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
|
354 |
*/
|
355 |
public void viewActivated() { |
356 |
PluginServices.getMainFrame().getStatusBar().setMessage("1",
|
357 |
FConstant.NAMES[getMapControl().getMapContext().getViewPort().getMapUnits()]); |
358 |
System.out.println("---------- 1 "+ FConstant.NAMES[getMapControl().getMapContext().getViewPort().getDistanceUnits()]); |
359 |
// getMapControl().status = MapControl.DESACTUALIZADO;
|
360 |
// getMapControl().repaint();
|
361 |
} |
362 |
|
363 |
/**
|
364 |
* @return
|
365 |
*/
|
366 |
public BufferedImage getImage() { |
367 |
return m_MapControl.getImage();
|
368 |
} |
369 |
|
370 |
public class ViewExceptionListener implements ExceptionListener { |
371 |
|
372 |
/**
|
373 |
* @see com.iver.cit.gvsig.fmap.ExceptionListener#exceptionThrown(java.lang.Throwable)
|
374 |
*/
|
375 |
public void exceptionThrown(Throwable t) { |
376 |
NotificationManager.addError(t.getMessage(), t); |
377 |
} |
378 |
|
379 |
} |
380 |
|
381 |
/**
|
382 |
* @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
|
383 |
*/
|
384 |
public void viewClosed() { |
385 |
///PluginServices.getMainFrame().getStatusBar().setMessage("1","");
|
386 |
} |
387 |
} |