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