KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > Property


1 /*
2  * Property.java
3  *
4  * Copyright (C) 2000-2004 Peter Graves
5  * $Id: Property.java,v 1.28 2004/09/03 19:31:43 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Hashtable JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28
29 public final class Property implements Comparable JavaDoc, Constants
30 {
31     private static final Hashtable JavaDoc ht = new Hashtable JavaDoc();
32
33     // Integer properties.
34
public static final Property ADJUST_ASCENT =
35         createProperty("adjustAscent", 0);
36     public static final Property ADJUST_DESCENT =
37         createProperty("adjustDescent", 0);
38     public static final Property ADJUST_LEADING =
39         createProperty("adjustLeading", 0);
40     public static final Property CHANGE_MARK_WIDTH =
41         createProperty("changeMarkWidth", 4);
42     public static final Property CHECK_IDLE_BACKGROUND =
43         createProperty("checkIdleBackground", 10);
44     public static final Property CHECK_IDLE_FOREGROUND =
45         createProperty("checkIdleForeground", 60);
46     public static final Property CHECK_INTERVAL =
47         createProperty("checkInterval", 60);
48     public static final Property DIALOG_FONT_SIZE =
49         createProperty("dialogFontSize", 11);
50     public static final Property FONT_SIZE =
51         createProperty("fontSize", 12);
52     public static final Property GUTTER_FONT_SIZE =
53         createProperty("gutterFontSize", 0);
54     public static final Property INDENT_SIZE =
55         createProperty("indentSize", 4);
56     public static final Property JLIST_FIXED_CELL_HEIGHT =
57         createProperty("JList.fixedCellHeight", 0);
58     public static final Property LIST_THREADS =
59         createProperty("listThreads", 0);
60     public static final Property LOG_MAX_BACKUP_INDEX =
61         createProperty("Log.maxBackupIndex", 0);
62     public static final Property LOG_MAX_FILE_SIZE =
63         createProperty("Log.maxFileSize", 100000);
64     public static final Property NNTP_READ_TIMEOUT =
65         createProperty("nntpReadTimeout", 0);
66     public static final Property PRINTER_FONT_SIZE =
67         createProperty("printerFontSize", 10);
68     public static final Property REORDER_BUFFERS =
69         createProperty("reorderBuffers", 1);
70     public static final Property SHELL_OUTPUT_LIMIT =
71         createProperty("shellOutputLimit", 1000);
72     public static final Property SSH_TIMEOUT =
73         createProperty("sshTimeout", 250);
74     public static final Property STATUS_BAR_DISPLAY_CONTEXT =
75         createProperty("StatusBar.displayContext", 1);
76     public static final Property TAB_WIDTH =
77         createProperty("tabWidth", 8);
78     public static final Property TEXT_FIELD_FONT_SIZE =
79         createProperty("textFieldFontSize", 0);
80     public static final Property VERTICAL_RULE =
81         createProperty("verticalRule", 0);
82     public static final Property VERTICAL_SCROLL_INCREMENT =
83         createProperty("verticalScrollIncrement", 5);
84     public static final Property WRAP_COL =
85         createProperty("wrapCol", 80);
86
87     // Boolean properties.
88
public static final Property ANTIALIAS =
89         createProperty("antialias", false);
90     public static final Property ATTRIBUTES_REQUIRE_QUOTES =
91         createProperty("attributesRequireQuotes", true);
92     public static final Property AUTOSAVE_NAMED_SESSIONS =
93         createProperty("autosaveNamedSessions", false);
94     public static final Property AUTO_INDENT =
95         createProperty("autoIndent", true);
96     public static final Property AUTO_NEWLINE =
97         createProperty("autoNewline", false);
98     public static final Property AUTO_PASTE_LINES =
99         createProperty("autoPasteLines", true);
100     public static final Property AUTO_RELOAD_KEY_MAPS =
101         createProperty("autoReloadKeyMaps", false);
102     public static final Property AUTO_SELECT_LINE =
103         createProperty("autoSelectLine", true);
104     public static final Property BEAUTIFY_HEADERS =
105         createProperty("beautifyHeaders", true);
106     public static final Property BLINK_CARET =
107         createProperty("blinkCaret", true);
108     public static final Property CHECK_ENABLED =
109         createProperty("checkEnabled", false);
110     public static final Property CONFIRM_SEND =
111         createProperty("confirmSend", true);
112     public static final Property DEBUG =
113         createProperty("debug", false);
114     public static final Property DIR_SORT_DIRECTORIES_FIRST =
115         createProperty("dirSortDirectoriesFirst", true);
116     public static final Property DIR_USE_NATIVE_FORMAT =
117         createProperty("dirUseNativeFormat", false);
118     public static final Property EMULATE_BOLD =
119         createProperty("emulateBold", false);
120     public static final Property ENABLE_CACHE =
121         createProperty("enableCache", false);
122     public static final Property ENABLE_DRAG_TEXT =
123         createProperty("enableDragText", true);
124     public static final Property ENABLE_EXPERIMENTAL_FEATURES =
125         createProperty("enableExperimentalFeatures", false);
126     public static final Property ENABLE_ITALICS =
127         createProperty("enableItalics", true);
128     public static final Property ENABLE_KEY_PRESSED_HOOK =
129         createProperty("enableKeyPressedHook", false);
130     public static final Property ENABLE_MAIL =
131         createProperty("enableMail", false);
132     public static final Property ENABLE_TOOL_TIPS =
133         createProperty("enableToolTips", false);
134     public static final Property ENABLE_TREE =
135         createProperty("enableTree", true);
136     public static final Property ENABLE_WEB =
137         createProperty("enableWeb", false);
138     public static final Property EXTEND_END =
139         createProperty("extendEnd", false);
140     public static final Property EXTEND_HOME =
141         createProperty("extendHome", false);
142     public static final Property FILENAME_COMPLETIONS_IGNORE_CASE =
143         createProperty("filenameCompletionsIgnoreCase", true);
144     public static final Property FIX_CASE =
145         createProperty("fixCase", false);
146     public static final Property FTP_USE_PASSIVE_MODE =
147         createProperty("ftpUsePassiveMode", true);
148     public static final Property GROUP_BY_THREAD =
149         createProperty("groupByThread", false);
150     public static final Property HIGHLIGHT_BRACKETS =
151         createProperty("highlightBrackets", false);
152     public static final Property HIGHLIGHT_MATCHING_BRACKET =
153         createProperty("highlightMatchingBracket", false);
154     public static final Property HTTP_ENABLE_COOKIES =
155         createProperty("httpEnableCookies", false);
156     public static final Property IMAP_USE_LOCAL_CACHE =
157         createProperty("imapUseLocalCache", true);
158     public static final Property INDENT_AFTER_BRACE =
159         createProperty("indentAfterBrace", true);
160     public static final Property INDENT_AFTER_OPENING_BRACE =
161         createProperty("indentAfterOpeningBrace", true);
162     public static final Property INDENT_BEFORE_BRACE =
163         createProperty("indentBeforeBrace", false);
164     public static final Property INDENT_LINE_FIX_WHITESPACE =
165         createProperty("indentLineFixWhitespace", false);
166     public static final Property LINEUP_ARGLIST =
167         createProperty("lineupArglist", true);
168     public static final Property LOG_ENABLED =
169         createProperty("Log.enabled", true);
170     public static final Property OFFLINE =
171         createProperty("offline", false);
172     public static final Property P4_AUTO_EDIT =
173         createProperty("p4AutoEdit", false);
174     public static final Property PARENS_REQUIRE_SPACES =
175         createProperty("parensRequireSpaces", false);
176     public static final Property POP_EXPUNGE_DELETED_MESSAGES_ON_SERVER =
177         createProperty("popExpungeDeletedMessagesOnServer", false);
178     public static final Property POP_KEEP_MESSAGES_ON_SERVER =
179         createProperty("popKeepMessagesOnServer", true);
180     public static final Property REMOVE_TRAILING_WHITESPACE =
181         createProperty("removeTrailingWhitespace", false);
182     public static final Property RESTRICT_CARET =
183         createProperty("restrictCaret", true);
184     public static final Property SAVE_IN_PLACE =
185         createProperty("saveInPlace", false);
186     public static final Property SCROLL_CARET =
187         createProperty("scrollCaret", true);
188     public static final Property SELECT_COMPLETION =
189         createProperty("selectCompletion", true);
190     public static final Property SHOW_CHANGE_MARKS =
191         createProperty("showChangeMarks", true);
192     public static final Property SHOW_COMPLETION_LIST =
193         createProperty("showCompletionList", true);
194     public static final Property SHOW_LINE_NUMBERS =
195         createProperty("showLineNumbers", false);
196     public static final Property SHOW_MESSAGE_NUMBERS =
197         createProperty("showMessageNumbers", false);
198     public static final Property SORT_BUFFER_LIST =
199         createProperty("sortBufferList", false);
200     public static final Property SSH_ECHO =
201         createProperty("sshEcho", false);
202     public static final Property STATUS_BAR_DISPLAY_LINE_COUNT =
203         createProperty("StatusBar.displayLineCount", false);
204     public static final Property STATUS_BAR_DISPLAY_LINE_SEPARATOR =
205         createProperty("StatusBar.displayLineSeparator", false);
206     public static final Property TAB_ALWAYS_INDENT =
207         createProperty("tabAlwaysIndent", true);
208     public static final Property TOOL_BAR_IS_ROLLOVER =
209         createProperty("ToolBar.isRollover", true);
210     public static final Property TOOL_BAR_SHOW_ICONS =
211         createProperty("ToolBar.showIcons", true);
212     public static final Property TOOL_BAR_SHOW_TEXT =
213         createProperty("ToolBar.showText", true);
214     public static final Property UNDELETE_ADVANCE_DOT =
215         createProperty("undeleteAdvanceDot", true);
216     public static final Property UNDERLINE_BOLD =
217         createProperty("underlineBold", false);
218     public static final Property UPPER_CASE_ATTRIBUTE_NAMES =
219         createProperty("upperCaseAttributeNames", false);
220     public static final Property UPPER_CASE_TAG_NAMES =
221         createProperty("upperCaseTagNames", true);
222     public static final Property USE_INCREMENTAL_FIND =
223         createProperty("useIncrementalFind", false);
224     public static final Property USE_MENU_MNEMONICS =
225         createProperty("useMenuMnemonics", true);
226     public static final Property USE_TABS =
227         createProperty("useTabs", false);
228     public static final Property WRAP =
229         createProperty("wrap", false);
230
231     // String properties with default values.
232
public static final Property ATTRIBUTION =
233         createProperty("attribution", "On %d, %n wrote:");
234     public static final Property CLHS_ROOT =
235         createProperty("clhsRoot", "/usr/share/doc/hyperspec");
236     public static final Property DEFAULT_ENCODING =
237         createProperty("defaultEncoding", "ISO-8859-1");
238     public static final Property DIALOG_FONT_NAME =
239         createProperty("dialogFontName", "Dialog");
240     public static final Property FONT_NAME =
241         createProperty("fontName", "Monospaced");
242     public static final Property PRINTER_FONT_NAME =
243         createProperty("printerFontName", "Courier");
244     public static final Property SHELL_PROMPT_PATTERN =
245         createProperty("shellPromptPattern", DEFAULT_SHELL_PROMPT_PATTERN);
246     public static final Property SSH_PROMPT_PATTERN =
247         createProperty("sshPromptPattern", DEFAULT_SHELL_PROMPT_PATTERN);
248     public static final Property TELNET_PROMPT_PATTERN =
249         createProperty("telnetPromptPattern", DEFAULT_SHELL_PROMPT_PATTERN);
250     public static final Property TEXT_FIELD_FONT_NAME =
251         createProperty("textFieldFontName", "Monospaced");
252
253     // String properties with no default values.
254
public static final Property BACKUP_DIRECTORY =
255         createProperty("backupDirectory");
256     public static final Property BROWSER =
257         createProperty("browser");
258     public static final Property BROWSER_OPTS =
259         createProperty("browserOpts");
260     public static final Property DOC_PATH =
261         createProperty("docPath");
262     public static final Property EOM =
263         createProperty("eom");
264     public static final Property EXPLICIT_TAG =
265         createProperty("explicitTag");
266     public static final Property EXTENSION =
267         createProperty("extension");
268     public static final Property FCC =
269         createProperty("fcc");
270     public static final Property FILES =
271         createProperty("files");
272     public static final Property FTP_ANONYMOUS_PASSWORD =
273         createProperty("ftpAnonymousPassword");
274     public static final Property GUTTER_FONT_NAME =
275         createProperty("gutterFontName");
276     public static final Property HTML_MODE_TAGS =
277         createProperty("HtmlMode.tags");
278     public static final Property HTTP_USER_AGENT =
279         createProperty("httpUserAgent");
280     public static final Property INBOX =
281         createProperty("inbox");
282     public static final Property INCLUDE_PATH =
283         createProperty("includePath");
284     public static final Property JAVA_MODE_INSERT_COMMENT_TEXT =
285         createProperty("JavaMode.insertCommentText");
286     public static final Property JDB =
287         createProperty("jdb");
288     public static final Property JDK_DOC_PATH =
289         createProperty("jdkDocPath");
290     public static final Property JDK_SOURCE_PATH =
291         createProperty("jdkSourcePath");
292     public static final Property GLOBAL_KEY_MAP =
293         createProperty("globalKeyMap");
294     public static final Property LOOK_AND_FEEL =
295         createProperty("lookAndFeel");
296     public static final Property LS_EXTRA_OPTIONS =
297         createProperty("lsExtraOptions");
298     public static final Property NEWS =
299         createProperty("news");
300     public static final Property PATCH_MODE =
301         createProperty("patchMode");
302     public static final Property SHELL_FILE_NAME =
303         createProperty("shellFileName");
304     public static final Property SIGNATURE =
305         createProperty("signature");
306     public static final Property SMTP =
307         createProperty("smtp");
308     public static final Property SOURCE_PATH =
309         createProperty("sourcePath");
310     public static final Property SSH =
311         createProperty("ssh");
312     public static final Property STAMP_FORMAT =
313         createProperty("stampFormat");
314     public static final Property TAG_PATH =
315         createProperty("tagPath");
316     public static final Property TELNET =
317         createProperty("telnet");
318     public static final Property THEME =
319         createProperty("theme");
320     public static final Property THEME_PATH =
321         createProperty("themePath");
322     public static final Property TUNNEL =
323         createProperty("tunnel");
324     public static final Property USER_FULL_NAME =
325         createProperty("userFullName");
326     public static final Property USER_MAIL_ADDRESS =
327         createProperty("userMailAddress");
328     public static final Property WINDOW_MANAGER =
329         createProperty("windowManager");
330
331     // Color properties (no default value).
332
public static final Property COLOR_BACKGROUND =
333         createProperty("color.background");
334     public static final Property COLOR_CARET = createProperty("color.caret");
335     public static final Property COLOR_CHANGE = createProperty("color.change");
336     public static final Property COLOR_SAVED_CHANGE =
337         createProperty("color.savedChange");
338     public static final Property COLOR_CURRENT_LINE_BACKGROUND =
339         createProperty("color.currentLineBackground");
340     public static final Property COLOR_GUTTER_BORDER =
341         createProperty("color.gutterBorder");
342     public static final Property COLOR_LINE_NUMBER =
343         createProperty("color.lineNumber");
344     public static final Property COLOR_MATCHING_BRACKET_BACKGROUND =
345         createProperty("color.matchingBracketBackground");
346     public static final Property COLOR_TEXT = createProperty("color.text");
347     public static final Property COLOR_SELECTION_BACKGROUND =
348         createProperty("color.selectionBackground");
349     public static final Property COLOR_VERTICAL_RULE =
350         createProperty("color.verticalRule");
351
352     private final String JavaDoc displayName;
353     private final String JavaDoc key;
354     private Class JavaDoc type;
355     private Object JavaDoc defaultValue;
356
357     private Property(String JavaDoc key)
358     {
359         displayName = key;
360         this.key = key.toLowerCase().intern();
361     }
362
363     private Property(String JavaDoc key, Object JavaDoc defaultValue)
364     {
365         displayName = key;
366         this.key = key.toLowerCase().intern();
367         this.defaultValue = defaultValue;
368     }
369
370     private Property(String JavaDoc key, boolean defaultValue)
371     {
372         displayName = key;
373         this.key = key.toLowerCase().intern();
374         this.type = Boolean.TYPE;
375         this.defaultValue = defaultValue ? Boolean.TRUE : Boolean.FALSE;
376     }
377
378     private Property(String JavaDoc key, int defaultValue)
379     {
380         displayName = key;
381         this.key = key.toLowerCase().intern();
382         this.type = Integer.TYPE;
383         this.defaultValue = new Integer JavaDoc(defaultValue);
384     }
385
386     private static Property createProperty(String JavaDoc key)
387     {
388         Property property = new Property(key);
389         put(key, property);
390         return property;
391     }
392
393     private static Property createProperty(String JavaDoc key, Object JavaDoc defaultValue)
394     {
395         Property property = new Property(key, defaultValue);
396         put(key, property);
397         return property;
398     }
399
400     private static Property createProperty(String JavaDoc key, boolean defaultValue)
401     {
402         Property property = new Property(key, defaultValue);
403         put(key, property);
404         return property;
405     }
406
407     private static Property createProperty(String JavaDoc key, int defaultValue)
408     {
409         Property property = new Property(key, defaultValue);
410         put(key, property);
411         return property;
412     }
413
414     private static void put(String JavaDoc key, Property property)
415     {
416         ht.put(key.toLowerCase(), property);
417     }
418
419     public static Property findProperty(String JavaDoc key)
420     {
421         return (Property) ht.get(key.toLowerCase());
422     }
423
424     public String JavaDoc getDisplayName()
425     {
426         return displayName;
427     }
428
429     public String JavaDoc key()
430     {
431         return key;
432     }
433
434     public Object JavaDoc getDefaultValue()
435     {
436         return defaultValue;
437     }
438
439     public boolean isBooleanProperty()
440     {
441         return type == Boolean.TYPE;
442     }
443
444     public boolean isIntegerProperty()
445     {
446         return type == Integer.TYPE;
447     }
448
449     public boolean validate(String JavaDoc value)
450     {
451         if (type == Boolean.TYPE) {
452             if (value.equals("true") || value.equals("1"))
453                 return true;
454             if (value.equals("false") || value.equals("0"))
455                 return true;
456             return false;
457         }
458         if (type == Integer.TYPE) {
459             try {
460                 Integer.parseInt(value);
461                 return true;
462             }
463             catch (NumberFormatException JavaDoc e) {
464                 return false;
465             }
466         }
467         return true;
468     }
469
470     public boolean equals(Object JavaDoc obj)
471     {
472         return this == obj;
473     }
474
475     public int hashCode()
476     {
477         return key.hashCode();
478     }
479
480     public String JavaDoc getLispName()
481     {
482         Debug.assertTrue(displayName != null);
483         FastStringBuffer sb = new FastStringBuffer();
484         for (int i = 0, length = displayName.length(); i < length; i++) {
485             char c = displayName.charAt(i);
486             if (Character.isUpperCase(c)) {
487                 sb.append('-');
488                 sb.append(c);
489             } else
490                 sb.append(Character.toUpperCase(c));
491         }
492         return sb.toString();
493     }
494
495     public int compareTo(Object JavaDoc o)
496     {
497         Property p = (Property) o;
498         return displayName.compareToIgnoreCase(p.displayName);
499     }
500
501     public static List JavaDoc apropos(String JavaDoc s)
502     {
503         String JavaDoc lower = s.toLowerCase();
504         ArrayList JavaDoc list = new ArrayList JavaDoc();
505         for (Iterator JavaDoc it = ht.values().iterator(); it.hasNext();) {
506             String JavaDoc displayName = ((Property)it.next()).getDisplayName();
507             if (displayName.toLowerCase().indexOf(lower) >= 0)
508                 list.add(displayName);
509         }
510         return list;
511     }
512
513     public static Iterator JavaDoc iterator()
514     {
515         return ht.values().iterator();
516     }
517 }
518
Popular Tags