String previous;
@Override
public void actionPerformed(ActionEvent e) {
if (chkUpdate.isSelected()) {
previous = txtDescription.getText();
final RecordEntity recordEntity = TimesheetComponent.getInstance().getLastRowRecordEntity();
if (recordEntity != null) {
txtDescription.setText(recordEntity.getDescription());
}
} else {
txtDescription.setText(previous);
}
}
});
btnStart.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (timer.isRunning()) {
timer.stop();
} else {
timer.start();
}
String title = "";
char mnemonic = ' ';
if (timer.isRunning()) {
title = "Pause";
mnemonic = 'P';
} else {
title = "Continue";
mnemonic = 'C';
}
btnStart.setText(title);
btnStart.setMnemonic(mnemonic);
}
});
btnReset.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
timer.stop();
elapsed = 0;
updateLabel();
btnStart.setText("Start");
btnStart.setMnemonic('S');
}
});
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// if elapsed time is 0, do not insert data into the table
if (elapsed == 0) return;
RecordEntity recordEntity;
double previousDuration = 0;
Double rate = null;
if (chkUpdate.isSelected()) {
// do an update
recordEntity = TimesheetComponent.getInstance().getLastRowRecordEntity();
if (recordEntity == null) {
// insert it instead
recordEntity = TimesheetComponent.getInstance().getNewRecordEntity();
} else {
previousDuration = recordEntity.getDuration();
rate = recordEntity.getRate();
}
} else {
// insert
recordEntity = TimesheetComponent.getInstance().getNewRecordEntity();
}
if (rate == null) {
rate = Config.getDefaultRate();
}
recordEntity.setDate(TimesheetComponent.getInstance().getSelectedDate());
recordEntity.setDuration(previousDuration + (elapsed / 3600.0));
recordEntity.setDescription(txtDescription.getText());
recordEntity.setRate(rate);
recordEntity.setUpdated(new Date());
recordEntity.save();
}
});
btnMinimize.addActionListener(new ActionListener() {
@Override