Statistics
| Revision:

svn-gvsig-desktop / tags / v10_RC2c / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectView.java @ 8745

History | View | Annotate | Download (10.6 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 java.awt.Color;
44
import java.awt.Component;
45
import java.lang.reflect.Field;
46
import java.text.DateFormat;
47
import java.util.Date;
48

    
49
import javax.swing.JOptionPane;
50

    
51
import org.cresques.cts.IProjection;
52

    
53
import com.iver.andami.PluginServices;
54
import com.iver.andami.ui.mdiManager.WindowInfo;
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.ViewPort;
60
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
61
import com.iver.cit.gvsig.fmap.layers.XMLException;
62
import com.iver.cit.gvsig.gui.project.OpenException;
63
import com.iver.cit.gvsig.gui.project.SaveException;
64
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
public class ProjectView extends ProjectElement implements ErrorListener {
73
        public static int numViews = 0;
74

    
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
        private MapContext mapOverViewContext;
80
        private MapContext mapContext;
81
        private int m_typeLink = 0;
82
        private String m_extLink;
83
        private String m_selectedField = null;
84

    
85
        /**
86
         * Gets the FMap's contexts of the main map in the view.
87
         *
88
         * @return
89
         */
90
        public MapContext getMapContext() {
91
                return mapContext;
92
        }
93

    
94
        /**
95
         * Gets the FMap's context from the locator, which is the
96
         * small map in the left-bottom corner of the View.
97
         *
98
         * @return
99
         */
100
        public MapContext getMapOverViewContext() {
101
                return mapOverViewContext;
102
        }
103

    
104
        /**
105
         * Crea una ProjectView, que es el modelo que hay detr?s de una vista.
106
         *
107
         * @param viewName
108
         *
109
         * @return
110
         */
111
        public static ProjectView createView(String viewName) {
112
                ProjectView v = new ProjectView();
113
                v.mapContext = new MapContext(new ViewPort(Project.getDefaultProjection()));
114
                v.mapOverViewContext = new MapContext(null);
115
                v.mapOverViewContext.setProjection(v.mapContext.getProjection());
116

    
117
                //v.mapOverViewContext = null;
118
                v.setName(viewName);
119
                v.setCreationDate(DateFormat.getInstance().format(new Date()));
120

    
121
                return v;
122
        }
123

    
124
        /**
125
         * @see com.iver.cit.gvsig.project.ProjectView#setMapContext(com.iver.cit.gvsig.fmap.MapContext)
126
         */
127
        public void setMapContext(MapContext fmap) {
128
                mapContext = fmap;
129
                fmap.addErrorListener(this);
130
        }
131

    
132
        /**
133
         * DOCUMENT ME!
134
         *
135
         * @param fmap DOCUMENT ME!
136
         */
137
        public void setMapOverViewContext(MapContext fmap) {
138
                mapOverViewContext = fmap;
139
                mapOverViewContext.setProjection(mapContext.getProjection());
140
        }
141

    
142
        /**
143
         * DOCUMENT ME!
144
         *
145
         * @return DOCUMENT ME!
146
         * @throws XMLException
147
         * @throws SaveException
148
         */
149
        public XMLEntity getXMLEntity() throws SaveException {
150
                XMLEntity xml = super.getXMLEntity();
151
                //xml.putProperty("nameClass", this.getClass().getName());
152
                try{
153
                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
                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
                } else {
167
                        xml.putProperty("mapOverView", false);
168
                }
169

    
170
                }catch (Exception e) {
171
                        throw new SaveException(e,this.getClass().getName());
172
                }
173
                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
        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
                setMapContext(MapContext.createFromXML03(xml.getChild(0)));
194

    
195
                if (xml.getBooleanProperty("mapOverView")) {
196
                        setMapOverViewContext(MapContext.createFromXML03(xml.getChild(1)));
197
                }
198

    
199
        }
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
         * @throws OpenException
210
         *
211
         * @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
212
         */
213
        public void setXMLEntity(XMLEntity xml, Project p)
214
                throws XMLException, DriverException, DriverIOException, OpenException {
215
                try{
216
                        int currentChild=0;
217
                        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

    
222
                        setMapContext(MapContext.createFromXML(xml.getChild(currentChild)));
223
                        currentChild++;
224
                        if (xml.getBooleanProperty("mapOverView")) {
225
                                setMapOverViewContext(MapContext.createFromXML(xml.getChild(currentChild)));
226
                                currentChild++;
227
                        }
228
                        showErrors();
229
                }catch (Exception e) {
230
                        throw new OpenException(e,this.getClass().getName());
231
                }
232
        }
233

    
234
        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
        /**
246
         * DOCUMENT ME!
247
         *
248
         * @param p DOCUMENT ME!
249
         *
250
         * @return DOCUMENT ME!
251
         * @throws XMLException
252
         * @throws DriverException
253
         * @throws DriverIOException
254
         * @throws OpenException
255
         */
256
        /*public ProjectView cloneProjectView(Project p)
257
                throws XMLException, DriverException, DriverIOException, OpenException {
258
                return (ProjectView) createFromXML(getXMLEntity(), p);
259
        }
260
*/
261
        /**
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

    
279
        public void setProjection (IProjection proj) {
280
                mapContext.setProjection(proj);
281
                mapOverViewContext.setProjection(proj);
282
        }
283

    
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

    
352
        public void errorThrown(ErrorEvent e) {
353
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
354
                                        PluginServices.getText(this,"fallo_capas")+" : \n"+
355
                                        e.getMessage());
356

    
357
        }
358

    
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
}