Time improvements - wip5
This commit is contained in:
parent
ed6c6070d9
commit
70bc18f173
@ -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) {
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user