Time improvements - wip4
This commit is contained in:
parent
14f4931999
commit
ed6c6070d9
@ -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
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
}
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
commands.enabled=true
|
||||
toasts.enabled=true
|
Loading…
x
Reference in New Issue
Block a user