From ed6c6070d9a165eac00b10bc30c68e8a24b8b3fb Mon Sep 17 00:00:00 2001 From: Robert Vokac Date: Sat, 10 Feb 2024 13:41:43 +0000 Subject: [PATCH] Time improvements - wip4 --- ...lcConf.java => TimeCalcConfiguration.java} | 159 ++++++++++-------- .../utils/timecalc/app/TimeCalcManager.java | 8 +- .../timecalc/app/TimeCalcProperties.java | 85 ++++++++++ .../timecalc/swing/progress/AnalogClock.java | 35 ++-- .../timecalc/swing/progress/Battery.java | 4 +- .../utils/timecalc/utils/common/Jokes.java | 4 +- timecalc.conf | 6 +- 7 files changed, 205 insertions(+), 96 deletions(-) rename modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/{TimeCalcConf.java => TimeCalcConfiguration.java} (53%) create mode 100644 modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperties.java diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcConf.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcConfiguration.java similarity index 53% rename from modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcConf.java rename to modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcConfiguration.java index 4eb9954..edbf214 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcConf.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcConfiguration.java @@ -1,74 +1,85 @@ -package org.nanoboot.utils.timecalc.app; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.Properties; - -/** - * @author Robert Vokac - * @since 20.02.2024 - */ -public class TimeCalcConf { - private static final String CLOCK_HANDS_LONG = "clock.hands.long"; - private static final String JOKE_VISIBLE = "jokes.visible"; - private static final String BATTERY_WAVES_ENABLED = "battery.waves.enabled"; - private static final String EVERYTHING_HIDDEN = "everything-hidden"; - private static final String TOASTS_ENABLED = "toasts.enabled"; - - private static TimeCalcConf INSTANCE; - private final Properties properties = new Properties(); - - private TimeCalcConf() { - if (!new File("timecalc.conf").exists()) { - //nothing to do; - return; - } - try { - this.properties.load(new FileInputStream("timecalc.conf")); - } catch (IOException e) { - System.err.println(e); - } - } - - public static TimeCalcConf getInstance() { - if (INSTANCE == null) { - INSTANCE = new TimeCalcConf(); - } - return INSTANCE; - } - - public boolean areClockHandsLong() { - return getBooleanProperty(CLOCK_HANDS_LONG, true); - } - - public boolean isJokeVisible() { - return getBooleanProperty(JOKE_VISIBLE, true); - } - - public boolean areBatteryWavesEnabled() { - return getBooleanProperty(BATTERY_WAVES_ENABLED, true); - } - - public boolean isEverythingHidden() { - return getBooleanProperty(EVERYTHING_HIDDEN, false); - } - - public boolean areToastsEnabled() { - return getBooleanProperty(TOASTS_ENABLED, true); - } - - private boolean getBooleanProperty(String key, boolean defaultValue) { - if (!properties.containsKey(key)) { - return defaultValue; - } - return properties.get(key).equals("true"); - } - public void load() { - //to be implemented - } - public void save() { - //to be implemented - } - -} +package org.nanoboot.utils.timecalc.app; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Properties; + +/** + * @author Robert Vokac + * @since 20.02.2024 + */ +public class TimeCalcProperties { + private static final String CLOCK_HANDS_LONG = "clock.hands.long"; + private static final String CLOCK_HANDS_SECOND_ENABLED = "clock.hands.second.enabled"; + private static final String CLOCK_HANDS_MILLISECOND_ENABLED = "clock.hands.millisecond.enabled"; + private static final String BATTERY_WAVES_ENABLED = "battery.waves.enabled"; + private static final String DEFAULT_VISIBILITY = "default-visibility"; + private static final String VISIBILITY_ONLY_GREY_OR_NONE_ENABLED = "visibility.only-grey-or-none.enabled"; + private static final String JOKES_ENABLED = "jokes.enabled"; + private static final String COMMANDS_ENABLED = "commands-enabled"; + private static final String TOASTS_ENABLED = "toasts.enabled"; + + private static TimeCalcProperties INSTANCE; + private final Properties properties = new Properties(); + + private TimeCalcProperties() { + if (!new File("timecalc.conf").exists()) { + //nothing to do; + return; + } + try { + this.properties.load(new FileInputStream("timecalc.conf")); + } catch (IOException e) { + System.err.println(e); + } + if(!isSecondEnabled() && isMillisecondEnabled()) { + System.out.println("Sorry, seconds are disabled, millisecond must be disabled too."); + this.properties.setProperty(TimeCalcProperties.CLOCK_HANDS_MILLISECOND_ENABLED, "false"); + } + } + + public static TimeCalcProperties getInstance() { + if (INSTANCE == null) { + INSTANCE = new TimeCalcProperties(); + } + return INSTANCE; + } + + public boolean areClockHandsLong() { + return getBooleanProperty(CLOCK_HANDS_LONG, true); + } + + public boolean isSecondEnabled() { + return getBooleanProperty(CLOCK_HANDS_SECOND_ENABLED, true); + } + public boolean isMillisecondEnabled() { + return getBooleanProperty(CLOCK_HANDS_MILLISECOND_ENABLED, false); + } + + public boolean areJokesEnabled() { + return getBooleanProperty(COMMANDS_ENABLED, true); + } + + public boolean areBatteryWavesEnabled() { + return getBooleanProperty(BATTERY_WAVES_ENABLED, true); + } + + public boolean areToastsEnabled() { + return getBooleanProperty(TOASTS_ENABLED, true); + } + + private boolean getBooleanProperty(String key, boolean defaultValue) { + if (!properties.containsKey(key)) { + return defaultValue; + } + return properties.get(key).equals("true"); + } + public void load() { + //to be implemented + } + public void save() { + //to be implemented + } + +} diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcManager.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcManager.java index 83b3423..5e2834e 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcManager.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcManager.java @@ -261,7 +261,7 @@ public class TimeCalcManager { } catch (IOException rex) { Logger.getLogger(TimeCalcManager.class.getName()).log(Level.SEVERE, null, rex); } - System.out.println("current dir=" + new File(".").getAbsolutePath()); + if(testProperties.containsKey("current.day")) { calNow.set(Calendar.DAY_OF_MONTH, Integer.parseInt((String) testProperties.get("current.day"))); analogClock.dayProperty.setValue(Integer.valueOf((String) testProperties.get("current.day"))); @@ -310,6 +310,10 @@ public class TimeCalcManager { } else { analogClock.millisecondProperty.bindTo(time.millisecondProperty); } + analogClock.millisecondEnabledProperty.setValue( + TimeCalcProperties.getInstance().isMillisecondEnabled()); + analogClock.secondEnabledProperty.setValue( + TimeCalcProperties.getInstance().isSecondEnabled()); window.add(analogClock); @@ -462,7 +466,7 @@ public class TimeCalcManager { exitButton.setOriginalForeground(); } jokeButton.setVisible( - TimeCalcConf.getInstance().isJokeVisible() + TimeCalcProperties.getInstance().areJokesEnabled() && !visibility.isNone()); window.setTitle(visibility.isNone() ? "" : windowTitle); diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperties.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperties.java new file mode 100644 index 0000000..edbf214 --- /dev/null +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperties.java @@ -0,0 +1,85 @@ +package org.nanoboot.utils.timecalc.app; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Properties; + +/** + * @author Robert Vokac + * @since 20.02.2024 + */ +public class TimeCalcProperties { + private static final String CLOCK_HANDS_LONG = "clock.hands.long"; + private static final String CLOCK_HANDS_SECOND_ENABLED = "clock.hands.second.enabled"; + private static final String CLOCK_HANDS_MILLISECOND_ENABLED = "clock.hands.millisecond.enabled"; + private static final String BATTERY_WAVES_ENABLED = "battery.waves.enabled"; + private static final String DEFAULT_VISIBILITY = "default-visibility"; + private static final String VISIBILITY_ONLY_GREY_OR_NONE_ENABLED = "visibility.only-grey-or-none.enabled"; + private static final String JOKES_ENABLED = "jokes.enabled"; + private static final String COMMANDS_ENABLED = "commands-enabled"; + private static final String TOASTS_ENABLED = "toasts.enabled"; + + private static TimeCalcProperties INSTANCE; + private final Properties properties = new Properties(); + + private TimeCalcProperties() { + if (!new File("timecalc.conf").exists()) { + //nothing to do; + return; + } + try { + this.properties.load(new FileInputStream("timecalc.conf")); + } catch (IOException e) { + System.err.println(e); + } + if(!isSecondEnabled() && isMillisecondEnabled()) { + System.out.println("Sorry, seconds are disabled, millisecond must be disabled too."); + this.properties.setProperty(TimeCalcProperties.CLOCK_HANDS_MILLISECOND_ENABLED, "false"); + } + } + + public static TimeCalcProperties getInstance() { + if (INSTANCE == null) { + INSTANCE = new TimeCalcProperties(); + } + return INSTANCE; + } + + public boolean areClockHandsLong() { + return getBooleanProperty(CLOCK_HANDS_LONG, true); + } + + public boolean isSecondEnabled() { + return getBooleanProperty(CLOCK_HANDS_SECOND_ENABLED, true); + } + public boolean isMillisecondEnabled() { + return getBooleanProperty(CLOCK_HANDS_MILLISECOND_ENABLED, false); + } + + public boolean areJokesEnabled() { + return getBooleanProperty(COMMANDS_ENABLED, true); + } + + public boolean areBatteryWavesEnabled() { + return getBooleanProperty(BATTERY_WAVES_ENABLED, true); + } + + public boolean areToastsEnabled() { + return getBooleanProperty(TOASTS_ENABLED, true); + } + + private boolean getBooleanProperty(String key, boolean defaultValue) { + if (!properties.containsKey(key)) { + return defaultValue; + } + return properties.get(key).equals("true"); + } + public void load() { + //to be implemented + } + public void save() { + //to be implemented + } + +} diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/AnalogClock.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/AnalogClock.java index 34365f5..f48fef5 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/AnalogClock.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/AnalogClock.java @@ -2,7 +2,7 @@ package org.nanoboot.utils.timecalc.swing.progress; import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.swing.common.Widget; -import org.nanoboot.utils.timecalc.app.TimeCalcConf; +import org.nanoboot.utils.timecalc.app.TimeCalcProperties; import org.nanoboot.utils.timecalc.utils.common.DateFormats; import org.nanoboot.utils.timecalc.utils.common.TimeHM; @@ -16,7 +16,8 @@ import java.awt.Graphics2D; import java.awt.RenderingHints; import java.util.Calendar; import java.util.Date; -import java.util.GregorianCalendar; + +import org.nanoboot.utils.timecalc.utils.property.BooleanProperty; import org.nanoboot.utils.timecalc.utils.property.IntegerProperty; //https://kodejava.org/how-do-i-write-a-simple-analog-clock-using-java-2d/ @@ -40,7 +41,9 @@ public class AnalogClock extends Widget { public IntegerProperty minuteProperty = new IntegerProperty("minuteProperty"); public IntegerProperty secondProperty = new IntegerProperty("secondProperty"); public IntegerProperty millisecondProperty = new IntegerProperty("millisecondProperty"); - public IntegerProperty dayOfWeekProperty = new IntegerProperty("dayOfWeek"); + public IntegerProperty dayOfWeekProperty = new IntegerProperty("dayOfWeekProperty"); + public BooleanProperty secondEnabledProperty = new BooleanProperty("secondEnabledProperty", true); + public BooleanProperty millisecondEnabledProperty = new BooleanProperty("millisecondEnabledProperty", false); public AnalogClock(TimeHM startTimeIn, TimeHM endTimeIn) { @@ -125,27 +128,33 @@ public class AnalogClock extends Widget { drawClockFace(g2d, centerX, centerY, side / 2 - 40, visibility); // - drawHand(g2d, side / 2 - 10, millisecond / 1000.0, 1.0f, - COLOR_FOR_MILLISECOND_HAND_STRONGLY_COLORED, visibility); - - if (TimeCalcConf.getInstance().areClockHandsLong()) { - drawHand(g2d, (side / 2 - 10) / 4, - (millisecond > 500 ? millisecond - 500 : millisecond + 500) / 1000.0, 1.0f, + if(millisecondEnabledProperty.isEnabled()) { + drawHand(g2d, side / 2 - 10, millisecond / 1000.0, 1.0f, COLOR_FOR_MILLISECOND_HAND_STRONGLY_COLORED, visibility); + + if (TimeCalcProperties.getInstance().areClockHandsLong()) { + drawHand(g2d, (side / 2 - 10) / 4, + (millisecond > 500 ? millisecond - 500 : + millisecond + 500) / 1000.0, 1.0f, + COLOR_FOR_MILLISECOND_HAND_STRONGLY_COLORED, + visibility); + } } - // + + if(secondEnabledProperty.isEnabled()) { drawHand(g2d, side / 2 - 10, second / 60.0, 0.5f, Color.RED, visibility); - if (TimeCalcConf.getInstance().areClockHandsLong()) { + if (TimeCalcProperties.getInstance().areClockHandsLong()) { drawHand(g2d, (side / 2 - 10) / 4, (second > 30 ? second - 30 : second + 30) / 60.0, 0.5f, Color.RED, visibility); } + } // double minutes = minute / 60.0 + second / 60.0 / 60.0; drawHand(g2d, side / 2 - 20, minutes, 2.0f, Color.BLUE, visibility); - if (TimeCalcConf.getInstance().areClockHandsLong()) { + if (TimeCalcProperties.getInstance().areClockHandsLong()) { drawHand(g2d, (side / 2 - 20) / 4, minutes + minutes > 0.5 ? minutes - 0.5 : minutes + (minutes > 0.5 ? (-1) : 1) * 0.5, 2.0f, @@ -156,7 +165,7 @@ public class AnalogClock extends Widget { drawHand(g2d, side / 2 - 40, hours, 4.0f, Color.BLACK, visibility); - if (TimeCalcConf.getInstance().areClockHandsLong()) { + if (TimeCalcProperties.getInstance().areClockHandsLong()) { drawHand(g2d, (side / 2 - 40) / 4, hours + hours > 0.5 ? hours - 0.5 : hours + (hours > 0.5 ? (-1) : 1) * 0.5, 4.0f, diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/Battery.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/Battery.java index 6c86ba8..819837b 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/Battery.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/Battery.java @@ -3,7 +3,7 @@ package org.nanoboot.utils.timecalc.swing.progress; import lombok.Getter; import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.swing.common.Widget; -import org.nanoboot.utils.timecalc.app.TimeCalcConf; +import org.nanoboot.utils.timecalc.app.TimeCalcProperties; import org.nanoboot.utils.timecalc.utils.property.BooleanProperty; import org.nanoboot.utils.timecalc.utils.common.NumberFormats; import org.nanoboot.utils.timecalc.utils.common.Utils; @@ -101,7 +101,7 @@ public class Battery extends Widget { 1;//donePercent < 0.5 ? 0.5 : donePercent;// (donePercent * 100 - ((int)(donePercent * 100))); int waterSurfaceHeight = (int) (4 * surfacePower);//2 + (int) (Math.random() * 3); - if (waterSurfaceHeight <= 2 || !TimeCalcConf.getInstance() + if (waterSurfaceHeight <= 2 || !TimeCalcProperties.getInstance() .areBatteryWavesEnabled() || wavesProperty.isDisabled()) { waterSurfaceHeight = 0; } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/Jokes.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/Jokes.java index 61f25b3..631e7aa 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/Jokes.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/Jokes.java @@ -1,7 +1,7 @@ package org.nanoboot.utils.timecalc.utils.common; import org.nanoboot.utils.timecalc.swing.common.Toaster; -import org.nanoboot.utils.timecalc.app.TimeCalcConf; +import org.nanoboot.utils.timecalc.app.TimeCalcProperties; import javax.swing.JFrame; import javax.swing.JTextPane; @@ -63,7 +63,7 @@ public class Jokes { } public static void showRandom() { - if(!TimeCalcConf.getInstance().isJokeVisible()) { + if(!TimeCalcProperties.getInstance().areJokesEnabled()) { //nothing to do return; } diff --git a/timecalc.conf b/timecalc.conf index 4e08fad..12c85ae 100644 --- a/timecalc.conf +++ b/timecalc.conf @@ -1,9 +1,9 @@ clock.hands.long=true clock.hands.second.enabled=true -clock.hands.millisecond.enabled=false -jokes.visible=true +clock.hands.millisecond.enabled=true battery.waves.enabled=true default-visibility=STRONGLY_COLORED visibility.only-grey-or-none.enabled=false jokes.enabled=true -commands.enabled=true \ No newline at end of file +commands.enabled=true +toasts.enabled=true \ No newline at end of file