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