From cea6530d2df11a9377dde0eab6eed7f4e6335067 Mon Sep 17 00:00:00 2001 From: mbirth Date: Wed, 8 Dec 2004 10:17:22 +0000 Subject: [PATCH] modified JFastReader.java * Extracted infoPrint-Class to separate file for re-using in other projects ! setResize(false) commented out for testing of MyCanvas --- JFastReader.java | 103 ++++++----------------------------------------- 1 file changed, 12 insertions(+), 91 deletions(-) diff --git a/JFastReader.java b/JFastReader.java index a40ce6c..2ee345f 100644 --- a/JFastReader.java +++ b/JFastReader.java @@ -101,26 +101,13 @@ public class JFastReader extends Frame implements ActionListener { Dimension dmScreen = Toolkit.getDefaultToolkit().getScreenSize(); // get Screen dimensions - Dialog diInfo = new Dialog(this, "infoPrint", false); - Label lbInfo = new Label(); - InfoPrintThread thIPT = new InfoPrintThread(); + MyInfoPrint MIP = new MyInfoPrint(this); private class MainWindowAdapter extends WindowAdapter { public void windowClosing(WindowEvent we) { // TODO: Insert commands to execute upon shutdown - System.out.println("Received windowClosing event... application shutting down."); - infoPrint("Goodbye..."); - System.out.println("Initiated InfoPrint..."); - try { - while (thIPT.isAlive()) { - thIPT.setStopnow(true); - Thread.sleep(100); - } - } catch (InterruptedException exIE) { - System.out.println("Sleeping won't work. "+exIE.toString()); - exIE.printStackTrace(); - } - System.out.println("InfoPrint stopped."); + MIP.infoPrint("Goodbye..."); + MIP.hide(); System.exit(0); } } @@ -163,7 +150,7 @@ public class JFastReader extends Frame implements ActionListener { getWord(1); showWord(curWord); } else { - infoPrint("Cancelled."); + MIP.infoPrint("Cancelled."); } } else if (ae.getSource().equals(btBack)) { System.out.println("<<< BACK"); @@ -215,7 +202,7 @@ public class JFastReader extends Frame implements ActionListener { int wordcount = 1; if (seeker.len <= 0) { // get wordcounts - infoPrint("Indexing..."); + MIP.infoPrint("Indexing..."); while ((tmp = f.readLine()) != null) { // System.out.println("Read line: >" + tmp + "<"); String[] words = splitString(tmp, " "); @@ -226,25 +213,25 @@ public class JFastReader extends Frame implements ActionListener { lastPos = f.getFilePointer(); } maxWord = --wordcount; - System.out.println("Words at all: "+maxWord); + // System.out.println("Words at all: "+maxWord); } long[] seekpos = seeker.getSeekForWord(w); f.seek(seekpos[1]); String myLine = f.readLine(); int indexl = 0; while (seekpos[0]0) { - System.out.println("Need word: "+w+"; cur: "+seekpos[0]); + // System.out.println("Need word: "+w+"; cur: "+seekpos[0]); indexl = myLine.indexOf(" ", indexl+1)+1; seekpos[0]++; } - System.out.println("Need word: "+w+"; got: "+seekpos[0]); + // System.out.println("Need word: "+w+"; got: "+seekpos[0]); int indexr = myLine.indexOf(" ", indexl+1); if (indexr <= 0) { indexr = myLine.length(); } result = myLine.substring(indexl, indexr); f.close(); } catch (IOException ioe) { System.out.println("IOException while reading file: "+ioe.toString()); - infoPrint("File IO error"); + MIP.infoPrint("File IO error"); } } return result; @@ -252,17 +239,16 @@ public class JFastReader extends Frame implements ActionListener { private void showWord(int w) { String wrd = getWord(w); - System.out.println("Should show word #"+w+" >"+wrd+"<"); cvFR.setWord(wrd); } public JFastReader() { // Constructor addWindowListener(new MainWindowAdapter()); setTitle(APPNAME+" "+APPVERSION+" by Markus Birth"); // set Frame title - setResizable(false); + //setResizable(false); setSize(WND_W, WND_H); // set Frame size setLocation((dmScreen.width-WND_W)/2, (dmScreen.height-WND_H)/2); // center Frame - infoPrint(APPNAME+" loading..."); + MIP.infoPrint(APPNAME+" loading..."); doAbout(); btAbout.addActionListener(this); @@ -323,7 +309,7 @@ public class JFastReader extends Frame implements ActionListener { // TODO: more initialization commands show(); // automagically calls paint(Graphics g) - diInfo.setVisible(false); // init done, hide infoPrint + MIP.hide(); // init done, hide infoPrint } public static void main(String args[]) { @@ -397,71 +383,6 @@ public class JFastReader extends Frame implements ActionListener { } return result; } - - } - - // waits 3 seconds and then hides the diInfo-Dialog - private class InfoPrintThread extends Thread { - private transient boolean stopnow; - - public void run() { - this.stopnow = false; - try { - // System.out.println("IPT: started."); - long dtStart = System.currentTimeMillis(); - while (System.currentTimeMillis()