svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / imp / DefaultPreferencesNode.java @ 40558
History | View | Annotate | Download (5.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 |
package org.gvsig.app.imp; |
25 |
|
26 |
import java.awt.Color; |
27 |
|
28 |
import org.gvsig.andami.PluginServices; |
29 |
import org.gvsig.app.PreferencesNode; |
30 |
import org.gvsig.utils.StringUtilities; |
31 |
import org.gvsig.utils.XMLEntity; |
32 |
|
33 |
public class DefaultPreferencesNode implements PreferencesNode { |
34 |
|
35 |
private String name; |
36 |
private XMLEntity node;
|
37 |
|
38 |
public DefaultPreferencesNode() {
|
39 |
this.name = null; |
40 |
} |
41 |
|
42 |
public DefaultPreferencesNode(String nodeName) { |
43 |
this.name = nodeName;
|
44 |
} |
45 |
|
46 |
protected XMLEntity getRootNode() {
|
47 |
XMLEntity node = PluginServices.getPluginServices("org.gvsig.app") .getPersistentXML();
|
48 |
return node;
|
49 |
} |
50 |
|
51 |
protected XMLEntity getNode() {
|
52 |
if( this.node == null ) { |
53 |
if( this.name == null ) { |
54 |
this.node = this.getRootNode(); |
55 |
} else {
|
56 |
this.node = this.getRootNode().firstChild(this.name); |
57 |
} |
58 |
} |
59 |
return this.node; |
60 |
} |
61 |
|
62 |
public String name() { |
63 |
return this.name; |
64 |
} |
65 |
|
66 |
public String[] keys() throws Exception { |
67 |
XMLEntity node = this.getNode();
|
68 |
int count = node.getChildrenCount();
|
69 |
String[] keys = new String[count]; |
70 |
for(int i=0 ; i<count ; i++ ) { |
71 |
keys[i] = node.getChild(i).getName(); |
72 |
} |
73 |
return keys;
|
74 |
} |
75 |
|
76 |
public void clear() throws Exception { |
77 |
XMLEntity node = this.getNode();
|
78 |
node.removeAllChildren(); |
79 |
} |
80 |
|
81 |
public void flush() throws Exception { |
82 |
// do nothing
|
83 |
} |
84 |
|
85 |
public String get(String name, String defaultValue) { |
86 |
XMLEntity node = this.getNode();
|
87 |
|
88 |
if (!node.contains(name)) {
|
89 |
return defaultValue;
|
90 |
} |
91 |
String value = node.getStringProperty(name);
|
92 |
return value;
|
93 |
} |
94 |
|
95 |
public boolean getBoolean(String name, boolean defaultValue) { |
96 |
XMLEntity node = this.getNode();
|
97 |
|
98 |
if (!node.contains(name)) {
|
99 |
return defaultValue;
|
100 |
} |
101 |
boolean value = node.getBooleanProperty(name);
|
102 |
return value;
|
103 |
} |
104 |
|
105 |
public byte[] getByteArray(String name, byte[] defaultValue) { |
106 |
XMLEntity node = this.getNode();
|
107 |
|
108 |
if (!node.contains(name)) {
|
109 |
return defaultValue;
|
110 |
} |
111 |
byte[] value = node.getByteArrayProperty(name); |
112 |
return value;
|
113 |
} |
114 |
|
115 |
public double getDouble(String name, double defaultValue) { |
116 |
XMLEntity node = this.getNode();
|
117 |
|
118 |
if (!node.contains(name)) {
|
119 |
return defaultValue;
|
120 |
} |
121 |
double value = node.getDoubleProperty(name);
|
122 |
return value;
|
123 |
} |
124 |
|
125 |
public float getFloat(String name, float defaultValue) { |
126 |
XMLEntity node = this.getNode();
|
127 |
|
128 |
if (!node.contains(name)) {
|
129 |
return defaultValue;
|
130 |
} |
131 |
float value = node.getFloatProperty(name);
|
132 |
return value;
|
133 |
} |
134 |
|
135 |
public int getInt(String name, int defaultValue) { |
136 |
XMLEntity node = this.getNode();
|
137 |
|
138 |
if (!node.contains(name)) {
|
139 |
return defaultValue;
|
140 |
} |
141 |
int value = node.getIntProperty(name);
|
142 |
return value;
|
143 |
} |
144 |
|
145 |
public long getLong(String name, long defaultValue) { |
146 |
XMLEntity node = this.getNode();
|
147 |
|
148 |
if (!node.contains(name)) {
|
149 |
return defaultValue;
|
150 |
} |
151 |
long value = node.getLongProperty(name);
|
152 |
return value;
|
153 |
} |
154 |
|
155 |
public Color getColor(String name, Color defaultValue) { |
156 |
XMLEntity node = this.getNode();
|
157 |
|
158 |
if (!node.contains(name)) {
|
159 |
return defaultValue;
|
160 |
} |
161 |
String value = node.getStringProperty(name);
|
162 |
return StringUtilities.string2Color(value);
|
163 |
} |
164 |
|
165 |
public void put(String name, String value) { |
166 |
XMLEntity node = this.getNode();
|
167 |
|
168 |
node.putProperty(name, value); |
169 |
} |
170 |
|
171 |
public void putBoolean(String name, boolean value) { |
172 |
XMLEntity node = this.getNode();
|
173 |
|
174 |
node.putProperty(name, value); |
175 |
} |
176 |
|
177 |
public void putByteArray(String name, byte[] value) { |
178 |
XMLEntity node = this.getNode();
|
179 |
|
180 |
node.putProperty(name, value); |
181 |
} |
182 |
|
183 |
public void putDouble(String name, double value) { |
184 |
XMLEntity node = this.getNode();
|
185 |
|
186 |
node.putProperty(name, value); |
187 |
} |
188 |
|
189 |
public void putFloat(String name, float value) { |
190 |
XMLEntity node = this.getNode();
|
191 |
|
192 |
node.putProperty(name, value); |
193 |
} |
194 |
|
195 |
public void putInt(String name, int value) { |
196 |
XMLEntity node = this.getNode();
|
197 |
|
198 |
node.putProperty(name, value); |
199 |
} |
200 |
|
201 |
public void putLong(String name, long value) { |
202 |
XMLEntity node = this.getNode();
|
203 |
|
204 |
node.putProperty(name, value); |
205 |
} |
206 |
|
207 |
public void remove(String name) { |
208 |
XMLEntity node = this.getNode();
|
209 |
|
210 |
if (!node.contains(name)) {
|
211 |
return;
|
212 |
} |
213 |
node.remove(name); |
214 |
} |
215 |
|
216 |
public void sync() throws Exception { |
217 |
// do nothing
|
218 |
} |
219 |
|
220 |
} |