Added support for custom working time and pause time

This commit is contained in:
Robert Vokac 2024-03-09 19:59:35 +00:00
parent 6930b3e8ed
commit e43df2feca
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
4 changed files with 88 additions and 38 deletions

View File

@ -169,10 +169,16 @@ Smileys can be colored or white-black (can be set in configuration)
* CTRL + {Y,N,D,H,M,S or I} - Decrease test time value * CTRL + {Y,N,D,H,M,S or I} - Decrease test time value
* ALT + {Y,N,D,H,M,S or I} - Rest test time value * ALT + {Y,N,D,H,M,S or I} - Rest test time value
* D - Reset custom time values to the real time * D - Reset custom time values to the real time
* SHIFT + A - Increase arrival time by 1 minute * SHIFT + A - Increase arrival time
* CTRL + A - Decrease arrival time by 1 minute * CTRL + A - Decrease arrival time
* SHIFT + O - Increase overtime by 1 minute * SHIFT + O - Increase overtime
* CTRL + O - Decrease overtime by 1 minute * CTRL + O - Decrease overtime
* SHIFT + W - Increase working time
* CTRL + W - Decrease worknig time
* SHIFT + P - Increase pause
* CTRL + P - Decrease pause
* SHIFT + C - Increase or decrease of time is change by 1 hour
* CTRL + C - Increase or decrease of time is change by 1 minute
## Command button ## Command button

View File

