001: /*
002: * CommandTable.java
003: *
004: * Copyright (C) 1998-2004 Peter Graves
005: * $Id: CommandTable.java,v 1.53 2004/09/19 18:38:58 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.HashMap;
026: import java.util.Iterator;
027: import java.util.List;
028:
029: public class CommandTable {
030: // The default load factor is 0.75, so an initial capacity of 600 will
031: // accommodate 450 entries without rehashing.
032: private static final int INITIAL_CAPACITY = 600;
033:
034: private static HashMap map;
035:
036: public static final Command getCommand(String name) {
037: if (name == null)
038: return null;
039: if (map == null)
040: init();
041: return (Command) map.get(name.toLowerCase());
042: }
043:
044: private static synchronized void init() {
045: if (map == null) {
046: map = new HashMap(INITIAL_CAPACITY);
047:
048: // Commands implemented in Editor.java.
049: addCommand("backspace");
050: addCommand("bob");
051: addCommand("bol");
052: addCommand("bottom");
053: addCommand("cancelBackgroundProcess");
054: addCommand("closeAll");
055: addCommand("closeOthers");
056: addCommand("closeParen");
057: addCommand("commentRegion");
058: addCommand("copyAppend");
059: addCommand("copyPath");
060: addCommand("copyRegion");
061: addCommand("cppFindMatch");
062: addCommand("cycleIndentSize");
063: addCommand("cyclePaste");
064: addCommand("cycleTabWidth");
065: addCommand("defaultMode");
066: addCommand("delete");
067: addCommand("deleteWordLeft");
068: addCommand("deleteWordRight");
069: addCommand("dirBrowseFile");
070: addCommand("dirCopyFile");
071: addCommand("dirDeleteFiles");
072: addCommand("dirDoShellCommand");
073: addCommand("dirGetFile");
074: addCommand("dirHome");
075: addCommand("dirHomeDir");
076: addCommand("dirMoveFile");
077: addCommand("dirRescan");
078: addCommand("dirTagFile");
079: addCommand("dirUpDir");
080: addCommand("doShellCommandOnRegion");
081: addCommand("down");
082: addCommand("dropBookmark");
083: addCommand("dropTemporaryMarker");
084: addCommand("electricCloseAngleBracket");
085: addCommand("electricCloseBrace");
086: addCommand("electricColon");
087: addCommand("electricOpenBrace");
088: addCommand("electricPound");
089: addCommand("electricSemi");
090: addCommand("electricStar");
091: addCommand("end");
092: addCommand("eob");
093: addCommand("eol");
094: addCommand("escape");
095: addCommand("executeCommand");
096: addCommand("findFirstOccurrence");
097: addCommand("findMatchingChar");
098: addCommand("findNext");
099: addCommand("findNextWord");
100: addCommand("findPrev");
101: addCommand("findPrevWord");
102: addCommand("fold");
103: addCommand("foldMethods");
104: addCommand("foldRegion");
105: addCommand("gotoBookmark");
106: addCommand("gotoTemporaryMarker");
107: addCommand("help");
108: addCommand("home");
109: addCommand("httpDeleteCookies");
110: addCommand("incrementalFind");
111: addCommand("indentLine");
112: addCommand("indentLineOrRegion");
113: addCommand("indentRegion");
114: addCommand("insertBraces");
115: addCommand("insertByte");
116: addCommand("insertChar");
117: addCommand("insertKeyText");
118: addCommand("insertParentheses");
119: addCommand("insertString");
120: addCommand("insertTab");
121: addCommand("jmips");
122: addCommand("killAppend");
123: addCommand("killBuffer");
124: addCommand("killFrame");
125: addCommand("killLine");
126: addCommand("killRegion");
127: addCommand("killWordLeft");
128: addCommand("killWordRight");
129: addCommand("left");
130: addCommand("mode");
131: addCommand("movePastCloseAndReindent");
132: addCommand("newBuffer");
133: addCommand("newFrame");
134: addCommand("newline");
135: addCommand("newlineAndIndent");
136: addCommand("nextBuffer");
137: addCommand("nextFrame");
138: addCommand("offset");
139: addCommand("openFile");
140: addCommand("openFileInOtherWindow");
141: addCommand("otherWindow");
142: addCommand("pageDown");
143: addCommand("pageDownOtherWindow");
144: addCommand("pageUp");
145: addCommand("pageUpOtherWindow");
146: addCommand("paste");
147: addCommand("pasteColumn");
148: addCommand("popPosition");
149: addCommand("prevBuffer");
150: addCommand("pushPosition");
151: addCommand("quit");
152: addCommand("redo");
153: addCommand("resetDisplay");
154: addCommand("revertBuffer");
155: addCommand("right");
156: addCommand("save");
157: addCommand("saveAll");
158: addCommand("saveAllExit");
159: addCommand("saveAs");
160: addCommand("saveCopy");
161: addCommand("selectAll");
162: addCommand("selectBob");
163: addCommand("selectDown");
164: addCommand("selectEnd");
165: addCommand("selectEob");
166: addCommand("selectHome");
167: addCommand("selectLeft");
168: addCommand("selectPageDown");
169: addCommand("selectPageUp");
170: addCommand("selectRight");
171: addCommand("selectSyntax");
172: addCommand("selectUp");
173: addCommand("selectWord");
174: addCommand("selectWordLeft");
175: addCommand("selectWordRight");
176: addCommand("setEncoding");
177: addCommand("sidebarListBuffers");
178: addCommand("sidebarListTags");
179: addCommand("slideIn");
180: addCommand("slideOut");
181: addCommand("splitWindow");
182: addCommand("stamp");
183: addCommand("tab");
184: addCommand("textMode");
185: addCommand("toCenter");
186: addCommand("toTop");
187: addCommand("toggleSidebar");
188: addCommand("top");
189: addCommand("uncommentRegion");
190: addCommand("undo");
191: addCommand("unfold");
192: addCommand("unfoldAll");
193: addCommand("unsplitWindow");
194: addCommand("unwrapParagraph");
195: addCommand("up");
196: addCommand("visibleTabs");
197: addCommand("whatChar");
198: addCommand("windowDown");
199: addCommand("windowUp");
200: addCommand("wordLeft");
201: addCommand("wordRight");
202: addCommand("wrapParagraph");
203: addCommand("wrapParagraphsInRegion");
204: addCommand("wrapRegion");
205:
206: // Commands implemented in other classes.
207: addCommand("about", "AboutDialog");
208: addCommand("alias", "AliasDialog");
209: addCommand("alignStrings", "AlignStrings");
210: addCommand("apropos", "Help");
211: addCommand("archiveOpenFile", "ArchiveMode");
212: addCommand("backwardSexp", "LispMode");
213: addCommand("backwardUpList", "LispMode");
214: addCommand("binaryMode", "BinaryMode");
215: addCommand("browseFileAtDot", "BrowseFile");
216: addCommand("centerTag", "TagCommands");
217: addCommand("changes", "ChangeMarks");
218: addCommand("checkPath", "CheckPath");
219: addCommand("chmod", "Directory");
220: addCommand("clearRegister", "Registers");
221: addCommand("compile", "CompilationCommands");
222: addCommand("compileAndLoadLispFile", "LispMode");
223: addCommand("compileLispFile", "LispMode");
224: addCommand("copyLink", "WebBuffer");
225: addCommand("copyXPath", "XmlMode");
226: addCommand("cvs", "CVS", "cvs");
227: addCommand("cvsAdd", "CVS", "add");
228: addCommand("cvsCommit", "CVS", "commit");
229: addCommand("cvsDiff", "CVS", "diff");
230: addCommand("cvsDiffDir", "CVS", "diffDir");
231: addCommand("cvsLog", "CVS", "log");
232: addCommand("decodeRegion", "RegionCommands");
233: addCommand("defaultKeyMaps", "KeyMap");
234: addCommand("describeKey", "DescribeKeyDialog");
235: addCommand("detabRegion", "RegionCommands");
236: addCommand("diff", "DiffMode");
237: addCommand("diffGotoFile", "DiffMode", "gotoFile");
238: addCommand("dir", "Directory");
239: addCommand("dirBack", "Directory");
240: addCommand("dirCycleSortBy", "Directory");
241: addCommand("dirDoShellCommand", "Directory");
242: addCommand("dirForward", "Directory");
243: addCommand("dirLimit", "Directory");
244: addCommand("dirOpenFile", "Directory");
245: addCommand("dirOpenFileAndKillDirectory", "Directory");
246: addCommand("dirUnlimit", "Directory");
247: addCommand("doShellCommandOnRegion", "RegionCommands");
248: addCommand("downList", "LispMode");
249: addCommand("editRegister", "Registers");
250: addCommand("entabRegion", "RegionCommands");
251: addCommand("evalDefunLisp", "LispMode");
252: addCommand("compileDefunLisp", "LispMode");
253: addCommand("evalRegionLisp", "LispMode");
254: addCommand("expand", "Expansion");
255: addCommand("find", "FindDialog");
256: addCommand("findInFiles", "FindInFiles");
257: addCommand("findOccurrenceAtDot", "ListOccurrences");
258: addCommand("findOccurrenceAtDotAndKillList",
259: "ListOccurrences");
260: addCommand("findTag", "TagCommands");
261: addCommand("findTagAtDot", "TagCommands");
262: addCommand("findTagAtDotOtherWindow", "TagCommands");
263: addCommand("finish", "CheckinBuffer");
264: addCommand("followContext", "FollowContextTask");
265: addCommand("forwardSexp", "LispMode");
266: addCommand("google", "WebMode");
267: addCommand("gotoFile", "GotoFile");
268: addCommand("help", "Help");
269: addCommand("htmlBold", "HtmlMode");
270: addCommand("htmlElectricEquals", "HtmlMode");
271: addCommand("htmlEndTag", "HtmlMode");
272: addCommand("htmlFindMatch", "HtmlMode");
273: addCommand("htmlInsertMatchingEndTag", "HtmlMode");
274: addCommand("htmlInsertTag", "HtmlMode");
275: addCommand("htmlStartTag", "HtmlMode");
276: addCommand("httpShowHeaders", "HttpLoadProcess");
277: addCommand("hyperspec", "LispMode");
278: addCommand("iList", "IList");
279: addCommand("imageCycleBackground", "ImageMode");
280: addCommand("imageFit", "ImageMode");
281: addCommand("imageRestore", "ImageMode");
282: addCommand("imageZoomIn", "ImageMode");
283: addCommand("imageZoomOut", "ImageMode");
284: addCommand("insertRegister", "Registers");
285: addCommand("jdkHelp", "JDKHelp");
286: addCommand("jlisp", "JLisp");
287: addCommand("jumpToColumn", "JumpCommands");
288: addCommand("jumpToLine", "JumpCommands");
289: addCommand("jumpToOffset", "JumpCommands");
290: addCommand("jumpToTag", "ListTagsMode");
291: addCommand("jumpToTagAndKillList", "ListTagsMode");
292: addCommand("killCompilation", "CompilationBuffer");
293: addCommand("lisp", "LispShell");
294: addCommand("listBindings", "Help");
295: addCommand("listFiles", "FindInFiles");
296: addCommand("lispFindMatchingChar", "LispMode");
297: addCommand("lispSelectSyntax", "LispMode");
298: addCommand("listIncludes", "CheckPath");
299: addCommand("listMatchingTags", "TagCommands");
300: addCommand("listMatchingTagsAtDot", "TagCommands");
301: addCommand("listOccurrences", "ListOccurrences");
302: addCommand("listOccurrencesOfPatternAtDot",
303: "ListOccurrences");
304: addCommand("listProperties", "PropertiesDialog");
305: addCommand("listRegisters", "Registers");
306: addCommand("listTags", "ListTagsDialog");
307: addCommand("listThreads", "Debug");
308: addCommand("loadLispFile", "LispMode");
309: addCommand("loadSession", "Session");
310: addCommand("lowerCaseRegion", "RegionCommands");
311: addCommand("makeTagFile", "TagCommands");
312: addCommand("man", "ManMode");
313: addCommand("manFollowLink", "ManMode");
314: addCommand("mouseFindOccurrence", "ListOccurrences");
315: addCommand("mouseFindTag", "TagCommands");
316: addCommand("mouseJumpToTag", "ListTagsMode");
317: addCommand("nextChange", "ChangeMarks");
318: addCommand("nextComment", "CheckinBuffer");
319: addCommand("nextError", "CompilationCommands");
320: addCommand("nextTag", "TagCommands");
321: addCommand("openFileInOtherFrame", "OpenFileDialog");
322: addCommand("p4", "P4");
323: addCommand("p4Add", "P4", "add");
324: addCommand("p4Change", "P4", "change");
325: addCommand("p4Diff", "P4", "diff");
326: addCommand("p4DiffDir", "P4", "diffDir");
327: addCommand("p4Edit", "P4", "edit");
328: addCommand("p4Log", "P4", "log");
329: addCommand("p4Revert", "P4", "revert");
330: addCommand("p4Submit", "P4", "submit");
331: addCommand("pastePrimarySelection", "SystemSelection");
332: addCommand("phpHelp", "PHPMode");
333: addCommand("playbackMacro", "Macro");
334: addCommand("previousChange", "ChangeMarks");
335: addCommand("previousComment", "CheckinBuffer");
336: addCommand("previousError", "CompilationCommands");
337: addCommand("previousTag", "TagCommands");
338: addCommand("print", "PrintCommands");
339: addCommand("printBuffer", "PrintCommands");
340: addCommand("printRegion", "PrintCommands");
341: addCommand("properties", "PropertiesDialog");
342: addCommand("recentFiles", "RecentFilesDialog");
343: addCommand("recompile", "CompilationCommands");
344: addCommand("recordMacro", "Macro");
345: addCommand("reloadKeyMaps", "KeyMap");
346: addCommand("renumberRegion", "RegionCommands");
347: addCommand("replace", "ReplaceDialog");
348: addCommand("replaceInFiles", "FindInFiles");
349: addCommand("resetLisp", "LispShellMode");
350: addCommand("saveSession", "Session");
351: addCommand("saveToRegister", "Registers");
352: addCommand("selectToMarker", "Marker");
353: addCommand("selectToTemporaryMarker", "Marker");
354: addCommand("shellCommand", "ShellCommand");
355: addCommand("shell", "Shell");
356: addCommand("shellBackspace", "CommandInterpreter");
357: addCommand("shellEnter", "CommandInterpreter");
358: addCommand("shellEscape", "CommandInterpreter");
359: addCommand("shellHome", "CommandInterpreter");
360: addCommand("shellInterrupt", "Shell");
361: addCommand("shellNextInput", "CommandInterpreter");
362: addCommand("shellNextPrompt", "CommandInterpreter");
363: addCommand("shellPreviousInput", "CommandInterpreter");
364: addCommand("shellPreviousPrompt", "CommandInterpreter");
365: addCommand("shellTab", "Shell");
366: addCommand("showMessage", "CompilationCommands");
367: addCommand("slime", "LispShell");
368: addCommand("sortLines", "Sort");
369: addCommand("source", "JDKHelp");
370: addCommand("ssh", "RemoteShell");
371: addCommand("tagDown", "ListTagsMode");
372: addCommand("tagUp", "ListTagsMode");
373: addCommand("telnet", "RemoteShell");
374: addCommand("thisError", "CompilationCommands");
375: addCommand("toggleWrap", "WrapText");
376: addCommand("upperCaseRegion", "RegionCommands");
377: addCommand("whereIs", "ExecuteCommandDialog");
378: addCommand("wrapComment", "WrapText");
379: addCommand("writeGlobalKeyMap", "SaveFileDialog");
380: addCommand("writeLocalKeyMap", "SaveFileDialog");
381: addCommand("xmlElectricEquals", "XmlMode");
382: addCommand("xmlElectricSlash", "XmlMode");
383: addCommand("xmlFindCurrentNode", "XmlMode");
384: addCommand("xmlFindMatch", "XmlMode");
385: addCommand("xmlInsertEmptyElementTag", "XmlMode");
386: addCommand("xmlInsertMatchingEndTag", "XmlMode");
387: addCommand("xmlInsertTag", "XmlMode");
388: addCommand("xmlParseBuffer", "XmlMode");
389: addCommand("xmlValidateBuffer", "XmlMode");
390:
391: // Mail commands.
392: addCommand("attachFile", "mail.MailCommands");
393: addCommand("bounce", "mail.MailCommands");
394: addCommand("ccGroup", "mail.MailCommands");
395: addCommand("compose", "mail.MailCommands");
396: addCommand("foldThread", "mail.MailCommands");
397: addCommand("foldThreads", "mail.MailCommands");
398: addCommand("inbox", "mail.MailCommands");
399: addCommand("mailboxCreateFolder", "mail.MailCommands");
400: addCommand("mailboxDelete", "mail.MailCommands");
401: addCommand("mailboxDeleteFolder", "mail.MailCommands");
402: addCommand("mailboxExpunge", "mail.MailCommands");
403: addCommand("mailboxFlag", "mail.MailCommands");
404: addCommand("mailboxGetNewMessages", "mail.MailCommands");
405: addCommand("mailboxLastMessage", "mail.MailCommands");
406: addCommand("mailboxLimit", "mail.MailCommands");
407: addCommand("mailboxMarkRead", "mail.MailCommands");
408: addCommand("mailboxMarkUnread", "mail.MailCommands");
409: addCommand("mailboxMoveToFolder", "mail.MailCommands");
410: addCommand("mailboxReadMessage", "mail.MailCommands");
411: addCommand("mailboxReadMessageOtherWindow",
412: "mail.MailCommands");
413: addCommand("mailboxSaveToFolder", "mail.MailCommands");
414: addCommand("mailboxStop", "mail.MailCommands");
415: addCommand("mailboxTag", "mail.MailCommands");
416: addCommand("mailboxTagPattern", "mail.MailCommands");
417: addCommand("mailboxToggleRaw", "mail.MailCommands");
418: addCommand("mailboxUndelete", "mail.MailCommands");
419: addCommand("mailboxUnlimit", "mail.MailCommands");
420: addCommand("mailboxUntagAll", "mail.MailCommands");
421: addCommand("messageDelete", "mail.MailCommands");
422: addCommand("messageFlag", "mail.MailCommands");
423: addCommand("messageForward", "mail.MailCommands");
424: addCommand("messageIndex", "mail.MailCommands");
425: addCommand("messageMoveToFolder", "mail.MailCommands");
426: addCommand("messageNext", "mail.MailCommands");
427: addCommand("messageNextInThread", "mail.MailCommands");
428: addCommand("messageParent", "mail.MailCommands");
429: addCommand("messagePrevious", "mail.MailCommands");
430: addCommand("messagePreviousInThread", "mail.MailCommands");
431: addCommand("messageReplyToGroup", "mail.MailCommands");
432: addCommand("messageReplyToSender", "mail.MailCommands");
433: addCommand("messageSaveAttachment", "mail.MailCommands");
434: addCommand("messageToggleHeaders", "mail.MailCommands");
435: addCommand("messageToggleRaw", "mail.MailCommands");
436: addCommand("messageToggleWrap", "mail.MailCommands");
437: addCommand("messageViewAttachment", "mail.MailCommands");
438: addCommand("openMailbox", "mail.MailCommands");
439: addCommand("send", "mail.MailCommands");
440: addCommand("sendMailBackTab", "mail.MailCommands");
441: addCommand("sendMailElectricColon", "mail.MailCommands");
442: addCommand("sendMailTab", "mail.MailCommands");
443: addCommand("toggleGroupByThread", "mail.MailCommands");
444:
445: // News commands.
446: addCommand("news", "mail.NewsCommands");
447: addCommand("openGroup", "mail.NewsCommands");
448: addCommand("openGroupAtDot", "mail.NewsCommands");
449: addCommand("readArticle", "mail.NewsCommands");
450: addCommand("readArticleOtherWindow", "mail.NewsCommands");
451:
452: // jdb commands.
453: addCommand("jdb", "jdb.JdbCommands");
454: addCommand("jdbContinue", "jdb.JdbCommands");
455: addCommand("jdbDeleteBreakpoint", "jdb.Jdb");
456: addCommand("jdbFinish", "jdb.JdbCommands");
457: addCommand("jdbLocals", "jdb.JdbCommands");
458: addCommand("jdbNext", "jdb.JdbCommands");
459: addCommand("jdbQuit", "jdb.JdbCommands");
460: addCommand("jdbRestart", "jdb.JdbCommands");
461: addCommand("jdbRunToCurrentLine", "jdb.Jdb");
462: addCommand("jdbSetBreakpoint", "jdb.Jdb");
463: addCommand("jdbStep", "jdb.JdbCommands");
464: addCommand("jdbSuspend", "jdb.JdbCommands");
465: addCommand("jdbToggleBreakpoint", "jdb.Jdb");
466:
467: // Web browser commands.
468: addCommand("webBack", "WebBuffer", "back");
469: addCommand("webForward", "WebBuffer", "forward");
470: addCommand("webReload", "WebBuffer", "refresh");
471: addCommand("followLink", "WebBuffer");
472: addCommand("mouseFollowLink", "WebBuffer");
473: addCommand("viewPage", "WebBuffer");
474: addCommand("viewSource", "WebBuffer");
475:
476: // Abbreviations.
477: addCommand("sr", "Registers", "saveToRegister");
478: addCommand("ir", "Registers", "insertRegister");
479: addCommand("lr", "Registers", "listRegisters");
480: addCommand("hs", "LispMode", "hyperspec");
481: addCommand("clhs", "LispMode", "hyperspec");
482: addCommand("abcl", "LispShell", "lisp");
483:
484: if (Editor.isDebugEnabled()
485: && map.size() > INITIAL_CAPACITY * 0.75) {
486: Log
487: .error("CommandTable.init need to increase initial capacity!");
488: Log.error("CommandTable.init size = " + map.size());
489: }
490: }
491: }
492:
493: // For commands that are implemented by a method of the same name in the
494: // org.armedbear.j.Editor class.
495: private static final void addCommand(String commandName) {
496: map.put(commandName.toLowerCase(), new Command(commandName));
497: }
498:
499: // For commands that are implemented by a method of the same name in the
500: // specified class.
501: private static final void addCommand(String commandName,
502: String className) {
503: map.put(commandName.toLowerCase(), new Command(commandName,
504: className, commandName));
505: }
506:
507: private static final void addCommand(String commandName,
508: String className, String methodName) {
509: map.put(commandName.toLowerCase(), new Command(commandName,
510: className, methodName));
511: }
512:
513: public static List getCompletionsForPrefix(String prefix) {
514: String lower = prefix.toLowerCase();
515: Iterator it = map.values().iterator();
516: ArrayList list = new ArrayList();
517: while (it.hasNext()) {
518: Command command = (Command) it.next();
519: if (command.getName().toLowerCase().startsWith(lower))
520: list.add(command.getName());
521: }
522: return list;
523: }
524:
525: public static List apropos(String s) {
526: String lower = s.toLowerCase();
527: Iterator it = map.values().iterator();
528: ArrayList list = new ArrayList();
529: while (it.hasNext()) {
530: String name = ((Command) it.next()).getName();
531: if (name.toLowerCase().indexOf(lower) >= 0)
532: list.add(name);
533: }
534: return list;
535: }
536: }
|