cz.aiken.util.lwtt
Class Task

java.lang.Object
  extended by cz.aiken.util.lwtt.Task
All Implemented Interfaces:
java.awt.event.ActionListener, java.lang.Comparable<Task>, java.util.EventListener

public class Task
extends java.lang.Object
implements java.awt.event.ActionListener, java.lang.Comparable<Task>

This class represents a tracked task.


Field Summary
static int PERIOD
          period for updating time values [ms]
static double UNITS_PER_HOUR
          time units per hour
 
Constructor Summary
Task()
          Creates a new instance of Task
Task(int id, java.lang.String name, long consumption, double price)
          Creates an instance for a task which has been already tracked.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Updates the time consumption value.
 int compareTo(Task t)
          Compares this task to another one.
 long getConsumption()
          Returns the current value of cumulative consumption [ms].
 int getId()
          Returns the task identifier.
 java.lang.String getName()
          Returns the task name.
static int getNewId()
          Generates a new task identifier.
 double getPrice()
          Returns the current price per hour [currency unit].
 double getTotalPrice()
          Returns the total price of this task [currency unit].
 boolean isRunning()
          Checks whether the task is running.
 void setActionListener(java.awt.event.ActionListener al)
          Sets the listener where action events should be passed to.
 void setConsumption(long consumption)
          Sets the task cumulative time consumption [ms].
 void setName(java.lang.String name)
          Sets the task name.
 void setPrice(double price)
          Sets the price per hour [currency unit].
 void start()
          Starts tracking of this task.
 void stop()
          Stops tracking of this task.
 java.lang.String toString()
          Converts the instance to the string representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PERIOD

public static final int PERIOD
period for updating time values [ms]

See Also:
Constant Field Values

UNITS_PER_HOUR

public static final double UNITS_PER_HOUR
time units per hour

See Also:
Constant Field Values
Constructor Detail

Task

public Task()
Creates a new instance of Task


Task

public Task(int id,
            java.lang.String name,
            long consumption,
            double price)
Creates an instance for a task which has been already tracked.

Parameters:
id - task identifier
name - task name
consumption - up to now time consumption
price - price per hour
Method Detail

getNewId

public static int getNewId()
Generates a new task identifier.

Returns:
new identifier

setActionListener

public void setActionListener(java.awt.event.ActionListener al)
Sets the listener where action events should be passed to.

Parameters:
al - action listener

getId

public int getId()
Returns the task identifier.

Returns:
task identifier

getName

public java.lang.String getName()
Returns the task name.

Returns:
task name

setName

public void setName(java.lang.String name)
Sets the task name.

Parameters:
name - new task name

getConsumption

public long getConsumption()
Returns the current value of cumulative consumption [ms].

Returns:
current cumulative consumption

setConsumption

public void setConsumption(long consumption)
Sets the task cumulative time consumption [ms].

Parameters:
consumption - new time consumption value

setPrice

public void setPrice(double price)
Sets the price per hour [currency unit]. Changing this parameter affects the current total price of the task.

Parameters:
price - new price value

getPrice

public double getPrice()
Returns the current price per hour [currency unit].

Returns:
current price value

getTotalPrice

public double getTotalPrice()
Returns the total price of this task [currency unit].

Returns:
total price of this task

toString

public java.lang.String toString()
Converts the instance to the string representation. It contains the task name and consumption.

Overrides:
toString in class java.lang.Object
Returns:
string representation

start

public void start()
Starts tracking of this task.


stop

public void stop()
Stops tracking of this task.


isRunning

public boolean isRunning()
Checks whether the task is running.

Returns:
true if running, false otherwise

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Updates the time consumption value. Then it creates a new action event and passes it to the assigned listener (if any).

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - action event

compareTo

public int compareTo(Task t)
Compares this task to another one. The comparison result is based on task identifiers.

Specified by:
compareTo in interface java.lang.Comparable<Task>
Parameters:
t - another task
Returns:
1 if this class' id is greater then the given class' id, -1 if both ids are equal and 0 otherwise