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