Subversion Repositories public

Compare Revisions

Ignore whitespace Rev 1 → Rev HEAD

/lwtt/tags/lwtt-1.2.0/cz/aiken/util/lwtt/TaskPropertiesDialog.java
0,0 → 1,216
/*
* TaskPropertiesDialog.java - task properties dialog
*
* Copyright (c) 2008 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import javax.swing.JOptionPane;
 
/**
* Task properties dialog class.
*
* This class allows to set various properties of a task. Currently only
* price per hour can be set.
*
* @author luk
*/
public class TaskPropertiesDialog extends javax.swing.JDialog {
/** A return status code - returned if Cancel button has been pressed */
public static final int RET_CANCEL = 0;
/** A return status code - returned if OK button has been pressed */
public static final int RET_OK = 1;
private double price = 1;
 
/** Creates a new TaskPropertiesDialog.
* @param parent parent object for this dialog
* @param modal modal dialog yes/no
*/
public TaskPropertiesDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
priceText.setText(Double.toString(price));
}
 
/**
* Returns the "return status" of this dialog - one of RET_OK or RET_CANCEL.
*
* @return return status
*/
public int getReturnStatus() {
return returnStatus;
}
/**
* Sets the price per hour.
*
* @param price new price per hour
*/
public void setPrice(double price) {
this.price = price;
priceText.setText(Double.toString(price));
}
/**
* Returns the price per hour.
*
* @return price per hour
*/
public double getPrice() {
return price;
}
 
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
 
okButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
priceLabel = new javax.swing.JLabel();
priceText = new javax.swing.JTextField();
 
setTitle("Properties");
setLocationByPlatform(true);
setResizable(false);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
 
okButton.setText("OK");
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
 
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
 
priceLabel.setText("Price per hour");
 
priceText.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
 
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cancelButton))
.addGroup(layout.createSequentialGroup()
.addComponent(priceLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(priceText, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)))
.addContainerGap())
);
 
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});
 
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(priceLabel)
.addComponent(priceText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cancelButton)
.addComponent(okButton))
.addContainerGap())
);
 
pack();
}// </editor-fold>//GEN-END:initComponents
 
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
try {
double p = Double.parseDouble(priceText.getText());
if (p < 0)
throw new NumberFormatException("price value must not be negative");
price = p;
doClose(RET_OK);
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(this, "Price per hour has invalid format.\nPlease use a non-negative number.", "Invalid format", JOptionPane.ERROR_MESSAGE);
}
}//GEN-LAST:event_okButtonActionPerformed
 
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
doClose(RET_CANCEL);
}//GEN-LAST:event_cancelButtonActionPerformed
 
/** Closes the dialog */
private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
doClose(RET_CANCEL);
}//GEN-LAST:event_closeDialog
 
private void doClose(int retStatus) {
returnStatus = retStatus;
setVisible(false);
dispose();
}
 
/**
* This method is only for testing purposes.
*
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
TaskPropertiesDialog dialog = new TaskPropertiesDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
 
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JButton okButton;
private javax.swing.JLabel priceLabel;
private javax.swing.JTextField priceText;
// End of variables declaration//GEN-END:variables
 
private int returnStatus = RET_CANCEL;
}
/lwtt/tags/lwtt-1.2.0/cz/aiken/util/lwtt/TaskPropertiesDialog.form
0,0 → 1,93
<?xml version="1.0" encoding="UTF-8" ?>
 
<Form version="1.3" maxVersion="1.6" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="title" type="java.lang.String" value="Properties"/>
<Property name="locationByPlatform" type="boolean" value="true"/>
<Property name="resizable" type="boolean" value="false"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<Events>
<EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="closeDialog"/>
</Events>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
 
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Component id="okButton" linkSize="1" min="-2" pref="67" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cancelButton" linkSize="1" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="priceLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="priceText" pref="69" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="priceLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="priceText" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="22" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="cancelButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="okButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="okButton">
<Properties>
<Property name="text" type="java.lang.String" value="OK"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="okButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="cancelButton">
<Properties>
<Property name="text" type="java.lang.String" value="Cancel"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="priceLabel">
<Properties>
<Property name="text" type="java.lang.String" value="Price per hour"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="priceText">
<Properties>
<Property name="horizontalAlignment" type="int" value="4"/>
</Properties>
</Component>
</SubComponents>
</Form>
/lwtt/tags/lwtt-1.2.0/cz/aiken/util/lwtt/Task.java
0,0 → 1,235
/*
* Task.java - implementation of tracked task
*
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import javax.swing.Timer;
import java.awt.event.*;
 
/**
* This class represents a tracked task.
* @author luk
*/
public class Task implements ActionListener, Comparable<Task> {
private int id;
private String name = "Unnamed task";
private long consumption = 0L;
private double price = 1;
private Timer timer = null;
/**
* period for updating time values [ms]
*/
public static final int PERIOD = 10000;
/**
* time units per hour
*/
public static final double UNITS_PER_HOUR = 3600000;
private ActionListener listener = null;
private static int nextId = 0;
/**
* Generates a new task identifier.
* @return new identifier
*/
public static int getNewId() {
int id = nextId;
nextId++;
return id;
}
/**
* Creates a new instance of Task
*/
public Task() {
id = getNewId();
}
/**
* Creates an instance for a task which has been already tracked.
* @param id task identifier
* @param name task name
* @param consumption up to now time consumption
* @param price price per hour
*/
public Task(int id, String name, long consumption, double price) {
this.id = id;
this.name = name;
this.consumption = consumption;
this.price = price;
if (id >= nextId)
nextId = id + 1;
}
/**
* Sets the listener where action events should be passed to.
* @param al action listener
*/
public void setActionListener(ActionListener al) {
listener = al;
}
/**
* Returns the task identifier.
* @return task identifier
*/
public int getId() {
return id;
}
/**
* Returns the task name.
* @return task name
*/
public String getName() {
return name;
}
/**
* Sets the task name.
* @param name new task name
*/
public void setName(String name) {
this.name = name;
}
/**
* Returns the current value of cumulative consumption [ms].
* @return current cumulative consumption
*/
public long getConsumption() {
return consumption;
}
/**
* Sets the task cumulative time consumption [ms].
* @param consumption new time consumption value
*/
public void setConsumption(long consumption) {
this.consumption = consumption;
}
/**
* Sets the price per hour [currency unit].
* Changing this parameter affects the current total price of the task.
* @param price new price value
*/
public void setPrice(double price) {
this.price = price;
}
/**
* Returns the current price per hour [currency unit].
* @return current price value
*/
public double getPrice() {
return price;
}
/**
* Returns the total price of this task [currency unit].
* @return total price of this task
*/
public double getTotalPrice() {
return ((double) consumption) / UNITS_PER_HOUR * price;
}
/**
* Converts the instance to the string representation. It contains
* the task name and consumption.
* @return string representation
*/
@Override
public String toString() {
return name + "(" + Long.toString(consumption) + ")";
}
/**
* Starts tracking of this task.
*/
public void start() {
if (timer != null)
return;
timer = new Timer(PERIOD, this);
timer.start();
}
/**
* Stops tracking of this task.
*/
public void stop() {
if (timer == null)
return;
timer.stop();
timer = null;
}
/**
* Checks whether the task is running.
* @return <CODE>true</CODE> if running, <CODE>false</CODE> otherwise
*/
public boolean isRunning() {
return timer != null;
}
/**
* Updates the time consumption value. Then it creates a new action event
* and passes it to the assigned listener (if any).
* @param e action event
*/
public void actionPerformed(ActionEvent e) {
consumption += PERIOD;
ActionEvent e2 = new ActionEvent(this, id, "");
if (listener != null)
listener.actionPerformed(e2);
}
 
/**
* Compares this task to another one. The comparison result is based
* on task identifiers.
* @param t another task
* @return 1 if this class' id is greater then the given class' id,
* -1 if both ids are equal and 0 otherwise
*/
public int compareTo(Task t) {
if (t == null)
throw new NullPointerException("cannot compare to null pointer");
if (id > t.getId())
return 1;
else if (id == t.getId())
return 0;
else
return -1;
}
}
/lwtt/tags/lwtt-1.2.0/cz/aiken/util/lwtt/TaskFrame.form
0,0 → 1,172
<?xml version="1.0" encoding="UTF-8" ?>
 
<Form version="1.3" maxVersion="1.3" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="title" type="java.lang.String" value="LWTT"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<Events>
<EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="windowClosing"/>
</Events>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
 
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jSplitPane1" alignment="1" pref="572" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jSplitPane1" pref="441" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JSplitPane" name="jSplitPane1">
<Properties>
<Property name="orientation" type="int" value="0"/>
</Properties>
 
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanel1">
<Properties>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[10, 25]"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="top"/>
</Constraint>
</Constraints>
 
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="startButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="stopButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="addButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="removeButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="resetButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="propsButton" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="152" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="startButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="stopButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="addButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="removeButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="resetButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="propsButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="startButton">
<Properties>
<Property name="text" type="java.lang.String" value="Start"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="startPressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="stopButton">
<Properties>
<Property name="text" type="java.lang.String" value="Stop"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="stopPressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="addButton">
<Properties>
<Property name="text" type="java.lang.String" value="Add"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="addPressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="removeButton">
<Properties>
<Property name="text" type="java.lang.String" value="Remove"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="removePressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="resetButton">
<Properties>
<Property name="text" type="java.lang.String" value="Reset"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="resetPressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="propsButton">
<Properties>
<Property name="text" type="java.lang.String" value="Properties..."/>
<Property name="actionCommand" type="java.lang.String" value="Properties"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="propsPressed"/>
</Events>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<Properties>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[454, 400]"/>
</Property>
<Property name="verifyInputWhenFocusTarget" type="boolean" value="false"/>
</Properties>
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="right"/>
</Constraint>
</Constraints>
 
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="jTable1">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="model" type="code"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_InitCodePost" type="java.lang.String" value="jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);&#xa;jTable1.setDefaultRenderer(StringBuffer.class, new DefaultTableCellRenderer() {&#xa; private Color fg = Color.RED;&#xa; private Color bg = new Color(255, 240, 240);&#xa; &#xa; public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {&#xa; Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);&#xa; &#xa; if (JLabel.class.isAssignableFrom(c.getClass())) {&#xa; ((JLabel) c).setHorizontalAlignment(JLabel.TRAILING);&#xa; }&#xa; &#xa; if (model.isRunning(row)) {&#xa; c.setForeground(fg);&#xa; if (!isSelected)&#xa; c.setBackground(bg);&#xa; }&#xa; else {&#xa; c.setForeground(Color.BLACK);&#xa; if (!isSelected)&#xa; c.setBackground(Color.WHITE);&#xa; }&#xa; &#xa; return c;&#xa; }&#xa;});"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Form>
/lwtt/tags/lwtt-1.2.0/cz/aiken/util/lwtt/TaskTableModel.java
0,0 → 1,382
/*
* TaskTableModel.java - implementation of tracked tasks table model
*
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
import java.io.*;
import java.awt.event.*;
import java.math.*;
import java.text.*;
 
/**
* This class represents the task table model.
* @author luk
*/
public class TaskTableModel extends AbstractTableModel implements ActionListener {
private ArrayList<Task> tasks = new ArrayList<Task>();
private javax.swing.Timer timer = new javax.swing.Timer(300000, this);
private MessageFormat timeFormat = new MessageFormat("{0,number}:{1,number,00}");
private MessageFormat priceFormat = new MessageFormat("{0,number}.{1,number,00}");
private TaskFrame taskFrame = null;
/**
* Creates a new instance of TaskTableModel
* @param tf task frame instance
*/
public TaskTableModel(TaskFrame tf) {
taskFrame = tf;
loadFromFile();
timer.start();
}
 
/**
* Returns the value at the given coordinates.
* @param rowIndex row index
* @param columnIndex column index
* @return appropriate cell value; if the arguments are invalid
* it returns <CODE>null</CODE>
*/
public Object getValueAt(int rowIndex, int columnIndex) {
switch (columnIndex) {
case 0:
return tasks.get(rowIndex).getName();
case 1:
long mins = tasks.get(rowIndex).getConsumption() / 60000;
BigDecimal hm[] = new BigDecimal((int) mins).divideAndRemainder(new BigDecimal(60));
return timeFormat.format(hm);
case 2:
double tp = tasks.get(rowIndex).getTotalPrice();
BigDecimal pr[] = new BigDecimal(tp * 100).divideAndRemainder(new BigDecimal(100));
return priceFormat.format(pr);
default: return null;
}
}
 
/**
* Returns the row count.
* @return row count
*/
public int getRowCount() {
return tasks.size();
}
 
/**
* Returns the column count (currently 2).
* @return column count
*/
public int getColumnCount() {
return 3;
}
 
/**
* Sets a new value of the given cell. If at least one of the
* coordinates is invalid it does nothing.
* @param aValue new value
* @param rowIndex row index
* @param columnIndex column index
*/
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
switch (columnIndex) {
case 0: tasks.get(rowIndex).setName((String) aValue);
break;
}
}
 
/**
* Returns the name of the given column.
* @param column column index
* @return column name; if the index is invalid it returns an empty
* string
*/
@Override
public String getColumnName(int column) {
switch (column) {
case 0: return "Task name";
case 1: return "Time consumption [h:min]";
case 2: return "Total price";
default: return "";
}
}
 
/**
* Returns the class of the given column.
* @param columnIndex column index
* @return appropriate class object; if the column index is invalid
* it returns <CODE>Void.class</CODE>.
*/
@Override
public Class<?> getColumnClass(int columnIndex) {
switch (columnIndex) {
case 0: return String.class;
case 1: return StringBuffer.class;
case 2: return StringBuffer.class;
default: return Void.class;
}
}
 
