diff --git a/Readme.md b/Readme.md index 68c1e9a..ea7024f 100644 --- a/Readme.md +++ b/Readme.md @@ -179,6 +179,7 @@ Smileys can be colored or white-black (can be set in configuration) * 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 +* CTRL + E - Save arrival, overtime, working time, pause time and note ## Command button diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcKeyAdapter.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcKeyAdapter.java index 51a24e3..75911f3 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcKeyAdapter.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcKeyAdapter.java @@ -5,6 +5,7 @@ import org.nanoboot.utils.timecalc.swing.common.MainWindow; import org.nanoboot.utils.timecalc.swing.progress.Time; import org.nanoboot.utils.timecalc.utils.common.FileConstants; import org.nanoboot.utils.timecalc.utils.common.Jokes; +import org.nanoboot.utils.timecalc.utils.common.TTime; import org.nanoboot.utils.timecalc.utils.common.Utils; import org.nanoboot.utils.timecalc.utils.property.IntegerProperty; @@ -14,7 +15,6 @@ import java.io.FileInputStream; import java.io.IOException; import java.util.Calendar; import java.util.Properties; -import org.nanoboot.utils.timecalc.utils.common.TTime; /** * @author Robert Vokac @@ -27,19 +27,19 @@ public class TimeCalcKeyAdapter extends KeyAdapter { private final TimeCalcConfiguration timeCalcConfiguration; private final TimeCalcApp timeCalcApp; - private final MainWindow window; + private final MainWindow mainWindow; private final Time time; private boolean changeByOneHour = false; public TimeCalcKeyAdapter( TimeCalcConfiguration timeCalcConfiguration, TimeCalcApp timeCalcApp, - MainWindow window, + MainWindow mainWindow, Time time ) { this.timeCalcConfiguration = timeCalcConfiguration; this.timeCalcApp = timeCalcApp; - this.window = window; + this.mainWindow = mainWindow; this.time = time; } @@ -48,16 +48,22 @@ public class TimeCalcKeyAdapter extends KeyAdapter { boolean shiftDown = e.isShiftDown(); boolean ctrlDown = e.isControlDown(); boolean altDown = e.isAltDown(); - boolean metaDown = e.isMetaDown(); - if (!shiftDown && !ctrlDown && !altDown) { + //boolean metaDown = e.isMetaDown(); + if (!shiftDown && !ctrlDown && !altDown /*&& !metaDown*/) { processKeyCode(keyCode); - } else { - processTestModeKeyCode(keyCode, shiftDown, ctrlDown, altDown); + } else + //if (!metaDown) + { + processShifCtrlAltModeKeyCodes(keyCode, shiftDown, ctrlDown, + altDown); } +// else { +// processMetaKeyCodes(keyCode); +// } //meta key ??? } - private void processTestModeKeyCode(int keyCode, boolean shiftDown, + private void processShifCtrlAltModeKeyCodes(int keyCode, boolean shiftDown, boolean ctrlDown, boolean altDown) { if (shiftDown && ctrlDown) { Utils.showNotification("Following key shortcut is not supported: SHIFT + CTRL"); @@ -119,40 +125,40 @@ public class TimeCalcKeyAdapter extends KeyAdapter { break; } case KeyEvent.VK_A: { - //Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " millisecond."); + if (increase) { - window.increaseArrival(changeTTime); + mainWindow.increaseArrival(changeTTime); } if (decrease) { - window.decreaseArrival(changeTTime); + mainWindow.decreaseArrival(changeTTime); } break; } case KeyEvent.VK_O: { - //Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " millisecond."); + if (increase) { - window.increaseOvertime(changeTTime); + mainWindow.increaseOvertime(changeTTime); } if (decrease) { - window.decreaseOvertime(changeTTime); + mainWindow.decreaseOvertime(changeTTime); } break; } case KeyEvent.VK_W: { if (increase) { - window.increaseWork(changeTTime); + mainWindow.increaseWork(changeTTime); } if (decrease) { - window.decreaseWork(changeTTime); + mainWindow.decreaseWork(changeTTime); } break; } case KeyEvent.VK_P: { if (increase) { - window.increasePause(changeTTime); + mainWindow.increasePause(changeTTime); } if (decrease) { - window.decreasePause(changeTTime); + mainWindow.decreasePause(changeTTime); } break; } @@ -161,6 +167,12 @@ public class TimeCalcKeyAdapter extends KeyAdapter { Utils.showNotification("Time will be changed by 1 " + (increase ? "hour" : "minute") + "."); break; } + case KeyEvent.VK_E: { + if(ctrlDown) { + mainWindow.doSaveButtonClick(); + } + break; + } default: // Utils.showNotification( // "Unsupported key was pressed. There is no key shortcut for this key: " @@ -168,6 +180,16 @@ public class TimeCalcKeyAdapter extends KeyAdapter { } } +// private void processMetaKeyCodes(int keyCode) { +// +// switch (keyCode) { +// case KeyEvent.VK_S: { +// +// break; +// } +// default: +// } +// } private void updateProperty(IntegerProperty integerProperty, boolean increase, boolean decrease, boolean reset, int timeUnit) { int currentValue = integerProperty.getValue(); @@ -402,11 +424,11 @@ public class TimeCalcKeyAdapter extends KeyAdapter { break; } case KeyEvent.VK_F2: { - window.doCommand(); + mainWindow.doCommand(); break; } case KeyEvent.VK_R: { - window.doRestart(); + mainWindow.doRestart(); break; } case KeyEvent.VK_N: { @@ -414,20 +436,20 @@ public class TimeCalcKeyAdapter extends KeyAdapter { break; } case KeyEvent.VK_W: { - window.openWorkDaysWindow(); + mainWindow.openWorkDaysWindow(); break; } case KeyEvent.VK_A: { - window.openActivitiesWindow(); + mainWindow.openActivitiesWindow(); break; } case KeyEvent.VK_X: { - window.doExit(); + mainWindow.doExit(); break; } case KeyEvent.VK_S: { - window.openConfigWindow(); + mainWindow.openConfigWindow(); break; } @@ -441,16 +463,16 @@ public class TimeCalcKeyAdapter extends KeyAdapter { case KeyEvent.VK_P: case KeyEvent.VK_F1: { - window.openHelpWindow(); + mainWindow.openHelpWindow(); break; } case KeyEvent.VK_U: { - window.doEnableEverything(); + mainWindow.doEnableEverything(); break; } case KeyEvent.VK_I: { - window.doDisableAlmostEverything(); + mainWindow.doDisableAlmostEverything(); break; } case KeyEvent.VK_E: { @@ -623,7 +645,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter { } } - window.repaint(); + mainWindow.repaint(); } private void switchProfile(boolean previous, boolean next) { diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/entity/WorkingDay.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/entity/WorkingDay.java index e6c3333..b33d1e4 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/entity/WorkingDay.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/entity/WorkingDay.java @@ -17,7 +17,7 @@ import lombok.ToString; @NoArgsConstructor public class WorkingDay { - public static final String NODATA = "nodata"; + private static final String NODATA = "nodata"; public static String createId(int year, int month, int day) { return (year + "-" + (month < 10 ? "0" : "") + month + "-" + (day < 10 ? "0" : "") + day); @@ -35,6 +35,10 @@ public class WorkingDay { private int workingTimeInMinutes; private int pauseTimeInMinutes; private String note; + private boolean timeOff; + public boolean isThisDayTimeOff() { + return timeOff || this.note.equals(NODATA); + } } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/entity/WorkingDayForStats.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/entity/WorkingDayForStats.java index 3d41cbd..92fcf9d 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/entity/WorkingDayForStats.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/entity/WorkingDayForStats.java @@ -28,6 +28,18 @@ public class WorkingDayForStats extends WorkingDay { private final TTime pause; private final TTime departure; + public static void fillStatisticsColumns(List list) { + //todo + } + public static List createList(List list) { + List result = new ArrayList<>(); + for (WorkingDay wd : list) { + WorkingDayForStats wdfs = new WorkingDayForStats(wd); + result.add(wdfs); + } + return result; + } + public WorkingDayForStats(WorkingDay workingDay) { this(workingDay.getId(), workingDay.getYear(), @@ -39,18 +51,19 @@ public class WorkingDayForStats extends WorkingDay { workingDay.getOvertimeMinute(), workingDay.getWorkingTimeInMinutes(), workingDay.getPauseTimeInMinutes(), - workingDay.getNote()); + workingDay.getNote(), + workingDay.isTimeOff()); } - public WorkingDayForStats(String id, int year, int month, int day, int arrivalHour, int arrivalMinute, int overtimeHour, int overtimeMinute, int workingTimeInMinutes, int pauseTimeInMinutes, String note) { - super(id, year, month, day, arrivalHour, arrivalMinute, overtimeHour, overtimeMinute, workingTimeInMinutes, pauseTimeInMinutes, note); - this.arrival = this.getNote().equals(WorkingDay.NODATA) ? null : new TTime(arrivalHour, arrivalMinute); - this.overtime = this.getNote().equals(WorkingDay.NODATA) ? null : new TTime(overtimeHour, overtimeMinute); - this.work = this.getNote().equals(WorkingDay.NODATA) ? null : TTime.ofMinutes(workingTimeInMinutes); - this.pause = this.getNote().equals(WorkingDay.NODATA) ? null : TTime.ofMinutes(pauseTimeInMinutes); - this.departure = this.getNote().equals(WorkingDay.NODATA) ? null : this.arrival.add(work).add(pause).add(overtime); - this.departureHour = this.getNote().equals(WorkingDay.NODATA) ? -1 : departure.getHour(); - this.departureMinute = this.getNote().equals(WorkingDay.NODATA) ? -1 : departure.getMinute(); + public WorkingDayForStats(String id, int year, int month, int day, int arrivalHour, int arrivalMinute, int overtimeHour, int overtimeMinute, int workingTimeInMinutes, int pauseTimeInMinutes, String note, boolean timeOff) { + super(id, year, month, day, arrivalHour, arrivalMinute, overtimeHour, overtimeMinute, workingTimeInMinutes, pauseTimeInMinutes, note, timeOff); + this.arrival = this.isThisDayTimeOff() ? null : new TTime(arrivalHour, arrivalMinute); + this.overtime = this.isThisDayTimeOff() ? null : new TTime(overtimeHour, overtimeMinute); + this.work = this.isThisDayTimeOff() ? null : TTime.ofMinutes(workingTimeInMinutes); + this.pause = this.isThisDayTimeOff() ? null : TTime.ofMinutes(pauseTimeInMinutes); + this.departure = this.isThisDayTimeOff() ? null : this.arrival.add(work).add(pause).add(overtime); + this.departureHour = this.isThisDayTimeOff() ? -1 : departure.getHour(); + this.departureMinute = this.isThisDayTimeOff() ? -1 : departure.getMinute(); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month - 1); @@ -59,13 +72,6 @@ public class WorkingDayForStats extends WorkingDay { this.dayOfWeek = dayOfWeek == 1 ? 7 : dayOfWeek - 1; } - public List createList(List list) { - List result = new ArrayList<>(); - for (WorkingDay wd : list) { - WorkingDayForStats wdfs = new WorkingDayForStats(wd); - } - return result; - } public String getDayOfWeekAsString() { return LocalDate.of(getYear(), getMonth() ,getDay()).getDayOfWeek().toString(); } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/persistence/api/WorkingDayRepositoryApi.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/persistence/api/WorkingDayRepositoryApi.java index 62a2fb2..7e0cd3d 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/persistence/api/WorkingDayRepositoryApi.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/persistence/api/WorkingDayRepositoryApi.java @@ -1,7 +1,10 @@ package org.nanoboot.utils.timecalc.persistence.api; import java.util.Calendar; + +import org.nanoboot.utils.timecalc.app.TimeCalcException; import org.nanoboot.utils.timecalc.entity.WorkingDay; +import org.nanoboot.utils.timecalc.utils.common.Utils; import java.util.List; @@ -29,5 +32,18 @@ public interface WorkingDayRepositoryApi { cal.get(Calendar.DAY_OF_MONTH) ); } - public List getYears(); + List getYears(); + void delete(int year, int month, int day); + default void delete(WorkingDay wd) { + delete(wd.getId()); + } + default void delete(String id) { + String[] array = id.split("-"); + if(array.length != 3) { + TimeCalcException e = new TimeCalcException("Invalid date: " + id); + Utils.showNotification(new TimeCalcException("Invalid date: " + id)); + throw e; + } + delete(Integer.parseInt(array[0]),Integer.parseInt(array[1]),Integer.parseInt(array[2])); + } } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/persistence/impl/sqlite/VersionTable.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/persistence/impl/sqlite/VersionTable.java index fd68e44..2fd1959 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/persistence/impl/sqlite/VersionTable.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/persistence/impl/sqlite/VersionTable.java @@ -22,7 +22,7 @@ package org.nanoboot.utils.timecalc.persistence.impl.sqlite; * * @author Robert Vokac */ -class VersionTable { +public class VersionTable { public static final String TABLE_NAME = "VERSION"; diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/persistence/impl/sqlite/WorkingDayRepositorySQLiteImpl.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/persistence/impl/sqlite/WorkingDayRepositorySQLiteImpl.java index d7d967d..d75ed78 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/persistence/impl/sqlite/WorkingDayRepositorySQLiteImpl.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/persistence/impl/sqlite/WorkingDayRepositorySQLiteImpl.java @@ -1,16 +1,16 @@ package org.nanoboot.utils.timecalc.persistence.impl.sqlite; +import org.nanoboot.utils.timecalc.app.TimeCalcException; +import org.nanoboot.utils.timecalc.entity.WorkingDay; +import org.nanoboot.utils.timecalc.persistence.api.WorkingDayRepositoryApi; +import org.nanoboot.utils.timecalc.utils.common.Utils; + import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; -import org.nanoboot.utils.timecalc.entity.WorkingDay; -import org.nanoboot.utils.timecalc.persistence.api.WorkingDayRepositoryApi; - import java.util.List; -import org.nanoboot.utils.timecalc.app.TimeCalcException; -import org.nanoboot.utils.timecalc.utils.common.Utils; /** * @author Robert Vokac @@ -35,7 +35,7 @@ public class WorkingDayRepositorySQLiteImpl implements WorkingDayRepositoryApi { sb .append("INSERT INTO ") .append(WorkingDayTable.TABLE_NAME) - .append(" VALUES (?,?,?,?, ?,?,?,?, ?,?,?)"); + .append(" VALUES (?,?,?,?, ?,?,?,?, ?,?,?,?)"); String sql = sb.toString(); @@ -56,6 +56,7 @@ public class WorkingDayRepositorySQLiteImpl implements WorkingDayRepositoryApi { stmt.setInt(++i, workingDay.getWorkingTimeInMinutes()); stmt.setInt(++i, workingDay.getPauseTimeInMinutes()); stmt.setString(++i, workingDay.getNote()); + stmt.setInt(++i, workingDay.isTimeOff() ? 1 : 0); // stmt.execute(); @@ -124,13 +125,20 @@ public class WorkingDayRepositorySQLiteImpl implements WorkingDayRepositoryApi { @Override public void update(WorkingDay workingDay) { - if(list(workingDay.getYear(), workingDay.getMonth(),workingDay.getDay()).isEmpty()) { + List list = + list(workingDay.getYear(), workingDay.getMonth(), + workingDay.getDay()); + if(list.isEmpty()) { create(workingDay); return; } System.out.println("Going to update: " + workingDay.toString()); + if(list.get(0).toString().equals(workingDay.toString())) { + System.out.println("Nothing to update."); + return; + } if(!Utils.askYesNo(null, "Do you want to update this Working Day? " + workingDay, "Update of Working Day")) { return; } @@ -145,7 +153,8 @@ public class WorkingDayRepositorySQLiteImpl implements WorkingDayRepositoryApi { .append(WorkingDayTable.OVERTIME_MINUTE).append("=?, ") .append(WorkingDayTable.WORKING_TIME_IN_MINUTES).append("=?, ") .append(WorkingDayTable.PAUSE_TIME_IN_MINUTES).append("=?, ") - .append(WorkingDayTable.NOTE).append("=? ") + .append(WorkingDayTable.NOTE).append("=?, ") + .append(WorkingDayTable.TIME_OFF).append("=? ") .append(" WHERE ").append( WorkingDayTable.ID).append("=?"); @@ -161,6 +170,7 @@ public class WorkingDayRepositorySQLiteImpl implements WorkingDayRepositoryApi { stmt.setInt(++i, workingDay.getWorkingTimeInMinutes()); stmt.setInt(++i, workingDay.getPauseTimeInMinutes()); stmt.setString(++i, workingDay.getNote()); + stmt.setInt(++i, workingDay.isTimeOff() ? 1 : 0); stmt.setString(++i, workingDay.getId()); @@ -193,7 +203,8 @@ public class WorkingDayRepositorySQLiteImpl implements WorkingDayRepositoryApi { rs.getInt(WorkingDayTable.OVERTIME_MINUTE), rs.getInt(WorkingDayTable.WORKING_TIME_IN_MINUTES), rs.getInt(WorkingDayTable.PAUSE_TIME_IN_MINUTES), - rs.getString(WorkingDayTable.NOTE) + rs.getString(WorkingDayTable.NOTE), + rs.getInt(WorkingDayTable.TIME_OFF) != 0 ); } @@ -236,4 +247,37 @@ public class WorkingDayRepositorySQLiteImpl implements WorkingDayRepositoryApi { return result; } + @Override + public void delete(int year, int month, int day) { + StringBuilder sb = new StringBuilder(); + sb + .append("DELETE ").append(" FROM ") + .append(WorkingDayTable.TABLE_NAME); + sb.append(" WHERE "); + sb.append(WorkingDayTable.YEAR).append("=? AND "); + sb.append(WorkingDayTable.MONTH).append("=? AND "); + ; + sb.append(WorkingDayTable.DAY).append("=? "); + ; + + String sql = sb.toString(); + int i = 0; + try ( + Connection connection = sqliteConnectionFactory + .createConnection(); + PreparedStatement stmt = connection.prepareStatement(sql);) { + stmt.setInt(++i, year); + stmt.setInt(++i, month); + stmt.setInt(++i, day); + stmt.execute(); + + } catch (SQLException e) { + System.out.println(e.getMessage()); + throw new RuntimeException(e); + } catch (ClassNotFoundException ex) { + System.out.println(ex.getMessage()); + throw new RuntimeException(ex); + } + } + } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/persistence/impl/sqlite/WorkingDayTable.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/persistence/impl/sqlite/WorkingDayTable.java index 61ce539..8f76157 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/persistence/impl/sqlite/WorkingDayTable.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/persistence/impl/sqlite/WorkingDayTable.java @@ -22,7 +22,7 @@ package org.nanoboot.utils.timecalc.persistence.impl.sqlite; * * @author Robert Vokac */ -class WorkingDayTable { +public class WorkingDayTable { public static final String TABLE_NAME = "WORKING_DAY"; @@ -38,6 +38,7 @@ class WorkingDayTable { public static final String WORKING_TIME_IN_MINUTES = "WORKING_TIME_IN_MINUTES"; public static final String PAUSE_TIME_IN_MINUTES = "PAUSE_TIME_IN_MINUTES"; public static final String NOTE = "NOTE"; + public static final String TIME_OFF = "TIME_OFF"; private WorkingDayTable() { //Not meant to be instantiated. diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/MainWindow.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/MainWindow.java index 84b3abc..72f2354 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/MainWindow.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/MainWindow.java @@ -64,9 +64,11 @@ public class MainWindow extends TWindow { private final TTextField workingTimeTextField; private final TTextField pauseTimeTextField; private final TTextField noteTextField; + private final TCheckBox timeOffCheckBox = new TCheckBox("Time off"); private final TTextField departureTextField; private final TTextField elapsedTextField; private final TTextField remainingTextField; + private final TButton saveButton; private HelpWindow helpWindow = null; private ConfigWindow configWindow = null; private ActivitiesWindow activitiesWindow = null; @@ -79,7 +81,7 @@ public class MainWindow extends TWindow { this.overtimeTextField = new TTextField(); this.workingTimeTextField = new TTextField("8:00"); this.pauseTimeTextField = new TTextField("0:30"); - this.noteTextField = new TTextField("", 160); + this.noteTextField = new TTextField("", 120); this.departureTextField = new TTextField(); this.elapsedTextField = new TTextField("", 100); this.remainingTextField = new TTextField("", 100); @@ -272,11 +274,12 @@ public class MainWindow extends TWindow { pauseTimeTextField.setBoundsFromLeft(pauseTimeInMinutesFieldLabel); // - TLabel noteTextFieldLabel = new TLabel("Note:"); + TLabel noteTextFieldLabel = new TLabel("Note:", 40); noteTextFieldLabel.setBoundsFromLeft(pauseTimeTextField); noteTextField.setBoundsFromLeft(noteTextFieldLabel); - //half day, pause time in minutes, note + timeOffCheckBox.setBoundsFromLeft(noteTextField); + // arrivalTextField.setEditable(false); overtimeTextField.setEditable(false); workingTimeTextField.setEditable(false); @@ -293,6 +296,7 @@ public class MainWindow extends TWindow { add(pauseTimeTextField); add(noteTextFieldLabel); add(noteTextField); + add(timeOffCheckBox); // TLabel departureTextFieldLabel = new TLabel("Departure:", 70); departureTextFieldLabel.setBoundsFromTop(arrivalTextFieldLabel); @@ -312,7 +316,7 @@ public class MainWindow extends TWindow { remainingTextField.setBoundsFromLeft(remainingTextFieldLabel); remainingTextField.setEditable(false); - TButton saveButton = new TButton("Save", 180); + this.saveButton = new TButton("Save", 180); saveButton.setBoundsFromLeft(remainingTextField); // @@ -601,29 +605,35 @@ public class MainWindow extends TWindow { workingDay.setWorkingTimeInMinutes(work_.toTotalMilliseconds() / 1000 / 60); workingDay.setPauseTimeInMinutes(pause_.toTotalMilliseconds() / 1000 / 60); workingDay.setNote(noteTextField.getText()); + workingDay.setTimeOff(timeOffCheckBox.isSelected()); workingDayRepository.update(workingDay); + if(workingDaysWindow != null) { + workingDaysWindow.doReloadButtonClick(); + } }); - WorkingDay workingDay = workingDayRepository.read(time.asCalendar()); + WorkingDay wd = workingDayRepository.read(time.asCalendar()); - if (workingDay != null) { - workingTimeTextField.valueProperty.setValue(TTime.ofMilliseconds(workingDay.getWorkingTimeInMinutes() * 60 * 1000).toString().substring(0, 5)); - pauseTimeTextField.valueProperty.setValue(TTime.ofMilliseconds(workingDay.getPauseTimeInMinutes() * 60 * 1000).toString().substring(0, 5)); - noteTextField.valueProperty.setValue(workingDay.getNote()); + if (wd != null) { + workingTimeTextField.valueProperty.setValue(TTime.ofMilliseconds(wd.getWorkingTimeInMinutes() * 60 * 1000).toString().substring(0, 5)); + pauseTimeTextField.valueProperty.setValue(TTime.ofMilliseconds(wd.getPauseTimeInMinutes() * 60 * 1000).toString().substring(0, 5)); + noteTextField.valueProperty.setValue(wd.getNote()); + timeOffCheckBox.setSelected(wd.isTimeOff()); } else { Calendar cal = time.asCalendar(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); - workingDay = new WorkingDay(); - workingDay.setId(WorkingDay.createId(year, month, day)); - workingDay.setYear(year); - workingDay.setMonth(month); - workingDay.setDay(day); - workingDay.setWorkingTimeInMinutes(480); - workingDay.setPauseTimeInMinutes(30); - workingDay.setNote(""); + wd = new WorkingDay(); + wd.setId(WorkingDay.createId(year, month, day)); + wd.setYear(year); + wd.setMonth(month); + wd.setDay(day); + wd.setWorkingTimeInMinutes(480); + wd.setPauseTimeInMinutes(30); + wd.setNote(""); + wd.setTimeOff(false); } TTime arrival_ = new TTime(arrivalTextField.getText()); TTime overtime_ = new TTime(overtimeTextField.getText()); @@ -635,17 +645,15 @@ public class MainWindow extends TWindow { // System.out.println("work_=" + work_); // System.out.println("pause_=" + pause_); - workingDay.setArrivalHour(arrival_.getHour()); - workingDay.setArrivalMinute(arrival_.getMinute()); + wd.setArrivalHour(arrival_.getHour()); + wd.setArrivalMinute(arrival_.getMinute()); - workingDay.setOvertimeHour(overtime_.getHour()); - workingDay.setOvertimeMinute(overtime_.getMinute()); + wd.setOvertimeHour(overtime_.getHour()); + wd.setOvertimeMinute(overtime_.getMinute()); - workingDayRepository.update(workingDay); - - //saveButton.doClick(); + workingDayRepository.update(wd); - System.out.println(workingDay); + System.out.println(wd); while (true) { if (updateWindow(timeCalcApp, time, clock, minuteBattery, hourBattery, @@ -967,6 +975,11 @@ public class MainWindow extends TWindow { } public void decreasePause(TTime tTime) { - pauseTimeTextField.valueProperty.setValue(new TTime(this.pauseTimeTextField.valueProperty.getValue()).remove(tTime).toString().substring(0, 5)); + pauseTimeTextField.valueProperty.setValue( + new TTime(this.pauseTimeTextField.valueProperty.getValue()) + .remove(tTime).toString().substring(0, 5)); + } + public void doSaveButtonClick(){ + this.saveButton.doClick(); } } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/WorkingDaysWindow.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/WorkingDaysWindow.java index 1907851..cd0e528 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/WorkingDaysWindow.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/WorkingDaysWindow.java @@ -24,23 +24,29 @@ import org.nanoboot.utils.timecalc.utils.common.TTime; * @since 16.02.2024 */ public class WorkingDaysWindow extends TWindow { + private static final String NO = "NO"; + private static final String YES = "YES"; + private static final String THREE_DASHES = "---"; + // + private static final Color RED = new Color(255,153,153); + public static final String E = "?"; private final WorkingDayRepositoryApi workingDayRepository; private final Time time; + private final JButton reloadButton; private JTable table = null; private final JScrollPane scrollPane; public WorkingDaysWindow(WorkingDayRepositoryApi workingDayRepository, Time time) { - setSize(800, 700); + setSize(1100, 700); setTitle("Work Days"); this.workingDayRepository = workingDayRepository; this.time = time; int year = time.yearProperty.getValue(); this.setLayout(null); - - + WorkingDaysWindow workingDaysWindow = this; List yearsList = workingDayRepository.getYears(); @@ -51,25 +57,43 @@ public class WorkingDaysWindow extends TWindow { JComboBox years = new JComboBox(yearsArray); years.setMaximumSize(new Dimension(150, 25)); - years.setSelectedItem(time.asCalendar().get(Calendar.YEAR)); + years.setSelectedItem(String.valueOf(year)); years.addActionListener(e -> { workingDaysWindow.loadYear(Integer.valueOf((String) years.getSelectedItem()), time); }); add(years); years.setBounds(SwingUtils.MARGIN,SwingUtils.MARGIN, 100, 30); - + + this.reloadButton = new JButton("Reload"); + reloadButton.addActionListener(e -> { + workingDaysWindow.loadYear(Integer.valueOf((String) years.getSelectedItem()), time); + }); + add(reloadButton); + reloadButton.setBounds(years.getX() + years.getWidth() + SwingUtils.MARGIN, years.getY(), 100, 30); + + JButton exitButton = new JButton("Exit"); exitButton.addActionListener(e -> { this.setVisible(false); }); add(exitButton); - exitButton.setBounds(years.getX() + years.getWidth() + SwingUtils.MARGIN, years.getY(), 100, 30); + exitButton.setBounds(reloadButton.getX() + reloadButton.getWidth() + SwingUtils.MARGIN, reloadButton.getY(), 100, 30); + TLabel deleteLabel = new TLabel("Delete:"); + add(deleteLabel); + deleteLabel.setBounds(exitButton.getX() + exitButton.getWidth() + SwingUtils.MARGIN, exitButton.getY(), 100, 30); + TTextField deleteTextField = new TTextField(); + add(deleteTextField); + deleteTextField.setBounds(deleteLabel.getX() + deleteLabel.getWidth() + SwingUtils.MARGIN, deleteLabel.getY(), 100, 30); + deleteTextField.addActionListener(e -> { + workingDayRepository.delete(deleteTextField.getText()); + reloadButton.doClick(); + }); this.scrollPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setBounds(SwingUtils.MARGIN, years.getY() + years.getHeight()+ SwingUtils.MARGIN, - getWidth() - 2 * SwingUtils.MARGIN, + getWidth() - 3 * SwingUtils.MARGIN, getHeight() - 4 * SwingUtils.MARGIN - 50); add(scrollPane); scrollPane.setViewportView(table); @@ -79,9 +103,12 @@ public class WorkingDaysWindow extends TWindow { } + public void doReloadButtonClick() { + this.reloadButton.doClick(); + } public void loadYear(int year, Time time) { - List list = new ArrayList<>(); + List workingDaysList = new ArrayList<>(); Calendar now = time.asCalendar(); final int currentYear = now.get(Calendar.YEAR); final int currentMonth = now.get(Calendar.MONTH) + 1; @@ -99,9 +126,9 @@ public class WorkingDaysWindow extends TWindow { WorkingDay wd = workingDayRepository.read(year, month, day); if (wd == null) { - wd = new WorkingDay(WorkingDay.createId(year, month,day), year, month, day, -1, -1, -1, -1, -1, -1, WorkingDay.NODATA); + wd = new WorkingDay(WorkingDay.createId(year, month,day), year, month, day, -1, -1, -1, -1, -1, -1, "Fictive day", true); } - list.add(wd); + workingDaysList.add(wd); // System.out.println("year=" + year); // System.out.println("month=" + month); @@ -116,31 +143,46 @@ public class WorkingDaysWindow extends TWindow { break; } } + + List wdfsList = WorkingDayForStats.createList(workingDaysList); + WorkingDayForStats.fillStatisticsColumns(wdfsList); + List> listForArray = new ArrayList<>(); - for (WorkingDay wd : list) { - ArrayList l = new ArrayList<>(); - listForArray.add(l); - WorkingDayForStats wdfs = new WorkingDayForStats(wd); - if (wdfs.getNote().equals(WorkingDay.NODATA)) { - l.add(wdfs.getDayOfWeekAsString()); - l.add(wdfs.getDayOfWeek() == 6 || wdfs.getDayOfWeek() == 7 ? YES : NO); - l.add(wdfs.getId()); - l.add(THREE_DASHES); - l.add(THREE_DASHES); - l.add(THREE_DASHES); - l.add(THREE_DASHES); - l.add(THREE_DASHES); - l.add(wdfs.getNote()); + for (WorkingDayForStats wdfs : wdfsList) { + ArrayList list2 = new ArrayList<>(); + listForArray.add(list2); + if (wdfs.isThisDayTimeOff()) { + list2.add(wdfs.getDayOfWeekAsString()); + list2.add(wdfs.getDayOfWeek() == 6 || wdfs.getDayOfWeek() == 7 ? YES : NO); + list2.add(wdfs.getId()); + list2.add(THREE_DASHES); + list2.add(THREE_DASHES); + list2.add(THREE_DASHES); + list2.add(THREE_DASHES); + list2.add(THREE_DASHES); + list2.add(wdfs.getNote()); + list2.add(wdfs.isTimeOff() ? YES : NO); + list2.add(E); + list2.add(E); + list2.add(E); + list2.add(E); + list2.add(E); } else { - l.add(wdfs.getDayOfWeekAsString()); - l.add(wdfs.getDayOfWeek() == 6 || wdfs.getDayOfWeek() == 7 ? YES : NO); - l.add(wdfs.getId()); - l.add(new TTime(wdfs.getArrivalHour(), wdfs.getArrivalMinute()).toString().substring(0, 5)); - l.add(new TTime(wdfs.getDepartureHour(), wdfs.getDepartureMinute()).toString().substring(0, 5)); - l.add(new TTime(wdfs.getOvertimeHour(), wdfs.getOvertimeMinute()).toString().substring(0, 5)); - l.add(TTime.ofMinutes(wdfs.getWorkingTimeInMinutes()).toString().substring(0, 5)); - l.add(TTime.ofMinutes(wdfs.getPauseTimeInMinutes()).toString().substring(0, 5)); - l.add(wdfs.getNote()); + list2.add(wdfs.getDayOfWeekAsString()); + list2.add(wdfs.getDayOfWeek() == 6 || wdfs.getDayOfWeek() == 7 ? YES : NO); + list2.add(wdfs.getId()); + list2.add(new TTime(wdfs.getArrivalHour(), wdfs.getArrivalMinute()).toString().substring(0, 5)); + list2.add(new TTime(wdfs.getDepartureHour(), wdfs.getDepartureMinute()).toString().substring(0, 5)); + list2.add(new TTime(wdfs.getOvertimeHour(), wdfs.getOvertimeMinute()).toString().substring(0, 5)); + list2.add(TTime.ofMinutes(wdfs.getWorkingTimeInMinutes()).toString().substring(0, 5)); + list2.add(TTime.ofMinutes(wdfs.getPauseTimeInMinutes()).toString().substring(0, 5)); + list2.add(wdfs.getNote()); + list2.add(wdfs.isTimeOff() ? YES : NO); + list2.add(E); + list2.add(E); + list2.add(E); + list2.add(E); + list2.add(E); } } @@ -154,7 +196,7 @@ public class WorkingDaysWindow extends TWindow { data[index] = data2; index++; } - String[] columns = new String[] {"Day of Week", "Weekend", "Date","Arrival","Departure","Overtime","Working time","Pause time","Note"}; + String[] columns = new String[] {"Day of Week", "Weekend", "Date","Arrival","Departure","Overtime","Working time","Pause time","Note", "Time off", "Total overtime", "Arrival MA7", "Arrival MA14", "Arrival MA28", "Arrival MA56"}; if(table != null) { scrollPane.remove(table); @@ -220,12 +262,5 @@ public class WorkingDaysWindow extends TWindow { } - private static final String NO = "NO"; - private static final String YES = "YES"; - private static final String THREE_DASHES = "---"; - private static final String TD_END = ""; - private static final String TD_START = ""; - private static final String TH_END = ""; - private static final String TH_START = ""; - private Color RED = new Color(255,153,153); + } \ No newline at end of file diff --git a/modules/time-calc-app/src/main/resources/help/Readme.md b/modules/time-calc-app/src/main/resources/help/Readme.md index 0c19281..196a3c6 100644 --- a/modules/time-calc-app/src/main/resources/help/Readme.md +++ b/modules/time-calc-app/src/main/resources/help/Readme.md @@ -13,13 +13,13 @@ _Time Calc is written in Java programming language and uses the Swing framework. ### Start of application When "Time Calc" is started", user is asked for: - - start time ... like 7:30 - - overtime ... like 0:45 ... overtime is optional and the default value is 0:00 +- start time ... like 7:30 +- overtime ... like 0:45 ... overtime is optional and the default value is 0:00 ### Restart of application You can restart the app, if you press the **"Restart"** button. - - Then you are asked again for start time and overtime. +- Then you are asked again for start time and overtime. ### End of application @@ -33,7 +33,7 @@ If these files are present, something special happens. ### .tc/starttime.txt -This file contains the default start time - used during the previous run of the app. +This file contains the default start time - used during the previous run of the app. If file starttime.txt does not exist, then the default start time is 7:00. ### .tc/overtime.txt @@ -64,29 +64,29 @@ Optional assignments of profiles to numbers is stored here. ### 3 Visibility modes - * STRONGLY_COLORED - many colors - * WEAKLY_COLORED - darkened colors - * GRAY - gray colors - * NONE - widgets are hidden +* STRONGLY_COLORED - many colors +* WEAKLY_COLORED - darkened colors +* GRAY - gray colors +* NONE - widgets are hidden ### Widgets #### Analog Clock - * hour hand - * minute hand (can be disabled in configuration) - * second hand (can be disabled in configuration) - * millisecond hand (can be disabled in configuration) - * shows current year, month, day of month and day of week, if analog clock is hovered by mouse cursor and Visibility is STRONGLY_COLORED - * shows yellow highlighted remaining time until end of today working hours, if analog clock is hovered by mouse cursor and Visibility is STRONGLY_COLORED - * hands can be long or shorter (can be set in configuration) +* hour hand +* minute hand (can be disabled in configuration) +* second hand (can be disabled in configuration) +* millisecond hand (can be disabled in configuration) +* shows current year, month, day of month and day of week, if analog clock is hovered by mouse cursor and Visibility is STRONGLY_COLORED +* shows yellow highlighted remaining time until end of today working hours, if analog clock is hovered by mouse cursor and Visibility is STRONGLY_COLORED +* hands can be long or shorter (can be set in configuration) #### Progress Square - * Show graphically day progress +* Show graphically day progress #### Progress Circle - * Show graphically day progress +* Show graphically day progress #### Hour Battery @@ -169,21 +169,28 @@ 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 * ALT + {Y,N,D,H,M,S or I} - Rest test time value * D - Reset custom time values to the real time -* SHIFT + A - Increase arrival time by 1 minute -* CTRL + A - Decrease arrival time by 1 minute -* SHIFT + O - Increase overtime by 1 minute -* CTRL + O - Decrease overtime by 1 minute +* SHIFT + A - Increase arrival time +* CTRL + A - Decrease arrival time +* SHIFT + O - Increase overtime +* 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 +* CTRL + E - Save arrival, overtime, working time, pause time and note ## Command button ## Todos - * Split to Maven modules - * Junit, Mockito, etc. - * Checkstyle - * Sonarlint - * Sonarqube - * Add SQLite support and store times of arrivals and departures and time of activities +* Split to Maven modules +* Junit, Mockito, etc. +* Checkstyle +* Sonarlint +* Sonarqube +* Add SQLite support and store times of arrivals and departures and time of activities ## For Developers