Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / ProjectView.java @ 7679

History | View | Annotate | Download (8.33 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.documents.view;
42

    
43
import java.awt.Color;
44
import java.awt.Component;
45
import java.beans.PropertyChangeListener;
46
import java.util.ArrayList;
47

    
48
import javax.swing.JOptionPane;
49

    
50
import org.cresques.cts.IProjection;
51

    
52
import com.iver.andami.PluginServices;
53
import com.iver.andami.ui.mdiManager.IWindow;
54
import com.iver.cit.gvsig.ProjectExtension;
55
import com.iver.cit.gvsig.fmap.DriverException;
56
import com.iver.cit.gvsig.fmap.ErrorEvent;
57
import com.iver.cit.gvsig.fmap.ErrorListener;
58
import com.iver.cit.gvsig.fmap.MapContext;
59
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
60
import com.iver.cit.gvsig.fmap.layers.CancelationException;
61
import com.iver.cit.gvsig.fmap.layers.FLayers;
62
import com.iver.cit.gvsig.fmap.layers.XMLException;
63
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
64
import com.iver.cit.gvsig.project.Project;
65
import com.iver.cit.gvsig.project.documents.ProjectDocument;
66
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
67
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
68
import com.iver.cit.gvsig.project.documents.table.ProjectTable;
69
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory;
70
import com.iver.cit.gvsig.project.documents.view.gui.ViewProperties;
71
import com.iver.utiles.XMLEntity;
72

    
73

    
74
/**
75
 * Clase que representa una vista del proyecto
76
 *
77
 * @author Fernando Gonz?lez Cort?s
78
 */
79
public class ProjectView extends ProjectViewBase {
80
        public static int numViews = 0;
81

    
82
        //public static int METROS = 0;
83
        //public static int KILOMETROS = 1;
84
        //public static int[] unidades = new int[] { METROS, KILOMETROS };
85
        ///private Color backgroundColor = new Color(255, 255, 255);
86

    
87
        /**
88
         * DOCUMENT ME!
89
         *
90
         * @return DOCUMENT ME!
91
         * @throws XMLException
92
         * @throws SaveException
93
         */
94
        public XMLEntity getXMLEntity() throws SaveException {
95
                XMLEntity xml = super.getXMLEntity();
96
                //xml.putProperty("nameClass", this.getClass().getName());
97
                try{
98
                xml.putProperty("numViews", numViews);
99
                xml.putProperty("m_selectedField", m_selectedField);
100
                xml.putProperty("m_typeLink", m_typeLink);
101
                xml.putProperty("m_extLink", m_extLink);
102
                xml.addChild(mapContext.getXMLEntity());
103

    
104
                if (mapOverViewContext != null) {
105
                        if (mapOverViewContext.getViewPort() != null) {
106
                                xml.putProperty("mapOverView", true);
107
                                xml.addChild(mapOverViewContext.getXMLEntity());
108
                        } else {
109
                                xml.putProperty("mapOverView", false);
110
                        }
111
                } else {
112
                        xml.putProperty("mapOverView", false);
113
                }
114
                XMLEntity viewProperties = this.getViewInfoXMLEntity();
115
                if (viewProperties!=null) { //store the properties of the window
116
                        xml.addChild(viewProperties);
117
                }
118
                }catch (Exception e) {
119
                        throw new SaveException(e,this.getClass().getName());
120
                }
121
                return xml;
122
        }
123

    
124
        /**
125
         * DOCUMENT ME!
126
         *
127
         * @param xml DOCUMENT ME!
128
         * @param p DOCUMENT ME!
129
         * @throws XMLException
130
         * @throws DriverException
131
         * @throws DriverIOException
132
         *
133
         * @see com.iver.cit.gvsig.project.documents.ProjectDocument#setXMLEntity(com.iver.utiles.XMLEntity)
134
         */
135
        public void setXMLEntity03(XMLEntity xml, Project p)
136
                throws XMLException, DriverException, DriverIOException {
137
                numViews = xml.getIntProperty("numViews");
138
                m_selectedField = xml.getStringProperty("m_selectedField");
139
                m_typeLink = xml.getIntProperty("m_typeLink");
140
                m_extLink = xml.getStringProperty("m_extLink");
141
                setMapContext(MapContext.createFromXML03(xml.getChild(0)));
142

    
143
                if (xml.getBooleanProperty("mapOverView")) {
144
                        setMapOverViewContext(MapContext.createFromXML03(xml.getChild(1)));
145
                }
146

    
147
        }
148

    
149
        /**
150
         * DOCUMENT ME!
151
         *
152
         * @param xml DOCUMENT ME!
153
         * @param p DOCUMENT ME!
154
         * @throws XMLException
155
         * @throws DriverException
156
         * @throws DriverIOException
157
         * @throws OpenException
158
         *
159
         * @see com.iver.cit.gvsig.project.documents.ProjectDocument#setXMLEntity(com.iver.utiles.XMLEntity)
160
         */
161
        public void setXMLEntity(XMLEntity xml, Project p)
162
                throws XMLException, DriverException, DriverIOException, OpenException {
163
                try{
164
                        int currentChild=0;
165
                        numViews = xml.getIntProperty("numViews");
166
                        m_selectedField = xml.getStringProperty("m_selectedField");
167
                        m_typeLink = xml.getIntProperty("m_typeLink");
168
                        m_extLink = xml.getStringProperty("m_extLink");
169

    
170
                        setMapContext(MapContext.createFromXML(xml.getChild(currentChild)));
171
                        currentChild++;
172
                        if (xml.getBooleanProperty("mapOverView")) {
173
                                setMapOverViewContext(MapContext.createFromXML(xml.getChild(currentChild)));
174
                                currentChild++;
175
                        }
176
                        if (currentChild<xml.getChildrenCount()) {
177
                                XMLEntity child = xml.getChild(currentChild);
178
                                if (child.contains("className") && child.getStringProperty("className").equals(this.getClass().getName()) && child.contains("name") && child.getStringProperty("name").equals("ViewInfoProperties")) {
179
                                        seedViewInfo = createViewInfoFromXMLEntity(child);
180
                                        //currentChild++;
181
                                }
182
                        }
183
                        showErrors();
184
                }catch (Exception e) {
185
                        throw new OpenException(e,this.getClass().getName());
186
                }
187
        }
188

    
189
        /**
190
         * DOCUMENT ME!
191
         *
192
         * @param p DOCUMENT ME!
193
         *
194
         * @return DOCUMENT ME!
195
         * @throws XMLException
196
         * @throws DriverException
197
         * @throws DriverIOException
198
         * @throws OpenException
199
         */
200
        /*public ProjectView cloneProjectView(Project p)
201
                throws XMLException, DriverException, DriverIOException, OpenException {
202
                return (ProjectView) createFromXML(getXMLEntity(), p);
203
        }
204
*/
205

    
206
        public String getFrameName() {
207
                return PluginServices.getText(this,"Vista");
208
        }
209
        public IWindow createWindow() {
210
                com.iver.cit.gvsig.project.documents.view.gui.View view = new com.iver.cit.gvsig.project.documents.view.gui.View();
211
                view.setModel(this);
212
                return view;
213
        }
214

    
215
        public IWindow getProperties() {
216
                return new ViewProperties(this);
217
        }
218

    
219
//        public int computeSignature() {
220
//                int result = 17;
221
//
222
//                Class clazz = getClass();
223
//                Field[] fields = clazz.getDeclaredFields();
224
//                for (int i = 0; i < fields.length; i++) {
225
//                        try {
226
//                                String type = fields[i].getType().getName();
227
//                                if (type.equals("boolean")) {
228
//                                        result += 37 + ((fields[i].getBoolean(this)) ? 1 : 0);
229
//                                } else if (type.equals("java.lang.String")) {
230
//                                        Object v = fields[i].get(this);
231
//                                        if (v == null) {
232
//                                                result += 37;
233
//                                                continue;
234
//                                        }
235
//                                        char[] chars = ((String) v).toCharArray();
236
//                                        for (int j = 0; j < chars.length; j++) {
237
//                                                result += 37 + (int) chars[i];
238
//                                        }
239
//                                } else if (type.equals("byte")) {
240
//                                        result += 37 + (int) fields[i].getByte(this);
241
//                                } else if (type.equals("char")) {
242
//                                        result += 37 + (int) fields[i].getChar(this);
243
//                                } else if (type.equals("short")) {
244
//                                        result += 37 + (int) fields[i].getShort(this);
245
//                                } else if (type.equals("int")) {
246
//                                        result += 37 + fields[i].getInt(this);
247
//                                } else if (type.equals("long")) {
248
//                                        long f = fields[i].getLong(this) ;
249
//                                        result += 37 + (f ^ (f >>> 32));
250
//                                } else if (type.equals("float")) {
251
//                                        result += 37 + Float.floatToIntBits(fields[i].getFloat(this));
252
//                                } else if (type.equals("double")) {
253
//                                        long f = Double.doubleToLongBits(fields[i].getDouble(this));
254
//                                        result += 37 + (f ^ (f >>> 32));
255
//                                } else {
256
//                                        Object obj = fields[i].get(this);
257
//                                        result += 37 + ((obj != null)? obj.hashCode() : 0);
258
//                                }
259
//                        } catch (Exception e) { e.printStackTrace(); }
260
//
261
//                }
262
//                return result;
263
//        }
264
}