diff --git a/JFastReader.java b/JFastReader.java index 4a57f42..03db6cb 100644 --- a/JFastReader.java +++ b/JFastReader.java @@ -76,7 +76,7 @@ public class JFastReader extends Frame implements ActionListener, AdjustmentList Scrollbar sbProgress = new Scrollbar(Scrollbar.HORIZONTAL, 0, 0, 0, 0); Label lbSpeedTag = new Label("Speed (wpm.)", Label.LEFT); - MyProgBar cvSpeed = new MyProgBar(10,600,sleepWPM); + MyProgBar cvSpeed = new MyProgBar(10,600,(long)sleepWPM, MyProgBar.PQ2); Label lbSpeed = new Label(String.valueOf(sleepWPM), Label.LEFT); Button btOptions = new Button("Opt."); @@ -202,13 +202,13 @@ public class JFastReader extends Frame implements ActionListener, AdjustmentList sleepWPM -= sleepWPMDelta; } lbSpeed.setText(String.valueOf(sleepWPM)); - cvSpeed.setPos(sleepWPM); + cvSpeed.setPos((long)sleepWPM); } else if (ae.getSource().equals(btFaster)) { if (sleepWPM+sleepWPMDelta<=600) { sleepWPM += sleepWPMDelta; } lbSpeed.setText(String.valueOf(sleepWPM)); - cvSpeed.setPos(sleepWPM); + cvSpeed.setPos((long)sleepWPM); } // TODO: more events } @@ -310,7 +310,7 @@ public class JFastReader extends Frame implements ActionListener, AdjustmentList private void showWord(int w) { String wrd = getWord(w); int sleeplen = (int)((double)wrd.length()/(double)defWordLen*(double)60000/(double)sleepWPM); - System.out.println("Sleep for >"+wrd+"< is "+sleeplen); + // System.out.println("Sleep for >"+wrd+"< is "+sleeplen); ptRead.setSleep(sleeplen); tfGo.setText(String.valueOf(w)); sbProgress.setValue(w); @@ -509,4 +509,4 @@ public class JFastReader extends Frame implements ActionListener, AdjustmentList } -} +} \ No newline at end of file diff --git a/MyProgBar.java b/MyProgBar.java index 6459f69..a64b39a 100644 --- a/MyProgBar.java +++ b/MyProgBar.java @@ -1,86 +1,118 @@ -import java.awt.Canvas; import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; -class MyProgBar extends Canvas { +public class MyProgBar extends Component { final static int WINDOWS = 1; final static int PQ1 = 2; final static int PQ2 = 3; - int minVal = 0; - int maxVal = 100; - int curVal = 50; + long minVal; + long maxVal; + long curVal; + private int systemDelta = 0; Color fgColor = new Color(0,0,128); - Color bgColor = Color.lightGray; + Color bgColor = new Color(220,220,220); Color txColor = Color.white; - private int mode = WINDOWS; + int Height = 18; + int Width = 40; + private int mode; - public MyProgBar(int min, int max, int pos, int mode) { - super(); + public MyProgBar(long min, long max, long pos, int mode) { this.minVal = min; this.maxVal = max; this.curVal = pos; this.mode = mode; + if (System.getProperty("os.name").equals("EPOC")) { + this.systemDelta = -1; + } } - public MyProgBar(int min, int max, int pos) { + public MyProgBar(long min, long max, long pos) { this(min, max, pos, MyProgBar.WINDOWS); } - public MyProgBar(int min, int max) { - this(min, max, min); + public MyProgBar(long min, long max) { + this(min, max, min, MyProgBar.WINDOWS); + } + + public MyProgBar() { + this(0, 100, 0, MyProgBar.WINDOWS); } public void paint(Graphics g) { - double percentage = (double)(curVal-minVal)/(double)(maxVal-minVal); - String percString = String.valueOf((int)(percentage*100)) + "%"; - g.setFont(new Font("Dialog", Font.PLAIN, 10)); - FontMetrics fm = getFontMetrics(g.getFont()); - g.setColor(bgColor); - g.fillRect(0,0,getSize().width-1,getSize().height-1); - g.setColor(fgColor); - int pright = (int)((double)(getSize().width-2)/(maxVal-minVal)*(curVal-minVal)); - g.fillRect(1,1,pright,getSize().height-2); - g.setXORMode(txColor); - int tleft; - switch (mode) { - default: - case MyProgBar.WINDOWS: - g.drawString(percString, getSize().width/2-fm.stringWidth(percString)/2, getSize().height/2-fm.getHeight()/2+fm.getAscent()); - break; - - case MyProgBar.PQ1: - tleft = pright+2; - if (tleft+fm.stringWidth(percString)>=getSize().width-1) tleft = getSize().width-1-fm.stringWidth(percString); - g.drawString(percString, tleft, getSize().height/2-fm.getHeight()/2+fm.getAscent()); - break; - - case MyProgBar.PQ2: - tleft = (pright-1)/2-fm.stringWidth(percString)/2+1; - if (tleft <= 2) tleft = 2; - g.drawString(percString, tleft, getSize().height/2-fm.getHeight()/2+fm.getAscent()); - break; + if (g != null) { + double percentage = (double)(curVal-minVal)/(double)(maxVal-minVal); + String percString = String.valueOf((int)(percentage*100)) + "%"; + g.setFont(new Font("Dialog", Font.PLAIN, 10)); + FontMetrics fm = getFontMetrics(g.getFont()); + int pright = (int)((double)(getSize().width-2)/(maxVal-minVal)*(curVal-minVal)); + g.setColor(bgColor); + g.fill3DRect(pright+1,1,getSize().width-2-pright+systemDelta,getSize().height-2+systemDelta, false); + g.setColor(fgColor); + g.fill3DRect(1,1,pright+systemDelta,getSize().height-2+systemDelta, true); + g.setXORMode(txColor); + int tleft; + switch (mode) { + default: + case MyProgBar.WINDOWS: + g.drawString(percString, getSize().width/2-fm.stringWidth(percString)/2, getSize().height/2-fm.getHeight()/2+fm.getAscent()); + break; + + case MyProgBar.PQ1: + tleft = pright+2; + if (tleft+fm.stringWidth(percString)>=getSize().width-1) tleft = getSize().width-1-fm.stringWidth(percString); + g.drawString(percString, tleft, getSize().height/2-fm.getHeight()/2+fm.getAscent()); + break; + + case MyProgBar.PQ2: + tleft = (pright-1)/2-fm.stringWidth(percString)/2+1; + if (tleft <= 2) tleft = 2; + g.drawString(percString, tleft, getSize().height/2-fm.getHeight()/2+fm.getAscent()); + break; + } + g.setPaintMode(); + g.setColor(Color.black); + g.drawRect(0,0,getSize().width-1,getSize().height-1); } - g.setPaintMode(); - g.setColor(Color.black); - g.drawRect(0,0,getSize().width-1,getSize().height-1); } - - public void setMinValue(int v) { + + public void setMinValue(long v) { minVal = v; } - public void setMaxValue(int v) { + public void setMaxValue(long v) { maxVal = v; } - public void setMode(int m) { - this.mode = m; + public void setBgColor(Color c) { + bgColor = c; + } + + public void setFgColor(Color c) { + fgColor = c; } - public void setPos(int p) { + public void setPos(long p) { curVal = p; + if (curVal > maxVal) curVal = maxVal; + else if (curVal < minVal ) curVal = minVal; paint(getGraphics()); } + + public void setMode(int m) { + mode = m; + paint(getGraphics()); + } + + public Dimension getPreferredSize() { + return new Dimension(Width, Height); + } + + public Dimension getMinimumSize() { + return new Dimension(Width, Height); + } + } \ No newline at end of file