JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
tfCmd = new JTextField();
final KeyListener keyL = new KeyAdapter() {
public void keyPressed(KeyEvent ev) {
if(ev.getKeyCode() == KeyEvent.VK_UP) {
if(historyPos > 0) {
String line = (String)history.elementAt(historyPos-1);
historyPos--;
tfCmd.setText(line);
}
} else if(ev.getKeyCode() == KeyEvent.VK_DOWN) {
if(historyPos < history.size()-1) {
String line = (String)history.elementAt(historyPos+1);
historyPos++;
tfCmd.setText(line);
}
} else if(ev.getKeyCode() == KeyEvent.VK_ENTER) {
String line = tfCmd.getText();
if(!("".equals(line) ||
"\n".equals(line) ||
"\n\r".equals(line) ||
"\r\n".equals(line))) {
history.addElement(line);
historyPos = history.size();
}
if("clear".equals(line)) {
clear();
} else if("quit".equals(line)) {
org.knopflerfish.bundle.desktop.swing
.Activator.desktop.stopFramework();
} else {
// Try simple command expansion first
if(line.startsWith("!") && line.length() > 1) {
String s2 = line.substring(1);
String bestStr = "";
for(int i = 0; i < history.size(); i++) {
String s = (String)history.elementAt(i);
if(s.startsWith(s2) || s.length() >= bestStr.length()) {
bestStr = s;
}
}
if(!"".equals(bestStr)) {
line = bestStr;
}
}
// ..and send to console via inputstream
String s = line + "\r\n";
text.append(s);
showLastLine();
if(in != null) {
in.print(s);
in.flush();
}
}
tfCmd.setText("");
}
}
};
tfCmd.addKeyListener(keyL);
// move focus away from text output to text input
// in key press
text.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent ev) {
int modifiers = ev.getModifiers();
// Don't steal special key events like CTRL-C
if(modifiers == 0) {