root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectView.java @ 6877
History | View | Annotate | Download (9.49 KB)
1 | 1222 | fernando | /* 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.project; |
||
42 | |||
43 | import java.awt.Color; |
||
44 | 3481 | caballero | import java.awt.Component; |
45 | 1222 | fernando | import java.text.DateFormat; |
46 | import java.util.Date; |
||
47 | |||
48 | 3481 | caballero | import javax.swing.JOptionPane; |
49 | |||
50 | 1222 | fernando | import org.cresques.cts.IProjection; |
51 | |||
52 | 3481 | caballero | import com.iver.andami.PluginServices; |
53 | 5029 | cesar | import com.iver.andami.ui.mdiManager.ViewInfo; |
54 | 1222 | fernando | import com.iver.cit.gvsig.fmap.DriverException; |
55 | 3493 | jaume | import com.iver.cit.gvsig.fmap.ErrorEvent; |
56 | import com.iver.cit.gvsig.fmap.ErrorListener; |
||
57 | 1222 | fernando | import com.iver.cit.gvsig.fmap.FMap; |
58 | import com.iver.cit.gvsig.fmap.ViewPort; |
||
59 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
60 | import com.iver.cit.gvsig.fmap.layers.XMLException; |
||
61 | 3183 | caballero | import com.iver.cit.gvsig.gui.project.OpenException; |
62 | import com.iver.cit.gvsig.gui.project.SaveException; |
||
63 | 1222 | fernando | import com.iver.utiles.XMLEntity; |
64 | |||
65 | |||
66 | /**
|
||
67 | * Clase que representa una vista del proyecto
|
||
68 | *
|
||
69 | * @author Fernando Gonz?lez Cort?s
|
||
70 | */
|
||
71 | 3493 | jaume | public class ProjectView extends ProjectElement implements ErrorListener { |
72 | 2609 | caballero | public static int numViews = 0; |
73 | 1222 | fernando | |
74 | //public static int METROS = 0;
|
||
75 | //public static int KILOMETROS = 1;
|
||
76 | //public static int[] unidades = new int[] { METROS, KILOMETROS };
|
||
77 | ///private Color backgroundColor = new Color(255, 255, 255);
|
||
78 | private FMap mapOverViewContext;
|
||
79 | private FMap mapContext;
|
||
80 | private int m_typeLink = 0; |
||
81 | private String m_extLink; |
||
82 | private String m_selectedField = null; |
||
83 | |||
84 | /**
|
||
85 | 5784 | jaume | * Gets the FMap's contexts of the main map in the view.
|
86 | 1222 | fernando | *
|
87 | * @return
|
||
88 | */
|
||
89 | public FMap getMapContext() {
|
||
90 | return mapContext;
|
||
91 | } |
||
92 | |||
93 | /**
|
||
94 | 5784 | jaume | * Gets the FMap's context from the locator, which is the
|
95 | * small map in the left-bottom corner of the View.
|
||
96 | 1222 | fernando | *
|
97 | * @return
|
||
98 | */
|
||
99 | public FMap getMapOverViewContext() {
|
||
100 | return mapOverViewContext;
|
||
101 | } |
||
102 | |||
103 | /**
|
||
104 | 6801 | fjp | * Crea una ProjectView, que es el modelo que hay detr?s de una vista.
|
105 | 1222 | fernando | *
|
106 | 6801 | fjp | * @param viewName
|
107 | 1222 | fernando | *
|
108 | * @return
|
||
109 | */
|
||
110 | 6801 | fjp | public static ProjectView createView(String viewName) { |
111 | 1222 | fernando | ProjectView v = new ProjectView();
|
112 | v.mapContext = new FMap(new ViewPort(Project.getProjection())); |
||
113 | v.mapOverViewContext = new FMap(null); |
||
114 | 5937 | jmvivo | v.mapOverViewContext.setProjection(v.mapContext.getProjection()); |
115 | 1222 | fernando | |
116 | //v.mapOverViewContext = null;
|
||
117 | 6801 | fjp | v.setName(viewName); |
118 | 1222 | fernando | v.setCreationDate(DateFormat.getInstance().format(new Date())); |
119 | |||
120 | return v;
|
||
121 | } |
||
122 | |||
123 | /**
|
||
124 | * @see com.iver.cit.gvsig.project.ProjectView#setMapContext(com.iver.cit.gvsig.fmap.FMap)
|
||
125 | */
|
||
126 | public void setMapContext(FMap fmap) { |
||
127 | mapContext = fmap; |
||
128 | 3493 | jaume | fmap.addErrorListener(this);
|
129 | 1222 | fernando | } |
130 | |||
131 | /**
|
||
132 | * DOCUMENT ME!
|
||
133 | *
|
||
134 | * @param fmap DOCUMENT ME!
|
||
135 | */
|
||
136 | public void setMapOverViewContext(FMap fmap) { |
||
137 | mapOverViewContext = fmap; |
||
138 | 5937 | jmvivo | mapOverViewContext.setProjection(mapContext.getProjection()); |
139 | 1222 | fernando | } |
140 | |||
141 | /**
|
||
142 | * DOCUMENT ME!
|
||
143 | *
|
||
144 | * @return DOCUMENT ME!
|
||
145 | 1830 | fernando | * @throws XMLException
|
146 | 6865 | jaume | * @throws SaveException
|
147 | 1222 | fernando | */
|
148 | 3183 | caballero | public XMLEntity getXMLEntity() throws SaveException { |
149 | 1222 | fernando | XMLEntity xml = super.getXMLEntity();
|
150 | //xml.putProperty("nameClass", this.getClass().getName());
|
||
151 | 3183 | caballero | try{
|
152 | 1222 | fernando | xml.putProperty("numViews", numViews);
|
153 | xml.putProperty("m_selectedField", m_selectedField);
|
||
154 | xml.putProperty("m_typeLink", m_typeLink);
|
||
155 | xml.putProperty("m_extLink", m_extLink);
|
||
156 | xml.addChild(mapContext.getXMLEntity()); |
||
157 | |||
158 | 1830 | fernando | if (mapOverViewContext != null) { |
159 | if (mapOverViewContext.getViewPort() != null) { |
||
160 | xml.putProperty("mapOverView", true); |
||
161 | xml.addChild(mapOverViewContext.getXMLEntity()); |
||
162 | } else {
|
||
163 | xml.putProperty("mapOverView", false); |
||
164 | } |
||
165 | 1222 | fernando | } else {
|
166 | xml.putProperty("mapOverView", false); |
||
167 | } |
||
168 | 5029 | cesar | XMLEntity viewProperties = this.getViewInfoXMLEntity();
|
169 | if (viewProperties!=null) { //store the properties of the window |
||
170 | xml.addChild(viewProperties); |
||
171 | } |
||
172 | 3183 | caballero | }catch (Exception e) { |
173 | throw new SaveException(e,this.getClass().getName()); |
||
174 | } |
||
175 | 1222 | fernando | return xml;
|
176 | } |
||
177 | |||
178 | /**
|
||
179 | * DOCUMENT ME!
|
||
180 | *
|
||
181 | * @param xml DOCUMENT ME!
|
||
182 | * @param p DOCUMENT ME!
|
||
183 | * @throws XMLException
|
||
184 | * @throws DriverException
|
||
185 | * @throws DriverIOException
|
||
186 | *
|
||
187 | * @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
188 | */
|
||
189 | 2183 | fernando | public void setXMLEntity03(XMLEntity xml, Project p) |
190 | throws XMLException, DriverException, DriverIOException {
|
||
191 | numViews = xml.getIntProperty("numViews");
|
||
192 | m_selectedField = xml.getStringProperty("m_selectedField");
|
||
193 | m_typeLink = xml.getIntProperty("m_typeLink");
|
||
194 | m_extLink = xml.getStringProperty("m_extLink");
|
||
195 | setMapContext(FMap.createFromXML03(xml.getChild(0)));
|
||
196 | 6865 | jaume | |
197 | 2183 | fernando | if (xml.getBooleanProperty("mapOverView")) { |
198 | setMapOverViewContext(FMap.createFromXML03(xml.getChild(1)));
|
||
199 | } |
||
200 | 6865 | jaume | |
201 | 2183 | fernando | } |
202 | |||
203 | /**
|
||
204 | * DOCUMENT ME!
|
||
205 | *
|
||
206 | * @param xml DOCUMENT ME!
|
||
207 | * @param p DOCUMENT ME!
|
||
208 | * @throws XMLException
|
||
209 | * @throws DriverException
|
||
210 | * @throws DriverIOException
|
||
211 | 6865 | jaume | * @throws OpenException
|
212 | 2183 | fernando | *
|
213 | * @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
214 | */
|
||
215 | 1222 | fernando | public void setXMLEntity(XMLEntity xml, Project p) |
216 | 3183 | caballero | throws XMLException, DriverException, DriverIOException, OpenException {
|
217 | try{
|
||
218 | 5029 | cesar | int currentChild=0; |
219 | 3481 | caballero | numViews = xml.getIntProperty("numViews");
|
220 | m_selectedField = xml.getStringProperty("m_selectedField");
|
||
221 | m_typeLink = xml.getIntProperty("m_typeLink");
|
||
222 | m_extLink = xml.getStringProperty("m_extLink");
|
||
223 | 6865 | jaume | |
224 | 5029 | cesar | setMapContext(FMap.createFromXML(xml.getChild(currentChild))); |
225 | currentChild++; |
||
226 | 3481 | caballero | if (xml.getBooleanProperty("mapOverView")) { |
227 | 5029 | cesar | setMapOverViewContext(FMap.createFromXML(xml.getChild(currentChild))); |
228 | currentChild++; |
||
229 | 3481 | caballero | } |
230 | 6865 | jaume | if (currentChild<xml.getChildrenCount()) {
|
231 | 5029 | cesar | XMLEntity child = xml.getChild(currentChild); |
232 | if (child.contains("className") && child.getStringProperty("className").equals(this.getClass().getName()) && child.contains("name") && child.getStringProperty("name").equals("ViewInfoProperties")) { |
||
233 | seedViewInfo = createViewInfoFromXMLEntity(child); |
||
234 | //currentChild++;
|
||
235 | } |
||
236 | } |
||
237 | 3493 | jaume | showErrors(); |
238 | 3183 | caballero | }catch (Exception e) { |
239 | throw new OpenException(e,this.getClass().getName()); |
||
240 | } |
||
241 | 1222 | fernando | } |
242 | |||
243 | 3493 | jaume | public void showErrors(){ |
244 | if (mapContext.getLayersError().size()>0){ |
||
245 | String layersError=""; |
||
246 | for (int i=0;i<mapContext.getLayersError().size();i++){ |
||
247 | layersError=layersError+"\n"+(String)mapContext.getLayersError().get(i); |
||
248 | } |
||
249 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
||
250 | PluginServices.getText(this,"fallo_capas")+" : \n"+ |
||
251 | layersError); |
||
252 | } |
||
253 | } |
||
254 | 1222 | fernando | /**
|
255 | * DOCUMENT ME!
|
||
256 | *
|
||
257 | * @param p DOCUMENT ME!
|
||
258 | *
|
||
259 | * @return DOCUMENT ME!
|
||
260 | * @throws XMLException
|
||
261 | * @throws DriverException
|
||
262 | * @throws DriverIOException
|
||
263 | 6865 | jaume | * @throws OpenException
|
264 | 1222 | fernando | */
|
265 | 3183 | caballero | /*public ProjectView cloneProjectView(Project p)
|
266 | throws XMLException, DriverException, DriverIOException, OpenException {
|
||
267 | 1222 | fernando | return (ProjectView) createFromXML(getXMLEntity(), p);
|
268 | }
|
||
269 | 3183 | caballero | */
|
270 | 1222 | fernando | /**
|
271 | * DOCUMENT ME!
|
||
272 | *
|
||
273 | * @return DOCUMENT ME!
|
||
274 | */
|
||
275 | public IProjection getProjection() {
|
||
276 | return mapContext.getProjection();
|
||
277 | } |
||
278 | |||
279 | /**
|
||
280 | * DOCUMENT ME!
|
||
281 | *
|
||
282 | * @return DOCUMENT ME!
|
||
283 | */
|
||
284 | public IProjection getOverViewProjection() {
|
||
285 | return mapOverViewContext.getProjection();
|
||
286 | } |
||
287 | 6865 | jaume | |
288 | 5937 | jmvivo | public void setProjection (IProjection proj) { |
289 | mapContext.setProjection(proj); |
||
290 | mapOverViewContext.setProjection(proj); |
||
291 | } |
||
292 | 1222 | fernando | |
293 | /**
|
||
294 | * DOCUMENT ME!
|
||
295 | *
|
||
296 | * @return DOCUMENT ME!
|
||
297 | */
|
||
298 | public String getExtLink() { |
||
299 | return m_extLink;
|
||
300 | } |
||
301 | |||
302 | /**
|
||
303 | * DOCUMENT ME!
|
||
304 | *
|
||
305 | * @return DOCUMENT ME!
|
||
306 | */
|
||
307 | public int getTypeLink() { |
||
308 | return m_typeLink;
|
||
309 | } |
||
310 | |||
311 | /**
|
||
312 | * Se selecciona la extensi?n para realizar cuando se quiera el link.
|
||
313 | *
|
||
314 | * @param s nombre del campo.
|
||
315 | */
|
||
316 | public void setExtLink(String s) { |
||
317 | m_extLink = s; |
||
318 | } |
||
319 | |||
320 | /**
|
||
321 | * Se selecciona el tipo de fichero para realizar cuando se quiera el link.
|
||
322 | *
|
||
323 | * @param i tipo de fichero.
|
||
324 | */
|
||
325 | public void setTypeLink(int i) { |
||
326 | m_typeLink = i; |
||
327 | } |
||
328 | |||
329 | /**
|
||
330 | * DOCUMENT ME!
|
||
331 | *
|
||
332 | * @param c DOCUMENT ME!
|
||
333 | */
|
||
334 | public void setBackColor(Color c) { |
||
335 | // getMapContext().getViewPort().addViewPortListener(getMapContext()
|
||
336 | // .getEventBuffer());
|
||
337 | getMapContext().getViewPort().setBackColor(c); |
||
338 | //getMapContext().getViewPort().removeViewPortListener(getMapContext()
|
||
339 | // .getEventBuffer());
|
||
340 | } |
||
341 | |||
342 | /**
|
||
343 | * Se selecciona el nombre del campo para realizar cuando se quiera el
|
||
344 | * link.
|
||
345 | *
|
||
346 | * @param s nombre del campo.
|
||
347 | */
|
||
348 | public void setSelectedField(String s) { |
||
349 | m_selectedField = s; |
||
350 | } |
||
351 | |||
352 | /**
|
||
353 | * DOCUMENT ME!
|
||
354 | *
|
||
355 | * @return DOCUMENT ME!
|
||
356 | */
|
||
357 | public String getSelectedField() { |
||
358 | return m_selectedField;
|
||
359 | } |
||
360 | 3493 | jaume | |
361 | public void errorThrown(ErrorEvent e) { |
||
362 | JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
||
363 | PluginServices.getText(this,"fallo_capas")+" : \n"+ |
||
364 | e.getMessage()); |
||
365 | 6865 | jaume | |
366 | 3493 | jaume | } |
367 | 1222 | fernando | } |