KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * ExecuteCommandDialog.java
3  *
4  * Copyright (C) 1998-2002 Peter Graves
5  * $Id: ExecuteCommandDialog.java,v 1.1.1.1 2002/09/24 16:08:26 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.List JavaDoc;
25
26 public final class ExecuteCommandDialog extends InputDialog
27 {
28     private ExecuteCommandDialog(Editor editor, String JavaDoc title, String JavaDoc historyKey)
29     {
30         super(editor, "Command:", title, null);
31         History history = new History(historyKey);
32         setHistory(history);
33         setDefaultValue(history.getPrevious());
34     }
35
36     protected final List JavaDoc getCompletions(String JavaDoc prefix)
37     {
38         return CommandTable.getCompletionsForPrefix(prefix);
39     }
40
41     public static void whereIs()
42     {
43         final Editor editor = Editor.currentEditor();
44         ExecuteCommandDialog d = new ExecuteCommandDialog(editor, "Where is...", "whereIs.input");
45         editor.centerDialog(d);
46         d.show();
47         editor.repaintNow();
48         String JavaDoc input = d.getInput();
49         if (input == null)
50             return;
51         input = input.trim();
52         if (input.length() == 0)
53             return;
54         whereIs(input);
55     }
56
57     public static void whereIs(String JavaDoc s)
58     {
59         final Editor editor = Editor.currentEditor();
60         final Buffer buffer = editor.getBuffer();
61         editor.setWaitCursor();
62         // If it's a known command, use its canonical name.
63
Command command = CommandTable.getCommand(s);
64         final String JavaDoc commandName = command != null ? command.getName() : s;
65         List JavaDoc list = KeyMap.getGlobalKeyMap().listKeys(commandName);
66         list.addAll(buffer.getKeyMapForMode().listKeys(commandName));
67         FastStringBuffer sb = new FastStringBuffer(commandName);
68         if (list.size() == 0) {
69             sb.append(" is not mapped");
70         } else if (list.size() == 1) {
71             sb.append(" is mapped to ");
72             sb.append((String JavaDoc)list.get(0));
73         } else {
74             sb.append(" is mapped to:");
75             sb.append(System.getProperty("line.separator"));
76             for (int i = 0; i < list.size(); i++) {
77                 sb.append(System.getProperty("line.separator"));
78                 sb.append(" ");
79                 sb.append((String JavaDoc) list.get(i));
80             }
81         }
82         editor.setDefaultCursor();
83         MessageDialog.showMessageDialog(editor, sb.toString(), "Where is...");
84     }
85 }
86
Popular Tags