Formatted code
This commit is contained in:
parent
b71e63950c
commit
a863709d4f
@ -3,8 +3,8 @@ package org.nanoboot.utils.timecalc.app;
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Constants;
|
||||
import org.nanoboot.utils.timecalc.utils.common.FileConstants;
|
||||
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import java.io.IOException;
|
||||
@ -15,11 +15,13 @@ import java.io.IOException;
|
||||
*/
|
||||
public class TimeCalcApp {
|
||||
|
||||
public StringProperty visibilityProperty =
|
||||
new StringProperty("timeCalcApp.visibilityReadWriteProperty",
|
||||
Visibility.WEAKLY_COLORED.name());
|
||||
private long startNanoTime = 0l;
|
||||
public StringProperty visibilityProperty = new StringProperty("timeCalcApp.visibilityReadWriteProperty", Visibility.WEAKLY_COLORED.name());
|
||||
|
||||
public void start(String[] args) throws IOException {
|
||||
if(startNanoTime != 0l) {
|
||||
if (startNanoTime != 0l) {
|
||||
throw new TimeCalcException("TimeCalcApp was already started.");
|
||||
}
|
||||
startNanoTime = System.nanoTime();
|
||||
@ -74,11 +76,13 @@ public class TimeCalcApp {
|
||||
public long getCountOfMinutesSinceAppStarted() {
|
||||
return getCountOfSecondsSinceAppStarted() / 60l;
|
||||
}
|
||||
|
||||
public long getCountOfSecondsSinceAppStarted() {
|
||||
return getCountOfMillisecondsSinceAppStarted() / 1000000000l;
|
||||
}
|
||||
|
||||
public long getCountOfMillisecondsSinceAppStarted() {
|
||||
if(startNanoTime == 0l) {
|
||||
if (startNanoTime == 0l) {
|
||||
throw new TimeCalcException("TimeCalcApp was not yet started.");
|
||||
}
|
||||
return System.nanoTime() - startNanoTime;
|
||||
|
@ -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.StringProperty;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author Robert Vokac
|
||||
* @since 20.02.2024
|
||||
*/
|
||||
public class TimeCalcConfiguration {
|
||||
public final BooleanProperty clockHandLongProperty = new BooleanProperty("clockHandLongProperty", true);
|
||||
public final BooleanProperty clockHandSecondEnabledProperty = new BooleanProperty("clockHandSecondEnabledProperty", true);
|
||||
public final BooleanProperty clockHandMillisecondEnabledProperty = new BooleanProperty("clockHandMillisecondEnabledProperty", false);
|
||||
public final BooleanProperty batteryWavesEnabledProperty = new BooleanProperty("batteryWavesEnabledProperty", true);
|
||||
public final BooleanProperty clockHandLongProperty =
|
||||
new BooleanProperty("clockHandLongProperty", true);
|
||||
public final BooleanProperty clockHandSecondEnabledProperty =
|
||||
new BooleanProperty("clockHandSecondEnabledProperty", true);
|
||||
public final BooleanProperty clockHandMillisecondEnabledProperty =
|
||||
new BooleanProperty("clockHandMillisecondEnabledProperty", false);
|
||||
public final BooleanProperty batteryWavesEnabledProperty =
|
||||
new BooleanProperty("batteryWavesEnabledProperty", true);
|
||||
public final StringProperty
|
||||
defaultVisibilityProperty = new StringProperty("defaultVisibilityProperty",
|
||||
Visibility.STRONGLY_COLORED.name());
|
||||
public final BooleanProperty visibilityOnlyGreyOrNoneEnabledProperty = new BooleanProperty("visibilityOnlyGreyOrNoneEnabledProperty", false);
|
||||
public final BooleanProperty jokesEnabledProperty = new BooleanProperty("jokesEnabledProperty", true);
|
||||
public final BooleanProperty commandsEnabledProperty = new BooleanProperty("commandsEnabledProperty", true);
|
||||
public final BooleanProperty toastsEnabledProperty = new BooleanProperty("toastsEnabledProperty", true);
|
||||
defaultVisibilityProperty =
|
||||
new StringProperty("defaultVisibilityProperty",
|
||||
Visibility.STRONGLY_COLORED.name());
|
||||
public final BooleanProperty visibilityOnlyGreyOrNoneEnabledProperty =
|
||||
new BooleanProperty("visibilityOnlyGreyOrNoneEnabledProperty",
|
||||
false);
|
||||
public final BooleanProperty jokesEnabledProperty =
|
||||
new BooleanProperty("jokesEnabledProperty", true);
|
||||
public final BooleanProperty commandsEnabledProperty =
|
||||
new BooleanProperty("commandsEnabledProperty", true);
|
||||
public final BooleanProperty toastsEnabledProperty =
|
||||
new BooleanProperty("toastsEnabledProperty", true);
|
||||
|
||||
public TimeCalcConfiguration() {
|
||||
|
||||
}
|
||||
public void setFromTimeCalcProperties(TimeCalcProperties timeCalcProperties) {
|
||||
|
||||
public void setFromTimeCalcProperties(
|
||||
TimeCalcProperties timeCalcProperties) {
|
||||
clockHandLongProperty.setValue(timeCalcProperties.areClockHandsLong());
|
||||
clockHandSecondEnabledProperty.setValue(timeCalcProperties.isSecondEnabled());
|
||||
clockHandMillisecondEnabledProperty.setValue(timeCalcProperties.isMillisecondEnabled());
|
||||
batteryWavesEnabledProperty.setValue(timeCalcProperties.areBatteryWavesEnabled());
|
||||
defaultVisibilityProperty.setValue(timeCalcProperties.getDefaultVisibility().name());
|
||||
visibilityOnlyGreyOrNoneEnabledProperty.setValue(timeCalcProperties.isVisibilityOnlyGreyOrNoneEnabled());
|
||||
clockHandSecondEnabledProperty
|
||||
.setValue(timeCalcProperties.isSecondEnabled());
|
||||
clockHandMillisecondEnabledProperty
|
||||
.setValue(timeCalcProperties.isMillisecondEnabled());
|
||||
batteryWavesEnabledProperty
|
||||
.setValue(timeCalcProperties.areBatteryWavesEnabled());
|
||||
defaultVisibilityProperty
|
||||
.setValue(timeCalcProperties.getDefaultVisibility().name());
|
||||
visibilityOnlyGreyOrNoneEnabledProperty.setValue(
|
||||
timeCalcProperties.isVisibilityOnlyGreyOrNoneEnabled());
|
||||
jokesEnabledProperty.setValue(timeCalcProperties.areJokesEnabled());
|
||||
commandsEnabledProperty.setValue(timeCalcProperties.areCommandsEnabled());
|
||||
commandsEnabledProperty
|
||||
.setValue(timeCalcProperties.areCommandsEnabled());
|
||||
toastsEnabledProperty.setValue(timeCalcProperties.areToastsEnabled());
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ package org.nanoboot.utils.timecalc.app;
|
||||
* @author Robert Vokac
|
||||
* @since 21.02.2024
|
||||
*/
|
||||
public class TimeCalcException extends RuntimeException{
|
||||
public class TimeCalcException extends RuntimeException {
|
||||
public TimeCalcException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
@ -47,10 +47,9 @@ import java.util.logging.Logger;
|
||||
* @since 08.02.2024
|
||||
*/
|
||||
public class TimeCalcManager {
|
||||
private static final int MARGIN = 10;
|
||||
public static final Color BG = new Color(238, 238, 238);
|
||||
public static final Color FG = new Color(210, 210, 210);
|
||||
|
||||
private static final int MARGIN = 10;
|
||||
private final String windowTitle;
|
||||
private final int totalMinutes;
|
||||
|
||||
@ -59,17 +58,19 @@ public class TimeCalcManager {
|
||||
private final TimeHM endTime;
|
||||
private final TimeCalcApp timeCalcApp;
|
||||
private boolean stopBeforeEnd = false;
|
||||
private Time time = new Time();
|
||||
private TimeCalcConfiguration timeCalcConfiguration = new TimeCalcConfiguration();
|
||||
private final Time time = new Time();
|
||||
private final TimeCalcConfiguration timeCalcConfiguration =
|
||||
new TimeCalcConfiguration();
|
||||
|
||||
public TimeCalcManager(String startTimeIn, String overTimeIn,
|
||||
TimeCalcApp timeCalcApp) {
|
||||
this.timeCalcApp = timeCalcApp;
|
||||
timeCalcConfiguration.setFromTimeCalcProperties(TimeCalcProperties.getInstance());
|
||||
// Utils.everythingHidden
|
||||
// .setValue(TimeCalcConf.getInstance().isEverythingHidden());
|
||||
// Utils.toastsAreEnabled
|
||||
// .setValue(TimeCalcConf.getInstance().areToastsEnabled());
|
||||
timeCalcConfiguration
|
||||
.setFromTimeCalcProperties(TimeCalcProperties.getInstance());
|
||||
// Utils.everythingHidden
|
||||
// .setValue(TimeCalcConf.getInstance().isEverythingHidden());
|
||||
// Utils.toastsAreEnabled
|
||||
// .setValue(TimeCalcConf.getInstance().areToastsEnabled());
|
||||
|
||||
overTimeIn = (overTimeIn == null || overTimeIn.isEmpty()) ?
|
||||
Constants.DEFAULT_OVERTIME : overTimeIn;
|
||||
@ -77,8 +78,11 @@ public class TimeCalcManager {
|
||||
this.startTime = new TimeHM(startTimeIn);
|
||||
this.overtime = new TimeHM(overTimeIn);
|
||||
|
||||
this.endTime = new TimeHM(startTime.getHour() + Constants.WORKING_HOURS_LENGTH + overtime.getHour(),
|
||||
startTime.getMinute() + Constants.WORKING_MINUTES_LENGTH + overtime.getMinute());
|
||||
this.endTime = new TimeHM(
|
||||
startTime.getHour() + Constants.WORKING_HOURS_LENGTH + overtime
|
||||
.getHour(),
|
||||
startTime.getMinute() + Constants.WORKING_MINUTES_LENGTH
|
||||
+ overtime.getMinute());
|
||||
|
||||
this.totalMinutes = TimeHM.countDiffInMinutes(startTime, endTime);
|
||||
int totalSeconds = totalMinutes * TimeHM.SECONDS_PER_MINUTE;
|
||||
@ -99,54 +103,69 @@ public class TimeCalcManager {
|
||||
window.addKeyListener(new KeyAdapter() {
|
||||
// Key Pressed method
|
||||
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) {
|
||||
timeCalcApp.visibilityProperty.setValue(Visibility.STRONGLY_COLORED.name());
|
||||
timeCalcApp.visibilityProperty
|
||||
.setValue(Visibility.STRONGLY_COLORED.name());
|
||||
}
|
||||
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(visibility.isNone()) {
|
||||
timeCalcApp.visibilityProperty.setValue(Visibility.STRONGLY_COLORED.name());
|
||||
if (visibility.isNone()) {
|
||||
timeCalcApp.visibilityProperty
|
||||
.setValue(Visibility.STRONGLY_COLORED.name());
|
||||
} else {
|
||||
timeCalcApp.visibilityProperty.setValue(Visibility.NONE.name());
|
||||
timeCalcApp.visibilityProperty
|
||||
.setValue(Visibility.NONE.name());
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_G) {
|
||||
if(visibility.isGray()) {
|
||||
timeCalcApp.visibilityProperty.setValue(Visibility.WEAKLY_COLORED.name());
|
||||
if (visibility.isGray()) {
|
||||
timeCalcApp.visibilityProperty
|
||||
.setValue(Visibility.WEAKLY_COLORED.name());
|
||||
} else {
|
||||
timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name());
|
||||
timeCalcApp.visibilityProperty
|
||||
.setValue(Visibility.GRAY.name());
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getKeyCode() == KeyEvent.VK_C) {
|
||||
if(visibility.isStronglyColored()) {
|
||||
timeCalcApp.visibilityProperty.setValue(Visibility.WEAKLY_COLORED.name());
|
||||
if (visibility.isStronglyColored()) {
|
||||
timeCalcApp.visibilityProperty
|
||||
.setValue(Visibility.WEAKLY_COLORED.name());
|
||||
} else {
|
||||
timeCalcApp.visibilityProperty.setValue(Visibility.STRONGLY_COLORED.name());
|
||||
timeCalcApp.visibilityProperty
|
||||
.setValue(Visibility.STRONGLY_COLORED.name());
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_V) {
|
||||
if(visibility.isNone()) {
|
||||
timeCalcApp.visibilityProperty.setValue(Visibility.STRONGLY_COLORED.name());
|
||||
if (visibility.isNone()) {
|
||||
timeCalcApp.visibilityProperty
|
||||
.setValue(Visibility.STRONGLY_COLORED.name());
|
||||
} else {
|
||||
timeCalcApp.visibilityProperty.setValue(Visibility.NONE.name());
|
||||
timeCalcApp.visibilityProperty
|
||||
.setValue(Visibility.NONE.name());
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
|
||||
if(visibility.isStronglyColored()) {
|
||||
timeCalcApp.visibilityProperty.setValue(Visibility.WEAKLY_COLORED.name());
|
||||
if (visibility.isStronglyColored()) {
|
||||
timeCalcApp.visibilityProperty
|
||||
.setValue(Visibility.WEAKLY_COLORED.name());
|
||||
}
|
||||
if(visibility.isWeaklyColored()) {
|
||||
timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name());
|
||||
if (visibility.isWeaklyColored()) {
|
||||
timeCalcApp.visibilityProperty
|
||||
.setValue(Visibility.GRAY.name());
|
||||
}
|
||||
if(visibility.isGray()) {
|
||||
timeCalcApp.visibilityProperty.setValue(Visibility.NONE.name());
|
||||
if (visibility.isGray()) {
|
||||
timeCalcApp.visibilityProperty
|
||||
.setValue(Visibility.NONE.name());
|
||||
}
|
||||
if(visibility.isNone()) {
|
||||
timeCalcApp.visibilityProperty.setValue(Visibility.STRONGLY_COLORED.name());
|
||||
if (visibility.isNone()) {
|
||||
timeCalcApp.visibilityProperty
|
||||
.setValue(Visibility.STRONGLY_COLORED.name());
|
||||
}
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_R) {
|
||||
@ -159,18 +178,30 @@ public class TimeCalcManager {
|
||||
window.repaint();
|
||||
}
|
||||
});
|
||||
WalkingHumanProgressAsciiArt walkingHumanProgressAsciiArt = new WalkingHumanProgressAsciiArt();
|
||||
walkingHumanProgressAsciiArt.setBounds(MARGIN, MARGIN + 210 + MARGIN, 450, 180);
|
||||
WalkingHumanProgressAsciiArt walkingHumanProgressAsciiArt =
|
||||
new WalkingHumanProgressAsciiArt();
|
||||
walkingHumanProgressAsciiArt
|
||||
.setBounds(MARGIN, MARGIN + 210 + MARGIN, 450, 180);
|
||||
|
||||
window.add(walkingHumanProgressAsciiArt);
|
||||
weatherButton
|
||||
.setBounds(20, walkingHumanProgressAsciiArt.getY() + walkingHumanProgressAsciiArt.getHeight() + MARGIN);
|
||||
commandButton.setBounds(20, walkingHumanProgressAsciiArt.getY() + walkingHumanProgressAsciiArt.getHeight() + MARGIN);
|
||||
.setBounds(20, walkingHumanProgressAsciiArt.getY()
|
||||
+ 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
|
||||
.setBounds(280, walkingHumanProgressAsciiArt.getY() + walkingHumanProgressAsciiArt.getHeight() + MARGIN);
|
||||
exitButton.setBounds(390, walkingHumanProgressAsciiArt.getY() + walkingHumanProgressAsciiArt.getHeight() + MARGIN);
|
||||
.setBounds(280, walkingHumanProgressAsciiArt.getY()
|
||||
+ walkingHumanProgressAsciiArt.getHeight()
|
||||
+ MARGIN);
|
||||
exitButton.setBounds(390, walkingHumanProgressAsciiArt.getY()
|
||||
+ walkingHumanProgressAsciiArt.getHeight()
|
||||
+ MARGIN);
|
||||
aboutButton.setBounds(exitButton.getX(),
|
||||
exitButton.getY() + exitButton.getHeight() + MARGIN);
|
||||
|
||||
@ -201,17 +232,25 @@ public class TimeCalcManager {
|
||||
JOptionPane.showMessageDialog(null, "Test");
|
||||
break;
|
||||
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;
|
||||
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;
|
||||
case "waves":
|
||||
timeCalcConfiguration.batteryWavesEnabledProperty.setValue(commandsAsArray[1].equals("1"));
|
||||
timeCalcConfiguration.batteryWavesEnabledProperty
|
||||
.setValue(commandsAsArray[1].equals("1"));
|
||||
break;
|
||||
case "uptime":
|
||||
JOptionPane.showMessageDialog(null,
|
||||
timeCalcApp.getCountOfMinutesSinceAppStarted()
|
||||
timeCalcApp
|
||||
.getCountOfMinutesSinceAppStarted()
|
||||
+ " minutes");
|
||||
break;
|
||||
case "toast":
|
||||
@ -246,75 +285,97 @@ public class TimeCalcManager {
|
||||
stopBeforeEnd = true;
|
||||
});
|
||||
|
||||
Calendar calNow = Calendar.getInstance();
|
||||
Calendar calNow = Calendar.getInstance();
|
||||
calNow.setTime(new Date());
|
||||
|
||||
AnalogClock analogClock = new AnalogClock(startTime, endTime);
|
||||
analogClock.setBounds(MARGIN, MARGIN, 200);
|
||||
|
||||
|
||||
Properties testProperties = new Properties();
|
||||
File testPropertiesFile = new File("test.txt");
|
||||
try {
|
||||
if(testPropertiesFile.exists()) {
|
||||
if (testPropertiesFile.exists()) {
|
||||
testProperties.load(new FileInputStream(testPropertiesFile));
|
||||
}
|
||||
} 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) {
|
||||
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")) {
|
||||
calNow.set(Calendar.DAY_OF_MONTH, Integer.parseInt((String) testProperties.get("current.day")));
|
||||
analogClock.dayProperty.setValue(Integer.valueOf((String) testProperties.get("current.day")));
|
||||
if (testProperties.containsKey("current.day")) {
|
||||
calNow.set(Calendar.DAY_OF_MONTH, Integer.parseInt(
|
||||
(String) testProperties.get("current.day")));
|
||||
analogClock.dayProperty.setValue(Integer.valueOf(
|
||||
(String) testProperties.get("current.day")));
|
||||
} else {
|
||||
analogClock.dayProperty.bindTo(time.dayProperty);
|
||||
}
|
||||
if(testProperties.containsKey("current.month")) {
|
||||
calNow.set(Calendar.MONTH, Integer.parseInt((String) testProperties.get("current.month")) - 1);
|
||||
analogClock.monthProperty.setValue(Integer.valueOf((String) testProperties.get("current.month")));
|
||||
if (testProperties.containsKey("current.month")) {
|
||||
calNow.set(Calendar.MONTH, Integer.parseInt(
|
||||
(String) testProperties.get("current.month")) - 1);
|
||||
analogClock.monthProperty.setValue(Integer.valueOf(
|
||||
(String) testProperties.get("current.month")));
|
||||
} else {
|
||||
analogClock.monthProperty.bindTo(time.monthProperty);
|
||||
}
|
||||
if(testProperties.containsKey("current.year")) {
|
||||
calNow.set(Calendar.YEAR, Integer.parseInt((String) testProperties.get("current.year")));
|
||||
analogClock.yearProperty.setValue(Integer.valueOf((String) testProperties.get("current.year")));
|
||||
if (testProperties.containsKey("current.year")) {
|
||||
calNow.set(Calendar.YEAR, Integer.parseInt(
|
||||
(String) testProperties.get("current.year")));
|
||||
analogClock.yearProperty.setValue(Integer.valueOf(
|
||||
(String) testProperties.get("current.year")));
|
||||
} else {
|
||||
analogClock.yearProperty.bindTo(time.yearProperty);
|
||||
}
|
||||
if(testProperties.containsKey("current.year") || testProperties.containsKey("current.month") ||testProperties.containsKey("current.day")) {
|
||||
analogClock.dayOfWeekProperty.setValue(calNow.get(Calendar.DAY_OF_WEEK));
|
||||
if (testProperties.containsKey("current.year") || testProperties
|
||||
.containsKey("current.month") || testProperties
|
||||
.containsKey("current.day")) {
|
||||
analogClock.dayOfWeekProperty
|
||||
.setValue(calNow.get(Calendar.DAY_OF_WEEK));
|
||||
} else {
|
||||
analogClock.dayOfWeekProperty.bindTo(time.dayOfWeek);
|
||||
}
|
||||
if(testProperties.containsKey("current.hour")) {
|
||||
calNow.set(Calendar.HOUR, Integer.parseInt((String) testProperties.get("current.hour")));
|
||||
analogClock.hourProperty.setValue(Integer.valueOf((String) testProperties.get("current.hour")));
|
||||
if (testProperties.containsKey("current.hour")) {
|
||||
calNow.set(Calendar.HOUR, Integer.parseInt(
|
||||
(String) testProperties.get("current.hour")));
|
||||
analogClock.hourProperty.setValue(Integer.valueOf(
|
||||
(String) testProperties.get("current.hour")));
|
||||
} else {
|
||||
analogClock.hourProperty.bindTo(time.hourProperty);
|
||||
}
|
||||
if(testProperties.containsKey("current.minute")) {
|
||||
calNow.set(Calendar.MINUTE, Integer.parseInt((String) testProperties.get("current.minute")));
|
||||
analogClock.minuteProperty.setValue(Integer.valueOf((String) testProperties.get("current.minute")));
|
||||
if (testProperties.containsKey("current.minute")) {
|
||||
calNow.set(Calendar.MINUTE, Integer.parseInt(
|
||||
(String) testProperties.get("current.minute")));
|
||||
analogClock.minuteProperty.setValue(Integer.valueOf(
|
||||
(String) testProperties.get("current.minute")));
|
||||
} else {
|
||||
analogClock.minuteProperty.bindTo(time.minuteProperty);
|
||||
}
|
||||
if(testProperties.containsKey("current.second")) {
|
||||
calNow.set(Calendar.SECOND, Integer.parseInt((String) testProperties.get("current.second")));
|
||||
analogClock.secondProperty.setValue(Integer.valueOf((String) testProperties.get("current.second")));
|
||||
if (testProperties.containsKey("current.second")) {
|
||||
calNow.set(Calendar.SECOND, Integer.parseInt(
|
||||
(String) testProperties.get("current.second")));
|
||||
analogClock.secondProperty.setValue(Integer.valueOf(
|
||||
(String) testProperties.get("current.second")));
|
||||
} else {
|
||||
analogClock.secondProperty.bindTo(time.secondProperty);
|
||||
}
|
||||
|
||||
if(testProperties.containsKey("current.millisecond")) {
|
||||
calNow.set(Calendar.MILLISECOND, Integer.parseInt((String) testProperties.get("current.millisecond")));
|
||||
analogClock.millisecondProperty.setValue(Integer.valueOf((String) testProperties.get("current.millisecond")));
|
||||
|
||||
if (testProperties.containsKey("current.millisecond")) {
|
||||
calNow.set(Calendar.MILLISECOND, Integer.parseInt(
|
||||
(String) testProperties.get("current.millisecond")));
|
||||
analogClock.millisecondProperty.setValue(Integer.valueOf(
|
||||
(String) testProperties.get("current.millisecond")));
|
||||
} else {
|
||||
analogClock.millisecondProperty.bindTo(time.millisecondProperty);
|
||||
}
|
||||
analogClock.millisecondEnabledProperty.bindTo(timeCalcConfiguration.clockHandMillisecondEnabledProperty);
|
||||
analogClock.secondEnabledProperty.bindTo(timeCalcConfiguration.clockHandSecondEnabledProperty);
|
||||
analogClock.handsLongProperty.bindTo(timeCalcConfiguration.clockHandLongProperty);
|
||||
analogClock.millisecondEnabledProperty
|
||||
.bindTo(timeCalcConfiguration.clockHandMillisecondEnabledProperty);
|
||||
analogClock.secondEnabledProperty
|
||||
.bindTo(timeCalcConfiguration.clockHandSecondEnabledProperty);
|
||||
analogClock.handsLongProperty
|
||||
.bindTo(timeCalcConfiguration.clockHandLongProperty);
|
||||
|
||||
window.add(analogClock);
|
||||
|
||||
@ -334,10 +395,10 @@ public class TimeCalcManager {
|
||||
window.add(progressCircle);
|
||||
|
||||
Battery dayBattery = new DayBattery(progressCircle.getBounds().x,
|
||||
progressCircle.getY() + MARGIN + progressCircle.getHeight(), 140);
|
||||
progressCircle.getY() + MARGIN + progressCircle.getHeight(),
|
||||
140);
|
||||
window.add(dayBattery);
|
||||
|
||||
|
||||
Battery weekBattery = new WeekBattery(
|
||||
dayBattery.getBounds().x + dayBattery.getWidth() + MARGIN * 2,
|
||||
dayBattery.getY(), 140);
|
||||
@ -381,15 +442,29 @@ public class TimeCalcManager {
|
||||
|
||||
Rectangle dayRectangle = dayBattery.getBounds();
|
||||
hourBattery.setBounds(dayRectangle);
|
||||
hourBattery.setBounds(hourBattery.getX() + 2 * MARGIN, hourBattery.getY(), 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
|
||||
.setBounds(hourBattery.getX() + 2 * MARGIN, hourBattery.getY(),
|
||||
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);
|
||||
dayBattery.wavesProperty.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
|
||||
weekBattery.wavesProperty.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
|
||||
monthBattery.wavesProperty.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
|
||||
hourBattery.wavesProperty
|
||||
.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
|
||||
dayBattery.wavesProperty
|
||||
.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
|
||||
weekBattery.wavesProperty
|
||||
.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
|
||||
monthBattery.wavesProperty
|
||||
.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
|
||||
|
||||
ComponentRegistry componentRegistry = new ComponentRegistry();
|
||||
componentRegistry.addAll(
|
||||
@ -406,9 +481,12 @@ public class TimeCalcManager {
|
||||
restartButton,
|
||||
exitButton
|
||||
);
|
||||
walkingHumanProgressAsciiArt.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||
progressSquare.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||
progressCircle.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||
walkingHumanProgressAsciiArt.visibilityProperty
|
||||
.bindTo(timeCalcApp.visibilityProperty);
|
||||
progressSquare.visibilityProperty
|
||||
.bindTo(timeCalcApp.visibilityProperty);
|
||||
progressCircle.visibilityProperty
|
||||
.bindTo(timeCalcApp.visibilityProperty);
|
||||
analogClock.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||
dayBattery.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||
weekBattery.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||
@ -419,21 +497,30 @@ public class TimeCalcManager {
|
||||
restartButton.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||
exitButton.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||
|
||||
jokeButton.setVisible(!Visibility.valueOf(jokeButton.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());
|
||||
jokeButton.setVisible(
|
||||
!Visibility.valueOf(jokeButton.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)-> {
|
||||
// System.out.println("Visibility of timeCalcApp was changed FROM " + oldValue + " TO " + newValue);
|
||||
// } );
|
||||
// analogClock.visibilityProperty.addListener((Property<String> p, String oldValue, String newValue)-> {
|
||||
// System.out.println("Visibility of analogClock was changed FROM " + oldValue + " TO " + newValue);
|
||||
// } );
|
||||
window.setSize(520 + 20 + 100, exitButton.getY() + 3 * exitButton.getHeight() + MARGIN);
|
||||
// timeCalcApp.visibilityProperty.addListener((Property<String> p, String oldValue, String newValue)-> {
|
||||
// System.out.println("Visibility of timeCalcApp was changed FROM " + oldValue + " TO " + newValue);
|
||||
// } );
|
||||
// analogClock.visibilityProperty.addListener((Property<String> p, String oldValue, String newValue)-> {
|
||||
// System.out.println("Visibility of analogClock was changed FROM " + oldValue + " TO " + newValue);
|
||||
// } );
|
||||
window.setSize(520 + 20 + 100,
|
||||
exitButton.getY() + 3 * exitButton.getHeight() + MARGIN);
|
||||
while (true) {
|
||||
//time.writeString();
|
||||
if(Math.random() > 0.95) {
|
||||
if (Math.random() > 0.95) {
|
||||
window.requestFocus();
|
||||
}
|
||||
if (stopBeforeEnd) {
|
||||
@ -442,7 +529,8 @@ public class TimeCalcManager {
|
||||
break;
|
||||
}
|
||||
|
||||
Visibility visibility = Visibility.valueOf(timeCalcApp.visibilityProperty.getValue());
|
||||
Visibility visibility = Visibility
|
||||
.valueOf(timeCalcApp.visibilityProperty.getValue());
|
||||
componentRegistry.setVisible(visibility.isNotNone());
|
||||
if (!visibility.isStronglyColored() || visibility.isGray()) {
|
||||
jokeButton.setBackground(BG);
|
||||
@ -480,13 +568,17 @@ public class TimeCalcManager {
|
||||
|
||||
int secondNow = Integer.parseInt(nowString.split(":")[2]);
|
||||
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 millisecondsRemains = 1000 - millisecondNow;
|
||||
|
||||
int hourDone = Constants.WORKING_HOURS_LENGTH + overtime.getHour() - timeRemains.getHour();
|
||||
int minutesDone = Constants.WORKING_MINUTES_LENGTH + overtime.getMinute() - timeRemains.getMinute();
|
||||
int hourDone = Constants.WORKING_HOURS_LENGTH + overtime.getHour()
|
||||
- timeRemains.getHour();
|
||||
int minutesDone =
|
||||
Constants.WORKING_MINUTES_LENGTH + overtime.getMinute()
|
||||
- timeRemains.getMinute();
|
||||
int secondsDone = secondNow;
|
||||
int millisecondsDone = millisecondNow;
|
||||
|
||||
@ -502,17 +594,21 @@ public class TimeCalcManager {
|
||||
dayBattery.setDonePercent(done);
|
||||
|
||||
int weekDayWhenMondayIsOne = calNow.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
weekBattery.setDonePercent(WeekBattery.getWeekProgress(weekDayWhenMondayIsOne, done));
|
||||
weekBattery.setDonePercent(
|
||||
WeekBattery.getWeekProgress(weekDayWhenMondayIsOne, done));
|
||||
weekBattery.setLabel(
|
||||
nowIsWeekend ? "5/5" : (weekDayWhenMondayIsOne + "/5"));
|
||||
|
||||
monthBattery.setDonePercent(MonthBattery.getMonthProgress(weekDayWhenMondayIsOne, workDaysDone, workDaysTotal, done));
|
||||
monthBattery.setDonePercent(MonthBattery
|
||||
.getMonthProgress(weekDayWhenMondayIsOne, workDaysDone,
|
||||
workDaysTotal, done));
|
||||
monthBattery.setLabel(
|
||||
(nowIsWeekend ? workDaysDone : workDaysDone + 1) + "/"
|
||||
+ (workDaysTotal));
|
||||
|
||||
hourBattery.setDonePercent(HourBattery.getHourProgress(timeRemains, secondsRemains,
|
||||
millisecondsRemains));
|
||||
hourBattery.setDonePercent(
|
||||
HourBattery.getHourProgress(timeRemains, secondsRemains,
|
||||
millisecondsRemains));
|
||||
if (!nowIsWeekend) {
|
||||
hourBattery.setLabel(
|
||||
hourDone + "/" + (
|
||||
@ -520,24 +616,28 @@ public class TimeCalcManager {
|
||||
}
|
||||
|
||||
int totalSecondsRemains =
|
||||
(timeRemains.getHour() * 60 * 60 + timeRemains.getMinute() * 60
|
||||
(timeRemains.getHour() * 60 * 60
|
||||
+ timeRemains.getMinute() * 60
|
||||
+ secondsRemains);
|
||||
int totalMillisecondsRemains =
|
||||
totalSecondsRemains * 1000 + millisecondsRemains;
|
||||
double totalSecondsRemainsDouble =
|
||||
((double) totalMillisecondsRemains) / 1000;
|
||||
|
||||
// if (timeRemains.getHour() == 0 && timeRemains.getMinute() <= 3) {
|
||||
// Utils.highlighted.set(true);
|
||||
// walkingHumanProgressAsciiArt.setForeground(Color.BLUE);
|
||||
// }
|
||||
// if (timeRemains.getHour() == 0 && timeRemains.getMinute() <= 3) {
|
||||
// Utils.highlighted.set(true);
|
||||
// walkingHumanProgressAsciiArt.setForeground(Color.BLUE);
|
||||
// }
|
||||
|
||||
if (timeRemains.getHour() <= 0 && timeRemains.getMinute() <= 0) {
|
||||
Toaster toasterManager = new Toaster();
|
||||
toasterManager.setDisplayTime(30000);
|
||||
toasterManager.showToaster(
|
||||
"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 {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
@ -551,7 +651,10 @@ public class TimeCalcManager {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
walkingHumanProgressAsciiArt.printPercentToAscii(done, timeRemains.getHour(), timeRemains.getMinute(), done,totalSecondsRemainsDouble, endTime);
|
||||
walkingHumanProgressAsciiArt
|
||||
.printPercentToAscii(done, timeRemains.getHour(),
|
||||
timeRemains.getMinute(), done,
|
||||
totalSecondsRemainsDouble, endTime);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -561,7 +664,8 @@ public class TimeCalcManager {
|
||||
}
|
||||
|
||||
walkingHumanProgressAsciiArt.setForeground(
|
||||
visibility.isStronglyColored() || walkingHumanProgressAsciiArt
|
||||
visibility.isStronglyColored()
|
||||
|| walkingHumanProgressAsciiArt
|
||||
.getClientProperty("mouseEntered").equals("true") ?
|
||||
Color.BLACK : Color.LIGHT_GRAY);
|
||||
}
|
||||
|
@ -13,11 +13,14 @@ import java.util.Properties;
|
||||
*/
|
||||
public class TimeCalcProperties {
|
||||
private static final String CLOCK_HANDS_LONG = "clock.hands.long";
|
||||
private static final String CLOCK_HANDS_SECOND_ENABLED = "clock.hands.second.enabled";
|
||||
private static final String CLOCK_HANDS_MILLISECOND_ENABLED = "clock.hands.millisecond.enabled";
|
||||
private static final String CLOCK_HANDS_SECOND_ENABLED =
|
||||
"clock.hands.second.enabled";
|
||||
private static final String CLOCK_HANDS_MILLISECOND_ENABLED =
|
||||
"clock.hands.millisecond.enabled";
|
||||
private static final String BATTERY_WAVES_ENABLED = "battery.waves.enabled";
|
||||
private static final String DEFAULT_VISIBILITY = "default-visibility";
|
||||
private static final String VISIBILITY_ONLY_GREY_OR_NONE_ENABLED = "visibility.only-grey-or-none.enabled";
|
||||
private static final String VISIBILITY_ONLY_GREY_OR_NONE_ENABLED =
|
||||
"visibility.only-grey-or-none.enabled";
|
||||
private static final String JOKES_ENABLED = "jokes.enabled";
|
||||
private static final String COMMANDS_ENABLED = "commands-enabled";
|
||||
private static final String TOASTS_ENABLED = "toasts.enabled";
|
||||
@ -35,9 +38,12 @@ public class TimeCalcProperties {
|
||||
} catch (IOException e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
if(!isSecondEnabled() && isMillisecondEnabled()) {
|
||||
System.out.println("Sorry, seconds are disabled, millisecond must be disabled too.");
|
||||
this.properties.setProperty(TimeCalcProperties.CLOCK_HANDS_MILLISECOND_ENABLED, "false");
|
||||
if (!isSecondEnabled() && isMillisecondEnabled()) {
|
||||
System.out.println(
|
||||
"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() {
|
||||
return getBooleanProperty(CLOCK_HANDS_SECOND_ENABLED, true);
|
||||
}
|
||||
|
||||
public boolean isMillisecondEnabled() {
|
||||
return getBooleanProperty(CLOCK_HANDS_MILLISECOND_ENABLED, false);
|
||||
}
|
||||
@ -85,15 +92,18 @@ public class TimeCalcProperties {
|
||||
public Boolean areCommandsEnabled() {
|
||||
return getBooleanProperty(COMMANDS_ENABLED, true);
|
||||
}
|
||||
|
||||
private boolean getBooleanProperty(String key, boolean defaultValue) {
|
||||
if (!properties.containsKey(key)) {
|
||||
return defaultValue;
|
||||
}
|
||||
return properties.get(key).equals("true");
|
||||
}
|
||||
|
||||
public void load() {
|
||||
//to be implemented
|
||||
}
|
||||
|
||||
public void save() {
|
||||
//to be implemented
|
||||
}
|
||||
|
@ -8,22 +8,28 @@ import org.nanoboot.utils.timecalc.utils.property.StringProperty;
|
||||
*/
|
||||
public enum Visibility {
|
||||
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) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -27,5 +27,4 @@ public class WorkingDay {
|
||||
private int overtimeHoursToBeCompensatedUntilThisDay;
|
||||
private int overtimeMinutesToBeCompensatedUntilThisDay;
|
||||
|
||||
|
||||
}
|
||||
|
@ -11,20 +11,23 @@ import java.util.Set;
|
||||
*/
|
||||
public class ComponentRegistry {
|
||||
private final Set<Component> set = new HashSet<>();
|
||||
|
||||
public ComponentRegistry() {
|
||||
|
||||
}
|
||||
|
||||
public void add(JComponent component) {
|
||||
this.set.add(component);
|
||||
}
|
||||
|
||||
public void addAll(JComponent... component) {
|
||||
for(JComponent c:component) {
|
||||
for (JComponent c : component) {
|
||||
add(c);
|
||||
}
|
||||
}
|
||||
|
||||
public void setVisible(boolean b) {
|
||||
for(Component c:set) {
|
||||
for (Component c : set) {
|
||||
c.setVisible(b);
|
||||
}
|
||||
}
|
||||
|
@ -14,11 +14,12 @@ import java.awt.Color;
|
||||
public class TimeCalcButton extends JButton {
|
||||
private static final int BUTTON_WIDTH = 100;
|
||||
private static final int BUTTON_HEIGHT = 30;
|
||||
public StringProperty visibilityProperty =
|
||||
new StringProperty("visibilityProperty",
|
||||
Visibility.STRONGLY_COLORED.name());
|
||||
private Color originalBackground;
|
||||
private Color originalForeground;
|
||||
|
||||
public StringProperty visibilityProperty = new StringProperty("visibilityProperty", Visibility.STRONGLY_COLORED.name());
|
||||
|
||||
public TimeCalcButton(String label) {
|
||||
super(label);
|
||||
}
|
||||
@ -29,11 +30,12 @@ public class TimeCalcButton extends JButton {
|
||||
this.originalForeground = getForeground();
|
||||
new Timer(100, e -> repaint()).start();
|
||||
}
|
||||
|
||||
public void setOriginalBackground() {
|
||||
this.setBackground(originalBackground);;
|
||||
this.setBackground(originalBackground);
|
||||
}
|
||||
|
||||
public void setOriginalForeground() {
|
||||
this.setForeground(originalForeground);;
|
||||
this.setForeground(originalForeground);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public class TimeCalcWindow extends JFrame {
|
||||
}
|
||||
|
||||
public Component[] addAll(Component... comp) {
|
||||
for(Component c:comp) {
|
||||
for (Component c : comp) {
|
||||
add(c);
|
||||
}
|
||||
return comp;
|
||||
|
@ -2,7 +2,6 @@ package org.nanoboot.utils.timecalc.swing.common;
|
||||
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
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_COLOR2 = new Color(210, 210, 210);
|
||||
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 double donePercent = 0;
|
||||
protected boolean mouseOver = false;
|
||||
|
||||
public StringProperty visibilityProperty = new StringProperty("widget.visibilityProperty", Visibility.STRONGLY_COLORED.name());
|
||||
|
||||
public Widget() {
|
||||
setBackground(BACKGROUND_COLOR);
|
||||
new Timer(getTimerDelay(), e -> repaint()).start();
|
||||
addMouseListener(new MouseListener() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
Visibility visibility = Visibility.valueOf(visibilityProperty.getValue());
|
||||
if(visibility.isStronglyColored()) {
|
||||
visibilityProperty.setValue(Visibility.WEAKLY_COLORED.name());
|
||||
Visibility visibility =
|
||||
Visibility.valueOf(visibilityProperty.getValue());
|
||||
if (visibility.isStronglyColored()) {
|
||||
visibilityProperty
|
||||
.setValue(Visibility.WEAKLY_COLORED.name());
|
||||
} 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) {
|
||||
super.paintComponent(g);
|
||||
|
||||
Visibility visibility = Visibility.valueOf(visibilityProperty.getValue());
|
||||
Visibility visibility =
|
||||
Visibility.valueOf(visibilityProperty.getValue());
|
||||
this.setVisible(visibility != Visibility.NONE);
|
||||
paintWidget(g);
|
||||
|
||||
|
@ -2,9 +2,10 @@ package org.nanoboot.utils.timecalc.swing.progress;
|
||||
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.swing.common.Widget;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcProperties;
|
||||
import org.nanoboot.utils.timecalc.utils.common.DateFormats;
|
||||
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 java.awt.BasicStroke;
|
||||
@ -17,49 +18,57 @@ import java.awt.RenderingHints;
|
||||
import java.util.Calendar;
|
||||
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/
|
||||
public class AnalogClock extends Widget {
|
||||
|
||||
public static final Color COLOR_FOR_MILLISECOND_HAND_STRONGLY_COLORED = new Color(246,
|
||||
152, 51);
|
||||
private TimeHM startTime;
|
||||
private TimeHM endTime;
|
||||
private int startAngle;
|
||||
private int endAngle;
|
||||
|
||||
public IntegerProperty startHourProperty = new IntegerProperty("startHourProperty");
|
||||
public IntegerProperty startMinuteProperty = new IntegerProperty("startMinuteProperty");
|
||||
public IntegerProperty endHourProperty = new IntegerProperty("endHourProperty");
|
||||
public IntegerProperty endMinuteProperty = new IntegerProperty("endMinuteProperty");
|
||||
public static final Color COLOR_FOR_MILLISECOND_HAND_STRONGLY_COLORED =
|
||||
new Color(246,
|
||||
152, 51);
|
||||
public IntegerProperty startHourProperty =
|
||||
new IntegerProperty("startHourProperty");
|
||||
public IntegerProperty startMinuteProperty =
|
||||
new IntegerProperty("startMinuteProperty");
|
||||
public IntegerProperty endHourProperty =
|
||||
new IntegerProperty("endHourProperty");
|
||||
public IntegerProperty endMinuteProperty =
|
||||
new IntegerProperty("endMinuteProperty");
|
||||
public IntegerProperty yearProperty = new IntegerProperty("yearProperty");
|
||||
public IntegerProperty monthProperty = new IntegerProperty("monthProperty");
|
||||
public IntegerProperty dayProperty = new IntegerProperty("dayProperty");
|
||||
public IntegerProperty hourProperty = new IntegerProperty("hourProperty");
|
||||
public IntegerProperty minuteProperty = new IntegerProperty("minuteProperty");
|
||||
public IntegerProperty secondProperty = new IntegerProperty("secondProperty");
|
||||
public IntegerProperty millisecondProperty = new IntegerProperty("millisecondProperty");
|
||||
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);
|
||||
public IntegerProperty minuteProperty =
|
||||
new IntegerProperty("minuteProperty");
|
||||
public IntegerProperty secondProperty =
|
||||
new IntegerProperty("secondProperty");
|
||||
public IntegerProperty millisecondProperty =
|
||||
new IntegerProperty("millisecondProperty");
|
||||
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,
|
||||
TimeHM endTimeIn) {
|
||||
|
||||
this.endTime = endTimeIn.cloneInstance();
|
||||
this.endAngle =
|
||||
(int) ((endTime.getHour() + endTime.getMinute() / 60d) / 12d * 360d);
|
||||
if(endTime.getHour() >12) {
|
||||
(int) ((endTime.getHour() + endTime.getMinute() / 60d) / 12d
|
||||
* 360d);
|
||||
if (endTime.getHour() > 12) {
|
||||
endTime.setHour(endTime.getHour() - 12);
|
||||
}
|
||||
this.startTime = startTimeIn.cloneInstance();
|
||||
this.startAngle =
|
||||
(int) ((startTime.getHour() + startTime.getMinute() / 60d) / 12d * 360d);
|
||||
|
||||
|
||||
(int) ((startTime.getHour() + startTime.getMinute() / 60d) / 12d
|
||||
* 360d);
|
||||
|
||||
setPreferredSize(new Dimension(200, 200));
|
||||
|
||||
@ -73,30 +82,31 @@ public class AnalogClock extends Widget {
|
||||
window.add(clock);
|
||||
window.pack();
|
||||
window.setVisible(true);
|
||||
// window.addKeyListener(new KeyAdapter() {
|
||||
// // Key Pressed method
|
||||
// public void keyPressed(KeyEvent e) {
|
||||
// if (e.getKeyCode() == KeyEvent.VK_UP) {
|
||||
// clock.startAngle_++;
|
||||
// }
|
||||
// if (e.getKeyCode() == KeyEvent.VK_DOWN) {
|
||||
// clock.startAngle_--;
|
||||
// }
|
||||
//
|
||||
// if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
|
||||
// clock.arcAngle_++;
|
||||
// }
|
||||
// if (e.getKeyCode() == KeyEvent.VK_LEFT) {
|
||||
// clock.arcAngle_--;
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// window.addKeyListener(new KeyAdapter() {
|
||||
// // Key Pressed method
|
||||
// public void keyPressed(KeyEvent e) {
|
||||
// if (e.getKeyCode() == KeyEvent.VK_UP) {
|
||||
// clock.startAngle_++;
|
||||
// }
|
||||
// if (e.getKeyCode() == KeyEvent.VK_DOWN) {
|
||||
// clock.startAngle_--;
|
||||
// }
|
||||
//
|
||||
// if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
|
||||
// clock.arcAngle_++;
|
||||
// }
|
||||
// if (e.getKeyCode() == KeyEvent.VK_LEFT) {
|
||||
// clock.arcAngle_--;
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintWidget(Graphics g) {
|
||||
|
||||
Visibility visibility = Visibility.valueOf(visibilityProperty.getValue());
|
||||
Visibility visibility =
|
||||
Visibility.valueOf(visibilityProperty.getValue());
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
@ -105,22 +115,23 @@ public class AnalogClock extends Widget {
|
||||
int centerX = getWidth() / 2;
|
||||
int centerY = getHeight() / 2;
|
||||
|
||||
|
||||
int millisecond = millisecondProperty.getValue();
|
||||
int second = secondProperty.getValue();
|
||||
int minute = minuteProperty.getValue();
|
||||
int hour = hourProperty.getValue();
|
||||
|
||||
if(mouseOver && visibility.isStronglyColored()) {
|
||||
this.startTime = new TimeHM(hour, minute);
|
||||
this.startAngle =
|
||||
(int) ((startTime.getHour() + startTime.getMinute() / 60d) / 12d * 360d);
|
||||
if (mouseOver && visibility.isStronglyColored()) {
|
||||
this.startTime = new TimeHM(hour, minute);
|
||||
this.startAngle =
|
||||
(int) ((startTime.getHour() + startTime.getMinute() / 60d)
|
||||
/ 12d * 360d);
|
||||
|
||||
Color currentColor = g2d.getColor();
|
||||
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);
|
||||
}
|
||||
@ -129,7 +140,7 @@ public class AnalogClock extends Widget {
|
||||
drawClockFace(g2d, centerX, centerY, side / 2 - 40, visibility);
|
||||
|
||||
//
|
||||
if(millisecondEnabledProperty.isEnabled()) {
|
||||
if (millisecondEnabledProperty.isEnabled()) {
|
||||
drawHand(g2d, side / 2 - 10, millisecond / 1000.0, 1.0f,
|
||||
COLOR_FOR_MILLISECOND_HAND_STRONGLY_COLORED, visibility);
|
||||
|
||||
@ -142,14 +153,15 @@ public class AnalogClock extends Widget {
|
||||
}
|
||||
}
|
||||
|
||||
if(secondEnabledProperty.isEnabled()) {
|
||||
drawHand(g2d, side / 2 - 10, second / 60.0, 0.5f, Color.RED, visibility);
|
||||
if (secondEnabledProperty.isEnabled()) {
|
||||
drawHand(g2d, side / 2 - 10, second / 60.0, 0.5f, Color.RED,
|
||||
visibility);
|
||||
|
||||
if (handsLongProperty.isEnabled()) {
|
||||
drawHand(g2d, (side / 2 - 10) / 4,
|
||||
(second > 30 ? second - 30 : second + 30) / 60.0, 0.5f,
|
||||
Color.RED, visibility);
|
||||
}
|
||||
if (handsLongProperty.isEnabled()) {
|
||||
drawHand(g2d, (side / 2 - 10) / 4,
|
||||
(second > 30 ? second - 30 : second + 30) / 60.0, 0.5f,
|
||||
Color.RED, visibility);
|
||||
}
|
||||
}
|
||||
//
|
||||
double minutes = minute / 60.0 + second / 60.0 / 60.0;
|
||||
@ -178,7 +190,8 @@ public class AnalogClock extends Widget {
|
||||
|
||||
private void drawCentre(Graphics2D g2d, int centerX, int centerY) {
|
||||
Color currentColor = g2d.getColor();
|
||||
Visibility visibility = Visibility.valueOf(visibilityProperty.getValue());
|
||||
Visibility visibility =
|
||||
Visibility.valueOf(visibilityProperty.getValue());
|
||||
g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.RED :
|
||||
FOREGROUND_COLOR);
|
||||
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(4, 4, centerX * 2 - 8, centerY * 2 - 8);
|
||||
if(this.mouseOver)
|
||||
{
|
||||
if (this.mouseOver) {
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
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());
|
||||
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)));
|
||||
g2d.drawString(DateFormats.DATE_TIME_FORMATTER_TIME.format(date),
|
||||
((int) (side * 0.25) + 30),
|
||||
|
@ -1,12 +1,12 @@
|
||||
package org.nanoboot.utils.timecalc.swing.progress;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcProperties;
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
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.Utils;
|
||||
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
|
||||
|
||||
import java.awt.Color;
|
||||
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 HIGH_ENERGY = 0.75;
|
||||
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 BooleanProperty blinking = new BooleanProperty("blinking");
|
||||
private long tmpNanoTime = 0l;
|
||||
|
||||
@Getter
|
||||
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 totalWidth;
|
||||
private String label = null;
|
||||
private final double[] randomDoubles = new double[] {1d, 1d, 1d, 1d, 1d, 1d, 1};
|
||||
|
||||
protected Battery(String name) {
|
||||
this.name = name;
|
||||
@ -58,19 +56,22 @@ public class Battery extends Widget {
|
||||
this.totalHeight = (int) (this.getHeight() / 10d * 7d);
|
||||
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();
|
||||
tmpNanoTime = System.nanoTime();
|
||||
}
|
||||
if(donePercent <= 0 && blinking.getValue()){
|
||||
if (donePercent <= 0 && blinking.getValue()) {
|
||||
blinking.setValue(false);
|
||||
}
|
||||
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
|
||||
Visibility visibility = Visibility.valueOf(visibilityProperty.getValue());
|
||||
g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.YELLOW :
|
||||
FOREGROUND_COLOR);
|
||||
Visibility visibility =
|
||||
Visibility.valueOf(visibilityProperty.getValue());
|
||||
g2d.setColor(
|
||||
visibility.isStronglyColored() || mouseOver ? Color.YELLOW :
|
||||
FOREGROUND_COLOR);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
@ -80,18 +81,22 @@ public class Battery extends Widget {
|
||||
|
||||
if (visibility.isStronglyColored() || mouseOver) {
|
||||
g2d.setColor(
|
||||
donePercent < LOW_ENERGY ? LOW_HIGHLIGHTED : (donePercent < HIGH_ENERGY ?
|
||||
MEDIUM_HIGHLIGHTED :
|
||||
(donePercent < VERY_HIGH_ENERGY ? HIGH_HIGHLIGHTED :
|
||||
HIGHEST_HIGHLIGHTED)));
|
||||
donePercent < LOW_ENERGY ? LOW_HIGHLIGHTED :
|
||||
(donePercent < HIGH_ENERGY ?
|
||||
MEDIUM_HIGHLIGHTED :
|
||||
(donePercent < VERY_HIGH_ENERGY ?
|
||||
HIGH_HIGHLIGHTED :
|
||||
HIGHEST_HIGHLIGHTED)));
|
||||
} else {
|
||||
g2d.setColor(donePercent < LOW_ENERGY ? LOW : (donePercent < HIGH_ENERGY ?
|
||||
MEDIUM : (donePercent < VERY_HIGH_ENERGY ? HIGH : HIGHEST)));
|
||||
g2d.setColor(donePercent < LOW_ENERGY ? LOW :
|
||||
(donePercent < HIGH_ENERGY ?
|
||||
MEDIUM :
|
||||
(donePercent < VERY_HIGH_ENERGY ? HIGH : HIGHEST)));
|
||||
}
|
||||
if (visibility.isGray()) {
|
||||
g2d.setColor(Utils.ULTRA_LIGHT_GRAY);
|
||||
}
|
||||
if(blinking.getValue()) {
|
||||
if (blinking.getValue()) {
|
||||
g2d.setColor(BACKGROUND_COLOR);
|
||||
}
|
||||
int doneHeight = (int) (totalHeight * donePercent);
|
||||
@ -106,9 +111,11 @@ public class Battery extends Widget {
|
||||
waterSurfaceHeight = 0;
|
||||
}
|
||||
|
||||
g2d.fillRect(intX+1, doneHeight < waterSurfaceHeight || donePercent >= 1 ?
|
||||
g2d.fillRect(intX + 1,
|
||||
doneHeight < waterSurfaceHeight || donePercent >= 1 ?
|
||||
todoHeight : todoHeight + waterSurfaceHeight,
|
||||
totalWidth - 3, doneHeight < waterSurfaceHeight || donePercent >= 1 ?
|
||||
totalWidth - 3,
|
||||
doneHeight < waterSurfaceHeight || donePercent >= 1 ?
|
||||
doneHeight : doneHeight - waterSurfaceHeight + 1);
|
||||
int pointCount = 8;
|
||||
if (doneHeight >= waterSurfaceHeight
|
||||
@ -140,41 +147,43 @@ public class Battery extends Widget {
|
||||
todoHeight + (waterSurfaceHeight * 1)},
|
||||
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,
|
||||
RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||
g2d.drawPolyline(
|
||||
new int[] {intX,
|
||||
(int) (intX + totalWidth / pointCount * 0.5),
|
||||
intX + totalWidth / pointCount * 3,
|
||||
intX + totalWidth / pointCount * 4,
|
||||
intX + totalWidth / pointCount * 5,
|
||||
intX + totalWidth / pointCount * 6,
|
||||
intX + totalWidth / pointCount * 7,
|
||||
intX + totalWidth / pointCount * 8},
|
||||
new int[] {todoHeight + (waterSurfaceHeight * 1),
|
||||
todoHeight + (int) (waterSurfaceHeight * getRandom(
|
||||
0, true)),
|
||||
todoHeight + (int) (waterSurfaceHeight * getRandom(
|
||||
1, true)),
|
||||
todoHeight + (int) (waterSurfaceHeight * getRandom(
|
||||
2, true)),
|
||||
todoHeight + (int) (waterSurfaceHeight * getRandom(
|
||||
3, true)),
|
||||
todoHeight + (int) (waterSurfaceHeight * getRandom(
|
||||
4, true)),
|
||||
todoHeight + (int) (waterSurfaceHeight * getRandom(
|
||||
5, true)),
|
||||
todoHeight + (waterSurfaceHeight * 1)},
|
||||
pointCount);
|
||||
g2d.drawPolyline(
|
||||
new int[] {intX,
|
||||
(int) (intX + totalWidth / pointCount * 0.5),
|
||||
intX + totalWidth / pointCount * 3,
|
||||
intX + totalWidth / pointCount * 4,
|
||||
intX + totalWidth / pointCount * 5,
|
||||
intX + totalWidth / pointCount * 6,
|
||||
intX + totalWidth / pointCount * 7,
|
||||
intX + totalWidth / pointCount * 8},
|
||||
new int[] {todoHeight + (waterSurfaceHeight * 1),
|
||||
todoHeight + (int) (waterSurfaceHeight * getRandom(
|
||||
0, true)),
|
||||
todoHeight + (int) (waterSurfaceHeight * getRandom(
|
||||
1, true)),
|
||||
todoHeight + (int) (waterSurfaceHeight * getRandom(
|
||||
2, true)),
|
||||
todoHeight + (int) (waterSurfaceHeight * getRandom(
|
||||
3, true)),
|
||||
todoHeight + (int) (waterSurfaceHeight * getRandom(
|
||||
4, true)),
|
||||
todoHeight + (int) (waterSurfaceHeight * getRandom(
|
||||
5, true)),
|
||||
todoHeight + (waterSurfaceHeight * 1)},
|
||||
pointCount);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
}
|
||||
g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.BLACK :
|
||||
Color.LIGHT_GRAY);
|
||||
|
||||
if(donePercent <1) {
|
||||
if (donePercent < 1) {
|
||||
Font currentFont = g2d.getFont();
|
||||
g2d.setFont(bigFont);
|
||||
g2d.drawString("⚡", ((int) (totalWidth * 0.45)),
|
||||
@ -184,7 +193,8 @@ public class Battery extends Widget {
|
||||
}
|
||||
|
||||
g2d.drawString(
|
||||
NumberFormats.FORMATTER_THREE_DECIMAL_PLACES.format(donePercent * 100) + "%",
|
||||
NumberFormats.FORMATTER_THREE_DECIMAL_PLACES
|
||||
.format(donePercent * 100) + "%",
|
||||
((int) (totalWidth * 0.15)),
|
||||
donePercent > 0.5 ? totalHeight / 4 * 3 : totalHeight / 4 * 1);
|
||||
|
||||
@ -210,6 +220,7 @@ public class Battery extends Widget {
|
||||
private double getRandom(int index) {
|
||||
return getRandom(index, false);
|
||||
}
|
||||
|
||||
private double getRandom(int index, boolean keepArray) {
|
||||
if (!keepArray && Math.random() > 0.96) {
|
||||
randomDoubles[index] = Math.random();
|
||||
@ -226,8 +237,9 @@ public class Battery extends Widget {
|
||||
}
|
||||
|
||||
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() {
|
||||
return 25;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ package org.nanoboot.utils.timecalc.swing.progress;
|
||||
* @author Robert Vokac
|
||||
* @since 21.02.2024
|
||||
*/
|
||||
public class DayBattery extends Battery{
|
||||
public class DayBattery extends Battery {
|
||||
public DayBattery(int x, int i, int i1) {
|
||||
super("Day", x, i, i1);
|
||||
}
|
||||
|
@ -6,13 +6,15 @@ import org.nanoboot.utils.timecalc.utils.common.TimeHM;
|
||||
* @author Robert Vokac
|
||||
* @since 21.02.2024
|
||||
*/
|
||||
public class HourBattery extends Battery{
|
||||
public class HourBattery extends Battery {
|
||||
public HourBattery(int x, int i, int i1) {
|
||||
super("Hour", x, i, i1);
|
||||
}
|
||||
|
||||
public static double getHourProgress(TimeHM timeRemains, int secondsRemains,
|
||||
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;
|
||||
}
|
||||
double minutesRemainsD = timeRemains.getMinute();
|
||||
|
@ -4,17 +4,19 @@ package org.nanoboot.utils.timecalc.swing.progress;
|
||||
* @author Robert Vokac
|
||||
* @since 21.02.2024
|
||||
*/
|
||||
public class MonthBattery extends Battery{
|
||||
public class MonthBattery extends Battery {
|
||||
public MonthBattery(int x, int i, int 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;
|
||||
}
|
||||
return weekDayWhenMondayIsOne == 0
|
||||
|| weekDayWhenMondayIsOne == 6 ?
|
||||
workDaysDone / workDaysTotal :
|
||||
(workDaysDone + done) / workDaysTotal;
|
||||
return weekDayWhenMondayIsOne == 0
|
||||
|| weekDayWhenMondayIsOne == 6 ?
|
||||
workDaysDone / workDaysTotal :
|
||||
(workDaysDone + done) / workDaysTotal;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package org.nanoboot.utils.timecalc.swing.progress;
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.swing.common.Widget;
|
||||
import org.nanoboot.utils.timecalc.utils.common.NumberFormats;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
@ -22,10 +21,12 @@ public class ProgressCircle extends Widget {
|
||||
if (side == 0) {
|
||||
this.side = Math.min(getWidth(), getHeight());
|
||||
}
|
||||
Visibility visibility = Visibility.valueOf(visibilityProperty.getValue());
|
||||
Visibility visibility =
|
||||
Visibility.valueOf(visibilityProperty.getValue());
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.darkGray :
|
||||
FOREGROUND_COLOR);
|
||||
g2d.setColor(
|
||||
visibility.isStronglyColored() || mouseOver ? Color.darkGray :
|
||||
FOREGROUND_COLOR);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
@ -39,10 +40,13 @@ public class ProgressCircle extends Widget {
|
||||
new Color(105, 175, 236) : FOREGROUND_COLOR2);
|
||||
g2d.fillArc(0 + (side2 / 2), 0 + (side2 / 2), side2, side2, 90,
|
||||
-(int) angleDouble2);
|
||||
g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.blue :FOREGROUND_COLOR);
|
||||
g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.blue :
|
||||
FOREGROUND_COLOR);
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
@ -3,7 +3,6 @@ package org.nanoboot.utils.timecalc.swing.progress;
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.swing.common.Widget;
|
||||
import org.nanoboot.utils.timecalc.utils.common.NumberFormats;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
@ -75,9 +74,13 @@ public class ProgressSquare extends Widget {
|
||||
}
|
||||
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)));
|
||||
|
||||
}
|
||||
|
||||
|
@ -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.ReadOnlyProperty;
|
||||
|
||||
import javax.swing.Timer;
|
||||
import java.awt.Graphics;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class Time extends Thread {
|
||||
|
||||
private IntegerProperty yearReadWriteProperty = new IntegerProperty("yearProperty");
|
||||
private IntegerProperty monthReadWriteProperty = new IntegerProperty("monthProperty");
|
||||
private IntegerProperty dayReadWriteProperty = new IntegerProperty("dayProperty");
|
||||
private IntegerProperty hourReadWriteProperty = new IntegerProperty("hourProperty");
|
||||
private IntegerProperty minuteReadWriteProperty = new IntegerProperty("minuteProperty");
|
||||
private IntegerProperty secondReadWriteProperty = new IntegerProperty("secondProperty");
|
||||
private IntegerProperty millisecondReadWriteProperty = new IntegerProperty("millisecondProperty");
|
||||
private IntegerProperty dayOfWeekReadWriteProperty = new IntegerProperty("dayOfWeek");
|
||||
public ReadOnlyProperty<Integer> yearProperty = yearReadWriteProperty.asReadOnlyProperty();
|
||||
public ReadOnlyProperty<Integer> monthProperty = monthReadWriteProperty.asReadOnlyProperty();
|
||||
public ReadOnlyProperty<Integer> dayProperty = dayReadWriteProperty.asReadOnlyProperty();
|
||||
public ReadOnlyProperty<Integer> hourProperty = hourReadWriteProperty.asReadOnlyProperty();
|
||||
public ReadOnlyProperty<Integer> minuteProperty = minuteReadWriteProperty.asReadOnlyProperty();
|
||||
public ReadOnlyProperty<Integer> secondProperty = secondReadWriteProperty.asReadOnlyProperty();
|
||||
public ReadOnlyProperty<Integer> millisecondProperty = millisecondReadWriteProperty.asReadOnlyProperty();
|
||||
public ReadOnlyProperty<Integer> dayOfWeek = dayOfWeekReadWriteProperty.asReadOnlyProperty();
|
||||
private final IntegerProperty yearReadWriteProperty =
|
||||
new IntegerProperty("yearProperty");
|
||||
public ReadOnlyProperty<Integer> yearProperty =
|
||||
yearReadWriteProperty.asReadOnlyProperty();
|
||||
private final IntegerProperty monthReadWriteProperty =
|
||||
new IntegerProperty("monthProperty");
|
||||
public ReadOnlyProperty<Integer> monthProperty =
|
||||
monthReadWriteProperty.asReadOnlyProperty();
|
||||
private final IntegerProperty dayReadWriteProperty =
|
||||
new IntegerProperty("dayProperty");
|
||||
public ReadOnlyProperty<Integer> dayProperty =
|
||||
dayReadWriteProperty.asReadOnlyProperty();
|
||||
private final IntegerProperty hourReadWriteProperty =
|
||||
new IntegerProperty("hourProperty");
|
||||
public ReadOnlyProperty<Integer> hourProperty =
|
||||
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;
|
||||
|
||||
public Time() {
|
||||
this.setDaemon(true);
|
||||
start();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
while(true) {
|
||||
while (true) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(new Date());
|
||||
yearReadWriteProperty.setValue(cal.get(Calendar.YEAR));
|
||||
|
File diff suppressed because one or more lines are too long
@ -4,16 +4,18 @@ package org.nanoboot.utils.timecalc.swing.progress;
|
||||
* @author Robert Vokac
|
||||
* @since 21.02.2024
|
||||
*/
|
||||
public class WeekBattery extends Battery{
|
||||
public class WeekBattery extends Battery {
|
||||
public WeekBattery(int x, int i, int 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;
|
||||
}
|
||||
return weekDayWhenMondayIsOne == 0
|
||||
|| weekDayWhenMondayIsOne == 6 ?
|
||||
100 : ((weekDayWhenMondayIsOne - 1) * 0.20 + done * 0.20);
|
||||
return weekDayWhenMondayIsOne == 0
|
||||
|| weekDayWhenMondayIsOne == 6 ?
|
||||
100 : ((weekDayWhenMondayIsOne - 1) * 0.20 + done * 0.20);
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,6 @@ import java.util.Locale;
|
||||
* @since 21.02.2024
|
||||
*/
|
||||
public class DateFormats {
|
||||
private DateFormats() {
|
||||
//Not meant to be instantiated.
|
||||
}
|
||||
public final static DateTimeFormatter DATE_TIME_FORMATTER_HHmmssSSS =
|
||||
DateTimeFormatter.ofPattern("HH:mm:ss:SSS");
|
||||
public static DateFormat DATE_TIME_FORMATTER_LONG =
|
||||
@ -22,4 +19,7 @@ public class DateFormats {
|
||||
new SimpleDateFormat("HH:mm:ss", Locale.ENGLISH);
|
||||
public static DateFormat DATE_TIME_FORMATTER_VERY_LONG =
|
||||
new SimpleDateFormat("yyyy:MM:dd:HH:mm:ss:EEEE", Locale.ENGLISH);
|
||||
private DateFormats() {
|
||||
//Not meant to be instantiated.
|
||||
}
|
||||
}
|
||||
|
@ -7,10 +7,10 @@ import java.io.File;
|
||||
* @since 21.02.2024
|
||||
*/
|
||||
public class FileConstants {
|
||||
private FileConstants() {
|
||||
//Not meant to be instantiated.
|
||||
}
|
||||
public static final File STARTTIME_TXT = new File("starttime.txt");
|
||||
public static final File OVERTIME_TXT = new File("overtime.txt");
|
||||
public static final File TEST_TXT = new File("test.txt");
|
||||
private FileConstants() {
|
||||
//Not meant to be instantiated.
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.nanoboot.utils.timecalc.utils.common;
|
||||
|
||||
import org.nanoboot.utils.timecalc.swing.common.Toaster;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcProperties;
|
||||
import org.nanoboot.utils.timecalc.swing.common.Toaster;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JTextPane;
|
||||
@ -63,7 +63,7 @@ public class Jokes {
|
||||
}
|
||||
|
||||
public static void showRandom() {
|
||||
if(!TimeCalcProperties.getInstance().areJokesEnabled()) {
|
||||
if (!TimeCalcProperties.getInstance().areJokesEnabled()) {
|
||||
//nothing to do
|
||||
return;
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package org.nanoboot.utils.timecalc.utils.common;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* @author Robert Vokac
|
||||
* @since 15.02.2024
|
||||
@ -15,9 +14,9 @@ public class JokesTxt {
|
||||
|
||||
public static String[] getAsArray() throws IOException {
|
||||
File jokeTxtFile = new File("jokes.txt");
|
||||
if(!jokeTxtFile.exists()) {
|
||||
if (!jokeTxtFile.exists()) {
|
||||
//nothing to do
|
||||
return new String[]{"A","B","C"};
|
||||
return new String[] {"A", "B", "C"};
|
||||
}
|
||||
return Utils.readTextFromFile(jokeTxtFile).split("-----SEPARATOR-----");
|
||||
}
|
||||
|
@ -8,11 +8,15 @@ import java.text.NumberFormat;
|
||||
* @since 21.02.2024
|
||||
*/
|
||||
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() {
|
||||
//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");
|
||||
}
|
||||
|
@ -12,9 +12,11 @@ public class TimeHM {
|
||||
public static final int MILLISECONDS_PER_SECOND = 1000;
|
||||
public static final int SECONDS_PER_MINUTE = 60;
|
||||
|
||||
@Getter @Setter
|
||||
@Getter
|
||||
@Setter
|
||||
private Integer hour;
|
||||
@Getter @Setter
|
||||
@Getter
|
||||
@Setter
|
||||
private Integer minute;
|
||||
|
||||
public TimeHM(String string) {
|
||||
@ -41,8 +43,11 @@ public class TimeHM {
|
||||
}
|
||||
|
||||
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() {
|
||||
return new TimeHM(hour, minute);
|
||||
}
|
||||
|
@ -20,8 +20,9 @@ import java.util.jar.Manifest;
|
||||
*/
|
||||
public class Utils {
|
||||
|
||||
public static final BooleanProperty toastsAreEnabled = new BooleanProperty("toastsAreEnabled", true);
|
||||
public static final Color ULTRA_LIGHT_GRAY = new Color(216,216,216);
|
||||
public static final BooleanProperty toastsAreEnabled =
|
||||
new BooleanProperty("toastsAreEnabled", true);
|
||||
public static final Color ULTRA_LIGHT_GRAY = new Color(216, 216, 216);
|
||||
/**
|
||||
* Count of bytes per one kilobyte.
|
||||
*/
|
||||
@ -81,10 +82,9 @@ public class Utils {
|
||||
((int) (Math.random() * 256)), ((int) (Math.random() * 256)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns version of "Time Calc" from jar file.
|
||||
*
|
||||
* @return version
|
||||
*/
|
||||
public static String getVersion() {
|
||||
@ -94,6 +94,7 @@ public class Utils {
|
||||
|
||||
/**
|
||||
* Returns build date of "Time Calc" from jar file.
|
||||
*
|
||||
* @return build date
|
||||
*/
|
||||
public static String getBuildDate() {
|
||||
@ -103,8 +104,9 @@ public class Utils {
|
||||
if (!classPath.startsWith("jar")) {
|
||||
return null;
|
||||
}
|
||||
String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1)
|
||||
+ "/META-INF/MANIFEST.MF";
|
||||
String manifestPath =
|
||||
classPath.substring(0, classPath.lastIndexOf("!") + 1)
|
||||
+ "/META-INF/MANIFEST.MF";
|
||||
Manifest manifest;
|
||||
try {
|
||||
manifest = new Manifest(new URL(manifestPath).openStream());
|
||||
@ -115,6 +117,7 @@ public class Utils {
|
||||
Attributes attr = manifest.getMainAttributes();
|
||||
return attr.getValue("Build-Date");
|
||||
}
|
||||
|
||||
public static byte[] decodeBase64ToByteArray(String s) {
|
||||
Base64.Decoder base64Decoder = Base64.getDecoder();
|
||||
return base64Decoder
|
||||
|
@ -9,9 +9,11 @@ public class BooleanProperty extends Property<Boolean> {
|
||||
public BooleanProperty(String name) {
|
||||
super(name, Boolean.FALSE);
|
||||
}
|
||||
|
||||
public BooleanProperty(String name, boolean valueIn) {
|
||||
this(name, Boolean.valueOf(valueIn));
|
||||
}
|
||||
|
||||
public BooleanProperty(String name, Boolean valueIn) {
|
||||
super(name, valueIn);
|
||||
}
|
||||
@ -19,20 +21,23 @@ public class BooleanProperty extends Property<Boolean> {
|
||||
public boolean isEnabled() {
|
||||
return getValue();
|
||||
}
|
||||
|
||||
public boolean isDisabled() {
|
||||
return !getValue();
|
||||
}
|
||||
|
||||
|
||||
public void flip() {
|
||||
setValue(!getValue());
|
||||
}
|
||||
|
||||
public void inverse() {
|
||||
flip();
|
||||
}
|
||||
|
||||
public void enable() {
|
||||
setValue(true);
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
setValue(false);
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ public class BooleanReadOnlyProperty extends ReadOnlyProperty<Boolean> {
|
||||
public BooleanReadOnlyProperty(String name, Boolean valueIn) {
|
||||
super(name, valueIn);
|
||||
}
|
||||
|
||||
public BooleanReadOnlyProperty(Property<Boolean> property) {
|
||||
super(property);
|
||||
}
|
||||
@ -16,6 +17,7 @@ public class BooleanReadOnlyProperty extends ReadOnlyProperty<Boolean> {
|
||||
public boolean isEnabled() {
|
||||
return getValue();
|
||||
}
|
||||
|
||||
public boolean isDisabled() {
|
||||
return !getValue();
|
||||
}
|
||||
|
@ -4,6 +4,6 @@ package org.nanoboot.utils.timecalc.utils.property;
|
||||
* @author Robert Vokac
|
||||
* @since 23.02.2024
|
||||
*/
|
||||
public interface ChangeListener<T> {
|
||||
void changed(Property<T> property, T oldValue, T newValue);
|
||||
public interface ChangeListener<T> {
|
||||
void changed(Property<T> property, T oldValue, T newValue);
|
||||
}
|
||||
|
@ -10,70 +10,83 @@ import java.util.List;
|
||||
* @author Robert Vokac
|
||||
* @since 23.02.2024
|
||||
*/
|
||||
public class Property <T>{
|
||||
private boolean valid = true;
|
||||
public class Property<T> {
|
||||
@Getter
|
||||
private final String name;
|
||||
private boolean valid = true;
|
||||
private T value;
|
||||
private Property<T> boundToProperty = null;
|
||||
private List<InvalidationListener> invalidationListeners = new ArrayList<>();
|
||||
private List<ChangeListener<T>>
|
||||
private final List<InvalidationListener> invalidationListeners =
|
||||
new ArrayList<>();
|
||||
private final List<ChangeListener<T>>
|
||||
changeListeners = new ArrayList<ChangeListener<T>>();
|
||||
|
||||
public Property(String name, T valueIn) {
|
||||
this.name = name; this.value = valueIn;
|
||||
this.name = name;
|
||||
this.value = valueIn;
|
||||
}
|
||||
|
||||
public ReadOnlyProperty<T> asReadOnlyProperty() {
|
||||
return new ReadOnlyProperty<>(this);
|
||||
}
|
||||
|
||||
public WriteOnlyProperty<T> asWriteOnlyProperty() {
|
||||
return new WriteOnlyProperty<>(this);
|
||||
}
|
||||
|
||||
public boolean isBound() {
|
||||
return boundToProperty != null;
|
||||
}
|
||||
|
||||
public void unBound() {
|
||||
if(!isBound()) {
|
||||
if (!isBound()) {
|
||||
throw new TimeCalcException("No bound property");
|
||||
}
|
||||
this.value = boundToProperty.value;
|
||||
this.boundToProperty = null;
|
||||
}
|
||||
|
||||
public void bindTo(Property<T> anotherProperty) {
|
||||
this.boundToProperty = anotherProperty;
|
||||
this.boundToProperty.addListener((Property<T> p, T oldValue, T newValue) -> {this.markInvalid();this.fireValueChangedEvent(oldValue);
|
||||
//System.out.println("bindTo markInvalid " + p.getName() + " " + p.getValue());
|
||||
} );
|
||||
this.boundToProperty
|
||||
.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() {
|
||||
return isBound() ? this.boundToProperty.getValue() : value;
|
||||
}
|
||||
|
||||
public void setValue(T newValue) {
|
||||
if(isBound()) {
|
||||
if (isBound()) {
|
||||
this.boundToProperty.setValue(newValue);
|
||||
} else {
|
||||
T oldValue = value;
|
||||
this.value = newValue;
|
||||
if(!oldValue.equals(newValue))
|
||||
{
|
||||
if (!oldValue.equals(newValue)) {
|
||||
fireValueChangedEvent(oldValue);
|
||||
markInvalid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return isBound() ? this.boundToProperty.isValid() : valid;
|
||||
}
|
||||
|
||||
protected void markInvalid() {
|
||||
// System.out.println(name + " is invalid now");
|
||||
// System.out.println(name + " is invalid now");
|
||||
valid = false;
|
||||
for (InvalidationListener listener : invalidationListeners) {
|
||||
listener.invalidated(this);
|
||||
}
|
||||
}
|
||||
|
||||
protected void fireValueChangedEvent(T oldValue) {
|
||||
// System.out.println(name + " was changed");
|
||||
// System.out.println(name + " was changed");
|
||||
for (ChangeListener listener : changeListeners) {
|
||||
listener.changed(this, oldValue, value);
|
||||
}
|
||||
@ -83,9 +96,9 @@ public class Property <T>{
|
||||
public void addListener(InvalidationListener listener) {
|
||||
this.invalidationListeners.add(listener);
|
||||
}
|
||||
|
||||
public void addListener(ChangeListener<T> listener) {
|
||||
this.changeListeners.add(listener);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -6,14 +6,17 @@ import org.nanoboot.utils.timecalc.app.TimeCalcException;
|
||||
* @author Robert Vokac
|
||||
* @since 23.02.2024
|
||||
*/
|
||||
public class PropertyWrapper <T> {
|
||||
public class PropertyWrapper<T> {
|
||||
private Property<T> innerProperty;
|
||||
|
||||
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) {
|
||||
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.");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,32 +7,44 @@ import org.nanoboot.utils.timecalc.app.TimeCalcException;
|
||||
* @since 23.02.2024
|
||||
*/
|
||||
public class ReadOnlyProperty<T> extends Property<T> {
|
||||
private Property<T> innerProperty;
|
||||
private final Property<T> innerProperty;
|
||||
|
||||
public ReadOnlyProperty(String name, T 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) {
|
||||
super(property.getName(), null);
|
||||
this.innerProperty = property;
|
||||
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.");
|
||||
this.innerProperty.addListener((Property p) -> {
|
||||
markInvalid();
|
||||
});
|
||||
}
|
||||
|
||||
public final T 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() {
|
||||
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) {
|
||||
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() {
|
||||
return this.innerProperty.isValid();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ public class StringReadOnlyProperty extends ReadOnlyProperty<String> {
|
||||
public StringReadOnlyProperty(String name, String valueIn) {
|
||||
super(name, valueIn);
|
||||
}
|
||||
|
||||
public StringReadOnlyProperty(Property<String> property) {
|
||||
super(property);
|
||||
}
|
||||
|
@ -7,28 +7,37 @@ import org.nanoboot.utils.timecalc.app.TimeCalcException;
|
||||
* @since 23.02.2024
|
||||
*/
|
||||
public class WriteOnlyProperty<T> extends Property<T> {
|
||||
private Property<T> innerProperty;
|
||||
private final Property<T> innerProperty;
|
||||
|
||||
public WriteOnlyProperty(String name, T 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) {
|
||||
super(property.getName(), null);
|
||||
this.innerProperty = property;
|
||||
}
|
||||
|
||||
public final void setValue(T newValue) {
|
||||
this.innerProperty.setValue(newValue);
|
||||
}
|
||||
|
||||
public final T getValue(T valueIn) {
|
||||
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.");
|
||||
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.");
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user