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 0683ec9..b6f8bc0 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 @@ -3,8 +3,6 @@ package org.nanoboot.utils.timecalc.app; import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.utils.common.Constants; import org.nanoboot.utils.timecalc.utils.common.FileConstants; -import org.nanoboot.utils.timecalc.utils.property.BooleanProperty; -import org.nanoboot.utils.timecalc.utils.property.ReadOnlyProperty; import org.nanoboot.utils.timecalc.utils.property.StringProperty; import org.nanoboot.utils.timecalc.utils.common.Utils; @@ -19,8 +17,6 @@ public class TimeCalcApp { private long startNanoTime = 0l; public StringProperty visibilityProperty = new StringProperty("timeCalcApp.visibilityReadWriteProperty", Visibility.WEAKLY_COLORED.name()); - public BooleanProperty - wavesProperty = new BooleanProperty("waves", true); public void start(String[] args) throws IOException { if(startNanoTime != 0l) { diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcConfiguration.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcConfiguration.java index edbf214..aae1edd 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcConfiguration.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcConfiguration.java @@ -1,5 +1,9 @@ package org.nanoboot.utils.timecalc.app; +import org.nanoboot.utils.timecalc.entity.Visibility; +import org.nanoboot.utils.timecalc.utils.property.BooleanProperty; +import org.nanoboot.utils.timecalc.utils.property.StringProperty; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -9,77 +13,32 @@ 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"; +public class TimeCalcConfiguration { + public final BooleanProperty clockHandLongProperty = new BooleanProperty("clockHandLongProperty", true); + public final BooleanProperty clockHandSecondEnabledProperty = new BooleanProperty("clockHandSecondEnabledProperty", true); + public final BooleanProperty clockHandMillisecondEnabledProperty = new BooleanProperty("clockHandMillisecondEnabledProperty", false); + public final BooleanProperty batteryWavesEnabledProperty = new BooleanProperty("batteryWavesEnabledProperty", true); + public final StringProperty + defaultVisibilityProperty = new StringProperty("defaultVisibilityProperty", + Visibility.STRONGLY_COLORED.name()); + public final BooleanProperty visibilityOnlyGreyOrNoneEnabledProperty = new BooleanProperty("visibilityOnlyGreyOrNoneEnabledProperty", false); + public final BooleanProperty jokesEnabledProperty = new BooleanProperty("jokesEnabledProperty", true); + public final BooleanProperty commandsEnabledProperty = new BooleanProperty("commandsEnabledProperty", true); + public final BooleanProperty toastsEnabledProperty = new BooleanProperty("toastsEnabledProperty", true); - private static TimeCalcProperties INSTANCE; - private final Properties properties = new Properties(); + public TimeCalcConfiguration() { - 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 + public void setFromTimeCalcProperties(TimeCalcProperties timeCalcProperties) { + clockHandLongProperty.setValue(timeCalcProperties.areClockHandsLong()); + clockHandSecondEnabledProperty.setValue(timeCalcProperties.isSecondEnabled()); + clockHandMillisecondEnabledProperty.setValue(timeCalcProperties.isMillisecondEnabled()); + batteryWavesEnabledProperty.setValue(timeCalcProperties.areBatteryWavesEnabled()); + defaultVisibilityProperty.setValue(timeCalcProperties.getDefaultVisibility().name()); + visibilityOnlyGreyOrNoneEnabledProperty.setValue(timeCalcProperties.isVisibilityOnlyGreyOrNoneEnabled()); + jokesEnabledProperty.setValue(timeCalcProperties.areJokesEnabled()); + commandsEnabledProperty.setValue(timeCalcProperties.areCommandsEnabled()); + toastsEnabledProperty.setValue(timeCalcProperties.areToastsEnabled()); } } 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 5e2834e..c06ff66 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 @@ -60,10 +60,12 @@ public class TimeCalcManager { private final TimeCalcApp timeCalcApp; private boolean stopBeforeEnd = false; private Time time = new Time(); + private TimeCalcConfiguration timeCalcConfiguration = new TimeCalcConfiguration(); public TimeCalcManager(String startTimeIn, String overTimeIn, TimeCalcApp timeCalcApp) { this.timeCalcApp = timeCalcApp; + timeCalcConfiguration.setFromTimeCalcProperties(TimeCalcProperties.getInstance()); // Utils.everythingHidden // .setValue(TimeCalcConf.getInstance().isEverythingHidden()); // Utils.toastsAreEnabled @@ -205,7 +207,7 @@ public class TimeCalcManager { timeCalcApp.visibilityProperty.setValue(commandsAsArray[1].equals("1") ? Visibility.GRAY.name() : Visibility.WEAKLY_COLORED.name()); break; case "waves": - timeCalcApp.wavesProperty.setValue(commandsAsArray[1].equals("1")); + timeCalcConfiguration.batteryWavesEnabledProperty.setValue(commandsAsArray[1].equals("1")); break; case "uptime": JOptionPane.showMessageDialog(null, @@ -310,11 +312,8 @@ public class TimeCalcManager { } else { analogClock.millisecondProperty.bindTo(time.millisecondProperty); } - analogClock.millisecondEnabledProperty.setValue( - TimeCalcProperties.getInstance().isMillisecondEnabled()); - analogClock.secondEnabledProperty.setValue( - TimeCalcProperties.getInstance().isSecondEnabled()); - + analogClock.millisecondEnabledProperty.bindTo(timeCalcConfiguration.clockHandMillisecondEnabledProperty); + analogClock.secondEnabledProperty.bindTo(timeCalcConfiguration.clockHandSecondEnabledProperty); window.add(analogClock); @@ -386,10 +385,10 @@ public class TimeCalcManager { weekBattery.setBounds(hourBattery.getX(), hourBattery.getY() + hourBattery.getHeight() + MARGIN, hourBattery.getWidth(), hourBattery.getHeight()); monthBattery.setBounds(hourBattery.getX() + hourBattery.getWidth() + MARGIN, hourBattery.getY() + hourBattery.getHeight() + MARGIN, hourBattery.getWidth(), hourBattery.getHeight()); - hourBattery.wavesProperty.bindTo(timeCalcApp.wavesProperty.asReadOnlyProperty()); - dayBattery.wavesProperty.bindTo(timeCalcApp.wavesProperty.asReadOnlyProperty()); - weekBattery.wavesProperty.bindTo(timeCalcApp.wavesProperty.asReadOnlyProperty()); - monthBattery.wavesProperty.bindTo(timeCalcApp.wavesProperty.asReadOnlyProperty()); + hourBattery.wavesProperty.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty); + dayBattery.wavesProperty.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty); + weekBattery.wavesProperty.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty); + monthBattery.wavesProperty.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty); ComponentRegistry componentRegistry = new ComponentRegistry(); componentRegistry.addAll( 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 index edbf214..4ddc4a0 100644 --- 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 @@ -1,5 +1,7 @@ package org.nanoboot.utils.timecalc.app; +import org.nanoboot.utils.timecalc.entity.Visibility; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -69,6 +71,20 @@ public class TimeCalcProperties { return getBooleanProperty(TOASTS_ENABLED, true); } + public Visibility getDefaultVisibility() { + if (!properties.containsKey(DEFAULT_VISIBILITY)) { + return Visibility.STRONGLY_COLORED; + } + return Visibility.valueOf((String) properties.get(DEFAULT_VISIBILITY)); + } + + public boolean isVisibilityOnlyGreyOrNoneEnabled() { + return getBooleanProperty(VISIBILITY_ONLY_GREY_OR_NONE_ENABLED, false); + } + + public Boolean areCommandsEnabled() { + return getBooleanProperty(COMMANDS_ENABLED, true); + } private boolean getBooleanProperty(String key, boolean defaultValue) { if (!properties.containsKey(key)) { return defaultValue; @@ -81,5 +97,4 @@ public class TimeCalcProperties { public void save() { //to be implemented } - } diff --git a/timecalc.conf b/timecalc.conf index 12c85ae..2c88070 100644 --- a/timecalc.conf +++ b/timecalc.conf @@ -1,6 +1,6 @@ clock.hands.long=true clock.hands.second.enabled=true -clock.hands.millisecond.enabled=true +clock.hands.millisecond.enabled=false battery.waves.enabled=true default-visibility=STRONGLY_COLORED visibility.only-grey-or-none.enabled=false