Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / DefaultProject.java @ 33740

History | View | Annotate | Download (25.2 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2009 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

    
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2004-2009 IVER TI
26
*   
27
*/
28

    
29
package org.gvsig.app.project;
30

    
31
import java.awt.Color;
32
import java.beans.PropertyChangeEvent;
33
import java.beans.PropertyChangeListener;
34
import java.beans.PropertyChangeSupport;
35
import java.io.File;
36
import java.io.FileInputStream;
37
import java.io.FileNotFoundException;
38
import java.io.FileOutputStream;
39
import java.io.InputStream;
40
import java.io.OutputStream;
41
import java.io.Serializable;
42
import java.text.DateFormat;
43
import java.text.MessageFormat;
44
import java.util.ArrayList;
45
import java.util.Collections;
46
import java.util.Date;
47
import java.util.HashMap;
48
import java.util.Iterator;
49
import java.util.List;
50
import java.util.Map;
51

    
52
import org.cresques.cts.IProjection;
53
import org.slf4j.Logger;
54
import org.slf4j.LoggerFactory;
55

    
56
import org.gvsig.andami.PluginServices;
57
import org.gvsig.andami.ui.mdiManager.IWindow;
58
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
59
import org.gvsig.app.extension.Version;
60
import org.gvsig.app.project.documents.AbstractDocument;
61
import org.gvsig.app.project.documents.Document;
62
import org.gvsig.app.project.documents.exceptions.SaveException;
63
import org.gvsig.app.project.documents.layout.DefaultLayoutDocument;
64
import org.gvsig.app.project.documents.layout.LayoutDocument;
65
import org.gvsig.app.project.documents.layout.LayoutManager;
66
import org.gvsig.app.project.documents.table.TableDocument;
67
import org.gvsig.app.project.documents.table.TableManager;
68
import org.gvsig.app.project.documents.view.BaseViewDocument;
69
import org.gvsig.app.project.documents.view.DefaultViewDocument;
70
import org.gvsig.app.project.documents.view.ViewManager;
71
import org.gvsig.fmap.dal.DataTypes;
72
import org.gvsig.fmap.mapcontext.MapContext;
73
import org.gvsig.fmap.mapcontext.layers.FLayer;
74
import org.gvsig.fmap.mapcontext.layers.FLayers;
75
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
76
import org.gvsig.tools.ToolsLocator;
77
import org.gvsig.tools.dynobject.DynField;
78
import org.gvsig.tools.dynobject.DynStruct;
79
import org.gvsig.tools.persistence.PersistenceManager;
80
import org.gvsig.tools.persistence.Persistent;
81
import org.gvsig.tools.persistence.PersistentContext;
82
import org.gvsig.tools.persistence.PersistentState;
83
import org.gvsig.tools.persistence.exception.PersistenceException;
84
import org.gvsig.tools.persistence.exception.PersistenceValidateExceptions;
85
import org.gvsig.utils.StringUtilities;
86

    
87
/**
88
 * Clase que representa un proyecto de gvSIG
89
 *
90
 * @author 2004-2005 Fernando Gonz?lez Cort?s
91
 * @author 2006-2009 Jose Manuel Vivo
92
 * @author 2005-         Vicente Caballero
93
 * @author 2009-         Joaquin del Cerro
94
 * 
95
 */
96

    
97
public class DefaultProject implements Serializable, PropertyChangeListener, Project {
98

    
99
        private Logger LOG = LoggerFactory.getLogger(DefaultProject.class);
100
        /**
101
         * @deprecated see ApplicationLocator.getManager().getVersion()
102
         */
103
        public static String VERSION = Version.format();
104

    
105
        
106
        /**
107
         * 
108
         */
109
        private static final long serialVersionUID = -4449622027521773178L;
110

    
111
        //private static final  Logger logger = LoggerFactory.getLogger(Project .class);
112

    
113
        private static ProjectPreferences preferences = new ProjectPreferences();
114

    
115
        /**
116
         * Index used by the generator of unique names of documents.
117
         */
118
        private Map<String, Integer> nextDocumentIndexByType = new HashMap<String, Integer>();
119

    
120
        private PropertyChangeSupport change;
121

    
122
        private boolean modified = false;
123

    
124
        private String name = null;
125

    
126
        private String creationDate = null;
127

    
128
        private String modificationDate = null;
129

    
130
        private String owner = null;
131

    
132
        private String comments = null;
133

    
134
        private Color selectionColor = null;
135

    
136
        private List<Document> documents = null;
137

    
138
        private List<ProjectExtent> extents = null;
139

    
140
        private IProjection projection;
141

    
142
        /**
143
         * Creates a new Project object.
144
         */
145
        DefaultProject() {
146
                this.change = new PropertyChangeSupport(this);
147
                this.clean();
148
        }
149

    
150
        protected void clean() {
151
                this.owner = "";
152
                this.comments = "";
153
                this.name = PluginServices.getText(this, "untitled");
154
                this.creationDate = DateFormat.getDateInstance().format(new Date());
155
                this.modificationDate = this.creationDate;
156

    
157
                this.documents = new ArrayList<Document>();
158
                this.extents = new ArrayList<ProjectExtent>();
159

    
160
                this.setSelectionColor(getPreferences().getDefaultSelectionColor());
161
        
162
                this.projection = null ; // se inicializa en el getProjection()
163
        }
164
        
165
        
166
        public static ProjectPreferences getPreferences() {
167
                return preferences;
168
        }
169

    
170
        public void propertyChange(PropertyChangeEvent evt) {
171
                change.firePropertyChange(evt);
172
        }
173

    
174
        public synchronized void addPropertyChangeListener(
175
                        PropertyChangeListener arg0) {
176
                change.addPropertyChangeListener(arg0);
177
        }
178

    
179
        
180
        /**
181
         * Return the creation date of the project
182
         *
183
         * @return
184
         */
185
        public String getCreationDate() {
186
                return creationDate;
187
        }
188

    
189
        protected void setCreationDate(String creationDate) {
190
                this.creationDate = creationDate ;
191
                change.firePropertyChange("setCreationDate", null, null);
192
        }
193

    
194

    
195
        /**
196
         * Return the name of the project
197
         *
198
         * @return
199
         */
200
        public String getName() {
201
                return name;
202
        }
203

    
204
        /**
205
         * Set the name of he project.
206
         *
207
         * @param string
208
         */
209
        public void setName(String name) {
210
                this.name = name;
211
                change.firePropertyChange("setName", null, null);
212
        }
213

    
214
        /**
215
         * Return the comments associateds with the project
216
         *
217
         * @return comments
218
         */
219
        public String getComments() {
220
                return comments;
221
        }
222

    
223
        /**
224
         * Set the comments associateds with the project
225
         *
226
         * @param comments as string
227
         */
228
        public void setComments(String string) {
229
                comments = string;
230
                change.firePropertyChange("setComments", null, null);
231
        }
232

    
233
        /**
234
         * Retuen the modification date of the project.
235
         *
236
         * @return modification date as string
237
         */
238
        public String getModificationDate() {
239
                return modificationDate;
240
        }
241

    
242
        protected void setModificationDate(String string) {
243
                modificationDate = string;
244
                change.firePropertyChange("setModificationDate", null, null);
245
        }
246

    
247
        /**
248
         * Return the author of the project,
249
         *
250
         * @return author as string
251
         */
252
        public String getOwner() {
253
                return owner;
254
        }
255

    
256
        /**
257
         * Sets the author of the project
258
         *
259
         * @param author name as string
260
         */
261
        public void setOwner(String owner) {
262
                this.owner = owner;
263
                change.firePropertyChange("setOwner", null, null);
264
        }
265

    
266
        /**
267
         * Obtiene el color de selecci?n que se usar? en el proyecto
268
         *
269
         * @return
270
         */
271
        public Color getSelectionColor() {
272
                if (selectionColor == null) {
273
                        selectionColor = getPreferences().getDefaultSelectionColor();
274
                }
275
                return selectionColor;
276
        }
277

    
278
        /**
279
         * Sets the selecction color
280
         *
281
         * @param selection color as string
282
         */
283
        public void setSelectionColor(String selectionColor) {
284
                this.setSelectionColor(StringUtilities.string2Color(selectionColor));
285
        }
286

    
287
        /**
288
         * Sets the selecction color
289
         *
290
         * @param selection color as Color
291
         */
292
        public void setSelectionColor(Color selectionColor) {
293
                this.selectionColor = selectionColor;
294
                MapContext.setSelectionColor(selectionColor);
295
                change.firePropertyChange("selectionColor", null, selectionColor);
296
        }
297

    
298
        public IProjection getProjection() {
299
                if (projection == null) {
300
                        projection =  getPreferences().getDefaultProjection();
301
                }
302
                return projection;
303
        }
304

    
305
        public void setProjection(IProjection projection) {
306
                this.projection = projection;
307
        }
308

    
309
        /**
310
         * Sets the modified state of project.
311
         * 
312
         * Can't set to not modified.
313
         *
314
         * @param modified as boolean
315
         */
316
        public void setModified(boolean modified) {
317
                this.modified = modified;
318
                if (modified==false) {
319
                        List<Document> documents = this.getDocuments();
320
                        for( int i=0 ; i<documents.size(); i++ ) {
321
                                documents.get(i).setModified(false);
322
                        }
323
                }
324
        }
325

    
326
         public boolean hasChanged() {
327
                 // we return true if the project is not empty (until we have a better method...)
328
                 if ((this.getDocuments().size() != 0) || modified) {
329
                         return true;
330
                 }
331
                 return false;
332
         }
333
        
334
                /**
335
                 * Return a list of documents in the project.
336
                 *
337
                 * @return documents as List of IProjectDocument
338
                 */
339
                public List<Document> getDocuments() {
340
                        return Collections.unmodifiableList(documents);
341
                }
342

    
343
        /**
344
         * Return a list with all documents of especified type.
345
         *
346
         * @param type of document
347
         *
348
         * @return List of IProjectDocument
349
         */
350
                public List<Document> getDocuments(String type) {
351
                        List<Document> docs = new ArrayList<Document>();
352
                        if( type != null ) {
353
                                for (Document document : this.documents) {
354
                                        if (type.equalsIgnoreCase(document.getTypeName())) {
355
                                                docs.add(document);
356
                                        }
357
                                }
358
                        }
359
                        return Collections.unmodifiableList(docs);
360
                }
361

    
362

    
363
        /**
364
         * Adds a document to the project
365
         *
366
         * @param document as IProjectDocument
367
         */
368
        public void add(Document document) {
369
                documents.add(document);
370
                document.addPropertyChangeListener(this);
371
                document.setProject(this);
372
        document.setName( 
373
                        this.getUniqueNameForDocument(
374
                                document.getTypeName(), 
375
                                document.getName()
376
                        )
377
        );
378
        document.afterAdd();
379
                this.setModified(true);
380
                change.firePropertyChange("addDocument",null, null);
381
        }
382

    
383
        /**
384
         * Remove a document of the project
385
         *
386
         * @param document as IProjectDocument
387
         */
388
        public void remove(Document doc) {
389
                documents.remove(doc);
390
                this.setModified(true);
391
                change.firePropertyChange("delDocument", null, null);
392
                doc.afterRemove();
393
        }
394

    
395
        public Iterator<Document> iterator() {
396
                return documents.iterator();
397
        }
398

    
399
        public boolean isEmpty() {
400
                return documents.isEmpty();
401
        }
402
                
403
        /**
404
         * Return the FeatureTableDocument associated with a layer
405
         *
406
         * @param layer
407
         *
408
         * @return FeatureTableDocument associated with the layer.
409
         */
410
        public TableDocument getTable(FLyrVect layer) {
411
                List<Document> tables = getDocuments(TableManager.TYPENAME);
412
                for (int i = 0; i < tables.size(); i++) {
413
                        TableDocument table = (TableDocument) tables.get(i);
414
                                if ( table.getStore().equals(layer.getFeatureStore())  ){
415
                                        return table;
416
                                }
417
                }
418

    
419
                return null;
420
        }
421

    
422
        /**
423
         * Return the view that contains the especified layer.
424
         *
425
         * @param layer
426
         *
427
         * @return name of the view that contains the layer
428
         *
429
         * @throws RuntimeException 
430
         *             Si la capa que se pasa como par?metro no se encuentra en
431
         *             ninguna vista
432
         */
433
        public String getViewName(FLayer layer) {
434
                List<Document> views = getDocuments(ViewManager.TYPENAME);
435
                for (int v = 0; v < views.size(); v++) {
436
                        DefaultViewDocument pView = (DefaultViewDocument) views.get(v);
437
                        FLayers layers = pView.getMapContext().getLayers();
438
                        if (isView(layers, layer)) {
439
                                return pView.getName();
440
                        }
441
                }
442

    
443
                throw new RuntimeException(MessageFormat.format("The layer '{1}' is not in a view",  layer.getName()));
444
        }
445

    
446
        private boolean isView(FLayers layers, FLayer layer) {
447
                for (int i = 0; i < layers.getLayersCount(); i++) {
448
                        if (layers.getLayer(i) instanceof FLayers) {
449
                                if (isView((FLayers) layers.getLayer(i), layer)){
450
                                        return true;
451
                                }
452
                        }
453
                        if (layers.getLayer(i) == layer) {
454
                                return true;
455
                        }
456
                }
457
                return false;
458
        }
459

    
460
        public void addExtent(ProjectExtent arg1) {
461
                extents.add(arg1);
462
                change.firePropertyChange("addExtent", null, null);
463
        }
464

    
465
        public ProjectExtent removeExtent(int arg0) {
466
                change.firePropertyChange("delExtent", null, null);
467
                return extents.remove(arg0);
468
        }
469

    
470
        public ProjectExtent[] getExtents() {
471
                return (ProjectExtent[]) extents.toArray(new ProjectExtent[0]);
472
        }
473

    
474
        /**
475
         * Obtiene un documento a partir de su nombre y el nombre de registro en el
476
         * pointExtension, este ?ltimo se puede obtener del
477
         * Project****Factory.registerName.
478
         *
479
         * @param name
480
         *            Nombre del documento
481
         * @param type
482
         *            nombre de registro en el extensionPoint
483
         *
484
         * @return Documento
485
         */
486
        public Document getDocument(String name, String type) {
487
                if( type != null ) {
488
                        for (int i = 0; i < documents.size(); i++) {
489
                                Document document = documents.get(i);
490
                                if (type.equalsIgnoreCase(document.getTypeName()) && name.equalsIgnoreCase(document.getName())) {
491
                                        return document;
492
                                }
493
                        }
494
                }
495
                return null;
496
        }
497

    
498
        public String getUniqueNameForDocument(String type, String name) {
499
                Document document = getDocument(name, type);
500
                if( document == null ) {
501
                        return name;
502
                }
503
                
504
        String newName = null;
505
        int num = this.getNextDocumentIndex(type);
506
        while( document != null ) {
507
            newName = name + " - " + num++;
508
                    document = getDocument(newName, type);                
509
        } 
510
        this.setNextDocumentIndex(type, num);
511
        return newName;
512
        }
513
        
514
        private int getNextDocumentIndex(String type) {
515
                if( nextDocumentIndexByType.get(type) == null ) {
516
                        nextDocumentIndexByType.put(type, new Integer(1));
517
                        return 1;
518
                }
519
                return nextDocumentIndexByType.get(type).intValue();
520
        }
521

    
522
        private void setNextDocumentIndex(String type, int newIndex) {
523
                if( nextDocumentIndexByType.get(type) == null ) {
524
                        nextDocumentIndexByType.put(type, new Integer(newIndex));
525
                } else {
526
                        nextDocumentIndexByType.put(type, new Integer(newIndex));
527
                }
528
        }
529

    
530
        public void saveState(File out) throws PersistenceException {
531
                FileOutputStream fout;
532
                try {
533
                        fout = new FileOutputStream(out);
534
                        saveState(fout, new File(out.getParent()));
535
                } catch (FileNotFoundException e) {
536
                        throw new PersistenceException(e);
537
                }
538
        }
539
        
540
        public void saveState(OutputStream out) throws PersistenceException {
541
                saveState(out, null);
542
        }
543
        
544
        public void saveState(OutputStream out, File rootFolder) throws PersistenceException {
545
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
546
                PersistentState state=null;
547
                state = manager.getState(this,true);
548
                try {
549
                        if( rootFolder!=null ) {
550
                                relativizeFiles(state, rootFolder);
551
                        }
552
                } catch(Exception ex) {
553
                        state.getContext().addError(ex);
554
                }
555
                manager.saveState( state, out);
556
                if( state.getContext().getErrors() != null  ) {
557
                        throw state.getContext().getErrors();
558
                }
559
        }
560
        
561
        private void relativizeFiles(PersistentState state, File rootFolder) {
562
                PersistentContext context = state.getContext();
563
                
564
                @SuppressWarnings("unchecked")
565
                Iterator<PersistentState> statesIterator = context.iterator();
566
                while( statesIterator.hasNext() ) {
567
                        PersistentState aState = statesIterator.next();
568
                        DynStruct definition = aState.getDefinition();
569
                        DynField[] fields = definition.getDynFields();
570
                        for (DynField field : fields) {
571
                                if( field.getType() == DataTypes.FILE ||
572
                                        field.getType() == DataTypes.FOLDER ) {
573
                                        try {
574
                                                File value = aState.getFile(field.getName());
575
                                                value = relativizeFile(value, rootFolder);
576
                                                aState.set(field.getName(), value );
577
                                        } catch (PersistenceException e) {
578
                                                LOG.warn("Can't relativice field '"+field.getName()+"' for class '"+definition.getName()+"'.",e);
579
                                        }
580
                                }
581
                        }
582
                }
583
        }
584
        
585
        private File relativizeFile(File file, File rootFolder) {
586
                // TODO: falta por implementar.
587
                return file;
588
        }
589
        
590
        public void loadState(InputStream in) {
591
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
592
                try {
593
                        PersistentState state = manager.loadState(in);
594
                        this.loadFromState(state);
595
                } catch (PersistenceException e) {
596
                        // TODO Auto-generated catch block
597
                        e.printStackTrace();
598
                }
599
                
600
        }
601
        
602
        public void loadState(File in) {
603
                FileInputStream fin;
604
                try {
605
                        fin = new FileInputStream(in);
606
                        loadState(fin);
607
                } catch (FileNotFoundException e) {
608
                        // TODO Auto-generated catch block
609
                        e.printStackTrace();
610
                }
611
        }
612
        
613
        @SuppressWarnings("unchecked")
614
        public void loadFromState(PersistentState state)
615
                        throws PersistenceException {
616
                this.clean();
617
                
618
                this.setComments( state.getString("comments") );
619
                this.setCreationDate( state.getString("creationDate") );
620
                this.setModificationDate( state.getString("modificationDate") );
621
                this.setName( state.getString("name") );
622
                this.setOwner( state.getString("owner") );
623
                this.setSelectionColor( (Color)state.get("selectionColor") );
624
                this.setProjection( (IProjection) state.get("projection") );
625
                
626
                List<ProjectExtent> extents = (List<ProjectExtent>) state.get("extents");
627
                for( int i=0; i<extents.size(); i++) {
628
                        this.addExtent( extents.get(i) );
629
                }
630
                
631
                List<AbstractDocument> documents = (List<AbstractDocument>) state.get("documents");
632
                for( int i=0; i<documents.size(); i++) {
633
                        this.add( documents.get(i) );
634
                }
635

    
636
        }
637

    
638
        public void saveToState(PersistentState state) throws PersistenceException {
639
                state.set("version", VERSION);
640
                state.set("comments", getComments());
641
                state.set("creationDate", this.getCreationDate());
642

    
643
                state.set("modificationDate",  this.getModificationDate());
644
                state.set("name", this.getName());
645
                state.set("owner", this.getOwner());
646
                state.set("selectionColor", this.getSelectionColor());
647
                
648
                state.set("projection",  this.getProjection());
649

    
650
                state.set("extents", this.extents);
651
                state.set("documents", this.getDocuments());
652

    
653
                PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
654
                List<PersistentState> windowsStates = new ArrayList<PersistentState>();
655
                IWindow[] windows = PluginServices.getMDIManager().getOrderedWindows();
656
                for (int i = windows.length - 1; i >= 0; i--) {
657
                        IWindow window = windows[i];
658
                        if( window instanceof Persistent ) {
659
                                try {
660
                                        windowsStates.add( persistenceManager.getState(windows));
661
                                } catch (PersistenceValidateExceptions e) {
662
                                        throw new PersistenceException(e);
663
                                }
664
                        }
665
                }
666
                LOG.warn("DefaultProject::saveToState, falta por persistir 'windowsInformation'");
667
                //state.set("windowsInformation", windowsStates);
668
                
669
        }
670
                        
671

    
672
        public static void registerPersistent() {
673
                PersistenceManager manager = ToolsLocator.getPersistenceManager();
674
                DynStruct definition = manager.addDefinition(
675
                                DefaultProject.class,
676
                                "Project",
677
                                "Project Persistence definition",
678
                                null, 
679
                                null
680
                );
681
                definition.addDynFieldString("version").setMandatory(true);
682
                definition.addDynFieldString("comments").setMandatory(true);
683
                definition.addDynFieldString("creationDate").setMandatory(true);
684
                definition.addDynFieldString("modificationDate").setMandatory(true);
685
                definition.addDynFieldString("name").setMandatory(true);
686
                definition.addDynFieldString("owner").setMandatory(true);
687

    
688
                definition.addDynFieldObject("selectionColor").setClassOfValue(Color.class).setMandatory(true);
689
                definition.addDynFieldObject("projection").setClassOfValue(IProjection.class).setMandatory(true);
690

    
691
                definition.addDynFieldList("extents").setClassOfItems(ProjectExtent.class).setMandatory(true);
692

    
693
                definition.addDynFieldList("documents").setClassOfItems(Document.class).setMandatory(true);
694
                
695
                AbstractDocument.registerPersistent();
696
        }
697

    
698
        /**
699
         * @deprecated use getPreferences().setDefaultSelectionColor()
700
         */
701
        public static void setDefaultSelectionColor(Color color) {
702
                getPreferences().setDefaultSelectionColor(color);
703
        }
704

    
705
        /**
706
         * @deprecated use getPreferences().getDefaultSelectionColor()
707
         */
708
        
709
        public static Color getDefaultSelectionColor() {
710
                return getPreferences().getDefaultSelectionColor();
711
        }
712

    
713
        /**
714
         * @deprecated use getPreferences().getDefaultMapUnits()
715
         */
716
        public static int getDefaultMapUnits() {
717
                return getPreferences().getDefaultMapUnits();
718
        }
719

    
720
        /**
721
         * @deprecated use getPreferences().getDefaultDistanceUnits()
722
         */
723
        public static int getDefaultDistanceUnits() {
724
                return getPreferences().getDefaultDistanceUnits();
725
        }
726
        
727
        /**
728
         * @deprecated use getPreferences().getDefaultDistanceArea()
729
         */
730
        public static int getDefaultDistanceArea() {
731
                return getPreferences().getDefaultDistanceArea();
732
        }
733
        
734
        /**
735
         * @deprecated use getPreferences().setDefaultMapUnits()
736
         */
737
        public static void setDefaultMapUnits(int mapUnits) {
738
                getPreferences().setDefaultMapUnits(mapUnits);
739
        }
740

    
741
        /**
742
         * @deprecated use getPreferences().setDefaultDistanceUnits()
743
         */
744
        public static void setDefaultDistanceUnits(int distanceUnits) {
745
                getPreferences().setDefaultDistanceUnits(distanceUnits);
746
        }
747
        
748
        /**
749
         * @deprecated use getPreferences().setDefaultDistanceArea()
750
         */
751
        public static void setDefaultDistanceArea(int distanceArea) {
752
                getPreferences().setDefaultDistanceArea(distanceArea);
753
        }
754

    
755
        /**
756
         * @deprecated use getPreferences().setDefaultProjection()
757
         */
758
        public static void setDefaultProjection(IProjection defaultProjection) {
759
                getPreferences().setDefaultProjection(defaultProjection);
760
        }
761

    
762
        /**
763
         * @deprecated use getPreferences().getDefaultProjection()
764
         */
765
        public static IProjection getDefaultProjection() {
766
                return getPreferences().getDefaultProjection();
767
        }
768

    
769
        /**
770
         * @deprecated see {@link #setSelectionColor(String)}, to be remove in gvSIG 2.1.0
771
         */
772
        public void setColor(String color) {
773
                this.setSelectionColor(StringUtilities.string2Color(color));
774
        }
775

    
776
        /**
777
         * Return the selection color 
778
         *
779
         * @return selection color as string
780
         * @deprecated use {@link #getSelectionColor()}
781
         */
782
        public String getColor() {
783
                return StringUtilities.color2String(selectionColor);
784
        }
785

    
786

    
787
        /**
788
         * Devuelve a partir del nombre la tabla asociada.
789
         *
790
         * @param name
791
         *            Nombre.
792
         * @deprecated utilizar getProjectDocumentByName(...);
793
         * @return ProjectTable de la tabla asociada.
794
         */
795
        public TableDocument getTable(String name) {
796
                return (TableDocument) this.getDocument(name,TableManager.TYPENAME);
797
        }
798

    
799
        /**
800
         * Return the list of maps of the project
801
         *
802
         * @return tables as ArrayList of IProjectDocument
803
         * 
804
         * @deprecated see {@link #getDocumentsByType(String)}
805
         */
806
        public List<Document> getMaps() {
807
                return getDocuments(LayoutManager.TYPENAME);
808
        }
809

    
810
        /**
811
         * Add a  {@link LayoutDocument} to the project
812
         *
813
         * @deprecated see {@link #add(Document)}
814
         */
815
        public void addMap(LayoutDocument m) {
816
                add(m);
817
        }
818

    
819
        /**
820
         * Remove a  map of the project
821
         *
822
         * @param index of the map as integer
823
         * 
824
         * @deprecated see {@link #remove(Document)}
825
         */
826
        public void delMap(int i) {
827
                List<Document> list = getDocuments(LayoutManager.TYPENAME);
828
                remove(list.get(i));
829
        }
830

    
831

    
832
        /**
833
         * Return the list of tables of the project
834
         *
835
         * @return tables as ArrayList of ProjectDocument
836
         * 
837
         * @deprecated see {@link #getDocumentsByType(String)}
838
         */
839
        public List<Document> getTables() {
840
                return getDocuments(TableManager.TYPENAME);
841
        }
842

    
843
        /**
844
         * Add a  {@link TableDocument } to the project
845
         *
846
         * @deprecated see {@link #add(AbstractDocument)}
847
         */
848
        public void addTable(TableDocument t) {
849
                add(t);
850
        }
851

    
852
        /**
853
         * Remove a  {@link TableDocument } of the project
854
         *
855
         * @param index of the table as integer
856
         * 
857
         * @deprecated see {@link #remove(AbstractDocument)}
858
         */
859
        public void delTable(int i) {
860
                List<Document> list = getDocuments(TableManager.TYPENAME);
861
                remove(list.get(i));
862
        }
863

    
864
        /**
865
         * Return the list of views of the project
866
         *
867
         * @return views as ArrayList of ProjectDocument
868
         * 
869
         * @deprecated see {@link #getDocumentsByType(String)}
870
         */
871
        public List<Document> getViews() {
872
                return getDocuments(ViewManager.TYPENAME);
873
        }
874

    
875
        /**
876
         * Add a  view to the project
877
         *
878
         * @deprecated see {@link #add(AbstractDocument)}
879
         */
880
        public void addView(DefaultViewDocument v) {
881
                add(v);
882
        }
883

    
884
        /**
885
         * Remove a view of the project
886
         *
887
         * @param index of the view as integer
888
         * 
889
         * @deprecated see {@link #remove(AbstractDocument)}
890
         */
891
        public void delView(int i) {
892
                List<Document> list = getDocuments(ViewManager.TYPENAME);
893
                remove(list.get(i));
894
        }
895

    
896
        /**
897
         * @deprecated see {@link #getDocument(String, String)} 
898
         */
899
        public Document getProjectDocumentByName(String name, String type) {
900
                return this.getDocument(name, type);
901
        }
902

    
903
        /**
904
         * @deprecated see {@link #getDocuments(String)} 
905
         */
906
        public List<Document> getDocumentsByType(String type) {
907
                return this.getDocuments(type);
908
        }
909

    
910
        /**
911
         * @deprecated aun por decidir que API darle al copy/paste 
912
         */
913
        public String exportToXML(AbstractDocument[] selectedItems) throws SaveException {
914
                // FIXME jjdc:hay que decirdir que API darle al copy/paste
915
                throw new UnsupportedOperationException("This method is not supported");
916
        }
917

    
918
        /**
919
         * @deprecated aun por decidir que API darle al copy/paste 
920
         */
921
        public void importFromXML(String sourceString, String docType) {
922
                // FIXME jjdc:hay que decirdir que API darle al copy/paste
923
                throw new UnsupportedOperationException("This method is not supported");
924
        }
925

    
926
        /**
927
         * @deprecated aun por decidir que API darle al copy/paste 
928
         */
929
        public boolean isValidXMLForImport(String sourceString, String docType) {
930
                // FIXME jjdc:hay que decirdir que API darle al copy/paste
931
                throw new UnsupportedOperationException("This method is not supported");
932
        }
933

    
934
        public boolean canImportDocuments(String data, String doctype) {
935
                // TODO Auto-generated method stub
936
                return false;
937
        }
938

    
939
        public String exportDocumentsAsText(List<Document> documents) {
940
                // TODO Auto-generated method stub
941
                return null;
942
        }
943

    
944
        public void importDocuments(String data, String doctype) {
945
                // TODO Auto-generated method stub
946
                
947
        }
948

    
949
        public Document getActiveDocument() {
950
                try {
951
                        SingletonWindow window = (SingletonWindow) PluginServices.getMDIManager().getActiveWindow();
952
                        Document doc = (Document) window.getWindowModel();
953
                        return doc;
954
                } catch(Exception ex) {
955
                        return null;
956
                }
957
        }
958
}