cz.aiken.util.lwtt
Class TaskTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by cz.aiken.util.lwtt.TaskTableModel
All Implemented Interfaces:
java.awt.event.ActionListener, java.io.Serializable, java.util.EventListener, javax.swing.table.TableModel

public class TaskTableModel
extends javax.swing.table.AbstractTableModel
implements java.awt.event.ActionListener

This class represents the task table model.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
TaskTableModel(TaskFrame tf)
          Creates a new instance of TaskTableModel
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Processes an action event.
 void addNewTask()
          Creates a new task.
 void cancelAutoSave()
          Destroys the timer controlling automatic data saving.
 java.lang.Class<?> getColumnClass(int columnIndex)
          Returns the class of the given column.
 int getColumnCount()
          Returns the column count (currently 2).
 java.lang.String getColumnName(int column)
          Returns the name of the given column.
static java.io.File getDir()
          Returns the absolute path to the directory where LWTT data should be saved.
static java.io.File getPath()
          Returns the absolute path to the file where LWTT data should be saved.
 int getRowCount()
          Returns the row count.
 Task getTask(int index)
           
 java.lang.Object getValueAt(int rowIndex, int columnIndex)
          Returns the value at the given coordinates.
 boolean isCellEditable(int rowIndex, int columnIndex)
          Checks whether the given cell is editable.
 boolean isRunning(int index)
          Checks whether the given task is running.
 void loadFromFile()
          Loads application's data from the file.
 void removeTasks(int start, int end)
          Removes the given tasks.
 void resetTasks(int start, int end)
          Resets the given tasks.
 void saveToFile()
          Saves application's data to the file.
 void setValueAt(java.lang.Object aValue, int rowIndex, int columnIndex)
          Sets a new value of the given cell.
 void startTasks(int start, int end)
          Starts the given tasks.
 void stopAllTasks()
          Stops all tasks.
 void stopTasks(int start, int end)
          Stops the given tasks.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableDataChanged, fireTableChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TaskTableModel

public TaskTableModel(TaskFrame tf)
Creates a new instance of TaskTableModel

Parameters:
tf - task frame instance
Method Detail

getValueAt

public java.lang.Object getValueAt(int rowIndex,
                                   int columnIndex)
Returns the value at the given coordinates.

Specified by:
getValueAt in interface javax.swing.table.TableModel
Parameters:
rowIndex - row index
columnIndex - column index
Returns:
appropriate cell value; if the arguments are invalid it returns null

getRowCount

public int getRowCount()
Returns the row count.

Specified by:
getRowCount in interface javax.swing.table.TableModel
Returns:
row count

getColumnCount

public int getColumnCount()
Returns the column count (currently 2).

Specified by:
getColumnCount in interface javax.swing.table.TableModel
Returns:
column count

setValueAt

public void setValueAt(java.lang.Object aValue,
                       int rowIndex,
                       int columnIndex)
Sets a new value of the given cell. If at least one of the coordinates is invalid it does nothing.

Specified by:
setValueAt in interface javax.swing.table.TableModel
Overrides:
setValueAt in class javax.swing.table.AbstractTableModel
Parameters:
aValue - new value
rowIndex - row index
columnIndex - column index

getColumnName

public java.lang.String getColumnName(int column)
Returns the name of the given column.

Specified by:
getColumnName in interface javax.swing.table.TableModel
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel
Parameters:
column - column index
Returns:
column name; if the index is invalid it returns an empty string

getColumnClass

public java.lang.Class<?> getColumnClass(int columnIndex)
Returns the class of the given column.

Specified by:
getColumnClass in interface javax.swing.table.TableModel
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel
Parameters:
columnIndex - column index
Returns:
appropriate class object; if the column index is invalid it returns Void.class.

isCellEditable

public boolean isCellEditable(int rowIndex,
                              int columnIndex)
Checks whether the given cell is editable.

Specified by:
isCellEditable in interface javax.swing.table.TableModel
Overrides:
isCellEditable in class javax.swing.table.AbstractTableModel
Parameters:
rowIndex - row index
columnIndex - column index
Returns:
true for the first column (index 0), false otherwise

getTask

public Task getTask(int index)

addNewTask

public void addNewTask()
Creates a new task.


removeTasks

public void removeTasks(int start,
                        int end)
Removes the given tasks.

Parameters:
start - start index
end - end index (including)

startTasks

public void startTasks(int start,
                       int end)
Starts the given tasks.

Parameters:
start - start index
end - end index (including)

stopTasks

public void stopTasks(int start,
                      int end)
Stops the given tasks.

Parameters:
start - start index
end - end index (including)

stopAllTasks

public void stopAllTasks()
Stops all tasks.


resetTasks

public void resetTasks(int start,
                       int end)
Resets the given tasks.

Parameters:
start - index of the first resetted task
end - index of the first NOT resetted task (the first task beyond the interval)

cancelAutoSave

public void cancelAutoSave()
Destroys the timer controlling automatic data saving.


getDir

public static java.io.File getDir()
Returns the absolute path to the directory where LWTT data should be saved.

Returns:
directory path

getPath

public static java.io.File getPath()
Returns the absolute path to the file where LWTT data should be saved.

Returns:
absolute file path

isRunning

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

Parameters:
index - task index
Returns:
true for running task, false otherwise

loadFromFile

public void loadFromFile()
Loads application's data from the file.


saveToFile

public void saveToFile()
Saves application's data to the file.


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Processes an action event. If the event has been generated by the auto-save timer it saves the data. Otherwise (a button action occurred) it updates the appropriate table cell.

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