01: /*
02: * CompileDialog.java
03: *
04: * Copyright (C) 1998-2003 Peter Graves
05: * $Id: CompileDialog.java,v 1.2 2003/07/24 15:11:39 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * 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.awt.BorderLayout;
25: import java.awt.event.KeyEvent;
26: import java.awt.event.KeyListener;
27: import javax.swing.BoxLayout;
28: import javax.swing.JDialog;
29: import javax.swing.JPanel;
30: import javax.swing.border.EmptyBorder;
31:
32: public final class CompileDialog extends JDialog implements KeyListener {
33: private final Editor editor;
34: private final HistoryTextField textField;
35: private final History compileHistory;
36: private String command;
37:
38: public CompileDialog(Editor editor) {
39: super (editor.getFrame(), "Compile", true);
40: this .editor = editor;
41: JPanel panel = new JPanel();
42: panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
43: panel.setBorder(new EmptyBorder(5, 5, 5, 5));
44: Label label = new Label("Compile command:");
45: panel.add(label);
46: textField = new HistoryTextField(20);
47: compileHistory = new History("compile.command");
48: textField.setHistory(compileHistory);
49: textField.recallLast();
50: panel.add(textField);
51: getContentPane().add(panel, BorderLayout.CENTER);
52: pack();
53: textField.requestFocus();
54: textField.addKeyListener(this );
55: }
56:
57: public final String getCommand() {
58: return command;
59: }
60:
61: public void keyPressed(KeyEvent e) {
62: final int keyCode = e.getKeyCode();
63: final int modifiers = e.getModifiers();
64: switch (keyCode) {
65: case KeyEvent.VK_ENTER: {
66: command = textField.getText();
67: compileHistory.append(command);
68: compileHistory.save();
69: dispose();
70: return;
71: }
72: case KeyEvent.VK_ESCAPE:
73: command = null;
74: dispose();
75: return;
76: default:
77: return;
78: }
79: }
80:
81: public void keyReleased(KeyEvent e) {
82: }
83:
84: public void keyTyped(KeyEvent e) {
85: }
86:
87: public void dispose() {
88: super.dispose();
89: editor.restoreFocus();
90: }
91: }
|