Mercurial > hg > jslab
view 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 |
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.swing; import samer.core.*; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; public class CommandField extends JTextField { public CommandField(int w) { super(w); setBackground( X.color(Shell.datum("swing.input.console.background"), Color.white)); setForeground( X.color(Shell.datum("swing.input.console.foreground"), Color.black)); Font font=X.font(Shell.datum("swing.input.console.font"),null); if (font!=null) setFont(font); 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(); JTextField tc = ((JTextField)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(); JTextField tc = ((JTextField)o); tc.setText(last); } } } }