Subversion Repositories public

Rev

Rev 89 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 89 Rev 93
Line 23... Line 23...
23
23
24
package cz.aiken.util.lwtt;
24
package cz.aiken.util.lwtt;
25
25
26
import javax.swing.Timer;
26
import javax.swing.Timer;
27
import java.awt.event.*;
27
import java.awt.event.*;
-
 
28
import java.math.*;
28
29
29
/**
30
/**
30
 * This class represents a tracked task.
31
 * This class represents a tracked task.
31
 * @author luk
32
 * @author luk
32
 */
33
 */
33
public class Task implements ActionListener, Comparable<Task> {
34
public class Task implements ActionListener, Comparable<Task> {
34
    private int id;
35
    private int id;
35
   
36
   
36
    private String name = "Unnamed task";
37
    private String name = "Unnamed task";
37
    private long consumption = 0L;
38
    private long consumption = 0L;
-
 
39
    private double price = 1;
38
   
40
   
39
    private Timer timer = null;
41
    private Timer timer = null;
40
    /**
42
    /**
41
     * period for updating time values [ms]
43
     * period for updating time values [ms]
42
     */
44
     */
43
    public static final int PERIOD = 10000;
45
    public static final int PERIOD = 10000;
44
   
46
   
-
 
47
    /**
-
 
48
     * time units per hour
-
 
49
     */
-
 
50
    public static final double UNITS_PER_HOUR = 3600000;
-
 
51
   
45
    private ActionListener listener = null;
52
    private ActionListener listener = null;
46
   
53
   
47
    private static int nextId = 0;
54
    private static int nextId = 0;
48
           
55
           
49
    /**
56
    /**
Line 66... Line 73...
66
    /**
73
    /**
67
     * Creates an instance for a task which has been already tracked.
74
     * Creates an instance for a task which has been already tracked.
68
     * @param id task identifier
75
     * @param id task identifier
69
     * @param name task name
76
     * @param name task name
70
     * @param consumption up to now time consumption
77
     * @param consumption up to now time consumption
-
 
78
     * @param price price per hour
71
     */
79
     */
72
    public Task(int id, String name, long consumption) {
80
    public Task(int id, String name, long consumption, double price) {
73
        this.id = id;
81
        this.id = id;
74
        this.name = name;
82
        this.name = name;
75
        this.consumption = consumption;
83
        this.consumption = consumption;
-
 
84
        this.price = price;
76
       
85
       
77
        if (id >= nextId)
86
        if (id >= nextId)
78
            nextId = id + 1;
87
            nextId = id + 1;
79
    }
88
    }
80
   
89
   
Line 125... Line 134...
125
    public void setConsumption(long consumption) {
134
    public void setConsumption(long consumption) {
126
        this.consumption = consumption;
135
        this.consumption = consumption;
127
    }
136
    }
128
   
137
   
129
    /**
138
    /**
-
 
139
     *  Sets the price per hour [currency unit].
-
 
140
     *  Changing this parameter affects the current total price of the task.
-
 
141
     * @param price new price value
-
 
142
     */
-
 
143
    public void setPrice(double price) {
-
 
144
        this.price = price;
-
 
145
    }
-
 
146
   
-
 
147
    /**
-
 
148
     * Returns the current price per hour [currency unit].
-
 
149
     * @return current price value
-
 
150
     */
-
 
151
    public double getPrice() {
-
 
152
        return price;
-
 
153
    }
-
 
154
   
-
 
155
    /**
-
 
156
     *  Returns the total price of this task [currency unit].
-
 
157
     * @return total price of this task
-
 
158
     */
-
 
159
    public double getTotalPrice() {
-
 
160
        return ((double) consumption) / UNITS_PER_HOUR * price;
-
 
161
    }
-
 
162
   
-
 
163
    /**
130
     * Converts the instance to the string representation. It contains
164
     * Converts the instance to the string representation. It contains
131
     * the task name and consumption.
165
     * the task name and consumption.
132
     * @return string representation
166
     * @return string representation
133
     */
167
     */
134
    @Override
168
    @Override