23 |
package org.jsampler; |
package org.jsampler; |
24 |
|
|
25 |
import java.beans.PropertyChangeSupport; |
import java.beans.PropertyChangeSupport; |
26 |
|
|
27 |
|
import java.io.BufferedReader; |
28 |
|
import java.io.StringReader; |
29 |
|
|
30 |
|
import java.util.Vector; |
31 |
import java.util.prefs.Preferences; |
import java.util.prefs.Preferences; |
32 |
|
|
33 |
/** |
/** |
77 |
} |
} |
78 |
|
|
79 |
/** |
/** |
80 |
* Sets an integer property. |
* Sets a string property. |
81 |
* @param name The name of the property. |
* @param name The name of the property. |
82 |
* @param i The new value for the specified property. |
* @param s The new value for the specified property. |
83 |
*/ |
*/ |
84 |
public void |
public void |
85 |
setStringProperty(String name, String s) { |
setStringProperty(String name, String s) { |
103 |
getDefaultStringValue(String name) { return null; } |
getDefaultStringValue(String name) { return null; } |
104 |
|
|
105 |
/** |
/** |
106 |
|
* Gets a string list property. |
107 |
|
* @param name The name of the property. |
108 |
|
* @return The value of the specified property. |
109 |
|
* If the property is not set, the return value is an empty array. |
110 |
|
* @see #getDefaultStringListValue |
111 |
|
*/ |
112 |
|
public String[] |
113 |
|
getStringListProperty(String name) { |
114 |
|
return getStringListProperty(name, getDefaultStringListValue(name)); |
115 |
|
} |
116 |
|
|
117 |
|
/** |
118 |
|
* Gets a string list property. |
119 |
|
* @param name The name of the property. |
120 |
|
* @param defaultValue The value to return if the property is not set. |
121 |
|
* @return The value of the specified property. |
122 |
|
*/ |
123 |
|
public String[] |
124 |
|
getStringListProperty(String name, String[] defaultValue) { |
125 |
|
String s = user().get(name, null); |
126 |
|
if(s == null) return defaultValue; |
127 |
|
if(s.length() == 0) return new String[0]; |
128 |
|
|
129 |
|
BufferedReader br = new BufferedReader(new StringReader(s)); |
130 |
|
Vector<String> v = new Vector(); |
131 |
|
|
132 |
|
try { |
133 |
|
s = br.readLine(); |
134 |
|
while(s != null) { |
135 |
|
v.add(s); |
136 |
|
s = br.readLine(); |
137 |
|
} |
138 |
|
} catch(Exception x) { |
139 |
|
x.printStackTrace(); |
140 |
|
} |
141 |
|
|
142 |
|
return v.toArray(new String[v.size()]); |
143 |
|
} |
144 |
|
|
145 |
|
/** |
146 |
|
* Sets a string list property. |
147 |
|
* Note that the string elements may not contain new lines. |
148 |
|
* @param name The name of the property. |
149 |
|
* @param list The new value for the specified property. |
150 |
|
*/ |
151 |
|
public void |
152 |
|
setStringListProperty(String name, String[] list) { |
153 |
|
String[] oldValue = getStringListProperty(name); |
154 |
|
|
155 |
|
if(list == null) user().remove(name); |
156 |
|
else { |
157 |
|
StringBuffer sb = new StringBuffer(); |
158 |
|
for(String s : list) sb.append(s).append("\n"); |
159 |
|
user().put(name, sb.toString()); |
160 |
|
} |
161 |
|
|
162 |
|
firePropertyChange(name, oldValue, list); |
163 |
|
} |
164 |
|
|
165 |
|
/** |
166 |
|
* Gets the default value for the specified property. |
167 |
|
* The default value is used when the property is not set. |
168 |
|
* Override this method to provide custom default values for specific properties. |
169 |
|
* @name The name of the property whose default value should be obtained. |
170 |
|
* @return An empty array. |
171 |
|
* @see #getStringListProperty(String name) |
172 |
|
*/ |
173 |
|
public String[] |
174 |
|
getDefaultStringListValue(String name) { return new String[0]; } |
175 |
|
|
176 |
|
/** |
177 |
* Gets an integer property. |
* Gets an integer property. |
178 |
* @param name The name of the property. |
* @param name The name of the property. |
179 |
* @return The value of the specified property. |
* @return The value of the specified property. |