Formatted code

This commit is contained in:
Robert Vokac 2024-02-10 14:25:17 +00:00
parent b71e63950c
commit a863709d4f
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
36 changed files with 708 additions and 440 deletions

View File

@ -3,8 +3,8 @@ 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.StringProperty;
import org.nanoboot.utils.timecalc.utils.common.Utils; import org.nanoboot.utils.timecalc.utils.common.Utils;
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import java.io.IOException; import java.io.IOException;
@ -15,11 +15,13 @@ import java.io.IOException;
*/ */
public class TimeCalcApp { public class TimeCalcApp {
public StringProperty visibilityProperty =
new StringProperty("timeCalcApp.visibilityReadWriteProperty",
Visibility.WEAKLY_COLORED.name());
private long startNanoTime = 0l; private long startNanoTime = 0l;
public StringProperty visibilityProperty = new StringProperty("timeCalcApp.visibilityReadWriteProperty", Visibility.WEAKLY_COLORED.name());
public void start(String[] args) throws IOException { public void start(String[] args) throws IOException {
if(startNanoTime != 0l) { if (startNanoTime != 0l) {
throw new TimeCalcException("TimeCalcApp was already started."); throw new TimeCalcException("TimeCalcApp was already started.");
} }
startNanoTime = System.nanoTime(); startNanoTime = System.nanoTime();
@ -74,11 +76,13 @@ public class TimeCalcApp {
public long getCountOfMinutesSinceAppStarted() { public long getCountOfMinutesSinceAppStarted() {
return getCountOfSecondsSinceAppStarted() / 60l; return getCountOfSecondsSinceAppStarted() / 60l;
} }
public long getCountOfSecondsSinceAppStarted() { public long getCountOfSecondsSinceAppStarted() {
return getCountOfMillisecondsSinceAppStarted() / 1000000000l; return getCountOfMillisecondsSinceAppStarted() / 1000000000l;
} }
public long getCountOfMillisecondsSinceAppStarted() { public long getCountOfMillisecondsSinceAppStarted() {
if(startNanoTime == 0l) { if (startNanoTime == 0l) {
throw new TimeCalcException("TimeCalcApp was not yet started."); throw new TimeCalcException("TimeCalcApp was not yet started.");
} }
return System.nanoTime() - startNanoTime; return System.nanoTime() - startNanoTime;

View File

@ -4,40 +4,53 @@ import org.nanoboot.utils.timecalc.entity.Visibility;
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty; import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
import org.nanoboot.utils.timecalc.utils.property.StringProperty; import org.nanoboot.utils.timecalc.utils.property.StringProperty;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
/** /**
* @author Robert Vokac * @author Robert Vokac
* @since 20.02.2024 * @since 20.02.2024
*/ */
public class TimeCalcConfiguration { public class TimeCalcConfiguration {
public final BooleanProperty clockHandLongProperty = new BooleanProperty("clockHandLongProperty", true); public final BooleanProperty clockHandLongProperty =
public final BooleanProperty clockHandSecondEnabledProperty = new BooleanProperty("clockHandSecondEnabledProperty", true); new BooleanProperty("clockHandLongProperty", true);
public final BooleanProperty clockHandMillisecondEnabledProperty = new BooleanProperty("clockHandMillisecondEnabledProperty", false); public final BooleanProperty clockHandSecondEnabledProperty =
public final BooleanProperty batteryWavesEnabledProperty = new BooleanProperty("batteryWavesEnabledProperty", true); new BooleanProperty("clockHandSecondEnabledProperty", true);
public final BooleanProperty clockHandMillisecondEnabledProperty =
new BooleanProperty("clockHandMillisecondEnabledProperty", false);
public final BooleanProperty batteryWavesEnabledProperty =
new BooleanProperty("batteryWavesEnabledProperty", true);
public final StringProperty public final StringProperty
defaultVisibilityProperty = new StringProperty("defaultVisibilityProperty", defaultVisibilityProperty =
Visibility.STRONGLY_COLORED.name()); new StringProperty("defaultVisibilityProperty",
public final BooleanProperty visibilityOnlyGreyOrNoneEnabledProperty = new BooleanProperty("visibilityOnlyGreyOrNoneEnabledProperty", false); Visibility.STRONGLY_COLORED.name());
public final BooleanProperty jokesEnabledProperty = new BooleanProperty("jokesEnabledProperty", true); public final BooleanProperty visibilityOnlyGreyOrNoneEnabledProperty =
public final BooleanProperty commandsEnabledProperty = new BooleanProperty("commandsEnabledProperty", true); new BooleanProperty("visibilityOnlyGreyOrNoneEnabledProperty",
public final BooleanProperty toastsEnabledProperty = new BooleanProperty("toastsEnabledProperty", true); 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);
public TimeCalcConfiguration() { public TimeCalcConfiguration() {
} }
public void setFromTimeCalcProperties(TimeCalcProperties timeCalcProperties) {
public void setFromTimeCalcProperties(
TimeCalcProperties timeCalcProperties) {
clockHandLongProperty.setValue(timeCalcProperties.areClockHandsLong()); clockHandLongProperty.setValue(timeCalcProperties.areClockHandsLong());
clockHandSecondEnabledProperty.setValue(timeCalcProperties.isSecondEnabled()); clockHandSecondEnabledProperty
clockHandMillisecondEnabledProperty.setValue(timeCalcProperties.isMillisecondEnabled()); .setValue(timeCalcProperties.isSecondEnabled());
batteryWavesEnabledProperty.setValue(timeCalcProperties.areBatteryWavesEnabled()); clockHandMillisecondEnabledProperty
defaultVisibilityProperty.setValue(timeCalcProperties.getDefaultVisibility().name()); .setValue(timeCalcProperties.isMillisecondEnabled());
visibilityOnlyGreyOrNoneEnabledProperty.setValue(timeCalcProperties.isVisibilityOnlyGreyOrNoneEnabled()); batteryWavesEnabledProperty
.setValue(timeCalcProperties.areBatteryWavesEnabled());
defaultVisibilityProperty
.setValue(timeCalcProperties.getDefaultVisibility().name());
visibilityOnlyGreyOrNoneEnabledProperty.setValue(
timeCalcProperties.isVisibilityOnlyGreyOrNoneEnabled());
jokesEnabledProperty.setValue(timeCalcProperties.areJokesEnabled()); jokesEnabledProperty.setValue(timeCalcProperties.areJokesEnabled());
commandsEnabledProperty.setValue(timeCalcProperties.areCommandsEnabled()); commandsEnabledProperty
.setValue(timeCalcProperties.areCommandsEnabled());
toastsEnabledProperty.setValue(timeCalcProperties.areToastsEnabled()); toastsEnabledProperty.setValue(timeCalcProperties.areToastsEnabled());
} }

View File

@ -4,7 +4,7 @@ package org.nanoboot.utils.timecalc.app;
* @author Robert Vokac * @author Robert Vokac
* @since 21.02.2024 * @since 21.02.2024
*/ */
public class TimeCalcException extends RuntimeException{ public class TimeCalcException extends RuntimeException {
public TimeCalcException(String msg) { public TimeCalcException(String msg) {
super(msg); super(msg);
} }

View File

@ -47,10 +47,9 @@ import java.util.logging.Logger;
* @since 08.02.2024 * @since 08.02.2024
*/ */
public class TimeCalcManager { public class TimeCalcManager {
private static final int MARGIN = 10;
public static final Color BG = new Color(238, 238, 238); public static final Color BG = new Color(238, 238, 238);
public static final Color FG = new Color(210, 210, 210); public static final Color FG = new Color(210, 210, 210);
private static final int MARGIN = 10;
private final String windowTitle; private final String windowTitle;
private final int totalMinutes; private final int totalMinutes;
@ -59,17 +58,19 @@ public class TimeCalcManager {
private final TimeHM endTime; private final TimeHM endTime;
private final TimeCalcApp timeCalcApp; private final TimeCalcApp timeCalcApp;
private boolean stopBeforeEnd = false; private boolean stopBeforeEnd = false;
private Time time = new Time(); private final Time time = new Time();
private TimeCalcConfiguration timeCalcConfiguration = new TimeCalcConfiguration(); private final 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()); timeCalcConfiguration
// Utils.everythingHidden .setFromTimeCalcProperties(TimeCalcProperties.getInstance());
// .setValue(TimeCalcConf.getInstance().isEverythingHidden()); // Utils.everythingHidden
// Utils.toastsAreEnabled // .setValue(TimeCalcConf.getInstance().isEverythingHidden());
// .setValue(TimeCalcConf.getInstance().areToastsEnabled()); // Utils.toastsAreEnabled
// .setValue(TimeCalcConf.getInstance().areToastsEnabled());
overTimeIn = (overTimeIn == null || overTimeIn.isEmpty()) ? overTimeIn = (overTimeIn == null || overTimeIn.isEmpty()) ?
Constants.DEFAULT_OVERTIME : overTimeIn; Constants.DEFAULT_OVERTIME : overTimeIn;
@ -77,8 +78,11 @@ public class TimeCalcManager {
this.startTime = new TimeHM(startTimeIn); this.startTime = new TimeHM(startTimeIn);
this.overtime = new TimeHM(overTimeIn); this.overtime = new TimeHM(overTimeIn);
this.endTime = new TimeHM(startTime.getHour() + Constants.WORKING_HOURS_LENGTH + overtime.getHour(), this.endTime = new TimeHM(
startTime.getMinute() + Constants.WORKING_MINUTES_LENGTH + overtime.getMinute()); startTime.getHour() + Constants.WORKING_HOURS_LENGTH + overtime
.getHour(),
startTime.getMinute() + Constants.WORKING_MINUTES_LENGTH
+ overtime.getMinute());
this.totalMinutes = TimeHM.countDiffInMinutes(startTime, endTime); this.totalMinutes = TimeHM.countDiffInMinutes(startTime, endTime);
int totalSeconds = totalMinutes * TimeHM.SECONDS_PER_MINUTE; int totalSeconds = totalMinutes * TimeHM.SECONDS_PER_MINUTE;
@ -99,54 +103,69 @@ public class TimeCalcManager {
window.addKeyListener(new KeyAdapter() { window.addKeyListener(new KeyAdapter() {
// Key Pressed method // Key Pressed method
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
Visibility visibility = Visibility.valueOf(timeCalcApp.visibilityProperty.getValue()); Visibility visibility = Visibility
.valueOf(timeCalcApp.visibilityProperty.getValue());
if (e.getKeyCode() == KeyEvent.VK_UP) { if (e.getKeyCode() == KeyEvent.VK_UP) {
timeCalcApp.visibilityProperty.setValue(Visibility.STRONGLY_COLORED.name()); timeCalcApp.visibilityProperty
.setValue(Visibility.STRONGLY_COLORED.name());
} }
if (e.getKeyCode() == KeyEvent.VK_DOWN) { if (e.getKeyCode() == KeyEvent.VK_DOWN) {
timeCalcApp.visibilityProperty.setValue(Visibility.NONE.name()); timeCalcApp.visibilityProperty
.setValue(Visibility.NONE.name());
} }
if (e.getKeyCode() == KeyEvent.VK_H) { if (e.getKeyCode() == KeyEvent.VK_H) {
if(visibility.isNone()) { if (visibility.isNone()) {
timeCalcApp.visibilityProperty.setValue(Visibility.STRONGLY_COLORED.name()); timeCalcApp.visibilityProperty
.setValue(Visibility.STRONGLY_COLORED.name());
} else { } else {
timeCalcApp.visibilityProperty.setValue(Visibility.NONE.name()); timeCalcApp.visibilityProperty
.setValue(Visibility.NONE.name());
} }
} }
if (e.getKeyCode() == KeyEvent.VK_G) { if (e.getKeyCode() == KeyEvent.VK_G) {
if(visibility.isGray()) { if (visibility.isGray()) {
timeCalcApp.visibilityProperty.setValue(Visibility.WEAKLY_COLORED.name()); timeCalcApp.visibilityProperty
.setValue(Visibility.WEAKLY_COLORED.name());
} else { } else {
timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name()); timeCalcApp.visibilityProperty
.setValue(Visibility.GRAY.name());
} }
} }
if (e.getKeyCode() == KeyEvent.VK_C) { if (e.getKeyCode() == KeyEvent.VK_C) {
if(visibility.isStronglyColored()) { if (visibility.isStronglyColored()) {
timeCalcApp.visibilityProperty.setValue(Visibility.WEAKLY_COLORED.name()); timeCalcApp.visibilityProperty
.setValue(Visibility.WEAKLY_COLORED.name());
} else { } else {
timeCalcApp.visibilityProperty.setValue(Visibility.STRONGLY_COLORED.name()); timeCalcApp.visibilityProperty
.setValue(Visibility.STRONGLY_COLORED.name());
} }
} }
if (e.getKeyCode() == KeyEvent.VK_V) { if (e.getKeyCode() == KeyEvent.VK_V) {
if(visibility.isNone()) { if (visibility.isNone()) {
timeCalcApp.visibilityProperty.setValue(Visibility.STRONGLY_COLORED.name()); timeCalcApp.visibilityProperty
.setValue(Visibility.STRONGLY_COLORED.name());
} else { } else {
timeCalcApp.visibilityProperty.setValue(Visibility.NONE.name()); timeCalcApp.visibilityProperty
.setValue(Visibility.NONE.name());
} }
} }
if (e.getKeyCode() == KeyEvent.VK_SPACE) { if (e.getKeyCode() == KeyEvent.VK_SPACE) {
if(visibility.isStronglyColored()) { if (visibility.isStronglyColored()) {
timeCalcApp.visibilityProperty.setValue(Visibility.WEAKLY_COLORED.name()); timeCalcApp.visibilityProperty
.setValue(Visibility.WEAKLY_COLORED.name());
} }
if(visibility.isWeaklyColored()) { if (visibility.isWeaklyColored()) {
timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name()); timeCalcApp.visibilityProperty
.setValue(Visibility.GRAY.name());
} }
if(visibility.isGray()) { if (visibility.isGray()) {
timeCalcApp.visibilityProperty.setValue(Visibility.NONE.name()); timeCalcApp.visibilityProperty
.setValue(Visibility.NONE.name());
} }
if(visibility.isNone()) { if (visibility.isNone()) {
timeCalcApp.visibilityProperty.setValue(Visibility.STRONGLY_COLORED.name()); timeCalcApp.visibilityProperty
.setValue(Visibility.STRONGLY_COLORED.name());
} }
} }
if (e.getKeyCode() == KeyEvent.VK_R) { if (e.getKeyCode() == KeyEvent.VK_R) {
@ -159,18 +178,30 @@ public class TimeCalcManager {
window.repaint(); window.repaint();
} }
}); });
WalkingHumanProgressAsciiArt walkingHumanProgressAsciiArt = new WalkingHumanProgressAsciiArt(); WalkingHumanProgressAsciiArt walkingHumanProgressAsciiArt =
walkingHumanProgressAsciiArt.setBounds(MARGIN, MARGIN + 210 + MARGIN, 450, 180); new WalkingHumanProgressAsciiArt();
walkingHumanProgressAsciiArt
.setBounds(MARGIN, MARGIN + 210 + MARGIN, 450, 180);
window.add(walkingHumanProgressAsciiArt); window.add(walkingHumanProgressAsciiArt);
weatherButton weatherButton
.setBounds(20, walkingHumanProgressAsciiArt.getY() + walkingHumanProgressAsciiArt.getHeight() + MARGIN); .setBounds(20, walkingHumanProgressAsciiArt.getY()
commandButton.setBounds(20, walkingHumanProgressAsciiArt.getY() + walkingHumanProgressAsciiArt.getHeight() + MARGIN); + walkingHumanProgressAsciiArt.getHeight()
+ MARGIN);
commandButton.setBounds(20, walkingHumanProgressAsciiArt.getY()
+ walkingHumanProgressAsciiArt.getHeight()
+ MARGIN);
jokeButton.setBounds(140, walkingHumanProgressAsciiArt.getY() + walkingHumanProgressAsciiArt.getHeight() + MARGIN); jokeButton.setBounds(140, walkingHumanProgressAsciiArt.getY()
+ walkingHumanProgressAsciiArt.getHeight()
+ MARGIN);
restartButton restartButton
.setBounds(280, walkingHumanProgressAsciiArt.getY() + walkingHumanProgressAsciiArt.getHeight() + MARGIN); .setBounds(280, walkingHumanProgressAsciiArt.getY()
exitButton.setBounds(390, walkingHumanProgressAsciiArt.getY() + walkingHumanProgressAsciiArt.getHeight() + MARGIN); + walkingHumanProgressAsciiArt.getHeight()
+ MARGIN);
exitButton.setBounds(390, walkingHumanProgressAsciiArt.getY()
+ walkingHumanProgressAsciiArt.getHeight()
+ MARGIN);
aboutButton.setBounds(exitButton.getX(), aboutButton.setBounds(exitButton.getX(),
exitButton.getY() + exitButton.getHeight() + MARGIN); exitButton.getY() + exitButton.getHeight() + MARGIN);
@ -201,17 +232,25 @@ public class TimeCalcManager {
JOptionPane.showMessageDialog(null, "Test"); JOptionPane.showMessageDialog(null, "Test");
break; break;
case "color": case "color":
timeCalcApp.visibilityProperty.setValue(commandsAsArray[1].equals("1") ? Visibility.STRONGLY_COLORED.name() : Visibility.WEAKLY_COLORED.name()); timeCalcApp.visibilityProperty.setValue(
commandsAsArray[1].equals("1") ?
Visibility.STRONGLY_COLORED.name() :
Visibility.WEAKLY_COLORED.name());
break; break;
case "gray": case "gray":
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":
timeCalcConfiguration.batteryWavesEnabledProperty.setValue(commandsAsArray[1].equals("1")); timeCalcConfiguration.batteryWavesEnabledProperty
.setValue(commandsAsArray[1].equals("1"));
break; break;
case "uptime": case "uptime":
JOptionPane.showMessageDialog(null, JOptionPane.showMessageDialog(null,
timeCalcApp.getCountOfMinutesSinceAppStarted() timeCalcApp
.getCountOfMinutesSinceAppStarted()
+ " minutes"); + " minutes");
break; break;
case "toast": case "toast":
@ -246,75 +285,97 @@ public class TimeCalcManager {
stopBeforeEnd = true; stopBeforeEnd = true;
}); });
Calendar calNow = Calendar.getInstance(); Calendar calNow = Calendar.getInstance();
calNow.setTime(new Date()); calNow.setTime(new Date());
AnalogClock analogClock = new AnalogClock(startTime, endTime); AnalogClock analogClock = new AnalogClock(startTime, endTime);
analogClock.setBounds(MARGIN, MARGIN, 200); analogClock.setBounds(MARGIN, MARGIN, 200);
Properties testProperties = new Properties(); Properties testProperties = new Properties();
File testPropertiesFile = new File("test.txt"); File testPropertiesFile = new File("test.txt");
try { try {
if(testPropertiesFile.exists()) { if (testPropertiesFile.exists()) {
testProperties.load(new FileInputStream(testPropertiesFile)); testProperties.load(new FileInputStream(testPropertiesFile));
} }
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
Logger.getLogger(TimeCalcManager.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(TimeCalcManager.class.getName())
.log(Level.SEVERE, null, ex);
} catch (IOException rex) { } catch (IOException rex) {
Logger.getLogger(TimeCalcManager.class.getName()).log(Level.SEVERE, null, rex); Logger.getLogger(TimeCalcManager.class.getName())
.log(Level.SEVERE, null, rex);
} }
if(testProperties.containsKey("current.day")) { if (testProperties.containsKey("current.day")) {
calNow.set(Calendar.DAY_OF_MONTH, Integer.parseInt((String) testProperties.get("current.day"))); calNow.set(Calendar.DAY_OF_MONTH, Integer.parseInt(
analogClock.dayProperty.setValue(Integer.valueOf((String) testProperties.get("current.day"))); (String) testProperties.get("current.day")));
analogClock.dayProperty.setValue(Integer.valueOf(
(String) testProperties.get("current.day")));
} else { } else {
analogClock.dayProperty.bindTo(time.dayProperty); analogClock.dayProperty.bindTo(time.dayProperty);
} }
if(testProperties.containsKey("current.month")) { if (testProperties.containsKey("current.month")) {
calNow.set(Calendar.MONTH, Integer.parseInt((String) testProperties.get("current.month")) - 1); calNow.set(Calendar.MONTH, Integer.parseInt(
analogClock.monthProperty.setValue(Integer.valueOf((String) testProperties.get("current.month"))); (String) testProperties.get("current.month")) - 1);
analogClock.monthProperty.setValue(Integer.valueOf(
(String) testProperties.get("current.month")));
} else { } else {
analogClock.monthProperty.bindTo(time.monthProperty); analogClock.monthProperty.bindTo(time.monthProperty);
} }
if(testProperties.containsKey("current.year")) { if (testProperties.containsKey("current.year")) {
calNow.set(Calendar.YEAR, Integer.parseInt((String) testProperties.get("current.year"))); calNow.set(Calendar.YEAR, Integer.parseInt(
analogClock.yearProperty.setValue(Integer.valueOf((String) testProperties.get("current.year"))); (String) testProperties.get("current.year")));
analogClock.yearProperty.setValue(Integer.valueOf(
(String) testProperties.get("current.year")));
} else { } else {
analogClock.yearProperty.bindTo(time.yearProperty); analogClock.yearProperty.bindTo(time.yearProperty);
} }
if(testProperties.containsKey("current.year") || testProperties.containsKey("current.month") ||testProperties.containsKey("current.day")) { if (testProperties.containsKey("current.year") || testProperties
analogClock.dayOfWeekProperty.setValue(calNow.get(Calendar.DAY_OF_WEEK)); .containsKey("current.month") || testProperties
.containsKey("current.day")) {
analogClock.dayOfWeekProperty
.setValue(calNow.get(Calendar.DAY_OF_WEEK));
} else { } else {
analogClock.dayOfWeekProperty.bindTo(time.dayOfWeek); analogClock.dayOfWeekProperty.bindTo(time.dayOfWeek);
} }
if(testProperties.containsKey("current.hour")) { if (testProperties.containsKey("current.hour")) {
calNow.set(Calendar.HOUR, Integer.parseInt((String) testProperties.get("current.hour"))); calNow.set(Calendar.HOUR, Integer.parseInt(
analogClock.hourProperty.setValue(Integer.valueOf((String) testProperties.get("current.hour"))); (String) testProperties.get("current.hour")));
analogClock.hourProperty.setValue(Integer.valueOf(
(String) testProperties.get("current.hour")));
} else { } else {
analogClock.hourProperty.bindTo(time.hourProperty); analogClock.hourProperty.bindTo(time.hourProperty);
} }
if(testProperties.containsKey("current.minute")) { if (testProperties.containsKey("current.minute")) {
calNow.set(Calendar.MINUTE, Integer.parseInt((String) testProperties.get("current.minute"))); calNow.set(Calendar.MINUTE, Integer.parseInt(
analogClock.minuteProperty.setValue(Integer.valueOf((String) testProperties.get("current.minute"))); (String) testProperties.get("current.minute")));
analogClock.minuteProperty.setValue(Integer.valueOf(
(String) testProperties.get("current.minute")));
} else { } else {
analogClock.minuteProperty.bindTo(time.minuteProperty); analogClock.minuteProperty.bindTo(time.minuteProperty);
} }
if(testProperties.containsKey("current.second")) { if (testProperties.containsKey("current.second")) {
calNow.set(Calendar.SECOND, Integer.parseInt((String) testProperties.get("current.second"))); calNow.set(Calendar.SECOND, Integer.parseInt(
analogClock.secondProperty.setValue(Integer.valueOf((String) testProperties.get("current.second"))); (String) testProperties.get("current.second")));
analogClock.secondProperty.setValue(Integer.valueOf(
(String) testProperties.get("current.second")));
} else { } else {
analogClock.secondProperty.bindTo(time.secondProperty); analogClock.secondProperty.bindTo(time.secondProperty);
} }
if(testProperties.containsKey("current.millisecond")) { if (testProperties.containsKey("current.millisecond")) {
calNow.set(Calendar.MILLISECOND, Integer.parseInt((String) testProperties.get("current.millisecond"))); calNow.set(Calendar.MILLISECOND, Integer.parseInt(
analogClock.millisecondProperty.setValue(Integer.valueOf((String) testProperties.get("current.millisecond"))); (String) testProperties.get("current.millisecond")));
analogClock.millisecondProperty.setValue(Integer.valueOf(
(String) testProperties.get("current.millisecond")));
} else { } else {
analogClock.millisecondProperty.bindTo(time.millisecondProperty); analogClock.millisecondProperty.bindTo(time.millisecondProperty);
} }
analogClock.millisecondEnabledProperty.bindTo(timeCalcConfiguration.clockHandMillisecondEnabledProperty); analogClock.millisecondEnabledProperty
analogClock.secondEnabledProperty.bindTo(timeCalcConfiguration.clockHandSecondEnabledProperty); .bindTo(timeCalcConfiguration.clockHandMillisecondEnabledProperty);
analogClock.handsLongProperty.bindTo(timeCalcConfiguration.clockHandLongProperty); analogClock.secondEnabledProperty
.bindTo(timeCalcConfiguration.clockHandSecondEnabledProperty);
analogClock.handsLongProperty
.bindTo(timeCalcConfiguration.clockHandLongProperty);
window.add(analogClock); window.add(analogClock);
@ -334,10 +395,10 @@ public class TimeCalcManager {
window.add(progressCircle); window.add(progressCircle);
Battery dayBattery = new DayBattery(progressCircle.getBounds().x, Battery dayBattery = new DayBattery(progressCircle.getBounds().x,
progressCircle.getY() + MARGIN + progressCircle.getHeight(), 140); progressCircle.getY() + MARGIN + progressCircle.getHeight(),
140);
window.add(dayBattery); window.add(dayBattery);
Battery weekBattery = new WeekBattery( Battery weekBattery = new WeekBattery(
dayBattery.getBounds().x + dayBattery.getWidth() + MARGIN * 2, dayBattery.getBounds().x + dayBattery.getWidth() + MARGIN * 2,
dayBattery.getY(), 140); dayBattery.getY(), 140);
@ -381,15 +442,29 @@ public class TimeCalcManager {
Rectangle dayRectangle = dayBattery.getBounds(); Rectangle dayRectangle = dayBattery.getBounds();
hourBattery.setBounds(dayRectangle); hourBattery.setBounds(dayRectangle);
hourBattery.setBounds(hourBattery.getX() + 2 * MARGIN, hourBattery.getY(), hourBattery.getWidth(), hourBattery.getHeight()); hourBattery
dayBattery.setBounds(hourBattery.getX() + hourBattery.getWidth() + MARGIN, hourBattery.getY(), hourBattery.getWidth(), hourBattery.getHeight()); .setBounds(hourBattery.getX() + 2 * MARGIN, hourBattery.getY(),
weekBattery.setBounds(hourBattery.getX(), hourBattery.getY() + hourBattery.getHeight() + MARGIN, hourBattery.getWidth(), hourBattery.getHeight()); hourBattery.getWidth(), hourBattery.getHeight());
monthBattery.setBounds(hourBattery.getX() + hourBattery.getWidth() + MARGIN, hourBattery.getY() + hourBattery.getHeight() + MARGIN, hourBattery.getWidth(), hourBattery.getHeight()); dayBattery
.setBounds(hourBattery.getX() + hourBattery.getWidth() + MARGIN,
hourBattery.getY(), 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());
hourBattery.wavesProperty.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty); hourBattery.wavesProperty
dayBattery.wavesProperty.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty); .bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
weekBattery.wavesProperty.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty); dayBattery.wavesProperty
monthBattery.wavesProperty.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty); .bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
weekBattery.wavesProperty
.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
monthBattery.wavesProperty
.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
ComponentRegistry componentRegistry = new ComponentRegistry(); ComponentRegistry componentRegistry = new ComponentRegistry();
componentRegistry.addAll( componentRegistry.addAll(
@ -406,9 +481,12 @@ public class TimeCalcManager {
restartButton, restartButton,
exitButton exitButton
); );
walkingHumanProgressAsciiArt.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); walkingHumanProgressAsciiArt.visibilityProperty
progressSquare.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); .bindTo(timeCalcApp.visibilityProperty);
progressCircle.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); progressSquare.visibilityProperty
.bindTo(timeCalcApp.visibilityProperty);
progressCircle.visibilityProperty
.bindTo(timeCalcApp.visibilityProperty);
analogClock.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); analogClock.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
dayBattery.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); dayBattery.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
weekBattery.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); weekBattery.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
@ -419,21 +497,30 @@ public class TimeCalcManager {
restartButton.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); restartButton.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
exitButton.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); exitButton.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
jokeButton.setVisible(!Visibility.valueOf(jokeButton.visibilityProperty.getValue()).isNone()); jokeButton.setVisible(
commandButton.setVisible(!Visibility.valueOf(commandButton.visibilityProperty.getValue()).isNone()); !Visibility.valueOf(jokeButton.visibilityProperty.getValue())
restartButton.setVisible(!Visibility.valueOf(restartButton.visibilityProperty.getValue()).isNone()); .isNone());
exitButton.setVisible(!Visibility.valueOf(exitButton.visibilityProperty.getValue()).isNone()); commandButton.setVisible(
!Visibility.valueOf(commandButton.visibilityProperty.getValue())
.isNone());
restartButton.setVisible(
!Visibility.valueOf(restartButton.visibilityProperty.getValue())
.isNone());
exitButton.setVisible(
!Visibility.valueOf(exitButton.visibilityProperty.getValue())
.isNone());
// timeCalcApp.visibilityProperty.addListener((Property<String> p, String oldValue, String newValue)-> { // timeCalcApp.visibilityProperty.addListener((Property<String> p, String oldValue, String newValue)-> {
// System.out.println("Visibility of timeCalcApp was changed FROM " + oldValue + " TO " + newValue); // System.out.println("Visibility of timeCalcApp was changed FROM " + oldValue + " TO " + newValue);
// } ); // } );
// analogClock.visibilityProperty.addListener((Property<String> p, String oldValue, String newValue)-> { // analogClock.visibilityProperty.addListener((Property<String> p, String oldValue, String newValue)-> {
// System.out.println("Visibility of analogClock was changed FROM " + oldValue + " TO " + newValue); // System.out.println("Visibility of analogClock was changed FROM " + oldValue + " TO " + newValue);
// } ); // } );
window.setSize(520 + 20 + 100, exitButton.getY() + 3 * exitButton.getHeight() + MARGIN); window.setSize(520 + 20 + 100,
exitButton.getY() + 3 * exitButton.getHeight() + MARGIN);
while (true) { while (true) {
//time.writeString(); //time.writeString();
if(Math.random() > 0.95) { if (Math.random() > 0.95) {
window.requestFocus(); window.requestFocus();
} }
if (stopBeforeEnd) { if (stopBeforeEnd) {
@ -442,7 +529,8 @@ public class TimeCalcManager {
break; break;
} }
Visibility visibility = Visibility.valueOf(timeCalcApp.visibilityProperty.getValue()); Visibility visibility = Visibility
.valueOf(timeCalcApp.visibilityProperty.getValue());
componentRegistry.setVisible(visibility.isNotNone()); componentRegistry.setVisible(visibility.isNotNone());
if (!visibility.isStronglyColored() || visibility.isGray()) { if (!visibility.isStronglyColored() || visibility.isGray()) {
jokeButton.setBackground(BG); jokeButton.setBackground(BG);
@ -480,13 +568,17 @@ public class TimeCalcManager {
int secondNow = Integer.parseInt(nowString.split(":")[2]); int secondNow = Integer.parseInt(nowString.split(":")[2]);
int millisecondNow = Integer.parseInt(nowString.split(":")[3]); int millisecondNow = Integer.parseInt(nowString.split(":")[3]);
TimeHM timeRemains = new TimeHM(endTime.getHour() - hourNow, endTime.getMinute() - minuteNow); TimeHM timeRemains = new TimeHM(endTime.getHour() - hourNow,
endTime.getMinute() - minuteNow);
int secondsRemains = 60 - secondNow; int secondsRemains = 60 - secondNow;
int millisecondsRemains = 1000 - millisecondNow; int millisecondsRemains = 1000 - millisecondNow;
int hourDone = Constants.WORKING_HOURS_LENGTH + overtime.getHour() - timeRemains.getHour(); int hourDone = Constants.WORKING_HOURS_LENGTH + overtime.getHour()
int minutesDone = Constants.WORKING_MINUTES_LENGTH + overtime.getMinute() - timeRemains.getMinute(); - timeRemains.getHour();
int minutesDone =
Constants.WORKING_MINUTES_LENGTH + overtime.getMinute()
- timeRemains.getMinute();
int secondsDone = secondNow; int secondsDone = secondNow;
int millisecondsDone = millisecondNow; int millisecondsDone = millisecondNow;
@ -502,17 +594,21 @@ public class TimeCalcManager {
dayBattery.setDonePercent(done); dayBattery.setDonePercent(done);
int weekDayWhenMondayIsOne = calNow.get(Calendar.DAY_OF_WEEK) - 1; int weekDayWhenMondayIsOne = calNow.get(Calendar.DAY_OF_WEEK) - 1;
weekBattery.setDonePercent(WeekBattery.getWeekProgress(weekDayWhenMondayIsOne, done)); weekBattery.setDonePercent(
WeekBattery.getWeekProgress(weekDayWhenMondayIsOne, done));
weekBattery.setLabel( weekBattery.setLabel(
nowIsWeekend ? "5/5" : (weekDayWhenMondayIsOne + "/5")); nowIsWeekend ? "5/5" : (weekDayWhenMondayIsOne + "/5"));
monthBattery.setDonePercent(MonthBattery.getMonthProgress(weekDayWhenMondayIsOne, workDaysDone, workDaysTotal, done)); monthBattery.setDonePercent(MonthBattery
.getMonthProgress(weekDayWhenMondayIsOne, workDaysDone,
workDaysTotal, done));
monthBattery.setLabel( monthBattery.setLabel(
(nowIsWeekend ? workDaysDone : workDaysDone + 1) + "/" (nowIsWeekend ? workDaysDone : workDaysDone + 1) + "/"
+ (workDaysTotal)); + (workDaysTotal));
hourBattery.setDonePercent(HourBattery.getHourProgress(timeRemains, secondsRemains, hourBattery.setDonePercent(
millisecondsRemains)); HourBattery.getHourProgress(timeRemains, secondsRemains,
millisecondsRemains));
if (!nowIsWeekend) { if (!nowIsWeekend) {
hourBattery.setLabel( hourBattery.setLabel(
hourDone + "/" + ( hourDone + "/" + (
@ -520,24 +616,28 @@ public class TimeCalcManager {
} }
int totalSecondsRemains = int totalSecondsRemains =
(timeRemains.getHour() * 60 * 60 + timeRemains.getMinute() * 60 (timeRemains.getHour() * 60 * 60
+ timeRemains.getMinute() * 60
+ secondsRemains); + secondsRemains);
int totalMillisecondsRemains = int totalMillisecondsRemains =
totalSecondsRemains * 1000 + millisecondsRemains; totalSecondsRemains * 1000 + millisecondsRemains;
double totalSecondsRemainsDouble = double totalSecondsRemainsDouble =
((double) totalMillisecondsRemains) / 1000; ((double) totalMillisecondsRemains) / 1000;
// if (timeRemains.getHour() == 0 && timeRemains.getMinute() <= 3) { // if (timeRemains.getHour() == 0 && timeRemains.getMinute() <= 3) {
// Utils.highlighted.set(true); // Utils.highlighted.set(true);
// walkingHumanProgressAsciiArt.setForeground(Color.BLUE); // walkingHumanProgressAsciiArt.setForeground(Color.BLUE);
// } // }
if (timeRemains.getHour() <= 0 && timeRemains.getMinute() <= 0) { if (timeRemains.getHour() <= 0 && timeRemains.getMinute() <= 0) {
Toaster toasterManager = new Toaster(); Toaster toasterManager = new Toaster();
toasterManager.setDisplayTime(30000); toasterManager.setDisplayTime(30000);
toasterManager.showToaster( toasterManager.showToaster(
"Congratulation :-) It is the time to go home."); "Congratulation :-) It is the time to go home.");
walkingHumanProgressAsciiArt.printPercentToAscii(done, timeRemains.getHour(), timeRemains.getMinute(), done,totalSecondsRemainsDouble, endTime); walkingHumanProgressAsciiArt
.printPercentToAscii(done, timeRemains.getHour(),
timeRemains.getMinute(), done,
totalSecondsRemainsDouble, endTime);
try { try {
Thread.sleep(10000); Thread.sleep(10000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -551,7 +651,10 @@ public class TimeCalcManager {
} }
} }
} else { } else {
walkingHumanProgressAsciiArt.printPercentToAscii(done, timeRemains.getHour(), timeRemains.getMinute(), done,totalSecondsRemainsDouble, endTime); walkingHumanProgressAsciiArt
.printPercentToAscii(done, timeRemains.getHour(),
timeRemains.getMinute(), done,
totalSecondsRemainsDouble, endTime);
} }
try { try {
@ -561,7 +664,8 @@ public class TimeCalcManager {
} }
walkingHumanProgressAsciiArt.setForeground( walkingHumanProgressAsciiArt.setForeground(
visibility.isStronglyColored() || walkingHumanProgressAsciiArt visibility.isStronglyColored()
|| walkingHumanProgressAsciiArt
.getClientProperty("mouseEntered").equals("true") ? .getClientProperty("mouseEntered").equals("true") ?
Color.BLACK : Color.LIGHT_GRAY); Color.BLACK : Color.LIGHT_GRAY);
} }

View File

@ -13,11 +13,14 @@ import java.util.Properties;
*/ */
public class TimeCalcProperties { public class TimeCalcProperties {
private static final String CLOCK_HANDS_LONG = "clock.hands.long"; 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_SECOND_ENABLED =
private static final String CLOCK_HANDS_MILLISECOND_ENABLED = "clock.hands.millisecond.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 BATTERY_WAVES_ENABLED = "battery.waves.enabled";
private static final String DEFAULT_VISIBILITY = "default-visibility"; 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 VISIBILITY_ONLY_GREY_OR_NONE_ENABLED =
"visibility.only-grey-or-none.enabled";
private static final String JOKES_ENABLED = "jokes.enabled"; private static final String JOKES_ENABLED = "jokes.enabled";
private static final String COMMANDS_ENABLED = "commands-enabled"; private static final String COMMANDS_ENABLED = "commands-enabled";
private static final String TOASTS_ENABLED = "toasts.enabled"; private static final String TOASTS_ENABLED = "toasts.enabled";
@ -35,9 +38,12 @@ public class TimeCalcProperties {
} catch (IOException e) { } catch (IOException e) {
System.err.println(e); System.err.println(e);
} }
if(!isSecondEnabled() && isMillisecondEnabled()) { if (!isSecondEnabled() && isMillisecondEnabled()) {
System.out.println("Sorry, seconds are disabled, millisecond must be disabled too."); System.out.println(
this.properties.setProperty(TimeCalcProperties.CLOCK_HANDS_MILLISECOND_ENABLED, "false"); "Sorry, seconds are disabled, millisecond must be disabled too.");
this.properties.setProperty(
TimeCalcProperties.CLOCK_HANDS_MILLISECOND_ENABLED,
"false");
} }
} }
@ -55,6 +61,7 @@ public class TimeCalcProperties {
public boolean isSecondEnabled() { public boolean isSecondEnabled() {
return getBooleanProperty(CLOCK_HANDS_SECOND_ENABLED, true); return getBooleanProperty(CLOCK_HANDS_SECOND_ENABLED, true);
} }
public boolean isMillisecondEnabled() { public boolean isMillisecondEnabled() {
return getBooleanProperty(CLOCK_HANDS_MILLISECOND_ENABLED, false); return getBooleanProperty(CLOCK_HANDS_MILLISECOND_ENABLED, false);
} }
@ -85,15 +92,18 @@ public class TimeCalcProperties {
public Boolean areCommandsEnabled() { public Boolean areCommandsEnabled() {
return getBooleanProperty(COMMANDS_ENABLED, true); 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;
} }
return properties.get(key).equals("true"); return properties.get(key).equals("true");
} }
public void load() { public void load() {
//to be implemented //to be implemented
} }
public void save() { public void save() {
//to be implemented //to be implemented
} }

View File

@ -8,22 +8,28 @@ import org.nanoboot.utils.timecalc.utils.property.StringProperty;
*/ */
public enum Visibility { public enum Visibility {
STRONGLY_COLORED, WEAKLY_COLORED, GRAY, NONE; STRONGLY_COLORED, WEAKLY_COLORED, GRAY, NONE;
public boolean isStronglyColored() {
return this == STRONGLY_COLORED;
}
public boolean isWeaklyColored() {
return this == WEAKLY_COLORED;
}
public boolean isGray() {
return this == GRAY;
}
public boolean isNone() {
return this == NONE;
}
public boolean isNotNone() {
return !isNone();
}
public static Visibility ofProperty(StringProperty stringProperty) { public static Visibility ofProperty(StringProperty stringProperty) {
return Visibility.valueOf(stringProperty.getValue()); return Visibility.valueOf(stringProperty.getValue());
} }
public boolean isStronglyColored() {
return this == STRONGLY_COLORED;
}
public boolean isWeaklyColored() {
return this == WEAKLY_COLORED;
}
public boolean isGray() {
return this == GRAY;
}
public boolean isNone() {
return this == NONE;
}
public boolean isNotNone() {
return !isNone();
}
} }

View File

@ -27,5 +27,4 @@ public class WorkingDay {
private int overtimeHoursToBeCompensatedUntilThisDay; private int overtimeHoursToBeCompensatedUntilThisDay;
private int overtimeMinutesToBeCompensatedUntilThisDay; private int overtimeMinutesToBeCompensatedUntilThisDay;
} }

View File

@ -11,20 +11,23 @@ import java.util.Set;
*/ */
public class ComponentRegistry { public class ComponentRegistry {
private final Set<Component> set = new HashSet<>(); private final Set<Component> set = new HashSet<>();
public ComponentRegistry() { public ComponentRegistry() {
} }
public void add(JComponent component) { public void add(JComponent component) {
this.set.add(component); this.set.add(component);
} }
public void addAll(JComponent... component) { public void addAll(JComponent... component) {
for(JComponent c:component) { for (JComponent c : component) {
add(c); add(c);
} }
} }
public void setVisible(boolean b) { public void setVisible(boolean b) {
for(Component c:set) { for (Component c : set) {
c.setVisible(b); c.setVisible(b);
} }
} }

View File

@ -14,11 +14,12 @@ import java.awt.Color;
public class TimeCalcButton extends JButton { public class TimeCalcButton extends JButton {
private static final int BUTTON_WIDTH = 100; private static final int BUTTON_WIDTH = 100;
private static final int BUTTON_HEIGHT = 30; private static final int BUTTON_HEIGHT = 30;
public StringProperty visibilityProperty =
new StringProperty("visibilityProperty",
Visibility.STRONGLY_COLORED.name());
private Color originalBackground; private Color originalBackground;
private Color originalForeground; private Color originalForeground;
public StringProperty visibilityProperty = new StringProperty("visibilityProperty", Visibility.STRONGLY_COLORED.name());
public TimeCalcButton(String label) { public TimeCalcButton(String label) {
super(label); super(label);
} }
@ -29,11 +30,12 @@ public class TimeCalcButton extends JButton {
this.originalForeground = getForeground(); this.originalForeground = getForeground();
new Timer(100, e -> repaint()).start(); new Timer(100, e -> repaint()).start();
} }
public void setOriginalBackground() { public void setOriginalBackground() {
this.setBackground(originalBackground);; this.setBackground(originalBackground);
} }
public void setOriginalForeground() { public void setOriginalForeground() {
this.setForeground(originalForeground);; this.setForeground(originalForeground);
} }
} }

View File

@ -21,7 +21,7 @@ public class TimeCalcWindow extends JFrame {
} }
public Component[] addAll(Component... comp) { public Component[] addAll(Component... comp) {
for(Component c:comp) { for (Component c : comp) {
add(c); add(c);
} }
return comp; return comp;

View File

@ -2,7 +2,6 @@ package org.nanoboot.utils.timecalc.swing.common;
import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.entity.Visibility;
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 javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.Timer; import javax.swing.Timer;
@ -19,23 +18,27 @@ public class Widget extends JPanel {
protected static final Color FOREGROUND_COLOR = new Color(220, 220, 220); protected static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
protected static final Color FOREGROUND_COLOR2 = new Color(210, 210, 210); protected static final Color FOREGROUND_COLOR2 = new Color(210, 210, 210);
protected static final Color BACKGROUND_COLOR = new Color(238, 238, 238); protected static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
public StringProperty visibilityProperty =
new StringProperty("widget.visibilityProperty",
Visibility.STRONGLY_COLORED.name());
protected int side = 0; protected int side = 0;
protected double donePercent = 0; protected double donePercent = 0;
protected boolean mouseOver = false; protected boolean mouseOver = false;
public StringProperty visibilityProperty = new StringProperty("widget.visibilityProperty", Visibility.STRONGLY_COLORED.name());
public Widget() { public Widget() {
setBackground(BACKGROUND_COLOR); setBackground(BACKGROUND_COLOR);
new Timer(getTimerDelay(), e -> repaint()).start(); new Timer(getTimerDelay(), e -> repaint()).start();
addMouseListener(new MouseListener() { addMouseListener(new MouseListener() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
Visibility visibility = Visibility.valueOf(visibilityProperty.getValue()); Visibility visibility =
if(visibility.isStronglyColored()) { Visibility.valueOf(visibilityProperty.getValue());
visibilityProperty.setValue(Visibility.WEAKLY_COLORED.name()); if (visibility.isStronglyColored()) {
visibilityProperty
.setValue(Visibility.WEAKLY_COLORED.name());
} else { } else {
visibilityProperty.setValue(Visibility.STRONGLY_COLORED.name()); visibilityProperty
.setValue(Visibility.STRONGLY_COLORED.name());
} }
} }
@ -83,7 +86,8 @@ public class Widget extends JPanel {
public final void paintComponent(Graphics g) { public final void paintComponent(Graphics g) {
super.paintComponent(g); super.paintComponent(g);
Visibility visibility = Visibility.valueOf(visibilityProperty.getValue()); Visibility visibility =
Visibility.valueOf(visibilityProperty.getValue());
this.setVisible(visibility != Visibility.NONE); this.setVisible(visibility != Visibility.NONE);
paintWidget(g); paintWidget(g);

View File

@ -2,9 +2,10 @@ package org.nanoboot.utils.timecalc.swing.progress;
import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.entity.Visibility;
import org.nanoboot.utils.timecalc.swing.common.Widget; import org.nanoboot.utils.timecalc.swing.common.Widget;
import org.nanoboot.utils.timecalc.app.TimeCalcProperties;
import org.nanoboot.utils.timecalc.utils.common.DateFormats; import org.nanoboot.utils.timecalc.utils.common.DateFormats;
import org.nanoboot.utils.timecalc.utils.common.TimeHM; import org.nanoboot.utils.timecalc.utils.common.TimeHM;
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
import org.nanoboot.utils.timecalc.utils.property.IntegerProperty;
import javax.swing.JFrame; import javax.swing.JFrame;
import java.awt.BasicStroke; import java.awt.BasicStroke;
@ -17,49 +18,57 @@ import java.awt.RenderingHints;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
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/ //https://kodejava.org/how-do-i-write-a-simple-analog-clock-using-java-2d/
public class AnalogClock extends Widget { public class AnalogClock extends Widget {
public static final Color COLOR_FOR_MILLISECOND_HAND_STRONGLY_COLORED = new Color(246, public static final Color COLOR_FOR_MILLISECOND_HAND_STRONGLY_COLORED =
152, 51); new Color(246,
private TimeHM startTime; 152, 51);
private TimeHM endTime; public IntegerProperty startHourProperty =
private int startAngle; new IntegerProperty("startHourProperty");
private int endAngle; public IntegerProperty startMinuteProperty =
new IntegerProperty("startMinuteProperty");
public IntegerProperty startHourProperty = new IntegerProperty("startHourProperty"); public IntegerProperty endHourProperty =
public IntegerProperty startMinuteProperty = new IntegerProperty("startMinuteProperty"); new IntegerProperty("endHourProperty");
public IntegerProperty endHourProperty = new IntegerProperty("endHourProperty"); public IntegerProperty endMinuteProperty =
public IntegerProperty endMinuteProperty = new IntegerProperty("endMinuteProperty"); new IntegerProperty("endMinuteProperty");
public IntegerProperty yearProperty = new IntegerProperty("yearProperty"); public IntegerProperty yearProperty = new IntegerProperty("yearProperty");
public IntegerProperty monthProperty = new IntegerProperty("monthProperty"); public IntegerProperty monthProperty = new IntegerProperty("monthProperty");
public IntegerProperty dayProperty = new IntegerProperty("dayProperty"); public IntegerProperty dayProperty = new IntegerProperty("dayProperty");
public IntegerProperty hourProperty = new IntegerProperty("hourProperty"); public IntegerProperty hourProperty = new IntegerProperty("hourProperty");
public IntegerProperty minuteProperty = new IntegerProperty("minuteProperty"); public IntegerProperty minuteProperty =
public IntegerProperty secondProperty = new IntegerProperty("secondProperty"); new IntegerProperty("minuteProperty");
public IntegerProperty millisecondProperty = new IntegerProperty("millisecondProperty"); public IntegerProperty secondProperty =
public IntegerProperty dayOfWeekProperty = new IntegerProperty("dayOfWeekProperty"); new IntegerProperty("secondProperty");
public BooleanProperty secondEnabledProperty = new BooleanProperty("secondEnabledProperty", true); public IntegerProperty millisecondProperty =
public BooleanProperty millisecondEnabledProperty = new BooleanProperty("millisecondEnabledProperty", false); new IntegerProperty("millisecondProperty");
public BooleanProperty handsLongProperty = new BooleanProperty("handsLongProperty", true); public IntegerProperty dayOfWeekProperty =
new IntegerProperty("dayOfWeekProperty");
public BooleanProperty secondEnabledProperty =
new BooleanProperty("secondEnabledProperty", true);
public BooleanProperty millisecondEnabledProperty =
new BooleanProperty("millisecondEnabledProperty", false);
public BooleanProperty handsLongProperty =
new BooleanProperty("handsLongProperty", true);
private TimeHM startTime;
private final TimeHM endTime;
private int startAngle;
private final int endAngle;
public AnalogClock(TimeHM startTimeIn, public AnalogClock(TimeHM startTimeIn,
TimeHM endTimeIn) { TimeHM endTimeIn) {
this.endTime = endTimeIn.cloneInstance(); this.endTime = endTimeIn.cloneInstance();
this.endAngle = this.endAngle =
(int) ((endTime.getHour() + endTime.getMinute() / 60d) / 12d * 360d); (int) ((endTime.getHour() + endTime.getMinute() / 60d) / 12d
if(endTime.getHour() >12) { * 360d);
if (endTime.getHour() > 12) {
endTime.setHour(endTime.getHour() - 12); endTime.setHour(endTime.getHour() - 12);
} }
this.startTime = startTimeIn.cloneInstance(); this.startTime = startTimeIn.cloneInstance();
this.startAngle = this.startAngle =
(int) ((startTime.getHour() + startTime.getMinute() / 60d) / 12d * 360d); (int) ((startTime.getHour() + startTime.getMinute() / 60d) / 12d
* 360d);
setPreferredSize(new Dimension(200, 200)); setPreferredSize(new Dimension(200, 200));
@ -73,30 +82,31 @@ public class AnalogClock extends Widget {
window.add(clock); window.add(clock);
window.pack(); window.pack();
window.setVisible(true); window.setVisible(true);
// window.addKeyListener(new KeyAdapter() { // window.addKeyListener(new KeyAdapter() {
// // Key Pressed method // // Key Pressed method
// public void keyPressed(KeyEvent e) { // public void keyPressed(KeyEvent e) {
// if (e.getKeyCode() == KeyEvent.VK_UP) { // if (e.getKeyCode() == KeyEvent.VK_UP) {
// clock.startAngle_++; // clock.startAngle_++;
// } // }
// if (e.getKeyCode() == KeyEvent.VK_DOWN) { // if (e.getKeyCode() == KeyEvent.VK_DOWN) {
// clock.startAngle_--; // clock.startAngle_--;
// } // }
// //
// if (e.getKeyCode() == KeyEvent.VK_RIGHT) { // if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
// clock.arcAngle_++; // clock.arcAngle_++;
// } // }
// if (e.getKeyCode() == KeyEvent.VK_LEFT) { // if (e.getKeyCode() == KeyEvent.VK_LEFT) {
// clock.arcAngle_--; // clock.arcAngle_--;
// } // }
// } // }
// }); // });
} }
@Override @Override
public void paintWidget(Graphics g) { public void paintWidget(Graphics g) {
Visibility visibility = Visibility.valueOf(visibilityProperty.getValue()); Visibility visibility =
Visibility.valueOf(visibilityProperty.getValue());
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);
@ -105,22 +115,23 @@ public class AnalogClock extends Widget {
int centerX = getWidth() / 2; int centerX = getWidth() / 2;
int centerY = getHeight() / 2; int centerY = getHeight() / 2;
int millisecond = millisecondProperty.getValue(); int millisecond = millisecondProperty.getValue();
int second = secondProperty.getValue(); int second = secondProperty.getValue();
int minute = minuteProperty.getValue(); int minute = minuteProperty.getValue();
int hour = hourProperty.getValue(); int hour = hourProperty.getValue();
if(mouseOver && visibility.isStronglyColored()) { if (mouseOver && visibility.isStronglyColored()) {
this.startTime = new TimeHM(hour, minute); this.startTime = new TimeHM(hour, minute);
this.startAngle = this.startAngle =
(int) ((startTime.getHour() + startTime.getMinute() / 60d) / 12d * 360d); (int) ((startTime.getHour() + startTime.getMinute() / 60d)
/ 12d * 360d);
Color currentColor = g2d.getColor(); Color currentColor = g2d.getColor();
g2d.setColor(Color.YELLOW); g2d.setColor(Color.YELLOW);
g2d.fillArc(0, 0, side, side, -startAngle +90, startAngle - endAngle); g2d.fillArc(0, 0, side, side, -startAngle + 90,
startAngle - endAngle);
//System.out.println("ANGLES: " + startAngle + " " + endAngle + " " + angleDiff ); //System.out.println("ANGLES: " + startAngle + " " + endAngle + " " + angleDiff );
g2d.setColor(currentColor); g2d.setColor(currentColor);
} }
@ -129,7 +140,7 @@ public class AnalogClock extends Widget {
drawClockFace(g2d, centerX, centerY, side / 2 - 40, visibility); drawClockFace(g2d, centerX, centerY, side / 2 - 40, visibility);
// //
if(millisecondEnabledProperty.isEnabled()) { if (millisecondEnabledProperty.isEnabled()) {
drawHand(g2d, side / 2 - 10, millisecond / 1000.0, 1.0f, drawHand(g2d, side / 2 - 10, millisecond / 1000.0, 1.0f,
COLOR_FOR_MILLISECOND_HAND_STRONGLY_COLORED, visibility); COLOR_FOR_MILLISECOND_HAND_STRONGLY_COLORED, visibility);
@ -142,14 +153,15 @@ public class AnalogClock extends Widget {
} }
} }
if(secondEnabledProperty.isEnabled()) { if (secondEnabledProperty.isEnabled()) {
drawHand(g2d, side / 2 - 10, second / 60.0, 0.5f, Color.RED, visibility); drawHand(g2d, side / 2 - 10, second / 60.0, 0.5f, Color.RED,
visibility);
if (handsLongProperty.isEnabled()) { if (handsLongProperty.isEnabled()) {
drawHand(g2d, (side / 2 - 10) / 4, drawHand(g2d, (side / 2 - 10) / 4,
(second > 30 ? second - 30 : second + 30) / 60.0, 0.5f, (second > 30 ? second - 30 : second + 30) / 60.0, 0.5f,
Color.RED, visibility); Color.RED, visibility);
} }
} }
// //
double minutes = minute / 60.0 + second / 60.0 / 60.0; double minutes = minute / 60.0 + second / 60.0 / 60.0;
@ -178,7 +190,8 @@ public class AnalogClock extends Widget {
private void drawCentre(Graphics2D g2d, int centerX, int centerY) { private void drawCentre(Graphics2D g2d, int centerX, int centerY) {
Color currentColor = g2d.getColor(); Color currentColor = g2d.getColor();
Visibility visibility = Visibility.valueOf(visibilityProperty.getValue()); Visibility visibility =
Visibility.valueOf(visibilityProperty.getValue());
g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.RED : g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.RED :
FOREGROUND_COLOR); FOREGROUND_COLOR);
g2d.fillOval(centerX - 3, centerY - 3, 8, 8); g2d.fillOval(centerX - 3, centerY - 3, 8, 8);
@ -211,15 +224,15 @@ public class AnalogClock extends Widget {
// g2d.drawOval(3, 3, centerX * 2 - 6, centerY * 2 - 6); // g2d.drawOval(3, 3, centerX * 2 - 6, centerY * 2 - 6);
// g2d.drawOval(4, 4, centerX * 2 - 8, centerY * 2 - 8); // g2d.drawOval(4, 4, centerX * 2 - 8, centerY * 2 - 8);
if(this.mouseOver) if (this.mouseOver) {
{
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, yearProperty.getValue()); cal.set(Calendar.YEAR, yearProperty.getValue());
cal.set(Calendar.MONTH, monthProperty.getValue() -1); cal.set(Calendar.MONTH, monthProperty.getValue() - 1);
cal.set(Calendar.DAY_OF_MONTH, dayProperty.getValue()); cal.set(Calendar.DAY_OF_MONTH, dayProperty.getValue());
Date date = cal.getTime(); Date date = cal.getTime();
g2d.drawString(DateFormats.DATE_TIME_FORMATTER_LONG.format(date), ((int) (side * 0.25)), g2d.drawString(DateFormats.DATE_TIME_FORMATTER_LONG.format(date),
((int) (side * 0.25)),
((int) (side * 0.35))); ((int) (side * 0.35)));
g2d.drawString(DateFormats.DATE_TIME_FORMATTER_TIME.format(date), g2d.drawString(DateFormats.DATE_TIME_FORMATTER_TIME.format(date),
((int) (side * 0.25) + 30), ((int) (side * 0.25) + 30),

View File

@ -1,12 +1,12 @@
package org.nanoboot.utils.timecalc.swing.progress; package org.nanoboot.utils.timecalc.swing.progress;
import lombok.Getter; import lombok.Getter;
import org.nanoboot.utils.timecalc.app.TimeCalcProperties;
import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.entity.Visibility;
import org.nanoboot.utils.timecalc.swing.common.Widget; import org.nanoboot.utils.timecalc.swing.common.Widget;
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.NumberFormats;
import org.nanoboot.utils.timecalc.utils.common.Utils; import org.nanoboot.utils.timecalc.utils.common.Utils;
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
@ -28,19 +28,17 @@ public class Battery extends Widget {
public static final double LOW_ENERGY = 0.15; public static final double LOW_ENERGY = 0.15;
public static final double HIGH_ENERGY = 0.75; public static final double HIGH_ENERGY = 0.75;
public static final double VERY_HIGH_ENERGY = 0.9; public static final double VERY_HIGH_ENERGY = 0.9;
public BooleanProperty wavesProperty = new BooleanProperty("waves", true);
private static final Font bigFont = new Font("sans", Font.BOLD, 24); private static final Font bigFont = new Font("sans", Font.BOLD, 24);
private BooleanProperty blinking = new BooleanProperty("blinking");
private long tmpNanoTime = 0l;
@Getter @Getter
private final String name; private final String name;
private final double[] randomDoubles =
new double[] {1d, 1d, 1d, 1d, 1d, 1d, 1};
public BooleanProperty wavesProperty = new BooleanProperty("waves", true);
private final BooleanProperty blinking = new BooleanProperty("blinking");
private long tmpNanoTime = 0l;
private int totalHeight = 0; private int totalHeight = 0;
private int totalWidth; private int totalWidth;
private String label = null; private String label = null;
private final double[] randomDoubles = new double[] {1d, 1d, 1d, 1d, 1d, 1d, 1};
protected Battery(String name) { protected Battery(String name) {
this.name = name; this.name = name;
@ -58,19 +56,22 @@ public class Battery extends Widget {
this.totalHeight = (int) (this.getHeight() / 10d * 7d); this.totalHeight = (int) (this.getHeight() / 10d * 7d);
this.totalWidth = this.getWidth(); this.totalWidth = this.getWidth();
} }
if(donePercent > 0 && donePercent < CRITICAL_LOW_ENERGY && (System.nanoTime() - tmpNanoTime) > (1000000000l) / 2l) { if (donePercent > 0 && donePercent < CRITICAL_LOW_ENERGY
&& (System.nanoTime() - tmpNanoTime) > (1000000000l) / 2l) {
blinking.flip(); blinking.flip();
tmpNanoTime = System.nanoTime(); tmpNanoTime = System.nanoTime();
} }
if(donePercent <= 0 && blinking.getValue()){ if (donePercent <= 0 && blinking.getValue()) {
blinking.setValue(false); blinking.setValue(false);
} }
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g;
Visibility visibility = Visibility.valueOf(visibilityProperty.getValue()); Visibility visibility =
g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.YELLOW : Visibility.valueOf(visibilityProperty.getValue());
FOREGROUND_COLOR); g2d.setColor(
visibility.isStronglyColored() || mouseOver ? Color.YELLOW :
FOREGROUND_COLOR);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);
@ -80,18 +81,22 @@ public class Battery extends Widget {
if (visibility.isStronglyColored() || mouseOver) { if (visibility.isStronglyColored() || mouseOver) {
g2d.setColor( g2d.setColor(
donePercent < LOW_ENERGY ? LOW_HIGHLIGHTED : (donePercent < HIGH_ENERGY ? donePercent < LOW_ENERGY ? LOW_HIGHLIGHTED :
MEDIUM_HIGHLIGHTED : (donePercent < HIGH_ENERGY ?
(donePercent < VERY_HIGH_ENERGY ? HIGH_HIGHLIGHTED : MEDIUM_HIGHLIGHTED :
HIGHEST_HIGHLIGHTED))); (donePercent < VERY_HIGH_ENERGY ?
HIGH_HIGHLIGHTED :
HIGHEST_HIGHLIGHTED)));
} else { } else {
g2d.setColor(donePercent < LOW_ENERGY ? LOW : (donePercent < HIGH_ENERGY ? g2d.setColor(donePercent < LOW_ENERGY ? LOW :
MEDIUM : (donePercent < VERY_HIGH_ENERGY ? HIGH : HIGHEST))); (donePercent < HIGH_ENERGY ?
MEDIUM :
(donePercent < VERY_HIGH_ENERGY ? HIGH : HIGHEST)));
} }
if (visibility.isGray()) { if (visibility.isGray()) {
g2d.setColor(Utils.ULTRA_LIGHT_GRAY); g2d.setColor(Utils.ULTRA_LIGHT_GRAY);
} }
if(blinking.getValue()) { if (blinking.getValue()) {
g2d.setColor(BACKGROUND_COLOR); g2d.setColor(BACKGROUND_COLOR);
} }
int doneHeight = (int) (totalHeight * donePercent); int doneHeight = (int) (totalHeight * donePercent);
@ -106,9 +111,11 @@ public class Battery extends Widget {
waterSurfaceHeight = 0; waterSurfaceHeight = 0;
} }
g2d.fillRect(intX+1, doneHeight < waterSurfaceHeight || donePercent >= 1 ? g2d.fillRect(intX + 1,
doneHeight < waterSurfaceHeight || donePercent >= 1 ?
todoHeight : todoHeight + waterSurfaceHeight, todoHeight : todoHeight + waterSurfaceHeight,
totalWidth - 3, doneHeight < waterSurfaceHeight || donePercent >= 1 ? totalWidth - 3,
doneHeight < waterSurfaceHeight || donePercent >= 1 ?
doneHeight : doneHeight - waterSurfaceHeight + 1); doneHeight : doneHeight - waterSurfaceHeight + 1);
int pointCount = 8; int pointCount = 8;
if (doneHeight >= waterSurfaceHeight if (doneHeight >= waterSurfaceHeight
@ -140,41 +147,43 @@ public class Battery extends Widget {
todoHeight + (waterSurfaceHeight * 1)}, todoHeight + (waterSurfaceHeight * 1)},
pointCount); pointCount);
g2d.setColor((visibility.isGray() || !visibility.isStronglyColored()) && !mouseOver ? Utils.ULTRA_LIGHT_GRAY : Color.DARK_GRAY); g2d.setColor(
(visibility.isGray() || !visibility.isStronglyColored())
&& !mouseOver ? Utils.ULTRA_LIGHT_GRAY : Color.DARK_GRAY);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF); RenderingHints.VALUE_ANTIALIAS_OFF);
g2d.drawPolyline( g2d.drawPolyline(
new int[] {intX, new int[] {intX,
(int) (intX + totalWidth / pointCount * 0.5), (int) (intX + totalWidth / pointCount * 0.5),
intX + totalWidth / pointCount * 3, intX + totalWidth / pointCount * 3,
intX + totalWidth / pointCount * 4, intX + totalWidth / pointCount * 4,
intX + totalWidth / pointCount * 5, intX + totalWidth / pointCount * 5,
intX + totalWidth / pointCount * 6, intX + totalWidth / pointCount * 6,
intX + totalWidth / pointCount * 7, intX + totalWidth / pointCount * 7,
intX + totalWidth / pointCount * 8}, intX + totalWidth / pointCount * 8},
new int[] {todoHeight + (waterSurfaceHeight * 1), new int[] {todoHeight + (waterSurfaceHeight * 1),
todoHeight + (int) (waterSurfaceHeight * getRandom( todoHeight + (int) (waterSurfaceHeight * getRandom(
0, true)), 0, true)),
todoHeight + (int) (waterSurfaceHeight * getRandom( todoHeight + (int) (waterSurfaceHeight * getRandom(
1, true)), 1, true)),
todoHeight + (int) (waterSurfaceHeight * getRandom( todoHeight + (int) (waterSurfaceHeight * getRandom(
2, true)), 2, true)),
todoHeight + (int) (waterSurfaceHeight * getRandom( todoHeight + (int) (waterSurfaceHeight * getRandom(
3, true)), 3, true)),
todoHeight + (int) (waterSurfaceHeight * getRandom( todoHeight + (int) (waterSurfaceHeight * getRandom(
4, true)), 4, true)),
todoHeight + (int) (waterSurfaceHeight * getRandom( todoHeight + (int) (waterSurfaceHeight * getRandom(
5, true)), 5, true)),
todoHeight + (waterSurfaceHeight * 1)}, todoHeight + (waterSurfaceHeight * 1)},
pointCount); pointCount);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);
} }
g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.BLACK : g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.BLACK :
Color.LIGHT_GRAY); Color.LIGHT_GRAY);
if(donePercent <1) { if (donePercent < 1) {
Font currentFont = g2d.getFont(); Font currentFont = g2d.getFont();
g2d.setFont(bigFont); g2d.setFont(bigFont);
g2d.drawString("", ((int) (totalWidth * 0.45)), g2d.drawString("", ((int) (totalWidth * 0.45)),
@ -184,7 +193,8 @@ public class Battery extends Widget {
} }
g2d.drawString( g2d.drawString(
NumberFormats.FORMATTER_THREE_DECIMAL_PLACES.format(donePercent * 100) + "%", NumberFormats.FORMATTER_THREE_DECIMAL_PLACES
.format(donePercent * 100) + "%",
((int) (totalWidth * 0.15)), ((int) (totalWidth * 0.15)),
donePercent > 0.5 ? totalHeight / 4 * 3 : totalHeight / 4 * 1); donePercent > 0.5 ? totalHeight / 4 * 3 : totalHeight / 4 * 1);
@ -210,6 +220,7 @@ public class Battery extends Widget {
private double getRandom(int index) { private double getRandom(int index) {
return getRandom(index, false); return getRandom(index, false);
} }
private double getRandom(int index, boolean keepArray) { private double getRandom(int index, boolean keepArray) {
if (!keepArray && Math.random() > 0.96) { if (!keepArray && Math.random() > 0.96) {
randomDoubles[index] = Math.random(); randomDoubles[index] = Math.random();
@ -226,8 +237,9 @@ public class Battery extends Widget {
} }
public void setBounds(int x, int y, int height) { public void setBounds(int x, int y, int height) {
setBounds(x, y, (int) (40d / 100d * ((double)height)), height); setBounds(x, y, (int) (40d / 100d * ((double) height)), height);
} }
public int getTimerDelay() { public int getTimerDelay() {
return 25; return 25;
} }

View File

@ -4,7 +4,7 @@ package org.nanoboot.utils.timecalc.swing.progress;
* @author Robert Vokac * @author Robert Vokac
* @since 21.02.2024 * @since 21.02.2024
*/ */
public class DayBattery extends Battery{ public class DayBattery extends Battery {
public DayBattery(int x, int i, int i1) { public DayBattery(int x, int i, int i1) {
super("Day", x, i, i1); super("Day", x, i, i1);
} }

View File

@ -6,13 +6,15 @@ import org.nanoboot.utils.timecalc.utils.common.TimeHM;
* @author Robert Vokac * @author Robert Vokac
* @since 21.02.2024 * @since 21.02.2024
*/ */
public class HourBattery extends Battery{ public class HourBattery extends Battery {
public HourBattery(int x, int i, int i1) { public HourBattery(int x, int i, int i1) {
super("Hour", x, i, i1); super("Hour", x, i, i1);
} }
public static double getHourProgress(TimeHM timeRemains, int secondsRemains, public static double getHourProgress(TimeHM timeRemains, int secondsRemains,
int millisecondsRemains) { int millisecondsRemains) {
if(secondsRemains < 0 || millisecondsRemains < 0 || timeRemains.getHour() < 0 || timeRemains.getMinute() < 0) { if (secondsRemains < 0 || millisecondsRemains < 0
|| timeRemains.getHour() < 0 || timeRemains.getMinute() < 0) {
return 1; return 1;
} }
double minutesRemainsD = timeRemains.getMinute(); double minutesRemainsD = timeRemains.getMinute();

View File

@ -4,17 +4,19 @@ package org.nanoboot.utils.timecalc.swing.progress;
* @author Robert Vokac * @author Robert Vokac
* @since 21.02.2024 * @since 21.02.2024
*/ */
public class MonthBattery extends Battery{ public class MonthBattery extends Battery {
public MonthBattery(int x, int i, int i1) { public MonthBattery(int x, int i, int i1) {
super("Month", x, i, i1); super("Month", x, i, i1);
} }
public static double getMonthProgress(int weekDayWhenMondayIsOne, int workDaysDone, int workDaysTotal, double done) {
if(done >1) { public static double getMonthProgress(int weekDayWhenMondayIsOne,
int workDaysDone, int workDaysTotal, double done) {
if (done > 1) {
done = 1; done = 1;
} }
return weekDayWhenMondayIsOne == 0 return weekDayWhenMondayIsOne == 0
|| weekDayWhenMondayIsOne == 6 ? || weekDayWhenMondayIsOne == 6 ?
workDaysDone / workDaysTotal : workDaysDone / workDaysTotal :
(workDaysDone + done) / workDaysTotal; (workDaysDone + done) / workDaysTotal;
} }
} }

View File

@ -3,7 +3,6 @@ package org.nanoboot.utils.timecalc.swing.progress;
import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.entity.Visibility;
import org.nanoboot.utils.timecalc.swing.common.Widget; import org.nanoboot.utils.timecalc.swing.common.Widget;
import org.nanoboot.utils.timecalc.utils.common.NumberFormats; import org.nanoboot.utils.timecalc.utils.common.NumberFormats;
import org.nanoboot.utils.timecalc.utils.common.Utils;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
@ -22,10 +21,12 @@ public class ProgressCircle extends Widget {
if (side == 0) { if (side == 0) {
this.side = Math.min(getWidth(), getHeight()); this.side = Math.min(getWidth(), getHeight());
} }
Visibility visibility = Visibility.valueOf(visibilityProperty.getValue()); Visibility visibility =
Visibility.valueOf(visibilityProperty.getValue());
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g;
g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.darkGray : g2d.setColor(
FOREGROUND_COLOR); visibility.isStronglyColored() || mouseOver ? Color.darkGray :
FOREGROUND_COLOR);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);
@ -39,10 +40,13 @@ public class ProgressCircle extends Widget {
new Color(105, 175, 236) : FOREGROUND_COLOR2); new Color(105, 175, 236) : FOREGROUND_COLOR2);
g2d.fillArc(0 + (side2 / 2), 0 + (side2 / 2), side2, side2, 90, g2d.fillArc(0 + (side2 / 2), 0 + (side2 / 2), side2, side2, 90,
-(int) angleDouble2); -(int) angleDouble2);
g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.blue :FOREGROUND_COLOR); g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.blue :
FOREGROUND_COLOR);
g2d.drawString( g2d.drawString(
NumberFormats.FORMATTER_ZERO_DECIMAL_PLACES.format(donePercent * 100) + "%", (int)(side / 8d * 0d),(int)(side / 8d * 7.5d)); NumberFormats.FORMATTER_ZERO_DECIMAL_PLACES
.format(donePercent * 100) + "%",
(int) (side / 8d * 0d), (int) (side / 8d * 7.5d));
} }
} }

View File

@ -3,7 +3,6 @@ package org.nanoboot.utils.timecalc.swing.progress;
import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.entity.Visibility;
import org.nanoboot.utils.timecalc.swing.common.Widget; import org.nanoboot.utils.timecalc.swing.common.Widget;
import org.nanoboot.utils.timecalc.utils.common.NumberFormats; import org.nanoboot.utils.timecalc.utils.common.NumberFormats;
import org.nanoboot.utils.timecalc.utils.common.Utils;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
@ -75,9 +74,13 @@ public class ProgressSquare extends Widget {
} }
g2d.setColor(FOREGROUND_COLOR); g2d.setColor(FOREGROUND_COLOR);
} }
g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.BLACK : BACKGROUND_COLOR); g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.BLACK :
BACKGROUND_COLOR);
g2d.drawString(NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES.format(donePercent * 100) + "%", (int)(side/8d*3d),(int)(side/8d*(donePercent > 0.5 ? 3d : 5d))); g2d.drawString(NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES
.format(donePercent * 100) + "%",
(int) (side / 8d * 3d),
(int) (side / 8d * (donePercent > 0.5 ? 3d : 5d)));
} }

View File

@ -3,38 +3,53 @@ package org.nanoboot.utils.timecalc.swing.progress;
import org.nanoboot.utils.timecalc.utils.property.IntegerProperty; import org.nanoboot.utils.timecalc.utils.property.IntegerProperty;
import org.nanoboot.utils.timecalc.utils.property.ReadOnlyProperty; import org.nanoboot.utils.timecalc.utils.property.ReadOnlyProperty;
import javax.swing.Timer;
import java.awt.Graphics;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
public class Time extends Thread { public class Time extends Thread {
private IntegerProperty yearReadWriteProperty = new IntegerProperty("yearProperty"); private final IntegerProperty yearReadWriteProperty =
private IntegerProperty monthReadWriteProperty = new IntegerProperty("monthProperty"); new IntegerProperty("yearProperty");
private IntegerProperty dayReadWriteProperty = new IntegerProperty("dayProperty"); public ReadOnlyProperty<Integer> yearProperty =
private IntegerProperty hourReadWriteProperty = new IntegerProperty("hourProperty"); yearReadWriteProperty.asReadOnlyProperty();
private IntegerProperty minuteReadWriteProperty = new IntegerProperty("minuteProperty"); private final IntegerProperty monthReadWriteProperty =
private IntegerProperty secondReadWriteProperty = new IntegerProperty("secondProperty"); new IntegerProperty("monthProperty");
private IntegerProperty millisecondReadWriteProperty = new IntegerProperty("millisecondProperty"); public ReadOnlyProperty<Integer> monthProperty =
private IntegerProperty dayOfWeekReadWriteProperty = new IntegerProperty("dayOfWeek"); monthReadWriteProperty.asReadOnlyProperty();
public ReadOnlyProperty<Integer> yearProperty = yearReadWriteProperty.asReadOnlyProperty(); private final IntegerProperty dayReadWriteProperty =
public ReadOnlyProperty<Integer> monthProperty = monthReadWriteProperty.asReadOnlyProperty(); new IntegerProperty("dayProperty");
public ReadOnlyProperty<Integer> dayProperty = dayReadWriteProperty.asReadOnlyProperty(); public ReadOnlyProperty<Integer> dayProperty =
public ReadOnlyProperty<Integer> hourProperty = hourReadWriteProperty.asReadOnlyProperty(); dayReadWriteProperty.asReadOnlyProperty();
public ReadOnlyProperty<Integer> minuteProperty = minuteReadWriteProperty.asReadOnlyProperty(); private final IntegerProperty hourReadWriteProperty =
public ReadOnlyProperty<Integer> secondProperty = secondReadWriteProperty.asReadOnlyProperty(); new IntegerProperty("hourProperty");
public ReadOnlyProperty<Integer> millisecondProperty = millisecondReadWriteProperty.asReadOnlyProperty(); public ReadOnlyProperty<Integer> hourProperty =
public ReadOnlyProperty<Integer> dayOfWeek = dayOfWeekReadWriteProperty.asReadOnlyProperty(); hourReadWriteProperty.asReadOnlyProperty();
private final IntegerProperty minuteReadWriteProperty =
new IntegerProperty("minuteProperty");
public ReadOnlyProperty<Integer> minuteProperty =
minuteReadWriteProperty.asReadOnlyProperty();
private final IntegerProperty secondReadWriteProperty =
new IntegerProperty("secondProperty");
public ReadOnlyProperty<Integer> secondProperty =
secondReadWriteProperty.asReadOnlyProperty();
private final IntegerProperty millisecondReadWriteProperty =
new IntegerProperty("millisecondProperty");
public ReadOnlyProperty<Integer> millisecondProperty =
millisecondReadWriteProperty.asReadOnlyProperty();
private final IntegerProperty dayOfWeekReadWriteProperty =
new IntegerProperty("dayOfWeek");
public ReadOnlyProperty<Integer> dayOfWeek =
dayOfWeekReadWriteProperty.asReadOnlyProperty();
//private long lastUpdateNanoTime = 0l; //private long lastUpdateNanoTime = 0l;
public Time() { public Time() {
this.setDaemon(true); this.setDaemon(true);
start(); start();
} }
public void run() { public void run() {
while(true) { while (true) {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
cal.setTime(new Date()); cal.setTime(new Date());
yearReadWriteProperty.setValue(cal.get(Calendar.YEAR)); yearReadWriteProperty.setValue(cal.get(Calendar.YEAR));

View File

@ -4,16 +4,18 @@ package org.nanoboot.utils.timecalc.swing.progress;
* @author Robert Vokac * @author Robert Vokac
* @since 21.02.2024 * @since 21.02.2024
*/ */
public class WeekBattery extends Battery{ public class WeekBattery extends Battery {
public WeekBattery(int x, int i, int i1) { public WeekBattery(int x, int i, int i1) {
super("Week", x, i, i1); super("Week", x, i, i1);
} }
public static double getWeekProgress(int weekDayWhenMondayIsOne, double done) {
if(done >1) { public static double getWeekProgress(int weekDayWhenMondayIsOne,
double done) {
if (done > 1) {
done = 1; done = 1;
} }
return weekDayWhenMondayIsOne == 0 return weekDayWhenMondayIsOne == 0
|| weekDayWhenMondayIsOne == 6 ? || weekDayWhenMondayIsOne == 6 ?
100 : ((weekDayWhenMondayIsOne - 1) * 0.20 + done * 0.20); 100 : ((weekDayWhenMondayIsOne - 1) * 0.20 + done * 0.20);
} }
} }

View File

@ -10,9 +10,6 @@ import java.util.Locale;
* @since 21.02.2024 * @since 21.02.2024
*/ */
public class DateFormats { public class DateFormats {
private DateFormats() {
//Not meant to be instantiated.
}
public final static DateTimeFormatter DATE_TIME_FORMATTER_HHmmssSSS = public final static DateTimeFormatter DATE_TIME_FORMATTER_HHmmssSSS =
DateTimeFormatter.ofPattern("HH:mm:ss:SSS"); DateTimeFormatter.ofPattern("HH:mm:ss:SSS");
public static DateFormat DATE_TIME_FORMATTER_LONG = public static DateFormat DATE_TIME_FORMATTER_LONG =
@ -22,4 +19,7 @@ public class DateFormats {
new SimpleDateFormat("HH:mm:ss", Locale.ENGLISH); new SimpleDateFormat("HH:mm:ss", Locale.ENGLISH);
public static DateFormat DATE_TIME_FORMATTER_VERY_LONG = public static DateFormat DATE_TIME_FORMATTER_VERY_LONG =
new SimpleDateFormat("yyyy:MM:dd:HH:mm:ss:EEEE", Locale.ENGLISH); new SimpleDateFormat("yyyy:MM:dd:HH:mm:ss:EEEE", Locale.ENGLISH);
private DateFormats() {
//Not meant to be instantiated.
}
} }

View File

@ -7,10 +7,10 @@ import java.io.File;
* @since 21.02.2024 * @since 21.02.2024
*/ */
public class FileConstants { public class FileConstants {
private FileConstants() {
//Not meant to be instantiated.
}
public static final File STARTTIME_TXT = new File("starttime.txt"); public static final File STARTTIME_TXT = new File("starttime.txt");
public static final File OVERTIME_TXT = new File("overtime.txt"); public static final File OVERTIME_TXT = new File("overtime.txt");
public static final File TEST_TXT = new File("test.txt"); public static final File TEST_TXT = new File("test.txt");
private FileConstants() {
//Not meant to be instantiated.
}
} }

View File

@ -1,7 +1,7 @@
package org.nanoboot.utils.timecalc.utils.common; package org.nanoboot.utils.timecalc.utils.common;
import org.nanoboot.utils.timecalc.swing.common.Toaster;
import org.nanoboot.utils.timecalc.app.TimeCalcProperties; import org.nanoboot.utils.timecalc.app.TimeCalcProperties;
import org.nanoboot.utils.timecalc.swing.common.Toaster;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JTextPane; import javax.swing.JTextPane;
@ -63,7 +63,7 @@ public class Jokes {
} }
public static void showRandom() { public static void showRandom() {
if(!TimeCalcProperties.getInstance().areJokesEnabled()) { if (!TimeCalcProperties.getInstance().areJokesEnabled()) {
//nothing to do //nothing to do
return; return;
} }

View File

@ -3,7 +3,6 @@ package org.nanoboot.utils.timecalc.utils.common;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
/** /**
* @author Robert Vokac * @author Robert Vokac
* @since 15.02.2024 * @since 15.02.2024
@ -15,9 +14,9 @@ public class JokesTxt {
public static String[] getAsArray() throws IOException { public static String[] getAsArray() throws IOException {
File jokeTxtFile = new File("jokes.txt"); File jokeTxtFile = new File("jokes.txt");
if(!jokeTxtFile.exists()) { if (!jokeTxtFile.exists()) {
//nothing to do //nothing to do
return new String[]{"A","B","C"}; return new String[] {"A", "B", "C"};
} }
return Utils.readTextFromFile(jokeTxtFile).split("-----SEPARATOR-----"); return Utils.readTextFromFile(jokeTxtFile).split("-----SEPARATOR-----");
} }

View File

@ -8,11 +8,15 @@ import java.text.NumberFormat;
* @since 21.02.2024 * @since 21.02.2024
*/ */
public class NumberFormats { public class NumberFormats {
public static final NumberFormat FORMATTER_ZERO_DECIMAL_PLACES =
new DecimalFormat("#00");
public static final NumberFormat FORMATTER_TWO_DECIMAL_PLACES =
new DecimalFormat("#00.00");
public static final NumberFormat FORMATTER_FIVE_DECIMAL_PLACES =
new DecimalFormat("#0.00000");
public static final NumberFormat FORMATTER_THREE_DECIMAL_PLACES =
new DecimalFormat("#0.000");
private NumberFormats() { private NumberFormats() {
//Not meant to be instantiated. //Not meant to be instantiated.
} }
public static final NumberFormat FORMATTER_ZERO_DECIMAL_PLACES = new DecimalFormat("#00");
public static final NumberFormat FORMATTER_TWO_DECIMAL_PLACES = new DecimalFormat("#00.00");
public static final NumberFormat FORMATTER_FIVE_DECIMAL_PLACES = new DecimalFormat("#0.00000");
public static final NumberFormat FORMATTER_THREE_DECIMAL_PLACES = new DecimalFormat("#0.000");
} }

View File

@ -12,9 +12,11 @@ public class TimeHM {
public static final int MILLISECONDS_PER_SECOND = 1000; public static final int MILLISECONDS_PER_SECOND = 1000;
public static final int SECONDS_PER_MINUTE = 60; public static final int SECONDS_PER_MINUTE = 60;
@Getter @Setter @Getter
@Setter
private Integer hour; private Integer hour;
@Getter @Setter @Getter
@Setter
private Integer minute; private Integer minute;
public TimeHM(String string) { public TimeHM(String string) {
@ -41,8 +43,11 @@ public class TimeHM {
} }
public static int countDiffInMinutes(TimeHM startTime, TimeHM endTime) { public static int countDiffInMinutes(TimeHM startTime, TimeHM endTime) {
return (endTime.getHour() * TimeHM.MINUTES_PER_HOUR + endTime.getMinute()) - (startTime.getHour() * TimeHM.MINUTES_PER_HOUR + startTime.getMinute()); return (endTime.getHour() * TimeHM.MINUTES_PER_HOUR + endTime
.getMinute()) - (startTime.getHour() * TimeHM.MINUTES_PER_HOUR
+ startTime.getMinute());
} }
public TimeHM cloneInstance() { public TimeHM cloneInstance() {
return new TimeHM(hour, minute); return new TimeHM(hour, minute);
} }

View File

@ -20,8 +20,9 @@ import java.util.jar.Manifest;
*/ */
public class Utils { public class Utils {
public static final BooleanProperty toastsAreEnabled = new BooleanProperty("toastsAreEnabled", true); public static final BooleanProperty toastsAreEnabled =
public static final Color ULTRA_LIGHT_GRAY = new Color(216,216,216); new BooleanProperty("toastsAreEnabled", true);
public static final Color ULTRA_LIGHT_GRAY = new Color(216, 216, 216);
/** /**
* Count of bytes per one kilobyte. * Count of bytes per one kilobyte.
*/ */
@ -81,10 +82,9 @@ public class Utils {
((int) (Math.random() * 256)), ((int) (Math.random() * 256))); ((int) (Math.random() * 256)), ((int) (Math.random() * 256)));
} }
/** /**
* Returns version of "Time Calc" from jar file. * Returns version of "Time Calc" from jar file.
*
* @return version * @return version
*/ */
public static String getVersion() { public static String getVersion() {
@ -94,6 +94,7 @@ public class Utils {
/** /**
* Returns build date of "Time Calc" from jar file. * Returns build date of "Time Calc" from jar file.
*
* @return build date * @return build date
*/ */
public static String getBuildDate() { public static String getBuildDate() {
@ -103,8 +104,9 @@ public class Utils {
if (!classPath.startsWith("jar")) { if (!classPath.startsWith("jar")) {
return null; return null;
} }
String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) String manifestPath =
+ "/META-INF/MANIFEST.MF"; classPath.substring(0, classPath.lastIndexOf("!") + 1)
+ "/META-INF/MANIFEST.MF";
Manifest manifest; Manifest manifest;
try { try {
manifest = new Manifest(new URL(manifestPath).openStream()); manifest = new Manifest(new URL(manifestPath).openStream());
@ -115,6 +117,7 @@ public class Utils {
Attributes attr = manifest.getMainAttributes(); Attributes attr = manifest.getMainAttributes();
return attr.getValue("Build-Date"); return attr.getValue("Build-Date");
} }
public static byte[] decodeBase64ToByteArray(String s) { public static byte[] decodeBase64ToByteArray(String s) {
Base64.Decoder base64Decoder = Base64.getDecoder(); Base64.Decoder base64Decoder = Base64.getDecoder();
return base64Decoder return base64Decoder

View File

@ -9,9 +9,11 @@ public class BooleanProperty extends Property<Boolean> {
public BooleanProperty(String name) { public BooleanProperty(String name) {
super(name, Boolean.FALSE); super(name, Boolean.FALSE);
} }
public BooleanProperty(String name, boolean valueIn) { public BooleanProperty(String name, boolean valueIn) {
this(name, Boolean.valueOf(valueIn)); this(name, Boolean.valueOf(valueIn));
} }
public BooleanProperty(String name, Boolean valueIn) { public BooleanProperty(String name, Boolean valueIn) {
super(name, valueIn); super(name, valueIn);
} }
@ -19,20 +21,23 @@ public class BooleanProperty extends Property<Boolean> {
public boolean isEnabled() { public boolean isEnabled() {
return getValue(); return getValue();
} }
public boolean isDisabled() { public boolean isDisabled() {
return !getValue(); return !getValue();
} }
public void flip() { public void flip() {
setValue(!getValue()); setValue(!getValue());
} }
public void inverse() { public void inverse() {
flip(); flip();
} }
public void enable() { public void enable() {
setValue(true); setValue(true);
} }
public void disable() { public void disable() {
setValue(false); setValue(false);
} }

View File

@ -9,6 +9,7 @@ public class BooleanReadOnlyProperty extends ReadOnlyProperty<Boolean> {
public BooleanReadOnlyProperty(String name, Boolean valueIn) { public BooleanReadOnlyProperty(String name, Boolean valueIn) {
super(name, valueIn); super(name, valueIn);
} }
public BooleanReadOnlyProperty(Property<Boolean> property) { public BooleanReadOnlyProperty(Property<Boolean> property) {
super(property); super(property);
} }
@ -16,6 +17,7 @@ public class BooleanReadOnlyProperty extends ReadOnlyProperty<Boolean> {
public boolean isEnabled() { public boolean isEnabled() {
return getValue(); return getValue();
} }
public boolean isDisabled() { public boolean isDisabled() {
return !getValue(); return !getValue();
} }

View File

@ -4,6 +4,6 @@ package org.nanoboot.utils.timecalc.utils.property;
* @author Robert Vokac * @author Robert Vokac
* @since 23.02.2024 * @since 23.02.2024
*/ */
public interface ChangeListener<T> { public interface ChangeListener<T> {
void changed(Property<T> property, T oldValue, T newValue); void changed(Property<T> property, T oldValue, T newValue);
} }

View File

@ -10,70 +10,83 @@ import java.util.List;
* @author Robert Vokac * @author Robert Vokac
* @since 23.02.2024 * @since 23.02.2024
*/ */
public class Property <T>{ public class Property<T> {
private boolean valid = true;
@Getter @Getter
private final String name; private final String name;
private boolean valid = true;
private T value; private T value;
private Property<T> boundToProperty = null; private Property<T> boundToProperty = null;
private List<InvalidationListener> invalidationListeners = new ArrayList<>(); private final List<InvalidationListener> invalidationListeners =
private List<ChangeListener<T>> new ArrayList<>();
private final List<ChangeListener<T>>
changeListeners = new ArrayList<ChangeListener<T>>(); changeListeners = new ArrayList<ChangeListener<T>>();
public Property(String name, T valueIn) { public Property(String name, T valueIn) {
this.name = name; this.value = valueIn; this.name = name;
this.value = valueIn;
} }
public ReadOnlyProperty<T> asReadOnlyProperty() { public ReadOnlyProperty<T> asReadOnlyProperty() {
return new ReadOnlyProperty<>(this); return new ReadOnlyProperty<>(this);
} }
public WriteOnlyProperty<T> asWriteOnlyProperty() { public WriteOnlyProperty<T> asWriteOnlyProperty() {
return new WriteOnlyProperty<>(this); return new WriteOnlyProperty<>(this);
} }
public boolean isBound() { public boolean isBound() {
return boundToProperty != null; return boundToProperty != null;
} }
public void unBound() { public void unBound() {
if(!isBound()) { if (!isBound()) {
throw new TimeCalcException("No bound property"); throw new TimeCalcException("No bound property");
} }
this.value = boundToProperty.value; this.value = boundToProperty.value;
this.boundToProperty = null; this.boundToProperty = null;
} }
public void bindTo(Property<T> anotherProperty) { public void bindTo(Property<T> anotherProperty) {
this.boundToProperty = anotherProperty; this.boundToProperty = anotherProperty;
this.boundToProperty.addListener((Property<T> p, T oldValue, T newValue) -> {this.markInvalid();this.fireValueChangedEvent(oldValue); this.boundToProperty
//System.out.println("bindTo markInvalid " + p.getName() + " " + p.getValue()); .addListener((Property<T> p, T oldValue, T newValue) -> {
} ); this.markInvalid();
this.fireValueChangedEvent(oldValue);
//System.out.println("bindTo markInvalid " + p.getName() + " " + p.getValue());
});
} }
public T getValue() { public T getValue() {
return isBound() ? this.boundToProperty.getValue() : value; return isBound() ? this.boundToProperty.getValue() : value;
} }
public void setValue(T newValue) { public void setValue(T newValue) {
if(isBound()) { if (isBound()) {
this.boundToProperty.setValue(newValue); this.boundToProperty.setValue(newValue);
} else { } else {
T oldValue = value; T oldValue = value;
this.value = newValue; this.value = newValue;
if(!oldValue.equals(newValue)) if (!oldValue.equals(newValue)) {
{
fireValueChangedEvent(oldValue); fireValueChangedEvent(oldValue);
markInvalid(); markInvalid();
} }
} }
} }
public boolean isValid() { public boolean isValid() {
return isBound() ? this.boundToProperty.isValid() : valid; return isBound() ? this.boundToProperty.isValid() : valid;
} }
protected void markInvalid() { protected void markInvalid() {
// System.out.println(name + " is invalid now"); // System.out.println(name + " is invalid now");
valid = false; valid = false;
for (InvalidationListener listener : invalidationListeners) { for (InvalidationListener listener : invalidationListeners) {
listener.invalidated(this); listener.invalidated(this);
} }
} }
protected void fireValueChangedEvent(T oldValue) { protected void fireValueChangedEvent(T oldValue) {
// System.out.println(name + " was changed"); // System.out.println(name + " was changed");
for (ChangeListener listener : changeListeners) { for (ChangeListener listener : changeListeners) {
listener.changed(this, oldValue, value); listener.changed(this, oldValue, value);
} }
@ -83,9 +96,9 @@ public class Property <T>{
public void addListener(InvalidationListener listener) { public void addListener(InvalidationListener listener) {
this.invalidationListeners.add(listener); this.invalidationListeners.add(listener);
} }
public void addListener(ChangeListener<T> listener) { public void addListener(ChangeListener<T> listener) {
this.changeListeners.add(listener); this.changeListeners.add(listener);
} }
} }

View File

@ -6,14 +6,17 @@ import org.nanoboot.utils.timecalc.app.TimeCalcException;
* @author Robert Vokac * @author Robert Vokac
* @since 23.02.2024 * @since 23.02.2024
*/ */
public class PropertyWrapper <T> { public class PropertyWrapper<T> {
private Property<T> innerProperty; private Property<T> innerProperty;
public final void unBound() { public final void unBound() {
throw new TimeCalcException("This is a write only property. Unbounding is forbiden."); throw new TimeCalcException(
"This is a write only property. Unbounding is forbiden.");
} }
public final void bindTo(Property<T> anotherProperty) { public final void bindTo(Property<T> anotherProperty) {
throw new TimeCalcException("This is a write only property. Bounding to another property is forbiden."); throw new TimeCalcException(
"This is a write only property. Bounding to another property is forbiden.");
} }
} }

View File

@ -7,32 +7,44 @@ import org.nanoboot.utils.timecalc.app.TimeCalcException;
* @since 23.02.2024 * @since 23.02.2024
*/ */
public class ReadOnlyProperty<T> extends Property<T> { public class ReadOnlyProperty<T> extends Property<T> {
private Property<T> innerProperty; private final Property<T> innerProperty;
public ReadOnlyProperty(String name, T valueIn) { public ReadOnlyProperty(String name, T valueIn) {
super(name, valueIn); super(name, valueIn);
throw new TimeCalcException("This constructor is forbidden in class " + getClass().getName() + "."); throw new TimeCalcException(
"This constructor is forbidden in class " + getClass().getName()
+ ".");
} }
public ReadOnlyProperty(Property<T> property) { public ReadOnlyProperty(Property<T> property) {
super(property.getName(), null); super(property.getName(), null);
this.innerProperty = property; this.innerProperty = property;
this.innerProperty.addListener((Property p) -> {markInvalid();} ); this.innerProperty.addListener((Property p) -> {
} markInvalid();
public final void setValue(T newValue) { });
throw new TimeCalcException("This is a read only property. New value cannot be set.");
} }
public final T getValue() { public final T getValue() {
return innerProperty.getValue(); return innerProperty.getValue();
} }
public final void setValue(T newValue) {
throw new TimeCalcException(
"This is a read only property. New value cannot be set.");
}
public final void unBound() { public final void unBound() {
throw new TimeCalcException("This is a write only property. Unbounding is forbiden."); throw new TimeCalcException(
"This is a write only property. Unbounding is forbiden.");
} }
public final void bindTo(Property<T> anotherProperty) { public final void bindTo(Property<T> anotherProperty) {
throw new TimeCalcException("This is a write only property. Bounding to another property is forbiden."); throw new TimeCalcException(
"This is a write only property. Bounding to another property is forbiden.");
} }
public boolean isValid() { public boolean isValid() {
return this.innerProperty.isValid(); return this.innerProperty.isValid();
} }
} }

View File

@ -9,6 +9,7 @@ public class StringReadOnlyProperty extends ReadOnlyProperty<String> {
public StringReadOnlyProperty(String name, String valueIn) { public StringReadOnlyProperty(String name, String valueIn) {
super(name, valueIn); super(name, valueIn);
} }
public StringReadOnlyProperty(Property<String> property) { public StringReadOnlyProperty(Property<String> property) {
super(property); super(property);
} }

View File

@ -7,28 +7,37 @@ import org.nanoboot.utils.timecalc.app.TimeCalcException;
* @since 23.02.2024 * @since 23.02.2024
*/ */
public class WriteOnlyProperty<T> extends Property<T> { public class WriteOnlyProperty<T> extends Property<T> {
private Property<T> innerProperty; private final Property<T> innerProperty;
public WriteOnlyProperty(String name, T valueIn) { public WriteOnlyProperty(String name, T valueIn) {
super(name, valueIn); super(name, valueIn);
throw new TimeCalcException("This constructor is forbidden in class " + getClass().getName() + "."); throw new TimeCalcException(
"This constructor is forbidden in class " + getClass().getName()
+ ".");
} }
public WriteOnlyProperty(Property<T> property) { public WriteOnlyProperty(Property<T> property) {
super(property.getName(), null); super(property.getName(), null);
this.innerProperty = property; this.innerProperty = property;
} }
public final void setValue(T newValue) { public final void setValue(T newValue) {
this.innerProperty.setValue(newValue); this.innerProperty.setValue(newValue);
} }
public final T getValue(T valueIn) { public final T getValue(T valueIn) {
throw new TimeCalcException("This is a write only property. Current value cannot be read."); throw new TimeCalcException(
} "This is a write only property. Current value cannot be read.");
public final void unBound() {
throw new TimeCalcException("This is a write only property. Unbounding is forbiden.");
}
public final void bindTo(Property<T> anotherProperty) {
throw new TimeCalcException("This is a write only property. Bounding to another property is forbiden.");
} }
public final void unBound() {
throw new TimeCalcException(
"This is a write only property. Unbounding is forbiden.");
}
public final void bindTo(Property<T> anotherProperty) {
throw new TimeCalcException(
"This is a write only property. Bounding to another property is forbiden.");
}
} }