Time improvements - wip5

This commit is contained in:
Robert Vokac 2024-02-10 13:46:01 +00:00
parent ed6c6070d9
commit 70bc18f173
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
5 changed files with 53 additions and 84 deletions

View File

@ -3,8 +3,6 @@ package org.nanoboot.utils.timecalc.app;
import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.entity.Visibility;
import org.nanoboot.utils.timecalc.utils.common.Constants; import org.nanoboot.utils.timecalc.utils.common.Constants;
import org.nanoboot.utils.timecalc.utils.common.FileConstants; 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.property.StringProperty;
import org.nanoboot.utils.timecalc.utils.common.Utils; import org.nanoboot.utils.timecalc.utils.common.Utils;
@ -19,8 +17,6 @@ public class TimeCalcApp {
private long startNanoTime = 0l; private long startNanoTime = 0l;
public StringProperty visibilityProperty = new StringProperty("timeCalcApp.visibilityReadWriteProperty", Visibility.WEAKLY_COLORED.name()); 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 { public void start(String[] args) throws IOException {
if(startNanoTime != 0l) { if(startNanoTime != 0l) {

View File

@ -1,5 +1,9 @@
package org.nanoboot.utils.timecalc.app; 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.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
@ -9,77 +13,32 @@ import java.util.Properties;
* @author Robert Vokac * @author Robert Vokac
* @since 20.02.2024 * @since 20.02.2024
*/ */
public class TimeCalcProperties { public class TimeCalcConfiguration {
private static final String CLOCK_HANDS_LONG = "clock.hands.long"; public final BooleanProperty clockHandLongProperty = new BooleanProperty("clockHandLongProperty", true);
private static final String CLOCK_HANDS_SECOND_ENABLED = "clock.hands.second.enabled"; public final BooleanProperty clockHandSecondEnabledProperty = new BooleanProperty("clockHandSecondEnabledProperty", true);
private static final String CLOCK_HANDS_MILLISECOND_ENABLED = "clock.hands.millisecond.enabled"; public final BooleanProperty clockHandMillisecondEnabledProperty = new BooleanProperty("clockHandMillisecondEnabledProperty", false);
private static final String BATTERY_WAVES_ENABLED = "battery.waves.enabled"; public final BooleanProperty batteryWavesEnabledProperty = new BooleanProperty("batteryWavesEnabledProperty", true);
private static final String DEFAULT_VISIBILITY = "default-visibility"; public final StringProperty
private static final String VISIBILITY_ONLY_GREY_OR_NONE_ENABLED = "visibility.only-grey-or-none.enabled"; defaultVisibilityProperty = new StringProperty("defaultVisibilityProperty",
private static final String JOKES_ENABLED = "jokes.enabled"; Visibility.STRONGLY_COLORED.name());
private static final String COMMANDS_ENABLED = "commands-enabled"; public final BooleanProperty visibilityOnlyGreyOrNoneEnabledProperty = new BooleanProperty("visibilityOnlyGreyOrNoneEnabledProperty", false);
private static final String TOASTS_ENABLED = "toasts.enabled"; 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; public TimeCalcConfiguration() {
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 void setFromTimeCalcProperties(TimeCalcProperties timeCalcProperties) {
public static TimeCalcProperties getInstance() { clockHandLongProperty.setValue(timeCalcProperties.areClockHandsLong());
if (INSTANCE == null) { clockHandSecondEnabledProperty.setValue(timeCalcProperties.isSecondEnabled());
INSTANCE = new TimeCalcProperties(); clockHandMillisecondEnabledProperty.setValue(timeCalcProperties.isMillisecondEnabled());
} batteryWavesEnabledProperty.setValue(timeCalcProperties.areBatteryWavesEnabled());
return INSTANCE; defaultVisibilityProperty.setValue(timeCalcProperties.getDefaultVisibility().name());
} visibilityOnlyGreyOrNoneEnabledProperty.setValue(timeCalcProperties.isVisibilityOnlyGreyOrNoneEnabled());
jokesEnabledProperty.setValue(timeCalcProperties.areJokesEnabled());
public boolean areClockHandsLong() { commandsEnabledProperty.setValue(timeCalcProperties.areCommandsEnabled());
return getBooleanProperty(CLOCK_HANDS_LONG, true); toastsEnabledProperty.setValue(timeCalcProperties.areToastsEnabled());
}
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
} }
} }

View File

@ -60,10 +60,12 @@ public class TimeCalcManager {
private final TimeCalcApp timeCalcApp; private final TimeCalcApp timeCalcApp;
private boolean stopBeforeEnd = false; private boolean stopBeforeEnd = false;
private Time time = new Time(); private Time time = new Time();
private TimeCalcConfiguration timeCalcConfiguration = new TimeCalcConfiguration();
public TimeCalcManager(String startTimeIn, String overTimeIn, public TimeCalcManager(String startTimeIn, String overTimeIn,
TimeCalcApp timeCalcApp) { TimeCalcApp timeCalcApp) {
this.timeCalcApp = timeCalcApp; this.timeCalcApp = timeCalcApp;
timeCalcConfiguration.setFromTimeCalcProperties(TimeCalcProperties.getInstance());
// Utils.everythingHidden // Utils.everythingHidden
// .setValue(TimeCalcConf.getInstance().isEverythingHidden()); // .setValue(TimeCalcConf.getInstance().isEverythingHidden());
// Utils.toastsAreEnabled // Utils.toastsAreEnabled
@ -205,7 +207,7 @@ public class TimeCalcManager {
timeCalcApp.visibilityProperty.setValue(commandsAsArray[1].equals("1") ? Visibility.GRAY.name() : Visibility.WEAKLY_COLORED.name()); timeCalcApp.visibilityProperty.setValue(commandsAsArray[1].equals("1") ? Visibility.GRAY.name() : Visibility.WEAKLY_COLORED.name());
break; break;
case "waves": case "waves":
timeCalcApp.wavesProperty.setValue(commandsAsArray[1].equals("1")); timeCalcConfiguration.batteryWavesEnabledProperty.setValue(commandsAsArray[1].equals("1"));
break; break;
case "uptime": case "uptime":
JOptionPane.showMessageDialog(null, JOptionPane.showMessageDialog(null,
@ -310,11 +312,8 @@ public class TimeCalcManager {
} else { } else {
analogClock.millisecondProperty.bindTo(time.millisecondProperty); analogClock.millisecondProperty.bindTo(time.millisecondProperty);
} }
analogClock.millisecondEnabledProperty.setValue( analogClock.millisecondEnabledProperty.bindTo(timeCalcConfiguration.clockHandMillisecondEnabledProperty);
TimeCalcProperties.getInstance().isMillisecondEnabled()); analogClock.secondEnabledProperty.bindTo(timeCalcConfiguration.clockHandSecondEnabledProperty);
analogClock.secondEnabledProperty.setValue(
TimeCalcProperties.getInstance().isSecondEnabled());
window.add(analogClock); window.add(analogClock);
@ -386,10 +385,10 @@ public class TimeCalcManager {
weekBattery.setBounds(hourBattery.getX(), hourBattery.getY() + hourBattery.getHeight() + MARGIN, hourBattery.getWidth(), hourBattery.getHeight()); 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()); monthBattery.setBounds(hourBattery.getX() + hourBattery.getWidth() + MARGIN, hourBattery.getY() + hourBattery.getHeight() + MARGIN, hourBattery.getWidth(), hourBattery.getHeight());
hourBattery.wavesProperty.bindTo(timeCalcApp.wavesProperty.asReadOnlyProperty()); hourBattery.wavesProperty.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
dayBattery.wavesProperty.bindTo(timeCalcApp.wavesProperty.asReadOnlyProperty()); dayBattery.wavesProperty.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
weekBattery.wavesProperty.bindTo(timeCalcApp.wavesProperty.asReadOnlyProperty()); weekBattery.wavesProperty.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
monthBattery.wavesProperty.bindTo(timeCalcApp.wavesProperty.asReadOnlyProperty()); monthBattery.wavesProperty.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
ComponentRegistry componentRegistry = new ComponentRegistry(); ComponentRegistry componentRegistry = new ComponentRegistry();
componentRegistry.addAll( componentRegistry.addAll(

View File

@ -1,5 +1,7 @@
package org.nanoboot.utils.timecalc.app; package org.nanoboot.utils.timecalc.app;
import org.nanoboot.utils.timecalc.entity.Visibility;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
@ -69,6 +71,20 @@ public class TimeCalcProperties {
return getBooleanProperty(TOASTS_ENABLED, true); 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) { private boolean getBooleanProperty(String key, boolean defaultValue) {
if (!properties.containsKey(key)) { if (!properties.containsKey(key)) {
return defaultValue; return defaultValue;
@ -81,5 +97,4 @@ public class TimeCalcProperties {
public void save() { public void save() {
//to be implemented //to be implemented
} }
} }

View File

@ -1,6 +1,6 @@
clock.hands.long=true clock.hands.long=true
clock.hands.second.enabled=true clock.hands.second.enabled=true
clock.hands.millisecond.enabled=true clock.hands.millisecond.enabled=false
battery.waves.enabled=true battery.waves.enabled=true
default-visibility=STRONGLY_COLORED default-visibility=STRONGLY_COLORED
visibility.only-grey-or-none.enabled=false visibility.only-grey-or-none.enabled=false