Subversion Repositories public

Compare Revisions

Ignore whitespace Rev 92 → Rev 93

/lwtt/trunk/cz/aiken/util/lwtt/TaskFrame.form
13,6 → 13,7
</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"/>
66,7 → 67,9
<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"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="propsButton" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="152" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
77,6 → 80,7
<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>
121,6 → 125,15
<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">
/lwtt/trunk/cz/aiken/util/lwtt/TaskPropetiesDialog.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
25,6 → 25,7
 
import javax.swing.Timer;
import java.awt.event.*;
import java.math.*;
 
/**
* This class represents a tracked task.
35,6 → 36,7
private String name = "Unnamed task";
private long consumption = 0L;
private double price = 1;
private Timer timer = null;
/**
42,6 → 44,11
*/
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;
68,11 → 75,13
* @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) {
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;
127,6 → 136,31
}
/**
* 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
/lwtt/trunk/cz/aiken/util/lwtt/TaskTableModel.java
41,6 → 41,7
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;
69,6 → 70,10
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;
}
}
86,7 → 91,7
* @return column count
*/
public int getColumnCount() {
return 2;
return 3;
}
 
/**
115,6 → 120,7
switch (column) {
case 0: return "Task name";
case 1: return "Time consumption [h:min]";
case 2: return "Total price";
default: return "";
}
}
130,6 → 136,7
switch (columnIndex) {
case 0: return String.class;
case 1: return StringBuffer.class;
case 2: return StringBuffer.class;
default: return Void.class;
}
}
146,6 → 153,10
return columnIndex == 0;
}
public Task getTask(int index) {
return tasks.get(index);
}
/**
* Creates a new task.
*/
183,6 → 194,7
Task t = tasks.get(i);
t.start();
fireTableCellUpdated(i, 1);
fireTableCellUpdated(i, 2);
}
}
196,6 → 208,7
Task t = tasks.get(i);
t.stop();
fireTableCellUpdated(i, 1);
fireTableCellUpdated(i, 2);
}
}
221,6 → 234,7
Task t = tasks.get(i);
t.setConsumption(0);
fireTableCellUpdated(i, 1);
fireTableCellUpdated(i, 2);
}
}
288,10 → 302,12
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);
Task t = new Task(id, name, cn);
double pr = Double.parseDouble(price);
Task t = new Task(id, name, cn, pr);
t.setActionListener(this);
tasks.add(t);
} catch (NumberFormatException e) {
331,6 → 347,7
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 {
358,6 → 375,7
else {
int row = tasks.indexOf(src);
fireTableCellUpdated(row, 1);
fireTableCellUpdated(row, 2);
}
}
/lwtt/trunk/cz/aiken/util/lwtt/TaskFrame.java
111,6 → 111,8
startButton.setEnabled(rcnt < cnt);
stopButton.setEnabled(rcnt > 0);
}
propsButton.setEnabled(cnt == 1);
}
/**
136,6 → 138,7
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();
 
186,6 → 189,14
}
});
 
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(
200,7 → 211,9
.add(removeButton)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(resetButton)
.addContainerGap(251, Short.MAX_VALUE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(propsButton)
.addContainerGap(152, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
209,6 → 222,7
.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);
302,6 → 316,21
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;
309,6 → 338,7
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;
/lwtt/trunk/cz/aiken/util/lwtt/TaskPropetiesDialog.java
0,0 → 1,175
/*
* TaskPropetiesDialog.java
*
* Created on 3. kv├Čten 2008, 20:16
*/
 
package cz.aiken.util.lwtt;
 
import javax.swing.JOptionPane;
 
/**
*
* @author luk
*/
public class TaskPropetiesDialog 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 new form TaskPropetiesDialog */
public TaskPropetiesDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
priceText.setText(Double.toString(price));
}
 
/** @return the return status of this dialog - one of RET_OK or RET_CANCEL */
public int getReturnStatus() {
return returnStatus;
}
public void setPrice(double price) {
this.price = price;
priceText.setText(Double.toString(price));
}
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();
}
 
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
TaskPropetiesDialog dialog = new TaskPropetiesDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
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;
}