1 28 37 38 package org.planetamessenger.ui; 39 40 41 public class JConsoleWindow extends java.io.PrintStream { 42 43 private static final int WIDTH = 400; 44 private static final int HEIGHT = 300; 45 46 javax.swing.text.SimpleAttributeSet attrs; 47 javax.swing.JTextPane dataPane; 48 javax.swing.JScrollPane scrollPane; 49 javax.swing.JFrame frame; 50 boolean bAutoScrolling; 51 52 53 57 public JConsoleWindow() { 58 59 super( System.out ); 60 61 attrs = new javax.swing.text.SimpleAttributeSet (); 62 frame = new javax.swing.JFrame (); 63 dataPane = new javax.swing.JTextPane (); 64 scrollPane = new javax.swing.JScrollPane ( dataPane ); 65 bAutoScrolling = true; 66 67 dataPane.setBackground( java.awt.Color.black ); 68 dataPane.setEditable( false ); 69 70 javax.swing.text.StyleConstants.setForeground( attrs, java.awt.Color.green ); 71 frame.getContentPane().add( scrollPane ); 72 frame.addWindowListener( new java.awt.event.WindowAdapter () { 73 public void windowClosing( java.awt.event.WindowEvent evt ) { 74 hide(); 75 } 76 } ); 77 78 frame.setSize( WIDTH, HEIGHT ); 79 } 82 83 88 public void setAutoScrolling( boolean bAutoScrolling ) { 89 90 this.bAutoScrolling = bAutoScrolling; 91 } 92 93 97 public boolean getAutoScrolling() { 98 99 return bAutoScrolling; 100 } 101 102 106 public void setTitle( String strTitle ) { 107 108 if( frame != null ) 109 frame.setTitle( strTitle ); 110 } 111 112 115 public void show() { 116 117 frame.setVisible( true ); 118 } 119 120 123 public void hide() { 124 125 frame.setVisible( false ); 126 } 127 128 131 public void destroy() { 132 133 frame.dispose(); 134 frame = null; 135 dataPane = null; 136 scrollPane = null; 137 } 138 139 143 public void updateUI() { 144 145 javax.swing.SwingUtilities.updateComponentTreeUI( frame ); 146 frame.invalidate(); 147 frame.validate(); 148 frame.repaint(); 149 } 150 151 157 public void println( java.lang.Object x ) { 158 159 println( x.toString() ); 160 } 161 162 168 public void println( java.lang.String x ) { 169 170 _print( x + "\n" ); 171 } 172 173 179 private void _print( String strMsg ) { 180 181 try { 182 javax.swing.text.Document doc = dataPane.getDocument(); 183 184 doc.insertString( doc.getLength(), strMsg, attrs ); 185 186 if( bAutoScrolling ) 187 dataPane.setCaretPosition( doc.getLength() ); 188 189 } catch( javax.swing.text.BadLocationException e ) { 190 e.printStackTrace(); 191 } 192 } 193 } 194 195 | Popular Tags |