1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.log4j.chainsaw;
18
19 import java.beans.PropertyChangeListener;
20 import java.beans.PropertyChangeSupport;
21
22
23 /***
24 * Encapsulates the Chainsaw Application wide properties
25 *
26 * @author Paul Smith <psmith@apache.org>
27 *
28 */
29 public class ApplicationPreferenceModel {
30
31 private boolean showNoReceiverWarning = true ;
32 private boolean statusBar = true;
33 private boolean toolbar = true;
34 private boolean receivers = true;
35 private boolean confirmExit = true;
36 private boolean showSplash = true;
37 private String lookAndFeelClassName = "";
38 private int toolTipDisplayMillis = 4000;
39 private int cyclicBufferSize = 5000;
40 private String lastUsedVersion = "";
41 private int responsiveness = 3;
42
43 private String identifierExpression = "PROP.hostname - PROP.application";
44
45 private transient final PropertyChangeSupport propertySupport =
46 new PropertyChangeSupport(this);
47
48 private int tabPlacement = 3;
49
50 /***
51 * If not 'empty', this property will be used as the URL to load log4j configuration at startup
52 */
53 private String configurationURL="";
54
55 /***
56 * this means for Receivers that require optional jars that can't be delivered
57 * by the Web start classloader, we need to be able to remove the SecurityManager in place
58 */
59 private boolean okToRemoveSecurityManager = false;
60
61 /***
62 * @param listener
63 */
64 public void addPropertyChangeListener(PropertyChangeListener listener) {
65 propertySupport.addPropertyChangeListener(listener);
66 }
67
68 /***
69 * @param propertyName
70 * @param listener
71 */
72 public void addPropertyChangeListener(String propertyName,
73 PropertyChangeListener listener) {
74 propertySupport.addPropertyChangeListener(propertyName, listener);
75 }
76
77 /***
78 * @param propertyName
79 * @param oldValue
80 * @param newValue
81 */
82 private void firePropertyChange(String propertyName, boolean oldValue,
83 boolean newValue) {
84 propertySupport.firePropertyChange(propertyName, oldValue, newValue);
85 }
86
87 /***
88 * @param propertyName
89 * @param oldValue
90 * @param newValue
91 */
92 private void firePropertyChange(String propertyName, int oldValue,
93 int newValue) {
94 propertySupport.firePropertyChange(propertyName, oldValue, newValue);
95 }
96
97 /***
98 * @param propertyName
99 * @param oldValue
100 * @param newValue
101 */
102 private void firePropertyChange(String propertyName, Object oldValue,
103 Object newValue) {
104 propertySupport.firePropertyChange(propertyName, oldValue, newValue);
105 }
106
107 /***
108 * @param propertyName
109 * @return listeners flag
110 */
111 public boolean hasListeners(String propertyName) {
112 return propertySupport.hasListeners(propertyName);
113 }
114
115 /***
116 * @param listener
117 */
118 public void removePropertyChangeListener(PropertyChangeListener listener) {
119 propertySupport.removePropertyChangeListener(listener);
120 }
121
122 /***
123 * @return Returns the showNoReceiverWarning.
124 */
125 public final boolean isShowNoReceiverWarning() {
126
127 return showNoReceiverWarning;
128 }
129
130 public final String getIdentifierExpression() {
131 return identifierExpression;
132 }
133
134 public final void setCyclicBufferSize(int newCyclicBufferSize) {
135 int oldCyclicBufferSize = cyclicBufferSize;
136 cyclicBufferSize = newCyclicBufferSize;
137 firePropertyChange("cyclicBufferSize", oldCyclicBufferSize, newCyclicBufferSize);
138 }
139
140 public final int getCyclicBufferSize() {
141 return cyclicBufferSize;
142 }
143
144 public final void setToolTipDisplayMillis(int newToolTipDisplayMillis) {
145 int oldToolTipDisplayMillis = toolTipDisplayMillis;
146 toolTipDisplayMillis = newToolTipDisplayMillis;
147 firePropertyChange("toolTipDisplayMillis", oldToolTipDisplayMillis, newToolTipDisplayMillis);
148 }
149
150 public final int getToolTipDisplayMillis() {
151 return toolTipDisplayMillis;
152 }
153
154 public final void setIdentifierExpression(String newIdentifierExpression) {
155 String oldIdentifierExpression=identifierExpression;
156 this.identifierExpression = newIdentifierExpression;
157 firePropertyChange("identifierExpression", oldIdentifierExpression, newIdentifierExpression);
158 }
159
160 /***
161 * @param newShowNoReceiverWarning The showNoReceiverWarning to set.
162 */
163 public final void setShowNoReceiverWarning(boolean newShowNoReceiverWarning) {
164 boolean oldShowNoReceiverWarning=showNoReceiverWarning;
165 this.showNoReceiverWarning = newShowNoReceiverWarning;
166 firePropertyChange("showNoReceiverWarning", oldShowNoReceiverWarning, newShowNoReceiverWarning);
167 }
168
169
170 /***
171 * Takes another model and copies all the values into this model
172 * @param model
173 */
174 public void apply(ApplicationPreferenceModel model)
175 {
176 setIdentifierExpression(model.getIdentifierExpression());
177 setShowNoReceiverWarning(model.isShowNoReceiverWarning());
178 setResponsiveness(model.getResponsiveness());
179 setTabPlacement(model.getTabPlacement());
180 setStatusBar(model.isStatusBar());
181 setToolbar(model.isToolbar());
182 setReceivers(model.isReceivers());
183 setLookAndFeelClassName(model.getLookAndFeelClassName());
184 setConfirmExit(model.isConfirmExit());
185 setShowSplash(model.isShowSplash());
186 setToolTipDisplayMillis(model.getToolTipDisplayMillis());
187 setCyclicBufferSize(model.getCyclicBufferSize());
188 setConfigurationURL(model.getConfigurationURL());
189 setLastUsedVersion(model.getLastUsedVersion());
190 setOkToRemoveSecurityManager(model.isOkToRemoveSecurityManager());
191 }
192
193 /***
194 * @return Returns the responsiveness.
195 */
196 public final int getResponsiveness()
197 {
198 return responsiveness;
199 }
200 /***
201 * @param newValue The responsiveness to set.
202 */
203 public final void setResponsiveness(int newValue)
204 {
205 int oldvalue = responsiveness;
206
207 if (newValue >= 1000) {
208 responsiveness = (newValue - 750) / 1000;
209 } else {
210 responsiveness = newValue;
211 }
212 firePropertyChange("responsiveness", oldvalue, responsiveness);
213 }
214
215 /***
216 * @param i
217 */
218 public void setTabPlacement(int i) {
219 int oldValue = this.tabPlacement;
220 this.tabPlacement = i;
221 firePropertyChange("tabPlacement",oldValue,this.tabPlacement);
222 }
223 /***
224 * @return Returns the tabPlacement.
225 */
226 public final int getTabPlacement() {
227 return tabPlacement;
228 }
229
230 /***
231 * @return Returns the statusBar.
232 */
233 public final boolean isStatusBar() {
234 return statusBar;
235 }
236
237 /***
238 * @param statusBar The statusBar to set.
239 */
240 public final void setStatusBar(boolean statusBar) {
241 boolean oldValue = this.statusBar;
242 this.statusBar = statusBar;
243 firePropertyChange("statusBar", oldValue, this.statusBar);
244 }
245
246 /***
247 * @return Returns the receivers.
248 */
249 public final boolean isReceivers()
250 {
251 return receivers;
252 }
253 /***
254 * @param receivers The receivers to set.
255 */
256 public final void setReceivers(boolean receivers)
257 {
258 boolean oldValue = this.receivers;
259 this.receivers = receivers;
260 firePropertyChange("receivers", oldValue, this.receivers);
261 }
262 /***
263 * @return Returns the toolbar.
264 */
265 public final boolean isToolbar()
266 {
267 return toolbar;
268 }
269 /***
270 * @param toolbar The toolbar to set.
271 */
272 public final void setToolbar(boolean toolbar)
273 {
274 boolean oldValue = this.toolbar;
275 this.toolbar = toolbar;
276 firePropertyChange("toolbar", oldValue, this.toolbar);
277 }
278 /***
279 * @return Returns the lookAndFeelClassName.
280 */
281 public final String getLookAndFeelClassName() {
282 return lookAndFeelClassName;
283 }
284
285 /***
286 * @param lookAndFeelClassName The lookAndFeelClassName to set.
287 */
288 public final void setLookAndFeelClassName(String lookAndFeelClassName) {
289 String oldValue = this.lookAndFeelClassName;
290 this.lookAndFeelClassName = lookAndFeelClassName;
291 firePropertyChange("lookAndFeelClassName", oldValue, this.lookAndFeelClassName);
292 }
293
294 /***
295 * @return Returns the confirmExit.
296 */
297 public final boolean isConfirmExit() {
298 return confirmExit;
299 }
300
301 /***
302 * @param confirmExit The confirmExit to set.
303 */
304 public final void setConfirmExit(boolean confirmExit) {
305 boolean oldValue = this.confirmExit;
306 this.confirmExit = confirmExit;
307 firePropertyChange("confirmExit", oldValue, this.confirmExit);
308 }
309
310 /***
311 * @return Returns the showSplash.
312 */
313 public final boolean isShowSplash() {
314 return showSplash;
315 }
316 /***
317 * @param showSplash The showSplash to set.
318 */
319 public final void setShowSplash(boolean showSplash) {
320 boolean oldValue = this.showSplash;
321 this.showSplash = showSplash;
322 firePropertyChange("showSplash", oldValue,this.showSplash);
323 }
324 /***
325 * @return Returns the configurationURL.
326 */
327 public final String getConfigurationURL()
328 {
329 return this.configurationURL;
330 }
331 /***
332 * @param configurationURL The configurationURL to set.
333 */
334 public final void setConfigurationURL(String configurationURL)
335 {
336 Object oldValue = this.configurationURL;
337 this.configurationURL = configurationURL;
338 firePropertyChange("configurationURL", oldValue, this.configurationURL);
339 }
340 /***
341 * @return Returns the lastUsedVersion.
342 */
343 public final String getLastUsedVersion()
344 {
345 return this.lastUsedVersion;
346 }
347 /***
348 * @param lastUsedVersion The lastUsedVersion to set.
349 */
350 public final void setLastUsedVersion(String lastUsedVersion)
351 {
352 String oldValue = this.lastUsedVersion;
353 this.lastUsedVersion = lastUsedVersion;
354 firePropertyChange("lastUsedVersion", oldValue, this.lastUsedVersion);
355 }
356
357 /***
358 * @return ok to remove security manager flag
359 */
360 public final boolean isOkToRemoveSecurityManager() {
361 return this.okToRemoveSecurityManager;
362 }
363 /***
364 * @param okToRemoveSecurityManager The okToRemoveSecurityManager to set.
365 */
366 public final void setOkToRemoveSecurityManager(boolean okToRemoveSecurityManager) {
367 boolean oldValue = this.okToRemoveSecurityManager;
368 this.okToRemoveSecurityManager = okToRemoveSecurityManager;
369 firePropertyChange("okToRemoveSecurityManager", oldValue, this.okToRemoveSecurityManager);
370 }
371 }