1 package com.melloware.jukes.gui.view.tasks;
2
3
4 /**
5 * Abstract class that uses a SwingWorker to perform a time-consuming task.
6 * <p>
7 * Copyright (c) 1999-2007 Melloware, Inc. <http://www.melloware.com>
8 * @author Emil A. Lefkof III <info@melloware.com>
9 * @version 4.0
10 */
11 @SuppressWarnings("PMD")
12 abstract public class LongTask {
13
14 protected boolean canceled = false;
15 protected boolean done = false;
16 protected int current = 0;
17 protected int lengthOfTask = 0;
18 protected String statMessage;
19
20 /**
21 * Constructor that needs a config object and a filename to work on.
22 * <p>
23 */
24 public LongTask() {
25 super();
26 }
27
28 /**
29 * Called to start the task.
30 */
31 abstract public void go();
32
33 /**
34 * Called to find out how much has been done.
35 */
36 public int getCurrent() {
37 return current;
38 }
39
40 /**
41 * Called to find out how much work needs
42 * to be done.
43 */
44 public int getLengthOfTask() {
45 return lengthOfTask;
46 }
47
48 /**
49 * Returns the most recent status message, or null
50 * if there is no current status message.
51 */
52 public String getMessage() {
53 return statMessage;
54 }
55
56 /**
57 * Called to find out if the task has been cancelled.
58 */
59 public boolean isCancelled() {
60 return canceled;
61 }
62
63 /**
64 * Called to find out if the task has completed.
65 */
66 public boolean isDone() {
67 return done;
68 }
69
70 /**
71 * Stops the current long task.
72 */
73 public void stop() {
74 canceled = true;
75 statMessage = null;
76 }
77
78 }