Merge /pub/main
[educational.data.git] / Dr.NO / src / drno / swingui / guiController / konsultationProgress.java
blob7135b2e2ff2293dfe6dd90edd51e0823a2614009
1 /*
2 * konsultationProgress.java
4 * Created on 30. april 2005, 15:15
5 */
7 package drno.swingui.guiController;
9 import java.util.Date;
10 import java.text.DateFormat;
11 import java.util.GregorianCalendar;
13 /**
15 * @author Leo
17 public class konsultationProgress {
18 int konsultationLength=0;
19 long taskCurrent=0;
20 long kstart,kcurrent;
21 boolean done = false;
22 boolean canceled = false;
23 boolean clockDone = false;
24 Date timeCurrent;
25 String statMessage,clockString;
26 //TableHandler th = new TableHandler();
28 /** Creates a new instance of konsultationProgress */
29 public konsultationProgress() {
33 public void go(){
34 GregorianCalendar c = new GregorianCalendar();
35 kstart = (c.getTime()).getTime()/1000;
36 final SwingWorker worker = new SwingWorker() {
37 public Object construct() {
38 taskCurrent = 0;
39 done = false;
40 canceled = false;
41 statMessage = null;
42 return new ActualTask();
45 worker.start();
48 public void goClock(){
49 final SwingWorker worker2 = new SwingWorker(){
50 public Object construct(){
51 clockString ="";
52 return new Clock();
55 worker2.start();
58 /**
59 * Called from ProgressBarDemo to find out how much work needs
60 * to be done.
62 public int getLengthOfTask() {
63 return konsultationLength;
65 public void setLengthOfTask(int length) {
66 konsultationLength = length*60;
69 /**
70 * Called from ProgressBarDemo to find out how much has been done.
72 public long getCurrent() {
73 return taskCurrent;
76 public void stop() {
77 canceled = true;
78 statMessage = null;
81 /**
82 * Called from ProgressBarDemo to find out if the task has completed.
84 public boolean isDone() {
85 return done;
88 /**
89 * Returns the most recent status message, or null
90 * if there is no current status message.
92 public String getMessage() {
93 return statMessage;
96 class Clock{
97 Clock(){
98 while(!clockDone){
99 try{
100 Thread.sleep(1000);
101 GregorianCalendar c = new GregorianCalendar();
102 DateFormat df = DateFormat.getTimeInstance(DateFormat.MEDIUM);
103 timeCurrent=c.getTime();
104 clockString = df.format(c.getTime());
105 //System.out.println(clockString);
107 catch(Exception e){
108 e.printStackTrace();
114 public String getTimeString(){
115 return clockString;
117 public Date getTime(){
118 return timeCurrent;
122 * The actual long running task. This runs in a SwingWorker thread.
124 class ActualTask {
125 ActualTask() {
126 //Fake a long task,
127 //making a random amount of progress every second.
128 while (!canceled && !done) {
129 try {
130 Thread.sleep(1000); //sleep for a second
131 GregorianCalendar c = new GregorianCalendar();
132 kcurrent = (c.getTime()).getTime()/1000;
133 taskCurrent = kcurrent-kstart;
134 if (taskCurrent >= konsultationLength) {
135 done = true;
136 taskCurrent = konsultationLength;
138 statMessage = "Completed " + taskCurrent +
139 " out of " + konsultationLength + ".";
140 } catch (Exception e) {
141 System.out.println("ActualTask interrupted");