Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectView.java @ 6356

History | View | Annotate | Download (9.47 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.text.DateFormat;
46
import java.util.Date;
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.ViewInfo;
54
import com.iver.cit.gvsig.fmap.DriverException;
55
import com.iver.cit.gvsig.fmap.ErrorEvent;
56
import com.iver.cit.gvsig.fmap.ErrorListener;
57
import com.iver.cit.gvsig.fmap.FMap;
58
import com.iver.cit.gvsig.fmap.ViewPort;
59
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
60
import com.iver.cit.gvsig.fmap.layers.XMLException;
61
import com.iver.cit.gvsig.gui.project.OpenException;
62
import com.iver.cit.gvsig.gui.project.SaveException;
63
import com.iver.utiles.XMLEntity;
64

    
65

    
66
/**
67
 * Clase que representa una vista del proyecto
68
 *
69
 * @author Fernando Gonz?lez Cort?s
70
 */
71
public class ProjectView extends ProjectElement implements ErrorListener {
72
        public static int numViews = 0;
73

    
74
        //public static int METROS = 0;
75
        //public static int KILOMETROS = 1;
76
        //public static int[] unidades = new int[] { METROS, KILOMETROS };
77
        ///private Color backgroundColor = new Color(255, 255, 255);
78
        private FMap mapOverViewContext;
79
        private FMap mapContext;
80
        private int m_typeLink = 0;
81
        private String m_extLink;
82
        private String m_selectedField = null;
83

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

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

    
103
        /**
104
         * DOCUMENT ME!
105
         *
106
         * @param baseName
107
         *
108
         * @return
109
         */
110
        public static ProjectView createView(String baseName) {
111
                ProjectView v = new ProjectView();
112
                v.mapContext = new FMap(new ViewPort(Project.getProjection()));
113
                v.mapOverViewContext = new FMap(null);
114
                v.mapOverViewContext.setProjection(v.mapContext.getProjection());
115

    
116
                //v.mapOverViewContext = null;
117
                v.setName(baseName + " - " + numViews);
118
                v.setCreationDate(DateFormat.getInstance().format(new Date()));
119
                numViews++;
120

    
121
                return v;
122
        }
123

    
124
        /**
125
         * @see com.iver.cit.gvsig.project.ProjectView#setMapContext(com.iver.cit.gvsig.fmap.FMap)
126
         */
127
        public void setMapContext(FMap 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(FMap 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
                XMLEntity viewProperties = this.getViewInfoXMLEntity();
170
                if (viewProperties!=null) { //store the properties of the window
171
                        xml.addChild(viewProperties);
172
                }
173
                }catch (Exception e) {
174
                        throw new SaveException(e,this.getClass().getName());
175
                }
176
                return xml;
177
        }
178

    
179
        /**
180
         * DOCUMENT ME!
181
         *
182
         * @param xml DOCUMENT ME!
183
         * @param p DOCUMENT ME!
184
         * @throws XMLException
185
         * @throws DriverException
186
         * @throws DriverIOException
187
         *
188
         * @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
189
         */
190
        public void setXMLEntity03(XMLEntity xml, Project p)
191
                throws XMLException, DriverException, DriverIOException {
192
                numViews = xml.getIntProperty("numViews");
193
                m_selectedField = xml.getStringProperty("m_selectedField");
194
                m_typeLink = xml.getIntProperty("m_typeLink");
195
                m_extLink = xml.getStringProperty("m_extLink");
196
                setMapContext(FMap.createFromXML03(xml.getChild(0)));
197
                
198
                if (xml.getBooleanProperty("mapOverView")) {
199
                        setMapOverViewContext(FMap.createFromXML03(xml.getChild(1)));
200
                }
201
                
202
        }
203

    
204
        /**
205
         * DOCUMENT ME!
206
         *
207
         * @param xml DOCUMENT ME!
208
         * @param p DOCUMENT ME!
209
         * @throws XMLException
210
         * @throws DriverException
211
         * @throws DriverIOException
212
         * @throws OpenException 
213
         *
214
         * @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
215
         */
216
        public void setXMLEntity(XMLEntity xml, Project p)
217
                throws XMLException, DriverException, DriverIOException, OpenException {
218
                try{
219
                        int currentChild=0;
220
                        numViews = xml.getIntProperty("numViews");
221
                        m_selectedField = xml.getStringProperty("m_selectedField");
222
                        m_typeLink = xml.getIntProperty("m_typeLink");
223
                        m_extLink = xml.getStringProperty("m_extLink");
224
                        
225
                        setMapContext(FMap.createFromXML(xml.getChild(currentChild)));
226
                        currentChild++;
227
                        if (xml.getBooleanProperty("mapOverView")) {
228
                                setMapOverViewContext(FMap.createFromXML(xml.getChild(currentChild)));
229
                                currentChild++;
230
                        }
231
                        if (currentChild<xml.getNumChild()) {
232
                                XMLEntity child = xml.getChild(currentChild);
233
                                if (child.contains("className") && child.getStringProperty("className").equals(this.getClass().getName()) && child.contains("name") && child.getStringProperty("name").equals("ViewInfoProperties")) {
234
                                        seedViewInfo = createViewInfoFromXMLEntity(child);
235
                                        //currentChild++;
236
                                }
237
                        }
238
                        showErrors();
239
                }catch (Exception e) {
240
                        throw new OpenException(e,this.getClass().getName());
241
                }
242
        }
243

    
244
        public void showErrors(){
245
                if (mapContext.getLayersError().size()>0){
246
                        String layersError="";
247
                        for (int i=0;i<mapContext.getLayersError().size();i++){
248
                                layersError=layersError+"\n"+(String)mapContext.getLayersError().get(i);
249
                        }
250
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
251
                                        PluginServices.getText(this,"fallo_capas")+" : \n"+
252
                                        layersError);
253
                }
254
        }
255
        /**
256
         * DOCUMENT ME!
257
         *
258
         * @param p DOCUMENT ME!
259
         *
260
         * @return DOCUMENT ME!
261
         * @throws XMLException
262
         * @throws DriverException
263
         * @throws DriverIOException
264
         * @throws OpenException 
265
         */
266
        /*public ProjectView cloneProjectView(Project p)
267
                throws XMLException, DriverException, DriverIOException, OpenException {
268
                return (ProjectView) createFromXML(getXMLEntity(), p);
269
        }
270
*/
271
        /**
272
         * DOCUMENT ME!
273
         *
274
         * @return DOCUMENT ME!
275
         */
276
        public IProjection getProjection() {
277
                return mapContext.getProjection();
278
        }
279

    
280
        /**
281
         * DOCUMENT ME!
282
         *
283
         * @return DOCUMENT ME!
284
         */
285
        public IProjection getOverViewProjection() {
286
                return mapOverViewContext.getProjection();
287
        }
288
        
289
        public void setProjection (IProjection proj) {
290
                mapContext.setProjection(proj);
291
                mapOverViewContext.setProjection(proj);
292
        }
293

    
294
        /**
295
         * DOCUMENT ME!
296
         *
297
         * @return DOCUMENT ME!
298
         */
299
        public String getExtLink() {
300
                return m_extLink;
301
        }
302

    
303
        /**
304
         * DOCUMENT ME!
305
         *
306
         * @return DOCUMENT ME!
307
         */
308
        public int getTypeLink() {
309
                return m_typeLink;
310
        }
311

    
312
        /**
313
     * Se selecciona la extensi?n para realizar cuando se quiera el link.
314
     *
315
     * @param s nombre del campo.
316
     */
317
        public void setExtLink(String s) {
318
                m_extLink = s;
319
        }
320

    
321
        /**
322
     * Se selecciona el tipo de fichero para realizar cuando se quiera el link.
323
     *
324
     * @param i tipo de fichero.
325
     */
326
        public void setTypeLink(int i) {
327
                m_typeLink = i;
328
        }
329

    
330
        /**
331
         * DOCUMENT ME!
332
         *
333
         * @param c DOCUMENT ME!
334
         */
335
        public void setBackColor(Color c) {
336
//                getMapContext().getViewPort().addViewPortListener(getMapContext()
337
        //                                                                                                           .getEventBuffer());
338
                getMapContext().getViewPort().setBackColor(c);
339
                //getMapContext().getViewPort().removeViewPortListener(getMapContext()
340
                        //                                                                                                  .getEventBuffer());
341
        }
342

    
343
        /**
344
         * Se selecciona el nombre del campo para realizar cuando se quiera el
345
         * link.
346
         *
347
         * @param s nombre del campo.
348
         */
349
        public void setSelectedField(String s) {
350
                m_selectedField = s;
351
        }
352

    
353
        /**
354
         * DOCUMENT ME!
355
         *
356
         * @return DOCUMENT ME!
357
         */
358
        public String getSelectedField() {
359
                return m_selectedField;
360
        }
361

    
362
        public void errorThrown(ErrorEvent e) {
363
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),
364
                                        PluginServices.getText(this,"fallo_capas")+" : \n"+
365
                                        e.getMessage());
366
        
367
        }
368
}