KickJava   Java API By Example, From Geeks To Geeks.

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


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