@ -14,6 +14,7 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Calendar; import java.util.Calendar;
import java.util.Properties; import java.util.Properties;
import org.nanoboot.utils.timecalc.utils.common.TTime;
/** /**
* @author Robert Vokac * @author Robert Vokac
@ -21,11 +22,15 @@ import java.util.Properties;
*/ */
public class TimeCalcKeyAdapter extends KeyAdapter { public class TimeCalcKeyAdapter extends KeyAdapter {
private static final TTime T_TIME_ONE_MINUTE = new TTime(0, 1);
private static final TTime T_TIME_ONE_HOUR = new TTime(1,0);
private final TimeCalcConfiguration timeCalcConfiguration; private final TimeCalcConfiguration timeCalcConfiguration;
private final TimeCalcApp timeCalcApp; private final TimeCalcApp timeCalcApp;
private final MainWindow window; private final MainWindow window;
private final Time time; private final Time time;
private boolean changeByOneHour = false;
public TimeCalcKeyAdapter( public TimeCalcKeyAdapter(
TimeCalcConfiguration timeCalcConfiguration, TimeCalcConfiguration timeCalcConfiguration,
TimeCalcApp timeCalcApp, TimeCalcApp timeCalcApp,
@ -69,6 +74,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
boolean increase = shiftDown; boolean increase = shiftDown;
boolean decrease = ctrlDown; boolean decrease = ctrlDown;
boolean reset = altDown; boolean reset = altDown;
TTime changeTTime = changeByOneHour ? T_TIME_ONE_HOUR : T_TIME_ONE_MINUTE;
switch (keyCode) { switch (keyCode) {
case KeyEvent.VK_Y: { case KeyEvent.VK_Y: {
//Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " year."); //Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " year.");
@ -115,23 +121,46 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
case KeyEvent.VK_A: { case KeyEvent.VK_A: {
//Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " millisecond."); //Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " millisecond.");
if (increase) { if (increase) {
window.increaseArrivalByOneMinute(); window.increaseArrival(changeTTime);
} }
if (decrease) { if (decrease) {
window.decreaseArrivalByOneMinute(); window.decreaseArrival(changeTTime);
} }
break; break;
} }
case KeyEvent.VK_O: { case KeyEvent.VK_O: {
//Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " millisecond."); //Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " millisecond.");
if (increase) { if (increase) {
window.increaseOvertimeByOneMinute(); window.increaseOvertime(changeTTime);
} }
if (decrease) { if (decrease) {
window.decreaseOvertimeByOneMinute(); window.decreaseOvertime(changeTTime);
} }
break; break;
} }
case KeyEvent.VK_W: {
if (increase) {
window.increaseWork(changeTTime);
}
if (decrease) {
window.decreaseWork(changeTTime);
}
break;
}
case KeyEvent.VK_P: {
if (increase) {
window.increasePause(changeTTime);
}
if (decrease) {
window.decreasePause(changeTTime);
}
break;
}
case KeyEvent.VK_C: {
this.changeByOneHour = increase;
Utils.showNotification("Time will be changed by 1 " + (increase ? "hour" : "minute") + ".");
break;
}
default: default:
// Utils.showNotification( // Utils.showNotification(
// "Unsupported key was pressed. There is no key shortcut for this key: " // "Unsupported key was pressed. There is no key shortcut for this key: "

View File

@ -58,8 +58,8 @@ public class MainWindow extends TWindow {
= new TimeCalcConfiguration(); = new TimeCalcConfiguration();
private final TTextField arrivalTextField; private final TTextField arrivalTextField;
private final TTextField overtimeTextField; private final TTextField overtimeTextField;
private final TTextField workingTimeInMinutesTextField; private final TTextField workingTimeTextField;
private final TTextField pauseTimeInMinutesTextField; private final TTextField pauseTimeTextField;
private final TTextField noteTextField; private final TTextField noteTextField;
private final TTextField departureTextField; private final TTextField departureTextField;
private final TTextField elapsedTextField; private final TTextField elapsedTextField;
@ -73,8 +73,8 @@ public class MainWindow extends TWindow {
{ {
this.arrivalTextField = new TTextField(); this.arrivalTextField = new TTextField();
this.overtimeTextField = new TTextField(); this.overtimeTextField = new TTextField();
this.workingTimeInMinutesTextField = new TTextField("480"); this.workingTimeTextField = new TTextField("8:00");
this.pauseTimeInMinutesTextField = new TTextField("30"); this.pauseTimeTextField = new TTextField("0:30");
this.noteTextField = new TTextField("", 160); this.noteTextField = new TTextField("", 160);
this.departureTextField = new TTextField(); this.departureTextField = new TTextField();
this.elapsedTextField = new TTextField("", 100); this.elapsedTextField = new TTextField("", 100);
@ -261,30 +261,32 @@ public class MainWindow extends TWindow {
TLabel workingTimeInMinutesTextFieldLabel = new TLabel("Work:", 40); TLabel workingTimeInMinutesTextFieldLabel = new TLabel("Work:", 40);
workingTimeInMinutesTextFieldLabel.setBoundsFromLeft(overtimeTextField); workingTimeInMinutesTextFieldLabel.setBoundsFromLeft(overtimeTextField);
workingTimeInMinutesTextField.setBoundsFromLeft(workingTimeInMinutesTextFieldLabel); workingTimeTextField.setBoundsFromLeft(workingTimeInMinutesTextFieldLabel);
// //
TLabel pauseTimeInMinutesFieldLabel = new TLabel("Pause:", 40); TLabel pauseTimeInMinutesFieldLabel = new TLabel("Pause:", 40);
pauseTimeInMinutesFieldLabel.setBoundsFromLeft(workingTimeInMinutesTextField); pauseTimeInMinutesFieldLabel.setBoundsFromLeft(workingTimeTextField);
pauseTimeInMinutesTextField.setBoundsFromLeft(pauseTimeInMinutesFieldLabel); pauseTimeTextField.setBoundsFromLeft(pauseTimeInMinutesFieldLabel);
// //
TLabel noteTextFieldLabel = new TLabel("Note:"); TLabel noteTextFieldLabel = new TLabel("Note:");
noteTextFieldLabel.setBoundsFromLeft(pauseTimeInMinutesTextField); noteTextFieldLabel.setBoundsFromLeft(pauseTimeTextField);
noteTextField.setBoundsFromLeft(noteTextFieldLabel); noteTextField.setBoundsFromLeft(noteTextFieldLabel);
//half day, pause time in minutes, note //half day, pause time in minutes, note
arrivalTextField.setEditable(false); arrivalTextField.setEditable(false);
overtimeTextField.setEditable(false); overtimeTextField.setEditable(false);
workingTimeTextField.setEditable(false);
pauseTimeTextField.setEditable(false);
add(arrivalTextFieldLabel); add(arrivalTextFieldLabel);
add(arrivalTextField); add(arrivalTextField);
add(overtimeTextFieldLabel); add(overtimeTextFieldLabel);
add(overtimeTextField); add(overtimeTextField);
add(workingTimeInMinutesTextFieldLabel); add(workingTimeInMinutesTextFieldLabel);
add(workingTimeInMinutesTextField); add(workingTimeTextField);
add(pauseTimeInMinutesFieldLabel); add(pauseTimeInMinutesFieldLabel);
add(pauseTimeInMinutesTextField); add(pauseTimeTextField);
add(noteTextFieldLabel); add(noteTextFieldLabel);
add(noteTextField); add(noteTextField);
// //
@ -620,16 +622,19 @@ public class MainWindow extends TWindow {
TTime startTime = null; TTime startTime = null;
TTime overtime = null; TTime overtime = null;
TTime workDuration = new TTime(workingTimeTextField.valueProperty.getValue());
TTime pauseDuration = new TTime(pauseTimeTextField.valueProperty.getValue());
try { try {
startTime = arrivalTextField.asTTime(); startTime = arrivalTextField.asTTime();
overtime = overtimeTextField.asTTime(); overtime = overtimeTextField.asTTime();
} catch (Exception e) { } catch (Exception e) {
} }
if (startTime == null || overtime == null) { if (startTime == null || overtime == null || workDuration == null || pauseDuration == null) {
return false; return false;
} }
TTime newDeparture = startTime.add(new TTime(8, 30));
TTime newDeparture = startTime.add(workDuration).add(pauseDuration);
if (overtime.isNegative()) { if (overtime.isNegative()) {
TTime tmpTTime = overtime.cloneInstance(); TTime tmpTTime = overtime.cloneInstance();
tmpTTime.setNegative(false); tmpTTime.setNegative(false);
@ -712,16 +717,12 @@ public class MainWindow extends TWindow {
// elapsedTextField.valueProperty.setValue(s + ":" + (secondNow < 10 ? "0" : "") + secondNow + ":" + (millisecondNow < 10 ? "00" : (millisecondNow < 100 ? "0" : millisecondNow)) + millisecondNow); // elapsedTextField.valueProperty.setValue(s + ":" + (secondNow < 10 ? "0" : "") + secondNow + ":" + (millisecondNow < 10 ? "00" : (millisecondNow < 100 ? "0" : millisecondNow)) + millisecondNow);
// } // }
TTime overtime = overtimeTextField.asTTime();
int hourDone = (int) (Constants.WORKING_HOURS_LENGTH + overtime.getHour()
- timeRemains.getHour());
int totalMillisecondsDone int totalMillisecondsDone
= timeElapsed.toTotalMilliseconds(); = timeElapsed.toTotalMilliseconds();
int totalHoursDone = totalMillisecondsDone / 1000 / 60 /60;
int totalMinutes = timeTotal.getMinute();
int totalMilliseconds = timeTotal.toTotalMilliseconds(); int totalMilliseconds = timeTotal.toTotalMilliseconds();
int totalMinutes = totalMilliseconds / 1000 / 60 ;
double done = ((double) totalMillisecondsDone) double done = ((double) totalMillisecondsDone)
/ ((double) totalMilliseconds); / ((double) totalMilliseconds);
@ -759,7 +760,7 @@ public class MainWindow extends TWindow {
if (!nowIsWeekend) { if (!nowIsWeekend) {
hourBattery.setLabel( hourBattery.setLabel(
hourDone + "/" + (totalMinutes / 60)); totalHoursDone + "/" + (totalMinutes / 60));
} }
minuteBattery.setDonePercent( minuteBattery.setDonePercent(
MinuteBattery.getMinuteProgress(secondNow, millisecondNow)); MinuteBattery.getMinuteProgress(secondNow, millisecondNow));
@ -859,21 +860,37 @@ public class MainWindow extends TWindow {
this.configWindow.doDisableAlmostEverything(); this.configWindow.doDisableAlmostEverything();
} }
public void increaseArrivalByOneMinute() { public void increaseArrival(TTime tTime) {
arrivalTextField.valueProperty.setValue(new TTime(this.arrivalTextField.valueProperty.getValue()).add(new TTime(0, 1)).toString().substring(0, 5)); arrivalTextField.valueProperty.setValue(new TTime(this.arrivalTextField.valueProperty.getValue()).add(tTime).toString().substring(0, 5));
} }
public void decreaseArrivalByOneMinute() { public void decreaseArrival(TTime tTime) {
arrivalTextField.valueProperty.setValue(new TTime(this.arrivalTextField.valueProperty.getValue()).remove(new TTime(0, 1)).toString().substring(0, 5)); arrivalTextField.valueProperty.setValue(new TTime(this.arrivalTextField.valueProperty.getValue()).remove(tTime).toString().substring(0, 5));
} }
public void increaseOvertimeByOneMinute() { public void increaseOvertime(TTime tTime) {
TTime newOvertime = new TTime(this.overtimeTextField.valueProperty.getValue()).add(new TTime(0, 1)); TTime newOvertime = new TTime(this.overtimeTextField.valueProperty.getValue()).add(tTime);
overtimeTextField.valueProperty.setValue(newOvertime.toString().substring(0, newOvertime.isNegative() ? 6 : 5)); overtimeTextField.valueProperty.setValue(newOvertime.toString().substring(0, newOvertime.isNegative() ? 6 : 5));
} }
public void decreaseOvertimeByOneMinute() { public void decreaseOvertime(TTime tTime) {
TTime newOvertime = new TTime(this.overtimeTextField.valueProperty.getValue()).remove(new TTime(0, 1)); TTime newOvertime = new TTime(this.overtimeTextField.valueProperty.getValue()).remove(tTime);
overtimeTextField.valueProperty.setValue(newOvertime.toString().substring(0, newOvertime.isNegative() ? 6 : 5)); overtimeTextField.valueProperty.setValue(newOvertime.toString().substring(0, newOvertime.isNegative() ? 6 : 5));
} }
public void increaseWork(TTime tTime) {
workingTimeTextField.valueProperty.setValue(new TTime(this.workingTimeTextField.valueProperty.getValue()).add(tTime).toString().substring(0, 5));
}
public void decreaseWork(TTime tTime) {
workingTimeTextField.valueProperty.setValue(new TTime(this.workingTimeTextField.valueProperty.getValue()).remove(tTime).toString().substring(0, 5));
}
public void increasePause(TTime tTime) {
pauseTimeTextField.valueProperty.setValue(new TTime(this.pauseTimeTextField.valueProperty.getValue()).add(tTime).toString().substring(0, 5));
}
public void decreasePause(TTime tTime) {
pauseTimeTextField.valueProperty.setValue(new TTime(this.pauseTimeTextField.valueProperty.getValue()).remove(tTime).toString().substring(0, 5));
}
} }

View File

@ -8,8 +8,6 @@ public class Constants {
public static final String DEFAULT_START_TIME = "7:00"; public static final String DEFAULT_START_TIME = "7:00";
public static final String DEFAULT_OVERTIME = "0:00"; public static final String DEFAULT_OVERTIME = "0:00";
public static final int WORKING_HOURS_LENGTH = 8;
public static final int WORKING_MINUTES_LENGTH = 30;
public static final String NEW_LINE = "\n"; public static final String NEW_LINE = "\n";
private Constants() { private Constants() {