Mercurial > hg > jslab
annotate src/samer/core_/util/heavy/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.heavy; |
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 |
samer@0 | 18 public class CommandField extends TextField |
samer@0 | 19 { |
samer@0 | 20 public CommandField(int w) |
samer@0 | 21 { |
samer@0 | 22 super(w); |
samer@0 | 23 |
samer@0 | 24 setBackground( Shell.getColor("awt.input.console.background", Color.black)); |
samer@0 | 25 setForeground( Shell.getColor("awt.input.console.foreground", Color.orange)); |
samer@0 | 26 try { setFont(X.font(Shell.datum("awt.input.console.font"),null)); } |
samer@0 | 27 catch (Exception ex) { /* ok if no font specified */ } |
samer@0 | 28 addActionListener(h); |
samer@0 | 29 addKeyListener(h); |
samer@0 | 30 } |
samer@0 | 31 |
samer@0 | 32 static Handler h = new Handler(); |
samer@0 | 33 static class Handler extends KeyAdapter implements ActionListener, java.io.Serializable |
samer@0 | 34 { |
samer@0 | 35 String last; |
samer@0 | 36 |
samer@0 | 37 public void actionPerformed(ActionEvent e) { |
samer@0 | 38 Object o = e.getSource(); |
samer@0 | 39 TextComponent tc = ((TextComponent)o); |
samer@0 | 40 last=tc.getText(); |
samer@0 | 41 Shell.print("> "+last); |
samer@0 | 42 Shell.interpret(new StringReader(last)); |
samer@0 | 43 tc.setText(""); |
samer@0 | 44 } |
samer@0 | 45 |
samer@0 | 46 public void keyPressed(KeyEvent e) { |
samer@0 | 47 if (e.getKeyCode()==KeyEvent.VK_UP) { |
samer@0 | 48 Object o = e.getSource(); |
samer@0 | 49 TextComponent tc = ((TextComponent)o); |
samer@0 | 50 tc.setText(last); |
samer@0 | 51 } |
samer@0 | 52 } |
samer@0 | 53 } |
samer@0 | 54 } |
samer@0 | 55 |