Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / ProjectPreferences.java @ 40558

History | View | Annotate | Download (8.96 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/* gvSIG. Geographic Information System of the Valencian Government
25
*
26
* Copyright (C) 2007-2009 Infrastructures and Transports Department
27
* of the Valencian Government (CIT)
28
* 
29
* This program is free software; you can redistribute it and/or
30
* modify it under the terms of the GNU General Public License
31
* as published by the Free Software Foundation; either version 2
32
* of the License, or (at your option) any later version.
33
* 
34
* This program is distributed in the hope that it will be useful,
35
* but WITHOUT ANY WARRANTY; without even the implied warranty of
36
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
* GNU General Public License for more details.
38
* 
39
* You should have received a copy of the GNU General Public License
40
* along with this program; if not, write to the Free Software
41
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
42
* MA  02110-1301, USA.
43
* 
44
*/
45

    
46
/*
47
* AUTHORS (In addition to CIT):
48
* 2004-2009 IVER TI
49
*   
50
*/
51

    
52
package org.gvsig.app.project;
53

    
54
import java.awt.Color;
55

    
56
import org.cresques.cts.IProjection;
57
import org.gvsig.andami.PluginServices;
58
import org.gvsig.app.imp.DefaultPreferencesNode;
59
import org.gvsig.fmap.crs.CRSFactory;
60
import org.gvsig.fmap.mapcontext.MapContext;
61
import org.gvsig.fmap.mapcontext.MapContextLocator;
62
import org.gvsig.utils.StringUtilities;
63
import org.gvsig.utils.XMLEntity;
64

    
65
/**
66
 * Clase que representa las preferencias para el proyecto
67
 *
68
 * @author 2009-         Joaquin del Cerro
69
 * 
70
 */
71

    
72
public class ProjectPreferences extends DefaultPreferencesNode {
73

    
74
        private IProjection defaultProjection = null;
75

    
76
        private IProjection defaultFactoryProjection =
77
            MapContextLocator.getMapContextManager().getDefaultCRS();
78

    
79
        private Color defaultSelectionColor = Color.YELLOW;
80
        
81
        private Color defaultViewBackColor = Color.WHITE;
82

    
83
        private Color defaultOverviewBackColor = Color.WHITE;        
84

    
85
        private int defaultMapUnits = -1;
86

    
87
        private int defaultDistanceUnits = -1;
88

    
89
        private int defaultDistanceArea = -1;
90

    
91
        
92
        public ProjectPreferences() {
93
        }
94

    
95
    /**
96
         * Sets the projection used when no projection is defined
97
         *
98
         * @param defaultProjection
99
         */
100
        public void setDefaultProjection(IProjection defaultProjection) {
101
                this.defaultProjection = defaultProjection;
102
        }
103

    
104
        public int getInt(String name, int defaultValue) {
105
                if( name.equalsIgnoreCase("DefaultDistanceUnits")) {
106
                        return this.getDefaultDistanceUnits();
107
                } else if( name.equalsIgnoreCase("DefaultDistanceArea")) {
108
                        return this.getDefaultDistanceArea();
109
                } else if( name.equalsIgnoreCase("DefaultMapUnits")) {
110
                        return this.getDefaultMapUnits();
111
                }
112
                
113
                return super.getInt(name, defaultValue);
114
        }
115
        
116
        public IProjection getDefaultProjection() {
117
                if (defaultProjection == null){
118
                        XMLEntity xml = PluginServices.getPluginServices("org.gvsig.app")
119
                        .getPersistentXML();
120

    
121
                        // Default Projection
122
                        String projCode = null;
123
                        if (xml.contains("DefaultProjection")) {
124
                                projCode = xml.getStringProperty("DefaultProjection");
125
                                setDefaultProjection(CRSFactory.getCRS(projCode));
126
                        } else {
127
                                setDefaultProjection(defaultFactoryProjection);
128
                        }
129

    
130
                }
131
                return defaultProjection;
132
        }
133

    
134
        /**
135
         * Sets the default selection color that will be used in subsequent
136
         * projects.
137
         *
138
         * @param color
139
         */
140
        public void setDefaultSelectionColor(Color color) {
141
                defaultSelectionColor = color;
142
        }
143

    
144
        /**
145
         * Returns the current default selection color defined which is the color
146
         * defined when the user does not define any other one
147
         *
148
         * @return java.awt.Color
149
         */
150
        public Color getDefaultSelectionColor() {
151
                XMLEntity xml = PluginServices.getPluginServices("org.gvsig.app")
152
                                .getPersistentXML();
153
                if (xml.contains("DefaultSelectionColor")) {
154
                        defaultSelectionColor = StringUtilities.string2Color(xml
155
                                        .getStringProperty("DefaultSelectionColor"));
156
                }
157
                return defaultSelectionColor;
158
        }
159

    
160
        public Color getDefaultViewBackColor() {
161
                XMLEntity xml = PluginServices.getPluginServices("org.gvsig.app").getPersistentXML();
162
                if (xml.contains("DefaultViewBackColor")) {
163
                        defaultViewBackColor = StringUtilities.
164
                                string2Color(xml.getStringProperty("DefaultViewBackColor"));
165
                }
166
                return defaultViewBackColor;
167
        }
168

    
169
        public void setDefaultViewBackColor(Color color) {
170
                defaultViewBackColor = color;
171
        }
172

    
173
        public Color getDefaultOverviewBackColor() {
174
                XMLEntity xml = PluginServices.getPluginServices("org.gvsig.app")
175
                                .getPersistentXML();
176
                if (xml.contains("defaultOverviewBackColor")) {
177
                        defaultOverviewBackColor = StringUtilities.string2Color(xml
178
                                        .getStringProperty("defaultOverviewBackColor"));
179
                }
180
                return defaultOverviewBackColor;
181

    
182
        }
183

    
184
        public void setDefaultOverviewBackColor(Color color) {
185
                defaultOverviewBackColor = color;
186
        }
187

    
188
        /**
189
         * Returns the user's default map units. This is the cartography data
190
         * distance units.
191
         *
192
         * @return int (index of the <b>Attributes.NAMES array</b>)
193
         */
194
        public int getDefaultMapUnits() {
195
                if (defaultMapUnits == -1) {
196
                        XMLEntity xml = PluginServices.getPluginServices(
197
                                        "org.gvsig.app").getPersistentXML();
198
                        if (xml.contains("DefaultMapUnits")) {
199
                                defaultMapUnits = xml.getIntProperty("DefaultMapUnits");
200
                        } else {
201
                                // first app run case
202
                                String[] unitNames = MapContext.getDistanceNames();
203
                                for (int i = 0; i < unitNames.length; i++) {
204
                                        // meter is the factory default's map unit
205
                                        if (unitNames[i].equals("Metros")) {
206
                                                defaultMapUnits = i;
207
                                                break;
208
                                        }
209
                                }
210
                        }
211
                        if (defaultMapUnits == -1 || defaultMapUnits >= MapContext.getDistanceNames().length){
212
                                defaultMapUnits = MapContext.getDistancePosition("Metros");
213
                        }
214
                }
215
                return defaultMapUnits;
216
        }
217

    
218
        /**
219
         * Returns the user's default view units for measuring distances. This is
220
         * the units that the user will see in the status bar of the view.
221
         *
222
         * @return int (index of the <b>Attributes.NAMES array</b>)
223
         */
224
        public int getDefaultDistanceUnits() {
225
                if (defaultDistanceUnits == -1) {
226
                        XMLEntity xml = PluginServices.getPluginServices(
227
                                        "org.gvsig.app").getPersistentXML();
228
                        if (xml.contains("DefaultDistanceUnits")) {
229
                                defaultDistanceUnits = xml
230
                                                .getIntProperty("DefaultDistanceUnits");
231
                        } else {
232
                                // first app run case
233
                                String[] unitNames = MapContext.getDistanceNames();
234
                                for (int i = 0; i < unitNames.length; i++) {
235
                                        // meter is the factory default's distance unit
236
                                        if (unitNames[i].equals("Metros")) {
237
                                                defaultDistanceUnits = i;
238
                                                break;
239
                                        }
240
                                }
241
                        }
242
                        if (defaultDistanceUnits == -1 || defaultDistanceUnits >= MapContext.getDistanceNames().length){
243
                                defaultDistanceUnits = MapContext.getDistancePosition("Metros");
244
                        }
245
                }
246
                return defaultDistanceUnits;
247
        }
248
        /**
249
         * Returns the user's default view units for measuring areas. This is
250
         * the units that the user will see in the status bar of the view.
251
         *
252
         * @return int (index of the <b>Attributes.NAMES array</b>)
253
         */
254
        public int getDefaultDistanceArea() {
255
                if (defaultDistanceArea == -1) {
256
                        XMLEntity xml = PluginServices.getPluginServices(
257
                                        "org.gvsig.app").getPersistentXML();
258
                        if (xml.contains("DefaultDistanceArea")) {
259
                                defaultDistanceArea = xml
260
                                                .getIntProperty("DefaultDistanceArea");
261
                        } else {
262
                                // first app run case
263
                                String[] unitNames = MapContext.getAreaNames();
264
                                for (int i = 0; i < unitNames.length; i++) {
265
                                        // meter is the factory default's distance unit
266
                                        if (unitNames[i].equals("Metros")) {
267
                                                defaultDistanceArea = i;
268
                                                break;
269
                                        }
270
                                }
271
                        }
272
                        if (defaultDistanceArea == -1 || defaultDistanceArea >= MapContext.getAreaNames().length){
273
                                defaultDistanceArea=getDefaultDistanceUnits();
274
                        }
275
                }
276
                return defaultDistanceArea;
277
        }
278
        /**
279
         * Sets the default map unit (the units used by the data).
280
         *
281
         * @param mapUnits
282
         */
283
        public void setDefaultMapUnits(int mapUnits) {
284
                defaultMapUnits = mapUnits;
285
        }
286

    
287
        /**
288
         * Sets the default distance units (the units shown in the status bar)
289
         *
290
         * @param distanceUnits
291
         */
292
        public void setDefaultDistanceUnits(int distanceUnits) {
293
                defaultDistanceUnits = distanceUnits;
294
        }
295
        /**
296
         * Sets the default distance area (the units shown in the status bar)
297
         *
298
         * @param distanceUnits
299
         */
300
        public void setDefaultDistanceArea(int distanceArea) {
301
                defaultDistanceArea = distanceArea;
302
        }
303

    
304
}