Fixed some bugs

This commit is contained in:
Ziver Koc 2008-12-25 15:16:53 +00:00
parent 28e690e402
commit d699626cf0
2 changed files with 8 additions and 6 deletions

View file

@ -8,7 +8,7 @@ import zutil.ui.Console;
public class ConsoleTest { public class ConsoleTest {
public static void main(String[] args) throws IOException{ public static void main(String[] args) throws IOException{
new Console("Console Test", true); new Console("Console Test");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
while(true){ while(true){

View file

@ -42,7 +42,7 @@ import zutil.FileFinder;
* *
*/ */
public class Console{ public class Console{
public static String defaultIcon = "zutil/data/JavaConsole.png"; public static String DEFAULT_ICON = "zutil/data/JavaConsole.png";
// UI things // UI things
private JFrame frame; private JFrame frame;
private JTextPane console; private JTextPane console;
@ -60,7 +60,7 @@ public class Console{
public Console(String title, int width, int height, int buffer, boolean tray){ public Console(String title, int width, int height, int buffer, boolean tray){
ConsoleInputStream in = new ConsoleInputStream(); ConsoleInputStream in = new ConsoleInputStream();
defaultIcon = FileFinder.find(defaultIcon).getAbsolutePath(); DEFAULT_ICON = FileFinder.find(DEFAULT_ICON).getAbsolutePath();
initUI(title, in); initUI(title, in);
bufferSize = buffer; bufferSize = buffer;
@ -69,7 +69,7 @@ public class Console{
System.setIn(in); System.setIn(in);
enableTray(tray); enableTray(tray);
setFrameIcon(Toolkit.getDefaultToolkit().getImage(defaultIcon)); setFrameIcon(Toolkit.getDefaultToolkit().getImage(DEFAULT_ICON));
frame.setSize(width, height); frame.setSize(width, height);
frame.setVisible(true); frame.setVisible(true);
} }
@ -161,7 +161,7 @@ public class Console{
// Icon // Icon
trayIcon = new TrayIcon( trayIcon = new TrayIcon(
Toolkit.getDefaultToolkit().getImage(defaultIcon), Toolkit.getDefaultToolkit().getImage(DEFAULT_ICON),
"Console", menu); "Console", menu);
trayIcon.setImageAutoSize(true); trayIcon.setImageAutoSize(true);
trayIcon.addMouseListener(new MouseListener(){ trayIcon.addMouseListener(new MouseListener(){
@ -217,7 +217,7 @@ public class Console{
public void print(String s){ public void print(String s){
appendConsole(s, style); appendConsole(s, style);
console.setCaretPosition(console.getDocument().getLength()); console.setCaretPosition(console.getDocument().getLength());
if(trayMessageType != null){ if(trayMessageType != null && trayIcon != null){
trayIcon.displayMessage( trayIcon.displayMessage(
s.substring(0, (s.length() > 25 ? 25 : s.length()))+"...", s.substring(0, (s.length() > 25 ? 25 : s.length()))+"...",
s, trayMessageType); s, trayMessageType);
@ -259,12 +259,14 @@ public class Console{
input = 0; input = 0;
return -1; return -1;
} }
read = true; read = true;
input = 0; input = 0;
while(input == 0){ while(input == 0){
try {Thread.sleep(10);} catch (InterruptedException e) {} try {Thread.sleep(10);} catch (InterruptedException e) {}
} }
read = false; read = false;
System.out.print((char)input); System.out.print((char)input);
if(input == KeyEvent.VK_ENTER){ if(input == KeyEvent.VK_ENTER){
input = -1; input = -1;