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