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 @ 43100
History | View | Annotate | Download (15.3 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 modify it under
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
9 |
* version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14 |
* details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License along with
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.app.project; |
24 |
|
25 |
import java.awt.Color; |
26 |
import org.apache.commons.lang.StringUtils; |
27 |
import org.apache.commons.lang3.BooleanUtils; |
28 |
|
29 |
import org.cresques.cts.IProjection; |
30 |
import org.gvsig.andami.PluginServices; |
31 |
import org.gvsig.andami.PluginsLocator; |
32 |
import org.gvsig.app.imp.DefaultPreferencesNode; |
33 |
import org.gvsig.fmap.crs.CRSFactory; |
34 |
import org.gvsig.fmap.mapcontext.MapContext; |
35 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
36 |
import org.gvsig.tools.dynobject.DynObject; |
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 |
public class ProjectPreferences extends DefaultPreferencesNode { |
47 |
|
48 |
public static final String DEFAULT_PROJECTION_KEY_NAME = "DefaultProjection"; |
49 |
private static final String ZOOM_IN_FACTOR = "ZoomInFactor"; |
50 |
private static final String ZOOM_OUT_FACTOR = "ZoomOutFactor"; |
51 |
private static final String KEEP_SCALE_ON_RESIZING = "KeepScaleOnResizing"; |
52 |
private static final String OPEN_WITH_A_NEW_MAXIMIZED_VIEW = "OpenWithANewMaximizedView"; |
53 |
private static final String ADD_NEW_LAYERS_IN_INVISIBLE_MODE = "NewLayersInInvisibleMode"; |
54 |
|
55 |
private IProjection defaultProjection = null; |
56 |
|
57 |
private final IProjection defaultFactoryProjection |
58 |
= MapContextLocator.getMapContextManager().getDefaultCRS(); |
59 |
|
60 |
private Color defaultSelectionColor = Color.YELLOW; |
61 |
|
62 |
private Color defaultViewBackColor = Color.WHITE; |
63 |
|
64 |
private Color defaultOverviewBackColor = Color.WHITE; |
65 |
|
66 |
private int defaultMapUnits = -1; |
67 |
|
68 |
private int defaultDistanceUnits = -1; |
69 |
|
70 |
private int defaultDistanceArea = -1; |
71 |
|
72 |
private final PluginServices plugin; |
73 |
private final DynObject pluginPreferences; |
74 |
|
75 |
public ProjectPreferences() {
|
76 |
this.plugin = PluginsLocator.getManager().getPlugin(this); |
77 |
this.pluginPreferences = plugin.getPluginProperties();
|
78 |
} |
79 |
|
80 |
/**
|
81 |
* Sets the projection used when no projection is defined
|
82 |
*
|
83 |
* @param defaultProjection
|
84 |
*/
|
85 |
public void setDefaultProjection(IProjection defaultProjection) { |
86 |
this.defaultProjection = defaultProjection;
|
87 |
if (defaultProjection != null) { |
88 |
XMLEntity xml = plugin.getPersistentXML(); |
89 |
xml.putProperty(DEFAULT_PROJECTION_KEY_NAME, defaultProjection.getAbrev()); |
90 |
} |
91 |
} |
92 |
|
93 |
public void setDefaultProjection(String defaultProjection) { |
94 |
if (!StringUtils.isEmpty(defaultProjection)) {
|
95 |
this.setDefaultProjection(CRSFactory.getCRS(defaultProjection));
|
96 |
} |
97 |
} |
98 |
|
99 |
public IProjection getDefaultProjection() {
|
100 |
if (this.defaultProjection == null) { |
101 |
XMLEntity xml = plugin.getPersistentXML(); |
102 |
if (xml.contains(DEFAULT_PROJECTION_KEY_NAME)) {
|
103 |
String projCode = xml.getStringProperty(DEFAULT_PROJECTION_KEY_NAME);
|
104 |
this.defaultProjection = CRSFactory.getCRS(projCode);
|
105 |
} else {
|
106 |
this.defaultProjection = defaultFactoryProjection;
|
107 |
} |
108 |
} |
109 |
return this.defaultProjection; |
110 |
} |
111 |
|
112 |
@Override
|
113 |
public int getInt(String name, int defaultValue) { |
114 |
if (name.equalsIgnoreCase("DefaultDistanceUnits")) { |
115 |
return this.getDefaultDistanceUnits(); |
116 |
} else if (name.equalsIgnoreCase("DefaultDistanceArea")) { |
117 |
return this.getDefaultDistanceArea(); |
118 |
} else if (name.equalsIgnoreCase("DefaultMapUnits")) { |
119 |
return this.getDefaultMapUnits(); |
120 |
} |
121 |
|
122 |
return super.getInt(name, defaultValue); |
123 |
} |
124 |
|
125 |
/**
|
126 |
* Sets the default selection color that will be used in subsequent
|
127 |
* projects.
|
128 |
*
|
129 |
* @param color
|
130 |
*/
|
131 |
public void setDefaultSelectionColor(Color color) { |
132 |
defaultSelectionColor = color; |
133 |
XMLEntity xml = plugin.getPersistentXML(); |
134 |
xml.putProperty("DefaultSelectionColor", StringUtilities.color2String(color));
|
135 |
} |
136 |
|
137 |
/**
|
138 |
* Returns the current default selection color defined which is the color
|
139 |
* defined when the user does not define any other one
|
140 |
*
|
141 |
* @return java.awt.Color
|
142 |
*/
|
143 |
public Color getDefaultSelectionColor() { |
144 |
XMLEntity xml = plugin.getPersistentXML(); |
145 |
if (xml.contains("DefaultSelectionColor")) { |
146 |
defaultSelectionColor = StringUtilities.string2Color(xml |
147 |
.getStringProperty("DefaultSelectionColor"));
|
148 |
} |
149 |
return defaultSelectionColor;
|
150 |
} |
151 |
|
152 |
public Color getDefaultViewBackColor() { |
153 |
XMLEntity xml = PluginServices.getPluginServices("org.gvsig.app").getPersistentXML();
|
154 |
if (xml.contains("DefaultViewBackColor")) { |
155 |
defaultViewBackColor = StringUtilities. |
156 |
string2Color(xml.getStringProperty("DefaultViewBackColor"));
|
157 |
} |
158 |
return defaultViewBackColor;
|
159 |
} |
160 |
|
161 |
public void setDefaultViewBackColor(Color color) { |
162 |
defaultViewBackColor = color; |
163 |
XMLEntity xml = plugin.getPersistentXML(); |
164 |
xml.putProperty("DefaultViewBackColor", StringUtilities.color2String(color));
|
165 |
} |
166 |
|
167 |
public Color getDefaultOverviewBackColor() { |
168 |
XMLEntity xml = plugin.getPersistentXML(); |
169 |
if (xml.contains("defaultOverviewBackColor")) { |
170 |
defaultOverviewBackColor = StringUtilities.string2Color(xml |
171 |
.getStringProperty("defaultOverviewBackColor"));
|
172 |
} |
173 |
return defaultOverviewBackColor;
|
174 |
|
175 |
} |
176 |
|
177 |
public void setDefaultOverviewBackColor(Color color) { |
178 |
defaultOverviewBackColor = color; |
179 |
} |
180 |
|
181 |
/**
|
182 |
* Returns the user's default map units. This is the cartography data
|
183 |
* distance units.
|
184 |
*
|
185 |
* @return int (index of the <b>Attributes.NAMES array</b>)
|
186 |
*/
|
187 |
public int getDefaultMapUnits() { |
188 |
if (defaultMapUnits == -1) { |
189 |
XMLEntity xml = plugin.getPersistentXML(); |
190 |
if (xml.contains("DefaultMapUnits")) { |
191 |
defaultMapUnits = xml.getIntProperty("DefaultMapUnits");
|
192 |
} else {
|
193 |
// first app run case
|
194 |
String[] unitNames = MapContext.getDistanceNames(); |
195 |
for (int i = 0; i < unitNames.length; i++) { |
196 |
// meter is the factory default's map unit
|
197 |
if (unitNames[i].equals("Metros")) { |
198 |
defaultMapUnits = i; |
199 |
break;
|
200 |
} |
201 |
} |
202 |
} |
203 |
if (defaultMapUnits == -1 || defaultMapUnits >= MapContext.getDistanceNames().length) { |
204 |
defaultMapUnits = MapContext.getDistancePosition("Metros");
|
205 |
} |
206 |
} |
207 |
return defaultMapUnits;
|
208 |
} |
209 |
|
210 |
/**
|
211 |
* Returns the user's default view units for measuring distances. This is
|
212 |
* the units that the user will see in the status bar of the view.
|
213 |
*
|
214 |
* @return int (index of the <b>Attributes.NAMES array</b>)
|
215 |
*/
|
216 |
public int getDefaultDistanceUnits() { |
217 |
if (defaultDistanceUnits == -1) { |
218 |
XMLEntity xml = plugin.getPersistentXML(); |
219 |
if (xml.contains("DefaultDistanceUnits")) { |
220 |
defaultDistanceUnits = xml |
221 |
.getIntProperty("DefaultDistanceUnits");
|
222 |
} else {
|
223 |
// first app run case
|
224 |
String[] unitNames = MapContext.getDistanceNames(); |
225 |
for (int i = 0; i < unitNames.length; i++) { |
226 |
// meter is the factory default's distance unit
|
227 |
if (unitNames[i].equals("Metros")) { |
228 |
defaultDistanceUnits = i; |
229 |
break;
|
230 |
} |
231 |
} |
232 |
} |
233 |
if (defaultDistanceUnits == -1 || defaultDistanceUnits >= MapContext.getDistanceNames().length) { |
234 |
defaultDistanceUnits = MapContext.getDistancePosition("Metros");
|
235 |
} |
236 |
} |
237 |
return defaultDistanceUnits;
|
238 |
} |
239 |
|
240 |
/**
|
241 |
* Returns the user's default view units for measuring areas. This is the
|
242 |
* units that the user will see in the status bar of the view.
|
243 |
*
|
244 |
* @return int (index of the <b>Attributes.NAMES array</b>)
|
245 |
*/
|
246 |
public int getDefaultDistanceArea() { |
247 |
if (defaultDistanceArea == -1) { |
248 |
XMLEntity xml = plugin.getPersistentXML(); |
249 |
if (xml.contains("DefaultDistanceArea")) { |
250 |
defaultDistanceArea = xml |
251 |
.getIntProperty("DefaultDistanceArea");
|
252 |
} else {
|
253 |
// first app run case
|
254 |
String[] unitNames = MapContext.getAreaNames(); |
255 |
for (int i = 0; i < unitNames.length; i++) { |
256 |
// meter is the factory default's distance unit
|
257 |
if (unitNames[i].equals("Metros")) { |
258 |
defaultDistanceArea = i; |
259 |
break;
|
260 |
} |
261 |
} |
262 |
} |
263 |
if (defaultDistanceArea == -1 || defaultDistanceArea >= MapContext.getAreaNames().length) { |
264 |
defaultDistanceArea = getDefaultDistanceUnits(); |
265 |
} |
266 |
} |
267 |
return defaultDistanceArea;
|
268 |
} |
269 |
|
270 |
/**
|
271 |
* Sets the default map unit (the units used by the data).
|
272 |
*
|
273 |
* @param mapUnits
|
274 |
*/
|
275 |
public void setDefaultMapUnits(int mapUnits) { |
276 |
defaultMapUnits = mapUnits; |
277 |
XMLEntity xml = plugin.getPersistentXML(); |
278 |
xml.putProperty("DefaultMapUnits", mapUnits);
|
279 |
} |
280 |
|
281 |
/**
|
282 |
* Sets the default distance units (the units shown in the status bar)
|
283 |
*
|
284 |
* @param distanceUnits
|
285 |
*/
|
286 |
public void setDefaultDistanceUnits(int distanceUnits) { |
287 |
defaultDistanceUnits = distanceUnits; |
288 |
XMLEntity xml = plugin.getPersistentXML(); |
289 |
xml.putProperty("DefaultDistanceUnits", distanceUnits);
|
290 |
} |
291 |
|
292 |
/**
|
293 |
* Sets the default distance area (the units shown in the status bar)
|
294 |
*
|
295 |
* @param distanceArea
|
296 |
*/
|
297 |
public void setDefaultDistanceArea(int distanceArea) { |
298 |
defaultDistanceArea = distanceArea; |
299 |
XMLEntity xml = plugin.getPersistentXML(); |
300 |
xml.putProperty("DefaultDistanceArea", distanceArea);
|
301 |
} |
302 |
|
303 |
public boolean getAddNewLayersInInvisibleMode() { |
304 |
Boolean addNewLayersInInvisibleMode = (Boolean) this.pluginPreferences.getDynValue(ADD_NEW_LAYERS_IN_INVISIBLE_MODE); |
305 |
if (addNewLayersInInvisibleMode == null) { |
306 |
XMLEntity xml = plugin.getPersistentXML(); |
307 |
if (xml.contains(ADD_NEW_LAYERS_IN_INVISIBLE_MODE)) {
|
308 |
addNewLayersInInvisibleMode = xml.getBooleanProperty(ADD_NEW_LAYERS_IN_INVISIBLE_MODE); |
309 |
} else {
|
310 |
addNewLayersInInvisibleMode = false;
|
311 |
} |
312 |
this.pluginPreferences.setDynValue(ADD_NEW_LAYERS_IN_INVISIBLE_MODE, addNewLayersInInvisibleMode);
|
313 |
} |
314 |
return BooleanUtils.isTrue(addNewLayersInInvisibleMode);
|
315 |
} |
316 |
|
317 |
public void setAddNewLayersInInvisibleMode(boolean addNewLayersInInvisibleMode) { |
318 |
this.pluginPreferences.setDynValue(ADD_NEW_LAYERS_IN_INVISIBLE_MODE, addNewLayersInInvisibleMode);
|
319 |
} |
320 |
|
321 |
public boolean getOpenWithANewMaximizedView() { |
322 |
Boolean openWithANewMaximizedView = (Boolean) this.pluginPreferences.getDynValue(OPEN_WITH_A_NEW_MAXIMIZED_VIEW); |
323 |
if (openWithANewMaximizedView == null) { |
324 |
XMLEntity xml = plugin.getPersistentXML(); |
325 |
if (xml.contains(OPEN_WITH_A_NEW_MAXIMIZED_VIEW)) {
|
326 |
openWithANewMaximizedView = xml.getBooleanProperty(OPEN_WITH_A_NEW_MAXIMIZED_VIEW); |
327 |
} else {
|
328 |
openWithANewMaximizedView = true;
|
329 |
} |
330 |
this.pluginPreferences.setDynValue(OPEN_WITH_A_NEW_MAXIMIZED_VIEW, openWithANewMaximizedView);
|
331 |
} |
332 |
return BooleanUtils.isTrue(openWithANewMaximizedView);
|
333 |
} |
334 |
|
335 |
public void setOpenWithANewMaximizedView(boolean openWithANewMaximizedView) { |
336 |
this.pluginPreferences.setDynValue(OPEN_WITH_A_NEW_MAXIMIZED_VIEW, openWithANewMaximizedView);
|
337 |
} |
338 |
|
339 |
public boolean getKeepScaleOnResizing() { |
340 |
Boolean keepScaleOnResizing = (Boolean) this.pluginPreferences.getDynValue(KEEP_SCALE_ON_RESIZING); |
341 |
if (keepScaleOnResizing == null) { |
342 |
XMLEntity xml = plugin.getPersistentXML(); |
343 |
if (xml.contains(KEEP_SCALE_ON_RESIZING)) {
|
344 |
keepScaleOnResizing = xml.getBooleanProperty(KEEP_SCALE_ON_RESIZING); |
345 |
} else {
|
346 |
keepScaleOnResizing = false;
|
347 |
} |
348 |
this.pluginPreferences.setDynValue(KEEP_SCALE_ON_RESIZING, keepScaleOnResizing);
|
349 |
} |
350 |
return BooleanUtils.isTrue(keepScaleOnResizing);
|
351 |
} |
352 |
|
353 |
public void setKeepScaleOnResizing(boolean keepScaleOnResizing) { |
354 |
this.pluginPreferences.setDynValue(KEEP_SCALE_ON_RESIZING, keepScaleOnResizing);
|
355 |
} |
356 |
|
357 |
public double getZoomInFactor() { |
358 |
Double zoomInFactor = (Double) this.pluginPreferences.getDynValue(ZOOM_IN_FACTOR); |
359 |
if (zoomInFactor == null) { |
360 |
XMLEntity xml = plugin.getPersistentXML(); |
361 |
if (xml.contains(ZOOM_IN_FACTOR)) {
|
362 |
zoomInFactor = xml.getDoubleProperty(ZOOM_IN_FACTOR); |
363 |
} else {
|
364 |
zoomInFactor = MapContext.ZOOMINFACTOR; |
365 |
} |
366 |
this.pluginPreferences.setDynValue(ZOOM_IN_FACTOR, zoomInFactor);
|
367 |
} |
368 |
return zoomInFactor;
|
369 |
} |
370 |
|
371 |
public void setZoomInFactor(double zoomInFactor) { |
372 |
this.pluginPreferences.setDynValue(ZOOM_IN_FACTOR, zoomInFactor);
|
373 |
} |
374 |
|
375 |
public double getZoomOutFactor() { |
376 |
Double zoomOutFactor = (Double) this.pluginPreferences.getDynValue(ZOOM_OUT_FACTOR); |
377 |
if (zoomOutFactor == null) { |
378 |
XMLEntity xml = plugin.getPersistentXML(); |
379 |
if (xml.contains(ZOOM_OUT_FACTOR)) {
|
380 |
zoomOutFactor = xml.getDoubleProperty(ZOOM_OUT_FACTOR); |
381 |
} else {
|
382 |
zoomOutFactor = MapContext.ZOOMINFACTOR; |
383 |
} |
384 |
this.pluginPreferences.setDynValue(ZOOM_OUT_FACTOR, zoomOutFactor);
|
385 |
} |
386 |
return zoomOutFactor;
|
387 |
} |
388 |
|
389 |
public void setZoomOutFactor(double zoomOutFactor) { |
390 |
this.pluginPreferences.setDynValue(ZOOM_OUT_FACTOR, zoomOutFactor);
|
391 |
} |
392 |
|
393 |
public boolean getHideLegendInToCOfNonVisibleLayers() { |
394 |
Boolean hideLegendInToCOfNonVisibleLayers = (Boolean)this.pluginPreferences.getDynValue("hideLegendInToCOfNonVisibleLayers"); |
395 |
return BooleanUtils.toBooleanDefaultIfNull(hideLegendInToCOfNonVisibleLayers,true); |
396 |
} |
397 |
|
398 |
public void setHideLegendInToCOfNonVisibleLayers(boolean hideLegendInToCOfNonVisibleLayers) { |
399 |
this.pluginPreferences.setDynValue("hideLegendInToCOfNonVisibleLayers", hideLegendInToCOfNonVisibleLayers); |
400 |
} |
401 |
|
402 |
} |