svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / ProjectMap.java @ 28368
History | View | Annotate | Download (10.3 KB)
1 | 7304 | caballero | /* 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.documents.layout; |
||
42 | |||
43 | 7757 | jmvivo | import java.util.Comparator; |
44 | import java.util.HashMap; |
||
45 | import java.util.Iterator; |
||
46 | import java.util.TreeMap; |
||
47 | import java.util.Map.Entry; |
||
48 | |||
49 | 10626 | caballero | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
50 | 7304 | caballero | import com.iver.andami.PluginServices; |
51 | import com.iver.andami.ui.mdiManager.IWindow; |
||
52 | import com.iver.cit.gvsig.fmap.layers.XMLException; |
||
53 | import com.iver.cit.gvsig.project.Project; |
||
54 | import com.iver.cit.gvsig.project.documents.ProjectDocument; |
||
55 | 7757 | jmvivo | import com.iver.cit.gvsig.project.documents.ProjectDocumentFactory; |
56 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.exceptions.OpenException; |
57 | import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
||
58 | 9392 | caballero | import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameView; |
59 | 7757 | jmvivo | import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame; |
60 | 9392 | caballero | import com.iver.cit.gvsig.project.documents.layout.gui.Layout; |
61 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.layout.gui.MapProperties; |
62 | 7757 | jmvivo | import com.iver.cit.gvsig.project.documents.view.ProjectView; |
63 | import com.iver.cit.gvsig.project.documents.view.ProjectViewFactory; |
||
64 | 7304 | caballero | import com.iver.utiles.XMLEntity; |
65 | |||
66 | |||
67 | /**
|
||
68 | 9392 | caballero | * Modelo del Layout.
|
69 | 7304 | caballero | *
|
70 | * @author Fernando Gonz?lez Cort?s
|
||
71 | */
|
||
72 | public class ProjectMap extends ProjectDocument { |
||
73 | 9690 | caballero | //public static int numMaps = 0;
|
74 | 7304 | caballero | private Layout model;
|
75 | |||
76 | /**
|
||
77 | * @see com.iver.cit.gvsig.project.documents.layout.ProjectMap#getModel()
|
||
78 | */
|
||
79 | public Layout getModel() {
|
||
80 | return model;
|
||
81 | } |
||
82 | |||
83 | /**
|
||
84 | * @see com.iver.cit.gvsig.project.documents.layout.ProjectMap#setMapContext(com.iver.cit.gvsig.project.castor.XMLEntity)
|
||
85 | */
|
||
86 | public void setModel(Layout f) { |
||
87 | model = f; |
||
88 | f.setName(getName()); |
||
89 | } |
||
90 | |||
91 | /**
|
||
92 | * @see com.iver.cit.gvsig.project.documents.ProjectDocument#setName(java.lang.String)
|
||
93 | */
|
||
94 | public void setName(String string) { |
||
95 | super.setName(string);
|
||
96 | |||
97 | Layout m = getModel(); |
||
98 | |||
99 | if (m != null) { |
||
100 | m.setName(string); |
||
101 | } |
||
102 | } |
||
103 | |||
104 | /**
|
||
105 | * DOCUMENT ME!
|
||
106 | *
|
||
107 | * @return DOCUMENT ME!
|
||
108 | * @throws SaveException
|
||
109 | * @throws XMLException
|
||
110 | *
|
||
111 | 10661 | caballero | * @throws ReadDriverException
|
112 | 7304 | caballero | */
|
113 | public XMLEntity getXMLEntity() throws SaveException { |
||
114 | XMLEntity xml = super.getXMLEntity();
|
||
115 | try{
|
||
116 | //xml.putProperty("nameClass", this.getClass().getName());
|
||
117 | 9690 | caballero | int numMaps=((Integer)ProjectDocument.NUMS.get(ProjectMapFactory.registerName)).intValue(); |
118 | 7304 | caballero | xml.putProperty("numMaps", numMaps);
|
119 | xml.addChild(model.getXMLEntity()); |
||
120 | }catch (Exception e) { |
||
121 | throw new SaveException(e,this.getClass().getName()); |
||
122 | } |
||
123 | return xml;
|
||
124 | } |
||
125 | |||
126 | /**
|
||
127 | * @throws OpenException
|
||
128 | * @see com.iver.cit.gvsig.project.documents.ProjectDocument#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
129 | */
|
||
130 | 7757 | jmvivo | public void setXMLEntity(XMLEntity xml) throws OpenException { |
131 | 7304 | caballero | try {
|
132 | 7757 | jmvivo | super.setXMLEntity(xml);
|
133 | 9690 | caballero | int numMaps=xml.getIntProperty("numMaps"); |
134 | ProjectDocument.NUMS.put(ProjectMapFactory.registerName,new Integer(numMaps)); |
||
135 | 7304 | caballero | for (int i=0; i<xml.getChildrenCount(); i++) |
136 | { |
||
137 | XMLEntity child = xml.getChild(i); |
||
138 | 7689 | cesar | if (child.contains("className") |
139 | 9392 | caballero | && (child.getStringProperty("className").equals("com.iver.cit.gvsig.gui.layout.Layout") || child.getStringProperty("className").equals(Layout.class.getName())) |
140 | 7304 | caballero | && child.contains("name")
|
141 | && child.getStringProperty("name").equals("layout")) { |
||
142 | 7757 | jmvivo | setModel(Layout.createLayout(child,getProject())); |
143 | 7304 | caballero | } |
144 | } |
||
145 | 7343 | caballero | this.model.setProjectMap(this); |
146 | 7304 | caballero | } catch (Exception e) { |
147 | throw new OpenException(e,this.getClass().getName()); |
||
148 | } |
||
149 | } |
||
150 | |||
151 | /**
|
||
152 | * @see com.iver.cit.gvsig.project.documents.ProjectDocument#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
153 | */
|
||
154 | 7757 | jmvivo | public void setXMLEntity03(XMLEntity xml) |
155 | 10626 | caballero | throws XMLException, ReadDriverException{
|
156 | 7757 | jmvivo | |
157 | super.setXMLEntity03(xml);
|
||
158 | 9690 | caballero | int numMaps=xml.getIntProperty("numMaps"); |
159 | ProjectDocument.NUMS.put(ProjectMapFactory.registerName,new Integer(numMaps)); |
||
160 | 7757 | jmvivo | model = Layout.createLayout03(xml.getChild(0), getProject());
|
161 | 7304 | caballero | } |
162 | |||
163 | |||
164 | public IWindow createWindow() {
|
||
165 | Layout l = getModel(); |
||
166 | setName(l.getName()); |
||
167 | l.setProjectMap(this);
|
||
168 | 9392 | caballero | l.getLayoutControl().fullRect(); |
169 | 7304 | caballero | l.getWindowInfo().setTitle(PluginServices.getText(this,
|
170 | "Mapa") + " : " +l.getName()); |
||
171 | 24529 | vcaballero | callCreateWindow(l); |
172 | 7304 | caballero | return l;
|
173 | } |
||
174 | public IWindow getProperties() {
|
||
175 | return new MapProperties(this); |
||
176 | } |
||
177 | |||
178 | 7343 | caballero | public void afterRemove() { |
179 | 7304 | caballero | // TODO Auto-generated method stub
|
180 | |||
181 | } |
||
182 | |||
183 | 7343 | caballero | public void afterAdd() { |
184 | 7304 | caballero | // TODO Auto-generated method stub
|
185 | |||
186 | } |
||
187 | |||
188 | 7757 | jmvivo | public void exportToXML(XMLEntity root, Project project) throws SaveException { |
189 | 9392 | caballero | XMLEntity mapsRoot = project.getExportXMLTypeRootNode(root,ProjectMapFactory.registerName); |
190 | 7757 | jmvivo | mapsRoot.addChild(this.getXMLEntity());
|
191 | 9392 | caballero | this.exportToXMLDependencies(root,project);
|
192 | 7757 | jmvivo | } |
193 | 9392 | caballero | |
194 | private void exportToXMLDependencies( XMLEntity root,Project project) |
||
195 | 7757 | jmvivo | throws SaveException {
|
196 | XMLEntity viewsRoot = project.getExportXMLTypeRootNode(root,ProjectViewFactory.registerName); |
||
197 | 9392 | caballero | IFFrame[] components = this.getModel().getLayoutContext().getFFrames(); |
198 | 7757 | jmvivo | for (int i=0; i < components.length; i++) { |
199 | if (components[i] instanceof FFrameView) { |
||
200 | ProjectView view = ((FFrameView)components[i]).getView(); |
||
201 | XMLEntity viewXML = viewsRoot.firstChild("name",view.getName());
|
||
202 | if (viewXML==null) { |
||
203 | view.exportToXML(root,project); |
||
204 | } |
||
205 | } |
||
206 | } |
||
207 | |||
208 | } |
||
209 | |||
210 | 10626 | caballero | public void importFromXML(XMLEntity root, XMLEntity typeRoot, int elementIndex, Project project, boolean removeDocumentsFromRoot) throws XMLException, OpenException, ReadDriverException { |
211 | 7757 | jmvivo | XMLEntity element = typeRoot.getChild(elementIndex); |
212 | 9392 | caballero | |
213 | 7757 | jmvivo | XMLEntity layout = element.getChild(0);
|
214 | //Cargamos las vistas vinculadas:
|
||
215 | 9392 | caballero | |
216 | 7757 | jmvivo | //Recuperamos todos los nombres
|
217 | int childIndex;
|
||
218 | XMLEntity child; |
||
219 | // Lo hacemos en un map por si una vista se usa varias veces
|
||
220 | HashMap viewsName = new HashMap(); |
||
221 | for (childIndex=0;childIndex<layout.getChildrenCount();childIndex++) { |
||
222 | child = layout.getChild(childIndex); |
||
223 | if (child.contains("viewName")) { |
||
224 | viewsName.put(child.getStringProperty("viewName"),child.getStringProperty("viewName")); |
||
225 | } |
||
226 | 9392 | caballero | |
227 | 7757 | jmvivo | } |
228 | |||
229 | 9392 | caballero | |
230 | 7757 | jmvivo | XMLEntity viewsRoot = project.getExportXMLTypeRootNode(root,ProjectViewFactory.registerName); |
231 | XMLEntity viewXML; |
||
232 | 9392 | caballero | |
233 | 7757 | jmvivo | // Construimos un diccionario ordenado inversamente por el indice
|
234 | // del elemento (por si se van eliminando elementos al importar) y
|
||
235 | // como valor el nombre de la vista
|
||
236 | TreeMap viewsToImport = new TreeMap( new Comparator() { |
||
237 | |||
238 | public int compare(Object o1, Object o2) { |
||
239 | 9392 | caballero | |
240 | 7757 | jmvivo | if (((Integer)o1).intValue() > ((Integer)o2).intValue()) { |
241 | return -1; //o1 first |
||
242 | } else if (((Integer)o1).intValue() < ((Integer)o2).intValue()){ |
||
243 | return 1; //o1 second |
||
244 | } |
||
245 | return 0; |
||
246 | } |
||
247 | 9392 | caballero | |
248 | 7757 | jmvivo | }); |
249 | Iterator iterViewsName = viewsName.keySet().iterator();
|
||
250 | int viewIndex;
|
||
251 | String viewName;
|
||
252 | while (iterViewsName.hasNext()) {
|
||
253 | viewName = (String)iterViewsName.next();
|
||
254 | viewIndex = viewsRoot.firstIndexOfChild("name",viewName);
|
||
255 | viewsToImport.put(new Integer(viewIndex),viewName); |
||
256 | } |
||
257 | 9392 | caballero | |
258 | |||
259 | ProjectView view; |
||
260 | 7757 | jmvivo | ProjectDocumentFactory viewFactory = project.getProjectDocumentFactory(ProjectViewFactory.registerName); |
261 | 9392 | caballero | |
262 | 7757 | jmvivo | Iterator iterViewToImport = viewsToImport.entrySet().iterator();
|
263 | Entry entry; |
||
264 | // Nos recorremos las vistas a importar
|
||
265 | while (iterViewToImport.hasNext()) {
|
||
266 | entry = (Entry)iterViewToImport.next(); |
||
267 | viewName = (String)entry.getValue();
|
||
268 | viewIndex = ((Integer)entry.getKey()).intValue();
|
||
269 | // Si ya existe la vista no la importamos
|
||
270 | view = (ProjectView)project.getProjectDocumentByName(viewName,ProjectViewFactory.registerName); |
||
271 | if (view == null) { |
||
272 | view = (ProjectView)viewFactory.create(project); |
||
273 | 9392 | caballero | view.importFromXML(root,viewsRoot,viewIndex,project,removeDocumentsFromRoot); |
274 | 7757 | jmvivo | } |
275 | 9392 | caballero | |
276 | 7757 | jmvivo | } |
277 | 9392 | caballero | |
278 | |||
279 | 7757 | jmvivo | this.setXMLEntity(element);
|
280 | project.addDocument(this);
|
||
281 | if (removeDocumentsFromRoot) {
|
||
282 | typeRoot.removeChild(elementIndex); |
||
283 | } |
||
284 | |||
285 | 9392 | caballero | |
286 | 7757 | jmvivo | } |
287 | |||
288 | 7304 | caballero | // public int computeSignature() {
|
289 | // int result = 17;
|
||
290 | //
|
||
291 | // Class clazz = getClass();
|
||
292 | // Field[] fields = clazz.getDeclaredFields();
|
||
293 | // for (int i = 0; i < fields.length; i++) {
|
||
294 | // try {
|
||
295 | // String type = fields[i].getType().getName();
|
||
296 | // if (type.equals("boolean")) {
|
||
297 | // result += 37 + ((fields[i].getBoolean(this)) ? 1 : 0);
|
||
298 | // } else if (type.equals("java.lang.String")) {
|
||
299 | // Object v = fields[i].get(this);
|
||
300 | // if (v == null) {
|
||
301 | // result += 37;
|
||
302 | // continue;
|
||
303 | // }
|
||
304 | // char[] chars = ((String) v).toCharArray();
|
||
305 | // for (int j = 0; j < chars.length; j++) {
|
||
306 | // result += 37 + (int) chars[i];
|
||
307 | // }
|
||
308 | // } else if (type.equals("byte")) {
|
||
309 | // result += 37 + (int) fields[i].getByte(this);
|
||
310 | // } else if (type.equals("char")) {
|
||
311 | // result += 37 + (int) fields[i].getChar(this);
|
||
312 | // } else if (type.equals("short")) {
|
||
313 | // result += 37 + (int) fields[i].getShort(this);
|
||
314 | // } else if (type.equals("int")) {
|
||
315 | // result += 37 + fields[i].getInt(this);
|
||
316 | // } else if (type.equals("long")) {
|
||
317 | // long f = fields[i].getLong(this) ;
|
||
318 | // result += 37 + (f ^ (f >>> 32));
|
||
319 | // } else if (type.equals("float")) {
|
||
320 | // result += 37 + Float.floatToIntBits(fields[i].getFloat(this));
|
||
321 | // } else if (type.equals("double")) {
|
||
322 | // long f = Double.doubleToLongBits(fields[i].getDouble(this));
|
||
323 | // result += 37 + (f ^ (f >>> 32));
|
||
324 | // } else {
|
||
325 | // Object obj = fields[i].get(this);
|
||
326 | // result += 37 + ((obj != null)? obj.hashCode() : 0);
|
||
327 | // }
|
||
328 | // } catch (Exception e) { e.printStackTrace(); }
|
||
329 | //
|
||
330 | // }
|
||
331 | // return result;
|
||
332 | // }
|
||
333 | } |