/**
* Checks whether the given cell is editable.
* @param rowIndex row index
* @param columnIndex column index
* @return <CODE>true</CODE> for the first column (index 0),
* <CODE>false</CODE> otherwise
*/
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == 0;
}
public Task getTask(int index) {
return tasks.get(index);
}
/**
* Creates a new task.
*/
public void addNewTask() {
Task t = new Task();
t.setActionListener(this);
tasks.add(t);
int row = tasks.size()-1;
fireTableRowsInserted(row, row);
}
/**
* Removes the given tasks.
* @param start start index
* @param end end index (including)
*/
public void removeTasks(int start, int end) {
for (int i=end; i>=start; i--) {
Task t = tasks.remove(i);
t.stop();
t.setActionListener(null);
}
fireTableRowsDeleted(start, end);
}
/**
* Starts the given tasks.
* @param start start index
* @param end end index (including)
*/
public void startTasks(int start, int end) {
for (int i=start; i<=end; i++) {
Task t = tasks.get(i);
t.start();
fireTableCellUpdated(i, 1);
fireTableCellUpdated(i, 2);
}
}
/**
* Stops the given tasks.
* @param start start index
* @param end end index (including)
*/
public void stopTasks(int start, int end) {
for (int i=start; i<=end; i++) {
Task t = tasks.get(i);
t.stop();
fireTableCellUpdated(i, 1);
fireTableCellUpdated(i, 2);
}
}
/**
* Stops all tasks.
*/
public void stopAllTasks() {
Iterator<Task> it = tasks.iterator();
while (it.hasNext()) {
it.next().stop();
}
fireTableDataChanged();
}
/**
* Resets the given tasks.
* @param start index of the first resetted task
* @param end index of the first NOT resetted task (the first task beyond the interval)
*/
public void resetTasks(int start, int end) {
for (int i=start; i<=end; i++) {
Task t = tasks.get(i);
t.setConsumption(0);
fireTableCellUpdated(i, 1);
fireTableCellUpdated(i, 2);
}
}
/**
* Destroys the timer controlling automatic data saving.
*/
public void cancelAutoSave() {
timer.stop();
}
/**
* Returns the absolute path to the directory where LWTT data should be
* saved.
* @return directory path
*/
public static File getDir() {
Properties sys = System.getProperties();
return new File(sys.getProperty("user.home"), ".lwtt");
}
/**
* Returns the absolute path to the file where LWTT data should be
* saved.
* @return absolute file path
*/
public static File getPath() {
return new File(getDir(), "data.xml");
}
/**
* Checks whether the given task is running.
* @param index task index
* @return <CODE>true</CODE> for running task,
* <CODE>false</CODE> otherwise
*/
public boolean isRunning(int index) {
return tasks.get(index).isRunning();
}
/**
* Loads application's data from the file.
*/
public synchronized void loadFromFile() {
tasks.clear();
File file = getPath();
if (!file.exists()) {
Properties props = new Properties();
taskFrame.setStartSettings(props);
return;
}
try {
FileInputStream is = new FileInputStream(file);
Properties props = new Properties();
props.loadFromXML(is);
is.close();
taskFrame.setStartSettings(props);
Iterator<Object> it = props.keySet().iterator();
while (it.hasNext()) {
String key = (String) it.next();
if (key.endsWith(".name")) {
String ids = key.substring(0, key.length() - 5);
String name = props.getProperty(ids + ".name");
String cons = props.getProperty(ids + ".consumption");
String price = props.getProperty(ids + ".price", "1");
try {
int id = Integer.parseInt(ids);
long cn = Long.parseLong(cons);
double pr = Double.parseDouble(price);
Task t = new Task(id, name, cn, pr);
t.setActionListener(this);
tasks.add(t);
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Cannot load data from file (bad format).", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
Collections.sort(tasks);
fireTableDataChanged();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Saves application's data to the file.
*/
public synchronized void saveToFile() {
File dir = getDir();
if (!dir.exists()) {
if (!dir.mkdir()) {
JOptionPane.showMessageDialog(null, "Cannot save data to file (cannot create data directory).", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
}
Properties props = new Properties();
props.setProperty("window.location.x", Integer.toString(taskFrame.getX()));
props.setProperty("window.location.y", Integer.toString(taskFrame.getY()));
props.setProperty("window.size.w", Integer.toString(taskFrame.getWidth()));
props.setProperty("window.size.h", Integer.toString(taskFrame.getHeight()));
for (int i=0; i<tasks.size(); i++) {
Task t = tasks.get(i);
String id = Integer.toString(t.getId());
props.setProperty(id + ".name", t.getName());
props.setProperty(id + ".consumption", Long.toString(t.getConsumption()));
props.setProperty(id + ".price", Double.toString(t.getPrice()));
}
try {
FileOutputStream os = new FileOutputStream(getPath());
props.storeToXML(os, "LWTT task data");
os.close();
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Cannot save data to file (" + e.getLocalizedMessage() + ").", "Error", JOptionPane.ERROR_MESSAGE);
}
}
 
/**
* 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.
* @param e action event
*/
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
if (src == timer) {
saveToFile();
}
else {
int row = tasks.indexOf(src);
fireTableCellUpdated(row, 1);
fireTableCellUpdated(row, 2);
}
}
}
/lwtt/tags/lwtt-1.2.0/cz/aiken/util/lwtt/TaskFrame.java
0,0 → 1,348
/*
* TaskFrame.java - implementation of LWTT main application window
*
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import java.util.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
 
/**
* This class represents the main application frame.
* @author luk
*/
public class TaskFrame extends JFrame implements ListSelectionListener {
private TaskTableModel model = null;
private Properties startSettings = null;
/**
* Time consumption column width
*/
public static final int CONS_COL_WIDTH = 180;
/**
* Creates new form TaskFrame
*/
public TaskFrame() {
model = new TaskTableModel(this);
initComponents();
TableColumn tc = jTable1.getColumnModel().getColumn(1);
tc.setMaxWidth(CONS_COL_WIDTH);
tc.setPreferredWidth(CONS_COL_WIDTH);
jTable1.getSelectionModel().addListSelectionListener(this);
updateButtons();
try {
String xs = startSettings.getProperty("window.location.x");
String ys = startSettings.getProperty("window.location.y");
if (xs != null && ys != null) {
setLocation(Integer.parseInt(xs), Integer.parseInt(ys));
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Cannot load window location (bad format).", "Error", JOptionPane.ERROR_MESSAGE);
}
try {
String ws = startSettings.getProperty("window.size.w");
String hs = startSettings.getProperty("window.size.h");
if (ws != null && hs != null) {
setSize(Integer.parseInt(ws), Integer.parseInt(hs));
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Cannot load window size (bad format).", "Error", JOptionPane.ERROR_MESSAGE);
}
}
/**
* Sets initial (start) settings.
* @param props properties with initial settings
*/
public void setStartSettings(Properties props) {
startSettings = props;
}
/**
* Updates the buttons' state.
*/
private void updateButtons() {
int cnt = jTable1.getSelectedRowCount();
if (cnt == 0) {
startButton.setEnabled(false);
stopButton.setEnabled(false);
removeButton.setEnabled(false);
resetButton.setEnabled(false);
}
else {
int start = jTable1.getSelectedRow();
int end = start + cnt - 1;
removeButton.setEnabled(true);
resetButton.setEnabled(true);
int rcnt = 0;
for (int i=start; i<=end; i++) {
if (model.isRunning(i))
rcnt++;
}
startButton.setEnabled(rcnt < cnt);
stopButton.setEnabled(rcnt > 0);
}
propsButton.setEnabled(cnt == 1);
}
/**
* Updates the buttons according the current selection.
* @param e list selection event
*/
public void valueChanged(ListSelectionEvent e) {
updateButtons();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
 
jSplitPane1 = new javax.swing.JSplitPane();
jPanel1 = new javax.swing.JPanel();
startButton = new javax.swing.JButton();
stopButton = new javax.swing.JButton();
addButton = new javax.swing.JButton();
removeButton = new javax.swing.JButton();
resetButton = new javax.swing.JButton();
propsButton = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
 
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("LWTT");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
TaskFrame.this.windowClosing(evt);
}
});
 
jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
 
jPanel1.setMinimumSize(new java.awt.Dimension(10, 25));
 
startButton.setText("Start");
startButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
startPressed(evt);
}
});
 
stopButton.setText("Stop");
stopButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
stopPressed(evt);
}
});
 
addButton.setText("Add");
addButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addPressed(evt);
}
});
 
removeButton.setText("Remove");
removeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
removePressed(evt);
}
});
 
resetButton.setText("Reset");
resetButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resetPressed(evt);
}
});
 
propsButton.setText("Properties...");
propsButton.setActionCommand("Properties");
propsButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
propsPressed(evt);
}
});
 
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(startButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(stopButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(addButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(removeButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(resetButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(propsButton)
.addContainerGap(152, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(startButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(stopButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(addButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(removeButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(resetButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(propsButton)
);
 
jSplitPane1.setTopComponent(jPanel1);
 
jScrollPane1.setPreferredSize(new java.awt.Dimension(454, 400));
jScrollPane1.setVerifyInputWhenFocusTarget(false);
 
jTable1.setModel(model);
jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
jTable1.setDefaultRenderer(StringBuffer.class, new DefaultTableCellRenderer() {
private Color fg = Color.RED;
private Color bg = new Color(255, 240, 240);
 
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
 
if (JLabel.class.isAssignableFrom(c.getClass())) {
((JLabel) c).setHorizontalAlignment(JLabel.TRAILING);
}
 
if (model.isRunning(row)) {
c.setForeground(fg);
if (!isSelected)
c.setBackground(bg);
}
else {
c.setForeground(Color.BLACK);
if (!isSelected)
c.setBackground(Color.WHITE);
}
 
return c;
}
});
jScrollPane1.setViewportView(jTable1);
 
jSplitPane1.setRightComponent(jScrollPane1);
 
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 572, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
);
 
pack();
}// </editor-fold>//GEN-END:initComponents
 
private void resetPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetPressed
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt > 0)
model.resetTasks(start, start + cnt - 1);
}//GEN-LAST:event_resetPressed
 
private void windowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_windowClosing
model.stopAllTasks();
model.saveToFile();
}//GEN-LAST:event_windowClosing
 
private void removePressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removePressed
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt > 0)
model.removeTasks(start, start + cnt - 1);
}//GEN-LAST:event_removePressed
 
private void addPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPressed
model.addNewTask();
}//GEN-LAST:event_addPressed
 
private void stopPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopPressed
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt > 0) {
model.stopTasks(start, start + cnt - 1);
updateButtons();
}
}//GEN-LAST:event_stopPressed
 
private void startPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startPressed
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt > 0) {
model.startTasks(start, start + cnt - 1);
updateButtons();
}
}//GEN-LAST:event_startPressed
 
