Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectMap.java @ 6888

History | View | Annotate | Download (6.11 KB)

1
/* 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 com.hardcode.gdbms.engine.data.driver.DriverException;
44

    
45
import com.iver.cit.gvsig.fmap.layers.XMLException;
46
import com.iver.cit.gvsig.gui.layout.Layout;
47
import com.iver.cit.gvsig.gui.project.OpenException;
48
import com.iver.cit.gvsig.gui.project.SaveException;
49

    
50
import com.iver.utiles.XMLEntity;
51

    
52
import java.lang.reflect.Field;
53
import java.text.DateFormat;
54

    
55
import java.util.Date;
56

    
57

    
58
/**
59
 * DOCUMENT ME!
60
 *
61
 * @author Fernando Gonz?lez Cort?s
62
 */
63
public class ProjectMap extends ProjectElement {
64
        public static int numMaps = 0;
65
        private Layout model;
66

    
67
        /**
68
         * DOCUMENT ME!
69
         *
70
         * @param baseName DOCUMENT ME!
71
         *
72
         * @return DOCUMENT ME!
73
         */
74
        public static ProjectMap createMap(String baseName) {
75
                ProjectMap m = new ProjectMap();
76
                m.setName(baseName + " - " + numMaps);
77
                m.setCreationDate(DateFormat.getInstance().format(new Date()));
78
                numMaps++;
79

    
80
                return m;
81
        }
82

    
83
        /**
84
         * @see com.iver.cit.gvsig.project.ProjectMap#getModel()
85
         */
86
        public Layout getModel() {
87
                return model;
88
        }
89

    
90
        /**
91
         * @see com.iver.cit.gvsig.project.ProjectMap#setMapContext(com.iver.cit.gvsig.project.castor.XMLEntity)
92
         */
93
        public void setModel(Layout f) {
94
                model = f;
95
                f.setName(getName());
96
                super.view = f;
97
        }
98

    
99
        /**
100
         * @see com.iver.cit.gvsig.project.ProjectElement#setName(java.lang.String)
101
         */
102
        public void setName(String string) {
103
                super.setName(string);
104

    
105
                Layout m = getModel();
106

    
107
                if (m != null) {
108
                        m.setName(string);
109
                }
110
        }
111

    
112
        /**
113
         * DOCUMENT ME!
114
         *
115
         * @return DOCUMENT ME!
116
         * @throws SaveException
117
         * @throws XMLException
118
         *
119
         * @throws DriverException
120
         */
121
        public XMLEntity getXMLEntity() throws SaveException   {
122
                XMLEntity xml = super.getXMLEntity();
123
                try{
124
                //xml.putProperty("nameClass", this.getClass().getName());
125
                xml.putProperty("numMaps", numMaps);
126
                xml.addChild(model.getXMLEntity());
127
                XMLEntity viewProperties = this.getViewInfoXMLEntity();
128
                if (viewProperties!=null) { //store the properties of the window
129
                        xml.addChild(viewProperties);
130
                }
131
                }catch (Exception e) {
132
                        throw new SaveException(e,this.getClass().getName());
133
                }
134
                return xml;
135
        }
136

    
137
        /**
138
         * @throws OpenException
139
         * @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
140
         */
141
        public void setXMLEntity(XMLEntity xml, Project p) throws OpenException {
142
                try {
143
                        numMaps = xml.getIntProperty("numMaps");
144
                        for (int i=0; i<xml.getChildrenCount(); i++)
145
                        {
146
                                XMLEntity child = xml.getChild(i);
147
                                if (child.contains("className") && child.getStringProperty("className").equals(this.getClass().getName()) && child.contains("name") && child.getStringProperty("name").equals("ViewInfoProperties")) {
148
                                        seedViewInfo = createViewInfoFromXMLEntity(child);
149
                                        //PluginServices.getMDIManager().changeViewInfo(view, viewInfo);
150

    
151
                                }
152
                                else if (child.contains("className")
153
                                                && child.getStringProperty("className").equals("com.iver.cit.gvsig.gui.layout.Layout")
154
                                                && child.contains("name")
155
                                                && child.getStringProperty("name").equals("layout")) {
156
                                        setModel(Layout.createLayout(child,p));
157
                                }
158
                        }
159
                } catch (Exception e) {
160
                        throw new OpenException(e,this.getClass().getName());
161
                }
162
        }
163

    
164
        /**
165
         * @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
166
         */
167
        public void setXMLEntity03(XMLEntity xml, Project p) {
168
                numMaps = xml.getIntProperty("numMaps");
169
                model = Layout.createLayout03(xml.getChild(0), p);
170
        }
171

    
172
//        public int computeSignature() {
173
//                int result = 17;
174
//
175
//                Class clazz = getClass();
176
//                Field[] fields = clazz.getDeclaredFields();
177
//                for (int i = 0; i < fields.length; i++) {
178
//                        try {
179
//                                String type = fields[i].getType().getName();
180
//                                if (type.equals("boolean")) {
181
//                                        result += 37 + ((fields[i].getBoolean(this)) ? 1 : 0);
182
//                                } else if (type.equals("java.lang.String")) {
183
//                                        Object v = fields[i].get(this);
184
//                                        if (v == null) {
185
//                                                result += 37;
186
//                                                continue;
187
//                                        }
188
//                                        char[] chars = ((String) v).toCharArray();
189
//                                        for (int j = 0; j < chars.length; j++) {
190
//                                                result += 37 + (int) chars[i];
191
//                                        }
192
//                                } else if (type.equals("byte")) {
193
//                                        result += 37 + (int) fields[i].getByte(this);
194
//                                } else if (type.equals("char")) {
195
//                                        result += 37 + (int) fields[i].getChar(this);
196
//                                } else if (type.equals("short")) {
197
//                                        result += 37 + (int) fields[i].getShort(this);
198
//                                } else if (type.equals("int")) {
199
//                                        result += 37 + fields[i].getInt(this);
200
//                                } else if (type.equals("long")) {
201
//                                        long f = fields[i].getLong(this) ;
202
//                                        result += 37 + (f ^ (f >>> 32));
203
//                                } else if (type.equals("float")) {
204
//                                        result += 37 + Float.floatToIntBits(fields[i].getFloat(this));
205
//                                } else if (type.equals("double")) {
206
//                                        long f = Double.doubleToLongBits(fields[i].getDouble(this));
207
//                                        result += 37 + (f ^ (f >>> 32));
208
//                                } else {
209
//                                        Object obj = fields[i].get(this);
210
//                                        result += 37 + ((obj != null)? obj.hashCode() : 0);
211
//                                }
212
//                        } catch (Exception e) { e.printStackTrace(); }
213
//
214
//                }
215
//                return result;
216
//        }
217
}