diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcApp.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcApp.java index 745d014..62beddd 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcApp.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcApp.java @@ -1,7 +1,6 @@ package org.nanoboot.utils.timecalc.app; import java.io.File; -import java.io.FileInputStream; import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.swing.windows.MainWindow; import org.nanoboot.utils.timecalc.utils.common.DateFormats; 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 8e2e672..2c94382 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 @@ -16,6 +16,8 @@ import java.io.FileInputStream; import java.io.IOException; import java.util.Calendar; import java.util.Properties; +import lombok.Setter; +import org.nanoboot.utils.timecalc.utils.common.NumberFormats; /** * @author Robert Vokac @@ -28,6 +30,8 @@ public class TimeCalcKeyAdapter extends KeyAdapter { private final MainWindow mainWindow; private final Time time; private boolean changeByFiveMinutes = false; + @Setter + private int msToAdd = 1; public TimeCalcKeyAdapter( TimeCalcConfiguration timeCalcConfiguration, @@ -61,7 +65,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter { //meta key ??? } - private void processShifCtrlAltModeKeyCodes(int keyCode, boolean shiftDown, + public void processShifCtrlAltModeKeyCodes(int keyCode, boolean shiftDown, boolean ctrlDown, boolean altDown) { if (shiftDown && ctrlDown) { Utils.showNotification("Following key shortcut is not supported: SHIFT + CTRL"); @@ -120,6 +124,36 @@ public class TimeCalcKeyAdapter extends KeyAdapter { //Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " millisecond."); updateProperty(timeCalcConfiguration.testMillisecondCustomProperty, increase, decrease, reset, Calendar.MILLISECOND); + break; + } + + case KeyEvent.VK_U: { + int ms_ = msToAdd; + int s_ = msToAdd / 1000; + ms_ = ms_ - s_ * 1000; + int m_ = msToAdd / 1000 / 60; + ms_ = ms_ - m_ * 1000 * 60; + int h_ = msToAdd / 1000 / 60 / 60; + ms_ = ms_ - h_ * 1000 * 60 * 60; + int d_ = msToAdd / 1000 / 60 / 60 / 24; + ms_ = ms_ - d_ * 1000 * 60 * 60 * 24; + //Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " second."); + updateProperty(timeCalcConfiguration.testDayCustomProperty, increase, decrease, reset, + Calendar.DAY_OF_MONTH, d_); + updateProperty(timeCalcConfiguration.testHourCustomProperty, increase, decrease, reset, + Calendar.HOUR_OF_DAY, h_); + updateProperty(timeCalcConfiguration.testMinuteCustomProperty, increase, decrease, reset, + Calendar.MINUTE, m_); + updateProperty(timeCalcConfiguration.testSecondCustomProperty, increase, decrease, reset, + Calendar.SECOND, s_); + updateProperty(timeCalcConfiguration.testMillisecondCustomProperty, increase, decrease, reset, + Calendar.MILLISECOND, ms_); + + + + + + break; } case KeyEvent.VK_K: { @@ -130,6 +164,36 @@ public class TimeCalcKeyAdapter extends KeyAdapter { } break; } + case KeyEvent.VK_Q: { + double oldSpeed = this.mainWindow.getSpeed(); + if(oldSpeed < 0) { + oldSpeed = 1.0d; + } + if(increase) { + this.mainWindow.increaseSpeed(); + } + if(decrease) { + this.mainWindow.decreaseSpeed(); + } + if(reset) { + this.mainWindow.resetSpeed(); + } + final double newSpeed = this.mainWindow.getSpeed(); + + if(oldSpeed != newSpeed) { + Utils.showNotification("Speed was changed from " + + ((int)oldSpeed) + + " to: " + ((int)newSpeed) + " (" + (NumberFormats.FORMATTER_TWO_DECIMAL_PLACES.format(Math.pow(2, newSpeed))) + ") (" + (newSpeed <= 21 ? TTime.ofMilliseconds(((int)(Math.pow(2,newSpeed) * 1000))) : "many") +" /1s)"); + } else { + if(decrease){ + Utils.showNotification("Current speed cannot be decreased: " + + NumberFormats.FORMATTER_TWO_DECIMAL_PLACES.format(oldSpeed)); + } + } + + break; + } + case KeyEvent.VK_A: { if (increase) { @@ -198,6 +262,14 @@ public class TimeCalcKeyAdapter extends KeyAdapter { // } private void updateProperty(IntegerProperty integerProperty, boolean increase, boolean decrease, boolean reset, int timeUnit) { + updateProperty(integerProperty, increase, decrease, reset, timeUnit, 1); + } + private void updateProperty(IntegerProperty integerProperty, + boolean increase, boolean decrease, boolean reset, int timeUnit, int value) { + if(value == 0) { + //nothing to do + return; + } int currentValue = integerProperty.getValue(); if ((increase || decrease) && currentValue == Integer.MAX_VALUE) { @@ -235,7 +307,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter { int oldMinute = cal.get(Calendar.MINUTE); int oldSecond = cal.get(Calendar.SECOND); int oldMillisecond = cal.get(Calendar.MILLISECOND); - cal.add(timeUnit, increase ? 1 : (-1)); + cal.add(timeUnit, increase ? value : (-value)); int newValue = cal.get(timeUnit); if (Calendar.MONTH == timeUnit) { newValue++; @@ -330,7 +402,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter { } - private void processKeyCode(int keyCode) { + public void processKeyCode(int keyCode) { boolean onlyGreyOrNone = timeCalcConfiguration.visibilitySupportedColoredProperty .isDisabled(); @@ -548,6 +620,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter { timeCalcConfiguration.testSecondCustomProperty.setValue(Integer.MAX_VALUE); timeCalcConfiguration.testMillisecondCustomProperty.setValue(Integer.MAX_VALUE); Utils.showNotification(timeCalcConfiguration.print(), 15000, 400); + this.mainWindow.resetSpeed(); break; } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/WalkingHumanProgress.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/WalkingHumanProgress.java index fe3329b..c4394a9 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/WalkingHumanProgress.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/WalkingHumanProgress.java @@ -33,8 +33,10 @@ public class WalkingHumanProgress extends Widget implements private static final String WALL = "||"; private final Set alreadyShownPercents = new HashSet<>(); private static final int LINE_WHERE_HEAD_IS = 2; + private final MainWindow mainWindow; - public WalkingHumanProgress() { + public WalkingHumanProgress(MainWindow mainWindow) { + this.mainWindow = mainWindow; setFont(new Font(Font.MONOSPACED, Font.PLAIN, 11)); setFocusable(false); @@ -135,14 +137,16 @@ public class WalkingHumanProgress extends Widget implements } catch (Exception e) { System.out.println(e); } - if (image != null) { - // toasterManager.setToasterWidth(600); - // toasterManager.setToasterHeight(400); - toasterManager.showToaster(new ImageIcon(image), - "Progress: " + (percentInt) + "%"); - } else { - toasterManager.setToasterHeight(200); - toasterManager.showToaster("Progress: " + (percentInt) + "%"); + if (this.mainWindow.getSpeed() == 0) { + if (image != null) { + // toasterManager.setToasterWidth(600); + // toasterManager.setToasterHeight(400); + toasterManager.showToaster(new ImageIcon(image), + "Progress: " + (percentInt) + "%"); + } else { + toasterManager.setToasterHeight(200); + toasterManager.showToaster("Progress: " + (percentInt) + "%"); + } } } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/windows/MainWindow.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/windows/MainWindow.java index 7efa2d5..af38566 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/windows/MainWindow.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/windows/MainWindow.java @@ -55,6 +55,7 @@ import javax.swing.JCheckBox; import javax.swing.JFrame; import java.awt.Color; import java.awt.Component; +import java.awt.event.KeyEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyVetoException; import java.io.File; @@ -67,6 +68,7 @@ import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.stream.Collectors; +import javax.swing.Timer; import org.nanoboot.utils.timecalc.swing.progress.ProgressDot; /** @@ -116,6 +118,8 @@ public class MainWindow extends TWindow { private final IntegerProperty forgetOvertimeProperty = new IntegerProperty("forgetOvertimeProperty", 0); private WeekStatistics weekStatistics = null; private final ProgressDot progressDot; + private int speed = Integer.MIN_VALUE; + private final TimeCalcKeyAdapter timeCalcKeyAdapter; { ChangeListener valueMustBeTime = @@ -208,7 +212,7 @@ public class MainWindow extends TWindow { } Toaster.notificationsVisibleProperty.bindTo(timeCalcConfiguration.notificationsVisibleProperty); - TimeCalcKeyAdapter timeCalcKeyAdapter + this.timeCalcKeyAdapter = new TimeCalcKeyAdapter(timeCalcConfiguration, timeCalcApp, this, time); addKeyListener(timeCalcKeyAdapter); @@ -282,7 +286,7 @@ public class MainWindow extends TWindow { add(yearBattery); WalkingHumanProgress walkingHumanProgress - = new WalkingHumanProgress(); + = new WalkingHumanProgress(this); walkingHumanProgress.setBounds(minuteBattery.getX(), minuteBattery.getY() + minuteBattery.getHeight(), 400, 80); add(walkingHumanProgress); @@ -820,6 +824,40 @@ public class MainWindow extends TWindow { workingDayRepository.update(wd); + new Timer(100, e -> { + if(speed == Integer.MIN_VALUE) { + timeCalcConfiguration.testEnabledProperty.setValue(false); + return; + } + if(timeCalcConfiguration.testEnabledProperty.isDisabled()) { + timeCalcConfiguration.testEnabledProperty.enable(); + } + if(time.yearCustomProperty.getValue() == Integer.MAX_VALUE) { + time.yearCustomProperty.setValue(time.yearProperty.getValue()); + } + if(time.monthCustomProperty.getValue() == Integer.MAX_VALUE) { + time.monthCustomProperty.setValue(time.monthProperty.getValue()); + } + if(time.dayCustomProperty.getValue() == Integer.MAX_VALUE) { + time.dayCustomProperty.setValue(time.dayProperty.getValue()); + } + if(time.hourCustomProperty.getValue() == Integer.MAX_VALUE) { + time.hourCustomProperty.setValue(time.hourProperty.getValue()); + } + if(time.minuteCustomProperty.getValue() == Integer.MAX_VALUE) { + time.minuteCustomProperty.setValue(time.minuteProperty.getValue()); + } + if(time.secondCustomProperty.getValue() == Integer.MAX_VALUE) { + time.secondCustomProperty.setValue(time.secondProperty.getValue()); + } + if(time.millisecondCustomProperty.getValue() == Integer.MAX_VALUE) { + time.millisecondCustomProperty.setValue(time.millisecondProperty.getValue()); + } + int msShouldBeAdded = (int) (Math.pow(2, speed) * 100d); + this.timeCalcKeyAdapter.setMsToAdd(msShouldBeAdded); + this.timeCalcKeyAdapter.processShifCtrlAltModeKeyCodes(KeyEvent.VK_U, true, false, false); + + }).start(); while (true) { if(Math.random() > 0.99) { @@ -1230,4 +1268,29 @@ public class MainWindow extends TWindow { } public int getForgetOvertime() {return this.forgetOvertimeProperty.getValue();} public void setForgetOvertime(int minutes) {this.forgetOvertimeProperty.setValue(minutes);} + public void increaseSpeed() { + if(speed == Integer.MIN_VALUE) { + speed = 0; + } + ++this.speed; + } + + public void decreaseSpeed() { + if(speed == Integer.MIN_VALUE) { + speed = 0; + } + if(speed == -3){ + //nothing to do + return; + } + --this.speed; + } + + public int getSpeed() { + return speed; + } + + public void resetSpeed() { + this.speed = Integer.MIN_VALUE; + } }