private void propsPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_propsPressed
TaskPropetiesDialog d = new TaskPropetiesDialog(this, true);
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt == 1) {
Task t = model.getTask(start);
d.setPrice(t.getPrice());
d.setVisible(true);
if (d.getReturnStatus() == TaskPropetiesDialog.RET_OK) {
t.setPrice(d.getPrice());
model.fireTableCellUpdated(start, 2);
}
}
}//GEN-LAST:event_propsPressed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addButton;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JTable jTable1;
private javax.swing.JButton propsButton;
private javax.swing.JButton removeButton;
private javax.swing.JButton resetButton;
private javax.swing.JButton startButton;
private javax.swing.JButton stopButton;
// End of variables declaration//GEN-END:variables
}
/lwtt/tags/lwtt-1.2.0/cz/aiken/util/lwtt/Main.java
0,0 → 1,62
/*
* Main.java - main LWTT class
*
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import javax.swing.*;
 
/**
* This class represents the application itself. It creates the main
* application frame and makes it visible.
* @author luk
*/
public class Main implements Runnable {
/**
* Main class constructor.
*/
public Main() {
}
/**
* Creates the main frame and makes it visible. Then it hands control
* on the main application loop.
*
* <I>This method may be called only by the event-dispatching thread.</I>
*/
public void run() {
TaskFrame tf = new TaskFrame();
tf.setVisible(true);
}
/**
* The main application method. It starts the application by
* scheduling the initialization for the event-dispatching thread.
* @param args the command line arguments (currently ignored)
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Main());
}
}
/lwtt/tags/lwtt-1.2.0/COPYING
0,0 → 1,339
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
 
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
 
Preamble
 
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
 
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
 
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
 
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
 
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
 
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
 
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
 
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
 
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
 
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
 
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
 
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
 
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
 
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
 
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
 
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
 
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
 
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
 
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
 
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
 
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
 
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
 
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
 
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
 
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
 
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
 
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
 
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
 
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
 
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
 
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
 
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
 
NO WARRANTY
 
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
 
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
 
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
 
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
 
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
 
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
Also add information on how to contact you by electronic and paper mail.
 
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
 
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
 
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
 
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
 
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
 
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
 
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
/lwtt/tags/lwtt-1.1.1/cz/aiken/util/lwtt/TaskTableModel.java
0,0 → 1,364
/*
* TaskTableModel.java - implementation of tracked tasks table model
*
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
import java.io.*;
import java.awt.event.*;
import java.math.*;
import java.text.*;
 
/**
* This class represents the task table model.
* @author luk
*/
public class TaskTableModel extends AbstractTableModel implements ActionListener {
private ArrayList<Task> tasks = new ArrayList<Task>();
private javax.swing.Timer timer = new javax.swing.Timer(300000, this);
private MessageFormat timeFormat = new MessageFormat("{0,number}:{1,number,00}");
private TaskFrame taskFrame = null;
/**
* Creates a new instance of TaskTableModel
* @param tf task frame instance
*/
public TaskTableModel(TaskFrame tf) {
taskFrame = tf;
loadFromFile();
timer.start();
}
 
/**
* Returns the value at the given coordinates.
* @param rowIndex row index
* @param columnIndex column index
* @return appropriate cell value; if the arguments are invalid
* it returns <CODE>null</CODE>
*/
public Object getValueAt(int rowIndex, int columnIndex) {
switch (columnIndex) {
case 0:
return tasks.get(rowIndex).getName();
case 1:
long mins = tasks.get(rowIndex).getConsumption() / 60000;
BigDecimal hm[] = new BigDecimal((int) mins).divideAndRemainder(new BigDecimal(60));
return timeFormat.format(hm);
default: return null;
}
}
 
/**
* Returns the row count.
* @return row count
*/
public int getRowCount() {
return tasks.size();
}
 
/**
* Returns the column count (currently 2).
* @return column count
*/
public int getColumnCount() {
return 2;
}
 
/**
* Sets a new value of the given cell. If at least one of the
* coordinates is invalid it does nothing.
* @param aValue new value
* @param rowIndex row index
* @param columnIndex column index
*/
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
switch (columnIndex) {
case 0: tasks.get(rowIndex).setName((String) aValue);
break;
}
}
 
/**
* Returns the name of the given column.
* @param column column index
* @return column name; if the index is invalid it returns an empty
* string
*/
@Override
public String getColumnName(int column) {
switch (column) {
case 0: return "Task name";
case 1: return "Time consumption [h:min]";
default: return "";
}
}
 
/**
* Returns the class of the given column.
* @param columnIndex column index
* @return appropriate class object; if the column index is invalid
* it returns <CODE>Void.class</CODE>.
*/
@Override
public Class<?> getColumnClass(int columnIndex) {
switch (columnIndex) {
case 0: return String.class;
case 1: return StringBuffer.class;
default: return Void.class;
}
}
 
/**
* Checks whether the given cell is editable.
* @param rowIndex row index
* @param columnIndex column index
* @return <CODE>true</CODE> for the first column (index 0),
* <CODE>false</CODE> otherwise
*/
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == 0;
}
/**
* Creates a new task.
*/
public void addNewTask() {
Task t = new Task();
t.setActionListener(this);
tasks.add(t);
int row = tasks.size()-1;
fireTableRowsInserted(row, row);
}
/**
* Removes the given tasks.
* @param start start index
* @param end end index (including)
*/
public void removeTasks(int start, int end) {
for (int i=end; i>=start; i--) {
Task t = tasks.remove(i);
t.stop();
t.setActionListener(null);
}
fireTableRowsDeleted(start, end);
}
/**
* Starts the given tasks.
* @param start start index
* @param end end index (including)
*/
public void startTasks(int start, int end) {
for (int i=start; i<=end; i++) {
Task t = tasks.get(i);
t.start();
fireTableCellUpdated(i, 1);
}
}
/**
* Stops the given tasks.
* @param start start index
* @param end end index (including)
*/
public void stopTasks(int start, int end) {
for (int i=start; i<=end; i++) {
Task t = tasks.get(i);
t.stop();
fireTableCellUpdated(i, 1);
}
}
/**
* Stops all tasks.
*/
public void stopAllTasks() {
Iterator<Task> it = tasks.iterator();
while (it.hasNext()) {
it.next().stop();
}
fireTableDataChanged();
}
/**
* Resets the given tasks.
* @param start index of the first resetted task
* @param end index of the first NOT resetted task (the first task beyond the interval)
*/
public void resetTasks(int start, int end) {
for (int i=start; i<=end; i++) {
Task t = tasks.get(i);
t.setConsumption(0);
fireTableCellUpdated(i, 1);
}
}
/**
* Destroys the timer controlling automatic data saving.
*/
public void cancelAutoSave() {
timer.stop();
}
/**
* Returns the absolute path to the directory where LWTT data should be
* saved.
* @return directory path
*/
public static File getDir() {
Properties sys = System.getProperties();
return new File(sys.getProperty("user.home"), ".lwtt");
}
/**
* Returns the absolute path to the file where LWTT data should be
* saved.
* @return absolute file path
*/
public static File getPath() {
return new File(getDir(), "data.xml");
}
/**
* Checks whether the given task is running.
* @param index task index
* @return <CODE>true</CODE> for running task,
* <CODE>false</CODE> otherwise
*/
public boolean isRunning(int index) {
return tasks.get(index).isRunning();
}
/**
* Loads application's data from the file.
*/
public synchronized void loadFromFile() {
tasks.clear();
File file = getPath();
if (!file.exists()) {
Properties props = new Properties();
taskFrame.setStartSettings(props);
return;
}
try {
FileInputStream is = new FileInputStream(file);
Properties props = new Properties();
props.loadFromXML(is);
is.close();
taskFrame.setStartSettings(props);
Iterator<Object> it = props.keySet().iterator();
while (it.hasNext()) {
String key = (String) it.next();
if (key.endsWith(".name")) {
String ids = key.substring(0, key.length() - 5);
String name = props.getProperty(ids + ".name");
String cons = props.getProperty(ids + ".consumption");
try {
int id = Integer.parseInt(ids);
long cn = Long.parseLong(cons);
Task t = new Task(id, name, cn);
t.setActionListener(this);
tasks.add(t);
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Cannot load data from file (bad format).", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
Collections.sort(tasks);
fireTableDataChanged();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Saves application's data to the file.
*/
public synchronized void saveToFile() {
File dir = getDir();
if (!dir.exists()) {
if (!dir.mkdir()) {
JOptionPane.showMessageDialog(null, "Cannot save data to file (cannot create data directory).", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
}
Properties props = new Properties();
props.setProperty("window.location.x", Integer.toString(taskFrame.getX()));
props.setProperty("window.location.y", Integer.toString(taskFrame.getY()));
props.setProperty("window.size.w", Integer.toString(taskFrame.getWidth()));
props.setProperty("window.size.h", Integer.toString(taskFrame.getHeight()));
for (int i=0; i<tasks.size(); i++) {
Task t = tasks.get(i);
String id = Integer.toString(t.getId());
props.setProperty(id + ".name", t.getName());
props.setProperty(id + ".consumption", Long.toString(t.getConsumption()));
}
try {
FileOutputStream os = new FileOutputStream(getPath());
props.storeToXML(os, "LWTT task data");
os.close();
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Cannot save data to file (" + e.getLocalizedMessage() + ").", "Error", JOptionPane.ERROR_MESSAGE);
}
}
 
/**
* 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.
* @param e action event
*/
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
if (src == timer) {
saveToFile();
}
else {
int row = tasks.indexOf(src);
fireTableCellUpdated(row, 1);
}
}
}
/lwtt/tags/lwtt-1.1.1/cz/aiken/util/lwtt/TaskFrame.form
0,0 → 1,159
<?xml version="1.0" encoding="UTF-8" ?>
 
<Form version="1.3" maxVersion="1.3" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="title" type="java.lang.String" value="LWTT"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<Events>
<EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="windowClosing"/>
</Events>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
 
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jSplitPane1" alignment="1" pref="572" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jSplitPane1" pref="441" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JSplitPane" name="jSplitPane1">
<Properties>
<Property name="orientation" type="int" value="0"/>
</Properties>
 
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanel1">
<Properties>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[10, 25]"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="top"/>
</Constraint>
</Constraints>
 
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="startButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="stopButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="addButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="removeButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="resetButton" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="251" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="startButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="stopButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="addButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="removeButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="resetButton" alignment="3" pref="25" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="startButton">
<Properties>
<Property name="text" type="java.lang.String" value="Start"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="startPressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="stopButton">
<Properties>
<Property name="text" type="java.lang.String" value="Stop"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="stopPressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="addButton">
<Properties>
<Property name="text" type="java.lang.String" value="Add"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="addPressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="removeButton">
<Properties>
<Property name="text" type="java.lang.String" value="Remove"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="removePressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="resetButton">
<Properties>
<Property name="text" type="java.lang.String" value="Reset"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="resetPressed"/>
</Events>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<Properties>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[454, 400]"/>
</Property>
<Property name="verifyInputWhenFocusTarget" type="boolean" value="false"/>
</Properties>
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="right"/>
</Constraint>
</Constraints>
 
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="jTable1">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="model" type="code"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_InitCodePost" type="java.lang.String" value="jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);&#xa;jTable1.setDefaultRenderer(StringBuffer.class, new DefaultTableCellRenderer() {&#xa; private Color fg = Color.RED;&#xa; private Color bg = new Color(255, 240, 240);&#xa; &#xa; public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {&#xa; Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);&#xa; &#xa; if (JLabel.class.isAssignableFrom(c.getClass())) {&#xa; ((JLabel) c).setHorizontalAlignment(JLabel.TRAILING);&#xa; }&#xa; &#xa; if (model.isRunning(row)) {&#xa; c.setForeground(fg);&#xa; if (!isSelected)&#xa; c.setBackground(bg);&#xa; }&#xa; else {&#xa; c.setForeground(Color.BLACK);&#xa; if (!isSelected)&#xa; c.setBackground(Color.WHITE);&#xa; }&#xa; &#xa; return c;&#xa; }&#xa;});"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Form>
/lwtt/tags/lwtt-1.1.1/cz/aiken/util/lwtt/Task.java
0,0 → 1,202
/*
* Task.java - implementation of tracked task
*
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import javax.swing.Timer;
import java.awt.event.*;
 
/**
* This class represents a tracked task.
* @author luk
*/
public class Task implements ActionListener, Comparable<Task> {
private int id;
private String name = "Unnamed task";
private long consumption = 0L;
private Timer timer = null;
/**
* period for updating time values [ms]
*/
public static final int PERIOD = 10000;
private ActionListener listener = null;
private static int nextId = 0;
/**
* Generates a new task identifier.
* @return new identifier
*/
public static int getNewId() {
int id = nextId;
nextId++;
return id;
}
/**
* Creates a new instance of Task
*/
public Task() {
id = getNewId();
}
/**
* Creates an instance for a task which has been already tracked.
* @param id task identifier
* @param name task name
* @param consumption up to now time consumption
*/
public Task(int id, String name, long consumption) {
this.id = id;
this.name = name;
this.consumption = consumption;
if (id >= nextId)
nextId = id + 1;
}
/**
* Sets the listener where action events should be passed to.
* @param al action listener
*/
public void setActionListener(ActionListener al) {
listener = al;
}
/**
* Returns the task identifier.
* @return task identifier
*/
public int getId() {
return id;
}
/**
* Returns the task name.
* @return task name
*/
public String getName() {
return name;
}
/**
* Sets the task name.
* @param name new task name
*/
public void setName(String name) {
this.name = name;
}
/**
* Returns the current value of cumulative consumption [ms].
* @return current cumulative consumption
*/
public long getConsumption() {
return consumption;
}
/**
* Sets the task cumulative time consumption [ms].
* @param consumption new time consumption value
*/
public void setConsumption(long consumption) {
this.consumption = consumption;
}
/**
* Converts the instance to the string representation. It contains
* the task name and consumption.
* @return string representation
*/
@Override
public String toString() {
return name + "(" + Long.toString(consumption) + ")";
}
/**
* Starts tracking of this task.
*/
public void start() {
if (timer != null)
return;
timer = new Timer(PERIOD, this);
timer.start();
}
/**
* Stops tracking of this task.
*/
public void stop() {
if (timer == null)
return;
timer.stop();
timer = null;
}
/**
* Checks whether the task is running.
* @return <CODE>true</CODE> if running, <CODE>false</CODE> otherwise
*/
public boolean isRunning() {
return timer != null;
}
/**
* Updates the time consumption value. Then it creates a new action event
* and passes it to the assigned listener (if any).
* @param e action event
*/
public void actionPerformed(ActionEvent e) {
consumption += PERIOD;
ActionEvent e2 = new ActionEvent(this, id, "");
if (listener != null)
listener.actionPerformed(e2);
}
 
/**
* Compares this task to another one. The comparison result is based
* on task identifiers.
* @param t another task
* @return 1 if this class' id is greater then the given class' id,
* -1 if both ids are equal and 0 otherwise
*/
public int compareTo(Task t) {
if (t == null)
throw new NullPointerException("cannot compare to null pointer");
if (id > t.getId())
return 1;
else if (id == t.getId())
return 0;
else
return -1;
}
}
/lwtt/tags/lwtt-1.1.1/cz/aiken/util/lwtt/Main.java
0,0 → 1,62
/*
* Main.java - main LWTT class
*
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import javax.swing.*;
 
/**
* This class represents the application itself. It creates the main
* application frame and makes it visible.
* @author luk
*/
public class Main implements Runnable {
/**
* Main class constructor.
*/
public Main() {
}
/**
* Creates the main frame and makes it visible. Then it hands control
* on the main application loop.
*
* <I>This method may be called only by the event-dispatching thread.</I>
*/
public void run() {
TaskFrame tf = new TaskFrame();
tf.setVisible(true);
}
/**
* The main application method. It starts the application by
* scheduling the initialization for the event-dispatching thread.
* @param args the command line arguments (currently ignored)
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Main());
}
}
/lwtt/tags/lwtt-1.1.1/cz/aiken/util/lwtt/TaskFrame.java
0,0 → 1,318
/*
* TaskFrame.java - implementation of LWTT main application window
*
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import java.util.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
 
/**
* This class represents the main application frame.
* @author luk
*/
public class TaskFrame extends JFrame implements ListSelectionListener {
private TaskTableModel model = null;
private Properties startSettings = null;
/**
* Time consumption column width
*/
public static final int CONS_COL_WIDTH = 180;
/**
* Creates new form TaskFrame
*/
public TaskFrame() {
model = new TaskTableModel(this);
initComponents();
TableColumn tc = jTable1.getColumnModel().getColumn(1);
tc.setMaxWidth(CONS_COL_WIDTH);
tc.setPreferredWidth(CONS_COL_WIDTH);
jTable1.getSelectionModel().addListSelectionListener(this);
updateButtons();
try {
String xs = startSettings.getProperty("window.location.x");
String ys = startSettings.getProperty("window.location.y");
if (xs != null && ys != null) {
setLocation(Integer.parseInt(xs), Integer.parseInt(ys));
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Cannot load window location (bad format).", "Error", JOptionPane.ERROR_MESSAGE);
}
try {
String ws = startSettings.getProperty("window.size.w");
String hs = startSettings.getProperty("window.size.h");
if (ws != null && hs != null) {
setSize(Integer.parseInt(ws), Integer.parseInt(hs));
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Cannot load window size (bad format).", "Error", JOptionPane.ERROR_MESSAGE);
}
}
/**
* Sets initial (start) settings.
* @param props properties with initial settings
*/
public void setStartSettings(Properties props) {
startSettings = props;
}
/**
* Updates the buttons' state.
*/
private void updateButtons() {
int cnt = jTable1.getSelectedRowCount();
if (cnt == 0) {
startButton.setEnabled(false);
stopButton.setEnabled(false);
removeButton.setEnabled(false);
resetButton.setEnabled(false);
}
else {
int start = jTable1.getSelectedRow();
int end = start + cnt - 1;
removeButton.setEnabled(true);
resetButton.setEnabled(true);
int rcnt = 0;
for (int i=start; i<=end; i++) {
if (model.isRunning(i))
rcnt++;
}
startButton.setEnabled(rcnt < cnt);
stopButton.setEnabled(rcnt > 0);
}
}
/**
* Updates the buttons according the current selection.
* @param e list selection event
*/
public void valueChanged(ListSelectionEvent e) {
updateButtons();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
 
jSplitPane1 = new javax.swing.JSplitPane();
jPanel1 = new javax.swing.JPanel();
startButton = new javax.swing.JButton();
stopButton = new javax.swing.JButton();
addButton = new javax.swing.JButton();
removeButton = new javax.swing.JButton();
resetButton = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
 
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("LWTT");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
TaskFrame.this.windowClosing(evt);
}
});
 
jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
 
jPanel1.setMinimumSize(new java.awt.Dimension(10, 25));
 
startButton.setText("Start");
startButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
startPressed(evt);
}
});
 
stopButton.setText("Stop");
stopButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
stopPressed(evt);
}
});
 
