comparison src/samer/core_/util/swing/CommandField.java @ 0:bf79fb79ee13

Initial Mercurial check in.
author samer
date Tue, 17 Jan 2012 17:50:20 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bf79fb79ee13
1 /*
2 * CommandField.java
3 *
4 * Copyright (c) 2000, Samer Abdallah, King's College London.
5 * All rights reserved.
6 *
7 * This software is provided AS iS and WITHOUT ANY WARRANTY;
8 * without even the implied warranty of MERCHANTABILITY or
9 * FITNESS FOR A PARTICULAR PURPOSE.
10 */
11
12 package samer.core.util.swing;
13 import samer.core.*;
14 import java.awt.*;
15 import java.awt.event.*;
16 import java.io.*;
17 import javax.swing.*;
18
19 public class CommandField extends JTextField
20 {
21 public CommandField(int w)
22 {
23 super(w);
24
25 setBackground( X.color(Shell.datum("swing.input.console.background"), Color.white));
26 setForeground( X.color(Shell.datum("swing.input.console.foreground"), Color.black));
27 Font font=X.font(Shell.datum("swing.input.console.font"),null);
28 if (font!=null) setFont(font);
29 addActionListener(h);
30 addKeyListener(h);
31 }
32
33 static Handler h = new Handler();
34 static class Handler extends KeyAdapter implements ActionListener, java.io.Serializable
35 {
36 String last;
37
38 public void actionPerformed(ActionEvent e) {
39 Object o = e.getSource();
40 JTextField tc = ((JTextField)o);
41 last=tc.getText();
42 Shell.print("> "+last);
43 Shell.interpret(new StringReader(last));
44 tc.setText("");
45 }
46
47 public void keyPressed(KeyEvent e) {
48 if (e.getKeyCode()==KeyEvent.VK_UP) {
49 Object o = e.getSource();
50 JTextField tc = ((JTextField)o);
51 tc.setText(last);
52 }
53 }
54 }
55 }
56