001: /*
002: * Property.java
003: *
004: * Copyright (C) 2000-2004 Peter Graves
005: * $Id: Property.java,v 1.28 2004/09/03 19:31:43 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j;
023:
024: import java.util.ArrayList;
025: import java.util.Hashtable;
026: import java.util.Iterator;
027: import java.util.List;
028:
029: public final class Property implements Comparable, Constants {
030: private static final Hashtable ht = new Hashtable();
031:
032: // Integer properties.
033: public static final Property ADJUST_ASCENT = createProperty(
034: "adjustAscent", 0);
035: public static final Property ADJUST_DESCENT = createProperty(
036: "adjustDescent", 0);
037: public static final Property ADJUST_LEADING = createProperty(
038: "adjustLeading", 0);
039: public static final Property CHANGE_MARK_WIDTH = createProperty(
040: "changeMarkWidth", 4);
041: public static final Property CHECK_IDLE_BACKGROUND = createProperty(
042: "checkIdleBackground", 10);
043: public static final Property CHECK_IDLE_FOREGROUND = createProperty(
044: "checkIdleForeground", 60);
045: public static final Property CHECK_INTERVAL = createProperty(
046: "checkInterval", 60);
047: public static final Property DIALOG_FONT_SIZE = createProperty(
048: "dialogFontSize", 11);
049: public static final Property FONT_SIZE = createProperty("fontSize",
050: 12);
051: public static final Property GUTTER_FONT_SIZE = createProperty(
052: "gutterFontSize", 0);
053: public static final Property INDENT_SIZE = createProperty(
054: "indentSize", 4);
055: public static final Property JLIST_FIXED_CELL_HEIGHT = createProperty(
056: "JList.fixedCellHeight", 0);
057: public static final Property LIST_THREADS = createProperty(
058: "listThreads", 0);
059: public static final Property LOG_MAX_BACKUP_INDEX = createProperty(
060: "Log.maxBackupIndex", 0);
061: public static final Property LOG_MAX_FILE_SIZE = createProperty(
062: "Log.maxFileSize", 100000);
063: public static final Property NNTP_READ_TIMEOUT = createProperty(
064: "nntpReadTimeout", 0);
065: public static final Property PRINTER_FONT_SIZE = createProperty(
066: "printerFontSize", 10);
067: public static final Property REORDER_BUFFERS = createProperty(
068: "reorderBuffers", 1);
069: public static final Property SHELL_OUTPUT_LIMIT = createProperty(
070: "shellOutputLimit", 1000);
071: public static final Property SSH_TIMEOUT = createProperty(
072: "sshTimeout", 250);
073: public static final Property STATUS_BAR_DISPLAY_CONTEXT = createProperty(
074: "StatusBar.displayContext", 1);
075: public static final Property TAB_WIDTH = createProperty("tabWidth",
076: 8);
077: public static final Property TEXT_FIELD_FONT_SIZE = createProperty(
078: "textFieldFontSize", 0);
079: public static final Property VERTICAL_RULE = createProperty(
080: "verticalRule", 0);
081: public static final Property VERTICAL_SCROLL_INCREMENT = createProperty(
082: "verticalScrollIncrement", 5);
083: public static final Property WRAP_COL = createProperty("wrapCol",
084: 80);
085:
086: // Boolean properties.
087: public static final Property ANTIALIAS = createProperty(
088: "antialias", false);
089: public static final Property ATTRIBUTES_REQUIRE_QUOTES = createProperty(
090: "attributesRequireQuotes", true);
091: public static final Property AUTOSAVE_NAMED_SESSIONS = createProperty(
092: "autosaveNamedSessions", false);
093: public static final Property AUTO_INDENT = createProperty(
094: "autoIndent", true);
095: public static final Property AUTO_NEWLINE = createProperty(
096: "autoNewline", false);
097: public static final Property AUTO_PASTE_LINES = createProperty(
098: "autoPasteLines", true);
099: public static final Property AUTO_RELOAD_KEY_MAPS = createProperty(
100: "autoReloadKeyMaps", false);
101: public static final Property AUTO_SELECT_LINE = createProperty(
102: "autoSelectLine", true);
103: public static final Property BEAUTIFY_HEADERS = createProperty(
104: "beautifyHeaders", true);
105: public static final Property BLINK_CARET = createProperty(
106: "blinkCaret", true);
107: public static final Property CHECK_ENABLED = createProperty(
108: "checkEnabled", false);
109: public static final Property CONFIRM_SEND = createProperty(
110: "confirmSend", true);
111: public static final Property DEBUG = createProperty("debug", false);
112: public static final Property DIR_SORT_DIRECTORIES_FIRST = createProperty(
113: "dirSortDirectoriesFirst", true);
114: public static final Property DIR_USE_NATIVE_FORMAT = createProperty(
115: "dirUseNativeFormat", false);
116: public static final Property EMULATE_BOLD = createProperty(
117: "emulateBold", false);
118: public static final Property ENABLE_CACHE = createProperty(
119: "enableCache", false);
120: public static final Property ENABLE_DRAG_TEXT = createProperty(
121: "enableDragText", true);
122: public static final Property ENABLE_EXPERIMENTAL_FEATURES = createProperty(
123: "enableExperimentalFeatures", false);
124: public static final Property ENABLE_ITALICS = createProperty(
125: "enableItalics", true);
126: public static final Property ENABLE_KEY_PRESSED_HOOK = createProperty(
127: "enableKeyPressedHook", false);
128: public static final Property ENABLE_MAIL = createProperty(
129: "enableMail", false);
130: public static final Property ENABLE_TOOL_TIPS = createProperty(
131: "enableToolTips", false);
132: public static final Property ENABLE_TREE = createProperty(
133: "enableTree", true);
134: public static final Property ENABLE_WEB = createProperty(
135: "enableWeb", false);
136: public static final Property EXTEND_END = createProperty(
137: "extendEnd", false);
138: public static final Property EXTEND_HOME = createProperty(
139: "extendHome", false);
140: public static final Property FILENAME_COMPLETIONS_IGNORE_CASE = createProperty(
141: "filenameCompletionsIgnoreCase", true);
142: public static final Property FIX_CASE = createProperty("fixCase",
143: false);
144: public static final Property FTP_USE_PASSIVE_MODE = createProperty(
145: "ftpUsePassiveMode", true);
146: public static final Property GROUP_BY_THREAD = createProperty(
147: "groupByThread", false);
148: public static final Property HIGHLIGHT_BRACKETS = createProperty(
149: "highlightBrackets", false);
150: public static final Property HIGHLIGHT_MATCHING_BRACKET = createProperty(
151: "highlightMatchingBracket", false);
152: public static final Property HTTP_ENABLE_COOKIES = createProperty(
153: "httpEnableCookies", false);
154: public static final Property IMAP_USE_LOCAL_CACHE = createProperty(
155: "imapUseLocalCache", true);
156: public static final Property INDENT_AFTER_BRACE = createProperty(
157: "indentAfterBrace", true);
158: public static final Property INDENT_AFTER_OPENING_BRACE = createProperty(
159: "indentAfterOpeningBrace", true);
160: public static final Property INDENT_BEFORE_BRACE = createProperty(
161: "indentBeforeBrace", false);
162: public static final Property INDENT_LINE_FIX_WHITESPACE = createProperty(
163: "indentLineFixWhitespace", false);
164: public static final Property LINEUP_ARGLIST = createProperty(
165: "lineupArglist", true);
166: public static final Property LOG_ENABLED = createProperty(
167: "Log.enabled", true);
168: public static final Property OFFLINE = createProperty("offline",
169: false);
170: public static final Property P4_AUTO_EDIT = createProperty(
171: "p4AutoEdit", false);
172: public static final Property PARENS_REQUIRE_SPACES = createProperty(
173: "parensRequireSpaces", false);
174: public static final Property POP_EXPUNGE_DELETED_MESSAGES_ON_SERVER = createProperty(
175: "popExpungeDeletedMessagesOnServer", false);
176: public static final Property POP_KEEP_MESSAGES_ON_SERVER = createProperty(
177: "popKeepMessagesOnServer", true);
178: public static final Property REMOVE_TRAILING_WHITESPACE = createProperty(
179: "removeTrailingWhitespace", false);
180: public static final Property RESTRICT_CARET = createProperty(
181: "restrictCaret", true);
182: public static final Property SAVE_IN_PLACE = createProperty(
183: "saveInPlace", false);
184: public static final Property SCROLL_CARET = createProperty(
185: "scrollCaret", true);
186: public static final Property SELECT_COMPLETION = createProperty(
187: "selectCompletion", true);
188: public static final Property SHOW_CHANGE_MARKS = createProperty(
189: "showChangeMarks", true);
190: public static final Property SHOW_COMPLETION_LIST = createProperty(
191: "showCompletionList", true);
192: public static final Property SHOW_LINE_NUMBERS = createProperty(
193: "showLineNumbers", false);
194: public static final Property SHOW_MESSAGE_NUMBERS = createProperty(
195: "showMessageNumbers", false);
196: public static final Property SORT_BUFFER_LIST = createProperty(
197: "sortBufferList", false);
198: public static final Property SSH_ECHO = createProperty("sshEcho",
199: false);
200: public static final Property STATUS_BAR_DISPLAY_LINE_COUNT = createProperty(
201: "StatusBar.displayLineCount", false);
202: public static final Property STATUS_BAR_DISPLAY_LINE_SEPARATOR = createProperty(
203: "StatusBar.displayLineSeparator", false);
204: public static final Property TAB_ALWAYS_INDENT = createProperty(
205: "tabAlwaysIndent", true);
206: public static final Property TOOL_BAR_IS_ROLLOVER = createProperty(
207: "ToolBar.isRollover", true);
208: public static final Property TOOL_BAR_SHOW_ICONS = createProperty(
209: "ToolBar.showIcons", true);
210: public static final Property TOOL_BAR_SHOW_TEXT = createProperty(
211: "ToolBar.showText", true);
212: public static final Property UNDELETE_ADVANCE_DOT = createProperty(
213: "undeleteAdvanceDot", true);
214: public static final Property UNDERLINE_BOLD = createProperty(
215: "underlineBold", false);
216: public static final Property UPPER_CASE_ATTRIBUTE_NAMES = createProperty(
217: "upperCaseAttributeNames", false);
218: public static final Property UPPER_CASE_TAG_NAMES = createProperty(
219: "upperCaseTagNames", true);
220: public static final Property USE_INCREMENTAL_FIND = createProperty(
221: "useIncrementalFind", false);
222: public static final Property USE_MENU_MNEMONICS = createProperty(
223: "useMenuMnemonics", true);
224: public static final Property USE_TABS = createProperty("useTabs",
225: false);
226: public static final Property WRAP = createProperty("wrap", false);
227:
228: // String properties with default values.
229: public static final Property ATTRIBUTION = createProperty(
230: "attribution", "On %d, %n wrote:");
231: public static final Property CLHS_ROOT = createProperty("clhsRoot",
232: "/usr/share/doc/hyperspec");
233: public static final Property DEFAULT_ENCODING = createProperty(
234: "defaultEncoding", "ISO-8859-1");
235: public static final Property DIALOG_FONT_NAME = createProperty(
236: "dialogFontName", "Dialog");
237: public static final Property FONT_NAME = createProperty("fontName",
238: "Monospaced");
239: public static final Property PRINTER_FONT_NAME = createProperty(
240: "printerFontName", "Courier");
241: public static final Property SHELL_PROMPT_PATTERN = createProperty(
242: "shellPromptPattern", DEFAULT_SHELL_PROMPT_PATTERN);
243: public static final Property SSH_PROMPT_PATTERN = createProperty(
244: "sshPromptPattern", DEFAULT_SHELL_PROMPT_PATTERN);
245: public static final Property TELNET_PROMPT_PATTERN = createProperty(
246: "telnetPromptPattern", DEFAULT_SHELL_PROMPT_PATTERN);
247: public static final Property TEXT_FIELD_FONT_NAME = createProperty(
248: "textFieldFontName", "Monospaced");
249:
250: // String properties with no default values.
251: public static final Property BACKUP_DIRECTORY = createProperty("backupDirectory");
252: public static final Property BROWSER = createProperty("browser");
253: public static final Property BROWSER_OPTS = createProperty("browserOpts");
254: public static final Property DOC_PATH = createProperty("docPath");
255: public static final Property EOM = createProperty("eom");
256: public static final Property EXPLICIT_TAG = createProperty("explicitTag");
257: public static final Property EXTENSION = createProperty("extension");
258: public static final Property FCC = createProperty("fcc");
259: public static final Property FILES = createProperty("files");
260: public static final Property FTP_ANONYMOUS_PASSWORD = createProperty("ftpAnonymousPassword");
261: public static final Property GUTTER_FONT_NAME = createProperty("gutterFontName");
262: public static final Property HTML_MODE_TAGS = createProperty("HtmlMode.tags");
263: public static final Property HTTP_USER_AGENT = createProperty("httpUserAgent");
264: public static final Property INBOX = createProperty("inbox");
265: public static final Property INCLUDE_PATH = createProperty("includePath");
266: public static final Property JAVA_MODE_INSERT_COMMENT_TEXT = createProperty("JavaMode.insertCommentText");
267: public static final Property JDB = createProperty("jdb");
268: public static final Property JDK_DOC_PATH = createProperty("jdkDocPath");
269: public static final Property JDK_SOURCE_PATH = createProperty("jdkSourcePath");
270: public static final Property GLOBAL_KEY_MAP = createProperty("globalKeyMap");
271: public static final Property LOOK_AND_FEEL = createProperty("lookAndFeel");
272: public static final Property LS_EXTRA_OPTIONS = createProperty("lsExtraOptions");
273: public static final Property NEWS = createProperty("news");
274: public static final Property PATCH_MODE = createProperty("patchMode");
275: public static final Property SHELL_FILE_NAME = createProperty("shellFileName");
276: public static final Property SIGNATURE = createProperty("signature");
277: public static final Property SMTP = createProperty("smtp");
278: public static final Property SOURCE_PATH = createProperty("sourcePath");
279: public static final Property SSH = createProperty("ssh");
280: public static final Property STAMP_FORMAT = createProperty("stampFormat");
281: public static final Property TAG_PATH = createProperty("tagPath");
282: public static final Property TELNET = createProperty("telnet");
283: public static final Property THEME = createProperty("theme");
284: public static final Property THEME_PATH = createProperty("themePath");
285: public static final Property TUNNEL = createProperty("tunnel");
286: public static final Property USER_FULL_NAME = createProperty("userFullName");
287: public static final Property USER_MAIL_ADDRESS = createProperty("userMailAddress");
288: public static final Property WINDOW_MANAGER = createProperty("windowManager");
289:
290: // Color properties (no default value).
291: public static final Property COLOR_BACKGROUND = createProperty("color.background");
292: public static final Property COLOR_CARET = createProperty("color.caret");
293: public static final Property COLOR_CHANGE = createProperty("color.change");
294: public static final Property COLOR_SAVED_CHANGE = createProperty("color.savedChange");
295: public static final Property COLOR_CURRENT_LINE_BACKGROUND = createProperty("color.currentLineBackground");
296: public static final Property COLOR_GUTTER_BORDER = createProperty("color.gutterBorder");
297: public static final Property COLOR_LINE_NUMBER = createProperty("color.lineNumber");
298: public static final Property COLOR_MATCHING_BRACKET_BACKGROUND = createProperty("color.matchingBracketBackground");
299: public static final Property COLOR_TEXT = createProperty("color.text");
300: public static final Property COLOR_SELECTION_BACKGROUND = createProperty("color.selectionBackground");
301: public static final Property COLOR_VERTICAL_RULE = createProperty("color.verticalRule");
302:
303: private final String displayName;
304: private final String key;
305: private Class type;
306: private Object defaultValue;
307:
308: private Property(String key) {
309: displayName = key;
310: this .key = key.toLowerCase().intern();
311: }
312:
313: private Property(String key, Object defaultValue) {
314: displayName = key;
315: this .key = key.toLowerCase().intern();
316: this .defaultValue = defaultValue;
317: }
318:
319: private Property(String key, boolean defaultValue) {
320: displayName = key;
321: this .key = key.toLowerCase().intern();
322: this .type = Boolean.TYPE;
323: this .defaultValue = defaultValue ? Boolean.TRUE : Boolean.FALSE;
324: }
325:
326: private Property(String key, int defaultValue) {
327: displayName = key;
328: this .key = key.toLowerCase().intern();
329: this .type = Integer.TYPE;
330: this .defaultValue = new Integer(defaultValue);
331: }
332:
333: private static Property createProperty(String key) {
334: Property property = new Property(key);
335: put(key, property);
336: return property;
337: }
338:
339: private static Property createProperty(String key,
340: Object defaultValue) {
341: Property property = new Property(key, defaultValue);
342: put(key, property);
343: return property;
344: }
345:
346: private static Property createProperty(String key,
347: boolean defaultValue) {
348: Property property = new Property(key, defaultValue);
349: put(key, property);
350: return property;
351: }
352:
353: private static Property createProperty(String key, int defaultValue) {
354: Property property = new Property(key, defaultValue);
355: put(key, property);
356: return property;
357: }
358:
359: private static void put(String key, Property property) {
360: ht.put(key.toLowerCase(), property);
361: }
362:
363: public static Property findProperty(String key) {
364: return (Property) ht.get(key.toLowerCase());
365: }
366:
367: public String getDisplayName() {
368: return displayName;
369: }
370:
371: public String key() {
372: return key;
373: }
374:
375: public Object getDefaultValue() {
376: return defaultValue;
377: }
378:
379: public boolean isBooleanProperty() {
380: return type == Boolean.TYPE;
381: }
382:
383: public boolean isIntegerProperty() {
384: return type == Integer.TYPE;
385: }
386:
387: public boolean validate(String value) {
388: if (type == Boolean.TYPE) {
389: if (value.equals("true") || value.equals("1"))
390: return true;
391: if (value.equals("false") || value.equals("0"))
392: return true;
393: return false;
394: }
395: if (type == Integer.TYPE) {
396: try {
397: Integer.parseInt(value);
398: return true;
399: } catch (NumberFormatException e) {
400: return false;
401: }
402: }
403: return true;
404: }
405:
406: public boolean equals(Object obj) {
407: return this == obj;
408: }
409:
410: public int hashCode() {
411: return key.hashCode();
412: }
413:
414: public String getLispName() {
415: Debug.assertTrue(displayName != null);
416: FastStringBuffer sb = new FastStringBuffer();
417: for (int i = 0, length = displayName.length(); i < length; i++) {
418: char c = displayName.charAt(i);
419: if (Character.isUpperCase(c)) {
420: sb.append('-');
421: sb.append(c);
422: } else
423: sb.append(Character.toUpperCase(c));
424: }
425: return sb.toString();
426: }
427:
428: public int compareTo(Object o) {
429: Property p = (Property) o;
430: return displayName.compareToIgnoreCase(p.displayName);
431: }
432:
433: public static List apropos(String s) {
434: String lower = s.toLowerCase();
435: ArrayList list = new ArrayList();
436: for (Iterator it = ht.values().iterator(); it.hasNext();) {
437: String displayName = ((Property) it.next())
438: .getDisplayName();
439: if (displayName.toLowerCase().indexOf(lower) >= 0)
440: list.add(displayName);
441: }
442: return list;
443: }
444:
445: public static Iterator iterator() {
446: return ht.values().iterator();
447: }
448: }
|