addButton.setText("Add");
addButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addPressed(evt);
}
});
 
removeButton.setText("Remove");
removeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
removePressed(evt);
}
});
 
resetButton.setText("Reset");
resetButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resetPressed(evt);
}
});
 
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(startButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(stopButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(addButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(removeButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(resetButton)
.addContainerGap(251, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(startButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(stopButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(addButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(removeButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(resetButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
);
 
jSplitPane1.setTopComponent(jPanel1);
 
jScrollPane1.setPreferredSize(new java.awt.Dimension(454, 400));
jScrollPane1.setVerifyInputWhenFocusTarget(false);
 
jTable1.setModel(model);
jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
jTable1.setDefaultRenderer(StringBuffer.class, new DefaultTableCellRenderer() {
private Color fg = Color.RED;
private Color bg = new Color(255, 240, 240);
 
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
 
if (JLabel.class.isAssignableFrom(c.getClass())) {
((JLabel) c).setHorizontalAlignment(JLabel.TRAILING);
}
 
if (model.isRunning(row)) {
c.setForeground(fg);
if (!isSelected)
c.setBackground(bg);
}
else {
c.setForeground(Color.BLACK);
if (!isSelected)
c.setBackground(Color.WHITE);
}
 
return c;
}
});
jScrollPane1.setViewportView(jTable1);
 
jSplitPane1.setRightComponent(jScrollPane1);
 
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 572, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
);
 
pack();
}// </editor-fold>//GEN-END:initComponents
 
private void resetPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetPressed
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt > 0)
model.resetTasks(start, start + cnt - 1);
}//GEN-LAST:event_resetPressed
 
private void windowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_windowClosing
model.stopAllTasks();
model.saveToFile();
}//GEN-LAST:event_windowClosing
 
private void removePressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removePressed
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt > 0)
model.removeTasks(start, start + cnt - 1);
}//GEN-LAST:event_removePressed
 
private void addPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPressed
model.addNewTask();
}//GEN-LAST:event_addPressed
 
private void stopPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopPressed
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt > 0) {
model.stopTasks(start, start + cnt - 1);
updateButtons();
}
}//GEN-LAST:event_stopPressed
 
private void startPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startPressed
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt > 0) {
model.startTasks(start, start + cnt - 1);
updateButtons();
}
}//GEN-LAST:event_startPressed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addButton;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JTable jTable1;
private javax.swing.JButton removeButton;
private javax.swing.JButton resetButton;
private javax.swing.JButton startButton;
private javax.swing.JButton stopButton;
// End of variables declaration//GEN-END:variables
}
/lwtt/tags/lwtt-1.1.1/COPYING
0,0 → 1,339
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
 
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
 
Preamble
 
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
 
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
 
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
 
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
 
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
 
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
 
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
 
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
 
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
 
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
 
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
 
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
 
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
 
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
 
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
 
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
 
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
 
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
 
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
 
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
 
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
 
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
 
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
 
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
 
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
 
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
 
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
 
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
 
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
 
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
 
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
 
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
 
NO WARRANTY
 
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
 
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
 
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
 
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
 
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
 
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
Also add information on how to contact you by electronic and paper mail.
 
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
 
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
 
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
 
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
 
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
 
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
 
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
/lwtt/tags/lwtt-1.1.0/cz/aiken/util/lwtt/TaskFrame.form
0,0 → 1,159
<?xml version="1.0" encoding="UTF-8" ?>
 
<Form version="1.3" maxVersion="1.3" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="title" type="java.lang.String" value="LWTT"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<Events>
<EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="windowClosing"/>
</Events>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
 
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jSplitPane1" alignment="1" pref="572" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jSplitPane1" pref="441" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JSplitPane" name="jSplitPane1">
<Properties>
<Property name="orientation" type="int" value="0"/>
</Properties>
 
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanel1">
<Properties>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[10, 25]"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="top"/>
</Constraint>
</Constraints>
 
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="startButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="stopButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="addButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="removeButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="resetButton" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="251" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="startButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="stopButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="addButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="removeButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="resetButton" alignment="3" pref="25" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="startButton">
<Properties>
<Property name="text" type="java.lang.String" value="Start"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="startPressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="stopButton">
<Properties>
<Property name="text" type="java.lang.String" value="Stop"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="stopPressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="addButton">
<Properties>
<Property name="text" type="java.lang.String" value="Add"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="addPressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="removeButton">
<Properties>
<Property name="text" type="java.lang.String" value="Remove"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="removePressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="resetButton">
<Properties>
<Property name="text" type="java.lang.String" value="Reset"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="resetPressed"/>
</Events>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<Properties>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[454, 400]"/>
</Property>
<Property name="verifyInputWhenFocusTarget" type="boolean" value="false"/>
</Properties>
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="right"/>
</Constraint>
</Constraints>
 
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="jTable1">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="model" type="code"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_InitCodePost" type="java.lang.String" value="jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);&#xa;jTable1.setDefaultRenderer(StringBuffer.class, new DefaultTableCellRenderer() {&#xa; private Color fg = Color.RED;&#xa; private Color bg = new Color(255, 240, 240);&#xa; &#xa; public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {&#xa; Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);&#xa; &#xa; if (JLabel.class.isAssignableFrom(c.getClass())) {&#xa; ((JLabel) c).setHorizontalAlignment(JLabel.TRAILING);&#xa; }&#xa; &#xa; if (model.isRunning(row)) {&#xa; c.setForeground(fg);&#xa; if (!isSelected)&#xa; c.setBackground(bg);&#xa; }&#xa; else {&#xa; c.setForeground(Color.BLACK);&#xa; if (!isSelected)&#xa; c.setBackground(Color.WHITE);&#xa; }&#xa; &#xa; return c;&#xa; }&#xa;});"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Form>
/lwtt/tags/lwtt-1.1.0/cz/aiken/util/lwtt/Task.java
0,0 → 1,202
/*
* Task.java - implementation of tracked task
*
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import javax.swing.Timer;
import java.awt.event.*;
 
/**
* This class represents a tracked task.
* @author luk
*/
public class Task implements ActionListener, Comparable<Task> {
private int id;
private String name = "Unnamed task";
private long consumption = 0L;
private Timer timer = null;
/**
* period for updating time values [ms]
*/
public static final int PERIOD = 10000;
private ActionListener listener = null;
private static int nextId = 0;
/**
* Generates a new task identifier.
* @return new identifier
*/
public static int getNewId() {
int id = nextId;
nextId++;
return id;
}
/**
* Creates a new instance of Task
*/
public Task() {
id = getNewId();
}
/**
* Creates an instance for a task which has been already tracked.
* @param id task identifier
* @param name task name
* @param consumption up to now time consumption
*/
public Task(int id, String name, long consumption) {
this.id = id;
this.name = name;
this.consumption = consumption;
if (id >= nextId)
nextId = id + 1;
}
/**
* Sets the listener where action events should be passed to.
* @param al action listener
*/
public void setActionListener(ActionListener al) {
listener = al;
}
/**
* Returns the task identifier.
* @return task identifier
*/
public int getId() {
return id;
}
/**
* Returns the task name.
* @return task name
*/
public String getName() {
return name;
}
/**
* Sets the task name.
* @param name new task name
*/
public void setName(String name) {
this.name = name;
}
/**
* Returns the current value of cumulative consumption [ms].
* @return current cumulative consumption
*/
public long getConsumption() {
return consumption;
}
/**
* Sets the task cumulative time consumption [ms].
* @param consumption new time consumption value
*/
public void setConsumption(long consumption) {
this.consumption = consumption;
}
/**
* Converts the instance to the string representation. It contains
* the task name and consumption.
* @return string representation
*/
@Override
public String toString() {
return name + "(" + Long.toString(consumption) + ")";
}
/**
* Starts tracking of this task.
*/
public void start() {
if (timer != null)
return;
timer = new Timer(PERIOD, this);
timer.start();
}
/**
* Stops tracking of this task.
*/
public void stop() {
if (timer == null)
return;
timer.stop();
timer = null;
}
/**
* Checks whether the task is running.
* @return <CODE>true</CODE> if running, <CODE>false</CODE> otherwise
*/
public boolean isRunning() {
return timer != null;
}
/**
* Updates the time consumption value. Then it creates a new action event
* and passes it to the assigned listener (if any).
* @param e action event
*/
public void actionPerformed(ActionEvent e) {
consumption += PERIOD;
ActionEvent e2 = new ActionEvent(this, id, "");
if (listener != null)
listener.actionPerformed(e2);
}
 
/**
* Compares this task to another one. The comparison result is based
* on task identifiers.
* @param t another task
* @return 1 if this class' id is greater then the given class' id,
* -1 if both ids are equal and 0 otherwise
*/
public int compareTo(Task t) {
if (t == null)
throw new NullPointerException("cannot compare to null pointer");
if (id > t.getId())
return 1;
else if (id == t.getId())
return 0;
else
return -1;
}
}
/lwtt/tags/lwtt-1.1.0/cz/aiken/util/lwtt/Main.java
0,0 → 1,62
/*
* Main.java - main LWTT class
*
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import javax.swing.*;
 
/**
* This class represents the application itself. It creates the main
* application frame and makes it visible.
* @author luk
*/
public class Main implements Runnable {
/**
* Main class constructor.
*/
public Main() {
}
/**
* Creates the main frame and makes it visible. Then it hands control
* on the main application loop.
*
* <I>This method may be called only by the event-dispatching thread.</I>
*/
public void run() {
TaskFrame tf = new TaskFrame();
tf.setVisible(true);
}
/**
* The main application method. It starts the application by
* scheduling the initialization for the event-dispatching thread.
* @param args the command line arguments (currently ignored)
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Main());
}
}
/lwtt/tags/lwtt-1.1.0/cz/aiken/util/lwtt/TaskTableModel.java
0,0 → 1,361
/*
* TaskTableModel.java - implementation of tracked tasks table model
*
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
import java.io.*;
import java.awt.event.*;
import java.math.*;
import java.text.*;
 
/**
* This class represents the task table model.
* @author luk
*/
public class TaskTableModel extends AbstractTableModel implements ActionListener {
private ArrayList<Task> tasks = new ArrayList<Task>();
private javax.swing.Timer timer = new javax.swing.Timer(300000, this);
private MessageFormat timeFormat = new MessageFormat("{0,number}:{1,number,00}");
private TaskFrame taskFrame = null;
/**
* Creates a new instance of TaskTableModel
* @param tf task frame instance
*/
public TaskTableModel(TaskFrame tf) {
taskFrame = tf;
loadFromFile();
timer.start();
}
 
/**
* Returns the value at the given coordinates.
* @param rowIndex row index
* @param columnIndex column index
* @return appropriate cell value; if the arguments are invalid
* it returns <CODE>null</CODE>
*/
public Object getValueAt(int rowIndex, int columnIndex) {
switch (columnIndex) {
case 0:
return tasks.get(rowIndex).getName();
case 1:
long mins = tasks.get(rowIndex).getConsumption() / 60000;
BigDecimal hm[] = new BigDecimal((int) mins).divideAndRemainder(new BigDecimal(60));
return timeFormat.format(hm);
default: return null;
}
}
 
/**
* Returns the row count.
* @return row count
*/
public int getRowCount() {
return tasks.size();
}
 
/**
* Returns the column count (currently 2).
* @return column count
*/
public int getColumnCount() {
return 2;
}
 
/**
* Sets a new value of the given cell. If at least one of the
* coordinates is invalid it does nothing.
* @param aValue new value
* @param rowIndex row index
* @param columnIndex column index
*/
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
switch (columnIndex) {
case 0: tasks.get(rowIndex).setName((String) aValue);
break;
}
}
 
/**
* Returns the name of the given column.
* @param column column index
* @return column name; if the index is invalid it returns an empty
* string
*/
@Override
public String getColumnName(int column) {
switch (column) {
case 0: return "Task name";
case 1: return "Time consumption [h:min]";
default: return "";
}
}
 
/**
* Returns the class of the given column.
* @param columnIndex column index
* @return appropriate class object; if the column index is invalid
* it returns <CODE>Void.class</CODE>.
*/
@Override
public Class<?> getColumnClass(int columnIndex) {
switch (columnIndex) {
case 0: return String.class;
case 1: return StringBuffer.class;
default: return Void.class;
}
}
 
/**
* Checks whether the given cell is editable.
* @param rowIndex row index
* @param columnIndex column index
* @return <CODE>true</CODE> for the first column (index 0),
* <CODE>false</CODE> otherwise
*/
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == 0;
}
/**
* Creates a new task.
*/
public void addNewTask() {
Task t = new Task();
t.setActionListener(this);
tasks.add(t);
int row = tasks.size()-1;
fireTableRowsInserted(row, row);
}
/**
* Removes the given tasks.
* @param start start index
* @param end end index (including)
*/
public void removeTasks(int start, int end) {
for (int i=end; i>=start; i--) {
Task t = tasks.remove(i);
t.stop();
t.setActionListener(null);
}
fireTableRowsDeleted(start, end);
}
/**
* Starts the given tasks.
* @param start start index
* @param end end index (including)
*/
public void startTasks(int start, int end) {
for (int i=start; i<=end; i++) {
Task t = tasks.get(i);
t.start();
fireTableCellUpdated(i, 1);
}
}
/**
* Stops the given tasks.
* @param start start index
* @param end end index (including)
*/
public void stopTasks(int start, int end) {
for (int i=start; i<=end; i++) {
Task t = tasks.get(i);
t.stop();
fireTableCellUpdated(i, 1);
}
}
/**
* Stops all tasks.
*/
public void stopAllTasks() {
Iterator<Task> it = tasks.iterator();
while (it.hasNext()) {
it.next().stop();
}
fireTableDataChanged();
}
/**
* Resets the given tasks.
* @param start index of the first resetted task
* @param end index of the first NOT resetted task (the first task beyond the interval)
*/
public void resetTasks(int start, int end) {
for (int i=start; i<=end; i++) {
Task t = tasks.get(i);
t.setConsumption(0);
fireTableCellUpdated(i, 1);
}
}
/**
* Destroys the timer controlling automatic data saving.
*/
public void cancelAutoSave() {
timer.stop();
}
/**
* Returns the absolute path to the directory where LWTT data should be
* saved.
* @return directory path
*/
public static File getDir() {
Properties sys = System.getProperties();
return new File(sys.getProperty("user.home"), ".lwtt");
}
/**
* Returns the absolute path to the file where LWTT data should be
* saved.
* @return absolute file path
*/
public static File getPath() {
return new File(getDir(), "data.xml");
}
/**
* Checks whether the given task is running.
* @param index task index
* @return <CODE>true</CODE> for running task,
* <CODE>false</CODE> otherwise
*/
public boolean isRunning(int index) {
return tasks.get(index).isRunning();
}
/**
* Loads application's data from the file.
*/
public synchronized void loadFromFile() {
tasks.clear();
File file = getPath();
if (!file.exists())
return;
try {
FileInputStream is = new FileInputStream(file);
Properties props = new Properties();
props.loadFromXML(is);
is.close();
taskFrame.setStartSettings(props);
Iterator<Object> it = props.keySet().iterator();
while (it.hasNext()) {
String key = (String) it.next();
if (key.endsWith(".name")) {
String ids = key.substring(0, key.length() - 5);
String name = props.getProperty(ids + ".name");
String cons = props.getProperty(ids + ".consumption");
try {
int id = Integer.parseInt(ids);
long cn = Long.parseLong(cons);
Task t = new Task(id, name, cn);
t.setActionListener(this);
tasks.add(t);
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Cannot load data from file (bad format).", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
Collections.sort(tasks);
fireTableDataChanged();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Saves application's data to the file.
*/
public synchronized void saveToFile() {
File dir = getDir();
if (!dir.exists()) {
if (!dir.mkdir()) {
JOptionPane.showMessageDialog(null, "Cannot save data to file (cannot create data directory).", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
}
Properties props = new Properties();
props.setProperty("window.location.x", Integer.toString(taskFrame.getX()));
props.setProperty("window.location.y", Integer.toString(taskFrame.getY()));
props.setProperty("window.size.w", Integer.toString(taskFrame.getWidth()));
props.setProperty("window.size.h", Integer.toString(taskFrame.getHeight()));
for (int i=0; i<tasks.size(); i++) {
Task t = tasks.get(i);
String id = Integer.toString(t.getId());
props.setProperty(id + ".name", t.getName());
props.setProperty(id + ".consumption", Long.toString(t.getConsumption()));
}
try {
FileOutputStream os = new FileOutputStream(getPath());
props.storeToXML(os, "LWTT task data");
os.close();
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Cannot save data to file (" + e.getLocalizedMessage() + ").", "Error", JOptionPane.ERROR_MESSAGE);
}
}
 
/**
* 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.
* @param e action event
*/
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
if (src == timer) {
saveToFile();
}
else {
int row = tasks.indexOf(src);
fireTableCellUpdated(row, 1);
}
}
}
/lwtt/tags/lwtt-1.1.0/cz/aiken/util/lwtt/TaskFrame.java
0,0 → 1,318
/*
* TaskFrame.java - implementation of LWTT main application window
*
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import java.util.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
 
/**
* This class represents the main application frame.
* @author luk
*/
public class TaskFrame extends JFrame implements ListSelectionListener {
private TaskTableModel model = null;
private Properties startSettings = null;
/**
* Time consumption column width
*/
public static final int CONS_COL_WIDTH = 180;
/**
* Creates new form TaskFrame
*/
public TaskFrame() {
model = new TaskTableModel(this);
initComponents();
TableColumn tc = jTable1.getColumnModel().getColumn(1);
tc.setMaxWidth(CONS_COL_WIDTH);
tc.setPreferredWidth(CONS_COL_WIDTH);
jTable1.getSelectionModel().addListSelectionListener(this);
updateButtons();
try {
String xs = startSettings.getProperty("window.location.x");
String ys = startSettings.getProperty("window.location.y");
if (xs != null && ys != null) {
setLocation(Integer.parseInt(xs), Integer.parseInt(ys));
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Cannot load window location (bad format).", "Error", JOptionPane.ERROR_MESSAGE);
}
try {
String ws = startSettings.getProperty("window.size.w");
String hs = startSettings.getProperty("window.size.h");
if (ws != null && hs != null) {
setSize(Integer.parseInt(ws), Integer.parseInt(hs));
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Cannot load window size (bad format).", "Error", JOptionPane.ERROR_MESSAGE);
}
}
/**
* Sets initial (start) settings.
* @param props properties with initial settings
*/
public void setStartSettings(Properties props) {
startSettings = props;
}
/**
* Updates the buttons' state.
*/
private void updateButtons() {
int cnt = jTable1.getSelectedRowCount();
if (cnt == 0) {
startButton.setEnabled(false);
stopButton.setEnabled(false);
removeButton.setEnabled(false);
resetButton.setEnabled(false);
}
else {
int start = jTable1.getSelectedRow();
int end = start + cnt - 1;
removeButton.setEnabled(true);
resetButton.setEnabled(true);
int rcnt = 0;
for (int i=start; i<=end; i++) {
if (model.isRunning(i))
rcnt++;
}
startButton.setEnabled(rcnt < cnt);
stopButton.setEnabled(rcnt > 0);
}
}
/**
* Updates the buttons according the current selection.
* @param e list selection event
*/
public void valueChanged(ListSelectionEvent e) {
updateButtons();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
 
jSplitPane1 = new javax.swing.JSplitPane();
jPanel1 = new javax.swing.JPanel();
startButton = new javax.swing.JButton();
stopButton = new javax.swing.JButton();
addButton = new javax.swing.JButton();
removeButton = new javax.swing.JButton();
resetButton = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
 
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("LWTT");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
TaskFrame.this.windowClosing(evt);
}
});
 
jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
 
jPanel1.setMinimumSize(new java.awt.Dimension(10, 25));
 
startButton.setText("Start");
startButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
startPressed(evt);
}
});
 
stopButton.setText("Stop");
stopButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
stopPressed(evt);
}
});
 
