KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * ExecuteCommandTextFieldHandler.java
3  *
4  * Copyright (C) 2002-2003 Peter Graves
5  * $Id: ExecuteCommandTextFieldHandler.java,v 1.4 2003/07/03 01:24:58 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 ExecuteCommandTextFieldHandler extends DefaultTextFieldHandler
27 {
28     public ExecuteCommandTextFieldHandler(Editor editor, HistoryTextField textField)
29     {
30         super(editor, textField);
31     }
32
33     public void enter()
34     {
35         String JavaDoc input = textField.getText();
36         if (input == null)
37             return;
38         input = input.trim();
39         if (input.length() == 0)
40             return;
41         // Save history.
42
History history = textField.getHistory();
43         if (history != null) {
44             history.append(input);
45             history.save();
46         }
47         if (!input.equals("inbox")) {
48             // Aliases.
49
String JavaDoc value = editor.getAlias(input);
50             if (value != null)
51                 input = value;
52         }
53         editor.ensureActive();
54         editor.setFocusToDisplay();
55         editor.updateLocation();
56         editor.executeCommand(input, true);
57         editor.getDispatcher().eventHandled();
58     }
59
60     public boolean wantTab()
61     {
62         return true;
63     }
64
65     public final List JavaDoc getCompletions(String JavaDoc prefix)
66     {
67         return CommandTable.getCompletionsForPrefix(prefix);
68     }
69 }
70
Popular Tags