Mercurial > hg > jslab
view src/samer/core_/util/swing/CommandField.java @ 8:5e3cbbf173aa tip
Reorganise some more
author | samer |
---|---|
date | Fri, 05 Apr 2019 22:41:58 +0100 |
parents | bf79fb79ee13 |
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); } } } }