1 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 { 34 private final Editor editor; 35 private final HistoryTextField textField; 36 private final History compileHistory; 37 private String command; 38 39 public CompileDialog(Editor editor) 40 { 41 super(editor.getFrame(), "Compile", true); 42 this.editor = editor; 43 JPanel panel = new JPanel (); 44 panel.setLayout(new BoxLayout (panel, BoxLayout.Y_AXIS)); 45 panel.setBorder(new EmptyBorder (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 getCommand() 60 { 61 return command; 62 } 63 64 public void keyPressed(KeyEvent 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 e) {} 86 87 public void keyTyped(KeyEvent e) {} 88 89 public void dispose() 90 { 91 super.dispose(); 92 editor.restoreFocus(); 93 } 94 } 95 | Popular Tags |