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

@ -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);
@ -128,26 +127,28 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
} }
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;
int d_ = totalMs / 1000 / 60 / 60 / 24;
totalMs = totalMs - d_ * 1000 * 60 * 60 * 24;
if (negative && (increase || decrease)) { 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,
@ -187,16 +188,20 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
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));
} }
} }
@ -273,6 +278,7 @@ 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) {
@ -673,8 +679,8 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
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);
} }

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;