addButton.setText("Add");
addButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addPressed(evt);
}
});
 
removeButton.setText("Remove");
removeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
removePressed(evt);
}
});
 
resetButton.setText("Reset");
resetButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resetPressed(evt);
}
});
 
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(startButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(stopButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(addButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(removeButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(resetButton)
.addContainerGap(251, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(startButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(stopButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(addButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(removeButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(resetButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
);
 
jSplitPane1.setTopComponent(jPanel1);
 
jScrollPane1.setPreferredSize(new java.awt.Dimension(454, 400));
jScrollPane1.setVerifyInputWhenFocusTarget(false);
 
jTable1.setModel(model);
jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
jTable1.setDefaultRenderer(StringBuffer.class, new DefaultTableCellRenderer() {
private Color fg = Color.RED;
private Color bg = new Color(255, 240, 240);
 
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
 
if (JLabel.class.isAssignableFrom(c.getClass())) {
((JLabel) c).setHorizontalAlignment(JLabel.TRAILING);
}
 
if (model.isRunning(row)) {
c.setForeground(fg);
if (!isSelected)
c.setBackground(bg);
}
else {
c.setForeground(Color.BLACK);
if (!isSelected)
c.setBackground(Color.WHITE);
}
 
return c;
}
});
jScrollPane1.setViewportView(jTable1);
 
jSplitPane1.setRightComponent(jScrollPane1);
 
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 572, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
);
 
pack();
}// </editor-fold>//GEN-END:initComponents
 
private void resetPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetPressed
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt > 0)
model.resetTasks(start, start + cnt - 1);
}//GEN-LAST:event_resetPressed
 
private void windowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_windowClosing
model.stopAllTasks();
model.saveToFile();
}//GEN-LAST:event_windowClosing
 
private void removePressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removePressed
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt > 0)
model.removeTasks(start, start + cnt - 1);
}//GEN-LAST:event_removePressed
 
private void addPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPressed
model.addNewTask();
}//GEN-LAST:event_addPressed
 
private void stopPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopPressed
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt > 0) {
model.stopTasks(start, start + cnt - 1);
updateButtons();
}
}//GEN-LAST:event_stopPressed
 
private void startPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startPressed
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt > 0) {
model.startTasks(start, start + cnt - 1);
updateButtons();
}
}//GEN-LAST:event_startPressed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addButton;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JTable jTable1;
private javax.swing.JButton removeButton;
private javax.swing.JButton resetButton;
private javax.swing.JButton startButton;
private javax.swing.JButton stopButton;
// End of variables declaration//GEN-END:variables
}
/lwtt/tags/lwtt-1.1.0/COPYING
0,0 → 1,339
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
 
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
 
Preamble
 
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
 
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
 
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
 
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
 
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
 
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
 
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
 
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
 
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
 
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
 
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
 
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
 
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
 
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
 
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
 
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
 
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
 
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
 
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
 
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
 
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
 
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
 
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
 
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
 
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
 
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
 
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
 
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
 
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
 
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
 
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
 
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
 
NO WARRANTY
 
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
 
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
 
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
 
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
 
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
 
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
Also add information on how to contact you by electronic and paper mail.
 
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
 
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
 
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
 
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
 
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
 
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
 
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
/lwtt/tags/lwtt-1.0.0/COPYING
0,0 → 1,339
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
 
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
 
Preamble
 
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
 
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
 
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
 
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
 
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
 
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
 
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
 
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
 
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
 
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
 
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
 
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
 
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
 
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
 
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
 
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
 
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
 
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
 
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
 
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
 
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
 
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
 
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
 
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
 
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
 
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
 
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
 
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
 
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
 
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
 
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
 
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
 
NO WARRANTY
 
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
 
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
 
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
 
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
 
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
 
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
Also add information on how to contact you by electronic and paper mail.
 
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
 
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
 
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
 
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
 
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
 
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
 
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
/lwtt/tags/lwtt-1.0.0/cz/aiken/util/lwtt/TaskFrame.form
0,0 → 1,148
<?xml version="1.0" encoding="UTF-8" ?>
 
