svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / ProjectPreferences.java @ 38769
History | View | Annotate | Download (8.02 KB)
1 | 31496 | jjdelcerro | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2009 Infrastructures and Transports Department
|
||
4 | 31544 | cordinyana | * of the Valencian Government (CIT)
|
5 | 31496 | jjdelcerro | *
|
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 | |||
33 | import org.cresques.cts.IProjection; |
||
34 | import org.gvsig.andami.PluginServices; |
||
35 | import org.gvsig.app.imp.DefaultPreferencesNode; |
||
36 | import org.gvsig.fmap.crs.CRSFactory; |
||
37 | import org.gvsig.fmap.mapcontext.MapContext; |
||
38 | 38769 | jldominguez | import org.gvsig.fmap.mapcontext.MapContextLocator; |
39 | 31496 | jjdelcerro | import org.gvsig.utils.StringUtilities; |
40 | import org.gvsig.utils.XMLEntity; |
||
41 | |||
42 | /**
|
||
43 | * Clase que representa las preferencias para el proyecto
|
||
44 | *
|
||
45 | * @author 2009- Joaquin del Cerro
|
||
46 | *
|
||
47 | */
|
||
48 | |||
49 | public class ProjectPreferences extends DefaultPreferencesNode { |
||
50 | |||
51 | private IProjection defaultProjection = null; |
||
52 | |||
53 | 38769 | jldominguez | private IProjection defaultFactoryProjection =
|
54 | MapContextLocator.getMapContextManager().getDefaultCRS(); |
||
55 | 31496 | jjdelcerro | |
56 | private Color defaultSelectionColor = Color.YELLOW; |
||
57 | |||
58 | private Color defaultViewBackColor = Color.WHITE; |
||
59 | |||
60 | private Color defaultOverviewBackColor = Color.WHITE; |
||
61 | |||
62 | private int defaultMapUnits = -1; |
||
63 | |||
64 | private int defaultDistanceUnits = -1; |
||
65 | |||
66 | private int defaultDistanceArea = -1; |
||
67 | |||
68 | |||
69 | public ProjectPreferences() {
|
||
70 | } |
||
71 | |||
72 | 38769 | jldominguez | /**
|
73 | 31496 | jjdelcerro | * Sets the projection used when no projection is defined
|
74 | *
|
||
75 | * @param defaultProjection
|
||
76 | */
|
||
77 | public void setDefaultProjection(IProjection defaultProjection) { |
||
78 | this.defaultProjection = defaultProjection;
|
||
79 | } |
||
80 | |||
81 | public int getInt(String name, int defaultValue) { |
||
82 | if( name.equalsIgnoreCase("DefaultDistanceUnits")) { |
||
83 | return this.getDefaultDistanceUnits(); |
||
84 | } else if( name.equalsIgnoreCase("DefaultDistanceArea")) { |
||
85 | return this.getDefaultDistanceArea(); |
||
86 | } else if( name.equalsIgnoreCase("DefaultMapUnits")) { |
||
87 | return this.getDefaultMapUnits(); |
||
88 | } |
||
89 | |||
90 | return super.getInt(name, defaultValue); |
||
91 | } |
||
92 | |||
93 | public IProjection getDefaultProjection() {
|
||
94 | if (defaultProjection == null){ |
||
95 | XMLEntity xml = PluginServices.getPluginServices("org.gvsig.app")
|
||
96 | .getPersistentXML(); |
||
97 | |||
98 | // Default Projection
|
||
99 | String projCode = null; |
||
100 | if (xml.contains("DefaultProjection")) { |
||
101 | projCode = xml.getStringProperty("DefaultProjection");
|
||
102 | setDefaultProjection(CRSFactory.getCRS(projCode)); |
||
103 | } else {
|
||
104 | setDefaultProjection(defaultFactoryProjection); |
||
105 | } |
||
106 | |||
107 | } |
||
108 | return defaultProjection;
|
||
109 | } |
||
110 | |||
111 | /**
|
||
112 | * Sets the default selection color that will be used in subsequent
|
||
113 | * projects.
|
||
114 | *
|
||
115 | * @param color
|
||
116 | */
|
||
117 | public void setDefaultSelectionColor(Color color) { |
||
118 | defaultSelectionColor = color; |
||
119 | } |
||
120 | |||
121 | /**
|
||
122 | * Returns the current default selection color defined which is the color
|
||
123 | * defined when the user does not define any other one
|
||
124 | *
|
||
125 | * @return java.awt.Color
|
||
126 | */
|
||
127 | public Color getDefaultSelectionColor() { |
||
128 | XMLEntity xml = PluginServices.getPluginServices("org.gvsig.app")
|
||
129 | .getPersistentXML(); |
||
130 | if (xml.contains("DefaultSelectionColor")) { |
||
131 | defaultSelectionColor = StringUtilities.string2Color(xml |
||
132 | .getStringProperty("DefaultSelectionColor"));
|
||
133 | } |
||
134 | return defaultSelectionColor;
|
||
135 | } |
||
136 | |||
137 | public Color getDefaultViewBackColor() { |
||
138 | XMLEntity xml = PluginServices.getPluginServices("org.gvsig.app").getPersistentXML();
|
||
139 | if (xml.contains("DefaultViewBackColor")) { |
||
140 | defaultViewBackColor = StringUtilities. |
||
141 | string2Color(xml.getStringProperty("DefaultViewBackColor"));
|
||
142 | } |
||
143 | return defaultViewBackColor;
|
||
144 | } |
||
145 | |||
146 | public void setDefaultViewBackColor(Color color) { |
||
147 | defaultViewBackColor = color; |
||
148 | } |
||
149 | |||
150 | public Color getDefaultOverviewBackColor() { |
||
151 | XMLEntity xml = PluginServices.getPluginServices("org.gvsig.app")
|
||
152 | .getPersistentXML(); |
||
153 | if (xml.contains("defaultOverviewBackColor")) { |
||
154 | defaultOverviewBackColor = StringUtilities.string2Color(xml |
||
155 | .getStringProperty("defaultOverviewBackColor"));
|
||
156 | } |
||
157 | return defaultOverviewBackColor;
|
||
158 | |||
159 | } |
||
160 | |||
161 | public void setDefaultOverviewBackColor(Color color) { |
||
162 | defaultOverviewBackColor = color; |
||
163 | } |
||
164 | |||
165 | /**
|
||
166 | * Returns the user's default map units. This is the cartography data
|
||
167 | * distance units.
|
||
168 | *
|
||
169 | * @return int (index of the <b>Attributes.NAMES array</b>)
|
||
170 | */
|
||
171 | public int getDefaultMapUnits() { |
||
172 | if (defaultMapUnits == -1) { |
||
173 | XMLEntity xml = PluginServices.getPluginServices( |
||
174 | "org.gvsig.app").getPersistentXML();
|
||
175 | if (xml.contains("DefaultMapUnits")) { |
||
176 | defaultMapUnits = xml.getIntProperty("DefaultMapUnits");
|
||
177 | } else {
|
||
178 | // first app run case
|
||
179 | String[] unitNames = MapContext.getDistanceNames(); |
||
180 | for (int i = 0; i < unitNames.length; i++) { |
||
181 | // meter is the factory default's map unit
|
||
182 | if (unitNames[i].equals("Metros")) { |
||
183 | defaultMapUnits = i; |
||
184 | break;
|
||
185 | } |
||
186 | } |
||
187 | } |
||
188 | if (defaultMapUnits == -1 || defaultMapUnits >= MapContext.getDistanceNames().length){ |
||
189 | defaultMapUnits = MapContext.getDistancePosition("Metros");
|
||
190 | } |
||
191 | } |
||
192 | return defaultMapUnits;
|
||
193 | } |
||
194 | |||
195 | /**
|
||
196 | * Returns the user's default view units for measuring distances. This is
|
||
197 | * the units that the user will see in the status bar of the view.
|
||
198 | *
|
||
199 | * @return int (index of the <b>Attributes.NAMES array</b>)
|
||
200 | */
|
||
201 | public int getDefaultDistanceUnits() { |
||
202 | if (defaultDistanceUnits == -1) { |
||
203 | XMLEntity xml = PluginServices.getPluginServices( |
||
204 | "org.gvsig.app").getPersistentXML();
|
||
205 | if (xml.contains("DefaultDistanceUnits")) { |
||
206 | defaultDistanceUnits = xml |
||
207 | .getIntProperty("DefaultDistanceUnits");
|
||
208 | } else {
|
||
209 | // first app run case
|
||
210 | String[] unitNames = MapContext.getDistanceNames(); |
||
211 | for (int i = 0; i < unitNames.length; i++) { |
||
212 | // meter is the factory default's distance unit
|
||
213 | if (unitNames[i].equals("Metros")) { |
||
214 | defaultDistanceUnits = i; |
||
215 | break;
|
||
216 | } |
||
217 | } |
||
218 | } |
||
219 | if (defaultDistanceUnits == -1 || defaultDistanceUnits >= MapContext.getDistanceNames().length){ |
||
220 | defaultDistanceUnits = MapContext.getDistancePosition("Metros");
|
||
221 | } |
||
222 | } |
||
223 | return defaultDistanceUnits;
|
||
224 | } |
||
225 | /**
|
||
226 | * Returns the user's default view units for measuring areas. This is
|
||
227 | * the units that the user will see in the status bar of the view.
|
||
228 | *
|
||
229 | * @return int (index of the <b>Attributes.NAMES array</b>)
|
||
230 | */
|
||
231 | public int getDefaultDistanceArea() { |
||
232 | if (defaultDistanceArea == -1) { |
||
233 | XMLEntity xml = PluginServices.getPluginServices( |
||
234 | "org.gvsig.app").getPersistentXML();
|
||
235 | if (xml.contains("DefaultDistanceArea")) { |
||
236 | defaultDistanceArea = xml |
||
237 | .getIntProperty("DefaultDistanceArea");
|
||
238 | } else {
|
||
239 | // first app run case
|
||
240 | String[] unitNames = MapContext.getAreaNames(); |
||
241 | for (int i = 0; i < unitNames.length; i++) { |
||
242 | // meter is the factory default's distance unit
|
||
243 | if (unitNames[i].equals("Metros")) { |
||
244 | defaultDistanceArea = i; |
||
245 | break;
|
||
246 | } |
||
247 | } |
||
248 | } |
||
249 | if (defaultDistanceArea == -1 || defaultDistanceArea >= MapContext.getAreaNames().length){ |
||
250 | defaultDistanceArea=getDefaultDistanceUnits(); |
||
251 | } |
||
252 | } |
||
253 | return defaultDistanceArea;
|
||
254 | } |
||
255 | /**
|
||
256 | * Sets the default map unit (the units used by the data).
|
||
257 | *
|
||
258 | * @param mapUnits
|
||
259 | */
|
||
260 | public void setDefaultMapUnits(int mapUnits) { |
||
261 | defaultMapUnits = mapUnits; |
||
262 | } |
||
263 | |||
264 | /**
|
||
265 | * Sets the default distance units (the units shown in the status bar)
|
||
266 | *
|
||
267 | * @param distanceUnits
|
||
268 | */
|
||
269 | public void setDefaultDistanceUnits(int distanceUnits) { |
||
270 | defaultDistanceUnits = distanceUnits; |
||
271 | } |
||
272 | /**
|
||
273 | * Sets the default distance area (the units shown in the status bar)
|
||
274 | *
|
||
275 | * @param distanceUnits
|
||
276 | */
|
||
277 | public void setDefaultDistanceArea(int distanceArea) { |
||
278 | defaultDistanceArea = distanceArea; |
||
279 | } |
||
280 | |||
281 | } |