Inheritance diagram for HistoryShell::
Public Methods | |
HistoryShell () | |
InputStream | getInputStream () |
OutputStream | getOutputStream () |
void | actionPerformed (ActionEvent e) |
void | componentHidden (ComponentEvent e) |
void | componentMoved (ComponentEvent e) |
void | componentShown (ComponentEvent e) |
void | componentResized (ComponentEvent e) |
void | keyPressed (KeyEvent e) |
void | keyReleased (KeyEvent e) |
void | keyTyped (KeyEvent e) |
Static Public Methods | |
void | main (String[] args) |
|
00024 { 00025 createContents(); 00026 00027 _textField.addActionListener(this); 00028 _textField.addKeyListener(this); 00029 _textField.setVisible(false); 00030 _textField.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); 00031 00032 _attr = new SimpleAttributeSet(); 00033 StyleConstants.setFontSize(_attr, _textField.getFont().getSize()); 00034 StyleConstants.setFontFamily(_attr, _textField.getFont().getFamily()); 00035 00036 _textPane.addComponentListener(this); 00037 _textPane.setEditable(false); 00038 00039 _history = new HistoryList(); 00040 00041 _input = new HistoryShellInputStream(); 00042 _output = new HistoryShellOutputStream(); 00043 } |
|
00047 { 00048 return _input; 00049 } |
|
00053 { 00054 return _output; 00055 } |
|
00059 { 00060 JFrame f = new JFrame("Test"); 00061 00062 HistoryShell sh = new HistoryShell(); 00063 00064 f.getContentPane().add(sh); 00065 f.setDefaultCloseOperation(3); 00066 f.setSize(400,300); 00067 f.show(); 00068 00069 InputStream is = sh.getInputStream(); 00070 PrintStream os = new PrintStream(sh.getOutputStream(), true); 00071 byte[] b = new byte[1024]; 00072 try { 00073 while(true) { 00074 os.print(">>> "); 00075 int n = is.read(b); 00076 os.println(new String(b, 0, n)); 00077 } 00078 }catch(IOException e) {} 00079 00080 } |
|
00083 { 00084 synchronized(_textField) 00085 { 00086 String text = _textField.getText(); 00087 _buff = (text+"\n").getBytes(); 00088 _buffPos = 0; 00089 _output.write(text+"\n"); 00090 00091 _textField.setText(""); 00092 _textField.setVisible(false); 00093 _textField.notifyAll(); 00094 00095 _history.add(text); 00096 } 00097 } |
|
00099 {} |
|
00100 {} |
|
00101 {} |
|
00104 { 00105 placeInputAtEnd(); 00106 } |
|
00110 { 00111 if(e.getKeyCode() == e.VK_UP) { 00112 String text = _history.getPrevious(); 00113 if(text != null) _textField.setText(text); 00114 e.consume(); 00115 } 00116 else if(e.getKeyCode() == e.VK_DOWN) { 00117 String text = _history.getNext(); 00118 if(text != null) _textField.setText(text); 00119 e.consume(); 00120 } 00121 00122 //The call to consume() is to avoid the scroll when UP 00123 //or DOWN are pressed. 00124 } |
|
00126 {} |
|
00127 {} |