/lwtt/trunk/cz/aiken/util/lwtt/TaskFrame.form |
---|
1,6 → 1,6 |
<?xml version="1.0" encoding="UTF-8" ?> |
<Form version="1.3" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> |
<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"/> |
12,7 → 12,10 |
<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"/> |
61,16 → 64,19 |
<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"/> |
<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="0" attributes="0"> |
<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> |
107,6 → 113,14 |
<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"> |
115,9 → 129,6 |
<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"/> |
137,7 → 148,7 |
</Property> |
</Properties> |
<AuxValues> |
<AuxValue name="JavaCodeGenerator_InitCodePost" type="java.lang.String" value="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;
 }
});"/> |
<AuxValue name="JavaCodeGenerator_InitCodePost" type="java.lang.String" value="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;
 }
});"/> |
</AuxValues> |
</Component> |
</SubComponents> |
/lwtt/trunk/cz/aiken/util/lwtt/Task.java |
---|
1,7 → 1,7 |
/* |
* Task.java - implementation of tracked task |
* |
* Copyright (c) 2006 Lukas Jelinek, http://www.aiken.cz |
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz |
* |
* ========================================================================== |
* |
56,8 → 56,6 |
return id; |
} |
/** |
* Creates a new instance of Task |
*/ |
133,6 → 131,7 |
* the task name and consumption. |
* @return string representation |
*/ |
@Override |
public String toString() { |
return name + "(" + Long.toString(consumption) + ")"; |
} |
/lwtt/trunk/cz/aiken/util/lwtt/Main.java |
---|
1,7 → 1,7 |
/* |
* Main.java - main LWTT class |
* |
* Copyright (c) 2006 Lukas Jelinek, http://www.aiken.cz |
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz |
* |
* ========================================================================== |
* |
23,7 → 23,7 |
package cz.aiken.util.lwtt; |
import javax.swing.SwingUtilities; |
import javax.swing.*; |
/** |
* This class represents the application itself. It creates the main |
43,11 → 43,11 |
* 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> |
* <I>This method may be called only by the event-dispatching thread.</I> |
*/ |
public void run() { |
TaskFrame tf = new TaskFrame(); |
tf.setVisible(true); |
TaskFrame tf = new TaskFrame(); |
tf.setVisible(true); |
} |
/** |
/lwtt/trunk/cz/aiken/util/lwtt/TaskTableModel.java |
---|
1,7 → 1,7 |
/* |
* TaskTableModel.java - implementation of tracked tasks table model |
* |
* Copyright (c) 2006 Lukas Jelinek, http://www.aiken.cz |
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz |
* |
* ========================================================================== |
* |
28,6 → 28,8 |
import java.util.*; |
import java.io.*; |
import java.awt.event.*; |
import java.math.*; |
import java.text.*; |
/** |
* This class represents the task table model. |
38,10 → 40,16 |
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() { |
public TaskTableModel(TaskFrame tf) { |
taskFrame = tf; |
loadFromFile(); |
timer.start(); |
} |
55,8 → 63,12 |
*/ |
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); |
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; |
} |
} |
84,12 → 96,11 |
* @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; |
case 1: tasks.get(rowIndex).setConsumption(((Long) aValue).longValue()); |
break; |
} |
} |
99,10 → 110,11 |
* @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 [min]"; |
case 1: return "Time consumption [h:min]"; |
default: return ""; |
} |
} |
113,10 → 125,11 |
* @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 Long.class; |
case 1: return StringBuffer.class; |
default: return Void.class; |
} |
} |
128,6 → 141,7 |
* @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; |
} |
198,6 → 212,19 |
} |
/** |
* 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() { |
249,6 → 276,8 |
props.loadFromXML(is); |
is.close(); |
taskFrame.setStartSettings(props); |
Iterator<Object> it = props.keySet().iterator(); |
while (it.hasNext()) { |
String key = (String) it.next(); |
290,6 → 319,10 |
} |
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()); |
/lwtt/trunk/cz/aiken/util/lwtt/TaskFrame.java |
---|
1,7 → 1,7 |
/* |
* TaskFrame.java - implementation of LWTT main application window |
* |
* Copyright (c) 2006 Lukas Jelinek, http://www.aiken.cz |
* Copyright (c) 2006, 2007, 2008 Lukas Jelinek, http://www.aiken.cz |
* |
* ========================================================================== |
* |
23,6 → 23,7 |
package cz.aiken.util.lwtt; |
import java.util.*; |
import java.awt.*; |
import javax.swing.*; |
import javax.swing.table.*; |
32,10 → 33,12 |
* This class represents the main application frame. |
* @author luk |
*/ |
public class TaskFrame extends javax.swing.JFrame implements ListSelectionListener { |
public class TaskFrame extends JFrame implements ListSelectionListener { |
private TaskTableModel model = new TaskTableModel(); |
private TaskTableModel model = null; |
private Properties startSettings = null; |
/** |
* Time consumption column width |
*/ |
45,6 → 48,7 |
* Creates new form TaskFrame |
*/ |
public TaskFrame() { |
model = new TaskTableModel(this); |
initComponents(); |
TableColumn tc = jTable1.getColumnModel().getColumn(1); |
tc.setMaxWidth(CONS_COL_WIDTH); |
51,19 → 55,53 |
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); |
} |
} |
void updateButtons() { |
/** |
* 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++) { |
88,8 → 126,9 |
* 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 |
// <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(); |
96,6 → 135,7 |
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(); |
108,7 → 148,9 |
}); |
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) { |
137,6 → 179,13 |
} |
}); |
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( |
149,28 → 198,33 |
.add(addButton) |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
.add(removeButton) |
.addContainerGap(310, Short.MAX_VALUE)) |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
.add(resetButton) |
.addContainerGap(251, 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) |
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); |
jScrollPane1.setViewport(null); |
jTable1.setModel(model); |
jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION); |
jTable1.setDefaultRenderer(Long.class, new DefaultTableCellRenderer() { |
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); |
} |
203,9 → 257,17 |
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(); |
248,6 → 310,7 |
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 |