<Form version="1.3" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="title" type="java.lang.String" value="LWTT"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<Events>
<EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="windowClosing"/>
</Events>
<AuxValues>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
 
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jSplitPane1" alignment="1" pref="572" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jSplitPane1" pref="441" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JSplitPane" name="jSplitPane1">
<Properties>
<Property name="orientation" type="int" value="0"/>
</Properties>
 
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanel1">
<Properties>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[10, 25]"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="top"/>
</Constraint>
</Constraints>
 
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="startButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="stopButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="addButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="removeButton" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="310" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="startButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="stopButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="addButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="removeButton" alignment="3" pref="25" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="startButton">
<Properties>
<Property name="text" type="java.lang.String" value="Start"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="startPressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="stopButton">
<Properties>
<Property name="text" type="java.lang.String" value="Stop"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="stopPressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="addButton">
<Properties>
<Property name="text" type="java.lang.String" value="Add"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="addPressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="removeButton">
<Properties>
<Property name="text" type="java.lang.String" value="Remove"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="removePressed"/>
</Events>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<Properties>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[454, 400]"/>
</Property>
<Property name="verifyInputWhenFocusTarget" type="boolean" value="false"/>
<Property name="viewport" type="javax.swing.JViewport" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="null"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="right"/>
</Constraint>
</Constraints>
 
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="jTable1">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="model" type="code"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_InitCodePost" type="java.lang.String" value="jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);&#xa;jTable1.setDefaultRenderer(Long.class, new DefaultTableCellRenderer() {&#xa; private Color fg = Color.RED;&#xa; private Color bg = new Color(255, 240, 240);&#xa; &#xa; public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {&#xa; Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);&#xa; if (JLabel.class.isAssignableFrom(c.getClass())) {&#xa; ((JLabel) c).setHorizontalAlignment(JLabel.TRAILING);&#xa; }&#xa; &#xa; if (model.isRunning(row)) {&#xa; c.setForeground(fg);&#xa; if (!isSelected)&#xa; c.setBackground(bg);&#xa; }&#xa; else {&#xa; c.setForeground(Color.BLACK);&#xa; if (!isSelected)&#xa; c.setBackground(Color.WHITE);&#xa; }&#xa; &#xa; return c;&#xa; }&#xa;});"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Form>
/lwtt/tags/lwtt-1.0.0/cz/aiken/util/lwtt/Task.java
0,0 → 1,203
/*
* Task.java - implementation of tracked task
*
* Copyright (c) 2006 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import javax.swing.Timer;
import java.awt.event.*;
 
/**
* This class represents a tracked task.
* @author luk
*/
public class Task implements ActionListener, Comparable<Task> {
private int id;
private String name = "Unnamed task";
private long consumption = 0L;
private Timer timer = null;
/**
* period for updating time values [ms]
*/
public static final int PERIOD = 10000;
private ActionListener listener = null;
private static int nextId = 0;
/**
* Generates a new task identifier.
* @return new identifier
*/
public static int getNewId() {
int id = nextId;
nextId++;
return id;
}
/**
* Creates a new instance of Task
*/
public Task() {
id = getNewId();
}
/**
* Creates an instance for a task which has been already tracked.
* @param id task identifier
* @param name task name
* @param consumption up to now time consumption
*/
public Task(int id, String name, long consumption) {
this.id = id;
this.name = name;
this.consumption = consumption;
if (id >= nextId)
nextId = id + 1;
}
/**
* Sets the listener where action events should be passed to.
* @param al action listener
*/
public void setActionListener(ActionListener al) {
listener = al;
}
/**
* Returns the task identifier.
* @return task identifier
*/
public int getId() {
return id;
}
/**
* Returns the task name.
* @return task name
*/
public String getName() {
return name;
}
/**
* Sets the task name.
* @param name new task name
*/
public void setName(String name) {
this.name = name;
}
/**
* Returns the current value of cumulative consumption [ms].
* @return current cumulative consumption
*/
public long getConsumption() {
return consumption;
}
/**
* Sets the task cumulative time consumption [ms].
* @param consumption new time consumption value
*/
public void setConsumption(long consumption) {
this.consumption = consumption;
}
/**
* Converts the instance to the string representation. It contains
* the task name and consumption.
* @return string representation
*/
public String toString() {
return name + "(" + Long.toString(consumption) + ")";
}
/**
* Starts tracking of this task.
*/
public void start() {
if (timer != null)
return;
timer = new Timer(PERIOD, this);
timer.start();
}
/**
* Stops tracking of this task.
*/
public void stop() {
if (timer == null)
return;
timer.stop();
timer = null;
}
/**
* Checks whether the task is running.
* @return <CODE>true</CODE> if running, <CODE>false</CODE> otherwise
*/
public boolean isRunning() {
return timer != null;
}
/**
* Updates the time consumption value. Then it creates a new action event
* and passes it to the assigned listener (if any).
* @param e action event
*/
public void actionPerformed(ActionEvent e) {
consumption += PERIOD;
ActionEvent e2 = new ActionEvent(this, id, "");
if (listener != null)
listener.actionPerformed(e2);
}
 
/**
* Compares this task to another one. The comparison result is based
* on task identifiers.
* @param t another task
* @return 1 if this class' id is greater then the given class' id,
* -1 if both ids are equal and 0 otherwise
*/
public int compareTo(Task t) {
if (t == null)
throw new NullPointerException("cannot compare to null pointer");
if (id > t.getId())
return 1;
else if (id == t.getId())
return 0;
else
return -1;
}
}
/lwtt/tags/lwtt-1.0.0/cz/aiken/util/lwtt/Main.java
0,0 → 1,62
/*
* Main.java - main LWTT class
*
* Copyright (c) 2006 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import javax.swing.SwingUtilities;
 
/**
* This class represents the application itself. It creates the main
* application frame and makes it visible.
* @author luk
*/
public class Main implements Runnable {
/**
* Main class constructor.
*/
public Main() {
}
/**
* Creates the main frame and makes it visible. Then it hands control
* on the main application loop.
*
* <I>This method must be called only by the event-dispatching thread.</I>
*/
public void run() {
TaskFrame tf = new TaskFrame();
tf.setVisible(true);
}
/**
* The main application method. It starts the application by
* scheduling the initialization for the event-dispatching thread.
* @param args the command line arguments (currently ignored)
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Main());
}
}
/lwtt/tags/lwtt-1.0.0/cz/aiken/util/lwtt/TaskTableModel.java
0,0 → 1,328
/*
* TaskTableModel.java - implementation of tracked tasks table model
*
* Copyright (c) 2006 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
import java.io.*;
import java.awt.event.*;
 
/**
* This class represents the task table model.
* @author luk
*/
public class TaskTableModel extends AbstractTableModel implements ActionListener {
private ArrayList<Task> tasks = new ArrayList<Task>();
private javax.swing.Timer timer = new javax.swing.Timer(300000, this);
/**
* Creates a new instance of TaskTableModel
*/
public TaskTableModel() {
loadFromFile();
timer.start();
}
 
/**
* Returns the value at the given coordinates.
* @param rowIndex row index
* @param columnIndex column index
* @return appropriate cell value; if the arguments are invalid
* it returns <CODE>null</CODE>
*/
public Object getValueAt(int rowIndex, int columnIndex) {
switch (columnIndex) {
case 0: return tasks.get(rowIndex).getName();
case 1: return new Long(tasks.get(rowIndex).getConsumption() / 60000);
default: return null;
}
}
 
/**
* Returns the row count.
* @return row count
*/
public int getRowCount() {
return tasks.size();
}
 
/**
* Returns the column count (currently 2).
* @return column count
*/
public int getColumnCount() {
return 2;
}
 
/**
* Sets a new value of the given cell. If at least one of the
* coordinates is invalid it does nothing.
* @param aValue new value
* @param rowIndex row index
* @param columnIndex column index
*/
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
switch (columnIndex) {
case 0: tasks.get(rowIndex).setName((String) aValue);
break;
case 1: tasks.get(rowIndex).setConsumption(((Long) aValue).longValue());
break;
}
}
 
/**
* Returns the name of the given column.
* @param column column index
* @return column name; if the index is invalid it returns an empty
* string
*/
public String getColumnName(int column) {
switch (column) {
case 0: return "Task name";
case 1: return "Time consumption [min]";
default: return "";
}
}
 
/**
* Returns the class of the given column.
* @param columnIndex column index
* @return appropriate class object; if the column index is invalid
* it returns <CODE>Void.class</CODE>.
*/
public Class<?> getColumnClass(int columnIndex) {
switch (columnIndex) {
case 0: return String.class;
case 1: return Long.class;
default: return Void.class;
}
}
 
/**
* Checks whether the given cell is editable.
* @param rowIndex row index
* @param columnIndex column index
* @return <CODE>true</CODE> for the first column (index 0),
* <CODE>false</CODE> otherwise
*/
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == 0;
}
/**
* Creates a new task.
*/
public void addNewTask() {
Task t = new Task();
t.setActionListener(this);
tasks.add(t);
int row = tasks.size()-1;
fireTableRowsInserted(row, row);
}
/**
* Removes the given tasks.
* @param start start index
* @param end end index (including)
*/
public void removeTasks(int start, int end) {
for (int i=end; i>=start; i--) {
Task t = tasks.remove(i);
t.stop();
t.setActionListener(null);
}
fireTableRowsDeleted(start, end);
}
/**
* Starts the given tasks.
* @param start start index
* @param end end index (including)
*/
public void startTasks(int start, int end) {
for (int i=start; i<=end; i++) {
Task t = tasks.get(i);
t.start();
fireTableCellUpdated(i, 1);
}
}
/**
* Stops the given tasks.
* @param start start index
* @param end end index (including)
*/
public void stopTasks(int start, int end) {
for (int i=start; i<=end; i++) {
Task t = tasks.get(i);
t.stop();
fireTableCellUpdated(i, 1);
}
}
/**
* Stops all tasks.
*/
public void stopAllTasks() {
Iterator<Task> it = tasks.iterator();
while (it.hasNext()) {
it.next().stop();
}
fireTableDataChanged();
}
/**
* Destroys the timer controlling automatic data saving.
*/
public void cancelAutoSave() {
timer.stop();
}
/**
* Returns the absolute path to the directory where LWTT data should be
* saved.
* @return directory path
*/
public static File getDir() {
Properties sys = System.getProperties();
return new File(sys.getProperty("user.home"), ".lwtt");
}
/**
* Returns the absolute path to the file where LWTT data should be
* saved.
* @return absolute file path
*/
public static File getPath() {
return new File(getDir(), "data.xml");
}
/**
* Checks whether the given task is running.
* @param index task index
* @return <CODE>true</CODE> for running task,
* <CODE>false</CODE> otherwise
*/
public boolean isRunning(int index) {
return tasks.get(index).isRunning();
}
/**
* Loads application's data from the file.
*/
public synchronized void loadFromFile() {
tasks.clear();
File file = getPath();
if (!file.exists())
return;
try {
FileInputStream is = new FileInputStream(file);
Properties props = new Properties();
props.loadFromXML(is);
is.close();
Iterator<Object> it = props.keySet().iterator();
while (it.hasNext()) {
String key = (String) it.next();
if (key.endsWith(".name")) {
String ids = key.substring(0, key.length() - 5);
String name = props.getProperty(ids + ".name");
String cons = props.getProperty(ids + ".consumption");
try {
int id = Integer.parseInt(ids);
long cn = Long.parseLong(cons);
Task t = new Task(id, name, cn);
t.setActionListener(this);
tasks.add(t);
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Cannot load data from file (bad format).", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
Collections.sort(tasks);
fireTableDataChanged();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Saves application's data to the file.
*/
public synchronized void saveToFile() {
File dir = getDir();
if (!dir.exists()) {
if (!dir.mkdir()) {
JOptionPane.showMessageDialog(null, "Cannot save data to file (cannot create data directory).", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
}
Properties props = new Properties();
for (int i=0; i<tasks.size(); i++) {
Task t = tasks.get(i);
String id = Integer.toString(t.getId());
props.setProperty(id + ".name", t.getName());
props.setProperty(id + ".consumption", Long.toString(t.getConsumption()));
}
try {
FileOutputStream os = new FileOutputStream(getPath());
props.storeToXML(os, "LWTT task data");
os.close();
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Cannot save data to file (" + e.getLocalizedMessage() + ").", "Error", JOptionPane.ERROR_MESSAGE);
}
}
 
/**
* 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.
* @param e action event
*/
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
if (src == timer) {
saveToFile();
}
else {
int row = tasks.indexOf(src);
fireTableCellUpdated(row, 1);
}
}
}
/lwtt/tags/lwtt-1.0.0/cz/aiken/util/lwtt/TaskFrame.java
0,0 → 1,255
/*
* TaskFrame.java - implementation of LWTT main application window
*
* Copyright (c) 2006 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
 
/**
* This class represents the main application frame.
* @author luk
*/
public class TaskFrame extends javax.swing.JFrame implements ListSelectionListener {
private TaskTableModel model = new TaskTableModel();
/**
* Time consumption column width
*/
public static final int CONS_COL_WIDTH = 180;
/**
* Creates new form TaskFrame
*/
public TaskFrame() {
initComponents();
TableColumn tc = jTable1.getColumnModel().getColumn(1);
tc.setMaxWidth(CONS_COL_WIDTH);
tc.setPreferredWidth(CONS_COL_WIDTH);
jTable1.getSelectionModel().addListSelectionListener(this);
updateButtons();
}
void updateButtons() {
int cnt = jTable1.getSelectedRowCount();
if (cnt == 0) {
startButton.setEnabled(false);
stopButton.setEnabled(false);
removeButton.setEnabled(false);
}
else {
int start = jTable1.getSelectedRow();
int end = start + cnt - 1;
removeButton.setEnabled(true);
int rcnt = 0;
for (int i=start; i<=end; i++) {
if (model.isRunning(i))
rcnt++;
}
startButton.setEnabled(rcnt < cnt);
stopButton.setEnabled(rcnt > 0);
}
}
/**
* Updates the buttons according the current selection.
* @param e list selection event
*/
public void valueChanged(ListSelectionEvent e) {
updateButtons();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jSplitPane1 = new javax.swing.JSplitPane();
jPanel1 = new javax.swing.JPanel();
startButton = new javax.swing.JButton();
stopButton = new javax.swing.JButton();
addButton = new javax.swing.JButton();
removeButton = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
 
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("LWTT");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
TaskFrame.this.windowClosing(evt);
}
});
 
jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
jPanel1.setMinimumSize(new java.awt.Dimension(10, 25));
startButton.setText("Start");
startButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
startPressed(evt);
}
});
 
stopButton.setText("Stop");
stopButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
stopPressed(evt);
}
});
 
addButton.setText("Add");
addButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addPressed(evt);
}
});
 
removeButton.setText("Remove");
removeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
removePressed(evt);
}
});
 
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(startButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(stopButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(addButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(removeButton)
.addContainerGap(310, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.BASELINE, startButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.BASELINE, stopButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.BASELINE, addButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.BASELINE, removeButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
);
jSplitPane1.setTopComponent(jPanel1);
 
jScrollPane1.setPreferredSize(new java.awt.Dimension(454, 400));
jScrollPane1.setVerifyInputWhenFocusTarget(false);
jScrollPane1.setViewport(null);
jTable1.setModel(model);
jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
jTable1.setDefaultRenderer(Long.class, new DefaultTableCellRenderer() {
private Color fg = Color.RED;
private Color bg = new Color(255, 240, 240);
 
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (JLabel.class.isAssignableFrom(c.getClass())) {
((JLabel) c).setHorizontalAlignment(JLabel.TRAILING);
}
 
if (model.isRunning(row)) {
c.setForeground(fg);
if (!isSelected)
c.setBackground(bg);
}
else {
c.setForeground(Color.BLACK);
if (!isSelected)
c.setBackground(Color.WHITE);
}
 
return c;
}
});
jScrollPane1.setViewportView(jTable1);
 
jSplitPane1.setRightComponent(jScrollPane1);
 
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 572, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
 
private void windowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_windowClosing
model.stopAllTasks();
model.saveToFile();
}//GEN-LAST:event_windowClosing
 
private void removePressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removePressed
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt > 0)
model.removeTasks(start, start + cnt - 1);
}//GEN-LAST:event_removePressed
 
