Mercurial > hg > jslab
view 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 |
line wrap: on
line source
/* * CommandField.java * * Copyright (c) 2000, Samer Abdallah, King's College London. * All rights reserved. * * This software is provided AS iS and WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. */ package samer.core.util.heavy; import samer.core.*; import java.awt.*; import java.awt.event.*; import java.io.*; public class CommandField extends TextField { public CommandField(int w) { super(w); setBackground( Shell.getColor("awt.input.console.background", Color.black)); setForeground( Shell.getColor("awt.input.console.foreground", Color.orange)); try { setFont(X.font(Shell.datum("awt.input.console.font"),null)); } catch (Exception ex) { /* ok if no font specified */ } addActionListener(h); addKeyListener(h); } static Handler h = new Handler(); static class Handler extends KeyAdapter implements ActionListener, java.io.Serializable { String last; public void actionPerformed(ActionEvent e) { Object o = e.getSource(); TextComponent tc = ((TextComponent)o); last=tc.getText(); Shell.print("> "+last); Shell.interpret(new StringReader(last)); tc.setText(""); } public void keyPressed(KeyEvent e) { if (e.getKeyCode()==KeyEvent.VK_UP) { Object o = e.getSource(); TextComponent tc = ((TextComponent)o); tc.setText(last); } } } }