Added some improvements

This commit is contained in:
Robert Vokac 2024-03-24 13:14:34 +01:00
parent d8f6796a76
commit 9afa86c0d9
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
2 changed files with 56 additions and 45 deletions

View File

@ -32,7 +32,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
private boolean changeByFiveMinutes = false; private boolean changeByFiveMinutes = false;
@Setter @Setter
private int msToAdd = 1; private int msToAdd = 1;
public TimeCalcKeyAdapter( public TimeCalcKeyAdapter(
TimeCalcConfiguration timeCalcConfiguration, TimeCalcConfiguration timeCalcConfiguration,
TimeCalcApp timeCalcApp, TimeCalcApp timeCalcApp,
@ -53,8 +53,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
//boolean metaDown = e.isMetaDown(); //boolean metaDown = e.isMetaDown();
if (!shiftDown && !ctrlDown && !altDown /*&& !metaDown*/) { if (!shiftDown && !ctrlDown && !altDown /*&& !metaDown*/) {
processKeyCode(keyCode); processKeyCode(keyCode);
} else } else //if (!metaDown)
//if (!metaDown)
{ {
processShifCtrlAltModeKeyCodes(keyCode, shiftDown, ctrlDown, processShifCtrlAltModeKeyCodes(keyCode, shiftDown, ctrlDown,
altDown); altDown);
@ -126,28 +125,30 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
Calendar.MILLISECOND); Calendar.MILLISECOND);
break; break;
} }
case KeyEvent.VK_U: { case KeyEvent.VK_U: {
int ms_ = msToAdd; int totalMs = msToAdd;
boolean negative = false; boolean negative = false;
if(ms_ < 0) { if (totalMs < 0) {
ms_ = Math.abs(ms_); totalMs = Math.abs(totalMs);
negative = true; negative = true;
} }
//System.out.println("going to add ms:" +msToAdd); //System.out.println("going to add ms:" +msToAdd);
int s_ = msToAdd / 1000; int ms_ = totalMs % 1000;
ms_ = ms_ - s_ * 1000; totalMs = totalMs - ms_;
int m_ = msToAdd / 1000 / 60; int s_ = totalMs / 1000 % 60;
ms_ = ms_ - m_ * 1000 * 60; totalMs = totalMs - s_ * 1000;
int h_ = msToAdd / 1000 / 60 / 60; int m_ = totalMs / 1000 / 60 % 60;
ms_ = ms_ - h_ * 1000 * 60 * 60; totalMs = totalMs - m_ * 1000 * 60;
int d_ = msToAdd / 1000 / 60 / 60 / 24; int h_ = totalMs / 1000 / 60 / 60 % 60;
ms_ = ms_ - d_ * 1000 * 60 * 60 * 24; totalMs = totalMs - h_ * 1000 * 60 * 60;
if(negative && (increase || decrease)) { int d_ = totalMs / 1000 / 60 / 60 / 24;
totalMs = totalMs - d_ * 1000 * 60 * 60 * 24;
if (negative && (increase || decrease)) {
increase = false; increase = false;
decrease = true; decrease = true;
} }
//Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " second.");
updateProperty(timeCalcConfiguration.testDayCustomProperty, increase, decrease, reset, updateProperty(timeCalcConfiguration.testDayCustomProperty, increase, decrease, reset,
Calendar.DAY_OF_MONTH, d_); Calendar.DAY_OF_MONTH, d_);
updateProperty(timeCalcConfiguration.testHourCustomProperty, increase, decrease, reset, updateProperty(timeCalcConfiguration.testHourCustomProperty, increase, decrease, reset,
@ -170,36 +171,40 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
} }
case KeyEvent.VK_Q: { case KeyEvent.VK_Q: {
double oldSpeed = this.mainWindow.getSpeed(); double oldSpeed = this.mainWindow.getSpeed();
if(oldSpeed < 0) { if (oldSpeed < 0) {
oldSpeed = 1.0d; oldSpeed = 1.0d;
} }
if(increase) { if (increase) {
this.mainWindow.increaseSpeed(); this.mainWindow.increaseSpeed();
} }
if(decrease) { if (decrease) {
this.mainWindow.decreaseSpeed(); this.mainWindow.decreaseSpeed();
} }
if(reset) { if (reset) {
this.mainWindow.resetSpeed(); this.mainWindow.resetSpeed();
} }
final double newSpeed = this.mainWindow.getSpeed(); final double newSpeed = this.mainWindow.getSpeed();
if(oldSpeed != newSpeed) { if (oldSpeed != newSpeed) {
final double msDouble = Math.pow(2,newSpeed) * 1000; final double msDouble = Math.pow(2, newSpeed) * 1000;
TTime t= TTime.ofMilliseconds(((int)msDouble)); TTime t = TTime.ofMilliseconds(((int) msDouble));
Utils.showNotification("Speed was changed from " + Utils.showNotification("Speed was changed from "
((int)oldSpeed) + + ((int) oldSpeed)
" to: " + ((int)newSpeed) + " (" + (NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES.format(Math.pow(2, newSpeed))) + ") (" + + " to: " + ((int) newSpeed) + " (" + (NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES.format(Math.pow(2, newSpeed))) + ") ("
(newSpeed <= -10 ? (NumberFormats.FORMATTER_SIX_DECIMAL_PLACES.format(msDouble) + "ms") : (/*newSpeed <=21*/ t.getHour() < 24 ? t : ((long)(msDouble / 1000d / 60d / 60d / 24d) + " days"))) + (newSpeed <= -10 ? (NumberFormats.FORMATTER_SIX_DECIMAL_PLACES.format(msDouble) + "ms") : (/*newSpeed <=21*/t.getHour() < 24 ? t : ((long) (msDouble / 1000d / 60d / 60d / 24d) + " days")))
+" /1s)"); + " /1s)");
} else { } else {
if(decrease){ if (decrease) {
Utils.showNotification("Current speed cannot be decreased: " + Utils.showNotification("Current speed cannot be decreased: "
NumberFormats.FORMATTER_TWO_DECIMAL_PLACES.format(oldSpeed)); + NumberFormats.FORMATTER_TWO_DECIMAL_PLACES.format(oldSpeed));
}
if (increase) {
Utils.showNotification("Current speed cannot be increased: "
+ NumberFormats.FORMATTER_TWO_DECIMAL_PLACES.format(oldSpeed));
} }
} }
break; break;
} }
@ -247,7 +252,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
break; break;
} }
case KeyEvent.VK_E: { case KeyEvent.VK_E: {
if(ctrlDown) { if (ctrlDown) {
mainWindow.doSaveButtonClick(); mainWindow.doSaveButtonClick();
} }
break; break;
@ -273,9 +278,10 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
boolean increase, boolean decrease, boolean reset, int timeUnit) { boolean increase, boolean decrease, boolean reset, int timeUnit) {
updateProperty(integerProperty, increase, decrease, reset, timeUnit, 1); updateProperty(integerProperty, increase, decrease, reset, timeUnit, 1);
} }
private void updateProperty(IntegerProperty integerProperty, private void updateProperty(IntegerProperty integerProperty,
boolean increase, boolean decrease, boolean reset, int timeUnit, int value) { boolean increase, boolean decrease, boolean reset, int timeUnit, int value) {
if(value == 0) { if (value == 0) {
//nothing to do //nothing to do
return; return;
} }
@ -668,19 +674,19 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
mainWindow.getForgetOvertime() mainWindow.getForgetOvertime()
); );
int newForgetOvertimeInt = -1; int newForgetOvertimeInt = -1;
if(newForgetOvertime != null) { if (newForgetOvertime != null) {
if(newForgetOvertime.contains(":")) { if (newForgetOvertime.contains(":")) {
newForgetOvertimeInt = new TTime(newForgetOvertime).toTotalMilliseconds() / 1000 / 60; newForgetOvertimeInt = new TTime(newForgetOvertime).toTotalMilliseconds() / 1000 / 60;
} else { } else {
try { try {
newForgetOvertimeInt = newForgetOvertimeInt
Integer.parseInt(newForgetOvertime); = Integer.parseInt(newForgetOvertime);
} catch (Exception e) { } catch (Exception e) {
Utils.showNotification(e); Utils.showNotification(e);
} }
} }
} }
if(newForgetOvertimeInt >= 0) { if (newForgetOvertimeInt >= 0) {
mainWindow.setForgetOvertime(newForgetOvertimeInt); mainWindow.setForgetOvertime(newForgetOvertimeInt);
} else { } else {
Utils.showNotification("Error:Forget overtime must not be less than zero."); Utils.showNotification("Error:Forget overtime must not be less than zero.");
@ -688,13 +694,13 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
break; break;
} }
case KeyEvent.VK_SLASH: { case KeyEvent.VK_SLASH: {
if(timeCalcConfiguration.testEnabledProperty.isDisabled()) { if (timeCalcConfiguration.testEnabledProperty.isDisabled()) {
if(!Utils.askYesNo(null, "Do you really want to enable \"Test mode\"? If yes, then you will be allowed to set custom time.", "Enabling \"Test mode\"")) { if (!Utils.askYesNo(null, "Do you really want to enable \"Test mode\"? If yes, then you will be allowed to set custom time.", "Enabling \"Test mode\"")) {
break; break;
} }
} }
timeCalcConfiguration.testEnabledProperty.flip(); timeCalcConfiguration.testEnabledProperty.flip();
Utils.showNotification((timeCalcConfiguration.testEnabledProperty.isEnabled()? "Enabled" : "Disabled") + " \"Test mode\"."); Utils.showNotification((timeCalcConfiguration.testEnabledProperty.isEnabled() ? "Enabled" : "Disabled") + " \"Test mode\".");
break; break;
} }
case KeyEvent.VK_COMMA: { case KeyEvent.VK_COMMA: {

View File

@ -1321,6 +1321,10 @@ public class MainWindow extends TWindow {
if (speed == Integer.MIN_VALUE) { if (speed == Integer.MIN_VALUE) {
speed = 0; speed = 0;
} }
if (speed == MAX_SPEED) {
//nothing to do
return;
}
++this.speed; ++this.speed;
timeCalcConfiguration.speedProperty.setValue(this.speed); timeCalcConfiguration.speedProperty.setValue(this.speed);
} }
@ -1337,6 +1341,7 @@ public class MainWindow extends TWindow {
timeCalcConfiguration.speedProperty.setValue(this.speed); timeCalcConfiguration.speedProperty.setValue(this.speed);
} }
public static final int MIN_SPEED = -10; public static final int MIN_SPEED = -10;
public static final int MAX_SPEED = 25;
public int getSpeed() { public int getSpeed() {
return speed; return speed;