private void addPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPressed
model.addNewTask();
}//GEN-LAST:event_addPressed
 
private void stopPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopPressed
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt > 0) {
model.stopTasks(start, start + cnt - 1);
updateButtons();
}
}//GEN-LAST:event_stopPressed
 
private void startPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startPressed
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt > 0) {
model.startTasks(start, start + cnt - 1);
updateButtons();
}
}//GEN-LAST:event_startPressed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addButton;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JTable jTable1;
private javax.swing.JButton removeButton;
private javax.swing.JButton startButton;
private javax.swing.JButton stopButton;
// End of variables declaration//GEN-END:variables
}
/lwtt/trunk/cz/aiken/util/lwtt/TaskPropertiesDialog.java
0,0 → 1,216
/*
* TaskPropertiesDialog.java - task properties dialog
*
* Copyright (c) 2008 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import javax.swing.JOptionPane;
 
/**
* Task properties dialog class.
*
* This class allows to set various properties of a task. Currently only
* price per hour can be set.
*
* @author luk
*/
public class TaskPropertiesDialog extends javax.swing.JDialog {
/** A return status code - returned if Cancel button has been pressed */
public static final int RET_CANCEL = 0;
/** A return status code - returned if OK button has been pressed */
public static final int RET_OK = 1;
private double price = 1;
 
/** Creates a new TaskPropertiesDialog.
* @param parent parent object for this dialog
* @param modal modal dialog yes/no
*/
public TaskPropertiesDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
priceText.setText(Double.toString(price));
}
 
/**
* Returns the "return status" of this dialog - one of RET_OK or RET_CANCEL.
*
* @return return status
*/
public int getReturnStatus() {
return returnStatus;
}
/**
* Sets the price per hour.
*
* @param price new price per hour
*/
public void setPrice(double price) {
this.price = price;
priceText.setText(Double.toString(price));
}
/**
* Returns the price per hour.
*
* @return price per hour
*/
public double getPrice() {
return price;
}
 
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
 
okButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
priceLabel = new javax.swing.JLabel();
priceText = new javax.swing.JTextField();
 
setTitle("Properties");
setLocationByPlatform(true);
setResizable(false);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
 
okButton.setText("OK");
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
 
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
 
priceLabel.setText("Price per hour");
 
priceText.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
 
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cancelButton))
.addGroup(layout.createSequentialGroup()
.addComponent(priceLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(priceText, javax.swing.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)))
.addContainerGap())
);
 
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cancelButton, okButton});
 
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(priceLabel)
.addComponent(priceText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cancelButton)
.addComponent(okButton))
.addContainerGap())
);
 
pack();
}// </editor-fold>//GEN-END:initComponents
 
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
try {
double p = Double.parseDouble(priceText.getText());
if (p < 0)
throw new NumberFormatException("price value must not be negative");
price = p;
doClose(RET_OK);
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(this, "Price per hour has invalid format.\nPlease use a non-negative number.", "Invalid format", JOptionPane.ERROR_MESSAGE);
}
}//GEN-LAST:event_okButtonActionPerformed
 
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
doClose(RET_CANCEL);
}//GEN-LAST:event_cancelButtonActionPerformed
 
/** Closes the dialog */
private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
doClose(RET_CANCEL);
}//GEN-LAST:event_closeDialog
 
private void doClose(int retStatus) {
returnStatus = retStatus;
setVisible(false);
dispose();
}
 
/**
* This method is only for testing purposes.
*
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
TaskPropertiesDialog dialog = new TaskPropertiesDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
 
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JButton okButton;
private javax.swing.JLabel priceLabel;
private javax.swing.JTextField priceText;
// End of variables declaration//GEN-END:variables
 
private int returnStatus = RET_CANCEL;
}
/lwtt/trunk/cz/aiken/util/lwtt/TaskPropertiesDialog.form
0,0 → 1,93
<?xml version="1.0" encoding="UTF-8" ?>
 
<Form version="1.3" maxVersion="1.6" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="title" type="java.lang.String" value="Properties"/>
<Property name="locationByPlatform" type="boolean" value="true"/>
<Property name="resizable" type="boolean" value="false"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<Events>
<EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="closeDialog"/>
</Events>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
 
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Component id="okButton" linkSize="1" min="-2" pref="67" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cancelButton" linkSize="1" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="priceLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="priceText" pref="69" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="priceLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="priceText" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="22" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="cancelButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="okButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="okButton">
<Properties>
<Property name="text" type="java.lang.String" value="OK"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="okButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="cancelButton">
<Properties>
<Property name="text" type="java.lang.String" value="Cancel"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="priceLabel">
<Properties>
<Property name="text" type="java.lang.String" value="Price per hour"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="priceText">
<Properties>
<Property name="horizontalAlignment" type="int" value="4"/>
</Properties>
</Component>
</SubComponents>
</Form>
/lwtt/trunk/cz/aiken/util/lwtt/Task.java
0,0 → 1,235
/*
* Task.java - implementation of tracked task
*
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import javax.swing.Timer;
import java.awt.event.*;
 
/**
* This class represents a tracked task.
* @author luk
*/
public class Task implements ActionListener, Comparable<Task> {
private int id;
private String name = "Unnamed task";
private long consumption = 0L;
private double price = 1;
private Timer timer = null;
/**
* period for updating time values [ms]
*/
public static final int PERIOD = 10000;
/**
* time units per hour
*/
public static final double UNITS_PER_HOUR = 3600000;
private ActionListener listener = null;
private static int nextId = 0;
/**
* Generates a new task identifier.
* @return new identifier
*/
public static int getNewId() {
int id = nextId;
nextId++;
return id;
}
/**
* Creates a new instance of Task
*/
public Task() {
id = getNewId();
}
/**
* Creates an instance for a task which has been already tracked.
* @param id task identifier
* @param name task name
* @param consumption up to now time consumption
* @param price price per hour
*/
public Task(int id, String name, long consumption, double price) {
this.id = id;
this.name = name;
this.consumption = consumption;
this.price = price;
if (id >= nextId)
nextId = id + 1;
}
/**
* Sets the listener where action events should be passed to.
* @param al action listener
*/
public void setActionListener(ActionListener al) {
listener = al;
}
/**
* Returns the task identifier.
* @return task identifier
*/
public int getId() {
return id;
}
/**
* Returns the task name.
* @return task name
*/
public String getName() {
return name;
}
/**
* Sets the task name.
* @param name new task name
*/
public void setName(String name) {
this.name = name;
}
/**
* Returns the current value of cumulative consumption [ms].
* @return current cumulative consumption
*/
public long getConsumption() {
return consumption;
}
/**
* Sets the task cumulative time consumption [ms].
* @param consumption new time consumption value
*/
public void setConsumption(long consumption) {
this.consumption = consumption;
}
/**
* Sets the price per hour [currency unit].
* Changing this parameter affects the current total price of the task.
* @param price new price value
*/
public void setPrice(double price) {
this.price = price;
}
/**
* Returns the current price per hour [currency unit].
* @return current price value
*/
public double getPrice() {
return price;
}
/**
* Returns the total price of this task [currency unit].
* @return total price of this task
*/
public double getTotalPrice() {
return ((double) consumption) / UNITS_PER_HOUR * price;
}
/**
* Converts the instance to the string representation. It contains
* the task name and consumption.
* @return string representation
*/
@Override
public String toString() {
return name + "(" + Long.toString(consumption) + ")";
}
/**
* Starts tracking of this task.
*/
public void start() {
if (timer != null)
return;
timer = new Timer(PERIOD, this);
timer.start();
}
/**
* Stops tracking of this task.
*/
public void stop() {
if (timer == null)
return;
timer.stop();
timer = null;
}
/**
* Checks whether the task is running.
* @return <CODE>true</CODE> if running, <CODE>false</CODE> otherwise
*/
public boolean isRunning() {
return timer != null;
}
/**
* Updates the time consumption value. Then it creates a new action event
* and passes it to the assigned listener (if any).
* @param e action event
*/
public void actionPerformed(ActionEvent e) {
consumption += PERIOD;
ActionEvent e2 = new ActionEvent(this, id, "");
if (listener != null)
listener.actionPerformed(e2);
}
 
/**
* Compares this task to another one. The comparison result is based
* on task identifiers.
* @param t another task
* @return 1 if this class' id is greater then the given class' id,
* -1 if both ids are equal and 0 otherwise
*/
public int compareTo(Task t) {
if (t == null)
throw new NullPointerException("cannot compare to null pointer");
if (id > t.getId())
return 1;
else if (id == t.getId())
return 0;
else
return -1;
}
}
/lwtt/trunk/cz/aiken/util/lwtt/TaskFrame.form
0,0 → 1,172
<?xml version="1.0" encoding="UTF-8" ?>
 
<Form version="1.3" maxVersion="1.3" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="title" type="java.lang.String" value="LWTT"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<Events>
<EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="windowClosing"/>
</Events>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="2"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
 
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jSplitPane1" alignment="1" pref="572" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jSplitPane1" pref="441" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JSplitPane" name="jSplitPane1">
<Properties>
<Property name="orientation" type="int" value="0"/>
</Properties>
 
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanel1">
<Properties>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[10, 25]"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="top"/>
</Constraint>
</Constraints>
 
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="startButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="stopButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="addButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="removeButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="resetButton" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="propsButton" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="152" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="startButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="stopButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="addButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="removeButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="resetButton" alignment="3" pref="25" max="32767" attributes="0"/>
<Component id="propsButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="startButton">
<Properties>
<Property name="text" type="java.lang.String" value="Start"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="startPressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="stopButton">
<Properties>
<Property name="text" type="java.lang.String" value="Stop"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="stopPressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="addButton">
<Properties>
<Property name="text" type="java.lang.String" value="Add"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="addPressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="removeButton">
<Properties>
<Property name="text" type="java.lang.String" value="Remove"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="removePressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="resetButton">
<Properties>
<Property name="text" type="java.lang.String" value="Reset"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="resetPressed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="propsButton">
<Properties>
<Property name="text" type="java.lang.String" value="Properties..."/>
<Property name="actionCommand" type="java.lang.String" value="Properties"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="propsPressed"/>
</Events>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<Properties>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[454, 400]"/>
</Property>
<Property name="verifyInputWhenFocusTarget" type="boolean" value="false"/>
</Properties>
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="right"/>
</Constraint>
</Constraints>
 
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="jTable1">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="model" type="code"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_InitCodePost" type="java.lang.String" value="jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);&#xa;jTable1.setDefaultRenderer(StringBuffer.class, new DefaultTableCellRenderer() {&#xa; private Color fg = Color.RED;&#xa; private Color bg = new Color(255, 240, 240);&#xa; &#xa; public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {&#xa; Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);&#xa; &#xa; if (JLabel.class.isAssignableFrom(c.getClass())) {&#xa; ((JLabel) c).setHorizontalAlignment(JLabel.TRAILING);&#xa; }&#xa; &#xa; if (model.isRunning(row)) {&#xa; c.setForeground(fg);&#xa; if (!isSelected)&#xa; c.setBackground(bg);&#xa; }&#xa; else {&#xa; c.setForeground(Color.BLACK);&#xa; if (!isSelected)&#xa; c.setBackground(Color.WHITE);&#xa; }&#xa; &#xa; return c;&#xa; }&#xa;});"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Form>
/lwtt/trunk/cz/aiken/util/lwtt/TaskTableModel.java
0,0 → 1,382
/*
* TaskTableModel.java - implementation of tracked tasks table model
*
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
import java.io.*;
import java.awt.event.*;
import java.math.*;
import java.text.*;
 
/**
* This class represents the task table model.
* @author luk
*/
public class TaskTableModel extends AbstractTableModel implements ActionListener {
private ArrayList<Task> tasks = new ArrayList<Task>();
private javax.swing.Timer timer = new javax.swing.Timer(300000, this);
private MessageFormat timeFormat = new MessageFormat("{0,number}:{1,number,00}");
private MessageFormat priceFormat = new MessageFormat("{0,number}.{1,number,00}");
private TaskFrame taskFrame = null;
/**
* Creates a new instance of TaskTableModel
* @param tf task frame instance
*/
public TaskTableModel(TaskFrame tf) {
taskFrame = tf;
loadFromFile();
timer.start();
}
 
/**
* Returns the value at the given coordinates.
* @param rowIndex row index
* @param columnIndex column index
* @return appropriate cell value; if the arguments are invalid
* it returns <CODE>null</CODE>
*/
public Object getValueAt(int rowIndex, int columnIndex) {
switch (columnIndex) {
case 0:
return tasks.get(rowIndex).getName();
case 1:
long mins = tasks.get(rowIndex).getConsumption() / 60000;
BigDecimal hm[] = new BigDecimal((int) mins).divideAndRemainder(new BigDecimal(60));
return timeFormat.format(hm);
case 2:
double tp = tasks.get(rowIndex).getTotalPrice();
BigDecimal pr[] = new BigDecimal(tp * 100).divideAndRemainder(new BigDecimal(100));
return priceFormat.format(pr);
default: return null;
}
}
 
/**
* Returns the row count.
* @return row count
*/
public int getRowCount() {
return tasks.size();
}
 
/**
* Returns the column count (currently 2).
* @return column count
*/
public int getColumnCount() {
return 3;
}
 
/**
* Sets a new value of the given cell. If at least one of the
* coordinates is invalid it does nothing.
* @param aValue new value
* @param rowIndex row index
* @param columnIndex column index
*/
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
switch (columnIndex) {
case 0: tasks.get(rowIndex).setName((String) aValue);
break;
}
}
 
/**
* Returns the name of the given column.
* @param column column index
* @return column name; if the index is invalid it returns an empty
* string
*/
@Override
public String getColumnName(int column) {
switch (column) {
case 0: return "Task name";
case 1: return "Time consumption [h:min]";
case 2: return "Total price";
default: return "";
}
}
 
/**
* Returns the class of the given column.
* @param columnIndex column index
* @return appropriate class object; if the column index is invalid
* it returns <CODE>Void.class</CODE>.
*/
@Override
public Class<?> getColumnClass(int columnIndex) {
switch (columnIndex) {
case 0: return String.class;
case 1: return StringBuffer.class;
case 2: return StringBuffer.class;
default: return Void.class;
}
}
 
/**
* Checks whether the given cell is editable.
* @param rowIndex row index
* @param columnIndex column index
* @return <CODE>true</CODE> for the first column (index 0),
* <CODE>false</CODE> otherwise
*/
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return columnIndex == 0;
}
public Task getTask(int index) {
return tasks.get(index);
}
/**
* Creates a new task.
*/
public void addNewTask() {
Task t = new Task();
t.setActionListener(this);
tasks.add(t);
int row = tasks.size()-1;
fireTableRowsInserted(row, row);
}
/**
* Removes the given tasks.
* @param start start index
* @param end end index (including)
*/
public void removeTasks(int start, int end) {
for (int i=end; i>=start; i--) {
Task t = tasks.remove(i);
t.stop();
t.setActionListener(null);
}
fireTableRowsDeleted(start, end);
}
/**
* Starts the given tasks.
* @param start start index
* @param end end index (including)
*/
public void startTasks(int start, int end) {
for (int i=start; i<=end; i++) {
Task t = tasks.get(i);
t.start();
fireTableCellUpdated(i, 1);
fireTableCellUpdated(i, 2);
}
}
/**
* Stops the given tasks.
* @param start start index
* @param end end index (including)
*/
public void stopTasks(int start, int end) {
for (int i=start; i<=end; i++) {
Task t = tasks.get(i);
t.stop();
fireTableCellUpdated(i, 1);
fireTableCellUpdated(i, 2);
}
}
/**
* Stops all tasks.
*/
public void stopAllTasks() {
Iterator<Task> it = tasks.iterator();
while (it.hasNext()) {
it.next().stop();
}
fireTableDataChanged();
}
/**
* Resets the given tasks.
* @param start index of the first resetted task
* @param end index of the first NOT resetted task (the first task beyond the interval)
*/
public void resetTasks(int start, int end) {
for (int i=start; i<=end; i++) {
Task t = tasks.get(i);
t.setConsumption(0);
fireTableCellUpdated(i, 1);
fireTableCellUpdated(i, 2);
}
}
/**
* Destroys the timer controlling automatic data saving.
*/
public void cancelAutoSave() {
timer.stop();
}
/**
* Returns the absolute path to the directory where LWTT data should be
* saved.
* @return directory path
*/
public static File getDir() {
Properties sys = System.getProperties();
return new File(sys.getProperty("user.home"), ".lwtt");
}
/**
* Returns the absolute path to the file where LWTT data should be
* saved.
* @return absolute file path
*/
public static File getPath() {
return new File(getDir(), "data.xml");
}
/**
* Checks whether the given task is running.
* @param index task index
* @return <CODE>true</CODE> for running task,
* <CODE>false</CODE> otherwise
*/
public boolean isRunning(int index) {
return tasks.get(index).isRunning();
}
/**
* Loads application's data from the file.
*/
public synchronized void loadFromFile() {
tasks.clear();
File file = getPath();
if (!file.exists()) {
Properties props = new Properties();
taskFrame.setStartSettings(props);
return;
}
try {
FileInputStream is = new FileInputStream(file);
Properties props = new Properties();
props.loadFromXML(is);
is.close();
taskFrame.setStartSettings(props);
Iterator<Object> it = props.keySet().iterator();
while (it.hasNext()) {
String key = (String) it.next();
if (key.endsWith(".name")) {
String ids = key.substring(0, key.length() - 5);
String name = props.getProperty(ids + ".name");
String cons = props.getProperty(ids + ".consumption");
String price = props.getProperty(ids + ".price", "1");
try {
int id = Integer.parseInt(ids);
long cn = Long.parseLong(cons);
double pr = Double.parseDouble(price);
Task t = new Task(id, name, cn, pr);
t.setActionListener(this);
tasks.add(t);
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Cannot load data from file (bad format).", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
Collections.sort(tasks);
fireTableDataChanged();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Saves application's data to the file.
*/
public synchronized void saveToFile() {
File dir = getDir();
if (!dir.exists()) {
if (!dir.mkdir()) {
JOptionPane.showMessageDialog(null, "Cannot save data to file (cannot create data directory).", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
}
Properties props = new Properties();
props.setProperty("window.location.x", Integer.toString(taskFrame.getX()));
props.setProperty("window.location.y", Integer.toString(taskFrame.getY()));
props.setProperty("window.size.w", Integer.toString(taskFrame.getWidth()));
props.setProperty("window.size.h", Integer.toString(taskFrame.getHeight()));
for (int i=0; i<tasks.size(); i++) {
Task t = tasks.get(i);
String id = Integer.toString(t.getId());
props.setProperty(id + ".name", t.getName());
props.setProperty(id + ".consumption", Long.toString(t.getConsumption()));
props.setProperty(id + ".price", Double.toString(t.getPrice()));
}
try {
FileOutputStream os = new FileOutputStream(getPath());
props.storeToXML(os, "LWTT task data");
os.close();
} catch (IOException e) {
JOptionPane.showMessageDialog(null, "Cannot save data to file (" + e.getLocalizedMessage() + ").", "Error", JOptionPane.ERROR_MESSAGE);
}
}
 
/**
* 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.
* @param e action event
*/
public void actionPerformed(ActionEvent e) {
Object src = e.getSource();
if (src == timer) {
saveToFile();
}
else {
int row = tasks.indexOf(src);
fireTableCellUpdated(row, 1);
fireTableCellUpdated(row, 2);
}
}
}
/lwtt/trunk/cz/aiken/util/lwtt/TaskFrame.java
0,0 → 1,348
/*
* TaskFrame.java - implementation of LWTT main application window
*
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import java.util.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
 
/**
* This class represents the main application frame.
* @author luk
*/
public class TaskFrame extends JFrame implements ListSelectionListener {
private TaskTableModel model = null;
private Properties startSettings = null;
/**
* Time consumption column width
*/
public static final int CONS_COL_WIDTH = 180;
/**
* Creates new form TaskFrame
*/
public TaskFrame() {
model = new TaskTableModel(this);
initComponents();
TableColumn tc = jTable1.getColumnModel().getColumn(1);
tc.setMaxWidth(CONS_COL_WIDTH);
tc.setPreferredWidth(CONS_COL_WIDTH);
jTable1.getSelectionModel().addListSelectionListener(this);
updateButtons();
try {
String xs = startSettings.getProperty("window.location.x");
String ys = startSettings.getProperty("window.location.y");
if (xs != null && ys != null) {
setLocation(Integer.parseInt(xs), Integer.parseInt(ys));
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Cannot load window location (bad format).", "Error", JOptionPane.ERROR_MESSAGE);
}
try {
String ws = startSettings.getProperty("window.size.w");
String hs = startSettings.getProperty("window.size.h");
if (ws != null && hs != null) {
setSize(Integer.parseInt(ws), Integer.parseInt(hs));
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Cannot load window size (bad format).", "Error", JOptionPane.ERROR_MESSAGE);
}
}
/**
* Sets initial (start) settings.
* @param props properties with initial settings
*/
public void setStartSettings(Properties props) {
startSettings = props;
}
/**
* Updates the buttons' state.
*/
private void updateButtons() {
int cnt = jTable1.getSelectedRowCount();
if (cnt == 0) {
startButton.setEnabled(false);
stopButton.setEnabled(false);
removeButton.setEnabled(false);
resetButton.setEnabled(false);
}
else {
int start = jTable1.getSelectedRow();
int end = start + cnt - 1;
removeButton.setEnabled(true);
resetButton.setEnabled(true);
int rcnt = 0;
for (int i=start; i<=end; i++) {
if (model.isRunning(i))
rcnt++;
}
startButton.setEnabled(rcnt < cnt);
stopButton.setEnabled(rcnt > 0);
}
propsButton.setEnabled(cnt == 1);
}
/**
* Updates the buttons according the current selection.
* @param e list selection event
*/
public void valueChanged(ListSelectionEvent e) {
updateButtons();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
 
jSplitPane1 = new javax.swing.JSplitPane();
jPanel1 = new javax.swing.JPanel();
startButton = new javax.swing.JButton();
stopButton = new javax.swing.JButton();
addButton = new javax.swing.JButton();
removeButton = new javax.swing.JButton();
resetButton = new javax.swing.JButton();
propsButton = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
 
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("LWTT");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
TaskFrame.this.windowClosing(evt);
}
});
 
jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
 
jPanel1.setMinimumSize(new java.awt.Dimension(10, 25));
 
startButton.setText("Start");
startButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
startPressed(evt);
}
});
 
stopButton.setText("Stop");
stopButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
stopPressed(evt);
}
});
 
addButton.setText("Add");
addButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addPressed(evt);
}
});
 
removeButton.setText("Remove");
removeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
removePressed(evt);
}
});
 
resetButton.setText("Reset");
resetButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resetPressed(evt);
}
});
 
propsButton.setText("Properties...");
propsButton.setActionCommand("Properties");
propsButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
propsPressed(evt);
}
});
 
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(startButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(stopButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(addButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(removeButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(resetButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(propsButton)
.addContainerGap(152, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(startButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(stopButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(addButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(removeButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(resetButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.add(propsButton)
);
 
jSplitPane1.setTopComponent(jPanel1);
 
jScrollPane1.setPreferredSize(new java.awt.Dimension(454, 400));
jScrollPane1.setVerifyInputWhenFocusTarget(false);
 
jTable1.setModel(model);
jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
jTable1.setDefaultRenderer(StringBuffer.class, new DefaultTableCellRenderer() {
private Color fg = Color.RED;
private Color bg = new Color(255, 240, 240);
 
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
 
if (JLabel.class.isAssignableFrom(c.getClass())) {
((JLabel) c).setHorizontalAlignment(JLabel.TRAILING);
}
 
if (model.isRunning(row)) {
c.setForeground(fg);
if (!isSelected)
c.setBackground(bg);
}
else {
c.setForeground(Color.BLACK);
if (!isSelected)
c.setBackground(Color.WHITE);
}
 
return c;
}
});
jScrollPane1.setViewportView(jTable1);
 
jSplitPane1.setRightComponent(jScrollPane1);
 
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 572, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
);
 
pack();
}// </editor-fold>//GEN-END:initComponents
 
private void resetPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetPressed
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt > 0)
model.resetTasks(start, start + cnt - 1);
}//GEN-LAST:event_resetPressed
 
private void windowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_windowClosing
model.stopAllTasks();
model.saveToFile();
}//GEN-LAST:event_windowClosing
 
private void removePressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removePressed
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt > 0)
model.removeTasks(start, start + cnt - 1);
}//GEN-LAST:event_removePressed
 
private void addPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPressed
model.addNewTask();
}//GEN-LAST:event_addPressed
 
private void stopPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopPressed
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt > 0) {
model.stopTasks(start, start + cnt - 1);
updateButtons();
}
}//GEN-LAST:event_stopPressed
 
private void startPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startPressed
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt > 0) {
model.startTasks(start, start + cnt - 1);
updateButtons();
}
}//GEN-LAST:event_startPressed
 
private void propsPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_propsPressed
TaskPropetiesDialog d = new TaskPropetiesDialog(this, true);
int start = jTable1.getSelectedRow();
int cnt = jTable1.getSelectedRowCount();
if (cnt == 1) {
Task t = model.getTask(start);
d.setPrice(t.getPrice());
d.setVisible(true);
if (d.getReturnStatus() == TaskPropetiesDialog.RET_OK) {
t.setPrice(d.getPrice());
model.fireTableCellUpdated(start, 2);
}
}
}//GEN-LAST:event_propsPressed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addButton;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JTable jTable1;
private javax.swing.JButton propsButton;
private javax.swing.JButton removeButton;
private javax.swing.JButton resetButton;
private javax.swing.JButton startButton;
private javax.swing.JButton stopButton;
// End of variables declaration//GEN-END:variables
}
/lwtt/trunk/cz/aiken/util/lwtt/Main.java
0,0 → 1,62
/*
* Main.java - main LWTT class
*
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz
*
* ==========================================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ==========================================================================
*/
 
package cz.aiken.util.lwtt;
 
import javax.swing.*;
 
/**
* This class represents the application itself. It creates the main
* application frame and makes it visible.
* @author luk
*/
public class Main implements Runnable {
/**
* Main class constructor.
*/
public Main() {
}
/**
* Creates the main frame and makes it visible. Then it hands control
* on the main application loop.
*
* <I>This method may be called only by the event-dispatching thread.</I>
*/
public void run() {
TaskFrame tf = new TaskFrame();
tf.setVisible(true);
}
/**
* The main application method. It starts the application by
* scheduling the initialization for the event-dispatching thread.
* @param args the command line arguments (currently ignored)
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Main());
}
}
/lwtt/trunk/COPYING
0,0 → 1,339
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
 
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
 
Preamble
 
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
 
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
 
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
 
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
 
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
 
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
 
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
 
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
 
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
 
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
 
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
 
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
 
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
 
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
 
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
 
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
 
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
 
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
 
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
 
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
 
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
 
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
 
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
 
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
 
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
 
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
 
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
 
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
 
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
 
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
 
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
 
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
 
NO WARRANTY
 
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
 
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
 
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
 
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
 
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
 
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
Also add information on how to contact you by electronic and paper mail.
 
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
 
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
 
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
 
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
 
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
 
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
 
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.