Formatted code

This commit is contained in:
Robert Vokac 2024-03-03 15:04:36 +00:00
parent 5a9e7fbf86
commit 5c67a2da5b
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
36 changed files with 1206 additions and 860 deletions

View File

@ -2,7 +2,6 @@ package org.nanoboot.utils.timecalc.app;
import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.entity.Visibility;
import org.nanoboot.utils.timecalc.swing.common.Toaster; import org.nanoboot.utils.timecalc.swing.common.Toaster;
import org.nanoboot.utils.timecalc.utils.common.Utils;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import java.awt.Color; import java.awt.Color;
@ -20,7 +19,8 @@ public class CommandActionListener
private final TimeCalcApp timeCalcApp; private final TimeCalcApp timeCalcApp;
private final TimeCalcConfiguration timeCalcConfiguration; private final TimeCalcConfiguration timeCalcConfiguration;
public CommandActionListener(TimeCalcApp timeCalcApp, TimeCalcConfiguration timeCalcConfiguration) { public CommandActionListener(TimeCalcApp timeCalcApp,
TimeCalcConfiguration timeCalcConfiguration) {
this.timeCalcApp = timeCalcApp; this.timeCalcApp = timeCalcApp;
this.timeCalcConfiguration = timeCalcConfiguration; this.timeCalcConfiguration = timeCalcConfiguration;
} }
@ -44,14 +44,14 @@ public class CommandActionListener
case "color": case "color":
timeCalcApp.visibilityProperty.setValue( timeCalcApp.visibilityProperty.setValue(
commandsAsArray[1].equals("1") commandsAsArray[1].equals("1")
? Visibility.STRONGLY_COLORED.name() ? Visibility.STRONGLY_COLORED.name()
: Visibility.WEAKLY_COLORED.name()); : Visibility.WEAKLY_COLORED.name());
break; break;
case "gray": case "gray":
timeCalcApp.visibilityProperty.setValue( timeCalcApp.visibilityProperty.setValue(
commandsAsArray[1].equals("1") commandsAsArray[1].equals("1")
? Visibility.GRAY.name() ? Visibility.GRAY.name()
: Visibility.WEAKLY_COLORED.name()); : Visibility.WEAKLY_COLORED.name());
break; break;
case "waves": case "waves":
timeCalcConfiguration.batteryWavesVisibleProperty timeCalcConfiguration.batteryWavesVisibleProperty
@ -75,7 +75,8 @@ public class CommandActionListener
t.showToaster(commands.substring(6)); t.showToaster(commands.substring(6));
break; break;
case "toasts": case "toasts":
timeCalcConfiguration.notificationsVisibleProperty.setValue(commandsAsArray[1].equals("1")); timeCalcConfiguration.notificationsVisibleProperty
.setValue(commandsAsArray[1].equals("1"));
break; break;
default: default:
JOptionPane.showMessageDialog(null, JOptionPane.showMessageDialog(null,

View File

@ -18,7 +18,7 @@ public class TimeCalcApp {
public StringProperty visibilityProperty public StringProperty visibilityProperty
= new StringProperty("timeCalcApp.visibilityProperty", = new StringProperty("timeCalcApp.visibilityProperty",
Visibility.WEAKLY_COLORED.name()); Visibility.WEAKLY_COLORED.name());
private long startNanoTime = 0l; private long startNanoTime = 0l;
public void start(String[] args) throws IOException { public void start(String[] args) throws IOException {
@ -34,32 +34,32 @@ public class TimeCalcApp {
FileConstants.OVERTIME_TXT); FileConstants.OVERTIME_TXT);
String newStartTime String newStartTime
= test ? (oldStartTime != null ? oldStartTime = test ? (oldStartTime != null ? oldStartTime
: Constants.DEFAULT_START_TIME) : Constants.DEFAULT_START_TIME)
: (String) JOptionPane.showInputDialog( : (String) JOptionPane.showInputDialog(
null, null,
"Start Time:", "Start Time:",
"Start Time", "Start Time",
JOptionPane.PLAIN_MESSAGE, JOptionPane.PLAIN_MESSAGE,
null, null,
null, null,
oldStartTime == null oldStartTime == null
? Constants.DEFAULT_START_TIME ? Constants.DEFAULT_START_TIME
: oldStartTime : oldStartTime
); );
String newOvertime String newOvertime
= test ? (oldOvertime != null ? oldOvertime = test ? (oldOvertime != null ? oldOvertime
: Constants.DEFAULT_OVERTIME) : Constants.DEFAULT_OVERTIME)
: (String) JOptionPane.showInputDialog( : (String) JOptionPane.showInputDialog(
null, null,
"Overtime:", "Overtime:",
"Overtime", "Overtime",
JOptionPane.PLAIN_MESSAGE, JOptionPane.PLAIN_MESSAGE,
null, null,
null, null,
oldOvertime == null oldOvertime == null
? Constants.DEFAULT_OVERTIME ? Constants.DEFAULT_OVERTIME
: oldOvertime : oldOvertime
); );
Utils.writeTextToFile(FileConstants.STARTTIME_TXT, newStartTime); Utils.writeTextToFile(FileConstants.STARTTIME_TXT, newStartTime);
Utils.writeTextToFile(FileConstants.OVERTIME_TXT, newOvertime); Utils.writeTextToFile(FileConstants.OVERTIME_TXT, newOvertime);

View File

@ -16,120 +16,132 @@ import java.util.Properties;
*/ */
public class TimeCalcConfiguration { public class TimeCalcConfiguration {
public final StringProperty visibilityDefaultProperty = new StringProperty(TimeCalcProperty.VISIBILITY_DEFAULT public final StringProperty visibilityDefaultProperty =
.getKey()); new StringProperty(TimeCalcProperty.VISIBILITY_DEFAULT
.getKey());
public final BooleanProperty visibilitySupportedColoredProperty public final BooleanProperty visibilitySupportedColoredProperty
= new BooleanProperty(TimeCalcProperty.VISIBILITY_SUPPORTED_COLORED = new BooleanProperty(TimeCalcProperty.VISIBILITY_SUPPORTED_COLORED
.getKey()); .getKey());
// //
public final BooleanProperty clockVisibleProperty public final BooleanProperty clockVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_VISIBLE = new BooleanProperty(TimeCalcProperty.CLOCK_VISIBLE
.getKey()); .getKey());
public final BooleanProperty clockHandsLongVisibleProperty public final BooleanProperty clockHandsLongVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_LONG_VISIBLE = new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_LONG_VISIBLE
.getKey()); .getKey());
public final BooleanProperty clockHandsColoredProperty public final BooleanProperty clockHandsColoredProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_COLORED = new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_COLORED
.getKey()); .getKey());
public final BooleanProperty clockHandsHourVisibleProperty public final BooleanProperty clockHandsHourVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_HOUR_VISIBLE.getKey()); = new BooleanProperty(
TimeCalcProperty.CLOCK_HANDS_HOUR_VISIBLE.getKey());
public final BooleanProperty clockHandsMinuteVisibleProperty public final BooleanProperty clockHandsMinuteVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_MINUTE_VISIBLE = new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_MINUTE_VISIBLE
.getKey()); .getKey());
public final BooleanProperty clockHandsSecondVisibleProperty public final BooleanProperty clockHandsSecondVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_SECOND_VISIBLE = new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_SECOND_VISIBLE
.getKey()); .getKey());
public final BooleanProperty clockHandsMillisecondVisibleProperty public final BooleanProperty clockHandsMillisecondVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_MILLISECOND_VISIBLE =
new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_MILLISECOND_VISIBLE
.getKey()); .getKey());
public final BooleanProperty clockBorderVisibleProperty public final BooleanProperty clockBorderVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_BORDER_VISIBLE = new BooleanProperty(TimeCalcProperty.CLOCK_BORDER_VISIBLE
.getKey()); .getKey());
public final BooleanProperty clockBorderOnlyHoursProperty public final BooleanProperty clockBorderOnlyHoursProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_BORDER_ONLY_HOURS = new BooleanProperty(TimeCalcProperty.CLOCK_BORDER_ONLY_HOURS
.getKey()); .getKey());
public final BooleanProperty clockNumbersVisibleProperty public final BooleanProperty clockNumbersVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_NUMBERS_VISIBLE = new BooleanProperty(TimeCalcProperty.CLOCK_NUMBERS_VISIBLE
.getKey()); .getKey());
public final BooleanProperty clockCircleVisibleProperty public final BooleanProperty clockCircleVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_CIRCLE_VISIBLE = new BooleanProperty(TimeCalcProperty.CLOCK_CIRCLE_VISIBLE
.getKey()); .getKey());
public final BooleanProperty clockCircleStrongBorderProperty public final BooleanProperty clockCircleStrongBorderProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_CIRCLE_STRONG_BORDER = new BooleanProperty(TimeCalcProperty.CLOCK_CIRCLE_STRONG_BORDER
.getKey()); .getKey());
public final StringProperty clockCircleBorderColorProperty public final StringProperty clockCircleBorderColorProperty
= new StringProperty(TimeCalcProperty.CLOCK_CIRCLE_BORDER_COLOR = new StringProperty(TimeCalcProperty.CLOCK_CIRCLE_BORDER_COLOR
.getKey()); .getKey());
public final BooleanProperty clockCentreCircleVisibleProperty public final BooleanProperty clockCentreCircleVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_CENTRE_CIRCLE_VISIBLE = new BooleanProperty(TimeCalcProperty.CLOCK_CENTRE_CIRCLE_VISIBLE
.getKey()); .getKey());
public final BooleanProperty clockCentreCircleBlackProperty public final BooleanProperty clockCentreCircleBlackProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_CENTRE_CIRCLE_BLACK = new BooleanProperty(TimeCalcProperty.CLOCK_CENTRE_CIRCLE_BLACK
.getKey()); .getKey());
public final BooleanProperty clockProgressVisibleOnlyIfMouseMovingOverProperty public final BooleanProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_PROGRESS_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER clockProgressVisibleOnlyIfMouseMovingOverProperty
= new BooleanProperty(
TimeCalcProperty.CLOCK_PROGRESS_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER
.getKey()); .getKey());
public final BooleanProperty clockDateVisibleOnlyIfMouseMovingOverProperty public final BooleanProperty clockDateVisibleOnlyIfMouseMovingOverProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_DATE_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER = new BooleanProperty(
TimeCalcProperty.CLOCK_DATE_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER
.getKey()); .getKey());
// //
public final BooleanProperty batteryWavesVisibleProperty public final BooleanProperty batteryWavesVisibleProperty
= new BooleanProperty(TimeCalcProperty.BATTERY_WAVES_VISIBLE = new BooleanProperty(TimeCalcProperty.BATTERY_WAVES_VISIBLE
.getKey()); .getKey());
public final BooleanProperty batteryCircleProgressProperty public final BooleanProperty batteryCircleProgressProperty
= new BooleanProperty(TimeCalcProperty.BATTERY_CIRCLE_PROGRESS_VISIBLE =
new BooleanProperty(TimeCalcProperty.BATTERY_CIRCLE_PROGRESS_VISIBLE
.getKey()); .getKey());
public final BooleanProperty batteryPercentProgressProperty public final BooleanProperty batteryPercentProgressProperty
= new BooleanProperty(TimeCalcProperty.BATTERY_PERCENT_PROGRESS_VISIBLE = new BooleanProperty(
TimeCalcProperty.BATTERY_PERCENT_PROGRESS_VISIBLE
.getKey()); .getKey());
public final BooleanProperty batteryChargingCharacterVisibleProperty public final BooleanProperty batteryChargingCharacterVisibleProperty
= new BooleanProperty(TimeCalcProperty.BATTERY_CHARGING_CHARACTER_VISIBLE = new BooleanProperty(
TimeCalcProperty.BATTERY_CHARGING_CHARACTER_VISIBLE
.getKey()); .getKey());
public final BooleanProperty batteryNameVisibleProperty public final BooleanProperty batteryNameVisibleProperty
= new BooleanProperty(TimeCalcProperty.BATTERY_NAME_VISIBLE = new BooleanProperty(TimeCalcProperty.BATTERY_NAME_VISIBLE
.getKey()); .getKey());
public final BooleanProperty batteryLabelVisibleProperty public final BooleanProperty batteryLabelVisibleProperty
= new BooleanProperty(TimeCalcProperty.BATTERY_LABEL_VISIBLE = new BooleanProperty(TimeCalcProperty.BATTERY_LABEL_VISIBLE
.getKey()); .getKey());
public final BooleanProperty batteryVisibleProperty public final BooleanProperty batteryVisibleProperty
= new BooleanProperty(TimeCalcProperty.BATTERY_VISIBLE = new BooleanProperty(TimeCalcProperty.BATTERY_VISIBLE
.getKey()); .getKey());
public final BooleanProperty batteryMinuteVisibleProperty public final BooleanProperty batteryMinuteVisibleProperty
= new BooleanProperty(TimeCalcProperty.BATTERY_MINUTE_VISIBLE = new BooleanProperty(TimeCalcProperty.BATTERY_MINUTE_VISIBLE
.getKey()); .getKey());
public final BooleanProperty batteryHourVisibleProperty public final BooleanProperty batteryHourVisibleProperty
= new BooleanProperty(TimeCalcProperty.BATTERY_HOUR_VISIBLE = new BooleanProperty(TimeCalcProperty.BATTERY_HOUR_VISIBLE
.getKey()); .getKey());
public final BooleanProperty batteryDayVisibleProperty public final BooleanProperty batteryDayVisibleProperty
= new BooleanProperty(TimeCalcProperty.BATTERY_DAY_VISIBLE = new BooleanProperty(TimeCalcProperty.BATTERY_DAY_VISIBLE
.getKey()); .getKey());
public final BooleanProperty batteryWeekVisibleProperty public final BooleanProperty batteryWeekVisibleProperty
= new BooleanProperty(TimeCalcProperty.BATTERY_WEEK_VISIBLE = new BooleanProperty(TimeCalcProperty.BATTERY_WEEK_VISIBLE
.getKey()); .getKey());
public final BooleanProperty batteryMonthVisibleProperty public final BooleanProperty batteryMonthVisibleProperty
= new BooleanProperty(TimeCalcProperty.BATTERY_MONTH_VISIBLE = new BooleanProperty(TimeCalcProperty.BATTERY_MONTH_VISIBLE
.getKey()); .getKey());
public final BooleanProperty batteryYearVisibleProperty public final BooleanProperty batteryYearVisibleProperty
= new BooleanProperty(TimeCalcProperty.BATTERY_YEAR_VISIBLE = new BooleanProperty(TimeCalcProperty.BATTERY_YEAR_VISIBLE
.getKey()); .getKey());
public final BooleanProperty batteryBlinkingIfCriticalLowVisibleProperty public final BooleanProperty batteryBlinkingIfCriticalLowVisibleProperty
= new BooleanProperty(TimeCalcProperty.BATTERY_BLINKING_IF_CRITICAL_LOW = new BooleanProperty(
TimeCalcProperty.BATTERY_BLINKING_IF_CRITICAL_LOW
.getKey()); .getKey());
public final BooleanProperty jokesVisibleProperty public final BooleanProperty jokesVisibleProperty
= new BooleanProperty(TimeCalcProperty.JOKES_VISIBLE = new BooleanProperty(TimeCalcProperty.JOKES_VISIBLE
.getKey()); .getKey());
public final BooleanProperty commandsVisibleProperty public final BooleanProperty commandsVisibleProperty
= new BooleanProperty(TimeCalcProperty.COMMANDS_VISIBLE = new BooleanProperty(TimeCalcProperty.COMMANDS_VISIBLE
.getKey()); .getKey());
public final BooleanProperty notificationsVisibleProperty public final BooleanProperty notificationsVisibleProperty
= new BooleanProperty(TimeCalcProperty.NOTIFICATIONS_VISIBLE = new BooleanProperty(TimeCalcProperty.NOTIFICATIONS_VISIBLE
.getKey()); .getKey());
public final BooleanProperty smileysVisibleProperty public final BooleanProperty smileysVisibleProperty
= new BooleanProperty(TimeCalcProperty.SMILEYS_VISIBLE.getKey()); = new BooleanProperty(TimeCalcProperty.SMILEYS_VISIBLE.getKey());
public final BooleanProperty smileysVisibleOnlyIfMouseMovingOverProperty public final BooleanProperty smileysVisibleOnlyIfMouseMovingOverProperty
= new BooleanProperty(TimeCalcProperty.SMILEYS_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER.getKey()); = new BooleanProperty(
TimeCalcProperty.SMILEYS_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER
.getKey());
public final BooleanProperty smileysColoredProperty public final BooleanProperty smileysColoredProperty
= new BooleanProperty(TimeCalcProperty.SMILEYS_COLORED.getKey()); = new BooleanProperty(TimeCalcProperty.SMILEYS_COLORED.getKey());
@ -138,80 +150,91 @@ public class TimeCalcConfiguration {
public final BooleanProperty circleVisibleProperty public final BooleanProperty circleVisibleProperty
= new BooleanProperty(TimeCalcProperty.CIRCLE_VISIBLE.getKey()); = new BooleanProperty(TimeCalcProperty.CIRCLE_VISIBLE.getKey());
public final BooleanProperty walkingHumanVisibleProperty public final BooleanProperty walkingHumanVisibleProperty
= new BooleanProperty(TimeCalcProperty.WALKING_HUMAN_VISIBLE.getKey()); = new BooleanProperty(
TimeCalcProperty.WALKING_HUMAN_VISIBLE.getKey());
public final StringProperty mainWindowCustomTitleProperty public final StringProperty mainWindowCustomTitleProperty
= new StringProperty(TimeCalcProperty.MAIN_WINDOW_CUSTOM_TITLE.getKey()); = new StringProperty(
TimeCalcProperty.MAIN_WINDOW_CUSTOM_TITLE.getKey());
public final StringProperty profileNameProperty public final StringProperty profileNameProperty
= new StringProperty(TimeCalcProperty.PROFILE_NAME.getKey()); = new StringProperty(TimeCalcProperty.PROFILE_NAME.getKey());
private final Map<TimeCalcProperty, Property> mapOfProperties = new HashMap<>(); private final Map<TimeCalcProperty, Property> mapOfProperties =
private List<Property> allProperties = new ArrayList<>(); new HashMap<>();
private final List<Property> allProperties = new ArrayList<>();
private TimeCalcProperties timeCalcProperties; private TimeCalcProperties timeCalcProperties;
public TimeCalcConfiguration() { public TimeCalcConfiguration() {
for (Property p : new Property[]{ for (Property p : new Property[] {
visibilityDefaultProperty, visibilityDefaultProperty,
visibilitySupportedColoredProperty, visibilitySupportedColoredProperty,
clockVisibleProperty, clockVisibleProperty,
clockHandsLongVisibleProperty, clockHandsLongVisibleProperty,
clockHandsColoredProperty, clockHandsColoredProperty,
clockHandsHourVisibleProperty, clockHandsHourVisibleProperty,
clockHandsMinuteVisibleProperty, clockHandsMinuteVisibleProperty,
clockHandsSecondVisibleProperty, clockHandsSecondVisibleProperty,
clockHandsMillisecondVisibleProperty, clockHandsMillisecondVisibleProperty,
clockBorderVisibleProperty, clockBorderVisibleProperty,
clockBorderOnlyHoursProperty, clockBorderOnlyHoursProperty,
clockNumbersVisibleProperty, clockNumbersVisibleProperty,
clockCircleVisibleProperty, clockCircleVisibleProperty,
clockCircleStrongBorderProperty, clockCircleStrongBorderProperty,
clockCircleBorderColorProperty, clockCircleBorderColorProperty,
clockCentreCircleVisibleProperty, clockCentreCircleVisibleProperty,
clockCentreCircleBlackProperty, clockCentreCircleBlackProperty,
clockProgressVisibleOnlyIfMouseMovingOverProperty, clockProgressVisibleOnlyIfMouseMovingOverProperty,
clockDateVisibleOnlyIfMouseMovingOverProperty, clockDateVisibleOnlyIfMouseMovingOverProperty,
batteryWavesVisibleProperty, batteryWavesVisibleProperty,
batteryCircleProgressProperty, batteryCircleProgressProperty,
batteryPercentProgressProperty, batteryPercentProgressProperty,
batteryChargingCharacterVisibleProperty, batteryChargingCharacterVisibleProperty,
batteryNameVisibleProperty, batteryNameVisibleProperty,
batteryLabelVisibleProperty, batteryLabelVisibleProperty,
batteryVisibleProperty, batteryVisibleProperty,
batteryMinuteVisibleProperty, batteryMinuteVisibleProperty,
batteryHourVisibleProperty, batteryHourVisibleProperty,
batteryDayVisibleProperty, batteryDayVisibleProperty,
batteryWeekVisibleProperty, batteryWeekVisibleProperty,
batteryMonthVisibleProperty, batteryMonthVisibleProperty,
batteryYearVisibleProperty, batteryYearVisibleProperty,
batteryBlinkingIfCriticalLowVisibleProperty, batteryBlinkingIfCriticalLowVisibleProperty,
jokesVisibleProperty, jokesVisibleProperty,
commandsVisibleProperty, commandsVisibleProperty,
notificationsVisibleProperty, notificationsVisibleProperty,
smileysVisibleProperty, smileysVisibleProperty,
smileysVisibleOnlyIfMouseMovingOverProperty, smileysVisibleOnlyIfMouseMovingOverProperty,
smileysColoredProperty, smileysColoredProperty,
squareVisibleProperty, squareVisibleProperty,
circleVisibleProperty, circleVisibleProperty,
walkingHumanVisibleProperty, walkingHumanVisibleProperty,
mainWindowCustomTitleProperty, mainWindowCustomTitleProperty,
profileNameProperty, profileNameProperty,
}) { }) {
allProperties.add(p); allProperties.add(p);
} }
allProperties.stream().forEach(p -> mapOfProperties.put(TimeCalcProperty.forKey(p.getName()), p)); allProperties.stream().forEach(p -> mapOfProperties
.put(TimeCalcProperty.forKey(p.getName()), p));
batteryVisibleProperty.addListener(e -> { batteryVisibleProperty.addListener(e -> {
batteryMinuteVisibleProperty.setValue(batteryVisibleProperty.getValue()); batteryMinuteVisibleProperty
batteryHourVisibleProperty.setValue(batteryVisibleProperty.getValue()); .setValue(batteryVisibleProperty.getValue());
batteryDayVisibleProperty.setValue(batteryVisibleProperty.getValue()); batteryHourVisibleProperty
batteryWeekVisibleProperty.setValue(batteryVisibleProperty.getValue()); .setValue(batteryVisibleProperty.getValue());
batteryMonthVisibleProperty.setValue(batteryVisibleProperty.getValue()); batteryDayVisibleProperty
batteryYearVisibleProperty.setValue(batteryVisibleProperty.getValue()); .setValue(batteryVisibleProperty.getValue());
batteryWeekVisibleProperty
.setValue(batteryVisibleProperty.getValue());
batteryMonthVisibleProperty
.setValue(batteryVisibleProperty.getValue());
batteryYearVisibleProperty
.setValue(batteryVisibleProperty.getValue());
}); });
} }
public Property getProperty(TimeCalcProperty timeCalcProperty) { public Property getProperty(TimeCalcProperty timeCalcProperty) {
if (!mapOfProperties.containsKey(timeCalcProperty)) { if (!mapOfProperties.containsKey(timeCalcProperty)) {
throw new TimeCalcException("There is no property for : " + timeCalcProperty); throw new TimeCalcException(
"There is no property for : " + timeCalcProperty);
} }
return mapOfProperties.get(timeCalcProperty); return mapOfProperties.get(timeCalcProperty);
} }
@ -219,11 +242,14 @@ public class TimeCalcConfiguration {
public void saveToTimeCalcProperties() { public void saveToTimeCalcProperties() {
System.out.println("Going to save properties."); System.out.println("Going to save properties.");
if (timeCalcProperties == null) { if (timeCalcProperties == null) {
throw new TimeCalcException("Cannot save properties, because timeCalcProperties is null."); throw new TimeCalcException(
"Cannot save properties, because timeCalcProperties is null.");
} }
Properties properties = new Properties(); Properties properties = new Properties();
this.allProperties.stream().forEach(p -> properties.put(p.getName(), p.getValue())); this.allProperties.stream()
this.timeCalcProperties.save(properties, this.profileNameProperty.getValue()); .forEach(p -> properties.put(p.getName(), p.getValue()));
this.timeCalcProperties
.save(properties, this.profileNameProperty.getValue());
} }
@ -232,24 +258,32 @@ public class TimeCalcConfiguration {
this.timeCalcProperties = timeCalcProperties; this.timeCalcProperties = timeCalcProperties;
for (Property p : allProperties) { for (Property p : allProperties) {
if (p instanceof BooleanProperty) { if (p instanceof BooleanProperty) {
((BooleanProperty) p).setValue(timeCalcProperties.getBooleanProperty(TimeCalcProperty.forKey(p.getName()))); p.setValue(timeCalcProperties
.getBooleanProperty(
TimeCalcProperty.forKey(p.getName())));
continue; continue;
} }
if (p.getName().equals(TimeCalcProperty.VISIBILITY_DEFAULT.name())) { if (p.getName()
visibilityDefaultProperty.setValue(timeCalcProperties.getStringProperty(TimeCalcProperty.VISIBILITY_DEFAULT)); .equals(TimeCalcProperty.VISIBILITY_DEFAULT.name())) {
visibilityDefaultProperty.setValue(timeCalcProperties
.getStringProperty(
TimeCalcProperty.VISIBILITY_DEFAULT));
continue; continue;
} }
if (p instanceof StringProperty) { if (p instanceof StringProperty) {
((StringProperty) p).setValue(timeCalcProperties.getStringProperty(TimeCalcProperty.forKey(p.getName()))); p.setValue(timeCalcProperties
.getStringProperty(
TimeCalcProperty.forKey(p.getName())));
continue; continue;
} }
throw new TimeCalcException("Unsupported Property class: " + p.getClass().getName()); throw new TimeCalcException(
"Unsupported Property class: " + p.getClass().getName());
} }
// for(Property p:allProperties) { // for(Property p:allProperties) {
// System.out.println(p.getName() + "=" + p.getValue()); // System.out.println(p.getName() + "=" + p.getValue());
// } // }
} }
} }

View File

@ -1,7 +1,5 @@
package org.nanoboot.utils.timecalc.app; package org.nanoboot.utils.timecalc.app;
import java.io.IOException;
/** /**
* @author Robert Vokac * @author Robert Vokac
* @since 21.02.2024 * @since 21.02.2024

View File

@ -35,7 +35,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
boolean onlyGreyOrNone boolean onlyGreyOrNone
= timeCalcConfiguration.visibilitySupportedColoredProperty = timeCalcConfiguration.visibilitySupportedColoredProperty
.isDisabled(); .isDisabled();
Visibility visibility = Visibility Visibility visibility = Visibility
.valueOf(timeCalcApp.visibilityProperty.getValue()); .valueOf(timeCalcApp.visibilityProperty.getValue());
@ -52,9 +52,10 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
keyCode == KeyEvent.VK_8 || keyCode == KeyEvent.VK_8 ||
keyCode == KeyEvent.VK_9; keyCode == KeyEvent.VK_9;
if (numberKeyWasPressed && !FileConstants.TIME_CALC_PROFILES_TXT_FILE
if(numberKeyWasPressed && !FileConstants.TIME_CALC_PROFILES_TXT_FILE.exists()) { .exists()) {
Utils.showNotification("Warning: There is no profile assigned to Key with number, you pressed."); Utils.showNotification(
"Warning: There is no profile assigned to Key with number, you pressed.");
} }
switch (keyCode) { switch (keyCode) {
@ -207,59 +208,97 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
} }
case KeyEvent.VK_F: { case KeyEvent.VK_F: {
if(FileConstants.TIME_CALC_PROFILES_TXT_FILE.exists()) { if (FileConstants.TIME_CALC_PROFILES_TXT_FILE.exists()) {
try { try {
Utils.showNotification(Utils.readTextFromFile(FileConstants.TIME_CALC_PROFILES_TXT_FILE), 15000, 200); Utils.showNotification(Utils.readTextFromFile(
FileConstants.TIME_CALC_PROFILES_TXT_FILE),
15000, 200);
} catch (IOException ioException) { } catch (IOException ioException) {
ioException.printStackTrace(); ioException.printStackTrace();
Utils.showNotification("Error: " + ioException.getMessage()); Utils.showNotification(
"Error: " + ioException.getMessage());
} }
} else { } else {
Utils.showNotification("Warning: There are no numbers assigned to profiles. Update file: " + FileConstants.TIME_CALC_PROFILES_TXT_FILE.getAbsolutePath() + "."); Utils.showNotification(
"Warning: There are no numbers assigned to profiles. Update file: "
+ FileConstants.TIME_CALC_PROFILES_TXT_FILE
.getAbsolutePath() + ".");
} }
break; break;
} }
case KeyEvent.VK_Q: { case KeyEvent.VK_Q: {
timeCalcConfiguration.squareVisibleProperty.flip();break; timeCalcConfiguration.squareVisibleProperty.flip();
break;
} }
case KeyEvent.VK_L: { case KeyEvent.VK_L: {
timeCalcConfiguration.circleVisibleProperty.flip();break; timeCalcConfiguration.circleVisibleProperty.flip();
break;
} }
case KeyEvent.VK_Y: { case KeyEvent.VK_Y: {
timeCalcConfiguration.smileysVisibleOnlyIfMouseMovingOverProperty.flip();break; timeCalcConfiguration.smileysVisibleOnlyIfMouseMovingOverProperty
.flip();
break;
} }
case KeyEvent.VK_M: { case KeyEvent.VK_M: {
timeCalcConfiguration.walkingHumanVisibleProperty.flip();break; timeCalcConfiguration.walkingHumanVisibleProperty.flip();
break;
} }
default: Utils.showNotification("Unsupported key was pressed. There is no key shortcut for this key."); default:
Utils.showNotification(
"Unsupported key was pressed. There is no key shortcut for this key.");
} }
if (numberKeyWasPressed && FileConstants.TIME_CALC_PROFILES_TXT_FILE.exists()) { if (numberKeyWasPressed && FileConstants.TIME_CALC_PROFILES_TXT_FILE
.exists()) {
Properties properties = new Properties(); Properties properties = new Properties();
try { try {
properties.load(new FileInputStream(FileConstants.TIME_CALC_PROFILES_TXT_FILE)); properties.load(new FileInputStream(
FileConstants.TIME_CALC_PROFILES_TXT_FILE));
} catch (IOException ioException) { } catch (IOException ioException) {
ioException.printStackTrace(); ioException.printStackTrace();
} }
int profileNumber = 0; int profileNumber = 0;
switch(keyCode) { switch (keyCode) {
case KeyEvent.VK_0: profileNumber = 0;break; case KeyEvent.VK_0:
case KeyEvent.VK_1: profileNumber = 1;break; profileNumber = 0;
case KeyEvent.VK_2: profileNumber = 2;break; break;
case KeyEvent.VK_3: profileNumber = 3;break; case KeyEvent.VK_1:
case KeyEvent.VK_4: profileNumber = 4;break; profileNumber = 1;
case KeyEvent.VK_5: profileNumber = 5;break; break;
case KeyEvent.VK_6: profileNumber = 6;break; case KeyEvent.VK_2:
case KeyEvent.VK_7: profileNumber = 7;break; profileNumber = 2;
case KeyEvent.VK_8: profileNumber = 8;break; break;
case KeyEvent.VK_9: profileNumber = 9;break; case KeyEvent.VK_3:
profileNumber = 3;
break;
case KeyEvent.VK_4:
profileNumber = 4;
break;
case KeyEvent.VK_5:
profileNumber = 5;
break;
case KeyEvent.VK_6:
profileNumber = 6;
break;
case KeyEvent.VK_7:
profileNumber = 7;
break;
case KeyEvent.VK_8:
profileNumber = 8;
break;
case KeyEvent.VK_9:
profileNumber = 9;
break;
} }
String key = String.valueOf(profileNumber); String key = String.valueOf(profileNumber);
if(properties.containsKey(key)) { if (properties.containsKey(key)) {
String profileName = (String) properties.get(key); String profileName = (String) properties.get(key);
if(profileName.equals( timeCalcConfiguration.profileNameProperty)) { if (profileName
Utils.showNotification("Profile \"" + profileName + "\" is already active. Nothing to do", 5000); .equals(timeCalcConfiguration.profileNameProperty)) {
Utils.showNotification("Profile \"" + profileName
+ "\" is already active. Nothing to do",
5000);
} else { } else {
Utils.showNotification("Info: Changing profile to: " + (( Utils.showNotification("Info: Changing profile to: " + ((
profileName.isEmpty() ? "{Default profile}" : profileName.isEmpty() ? "{Default profile}" :
@ -270,11 +309,12 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
} }
} else { } else {
Utils.showNotification("Warning: There is no profile assigned to Key " + profileNumber, 5000); Utils.showNotification(
"Warning: There is no profile assigned to Key "
+ profileNumber, 5000);
} }
} }
window.repaint(); window.repaint();
} }

View File

@ -19,7 +19,6 @@ import java.util.Properties;
*/ */
public class TimeCalcProperties { public class TimeCalcProperties {
private static TimeCalcProperties INSTANCE; private static TimeCalcProperties INSTANCE;
private final Properties properties = new Properties(); private final Properties properties = new Properties();
@ -29,14 +28,17 @@ public class TimeCalcProperties {
System.out.println("Loading configuration - start"); System.out.println("Loading configuration - start");
String profileName = ""; String profileName = "";
try { try {
profileName = FileConstants.TIME_CALC_CURRENT_PROFILE_TXT_FILE.exists() ? Utils.readTextFromFile( profileName =
FileConstants.TIME_CALC_CURRENT_PROFILE_TXT_FILE) : ""; FileConstants.TIME_CALC_CURRENT_PROFILE_TXT_FILE.exists() ?
Utils.readTextFromFile(
FileConstants.TIME_CALC_CURRENT_PROFILE_TXT_FILE) :
"";
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
throw new TimeCalcException(e); throw new TimeCalcException(e);
} }
File file = getFile(profileName); File file = getFile(profileName);
if(file.exists()) { if (file.exists()) {
try { try {
this.properties.load(new FileInputStream(file)); this.properties.load(new FileInputStream(file));
} catch (IOException e) { } catch (IOException e) {
@ -55,7 +57,8 @@ public class TimeCalcProperties {
.filter(l -> l.contains("=")) .filter(l -> l.contains("="))
.forEach(l -> { .forEach(l -> {
String[] array = l.split("="); String[] array = l.split("=");
defaultProperties.put(array[0], array.length > 1 ? array[1] : ""); defaultProperties.put(array[0],
array.length > 1 ? array[1] : "");
}); });
} catch (IOException e) { } catch (IOException e) {
@ -81,8 +84,11 @@ public class TimeCalcProperties {
} }
private String getDefaultStringValue(TimeCalcProperty timeCalcProperty) { private String getDefaultStringValue(TimeCalcProperty timeCalcProperty) {
if (!defaultProperties.containsKey((String) timeCalcProperty.getKey())) { if (!defaultProperties
throw new TimeCalcException("timecalc-default.conf is missing key: \"" + timeCalcProperty.getKey() + "\""); .containsKey(timeCalcProperty.getKey())) {
throw new TimeCalcException(
"timecalc-default.conf is missing key: \""
+ timeCalcProperty.getKey() + "\"");
} }
return defaultProperties.get(timeCalcProperty.getKey()); return defaultProperties.get(timeCalcProperty.getKey());
} }
@ -97,7 +103,8 @@ public class TimeCalcProperties {
} }
public String getStringProperty(TimeCalcProperty timeCalcProperty) { public String getStringProperty(TimeCalcProperty timeCalcProperty) {
return getStringProperty(timeCalcProperty, getDefaultStringValue(timeCalcProperty)); return getStringProperty(timeCalcProperty,
getDefaultStringValue(timeCalcProperty));
} }
private String getStringProperty(TimeCalcProperty timeCalcProperty, private String getStringProperty(TimeCalcProperty timeCalcProperty,
@ -110,7 +117,8 @@ public class TimeCalcProperties {
} }
private String getVisibilityProperty(TimeCalcProperty timeCalcProperty) { private String getVisibilityProperty(TimeCalcProperty timeCalcProperty) {
return getStringProperty(timeCalcProperty, Visibility.STRONGLY_COLORED.name()); return getStringProperty(timeCalcProperty,
Visibility.STRONGLY_COLORED.name());
} }
private void setBooleanProperty(TimeCalcProperty timeCalcProperty, private void setBooleanProperty(TimeCalcProperty timeCalcProperty,
@ -133,15 +141,15 @@ public class TimeCalcProperties {
public void save(Properties properties, String profileName) { public void save(Properties properties, String profileName) {
properties.entrySet().stream().forEach(e properties.entrySet().stream().forEach(e
-> { -> {
if (this.properties.containsKey(e.getKey())) { if (this.properties.containsKey(e.getKey())) {
this.properties this.properties
.replace(e.getKey(), e.getValue().toString()); .replace(e.getKey(), e.getValue().toString());
} else { } else {
this.properties this.properties
.put(e.getKey(), e.getValue().toString()); .put(e.getKey(), e.getValue().toString());
} }
} }
); );
File file = getFile(profileName); File file = getFile(profileName);
try { try {
@ -153,23 +161,26 @@ public class TimeCalcProperties {
"Saving to " + file + " failed: " + e.getMessage()); "Saving to " + file + " failed: " + e.getMessage());
} }
Utils.writeTextToFile(FileConstants.TIME_CALC_CURRENT_PROFILE_TXT_FILE, profileName); Utils.writeTextToFile(FileConstants.TIME_CALC_CURRENT_PROFILE_TXT_FILE,
profileName);
} }
private File getFile(String profileName) { private File getFile(String profileName) {
return profileName == null || profileName.isEmpty() ? return profileName == null || profileName.isEmpty() ?
FileConstants.FILE_WITHOUT_ANY_PROFILE : FileConstants.FILE_WITHOUT_ANY_PROFILE :
new File(FileConstants.FILE_WITHOUT_ANY_PROFILE.getParentFile(), "timecalc." + profileName + ".conf"); new File(FileConstants.FILE_WITHOUT_ANY_PROFILE.getParentFile(),
"timecalc." + profileName + ".conf");
} }
public void loadProfile(String profileName) { public void loadProfile(String profileName) {
File file = getFile(profileName); File file = getFile(profileName);
if(!file.exists()) { if (!file.exists()) {
Utils.showNotification("There is no profile with name: " + profileName); Utils.showNotification(
"There is no profile with name: " + profileName);
return; return;
} }
try { try {
this.properties.load( new FileInputStream(file)); this.properties.load(new FileInputStream(file));
} catch (IOException e) { } catch (IOException e) {
System.err.println(e); System.err.println(e);
} }

View File

@ -12,33 +12,49 @@ import java.util.Optional;
*/ */
public enum TimeCalcProperty { public enum TimeCalcProperty {
VISIBILITY_DEFAULT("visibility.default", "Default Visibility"), VISIBILITY_DEFAULT("visibility.default", "Default Visibility"),
VISIBILITY_SUPPORTED_COLORED("visibility.supported.colored", "Visibility : Supported : Colored"), VISIBILITY_SUPPORTED_COLORED("visibility.supported.colored",
"Visibility : Supported : Colored"),
// //
CLOCK_VISIBLE("clock.visible", "Clock"), CLOCK_VISIBLE("clock.visible", "Clock"),
CLOCK_HANDS_LONG_VISIBLE("clock.hands.long.visible", "Clock : Long Hands"), CLOCK_HANDS_LONG_VISIBLE("clock.hands.long.visible", "Clock : Long Hands"),
CLOCK_HANDS_COLORED("clock.hands.colored", "Clock : Colored Hands"), CLOCK_HANDS_COLORED("clock.hands.colored", "Clock : Colored Hands"),
CLOCK_HANDS_HOUR_VISIBLE("clock.hands.hour.visible", "Clock : Hour hand"), CLOCK_HANDS_HOUR_VISIBLE("clock.hands.hour.visible", "Clock : Hour hand"),
CLOCK_HANDS_MINUTE_VISIBLE("clock.hands.minute.visible", "Clock : Minute hand"), CLOCK_HANDS_MINUTE_VISIBLE("clock.hands.minute.visible",
CLOCK_HANDS_SECOND_VISIBLE("clock.hands.second.visible", "Clock : Second hand"), "Clock : Minute hand"),
CLOCK_HANDS_MILLISECOND_VISIBLE("clock.hands.millisecond.visible", "Clock : Millisecond hand"), CLOCK_HANDS_SECOND_VISIBLE("clock.hands.second.visible",
"Clock : Second hand"),
CLOCK_HANDS_MILLISECOND_VISIBLE("clock.hands.millisecond.visible",
"Clock : Millisecond hand"),
CLOCK_BORDER_VISIBLE("clock.border.visible", "Clock : Border"), CLOCK_BORDER_VISIBLE("clock.border.visible", "Clock : Border"),
CLOCK_BORDER_ONLY_HOURS("clock.border.only-hours", "Clock : Border : Only hours"), CLOCK_BORDER_ONLY_HOURS("clock.border.only-hours",
"Clock : Border : Only hours"),
CLOCK_NUMBERS_VISIBLE("clock.numbers.visible", "Clock : Numbers"), CLOCK_NUMBERS_VISIBLE("clock.numbers.visible", "Clock : Numbers"),
CLOCK_CIRCLE_VISIBLE("clock.circle.visible", "Clock : Circle"), CLOCK_CIRCLE_VISIBLE("clock.circle.visible", "Clock : Circle"),
CLOCK_CIRCLE_STRONG_BORDER("clock.circle.strong-border", "Clock : Circle : Strong border"), CLOCK_CIRCLE_STRONG_BORDER("clock.circle.strong-border",
CLOCK_CIRCLE_BORDER_COLOR("clock.circle.border-color", "Clock : Circle : Border color", "Clock : Circle : Strong border"),
CLOCK_CIRCLE_BORDER_COLOR("clock.circle.border-color",
"Clock : Circle : Border color",
Color.class), Color.class),
CLOCK_CENTRE_CIRCLE_VISIBLE("clock.centre-circle.visible", "Clock : Centre circle"), CLOCK_CENTRE_CIRCLE_VISIBLE("clock.centre-circle.visible",
CLOCK_CENTRE_CIRCLE_BLACK("clock.centre-circle.black", "Clock : Centre Circle is black"), "Clock : Centre circle"),
CLOCK_PROGRESS_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER("clock.progress.visible-only-if-mouse-moving-over", "Clock : Progress visible only, if mouse moving over"), CLOCK_CENTRE_CIRCLE_BLACK("clock.centre-circle.black",
CLOCK_DATE_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER("clock.date.visible-only-if-mouse-moving-over", "Clock : Date visible only, if mouse moving over"), "Clock : Centre Circle is black"),
CLOCK_PROGRESS_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER(
"clock.progress.visible-only-if-mouse-moving-over",
"Clock : Progress visible only, if mouse moving over"),
CLOCK_DATE_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER(
"clock.date.visible-only-if-mouse-moving-over",
"Clock : Date visible only, if mouse moving over"),
// //
BATTERY_WAVES_VISIBLE("battery.waves.visible", "Battery : Waves"), BATTERY_WAVES_VISIBLE("battery.waves.visible", "Battery : Waves"),
BATTERY_CIRCLE_PROGRESS_VISIBLE("battery.circle-progress.visible", "Battery : Circle Progress"), BATTERY_CIRCLE_PROGRESS_VISIBLE("battery.circle-progress.visible",
BATTERY_PERCENT_PROGRESS_VISIBLE("battery.percent-progress.visible", "Battery : Percent Progress"), "Battery : Circle Progress"),
BATTERY_PERCENT_PROGRESS_VISIBLE("battery.percent-progress.visible",
"Battery : Percent Progress"),
BATTERY_CHARGING_CHARACTER_VISIBLE("battery.charging-character.visible", "Battery : Charging Character"), BATTERY_CHARGING_CHARACTER_VISIBLE("battery.charging-character.visible",
"Battery : Charging Character"),
BATTERY_NAME_VISIBLE("battery.name.visible", "Battery : Name"), BATTERY_NAME_VISIBLE("battery.name.visible", "Battery : Name"),
BATTERY_LABEL_VISIBLE("battery.label.visible", "Battery : Label"), BATTERY_LABEL_VISIBLE("battery.label.visible", "Battery : Label"),
@ -49,20 +65,23 @@ public enum TimeCalcProperty {
BATTERY_WEEK_VISIBLE("battery.week.visible", "Battery : Week"), BATTERY_WEEK_VISIBLE("battery.week.visible", "Battery : Week"),
BATTERY_MONTH_VISIBLE("battery.month.visible", "Battery : Month"), BATTERY_MONTH_VISIBLE("battery.month.visible", "Battery : Month"),
BATTERY_YEAR_VISIBLE("battery.year.visible", "Battery : Year"), BATTERY_YEAR_VISIBLE("battery.year.visible", "Battery : Year"),
BATTERY_BLINKING_IF_CRITICAL_LOW("battery.blinking-if-critical-low", "Battery : Blinking, if critical low"), BATTERY_BLINKING_IF_CRITICAL_LOW("battery.blinking-if-critical-low",
"Battery : Blinking, if critical low"),
JOKES_VISIBLE("jokes.visible", "Jokes"), JOKES_VISIBLE("jokes.visible", "Jokes"),
COMMANDS_VISIBLE("commands.visible", "Commands"), COMMANDS_VISIBLE("commands.visible", "Commands"),
NOTIFICATIONS_VISIBLE("notifications.visible", "Notifications"), NOTIFICATIONS_VISIBLE("notifications.visible", "Notifications"),
SMILEYS_VISIBLE("smileys.visible", "Smileys"), SMILEYS_VISIBLE("smileys.visible", "Smileys"),
SMILEYS_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER("smileys.visible-only-if-mouse-moving-over", "Smileys : Visible only, if mouse moving over"), SMILEYS_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER(
"smileys.visible-only-if-mouse-moving-over",
"Smileys : Visible only, if mouse moving over"),
SMILEYS_COLORED("smileys.colored", "Smileys : Colored"), SMILEYS_COLORED("smileys.colored", "Smileys : Colored"),
SQUARE_VISIBLE("square.visible", "Square"), SQUARE_VISIBLE("square.visible", "Square"),
CIRCLE_VISIBLE("circle.visible", "Circle"), CIRCLE_VISIBLE("circle.visible", "Circle"),
WALKING_HUMAN_VISIBLE("walking-human.visible", "Walking Human"), WALKING_HUMAN_VISIBLE("walking-human.visible", "Walking Human"),
MAIN_WINDOW_CUSTOM_TITLE("main-window.custom-title", "Main Window : Custom Title"), MAIN_WINDOW_CUSTOM_TITLE("main-window.custom-title",
"Main Window : Custom Title"),
PROFILE_NAME("profile.name", "Profile : Name"); PROFILE_NAME("profile.name", "Profile : Name");
@Getter @Getter
@ -72,18 +91,6 @@ public enum TimeCalcProperty {
@Getter @Getter
private final Class clazz; private final Class clazz;
public static TimeCalcProperty forKey(String key) {
Optional<TimeCalcProperty> timeCalcPropertyOptional = Arrays.stream(values()).filter(t -> t.getKey().equals(key)).findFirst();
if (timeCalcPropertyOptional.isPresent()) {
return timeCalcPropertyOptional.get();
} else {
TimeCalcException e
= new TimeCalcException("There is no key: " + key);
e.printStackTrace();
throw e;
}
}
TimeCalcProperty(String key, String description, Class clazz) { TimeCalcProperty(String key, String description, Class clazz) {
this.key = key; this.key = key;
this.description = description; this.description = description;
@ -94,4 +101,18 @@ public enum TimeCalcProperty {
this(key, description, Boolean.class); this(key, description, Boolean.class);
} }
public static TimeCalcProperty forKey(String key) {
Optional<TimeCalcProperty> timeCalcPropertyOptional =
Arrays.stream(values()).filter(t -> t.getKey().equals(key))
.findFirst();
if (timeCalcPropertyOptional.isPresent()) {
return timeCalcPropertyOptional.get();
} else {
TimeCalcException e
= new TimeCalcException("There is no key: " + key);
e.printStackTrace();
throw e;
}
}
} }

View File

@ -30,7 +30,10 @@ public class Activity {
} }
public String createBugzillaComment() { public String createBugzillaComment() {
return ticket + SUBJECT_FIELD_SEPARATOR + year + "-" + month + "-" + day + SUBJECT_FIELD_SEPARATOR + ((spentHours + spentMinutes / 60d) + "h") + SUBJECT_FIELD_SEPARATOR + comment; return ticket + SUBJECT_FIELD_SEPARATOR + year + "-" + month + "-" + day
+ SUBJECT_FIELD_SEPARATOR + ((spentHours + spentMinutes / 60d)
+ "h") + SUBJECT_FIELD_SEPARATOR
+ comment;
} }
} }

View File

@ -29,19 +29,20 @@ public class ComponentRegistry<T extends Component> {
add(c); add(c);
} }
} }
public void setVisible(boolean b) { public void setVisible(boolean b) {
setVisible(null, b); setVisible(null, b);
} }
public void setVisible(Predicate<Component> predicate, boolean b) { public void setVisible(Predicate<Component> predicate, boolean b) {
for (T c : set) { for (T c : set) {
if(c instanceof TButton) { if (c instanceof TButton) {
if(!MainWindow.hideShowCheckBox.isSelected() && b) { if (!MainWindow.hideShowCheckBox.isSelected() && b) {
continue; continue;
} }
} }
if(predicate != null) { if (predicate != null) {
if(!predicate.test(c)) { if (!predicate.test(c)) {
continue; continue;
} }
} }

View File

@ -6,11 +6,20 @@ 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 javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
import javax.swing.JColorChooser; import javax.swing.JColorChooser;
import javax.swing.JComboBox; import javax.swing.JComboBox;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font; import java.awt.Font;
@ -24,15 +33,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
/** /**
* @author Robert Vokac * @author Robert Vokac
@ -42,149 +42,184 @@ public class ConfigWindow extends TWindow {
public static final int WIDTH1 = 600; public static final int WIDTH1 = 600;
public static final int HEIGHT1 = 30; public static final int HEIGHT1 = 30;
public static final String CLIENT_PROPERTY_KEY = TimeCalcProperty.class.getName(); public static final String CLIENT_PROPERTY_KEY =
TimeCalcProperty.class.getName();
public static final String THREE_DASHES = "---"; public static final String THREE_DASHES = "---";
private static final Font BIG_FONT = new Font("sans", Font.BOLD, 24);
private static final String FIVE_SPACES = " ";
public final JComboBox visibilityDefaultProperty = new JComboBox(
Arrays.stream(Visibility.values()).map(v -> v.name()).collect(
Collectors.toList()).toArray());
private final TimeCalcConfiguration timeCalcConfiguration; private final TimeCalcConfiguration timeCalcConfiguration;
private int currentY = SwingUtils.MARGIN;
private List<JComponent> propertiesList = new ArrayList<>();
private Map<TimeCalcProperty, JComponent> propertiesMap = new HashMap<>();
private TButton enableAsMuchAsPossible = new TButton("Enable as much as possible");
private TButton disableAsMuchAsPossible = new TButton("Disable as much as possible");
public final JComboBox visibilityDefaultProperty = new JComboBox(Arrays.stream(Visibility.values()).map(v -> v.name()).collect(
Collectors.toList()).toArray());
private JCheckBox visibilitySupportedColoredProperty
= new JCheckBox(TimeCalcProperty.VISIBILITY_SUPPORTED_COLORED.getKey());
private JCheckBox clockVisibleProperty
= new JCheckBox(TimeCalcProperty.CLOCK_VISIBLE.getKey());
private JCheckBox clockHandsLongVisibleProperty
= new JCheckBox(TimeCalcProperty.CLOCK_HANDS_LONG_VISIBLE.getKey());
private JCheckBox clockHandsColoredProperty
= new JCheckBox(TimeCalcProperty.CLOCK_HANDS_COLORED.getKey());
private JCheckBox clockHandsHourVisibleProperty
= new JCheckBox(TimeCalcProperty.CLOCK_HANDS_HOUR_VISIBLE.getKey());
private JCheckBox clockHandsMinuteVisibleProperty
= new JCheckBox(TimeCalcProperty.CLOCK_HANDS_MINUTE_VISIBLE.getKey());
private JCheckBox clockHandsSecondVisibleProperty
= new JCheckBox(TimeCalcProperty.CLOCK_HANDS_SECOND_VISIBLE.getKey());
private JCheckBox clockHandsMillisecondVisibleProperty
= new JCheckBox(TimeCalcProperty.CLOCK_HANDS_MILLISECOND_VISIBLE.getKey());
private JCheckBox clockBorderVisibleProperty
= new JCheckBox(TimeCalcProperty.CLOCK_BORDER_VISIBLE.getKey());
private JCheckBox clockBorderOnlyHoursProperty
= new JCheckBox(TimeCalcProperty.CLOCK_BORDER_ONLY_HOURS.getKey());
private JCheckBox clockNumbersVisibleProperty
= new JCheckBox(TimeCalcProperty.CLOCK_NUMBERS_VISIBLE.getKey());
private JCheckBox clockCircleVisibleProperty
= new JCheckBox(TimeCalcProperty.CLOCK_CIRCLE_VISIBLE.getKey());
private JCheckBox clockCircleStrongBorderProperty
= new JCheckBox(TimeCalcProperty.CLOCK_CIRCLE_STRONG_BORDER.getKey());
private JColorChooser clockCircleBorderColorProperty
= new JColorChooser(Color.BLACK);
private JCheckBox clockCentreCircleVisibleProperty
= new JCheckBox(TimeCalcProperty.CLOCK_CENTRE_CIRCLE_VISIBLE.getKey());
private JCheckBox clockCentreCircleBlackProperty
= new JCheckBox(TimeCalcProperty.CLOCK_CENTRE_CIRCLE_BLACK.getKey());
private JCheckBox clockProgressVisibleOnlyIfMouseMovingOverProperty
= new JCheckBox(TimeCalcProperty.CLOCK_PROGRESS_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER.getKey());
private JCheckBox clockDateVisibleOnlyIfMouseMovingOverProperty
= new JCheckBox(TimeCalcProperty.CLOCK_DATE_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER.getKey());
//
private JCheckBox batteryWavesVisibleProperty
= new JCheckBox(TimeCalcProperty.BATTERY_WAVES_VISIBLE.getKey());
private JCheckBox batteryCircleProgressVisibleProperty
= new JCheckBox(TimeCalcProperty.BATTERY_CIRCLE_PROGRESS_VISIBLE.getKey());
private JCheckBox batteryPercentProgressProperty
= new JCheckBox(TimeCalcProperty.BATTERY_PERCENT_PROGRESS_VISIBLE.getKey());
private JCheckBox batteryChargingCharacterVisibleProperty
= new JCheckBox(TimeCalcProperty.BATTERY_CHARGING_CHARACTER_VISIBLE.getKey());
private JCheckBox batteryNameVisibleProperty
= new JCheckBox(TimeCalcProperty.BATTERY_NAME_VISIBLE.getKey());
private JCheckBox batteryLabelVisibleProperty = new JCheckBox(TimeCalcProperty.BATTERY_LABEL_VISIBLE.getKey());
private JCheckBox batteryVisibleProperty = new JCheckBox(TimeCalcProperty.BATTERY_VISIBLE.getKey());
private JCheckBox batteryMinuteVisibleProperty = new JCheckBox(TimeCalcProperty.BATTERY_MINUTE_VISIBLE.getKey());
private JCheckBox batteryHourVisibleProperty = new JCheckBox(TimeCalcProperty.BATTERY_HOUR_VISIBLE.getKey());
private JCheckBox batteryDayVisibleProperty = new JCheckBox(TimeCalcProperty.BATTERY_DAY_VISIBLE.getKey());
private JCheckBox batteryWeekVisibleProperty = new JCheckBox(TimeCalcProperty.BATTERY_WEEK_VISIBLE.getKey());
private JCheckBox batteryMonthVisibleProperty = new JCheckBox(TimeCalcProperty.BATTERY_MONTH_VISIBLE.getKey());
private JCheckBox batteryYearVisibleProperty = new JCheckBox(TimeCalcProperty.BATTERY_YEAR_VISIBLE.getKey());
private JCheckBox batteryBlinkingIfCriticalLowVisibleProperty = new JCheckBox(TimeCalcProperty.BATTERY_BLINKING_IF_CRITICAL_LOW.getKey());
private JCheckBox jokesVisibleProperty
= new JCheckBox(TimeCalcProperty.JOKES_VISIBLE.getKey());
private JCheckBox commandsVisibleProperty
= new JCheckBox(TimeCalcProperty.COMMANDS_VISIBLE.getKey());
private JCheckBox notificationsVisibleProperty
= new JCheckBox(TimeCalcProperty.NOTIFICATIONS_VISIBLE.getKey());
private JCheckBox smileysVisibleOnlyIfMouseMovingOverProperty
= new JCheckBox(TimeCalcProperty.SMILEYS_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER.getKey());
private JCheckBox smileysVisibleProperty
= new JCheckBox(TimeCalcProperty.SMILEYS_VISIBLE.getKey());
private JCheckBox smileysColoredProperty
= new JCheckBox(TimeCalcProperty.SMILEYS_COLORED.getKey());
private JCheckBox squareVisibleProperty
= new JCheckBox(TimeCalcProperty.SQUARE_VISIBLE.getKey());
private JCheckBox circleVisibleProperty
= new JCheckBox(TimeCalcProperty.CIRCLE_VISIBLE.getKey());
private JCheckBox walkingHumanVisibleProperty
= new JCheckBox(TimeCalcProperty.WALKING_HUMAN_VISIBLE.getKey());
private JTextField mainWindowCustomTitleProperty
= new JTextField();
private JTextField profileNameProperty
= new JTextField();
private final JPanel panelInsideScrollPane; private final JPanel panelInsideScrollPane;
private int currentY = SwingUtils.MARGIN;
private final List<JComponent> propertiesList = new ArrayList<>();
private final Map<TimeCalcProperty, JComponent> propertiesMap = new HashMap<>();
private final TButton enableAsMuchAsPossible =
new TButton("Enable as much as possible");
private final TButton disableAsMuchAsPossible =
new TButton("Disable as much as possible");
private final JCheckBox visibilitySupportedColoredProperty
= new JCheckBox(
TimeCalcProperty.VISIBILITY_SUPPORTED_COLORED.getKey());
private final JCheckBox clockVisibleProperty
= new JCheckBox(TimeCalcProperty.CLOCK_VISIBLE.getKey());
private final JCheckBox clockHandsLongVisibleProperty
= new JCheckBox(TimeCalcProperty.CLOCK_HANDS_LONG_VISIBLE.getKey());
private final JCheckBox clockHandsColoredProperty
= new JCheckBox(TimeCalcProperty.CLOCK_HANDS_COLORED.getKey());
private final JCheckBox clockHandsHourVisibleProperty
= new JCheckBox(TimeCalcProperty.CLOCK_HANDS_HOUR_VISIBLE.getKey());
private final JCheckBox clockHandsMinuteVisibleProperty
=
new JCheckBox(TimeCalcProperty.CLOCK_HANDS_MINUTE_VISIBLE.getKey());
private final JCheckBox clockHandsSecondVisibleProperty
=
new JCheckBox(TimeCalcProperty.CLOCK_HANDS_SECOND_VISIBLE.getKey());
private final JCheckBox clockHandsMillisecondVisibleProperty
= new JCheckBox(
TimeCalcProperty.CLOCK_HANDS_MILLISECOND_VISIBLE.getKey());
private final JCheckBox clockBorderVisibleProperty
= new JCheckBox(TimeCalcProperty.CLOCK_BORDER_VISIBLE.getKey());
private final JCheckBox clockBorderOnlyHoursProperty
= new JCheckBox(TimeCalcProperty.CLOCK_BORDER_ONLY_HOURS.getKey());
private final JCheckBox clockNumbersVisibleProperty
= new JCheckBox(TimeCalcProperty.CLOCK_NUMBERS_VISIBLE.getKey());
private final JCheckBox clockCircleVisibleProperty
= new JCheckBox(TimeCalcProperty.CLOCK_CIRCLE_VISIBLE.getKey());
private final JCheckBox clockCircleStrongBorderProperty
=
new JCheckBox(TimeCalcProperty.CLOCK_CIRCLE_STRONG_BORDER.getKey());
private final JColorChooser clockCircleBorderColorProperty
= new JColorChooser(Color.BLACK);
private final JCheckBox clockCentreCircleVisibleProperty
= new JCheckBox(
TimeCalcProperty.CLOCK_CENTRE_CIRCLE_VISIBLE.getKey());
private final JCheckBox clockCentreCircleBlackProperty
=
new JCheckBox(TimeCalcProperty.CLOCK_CENTRE_CIRCLE_BLACK.getKey());
private final JCheckBox clockProgressVisibleOnlyIfMouseMovingOverProperty
= new JCheckBox(
TimeCalcProperty.CLOCK_PROGRESS_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER
.getKey());
private final JCheckBox clockDateVisibleOnlyIfMouseMovingOverProperty
= new JCheckBox(
TimeCalcProperty.CLOCK_DATE_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER
.getKey());
//
private final JCheckBox batteryWavesVisibleProperty
= new JCheckBox(TimeCalcProperty.BATTERY_WAVES_VISIBLE.getKey());
private final JCheckBox batteryCircleProgressVisibleProperty
= new JCheckBox(
TimeCalcProperty.BATTERY_CIRCLE_PROGRESS_VISIBLE.getKey());
private final JCheckBox batteryPercentProgressProperty
= new JCheckBox(
TimeCalcProperty.BATTERY_PERCENT_PROGRESS_VISIBLE.getKey());
private final JCheckBox batteryChargingCharacterVisibleProperty
= new JCheckBox(
TimeCalcProperty.BATTERY_CHARGING_CHARACTER_VISIBLE.getKey());
private final JCheckBox batteryNameVisibleProperty
= new JCheckBox(TimeCalcProperty.BATTERY_NAME_VISIBLE.getKey());
private final JCheckBox batteryLabelVisibleProperty =
new JCheckBox(TimeCalcProperty.BATTERY_LABEL_VISIBLE.getKey());
private final JCheckBox batteryVisibleProperty =
new JCheckBox(TimeCalcProperty.BATTERY_VISIBLE.getKey());
private final JCheckBox batteryMinuteVisibleProperty =
new JCheckBox(TimeCalcProperty.BATTERY_MINUTE_VISIBLE.getKey());
private final JCheckBox batteryHourVisibleProperty =
new JCheckBox(TimeCalcProperty.BATTERY_HOUR_VISIBLE.getKey());
private final JCheckBox batteryDayVisibleProperty =
new JCheckBox(TimeCalcProperty.BATTERY_DAY_VISIBLE.getKey());
private final JCheckBox batteryWeekVisibleProperty =
new JCheckBox(TimeCalcProperty.BATTERY_WEEK_VISIBLE.getKey());
private final JCheckBox batteryMonthVisibleProperty =
new JCheckBox(TimeCalcProperty.BATTERY_MONTH_VISIBLE.getKey());
private final JCheckBox batteryYearVisibleProperty =
new JCheckBox(TimeCalcProperty.BATTERY_YEAR_VISIBLE.getKey());
private final JCheckBox batteryBlinkingIfCriticalLowVisibleProperty =
new JCheckBox(
TimeCalcProperty.BATTERY_BLINKING_IF_CRITICAL_LOW.getKey());
private final JCheckBox jokesVisibleProperty
= new JCheckBox(TimeCalcProperty.JOKES_VISIBLE.getKey());
private final JCheckBox commandsVisibleProperty
= new JCheckBox(TimeCalcProperty.COMMANDS_VISIBLE.getKey());
private final JCheckBox notificationsVisibleProperty
= new JCheckBox(TimeCalcProperty.NOTIFICATIONS_VISIBLE.getKey());
private final JCheckBox smileysVisibleOnlyIfMouseMovingOverProperty
= new JCheckBox(
TimeCalcProperty.SMILEYS_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER
.getKey());
private final JCheckBox smileysVisibleProperty
= new JCheckBox(TimeCalcProperty.SMILEYS_VISIBLE.getKey());
private final JCheckBox smileysColoredProperty
= new JCheckBox(TimeCalcProperty.SMILEYS_COLORED.getKey());
private final JCheckBox squareVisibleProperty
= new JCheckBox(TimeCalcProperty.SQUARE_VISIBLE.getKey());
private final JCheckBox circleVisibleProperty
= new JCheckBox(TimeCalcProperty.CIRCLE_VISIBLE.getKey());
private final JCheckBox walkingHumanVisibleProperty
= new JCheckBox(TimeCalcProperty.WALKING_HUMAN_VISIBLE.getKey());
private final JTextField mainWindowCustomTitleProperty
= new JTextField();
private final JTextField profileNameProperty
= new JTextField();
public ConfigWindow(TimeCalcConfiguration timeCalcConfiguration) { public ConfigWindow(TimeCalcConfiguration timeCalcConfiguration) {
this.timeCalcConfiguration = timeCalcConfiguration; this.timeCalcConfiguration = timeCalcConfiguration;
setTitle("Configuration"); setTitle("Configuration");
this.setSize(800, 800); this.setSize(800, 800);
JPanel mainPanel = new JPanel(); JPanel mainPanel = new JPanel();
mainPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, getHeight() - 6 * SwingUtils.MARGIN)); mainPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE,
getHeight() - 6 * SwingUtils.MARGIN));
this.panelInsideScrollPane = new JPanel(); this.panelInsideScrollPane = new JPanel();
final BoxLayout boxLayout = new BoxLayout(panelInsideScrollPane, BoxLayout.Y_AXIS); final BoxLayout boxLayout =
new BoxLayout(panelInsideScrollPane, BoxLayout.Y_AXIS);
panelInsideScrollPane.setAlignmentX(LEFT_ALIGNMENT); panelInsideScrollPane.setAlignmentX(LEFT_ALIGNMENT);
mainPanel.setAlignmentX(LEFT_ALIGNMENT); mainPanel.setAlignmentX(LEFT_ALIGNMENT);
panelInsideScrollPane.setLayout(boxLayout); panelInsideScrollPane.setLayout(boxLayout);
panelInsideScrollPane.setMinimumSize(new Dimension(Integer.MAX_VALUE, 400)); panelInsideScrollPane
.setMinimumSize(new Dimension(Integer.MAX_VALUE, 400));
JScrollPane scrollPane = new JScrollPane(panelInsideScrollPane); JScrollPane scrollPane = new JScrollPane(panelInsideScrollPane);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setVerticalScrollBarPolicy(
scrollPane.setPreferredSize(new Dimension(getWidth() - 50, getHeight() - 100)); JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setPreferredSize(
new Dimension(getWidth() - 50, getHeight() - 100));
scrollPane.setWheelScrollingEnabled(true); scrollPane.setWheelScrollingEnabled(true);
scrollPane.setBorder(null); scrollPane.setBorder(null);
// mainPanel.setBackground(Color.red); // mainPanel.setBackground(Color.red);
// scrollPane.setBackground(Color.green); // scrollPane.setBackground(Color.green);
// panelInsideScrollPane.setBackground(Color.blue); // panelInsideScrollPane.setBackground(Color.blue);
add(mainPanel); add(mainPanel);
//mainPanel.setLayout(null); //mainPanel.setLayout(null);
mainPanel.add(enableAsMuchAsPossible); mainPanel.add(enableAsMuchAsPossible);
enableAsMuchAsPossible.setBounds(SwingUtils.MARGIN, SwingUtils.MARGIN, 250, enableAsMuchAsPossible
HEIGHT1); .setBounds(SwingUtils.MARGIN, SwingUtils.MARGIN, 250,
HEIGHT1);
mainPanel.add(disableAsMuchAsPossible); mainPanel.add(disableAsMuchAsPossible);
disableAsMuchAsPossible.setBounds(enableAsMuchAsPossible.getX() + enableAsMuchAsPossible.getWidth() + SwingUtils.MARGIN, SwingUtils.MARGIN, 250, disableAsMuchAsPossible.setBounds(
enableAsMuchAsPossible.getX() + enableAsMuchAsPossible
.getWidth() + SwingUtils.MARGIN, SwingUtils.MARGIN, 250,
HEIGHT1); HEIGHT1);
scrollPane.setBounds(enableAsMuchAsPossible.getX(), enableAsMuchAsPossible.getY() + enableAsMuchAsPossible.getHeight() + SwingUtils.MARGIN, Integer.MAX_VALUE, Integer.MAX_VALUE); scrollPane.setBounds(enableAsMuchAsPossible.getX(),
enableAsMuchAsPossible.getY() + enableAsMuchAsPossible
.getHeight() + SwingUtils.MARGIN, Integer.MAX_VALUE,
Integer.MAX_VALUE);
mainPanel.add(scrollPane); mainPanel.add(scrollPane);
for(boolean enable:new boolean[]{true, false}) { for (boolean enable : new boolean[] {true, false}) {
TButton button = enable ? enableAsMuchAsPossible : disableAsMuchAsPossible; TButton button =
enable ? enableAsMuchAsPossible : disableAsMuchAsPossible;
button.addActionListener(e -> { button.addActionListener(e -> {
visibilityDefaultProperty.setSelectedItem(Visibility.STRONGLY_COLORED.name()); visibilityDefaultProperty
clockVisibleProperty.setSelected(true); .setSelectedItem(Visibility.STRONGLY_COLORED.name());
clockHandsHourVisibleProperty.setSelected(enable); clockVisibleProperty.setSelected(true);
clockHandsHourVisibleProperty.setSelected(enable);
clockHandsMinuteVisibleProperty.setSelected(enable); clockHandsMinuteVisibleProperty.setSelected(enable);
clockHandsSecondVisibleProperty.setSelected(enable); clockHandsSecondVisibleProperty.setSelected(enable);
clockHandsMillisecondVisibleProperty.setSelected(enable); clockHandsMillisecondVisibleProperty.setSelected(enable);
@ -196,13 +231,17 @@ public class ConfigWindow extends TWindow {
clockCircleVisibleProperty.setSelected(enable); clockCircleVisibleProperty.setSelected(enable);
clockCircleStrongBorderProperty.setSelected(!enable); clockCircleStrongBorderProperty.setSelected(!enable);
clockCircleBorderColorProperty.setColor(enable ? Color.BLUE : Color.BLACK); clockCircleBorderColorProperty
timeCalcConfiguration.clockCircleBorderColorProperty.setValue(enable ? "0,0,255" : "0,0,0"); .setColor(enable ? Color.BLUE : Color.BLACK);
timeCalcConfiguration.clockCircleBorderColorProperty
.setValue(enable ? "0,0,255" : "0,0,0");
clockCentreCircleVisibleProperty.setSelected(enable); clockCentreCircleVisibleProperty.setSelected(enable);
clockCentreCircleBlackProperty.setSelected(!enable); clockCentreCircleBlackProperty.setSelected(!enable);
clockProgressVisibleOnlyIfMouseMovingOverProperty.setSelected(!enable); clockProgressVisibleOnlyIfMouseMovingOverProperty
clockDateVisibleOnlyIfMouseMovingOverProperty.setSelected(false); .setSelected(!enable);
clockDateVisibleOnlyIfMouseMovingOverProperty
.setSelected(false);
batteryVisibleProperty.setSelected(true); batteryVisibleProperty.setSelected(true);
batteryWavesVisibleProperty.setSelected(enable); batteryWavesVisibleProperty.setSelected(enable);
batteryCircleProgressVisibleProperty.setSelected(enable); batteryCircleProgressVisibleProperty.setSelected(enable);
@ -217,18 +256,19 @@ public class ConfigWindow extends TWindow {
batteryMonthVisibleProperty.setSelected(enable); batteryMonthVisibleProperty.setSelected(enable);
batteryYearVisibleProperty.setSelected(enable); batteryYearVisibleProperty.setSelected(enable);
batteryBlinkingIfCriticalLowVisibleProperty.setSelected(enable); batteryBlinkingIfCriticalLowVisibleProperty.setSelected(enable);
// //
jokesVisibleProperty.setSelected(true); jokesVisibleProperty.setSelected(true);
commandsVisibleProperty.setSelected(enable); commandsVisibleProperty.setSelected(enable);
notificationsVisibleProperty.setSelected(enable); notificationsVisibleProperty.setSelected(enable);
smileysVisibleProperty.setSelected(enable); smileysVisibleProperty.setSelected(enable);
smileysColoredProperty.setSelected(enable); smileysColoredProperty.setSelected(enable);
smileysVisibleOnlyIfMouseMovingOverProperty.setSelected(!enable); smileysVisibleOnlyIfMouseMovingOverProperty
.setSelected(!enable);
squareVisibleProperty.setSelected(enable); squareVisibleProperty.setSelected(enable);
circleVisibleProperty.setSelected(enable); circleVisibleProperty.setSelected(enable);
walkingHumanVisibleProperty.setSelected(enable); walkingHumanVisibleProperty.setSelected(enable);
MainWindow.hideShowCheckBox.setSelected(enable); MainWindow.hideShowCheckBox.setSelected(enable);
}); });
} }
propertiesList.addAll(Arrays.asList(visibilityDefaultProperty, propertiesList.addAll(Arrays.asList(visibilityDefaultProperty,
@ -280,32 +320,46 @@ public class ConfigWindow extends TWindow {
propertiesList.stream().forEach(p -> { propertiesList.stream().forEach(p -> {
p.setAlignmentX(LEFT_ALIGNMENT); p.setAlignmentX(LEFT_ALIGNMENT);
if (p == visibilityDefaultProperty) { if (p == visibilityDefaultProperty) {
p.putClientProperty(CLIENT_PROPERTY_KEY, TimeCalcProperty.VISIBILITY_DEFAULT.getKey()); p.putClientProperty(CLIENT_PROPERTY_KEY,
addToNextRow(new JLabel(TimeCalcProperty.VISIBILITY_DEFAULT.getDescription())); TimeCalcProperty.VISIBILITY_DEFAULT.getKey());
addToNextRow(new JLabel(
TimeCalcProperty.VISIBILITY_DEFAULT.getDescription()));
} }
if (p == clockCircleBorderColorProperty) { if (p == clockCircleBorderColorProperty) {
p.putClientProperty(CLIENT_PROPERTY_KEY, TimeCalcProperty.CLOCK_CIRCLE_BORDER_COLOR.getKey()); p.putClientProperty(CLIENT_PROPERTY_KEY,
addToNextRow(new JLabel(TimeCalcProperty.CLOCK_CIRCLE_BORDER_COLOR.getDescription().replace("Clock : ", ""))); TimeCalcProperty.CLOCK_CIRCLE_BORDER_COLOR.getKey());
addToNextRow(new JLabel(
TimeCalcProperty.CLOCK_CIRCLE_BORDER_COLOR
.getDescription().replace("Clock : ", "")));
} }
if (p == mainWindowCustomTitleProperty) { if (p == mainWindowCustomTitleProperty) {
addToNextRow(new JLabel(TimeCalcProperty.MAIN_WINDOW_CUSTOM_TITLE.getDescription())); addToNextRow(new JLabel(
p.putClientProperty(CLIENT_PROPERTY_KEY, TimeCalcProperty.MAIN_WINDOW_CUSTOM_TITLE.getKey()); TimeCalcProperty.MAIN_WINDOW_CUSTOM_TITLE
.getDescription()));
p.putClientProperty(CLIENT_PROPERTY_KEY,
TimeCalcProperty.MAIN_WINDOW_CUSTOM_TITLE.getKey());
} }
if (p == profileNameProperty) { if (p == profileNameProperty) {
addToNextRow(new JLabel(TimeCalcProperty.PROFILE_NAME.getDescription())); addToNextRow(new JLabel(
p.putClientProperty(CLIENT_PROPERTY_KEY, TimeCalcProperty.PROFILE_NAME.getKey()); TimeCalcProperty.PROFILE_NAME.getDescription()));
p.putClientProperty(CLIENT_PROPERTY_KEY,
TimeCalcProperty.PROFILE_NAME.getKey());
} }
if (p instanceof JComboBox) { if (p instanceof JComboBox) {
JComboBox jComboBox = ((JComboBox) p); JComboBox jComboBox = ((JComboBox) p);
jComboBox.setMaximumSize(new Dimension(150, 25)); jComboBox.setMaximumSize(new Dimension(150, 25));
String timeCalcPropertyKey = (String) jComboBox.getClientProperty( String timeCalcPropertyKey =
CLIENT_PROPERTY_KEY); (String) jComboBox.getClientProperty(
CLIENT_PROPERTY_KEY);
TimeCalcProperty timeCalcProperty TimeCalcProperty timeCalcProperty
= TimeCalcProperty.forKey(timeCalcPropertyKey); = TimeCalcProperty.forKey(timeCalcPropertyKey);
jComboBox.setSelectedItem(timeCalcConfiguration.getProperty(timeCalcProperty).getValue()); jComboBox.setSelectedItem(
timeCalcConfiguration.getProperty(timeCalcProperty)
.getValue());
jComboBox.addActionListener(e -> { jComboBox.addActionListener(e -> {
((StringProperty) timeCalcConfiguration.getProperty(timeCalcProperty)) timeCalcConfiguration
.getProperty(timeCalcProperty)
.setValue( .setValue(
(String) jComboBox.getSelectedItem()); (String) jComboBox.getSelectedItem());
}); });
@ -314,7 +368,8 @@ public class ConfigWindow extends TWindow {
if (p instanceof JCheckBox) { if (p instanceof JCheckBox) {
JCheckBox checkBox = ((JCheckBox) p); JCheckBox checkBox = ((JCheckBox) p);
String timeCalcPropertyKey = checkBox.getText(); String timeCalcPropertyKey = checkBox.getText();
checkBox.putClientProperty(CLIENT_PROPERTY_KEY, timeCalcPropertyKey); checkBox.putClientProperty(CLIENT_PROPERTY_KEY,
timeCalcPropertyKey);
TimeCalcProperty timeCalcProperty TimeCalcProperty timeCalcProperty
= TimeCalcProperty.forKey(timeCalcPropertyKey); = TimeCalcProperty.forKey(timeCalcPropertyKey);
@ -322,8 +377,9 @@ public class ConfigWindow extends TWindow {
BooleanProperty property BooleanProperty property
= (BooleanProperty) timeCalcConfiguration = (BooleanProperty) timeCalcConfiguration
.getProperty(timeCalcProperty); .getProperty(timeCalcProperty);
property.addListener(e -> checkBox.setSelected(property.isEnabled())); property.addListener(
e -> checkBox.setSelected(property.isEnabled()));
checkBox.setSelected(property.isEnabled()); checkBox.setSelected(property.isEnabled());
checkBox.addItemListener(e -> { checkBox.addItemListener(e -> {
property property
@ -331,36 +387,41 @@ public class ConfigWindow extends TWindow {
}); });
String[] array = checkBox.getText().split(" : "); String[] array = checkBox.getText().split(" : ");
String groupName = array[0]; String groupName = array[0];
if(groupName.equals("Clock") ||groupName.equals("Battery") ||groupName.equals("Smileys")) { if (groupName.equals("Clock") || groupName.equals("Battery")
|| groupName.equals("Smileys")) {
checkBox.setText(array.length > 1 ? (checkBox.getText().substring(groupName.length() + 3)) : "Visible"); checkBox.setText(array.length > 1 ? (checkBox.getText()
if(array.length == 1) { .substring(groupName.length() + 3)) : "Visible");
panelInsideScrollPane.add(new JSeparator(SwingConstants.VERTICAL)); if (array.length == 1) {
panelInsideScrollPane
.add(new JSeparator(SwingConstants.VERTICAL));
JLabel label = new JLabel(groupName); JLabel label = new JLabel(groupName);
label.setFont(BIG_FONT); label.setFont(BIG_FONT);
panelInsideScrollPane.add(label); panelInsideScrollPane.add(label);
} }
} }
if( if (
timeCalcProperty == TimeCalcProperty.VISIBILITY_DEFAULT timeCalcProperty == TimeCalcProperty.VISIBILITY_DEFAULT
|| ||
timeCalcProperty == TimeCalcProperty.JOKES_VISIBLE timeCalcProperty == TimeCalcProperty.JOKES_VISIBLE
) { ) {
JLabel label = new JLabel("Misc"); JLabel label = new JLabel("Misc");
label.setFont(BIG_FONT); label.setFont(BIG_FONT);
panelInsideScrollPane.add(label); panelInsideScrollPane.add(label);
} }
} }
if (p instanceof JColorChooser) { if (p instanceof JColorChooser) {
JColorChooser colorChooser = ((JColorChooser) p); JColorChooser colorChooser = ((JColorChooser) p);
//jColorChooser.setMaximumSize(new Dimension(150, 25)); //jColorChooser.setMaximumSize(new Dimension(150, 25));
String timeCalcPropertyKey = (String) colorChooser.getClientProperty( String timeCalcPropertyKey =
CLIENT_PROPERTY_KEY); (String) colorChooser.getClientProperty(
CLIENT_PROPERTY_KEY);
TimeCalcProperty timeCalcProperty TimeCalcProperty timeCalcProperty
= TimeCalcProperty.forKey(timeCalcPropertyKey); = TimeCalcProperty.forKey(timeCalcPropertyKey);
String currentColor = ((StringProperty) timeCalcConfiguration.getProperty(timeCalcProperty)).getValue(); String currentColor = ((StringProperty) timeCalcConfiguration
.getProperty(timeCalcProperty)).getValue();
String[] currentColorAsStringArray = currentColor.split(","); String[] currentColorAsStringArray = currentColor.split(",");
int red = Integer.valueOf(currentColorAsStringArray[0]); int red = Integer.valueOf(currentColorAsStringArray[0]);
int green = Integer.valueOf(currentColorAsStringArray[1]); int green = Integer.valueOf(currentColorAsStringArray[1]);
@ -373,11 +434,12 @@ public class ConfigWindow extends TWindow {
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
Color selectedColor = colorChooser.getSelectionModel() Color selectedColor = colorChooser.getSelectionModel()
.getSelectedColor(); .getSelectedColor();
selectedColor = JColorChooser.showDialog(null, "Choose a color", color); selectedColor = JColorChooser
.showDialog(null, "Choose a color", color);
if (selectedColor != null) { if (selectedColor != null) {
colorChooser.setColor(selectedColor); colorChooser.setColor(selectedColor);
((StringProperty) timeCalcConfiguration timeCalcConfiguration
.getProperty(timeCalcProperty)) .getProperty(timeCalcProperty)
.setValue( .setValue(
selectedColor.getRed() + "," selectedColor.getRed() + ","
+ selectedColor.getGreen() + "," + selectedColor.getGreen() + ","
@ -411,23 +473,29 @@ public class ConfigWindow extends TWindow {
JTextField jTextField = ((JTextField) p); JTextField jTextField = ((JTextField) p);
jTextField.setMaximumSize(new Dimension(150, 25)); jTextField.setMaximumSize(new Dimension(150, 25));
String timeCalcPropertyKey = (String) jTextField.getClientProperty( String timeCalcPropertyKey =
CLIENT_PROPERTY_KEY); (String) jTextField.getClientProperty(
CLIENT_PROPERTY_KEY);
TimeCalcProperty timeCalcProperty TimeCalcProperty timeCalcProperty
= TimeCalcProperty.forKey(timeCalcPropertyKey); = TimeCalcProperty.forKey(timeCalcPropertyKey);
jTextField.setText((String) timeCalcConfiguration.getProperty(timeCalcProperty).getValue()); jTextField.setText((String) timeCalcConfiguration
.getProperty(timeCalcProperty).getValue());
jTextField.getDocument().addDocumentListener(new DocumentListener() { jTextField.getDocument()
public void changedUpdate(DocumentEvent e) { .addDocumentListener(new DocumentListener() {
} public void changedUpdate(DocumentEvent e) {
public void removeUpdate(DocumentEvent e) { }
}
public void insertUpdate(DocumentEvent e) { public void removeUpdate(DocumentEvent e) {
((StringProperty) timeCalcConfiguration.getProperty(timeCalcProperty)) }
.setValue(
(String) jTextField.getText()); public void insertUpdate(DocumentEvent e) {
} timeCalcConfiguration
}); .getProperty(timeCalcProperty)
.setValue(
jTextField.getText());
}
});
} }
propertiesMap.put(TimeCalcProperty.forKey( propertiesMap.put(TimeCalcProperty.forKey(
@ -437,39 +505,39 @@ public class ConfigWindow extends TWindow {
Arrays.stream(getComponents()).forEach(c -> c.getClass().getName()); Arrays.stream(getComponents()).forEach(c -> c.getClass().getName());
ConfigWindow configWindow = this; ConfigWindow configWindow = this;
// class ConfigThread implements Runnable { // class ConfigThread implements Runnable {
// public final AtomicBoolean stopped = new AtomicBoolean(); // public final AtomicBoolean stopped = new AtomicBoolean();
// //
// public void run() { // public void run() {
// while (true) { // while (true) {
// if (stopped.get()) { // if (stopped.get()) {
// System.out.println("stopping thread"); // System.out.println("stopping thread");
// break; // break;
// } // }
// if (!configWindow.visibilitySupportedColoredProperty // if (!configWindow.visibilitySupportedColoredProperty
// .isSelected() // .isSelected()
// && configWindow.visibilityDefaultProperty.isEnabled()) { // && configWindow.visibilityDefaultProperty.isEnabled()) {
// configWindow.visibilityDefaultProperty.disable(); // configWindow.visibilityDefaultProperty.disable();
// } // }
// if (configWindow.visibilitySupportedColoredProperty // if (configWindow.visibilitySupportedColoredProperty
// .isSelected() // .isSelected()
// && !configWindow.visibilityDefaultProperty // && !configWindow.visibilityDefaultProperty
// .isEnabled()) { // .isEnabled()) {
// configWindow.visibilityDefaultProperty.enable(); // configWindow.visibilityDefaultProperty.enable();
// } // }
// } // }
// try { // try {
// Thread.sleep(100); // Thread.sleep(100);
// } catch (InterruptedException e) { // } catch (InterruptedException e) {
// e.printStackTrace(); // e.printStackTrace();
// System.out.println(e); // System.out.println(e);
// } // }
// } // }
// } // }
// ConfigThread configThread = new ConfigThread(); // ConfigThread configThread = new ConfigThread();
// Thread thread = new Thread(configThread); // Thread thread = new Thread(configThread);
// //
// thread.start(); // thread.start();
addWindowListener(new WindowAdapter() { addWindowListener(new WindowAdapter() {
@Override @Override
@ -483,8 +551,6 @@ public class ConfigWindow extends TWindow {
} }
}); });
} }
private static final Font BIG_FONT = new Font("sans", Font.BOLD, 24);
private static final String FIVE_SPACES = " ";
private void addToNextRow(JComponent jComponent) { private void addToNextRow(JComponent jComponent) {
panelInsideScrollPane.add(jComponent); panelInsideScrollPane.add(jComponent);
@ -501,6 +567,7 @@ public class ConfigWindow extends TWindow {
public void doEnableEverything() { public void doEnableEverything() {
this.enableAsMuchAsPossible.doClick(); this.enableAsMuchAsPossible.doClick();
} }
public void doDisableAlmostEverything() { public void doDisableAlmostEverything() {
this.disableAsMuchAsPossible.doClick(); this.disableAsMuchAsPossible.doClick();
} }

View File

@ -29,10 +29,13 @@ public class HelpWindow extends TWindow {
return; return;
} }
helpHtml = "<div style=\"font-family:sans;margin-bottom:20px;\">" + helpHtml + "</div>"; helpHtml = "<div style=\"font-family:sans;margin-bottom:20px;\">"
+ helpHtml + "</div>";
this.setLayout(null); this.setLayout(null);
JScrollPane scrollPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); JScrollPane scrollPane =
new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setBounds(1, 1, scrollPane.setBounds(1, 1,
getWidth() - 2 * SwingUtils.MARGIN, getWidth() - 2 * SwingUtils.MARGIN,
getHeight() - 4 * SwingUtils.MARGIN); getHeight() - 4 * SwingUtils.MARGIN);

View File

@ -50,6 +50,7 @@ public class MainWindow extends TWindow {
public static final Color BACKGROUND_COLOR = new Color(238, 238, 238); public static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
public static final Color FOREGROUND_COLOR = new Color(210, 210, 210); public static final Color FOREGROUND_COLOR = new Color(210, 210, 210);
public static final JCheckBox hideShowCheckBox = new JCheckBox();
private final TButton workDaysButton; private final TButton workDaysButton;
private final TButton activitiesButton; private final TButton activitiesButton;
private final TButton exitButton; private final TButton exitButton;
@ -61,15 +62,13 @@ public class MainWindow extends TWindow {
private final TButton commandButton; private final TButton commandButton;
private final TButton jokeButton; private final TButton jokeButton;
private final AboutButton aboutButton; private final AboutButton aboutButton;
public static final JCheckBox hideShowCheckBox = new JCheckBox(); private final TimeCalcConfiguration timeCalcConfiguration
= new TimeCalcConfiguration();
private HelpWindow helpWindow = null; private HelpWindow helpWindow = null;
private ConfigWindow configWindow = null; private ConfigWindow configWindow = null;
private ActivitiesWindow activitiesWindow = null; private ActivitiesWindow activitiesWindow = null;
private WorkDaysWindow workDaysWindow = null; private WorkDaysWindow workDaysWindow = null;
private boolean stopBeforeEnd = false; private boolean stopBeforeEnd = false;
private final TimeCalcConfiguration timeCalcConfiguration
= new TimeCalcConfiguration();
public MainWindow(String startTimeIn, String overTimeIn, public MainWindow(String startTimeIn, String overTimeIn,
TimeCalcApp timeCalcApp) { TimeCalcApp timeCalcApp) {
@ -96,7 +95,7 @@ public class MainWindow extends TWindow {
TimeHM endTime = new TimeHM( TimeHM endTime = new TimeHM(
startTime.getHour() + Constants.WORKING_HOURS_LENGTH + overtime startTime.getHour() + Constants.WORKING_HOURS_LENGTH + overtime
.getHour(), .getHour(),
startTime.getMinute() + Constants.WORKING_MINUTES_LENGTH startTime.getMinute() + Constants.WORKING_MINUTES_LENGTH
+ overtime.getMinute()); + overtime.getMinute());
@ -107,7 +106,7 @@ public class MainWindow extends TWindow {
this.configButton = new TButton("Config"); this.configButton = new TButton("Config");
this.workDaysButton = new TButton("Work Days"); this.workDaysButton = new TButton("Work Days");
this.activitiesButton = new TButton("Activities" this.activitiesButton = new TButton("Activities"
+ ""); + "");
this.restartButton = new TButton("Restart"); this.restartButton = new TButton("Restart");
this.exitButton = new TButton("Exit"); this.exitButton = new TButton("Exit");
this.focusButton = new TButton("Focus"); this.focusButton = new TButton("Focus");
@ -119,13 +118,18 @@ public class MainWindow extends TWindow {
//window.add(weatherButton); //window.add(weatherButton);
addAll(configButton, workDaysButton, activitiesButton, restartButton, addAll(configButton, workDaysButton, activitiesButton, restartButton,
exitButton, focusButton, helpButton, commandButton, jokeButton, hideShowCheckBox); exitButton, focusButton, helpButton, commandButton, jokeButton,
hideShowCheckBox);
timeCalcApp.visibilityProperty.bindTo(timeCalcConfiguration.visibilityDefaultProperty); timeCalcApp.visibilityProperty
if (!timeCalcConfiguration.visibilitySupportedColoredProperty.isEnabled()) { .bindTo(timeCalcConfiguration.visibilityDefaultProperty);
if (!timeCalcConfiguration.visibilitySupportedColoredProperty
.isEnabled()) {
timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name()); timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name());
} }
TimeCalcKeyAdapter timeCalcKeyAdapter = new TimeCalcKeyAdapter(timeCalcConfiguration, timeCalcApp, this); TimeCalcKeyAdapter timeCalcKeyAdapter =
new TimeCalcKeyAdapter(timeCalcConfiguration, timeCalcApp,
this);
addKeyListener(timeCalcKeyAdapter); addKeyListener(timeCalcKeyAdapter);
AnalogClock analogClock = new AnalogClock(startTime, endTime); AnalogClock analogClock = new AnalogClock(startTime, endTime);
@ -134,23 +138,30 @@ public class MainWindow extends TWindow {
ProgressSquare progressSquare = new ProgressSquare(); ProgressSquare progressSquare = new ProgressSquare();
progressSquare progressSquare
.setBounds(analogClock.getX() + analogClock.getWidth() + SwingUtils.MARGIN, analogClock.getY(), .setBounds(analogClock.getX() + analogClock.getWidth()
+ SwingUtils.MARGIN, analogClock.getY(),
200); 200);
add(progressSquare); add(progressSquare);
progressSquare.visibleProperty.bindTo(timeCalcConfiguration.squareVisibleProperty); progressSquare.visibleProperty
.bindTo(timeCalcConfiguration.squareVisibleProperty);
ProgressCircle progressCircle = new ProgressCircle(); ProgressCircle progressCircle = new ProgressCircle();
progressCircle progressCircle
.setBounds( .setBounds(
progressSquare.getX() + progressSquare.getWidth() + SwingUtils.MARGIN, progressSquare.getY(), 80); progressSquare.getX() + progressSquare.getWidth()
+ SwingUtils.MARGIN, progressSquare.getY(), 80);
add(progressCircle); add(progressCircle);
progressCircle.visibleProperty.bindTo(timeCalcConfiguration.circleVisibleProperty); progressCircle.visibleProperty
.bindTo(timeCalcConfiguration.circleVisibleProperty);
WalkingHumanProgress walkingHumanProgress WalkingHumanProgress walkingHumanProgress
= new WalkingHumanProgress(); = new WalkingHumanProgress();
walkingHumanProgress.setBounds(analogClock.getX(), analogClock.getY() + analogClock.getHeight() + SwingUtils.MARGIN, 420, 180); walkingHumanProgress.setBounds(analogClock.getX(),
analogClock.getY() + analogClock.getHeight()
+ SwingUtils.MARGIN, 420, 180);
add(walkingHumanProgress); add(walkingHumanProgress);
walkingHumanProgress.visibleProperty.bindTo(timeCalcConfiguration.walkingHumanVisibleProperty); walkingHumanProgress.visibleProperty
.bindTo(timeCalcConfiguration.walkingHumanVisibleProperty);
weatherButton weatherButton
.setBounds(SwingUtils.MARGIN, walkingHumanProgress.getY() .setBounds(SwingUtils.MARGIN, walkingHumanProgress.getY()
@ -169,7 +180,9 @@ public class MainWindow extends TWindow {
commandButton.setBoundsFromLeft(focusButton); commandButton.setBoundsFromLeft(focusButton);
jokeButton.setBoundsFromLeft(commandButton); jokeButton.setBoundsFromLeft(commandButton);
hideShowCheckBox.setSelected(true); hideShowCheckBox.setSelected(true);
hideShowCheckBox.setBounds(jokeButton.getX() + jokeButton.getWidth() + SwingUtils.MARGIN, jokeButton.getY(), 20, 20); hideShowCheckBox.setBounds(
jokeButton.getX() + jokeButton.getWidth() + SwingUtils.MARGIN,
jokeButton.getY(), 20, 20);
// //
aboutButton.setBounds(exitButton.getX(), aboutButton.setBounds(exitButton.getX(),
exitButton.getY() + exitButton.getHeight() + SwingUtils.MARGIN); exitButton.getY() + exitButton.getHeight() + SwingUtils.MARGIN);
@ -181,7 +194,8 @@ public class MainWindow extends TWindow {
weatherButton weatherButton
.addActionListener(e -> new WeatherWindow().setVisible(true)); .addActionListener(e -> new WeatherWindow().setVisible(true));
commandButton.addActionListener(new CommandActionListener(timeCalcApp, timeCalcConfiguration)); commandButton.addActionListener(
new CommandActionListener(timeCalcApp, timeCalcConfiguration));
jokeButton.addActionListener(e -> { jokeButton.addActionListener(e -> {
for (int i = 1; i <= 1; i++) { for (int i = 1; i <= 1; i++) {
@ -246,17 +260,28 @@ public class MainWindow extends TWindow {
Time time = new Time(); Time time = new Time();
bindToIfPropertyMissing(testProperties, "test.current.day", calNow, Calendar.DAY_OF_MONTH, analogClock.dayProperty, time.dayProperty); bindToIfPropertyMissing(testProperties, "test.current.day", calNow,
bindToIfPropertyMissing(testProperties, "test.current.month", calNow, Calendar.MONTH, analogClock.monthProperty, time.monthProperty); Calendar.DAY_OF_MONTH, analogClock.dayProperty,
bindToIfPropertyMissing(testProperties, "test.current.year", calNow, Calendar.YEAR, analogClock.yearProperty, time.yearProperty); time.dayProperty);
bindToIfPropertyMissing(testProperties, "test.current.hour", calNow, Calendar.HOUR, analogClock.hourProperty, time.hourProperty); bindToIfPropertyMissing(testProperties, "test.current.month", calNow,
bindToIfPropertyMissing(testProperties, "test.current.minute", calNow, Calendar.MINUTE, analogClock.minuteProperty, time.minuteProperty); Calendar.MONTH, analogClock.monthProperty, time.monthProperty);
bindToIfPropertyMissing(testProperties, "test.current.second", calNow, Calendar.SECOND, analogClock.secondProperty, time.secondProperty); bindToIfPropertyMissing(testProperties, "test.current.year", calNow,
bindToIfPropertyMissing(testProperties, "test.current.millisecond", calNow, Calendar.MILLISECOND, analogClock.millisecondProperty, time.millisecondProperty); Calendar.YEAR, analogClock.yearProperty, time.yearProperty);
bindToIfPropertyMissing(testProperties, "test.current.hour", calNow,
Calendar.HOUR, analogClock.hourProperty, time.hourProperty);
bindToIfPropertyMissing(testProperties, "test.current.minute", calNow,
Calendar.MINUTE, analogClock.minuteProperty,
time.minuteProperty);
bindToIfPropertyMissing(testProperties, "test.current.second", calNow,
Calendar.SECOND, analogClock.secondProperty,
time.secondProperty);
bindToIfPropertyMissing(testProperties, "test.current.millisecond",
calNow, Calendar.MILLISECOND, analogClock.millisecondProperty,
time.millisecondProperty);
if (testProperties.containsKey("test.current.year") || testProperties if (testProperties.containsKey("test.current.year") || testProperties
.containsKey("test.current.month") || testProperties .containsKey("test.current.month") || testProperties
.containsKey("test.current.day")) { .containsKey("test.current.day")) {
analogClock.dayOfWeekProperty analogClock.dayOfWeekProperty
.setValue(calNow.get(Calendar.DAY_OF_WEEK)); .setValue(calNow.get(Calendar.DAY_OF_WEEK));
} else { } else {
@ -273,35 +298,54 @@ public class MainWindow extends TWindow {
.bindTo(timeCalcConfiguration.clockHandsHourVisibleProperty); .bindTo(timeCalcConfiguration.clockHandsHourVisibleProperty);
analogClock.handsLongProperty analogClock.handsLongProperty
.bindTo(timeCalcConfiguration.clockHandsLongVisibleProperty); .bindTo(timeCalcConfiguration.clockHandsLongVisibleProperty);
analogClock.borderVisibleProperty.bindTo(timeCalcConfiguration.clockBorderVisibleProperty); analogClock.borderVisibleProperty
analogClock.borderOnlyHoursProperty.bindTo(timeCalcConfiguration.clockBorderOnlyHoursProperty); .bindTo(timeCalcConfiguration.clockBorderVisibleProperty);
analogClock.numbersVisibleProperty.bindTo(timeCalcConfiguration.clockNumbersVisibleProperty); analogClock.borderOnlyHoursProperty
analogClock.circleVisibleProperty.bindTo(timeCalcConfiguration.clockCircleVisibleProperty); .bindTo(timeCalcConfiguration.clockBorderOnlyHoursProperty);
analogClock.circleStrongBorderProperty.bindTo(timeCalcConfiguration.clockCircleStrongBorderProperty); analogClock.numbersVisibleProperty
analogClock.centreCircleVisibleProperty.bindTo(timeCalcConfiguration.clockCentreCircleVisibleProperty); .bindTo(timeCalcConfiguration.clockNumbersVisibleProperty);
analogClock.centreCircleBorderColorProperty.bindTo(timeCalcConfiguration.clockCircleBorderColorProperty); analogClock.circleVisibleProperty
analogClock.handsColoredProperty.bindTo(timeCalcConfiguration.clockHandsColoredProperty); .bindTo(timeCalcConfiguration.clockCircleVisibleProperty);
analogClock.centreCircleBlackProperty.bindTo(timeCalcConfiguration.clockCentreCircleBlackProperty); analogClock.circleStrongBorderProperty
analogClock.progressVisibleOnlyIfMouseMovingOverProperty.bindTo(timeCalcConfiguration.clockProgressVisibleOnlyIfMouseMovingOverProperty); .bindTo(timeCalcConfiguration.clockCircleStrongBorderProperty);
analogClock.dateVisibleOnlyIfMouseMovingOverProperty.bindTo(timeCalcConfiguration.clockDateVisibleOnlyIfMouseMovingOverProperty); analogClock.centreCircleVisibleProperty
analogClock.visibleProperty.bindTo(timeCalcConfiguration.clockVisibleProperty); .bindTo(timeCalcConfiguration.clockCentreCircleVisibleProperty);
analogClock.centreCircleBorderColorProperty
.bindTo(timeCalcConfiguration.clockCircleBorderColorProperty);
analogClock.handsColoredProperty
.bindTo(timeCalcConfiguration.clockHandsColoredProperty);
analogClock.centreCircleBlackProperty
.bindTo(timeCalcConfiguration.clockCentreCircleBlackProperty);
analogClock.progressVisibleOnlyIfMouseMovingOverProperty
.bindTo(timeCalcConfiguration.clockProgressVisibleOnlyIfMouseMovingOverProperty);
analogClock.dateVisibleOnlyIfMouseMovingOverProperty
.bindTo(timeCalcConfiguration.clockDateVisibleOnlyIfMouseMovingOverProperty);
analogClock.visibleProperty
.bindTo(timeCalcConfiguration.clockVisibleProperty);
MinuteBattery minuteBattery = new MinuteBattery(progressCircle.getBounds().x, MinuteBattery minuteBattery =
progressCircle.getY() + SwingUtils.MARGIN + progressCircle.getHeight(), 140); new MinuteBattery(progressCircle.getBounds().x,
progressCircle.getY() + SwingUtils.MARGIN
+ progressCircle.getHeight(), 140);
add(minuteBattery); add(minuteBattery);
Battery hourBattery = new HourBattery(minuteBattery.getBounds().x + minuteBattery.getWidth() + SwingUtils.MARGIN, Battery hourBattery = new HourBattery(
minuteBattery.getBounds().x + minuteBattery.getWidth()
+ SwingUtils.MARGIN,
minuteBattery.getY(), minuteBattery.getY(),
140); 140);
add(hourBattery); add(hourBattery);
Battery dayBattery = new DayBattery(hourBattery.getBounds().x + hourBattery.getWidth() + SwingUtils.MARGIN, Battery dayBattery = new DayBattery(
hourBattery.getBounds().x + hourBattery.getWidth()
+ SwingUtils.MARGIN,
hourBattery.getY(), hourBattery.getY(),
140); 140);
add(dayBattery); add(dayBattery);
Battery weekBattery = new WeekBattery( Battery weekBattery = new WeekBattery(
minuteBattery.getBounds().x, minuteBattery.getBounds().x,
dayBattery.getY() + dayBattery.getHeight() + SwingUtils.MARGIN, 140); dayBattery.getY() + dayBattery.getHeight() + SwingUtils.MARGIN,
140);
add(weekBattery); add(weekBattery);
int currentDayOfMonth = analogClock.dayProperty.getValue(); int currentDayOfMonth = analogClock.dayProperty.getValue();
@ -310,10 +354,12 @@ public class MainWindow extends TWindow {
int workDaysTodo = 0; int workDaysTodo = 0;
int workDaysTotal; int workDaysTotal;
for (int dayOfMonth = 1; for (int dayOfMonth = 1;
dayOfMonth <= calNow.getActualMaximum(Calendar.DAY_OF_MONTH); dayOfMonth <= calNow.getActualMaximum(Calendar.DAY_OF_MONTH);
dayOfMonth++) { dayOfMonth++) {
DayOfWeek dayOfWeek = LocalDate.of(analogClock.yearProperty.getValue(), DayOfWeek dayOfWeek =
analogClock.monthProperty.getValue(), dayOfMonth).getDayOfWeek(); LocalDate.of(analogClock.yearProperty.getValue(),
analogClock.monthProperty.getValue(), dayOfMonth)
.getDayOfWeek();
boolean weekend boolean weekend
= dayOfWeek.toString().equals("SATURDAY") || dayOfWeek = dayOfWeek.toString().equals("SATURDAY") || dayOfWeek
.toString().equals("SUNDAY"); .toString().equals("SUNDAY");
@ -328,75 +374,114 @@ public class MainWindow extends TWindow {
.of(calNow.get(Calendar.YEAR), calNow.get(Calendar.MONTH) + 1, .of(calNow.get(Calendar.YEAR), calNow.get(Calendar.MONTH) + 1,
currentDayOfMonth).getDayOfWeek().toString(); currentDayOfMonth).getDayOfWeek().toString();
boolean nowIsWeekend = currentDayOfWeekAsString.equals("SATURDAY") boolean nowIsWeekend = currentDayOfWeekAsString.equals("SATURDAY")
|| currentDayOfWeekAsString.equals("SUNDAY"); || currentDayOfWeekAsString.equals("SUNDAY");
workDaysTotal = workDaysDone + (nowIsWeekend ? 0 : 1) + workDaysTodo; workDaysTotal = workDaysDone + (nowIsWeekend ? 0 : 1) + workDaysTodo;
Battery monthBattery = new MonthBattery( Battery monthBattery = new MonthBattery(
weekBattery.getBounds().x + weekBattery.getWidth() + SwingUtils.MARGIN, weekBattery.getBounds().x + weekBattery.getWidth()
+ SwingUtils.MARGIN,
weekBattery.getY(), 140); weekBattery.getY(), 140);
add(monthBattery); add(monthBattery);
Battery yearBattery = new YearBattery( Battery yearBattery = new YearBattery(
monthBattery.getBounds().x + monthBattery.getWidth() + SwingUtils.MARGIN, monthBattery.getBounds().x + monthBattery.getWidth()
+ SwingUtils.MARGIN,
monthBattery.getY(), 140); monthBattery.getY(), 140);
add(yearBattery); add(yearBattery);
ComponentRegistry<Component> componentRegistry = new ComponentRegistry(); ComponentRegistry<Component> componentRegistry =
new ComponentRegistry();
componentRegistry.addAll(this.getContentPane().getComponents()); componentRegistry.addAll(this.getContentPane().getComponents());
ComponentRegistry<TButton> buttonRegistry = new ComponentRegistry(); ComponentRegistry<TButton> buttonRegistry = new ComponentRegistry();
componentRegistry.getSet().stream().filter(c -> c instanceof TButton).forEach(c componentRegistry.getSet().stream().filter(c -> c instanceof TButton)
-> { .forEach(c
buttonRegistry.add((TButton) c); -> {
buttonRegistry.add((TButton) c);
}); });
// commandButton.visibleProperty.bindTo(timeCalcConfiguration.commandsVisibleProperty); // commandButton.visibleProperty.bindTo(timeCalcConfiguration.commandsVisibleProperty);
// jokeButton.visibleProperty.bindTo(timeCalcConfiguration.jokesVisibleProperty); // jokeButton.visibleProperty.bindTo(timeCalcConfiguration.jokesVisibleProperty);
componentRegistry.getSet().stream().filter(c componentRegistry.getSet().stream().filter(c
-> GetProperty.class.isAssignableFrom(c.getClass())).forEach(c -> GetProperty.class.isAssignableFrom(c.getClass())).forEach(c
-> { -> {
((GetProperty) c).getVisibilityProperty().bindTo(timeCalcApp.visibilityProperty); ((GetProperty) c).getVisibilityProperty()
((GetProperty) c).getVisibilitySupportedColoredProperty().bindTo(timeCalcConfiguration.visibilitySupportedColoredProperty); .bindTo(timeCalcApp.visibilityProperty);
((GetProperty) c).getVisibilitySupportedColoredProperty()
.bindTo(timeCalcConfiguration.visibilitySupportedColoredProperty);
}); });
componentRegistry.getSet().stream().filter(c -> c instanceof Battery).forEach(c componentRegistry.getSet().stream().filter(c -> c instanceof Battery)
-> { .forEach(c
Battery battery = ((Battery) c); -> {
battery.wavesVisibleProperty.bindTo(timeCalcConfiguration.batteryWavesVisibleProperty); Battery battery = ((Battery) c);
battery.circleProgressVisibleProperty.bindTo(timeCalcConfiguration.batteryCircleProgressProperty); battery.wavesVisibleProperty
battery.percentProgressVisibleProperty.bindTo(timeCalcConfiguration.batteryPercentProgressProperty); .bindTo(timeCalcConfiguration.batteryWavesVisibleProperty);
battery.chargingCharacterVisibleProperty.bindTo(timeCalcConfiguration.batteryChargingCharacterVisibleProperty); battery.circleProgressVisibleProperty
battery.nameVisibleProperty.bindTo(timeCalcConfiguration.batteryNameVisibleProperty); .bindTo(timeCalcConfiguration.batteryCircleProgressProperty);
battery.labelVisibleProperty.bindTo(timeCalcConfiguration.batteryLabelVisibleProperty); battery.percentProgressVisibleProperty
battery.blinkingIfCriticalLowVisibleProperty.bindTo(timeCalcConfiguration.batteryBlinkingIfCriticalLowVisibleProperty); .bindTo(timeCalcConfiguration.batteryPercentProgressProperty);
switch(battery.getName()) { battery.chargingCharacterVisibleProperty
case MinuteBattery.MINUTE : battery.visibleProperty.bindTo(timeCalcConfiguration.batteryMinuteVisibleProperty);break; .bindTo(timeCalcConfiguration.batteryChargingCharacterVisibleProperty);
case HourBattery.HOUR : battery.visibleProperty.bindTo(timeCalcConfiguration.batteryHourVisibleProperty);break; battery.nameVisibleProperty
case DayBattery.DAY : battery.visibleProperty.bindTo(timeCalcConfiguration.batteryDayVisibleProperty);break; .bindTo(timeCalcConfiguration.batteryNameVisibleProperty);
case WeekBattery.WEEK : battery.visibleProperty.bindTo(timeCalcConfiguration.batteryWeekVisibleProperty);break; battery.labelVisibleProperty
case MonthBattery.MONTH : battery.visibleProperty.bindTo(timeCalcConfiguration.batteryMonthVisibleProperty);break; .bindTo(timeCalcConfiguration.batteryLabelVisibleProperty);
case YearBattery.YEAR : battery.visibleProperty.bindTo(timeCalcConfiguration.batteryYearVisibleProperty);break; battery.blinkingIfCriticalLowVisibleProperty
default: {} .bindTo(timeCalcConfiguration.batteryBlinkingIfCriticalLowVisibleProperty);
}; switch (battery.getName()) {
}); case MinuteBattery.MINUTE:
battery.visibleProperty
.bindTo(timeCalcConfiguration.batteryMinuteVisibleProperty);
break;
case HourBattery.HOUR:
battery.visibleProperty
.bindTo(timeCalcConfiguration.batteryHourVisibleProperty);
break;
case DayBattery.DAY:
battery.visibleProperty
.bindTo(timeCalcConfiguration.batteryDayVisibleProperty);
break;
case WeekBattery.WEEK:
battery.visibleProperty
.bindTo(timeCalcConfiguration.batteryWeekVisibleProperty);
break;
case MonthBattery.MONTH:
battery.visibleProperty
.bindTo(timeCalcConfiguration.batteryMonthVisibleProperty);
break;
case YearBattery.YEAR:
battery.visibleProperty
.bindTo(timeCalcConfiguration.batteryYearVisibleProperty);
break;
default: {
}
}
});
componentRegistry.getSet().stream().filter(c -> c instanceof Widget)
componentRegistry.getSet().stream().filter(c -> c instanceof Widget).forEach(c .forEach(c
-> { -> {
Widget widget = (Widget) c; Widget widget = (Widget) c;
widget.smileysVisibleProperty.bindTo(timeCalcConfiguration.smileysVisibleProperty); widget.smileysVisibleProperty
widget.smileysVisibleOnlyIfMouseMovingOverProperty.bindTo(timeCalcConfiguration.smileysVisibleOnlyIfMouseMovingOverProperty); .bindTo(timeCalcConfiguration.smileysVisibleProperty);
widget.smileysColoredProperty.bindTo(timeCalcConfiguration.smileysColoredProperty); widget.smileysVisibleOnlyIfMouseMovingOverProperty
} .bindTo(timeCalcConfiguration.smileysVisibleOnlyIfMouseMovingOverProperty);
); widget.smileysColoredProperty
setSize(dayBattery.getX() + dayBattery.getWidth() + 3 * SwingUtils.MARGIN, .bindTo(timeCalcConfiguration.smileysColoredProperty);
focusButton.getY() + focusButton.getHeight() + SwingUtils.MARGIN + focusButton.getHeight() + 2 * SwingUtils.MARGIN); }
);
setSize(dayBattery.getX() + dayBattery.getWidth()
+ 3 * SwingUtils.MARGIN,
focusButton.getY() + focusButton.getHeight() + SwingUtils.MARGIN
+ focusButton.getHeight() + 2 * SwingUtils.MARGIN);
while (true) { while (true) {
//System.out.println("timeCalcConfiguration.handsLongProperty=" + timeCalcConfiguration.clockHandLongProperty.isEnabled()); //System.out.println("timeCalcConfiguration.handsLongProperty=" + timeCalcConfiguration.clockHandLongProperty.isEnabled());
Visibility currentVisibility = Visibility Visibility currentVisibility = Visibility
.valueOf(timeCalcApp.visibilityProperty.getValue()); .valueOf(timeCalcApp.visibilityProperty.getValue());
if (!timeCalcConfiguration.visibilitySupportedColoredProperty.isEnabled() && currentVisibility.isColored()) { if (!timeCalcConfiguration.visibilitySupportedColoredProperty
.isEnabled() && currentVisibility.isColored()) {
timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name()); timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name());
} }
if (stopBeforeEnd) { if (stopBeforeEnd) {
@ -424,14 +509,16 @@ public class MainWindow extends TWindow {
break; break;
} }
componentRegistry.setVisible(c -> (c instanceof Widget ? ((Widget)c).visibleProperty.isEnabled() componentRegistry.setVisible(c -> (!(c instanceof Widget)
: true) /*|| (c instanceof TButton ? ((Widget)c).visibleProperty.isEnabled() || ((Widget) c).visibleProperty
.isEnabled()) /*|| (c instanceof TButton ? ((Widget)c).visibleProperty.isEnabled()
: true)*/, currentVisibility.isNotNone()); : true)*/, currentVisibility.isNotNone());
jokeButton.setVisible( jokeButton.setVisible(
TimeCalcProperties.getInstance().getBooleanProperty( TimeCalcProperties.getInstance().getBooleanProperty(
TimeCalcProperty.JOKES_VISIBLE) TimeCalcProperty.JOKES_VISIBLE)
&& !currentVisibility.isNone() && MainWindow.hideShowCheckBox.isSelected()); && !currentVisibility.isNone()
&& MainWindow.hideShowCheckBox.isSelected());
setTitle(currentVisibility.isNone() ? "" : getWindowTitle()); setTitle(currentVisibility.isNone() ? "" : getWindowTitle());
@ -447,10 +534,10 @@ public class MainWindow extends TWindow {
int millisecondsRemains = 1000 - millisecondNow; int millisecondsRemains = 1000 - millisecondNow;
int hourDone = Constants.WORKING_HOURS_LENGTH + overtime.getHour() int hourDone = Constants.WORKING_HOURS_LENGTH + overtime.getHour()
- timeRemains.getHour(); - timeRemains.getHour();
int minutesDone int minutesDone
= Constants.WORKING_MINUTES_LENGTH + overtime.getMinute() = Constants.WORKING_MINUTES_LENGTH + overtime.getMinute()
- timeRemains.getMinute(); - timeRemains.getMinute();
int secondsDone = secondNow; int secondsDone = secondNow;
int millisecondsDone = millisecondNow; int millisecondsDone = millisecondNow;
@ -460,7 +547,7 @@ public class MainWindow extends TWindow {
= totalSecondsDone * 1000 + millisecondsDone; = totalSecondsDone * 1000 + millisecondsDone;
double done = ((double) totalMillisecondsDone) double done = ((double) totalMillisecondsDone)
/ ((double) totalMilliseconds); / ((double) totalMilliseconds);
progressSquare.setDonePercent(done); progressSquare.setDonePercent(done);
progressCircle.setDonePercent(done); progressCircle.setDonePercent(done);
dayBattery.setDonePercent(done); dayBattery.setDonePercent(done);
@ -486,14 +573,16 @@ public class MainWindow extends TWindow {
hourBattery.setLabel( hourBattery.setLabel(
hourDone + "/" + (totalMinutes / 60)); hourDone + "/" + (totalMinutes / 60));
} }
minuteBattery.setDonePercent(MinuteBattery.getMinuteProgress(secondNow, millisecondNow)); minuteBattery.setDonePercent(
yearBattery.setDonePercent(YearBattery.getYearProgress(analogClock)); MinuteBattery.getMinuteProgress(secondNow, millisecondNow));
yearBattery
.setDonePercent(YearBattery.getYearProgress(analogClock));
yearBattery.setLabel(""); yearBattery.setLabel("");
//yearBattery.setDonePercent(YearBattery.getYearProgress(2024,0,1,0,0,0,0)); //yearBattery.setDonePercent(YearBattery.getYearProgress(2024,0,1,0,0,0,0));
int totalSecondsRemains int totalSecondsRemains
= (timeRemains.getHour() * 60 * 60 = (timeRemains.getHour() * 60 * 60
+ timeRemains.getMinute() * 60 + timeRemains.getMinute() * 60
+ secondsRemains); + secondsRemains);
int totalMillisecondsRemains int totalMillisecondsRemains
= totalSecondsRemains * 1000 + millisecondsRemains; = totalSecondsRemains * 1000 + millisecondsRemains;
double totalSecondsRemainsDouble double totalSecondsRemainsDouble
@ -568,10 +657,13 @@ public class MainWindow extends TWindow {
} }
private void bindToIfPropertyMissing(Properties properties, String key, Calendar cal, int timeUnit, IntegerProperty firstProperty, Property secondProperty) { private void bindToIfPropertyMissing(Properties properties, String key,
Calendar cal, int timeUnit, IntegerProperty firstProperty,
Property secondProperty) {
if (properties.containsKey(key)) { if (properties.containsKey(key)) {
cal.set(timeUnit, Integer.parseInt( cal.set(timeUnit, Integer.parseInt(
(String) properties.get(key)) + (timeUnit == Calendar.MONTH ? -1 : 0)); (String) properties.get(key)) + (
timeUnit == Calendar.MONTH ? -1 : 0));
firstProperty.setValue(Integer.valueOf( firstProperty.setValue(Integer.valueOf(
(String) properties.get(key))); (String) properties.get(key)));
} else { } else {
@ -608,16 +700,17 @@ public class MainWindow extends TWindow {
} }
public void doEnableEverything() { public void doEnableEverything() {
if(this.configWindow == null) { if (this.configWindow == null) {
openConfigWindow(); openConfigWindow();
this.configWindow.setVisible(false); this.configWindow.setVisible(false);
} }
this.configWindow.doEnableEverything(); this.configWindow.doEnableEverything();
} }
public void doDisableAlmostEverything() { public void doDisableAlmostEverything() {
if(this.configWindow == null) { if (this.configWindow == null) {
openConfigWindow(); openConfigWindow();
this.configWindow.setVisible(false); this.configWindow.setVisible(false);
} }

View File

@ -5,6 +5,7 @@ import java.awt.Color;
import java.awt.Font; import java.awt.Font;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import static org.nanoboot.utils.timecalc.swing.common.Widget.CLOSE_BUTTON_SIDE; import static org.nanoboot.utils.timecalc.swing.common.Widget.CLOSE_BUTTON_SIDE;
/** /**
@ -13,24 +14,32 @@ import static org.nanoboot.utils.timecalc.swing.common.Widget.CLOSE_BUTTON_SIDE;
*/ */
public class SwingUtils { public class SwingUtils {
public static void paintCloseIcon(Graphics brush, int width) { public static final int MARGIN = 10;
brush.setColor(SwingUtils.CLOSE_BUTTON_BACKGROUND_COLOR); public static final Color CLOSE_BUTTON_BACKGROUND_COLOR =
brush.fillOval(width- CLOSE_BUTTON_SIDE - 1, 0 + 1, CLOSE_BUTTON_SIDE, CLOSE_BUTTON_SIDE); new Color(127, 127, 127);
brush.setColor(Color.LIGHT_GRAY); public static final Font SMALL_FONT = new Font("sans", Font.BOLD, 10);
Graphics2D brush2d = (Graphics2D) brush; public static final Font MEDIUM_MONOSPACE_FONT =
brush2d.setStroke(new BasicStroke(2f)); new Font(Font.MONOSPACED, Font.PLAIN, 12);
brush.drawLine(width - CLOSE_BUTTON_SIDE - 1 + 2, 0 + 1 + 2, width - 0 * CLOSE_BUTTON_SIDE - 1 - 2, 0 + CLOSE_BUTTON_SIDE + 1 - 2);
brush.drawLine(width - CLOSE_BUTTON_SIDE - 1 + 2, 0 + CLOSE_BUTTON_SIDE + 1 - 2, width - 0 * CLOSE_BUTTON_SIDE - 1 - 2, 0 + 1 + 2);
}
private SwingUtils() { private SwingUtils() {
//Not meant to be instantiated. //Not meant to be instantiated.
} }
public static final int MARGIN = 10;
public static final Color CLOSE_BUTTON_BACKGROUND_COLOR = new Color(127, 127, 127);
public static final Font SMALL_FONT = new Font("sans", Font.BOLD, 10); public static void paintCloseIcon(Graphics brush, int width) {
public static final Font MEDIUM_MONOSPACE_FONT = new Font(Font.MONOSPACED, Font.PLAIN, 12); brush.setColor(SwingUtils.CLOSE_BUTTON_BACKGROUND_COLOR);
brush.fillOval(width - CLOSE_BUTTON_SIDE - 1, 0 + 1, CLOSE_BUTTON_SIDE,
CLOSE_BUTTON_SIDE);
brush.setColor(Color.LIGHT_GRAY);
Graphics2D brush2d = (Graphics2D) brush;
brush2d.setStroke(new BasicStroke(2f));
brush.drawLine(width - CLOSE_BUTTON_SIDE - 1 + 2, 0 + 1 + 2,
width - 0 * CLOSE_BUTTON_SIDE - 1 - 2,
0 + CLOSE_BUTTON_SIDE + 1 - 2);
brush.drawLine(width - CLOSE_BUTTON_SIDE - 1 + 2,
0 + CLOSE_BUTTON_SIDE + 1 - 2,
width - 0 * CLOSE_BUTTON_SIDE - 1 - 2, 0 + 1 + 2);
}
public static final Color getColorFromString(String s) { public static final Color getColorFromString(String s) {
if (s.isEmpty()) { if (s.isEmpty()) {
System.out.println("error: empty string for color"); System.out.println("error: empty string for color");

View File

@ -19,22 +19,20 @@ public class TButton extends JButton implements GetProperty {
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());
public final BooleanProperty visibilitySupportedColoredProperty public final BooleanProperty visibilitySupportedColoredProperty
= new BooleanProperty("visibilitySupportedColoredProperty", true); = new BooleanProperty("visibilitySupportedColoredProperty", true);
private Color originalBackground;
private Color originalForeground;
public final BooleanProperty visibleProperty public final BooleanProperty visibleProperty
= new BooleanProperty("visibleProperty", true); = new BooleanProperty("visibleProperty", true);
public StringProperty visibilityProperty
= new StringProperty("visibilityProperty",
Visibility.STRONGLY_COLORED.name());
private Color originalBackground;
private Color originalForeground;
public TButton(String label) { public TButton(String label) {
super(label); super(label);
new Timer(100, e -> { new Timer(100, e -> {
if(!MainWindow.hideShowCheckBox.isSelected()) { if (!MainWindow.hideShowCheckBox.isSelected()) {
setVisible(false); setVisible(false);
return; return;
} else { } else {
@ -68,7 +66,8 @@ public class TButton extends JButton implements GetProperty {
} }
public void setBoundsFromLeft(JComponent jComponent) { public void setBoundsFromLeft(JComponent jComponent) {
setBounds(jComponent.getX() + jComponent.getWidth() + SwingUtils.MARGIN, jComponent.getY()); setBounds(jComponent.getX() + jComponent.getWidth() + SwingUtils.MARGIN,
jComponent.getY());
} }
public void setBoundsFromTop(JComponent jComponent) { public void setBoundsFromTop(JComponent jComponent) {
@ -77,8 +76,8 @@ public class TButton extends JButton implements GetProperty {
public void setBoundsFromTop(JComponent jComponent, int marginCount) { public void setBoundsFromTop(JComponent jComponent, int marginCount) {
setBounds(SwingUtils.MARGIN, jComponent.getY() setBounds(SwingUtils.MARGIN, jComponent.getY()
+ jComponent.getHeight() + jComponent.getHeight()
+ marginCount * SwingUtils.MARGIN); + marginCount * SwingUtils.MARGIN);
} }
@Override @Override
@ -92,6 +91,7 @@ public class TButton extends JButton implements GetProperty {
} }
void addActionListener() { void addActionListener() {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody throw new UnsupportedOperationException(
"Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
} }
} }

View File

@ -24,7 +24,6 @@ package org.nanoboot.utils.timecalc.swing.common;
* // Show a simple toaster toasterManager.showToaster( new ImageIcon( * // Show a simple toaster toasterManager.showToaster( new ImageIcon(
* "mylogo.gif" ), "A simple toaster with an image" ); } } * "mylogo.gif" ), "A simple toaster with an image" ); } }
*/ */
import org.nanoboot.utils.timecalc.utils.common.Utils;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.Icon; import javax.swing.Icon;
@ -110,10 +109,10 @@ public class Toaster {
* Show a toaster with the specified message and the associated icon. * Show a toaster with the specified message and the associated icon.
*/ */
public void showToaster(Icon icon, String msg) { public void showToaster(Icon icon, String msg) {
// if (!Utils.toastsAreEnabled.getValue()) { // if (!Utils.toastsAreEnabled.getValue()) {
// //nothing to do // //nothing to do
// return; // return;
// } // }
SingleToaster singleToaster = new SingleToaster(); SingleToaster singleToaster = new SingleToaster();
if (icon != null) { if (icon != null) {
singleToaster.iconLabel.setIcon(icon); singleToaster.iconLabel.setIcon(icon);
@ -431,8 +430,9 @@ public class Toaster {
stopYPosition = startYPosition - toasterHeight - 1; stopYPosition = startYPosition - toasterHeight - 1;
if (currentNumberOfToaster > 0) { if (currentNumberOfToaster > 0) {
stopYPosition stopYPosition
= stopYPosition - (maxToaster % maxToasterInSceen =
* toasterHeight); stopYPosition - (maxToaster % maxToasterInSceen
* toasterHeight);
} else { } else {
maxToaster = 0; maxToaster = 0;
} }
@ -442,8 +442,9 @@ public class Toaster {
if (currentNumberOfToaster > 0) { if (currentNumberOfToaster > 0) {
stopYPosition stopYPosition
= stopYPosition + (maxToaster % maxToasterInSceen =
* toasterHeight); stopYPosition + (maxToaster % maxToasterInSceen
* toasterHeight);
} else { } else {
maxToaster = 0; maxToaster = 0;
} }

View File

@ -86,7 +86,7 @@ public class WeatherWindow extends JFrame {
jep.setContentType("text/html"); jep.setContentType("text/html");
jep.setText("<html><head><meta charset=\"UTF-8\"></head><body>" jep.setText("<html><head><meta charset=\"UTF-8\"></head><body>"
+ pocasiHtml + "</body></html>"); + pocasiHtml + "</body></html>");
Utils.writeTextToFile(new File("aaa"), Utils.writeTextToFile(new File("aaa"),
"<html><head><meta charset=\"UTF-8\"></head><body>" "<html><head><meta charset=\"UTF-8\"></head><body>"
+ pocasiHtml + "</body></html>"); + pocasiHtml + "</body></html>");

View File

@ -1,6 +1,7 @@
package org.nanoboot.utils.timecalc.swing.common; package org.nanoboot.utils.timecalc.swing.common;
import org.nanoboot.utils.timecalc.app.GetProperty; import org.nanoboot.utils.timecalc.app.GetProperty;
import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.entity.Visibility;
import org.nanoboot.utils.timecalc.swing.progress.ProgressSmileyIcon; import org.nanoboot.utils.timecalc.swing.progress.ProgressSmileyIcon;
import org.nanoboot.utils.timecalc.utils.common.ProgressSmiley; import org.nanoboot.utils.timecalc.utils.common.ProgressSmiley;
@ -12,7 +13,6 @@ import javax.swing.ImageIcon;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.Timer; import javax.swing.Timer;
import java.awt.BasicStroke;
import java.awt.Color; import java.awt.Color;
import java.awt.Font; import java.awt.Font;
import java.awt.Graphics; import java.awt.Graphics;
@ -20,7 +20,6 @@ import java.awt.Graphics2D;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener; import java.awt.event.MouseMotionListener;
import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
/** /**
* @author Robert Vokac * @author Robert Vokac
@ -29,16 +28,12 @@ import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
public class Widget extends JPanel implements public class Widget extends JPanel implements
GetProperty { GetProperty {
public static final int CLOSE_BUTTON_SIDE = 15;
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);
protected static final Font BIG_FONT = new Font("sans", Font.BOLD, 24); protected static final Font BIG_FONT = new Font("sans", Font.BOLD, 24);
protected static final Font MEDIUM_FONT = new Font("sans", Font.BOLD, 16); protected static final Font MEDIUM_FONT = new Font("sans", Font.BOLD, 16);
public static final int CLOSE_BUTTON_SIDE = 15;
public StringProperty visibilityProperty
= new StringProperty("widget.visibilityProperty",
Visibility.STRONGLY_COLORED.name());
public final BooleanProperty visibilitySupportedColoredProperty public final BooleanProperty visibilitySupportedColoredProperty
= new BooleanProperty("visibilitySupportedColoredProperty", true); = new BooleanProperty("visibilitySupportedColoredProperty", true);
public final BooleanProperty visibleProperty public final BooleanProperty visibleProperty
@ -46,9 +41,14 @@ public class Widget extends JPanel implements
public final BooleanProperty smileysVisibleProperty public final BooleanProperty smileysVisibleProperty
= new BooleanProperty(TimeCalcProperty.SMILEYS_VISIBLE.getKey()); = new BooleanProperty(TimeCalcProperty.SMILEYS_VISIBLE.getKey());
public final BooleanProperty smileysVisibleOnlyIfMouseMovingOverProperty public final BooleanProperty smileysVisibleOnlyIfMouseMovingOverProperty
= new BooleanProperty(TimeCalcProperty.SMILEYS_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER.getKey()); = new BooleanProperty(
TimeCalcProperty.SMILEYS_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER
.getKey());
public final BooleanProperty smileysColoredProperty public final BooleanProperty smileysColoredProperty
= new BooleanProperty("smileysColoredProperty", true); = new BooleanProperty("smileysColoredProperty", true);
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;
@ -69,7 +69,8 @@ public class Widget extends JPanel implements
int x = e.getX(); int x = e.getX();
int y = e.getY(); int y = e.getY();
mouseOverCloseButton = x >= getWidth() - CLOSE_BUTTON_SIDE && y <= CLOSE_BUTTON_SIDE; mouseOverCloseButton = x >= getWidth() - CLOSE_BUTTON_SIDE
&& y <= CLOSE_BUTTON_SIDE;
} }
}); });
addMouseListener(new MouseListener() { addMouseListener(new MouseListener() {
@ -124,16 +125,16 @@ public class Widget extends JPanel implements
return 100; return 100;
} }
// @Override // @Override
// public void setVisible(boolean aFlag) { // public void setVisible(boolean aFlag) {
// if(visibleProperty.isEnabled() && !aFlag) { // if(visibleProperty.isEnabled() && !aFlag) {
// super.setVisible(false); // super.setVisible(false);
// } // }
// if(visibleProperty.isDisabled() && aFlag) { // if(visibleProperty.isDisabled() && aFlag) {
// super.setVisible(false); // super.setVisible(false);
// } // }
// //
// } // }
public final void setDonePercent(double donePercent) { public final void setDonePercent(double donePercent) {
if (donePercent > 1) { if (donePercent > 1) {
donePercent = 1; donePercent = 1;
@ -154,13 +155,14 @@ public class Widget extends JPanel implements
setVisible(visibleProperty.isEnabled()); setVisible(visibleProperty.isEnabled());
if(visibleProperty.isDisabled()) { if (visibleProperty.isDisabled()) {
//nothing to do //nothing to do
return; return;
} }
Visibility visibility Visibility visibility
= Visibility.valueOf(visibilityProperty.getValue()); = Visibility.valueOf(visibilityProperty.getValue());
super.setVisible(visibility != Visibility.NONE && visibleProperty.isEnabled()); super.setVisible(
visibility != Visibility.NONE && visibleProperty.isEnabled());
paintWidget(brush); paintWidget(brush);
if (mouseOver && mouseOverCloseButton) { if (mouseOver && mouseOverCloseButton) {
@ -182,8 +184,11 @@ public class Widget extends JPanel implements
return visibilitySupportedColoredProperty; return visibilitySupportedColoredProperty;
} }
protected void paintSmiley(Visibility visibility, Graphics2D brush, int x, int y) { protected void paintSmiley(Visibility visibility, Graphics2D brush, int x,
if (smileysVisibleProperty.isDisabled() || (!mouseOver && smileysVisibleOnlyIfMouseMovingOverProperty.isEnabled())) { int y) {
if (smileysVisibleProperty.isDisabled() || (!mouseOver
&& smileysVisibleOnlyIfMouseMovingOverProperty
.isEnabled())) {
if (this.smileyIcon != null) { if (this.smileyIcon != null) {
this.remove(smileyIcon); this.remove(smileyIcon);
this.smileyIcon = null; this.smileyIcon = null;
@ -212,7 +217,8 @@ public class Widget extends JPanel implements
brush.setColor(Color.BLACK); brush.setColor(Color.BLACK);
} }
Color currentColor = brush.getColor(); Color currentColor = brush.getColor();
brush.setColor(visibility.isStronglyColored() ? Color.WHITE : BACKGROUND_COLOR); brush.setColor(visibility.isStronglyColored() ? Color.WHITE :
BACKGROUND_COLOR);
brush.fillRect( brush.fillRect(
x, y, x, y,
20, 20,
@ -226,7 +232,9 @@ public class Widget extends JPanel implements
); );
} }
if (colored) { if (colored) {
ImageIcon imageIcon = ProgressSmileyIcon.forSmiley(ProgressSmiley.forProgress(donePercent)).getIcon(); ImageIcon imageIcon = ProgressSmileyIcon
.forSmiley(ProgressSmiley.forProgress(donePercent))
.getIcon();
if (this.smileyIcon != null) { if (this.smileyIcon != null) {
this.remove(smileyIcon); this.remove(smileyIcon);
this.smileyIcon = null; this.smileyIcon = null;

View File

@ -26,7 +26,41 @@ public class AnalogClock extends Widget {
public static final Color COLOR_FOR_MILLISECOND_HAND_STRONGLY_COLORED public static final Color COLOR_FOR_MILLISECOND_HAND_STRONGLY_COLORED
= new Color(246, = new Color(246,
152, 51); 152, 51);
public final BooleanProperty borderVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_BORDER_VISIBLE
.getKey());
public final BooleanProperty borderOnlyHoursProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_BORDER_ONLY_HOURS
.getKey());
public final BooleanProperty numbersVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_NUMBERS_VISIBLE
.getKey());
public final BooleanProperty circleVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_CIRCLE_VISIBLE
.getKey());
public final BooleanProperty circleStrongBorderProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_CIRCLE_STRONG_BORDER
.getKey());
public final BooleanProperty centreCircleVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_CENTRE_CIRCLE_VISIBLE
.getKey());
public final StringProperty centreCircleBorderColorProperty
= new StringProperty(TimeCalcProperty.CLOCK_CIRCLE_BORDER_COLOR
.getKey());
public final BooleanProperty centreCircleBlackProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_CENTRE_CIRCLE_BLACK
.getKey());
public final BooleanProperty progressVisibleOnlyIfMouseMovingOverProperty
= new BooleanProperty(
TimeCalcProperty.CLOCK_PROGRESS_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER
.getKey());
public final BooleanProperty dateVisibleOnlyIfMouseMovingOverProperty
= new BooleanProperty(
TimeCalcProperty.CLOCK_DATE_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER
.getKey());
private final TimeHM endTime;
private final int endAngle;
public IntegerProperty startHourProperty public IntegerProperty startHourProperty
= new IntegerProperty("startHourProperty"); = new IntegerProperty("startHourProperty");
public IntegerProperty startMinuteProperty public IntegerProperty startMinuteProperty
@ -59,39 +93,8 @@ public class AnalogClock extends Widget {
= new BooleanProperty("handsLongProperty", true); = new BooleanProperty("handsLongProperty", true);
public BooleanProperty handsColoredProperty public BooleanProperty handsColoredProperty
= new BooleanProperty("handsColoredProperty", true); = new BooleanProperty("handsColoredProperty", true);
public final BooleanProperty borderVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_BORDER_VISIBLE
.getKey());
public final BooleanProperty borderOnlyHoursProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_BORDER_ONLY_HOURS
.getKey());
public final BooleanProperty numbersVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_NUMBERS_VISIBLE
.getKey());
public final BooleanProperty circleVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_CIRCLE_VISIBLE
.getKey());
public final BooleanProperty circleStrongBorderProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_CIRCLE_STRONG_BORDER
.getKey());
public final BooleanProperty centreCircleVisibleProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_CENTRE_CIRCLE_VISIBLE
.getKey());
public final StringProperty centreCircleBorderColorProperty
= new StringProperty(TimeCalcProperty.CLOCK_CIRCLE_BORDER_COLOR
.getKey());
public final BooleanProperty centreCircleBlackProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_CENTRE_CIRCLE_BLACK
.getKey());
public final BooleanProperty progressVisibleOnlyIfMouseMovingOverProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_PROGRESS_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER.getKey());
public final BooleanProperty dateVisibleOnlyIfMouseMovingOverProperty
= new BooleanProperty(TimeCalcProperty.CLOCK_DATE_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER.getKey());
private TimeHM startTime; private TimeHM startTime;
private final TimeHM endTime;
private int startAngle; private int startAngle;
private final int endAngle;
private Color customCircleColor = null; private Color customCircleColor = null;
public AnalogClock(TimeHM startTimeIn, public AnalogClock(TimeHM startTimeIn,
@ -100,19 +103,21 @@ public class AnalogClock extends Widget {
this.endTime = endTimeIn.cloneInstance(); this.endTime = endTimeIn.cloneInstance();
this.endAngle this.endAngle
= (int) ((endTime.getHour() + endTime.getMinute() / 60d) / 12d = (int) ((endTime.getHour() + endTime.getMinute() / 60d) / 12d
* 360d); * 360d);
if (endTime.getHour() > 12) { 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));
centreCircleBorderColorProperty.addListener(property centreCircleBorderColorProperty.addListener(property
-> customCircleColor = SwingUtils.getColorFromString(centreCircleBorderColorProperty.getValue())); -> customCircleColor = SwingUtils.getColorFromString(
centreCircleBorderColorProperty.getValue()));
} }
public static void main(String[] args) { public static void main(String[] args) {
@ -163,13 +168,15 @@ public class AnalogClock extends Widget {
int hour = hourProperty.getValue(); int hour = hourProperty.getValue();
if (customCircleColor == null) { if (customCircleColor == null) {
customCircleColor = SwingUtils.getColorFromString(centreCircleBorderColorProperty.getValue()); customCircleColor = SwingUtils.getColorFromString(
centreCircleBorderColorProperty.getValue());
} }
if ((mouseOver || progressVisibleOnlyIfMouseMovingOverProperty.isDisabled()) && visibility.isStronglyColored()) { if ((mouseOver || progressVisibleOnlyIfMouseMovingOverProperty
.isDisabled()) && visibility.isStronglyColored()) {
this.startTime = new TimeHM(hour, minute); this.startTime = new TimeHM(hour, minute);
this.startAngle this.startAngle
= (int) ((startTime.getHour() + startTime.getMinute() / 60d) = (int) ((startTime.getHour() + startTime.getMinute() / 60d)
/ 12d * 360d); / 12d * 360d);
Color currentColor = g2d.getColor(); Color currentColor = g2d.getColor();
g2d.setColor(Color.YELLOW); g2d.setColor(Color.YELLOW);
@ -181,7 +188,9 @@ public class AnalogClock extends Widget {
} }
// //
if (millisecondEnabledProperty.isEnabled() && secondEnabledProperty.isEnabled() && minuteEnabledProperty.isEnabled() && hourEnabledProperty.isEnabled()) { if (millisecondEnabledProperty.isEnabled() && secondEnabledProperty
.isEnabled() && minuteEnabledProperty.isEnabled()
&& hourEnabledProperty.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);
@ -194,7 +203,8 @@ public class AnalogClock extends Widget {
} }
} }
if (secondEnabledProperty.isEnabled() && minuteEnabledProperty.isEnabled() && hourEnabledProperty.isEnabled()) { if (secondEnabledProperty.isEnabled() && minuteEnabledProperty
.isEnabled() && hourEnabledProperty.isEnabled()) {
drawHand(g2d, side / 2 - 10, second / 60.0, 0.5f, Color.RED, drawHand(g2d, side / 2 - 10, second / 60.0, 0.5f, Color.RED,
visibility); visibility);
@ -204,7 +214,8 @@ public class AnalogClock extends Widget {
Color.RED, visibility); Color.RED, visibility);
} }
} }
if (minuteEnabledProperty.isEnabled() && hourEnabledProperty.isEnabled()) { if (minuteEnabledProperty.isEnabled() && hourEnabledProperty
.isEnabled()) {
double minutes = minute / 60.0 + second / 60.0 / 60.0; double minutes = minute / 60.0 + second / 60.0 / 60.0;
drawHand(g2d, side / 2 - 20, minutes, 2.0f, drawHand(g2d, side / 2 - 20, minutes, 2.0f,
Color.BLUE, visibility); Color.BLUE, visibility);
@ -217,7 +228,8 @@ public class AnalogClock extends Widget {
} }
} }
if (hourEnabledProperty.isEnabled()) { if (hourEnabledProperty.isEnabled()) {
double hours = hour / 12.0 + minute / 60.0 / 12 + second / 60 / 60 / 12; double hours =
hour / 12.0 + minute / 60.0 / 12 + second / 60 / 60 / 12;
drawHand(g2d, side / 2 - 40, drawHand(g2d, side / 2 - 40,
hours, 4.0f, hours, 4.0f,
Color.BLACK, visibility); Color.BLACK, visibility);
@ -233,7 +245,8 @@ public class AnalogClock extends Widget {
if (borderOnlyHoursProperty.isEnabled() && minuteI % 5 != 0) { if (borderOnlyHoursProperty.isEnabled() && minuteI % 5 != 0) {
continue; continue;
} }
drawBorder(g2d, minuteI, minuteI % 5 == 0 ? (numbersVisibleProperty.isEnabled() ? 2f : 4f) : 1f, drawBorder(g2d, minuteI, minuteI % 5 == 0 ?
(numbersVisibleProperty.isEnabled() ? 2f : 4f) : 1f,
Color.BLACK, visibility); Color.BLACK, visibility);
} }
} }
@ -249,7 +262,9 @@ public class AnalogClock extends Widget {
Color currentColor = brush.getColor(); Color currentColor = brush.getColor();
Visibility visibility Visibility visibility
= Visibility.valueOf(visibilityProperty.getValue()); = Visibility.valueOf(visibilityProperty.getValue());
brush.setColor(visibility.isStronglyColored() || mouseOver ? (centreCircleBlackProperty.isEnabled() ? Color.BLACK : Color.RED) brush.setColor(visibility.isStronglyColored() || mouseOver ?
(centreCircleBlackProperty.isEnabled() ? Color.BLACK :
Color.RED)
: FOREGROUND_COLOR); : FOREGROUND_COLOR);
brush.fillOval(centerX - 3, centerY - 3, 8, 8); brush.fillOval(centerX - 3, centerY - 3, 8, 8);
brush.setColor(currentColor); brush.setColor(currentColor);
@ -259,12 +274,19 @@ public class AnalogClock extends Widget {
float stroke, Color color, Visibility visibility) { float stroke, Color color, Visibility visibility) {
double value = ((double) forMinute) / 60d; double value = ((double) forMinute) / 60d;
boolean hourAngle = forMinute % 5 == 0; boolean hourAngle = forMinute % 5 == 0;
int length = side / (numbersVisibleProperty.isEnabled() ? 18 : (hourAngle ? 12 : 18)); int length = side / (numbersVisibleProperty.isEnabled() ? 18 :
(hourAngle ? 12 : 18));
double angle = Math.PI * 2 * (value - 0.25); double angle = Math.PI * 2 * (value - 0.25);
int startX = (int) (getWidth() / 2 + (side / 2 - length) * Math.cos(angle)); int startX =
int startY = (int) (getHeight() / 2 + (side / 2 - length) * Math.sin(angle)); (int) (getWidth() / 2 + (side / 2 - length) * Math.cos(angle));
int endX = (int) (getWidth() / 2 + (side / 2 - length * 0.50d * (hourAngle ? 0.25 : 1)) * Math.cos(angle)); int startY =
int endY = (int) (getHeight() / 2 + (side / 2 - length * 0.50d * (hourAngle ? 0.25 : 1)) * Math.sin(angle)); (int) (getHeight() / 2 + (side / 2 - length) * Math.sin(angle));
int endX = (int) (getWidth() / 2
+ (side / 2 - length * 0.50d * (hourAngle ? 0.25 : 1))
* Math.cos(angle));
int endY = (int) (getHeight() / 2
+ (side / 2 - length * 0.50d * (hourAngle ? 0.25 : 1))
* Math.sin(angle));
brush.setColor((visibility.isStronglyColored() || mouseOver) ? color brush.setColor((visibility.isStronglyColored() || mouseOver) ? color
: FOREGROUND_COLOR); : FOREGROUND_COLOR);
@ -279,7 +301,8 @@ public class AnalogClock extends Widget {
int endX = (int) (getWidth() / 2 + length * Math.cos(angle)); int endX = (int) (getWidth() / 2 + length * Math.cos(angle));
int endY = (int) (getHeight() / 2 + length * Math.sin(angle)); int endY = (int) (getHeight() / 2 + length * Math.sin(angle));
brush.setColor((visibility.isStronglyColored() || mouseOver) ? (handsColoredProperty.isEnabled() ? color : Color.BLACK) brush.setColor((visibility.isStronglyColored() || mouseOver) ?
(handsColoredProperty.isEnabled() ? color : Color.BLACK)
: FOREGROUND_COLOR); : FOREGROUND_COLOR);
brush.setStroke(new BasicStroke(stroke)); brush.setStroke(new BasicStroke(stroke));
brush.drawLine(getWidth() / 2, getHeight() / 2, endX, endY); brush.drawLine(getWidth() / 2, getHeight() / 2, endX, endY);
@ -306,7 +329,8 @@ public class AnalogClock extends Widget {
brush.setColor(currentColor); brush.setColor(currentColor);
} }
if (this.mouseOver || dateVisibleOnlyIfMouseMovingOverProperty.isDisabled()) { if (this.mouseOver || dateVisibleOnlyIfMouseMovingOverProperty
.isDisabled()) {
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);

View File

@ -37,23 +37,31 @@ public class Battery extends Widget {
@Getter @Getter
private final String name; private final String name;
private final double[] randomDoubles private final double[] randomDoubles
= new double[]{1d, 1d, 1d, 1d, 1d, 1d, 1}; = new double[] {1d, 1d, 1d, 1d, 1d, 1d, 1};
public BooleanProperty wavesVisibleProperty = new BooleanProperty(TimeCalcProperty.BATTERY_WAVES_VISIBLE
.getKey(), true);
public BooleanProperty circleProgressVisibleProperty = new BooleanProperty(TimeCalcProperty.BATTERY_CIRCLE_PROGRESS_VISIBLE
.getKey(), true);
public BooleanProperty percentProgressVisibleProperty = new BooleanProperty(TimeCalcProperty.BATTERY_PERCENT_PROGRESS_VISIBLE
.getKey(), true);
public BooleanProperty chargingCharacterVisibleProperty = new BooleanProperty(TimeCalcProperty.BATTERY_CHARGING_CHARACTER_VISIBLE
.getKey(), true);
public BooleanProperty nameVisibleProperty = new BooleanProperty(TimeCalcProperty.BATTERY_NAME_VISIBLE
.getKey(), true);
public BooleanProperty labelVisibleProperty = new BooleanProperty(TimeCalcProperty.BATTERY_LABEL_VISIBLE
.getKey(), true);
public BooleanProperty blinkingIfCriticalLowVisibleProperty
= new BooleanProperty(TimeCalcProperty.BATTERY_BLINKING_IF_CRITICAL_LOW
.getKey(), true);
private final BooleanProperty blinking = new BooleanProperty("blinking"); private final BooleanProperty blinking = new BooleanProperty("blinking");
public BooleanProperty wavesVisibleProperty =
new BooleanProperty(TimeCalcProperty.BATTERY_WAVES_VISIBLE
.getKey(), true);
public BooleanProperty circleProgressVisibleProperty =
new BooleanProperty(TimeCalcProperty.BATTERY_CIRCLE_PROGRESS_VISIBLE
.getKey(), true);
public BooleanProperty percentProgressVisibleProperty = new BooleanProperty(
TimeCalcProperty.BATTERY_PERCENT_PROGRESS_VISIBLE
.getKey(), true);
public BooleanProperty chargingCharacterVisibleProperty =
new BooleanProperty(
TimeCalcProperty.BATTERY_CHARGING_CHARACTER_VISIBLE
.getKey(), true);
public BooleanProperty nameVisibleProperty =
new BooleanProperty(TimeCalcProperty.BATTERY_NAME_VISIBLE
.getKey(), true);
public BooleanProperty labelVisibleProperty =
new BooleanProperty(TimeCalcProperty.BATTERY_LABEL_VISIBLE
.getKey(), true);
public BooleanProperty blinkingIfCriticalLowVisibleProperty
= new BooleanProperty(
TimeCalcProperty.BATTERY_BLINKING_IF_CRITICAL_LOW
.getKey(), true);
private long tmpNanoTime = 0l; private long tmpNanoTime = 0l;
private int totalHeight = 0; private int totalHeight = 0;
private int totalWidth; private int totalWidth;
@ -77,7 +85,7 @@ public class Battery extends Widget {
} }
if (blinkingIfCriticalLowVisibleProperty.isEnabled()) { if (blinkingIfCriticalLowVisibleProperty.isEnabled()) {
if (donePercent > 0 && donePercent <= CRITICAL_LOW_ENERGY if (donePercent > 0 && donePercent <= CRITICAL_LOW_ENERGY
&& (System.nanoTime() - tmpNanoTime) > (1000000000l) / 2l) { && (System.nanoTime() - tmpNanoTime) > (1000000000l) / 2l) {
blinking.flip(); blinking.flip();
tmpNanoTime = System.nanoTime(); tmpNanoTime = System.nanoTime();
} }
@ -99,7 +107,7 @@ public class Battery extends Widget {
= Visibility.valueOf(visibilityProperty.getValue()); = Visibility.valueOf(visibilityProperty.getValue());
brush.setColor( brush.setColor(
visibility.isStronglyColored() || mouseOver ? Color.YELLOW visibility.isStronglyColored() || mouseOver ? Color.YELLOW
: FOREGROUND_COLOR); : FOREGROUND_COLOR);
brush.setRenderingHint(RenderingHints.KEY_ANTIALIASING, brush.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);
@ -111,15 +119,15 @@ public class Battery extends Widget {
brush.setColor( brush.setColor(
donePercent < LOW_ENERGY ? LOW_HIGHLIGHTED donePercent < LOW_ENERGY ? LOW_HIGHLIGHTED
: (donePercent < HIGH_ENERGY : (donePercent < HIGH_ENERGY
? MEDIUM_HIGHLIGHTED ? MEDIUM_HIGHLIGHTED
: (donePercent < VERY_HIGH_ENERGY : (donePercent < VERY_HIGH_ENERGY
? HIGH_HIGHLIGHTED ? HIGH_HIGHLIGHTED
: HIGHEST_HIGHLIGHTED))); : HIGHEST_HIGHLIGHTED)));
} else { } else {
brush.setColor(donePercent < LOW_ENERGY ? LOW brush.setColor(donePercent < LOW_ENERGY ? LOW
: (donePercent < HIGH_ENERGY : (donePercent < HIGH_ENERGY
? MEDIUM ? MEDIUM
: (donePercent < VERY_HIGH_ENERGY ? HIGH : HIGHEST))); : (donePercent < VERY_HIGH_ENERGY ? HIGH : HIGHEST)));
} }
if (visibility.isGray()) { if (visibility.isGray()) {
brush.setColor(Utils.ULTRA_LIGHT_GRAY); brush.setColor(Utils.ULTRA_LIGHT_GRAY);
@ -131,7 +139,8 @@ public class Battery extends Widget {
int intX = 1; int intX = 1;
int todoHeight = totalHeight - doneHeight; int todoHeight = totalHeight - doneHeight;
double surfacePower double surfacePower
= 1;//donePercent < 0.5 ? 0.5 : donePercent;// (donePercent * 100 - ((int)(donePercent * 100))); =
1;//donePercent < 0.5 ? 0.5 : donePercent;// (donePercent * 100 - ((int)(donePercent * 100)));
int waterSurfaceHeight int waterSurfaceHeight
= (int) (4 * surfacePower);//2 + (int) (Math.random() * 3); = (int) (4 * surfacePower);//2 + (int) (Math.random() * 3);
if (waterSurfaceHeight <= 2 || wavesVisibleProperty.isDisabled()) { if (waterSurfaceHeight <= 2 || wavesVisibleProperty.isDisabled()) {
@ -146,32 +155,32 @@ public class Battery extends Widget {
? doneHeight : doneHeight - waterSurfaceHeight + 1); ? doneHeight : doneHeight - waterSurfaceHeight + 1);
int pointCount = 8; int pointCount = 8;
if (doneHeight >= waterSurfaceHeight if (doneHeight >= waterSurfaceHeight
&& donePercent < 1) {// && todoHeight > waterSurfaceHeight) { && donePercent < 1) {// && todoHeight > waterSurfaceHeight) {
//g2d.fillArc(intX, intY, width_, intHeight - waterSurfaceHeight, 30, 60); //g2d.fillArc(intX, intY, width_, intHeight - waterSurfaceHeight, 30, 60);
brush.fillPolygon( brush.fillPolygon(
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)), 0)),
todoHeight + (int) (waterSurfaceHeight * getRandom( todoHeight + (int) (waterSurfaceHeight * getRandom(
1)), 1)),
todoHeight + (int) (waterSurfaceHeight * getRandom( todoHeight + (int) (waterSurfaceHeight * getRandom(
2)), 2)),
todoHeight + (int) (waterSurfaceHeight * getRandom( todoHeight + (int) (waterSurfaceHeight * getRandom(
3)), 3)),
todoHeight + (int) (waterSurfaceHeight * getRandom( todoHeight + (int) (waterSurfaceHeight * getRandom(
4)), 4)),
todoHeight + (int) (waterSurfaceHeight * getRandom( todoHeight + (int) (waterSurfaceHeight * getRandom(
5)), 5)),
todoHeight + (waterSurfaceHeight * 1)}, todoHeight + (waterSurfaceHeight * 1)},
pointCount); pointCount);
brush.setColor( brush.setColor(
@ -181,28 +190,28 @@ public class Battery extends Widget {
brush.setRenderingHint(RenderingHints.KEY_ANTIALIASING, brush.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF); RenderingHints.VALUE_ANTIALIAS_OFF);
brush.drawPolyline( brush.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);
brush.setRenderingHint(RenderingHints.KEY_ANTIALIASING, brush.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);
@ -227,10 +236,12 @@ public class Battery extends Widget {
brush.setFont(currentFont); brush.setFont(currentFont);
} }
if(circleProgressVisibleProperty.isEnabled()) { if (circleProgressVisibleProperty.isEnabled()) {
Color currentColor = brush.getColor(); Color currentColor = brush.getColor();
brush.setColor( brush.setColor(
visibility.isStronglyColored() ? HIGH_HIGHLIGHTED : (visibility.isWeaklyColored() ? HIGH : Color.lightGray)); visibility.isStronglyColored() ? HIGH_HIGHLIGHTED :
(visibility.isWeaklyColored() ? HIGH :
Color.lightGray));
double angleDouble = donePercent * 360; double angleDouble = donePercent * 360;
@ -239,7 +250,9 @@ public class Battery extends Widget {
15, 15, 90, -(int) angleDouble); 15, 15, 90, -(int) angleDouble);
brush.setColor( brush.setColor(
visibility.isStronglyColored() ? LIGHT_RED visibility.isStronglyColored() ? LIGHT_RED
: visibility.isWeaklyColored() ? ULTRA_LIGHT_RED : BACKGROUND_COLOR); :
visibility.isWeaklyColored() ? ULTRA_LIGHT_RED :
BACKGROUND_COLOR);
brush.fillArc(((int) (totalWidth * 0.45)) + 15, brush.fillArc(((int) (totalWidth * 0.45)) + 15,
totalHeight / 4 * 3 + 28, totalHeight / 4 * 3 + 28,
15, 15, 90, +(int) (360 - angleDouble)); 15, 15, 90, +(int) (360 - angleDouble));
@ -247,22 +260,25 @@ public class Battery extends Widget {
brush.setColor(currentColor); brush.setColor(currentColor);
} }
} }
if(percentProgressVisibleProperty.isEnabled()) { if (percentProgressVisibleProperty.isEnabled()) {
brush.drawString( brush.drawString(
NumberFormats.FORMATTER_THREE_DECIMAL_PLACES NumberFormats.FORMATTER_THREE_DECIMAL_PLACES
.format(donePercent * 100) + "%", .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);
} }
if (labelVisibleProperty.isEnabled() && label != null && !label.isEmpty()) { if (labelVisibleProperty.isEnabled() && label != null && !label
.isEmpty()) {
brush.drawString( brush.drawString(
label, label,
((int) (totalWidth * 0.15)), ((int) (totalWidth * 0.15)),
(donePercent > 0.5 ? totalHeight / 4 * 3 (donePercent > 0.5 ? totalHeight / 4 * 3
: totalHeight / 4 * 1) + 20); : totalHeight / 4 * 1) + 20);
} }
if (nameVisibleProperty.isEnabled() && name != null && !name.isEmpty()) { if (nameVisibleProperty.isEnabled() && name != null && !name
.isEmpty()) {
brush.drawString( brush.drawString(
name, name,
((int) (totalWidth * 0.10)), ((int) (totalWidth * 0.10)),

View File

@ -6,8 +6,9 @@ package org.nanoboot.utils.timecalc.swing.progress;
*/ */
public class DayBattery extends Battery { public class DayBattery extends Battery {
public static final String DAY = "Day";
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);
} }
public static final String DAY = "Day";
} }

View File

@ -8,15 +8,16 @@ import org.nanoboot.utils.timecalc.utils.common.TimeHM;
*/ */
public class HourBattery extends Battery { public class HourBattery extends Battery {
public static final String HOUR = "Hour";
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 final String HOUR = "Hour";
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 if (secondsRemains < 0 || millisecondsRemains < 0
|| timeRemains.getHour() < 0 || timeRemains.getMinute() < 0) { || timeRemains.getHour() < 0 || timeRemains.getMinute() < 0) {
return 1; return 1;
} }
double minutesRemainsD = timeRemains.getMinute(); double minutesRemainsD = timeRemains.getMinute();

View File

@ -1,17 +1,16 @@
package org.nanoboot.utils.timecalc.swing.progress; package org.nanoboot.utils.timecalc.swing.progress;
import org.nanoboot.utils.timecalc.utils.common.TimeHM;
/** /**
* @author Robert Vokac * @author Robert Vokac
* @since 21.02.2024 * @since 21.02.2024
*/ */
public class MinuteBattery extends Battery { public class MinuteBattery extends Battery {
public static final String MINUTE = "Minute";
public MinuteBattery(int x, int i, int i1) { public MinuteBattery(int x, int i, int i1) {
super(MINUTE, x, i, i1); super(MINUTE, x, i, i1);
} }
public static final String MINUTE = "Minute";
public static double getMinuteProgress(int secondNow, int millisecondNow) { public static double getMinuteProgress(int secondNow, int millisecondNow) {
return millisecondNow / 60d / 1000d + secondNow / 60d; return millisecondNow / 60d / 1000d + secondNow / 60d;

View File

@ -6,10 +6,11 @@ package org.nanoboot.utils.timecalc.swing.progress;
*/ */
public class MonthBattery extends Battery { public class MonthBattery extends Battery {
public static final String MONTH = "Month";
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 final String MONTH = "Month";
public static double getMonthProgress(int weekDayWhenMondayIsOne, public static double getMonthProgress(int weekDayWhenMondayIsOne,
int workDaysDone, int workDaysTotal, double done) { int workDaysDone, int workDaysTotal, double done) {
@ -17,8 +18,8 @@ public class MonthBattery extends Battery {
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

@ -2,11 +2,8 @@ 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.ProgressSmiley;
import org.nanoboot.utils.timecalc.utils.common.NumberFormats; import org.nanoboot.utils.timecalc.utils.common.NumberFormats;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
@ -29,7 +26,7 @@ public class ProgressCircle extends Widget {
Graphics2D brush = (Graphics2D) g; Graphics2D brush = (Graphics2D) g;
brush.setColor( brush.setColor(
visibility.isStronglyColored() || mouseOver ? Color.darkGray visibility.isStronglyColored() || mouseOver ? Color.darkGray
: FOREGROUND_COLOR); : FOREGROUND_COLOR);
brush.setRenderingHint(RenderingHints.KEY_ANTIALIASING, brush.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);

View File

@ -14,12 +14,22 @@ import java.util.Map;
*/ */
public class ProgressSmileyIcon extends javax.swing.ImageIcon { public class ProgressSmileyIcon extends javax.swing.ImageIcon {
private static final Map<ProgressSmiley, ProgressSmileyIcon> cache = new HashMap<>(); private static final Map<ProgressSmiley, ProgressSmileyIcon> cache =
new HashMap<>();
@Getter @Getter
private final ProgressSmiley progressSmiley; private final ProgressSmiley progressSmiley;
@Getter @Getter
private final ImageIcon icon; private final ImageIcon icon;
private ProgressSmileyIcon(ProgressSmiley progressSmiley) {
this.progressSmiley = progressSmiley;
java.net.URL smileyUrl = getClass()
.getResource("/smileys/" + progressSmiley.name() + ".png");
ImageIcon tmpIcon = new javax.swing.ImageIcon(smileyUrl);
this.icon = new ImageIcon(tmpIcon.getImage()
.getScaledInstance(15, 15, Image.SCALE_SMOOTH));
}
public static ProgressSmileyIcon forSmiley(ProgressSmiley progressSmiley) { public static ProgressSmileyIcon forSmiley(ProgressSmiley progressSmiley) {
if (!cache.containsKey(progressSmiley)) { if (!cache.containsKey(progressSmiley)) {
cache.put(progressSmiley, new ProgressSmileyIcon(progressSmiley)); cache.put(progressSmiley, new ProgressSmileyIcon(progressSmiley));
@ -27,11 +37,4 @@ public class ProgressSmileyIcon extends javax.swing.ImageIcon {
return cache.get(progressSmiley); return cache.get(progressSmiley);
} }
private ProgressSmileyIcon(ProgressSmiley progressSmiley) {
this.progressSmiley = progressSmiley;
java.net.URL smileyUrl = getClass().getResource("/smileys/" + progressSmiley.name() + ".png");
ImageIcon tmpIcon = new javax.swing.ImageIcon(smileyUrl);
this.icon = new ImageIcon(tmpIcon.getImage().getScaledInstance(15, 15, Image.SCALE_SMOOTH));
}
} }

View File

@ -78,7 +78,7 @@ public class ProgressSquare extends Widget {
: BACKGROUND_COLOR); : BACKGROUND_COLOR);
brush.drawString(NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES brush.drawString(NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES
.format(donePercent * 100) + "%", .format(donePercent * 100) + "%",
(int) (side / 8d * 3d), (int) (side / 8d * 3d),
(int) (side / 8d * (donePercent > 0.5 ? 3d : 5d))); (int) (side / 8d * (donePercent > 0.5 ? 3d : 5d)));
paintSmiley(visibility, brush, (int) (side / 8d * 3d) + 65, paintSmiley(visibility, brush, (int) (side / 8d * 3d) + 65,

View File

@ -10,34 +10,34 @@ public class Time extends Thread {
private final IntegerProperty yearReadWriteProperty private final IntegerProperty yearReadWriteProperty
= new IntegerProperty("yearProperty"); = new IntegerProperty("yearProperty");
public ReadOnlyProperty<Integer> yearProperty
= yearReadWriteProperty.asReadOnlyProperty();
private final IntegerProperty monthReadWriteProperty private final IntegerProperty monthReadWriteProperty
= new IntegerProperty("monthProperty"); = new IntegerProperty("monthProperty");
public ReadOnlyProperty<Integer> monthProperty
= monthReadWriteProperty.asReadOnlyProperty();
private final IntegerProperty dayReadWriteProperty private final IntegerProperty dayReadWriteProperty
= new IntegerProperty("dayProperty"); = new IntegerProperty("dayProperty");
public ReadOnlyProperty<Integer> dayProperty
= dayReadWriteProperty.asReadOnlyProperty();
private final IntegerProperty hourReadWriteProperty private final IntegerProperty hourReadWriteProperty
= new IntegerProperty("hourProperty"); = new IntegerProperty("hourProperty");
public ReadOnlyProperty<Integer> hourProperty
= hourReadWriteProperty.asReadOnlyProperty();
private final IntegerProperty minuteReadWriteProperty private final IntegerProperty minuteReadWriteProperty
= new IntegerProperty("minuteProperty"); = new IntegerProperty("minuteProperty");
public ReadOnlyProperty<Integer> minuteProperty
= minuteReadWriteProperty.asReadOnlyProperty();
private final IntegerProperty secondReadWriteProperty private final IntegerProperty secondReadWriteProperty
= new IntegerProperty("secondProperty"); = new IntegerProperty("secondProperty");
public ReadOnlyProperty<Integer> secondProperty
= secondReadWriteProperty.asReadOnlyProperty();
private final IntegerProperty millisecondReadWriteProperty private final IntegerProperty millisecondReadWriteProperty
= new IntegerProperty("millisecondProperty"); = new IntegerProperty("millisecondProperty");
public ReadOnlyProperty<Integer> millisecondProperty
= millisecondReadWriteProperty.asReadOnlyProperty();
private final IntegerProperty dayOfWeekReadWriteProperty private final IntegerProperty dayOfWeekReadWriteProperty
= new IntegerProperty("dayOfWeek"); = 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 public ReadOnlyProperty<Integer> dayOfWeek
= dayOfWeekReadWriteProperty.asReadOnlyProperty(); = dayOfWeekReadWriteProperty.asReadOnlyProperty();
//private long lastUpdateNanoTime = 0l; //private long lastUpdateNanoTime = 0l;

View File

@ -20,7 +20,6 @@ import java.awt.Font;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.awt.font.LineBreakMeasurer;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.util.HashSet; import java.util.HashSet;
@ -42,6 +41,7 @@ public class WalkingHumanProgress extends Widget implements
private double done; private double done;
private double totalSecondsRemainsDouble; private double totalSecondsRemainsDouble;
private TimeHM endTime; private TimeHM endTime;
public WalkingHumanProgress() { public WalkingHumanProgress() {
setFont(new Font(Font.MONOSPACED, Font.PLAIN, 11)); setFont(new Font(Font.MONOSPACED, Font.PLAIN, 11));
putClientProperty("mouseEntered", "false"); putClientProperty("mouseEntered", "false");
@ -92,7 +92,7 @@ public class WalkingHumanProgress extends Widget implements
setForeground( setForeground(
visibility.isStronglyColored() visibility.isStronglyColored()
|| getClientProperty("mouseEntered").equals("true") || getClientProperty("mouseEntered").equals("true")
? Color.BLACK : Color.LIGHT_GRAY); ? Color.BLACK : Color.LIGHT_GRAY);
}).start(); }).start();
} }
@ -117,11 +117,12 @@ public class WalkingHumanProgress extends Widget implements
} else { } else {
String[] lines = string.split("\n"); String[] lines = string.split("\n");
Visibility visibility Visibility visibility
= Visibility.valueOf(visibilityProperty.getValue()); = Visibility.valueOf(visibilityProperty.getValue());
brush.setColor(visibility.isStronglyColored() ? Color.BLUE : visibility.isWeaklyColored() ? Color.GRAY : Color.LIGHT_GRAY); brush.setColor(visibility.isStronglyColored() ? Color.BLUE :
visibility.isWeaklyColored() ? Color.GRAY :
Color.LIGHT_GRAY);
brush.setFont(SwingUtils.MEDIUM_MONOSPACE_FONT); brush.setFont(SwingUtils.MEDIUM_MONOSPACE_FONT);
int y = SwingUtils.MARGIN; int y = SwingUtils.MARGIN;
for (String line : lines) { for (String line : lines) {
@ -228,15 +229,15 @@ public class WalkingHumanProgress extends Widget implements
double totalSecondsRemainsDouble, TimeHM endTime) { double totalSecondsRemainsDouble, TimeHM endTime) {
String msg String msg
= "Done=" + NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES.format( = "Done=" + NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES.format(
done * 100) + "% Remains=" done * 100) + "% Remains="
+ String.format("%02d", hourRemains) + ":" + String + String.format("%02d", hourRemains) + ":" + String
.format("%02d", minuteRemains) .format("%02d", minuteRemains)
+ /*":" + String.format("%02d", secondsRemains)+ */ " (" + /*":" + String.format("%02d", secondsRemains)+ */ " ("
+ NumberFormats.FORMATTER_THREE_DECIMAL_PLACES + NumberFormats.FORMATTER_THREE_DECIMAL_PLACES
.format(totalSecondsRemainsDouble - 60) .format(totalSecondsRemainsDouble - 60)
+ " s" + ")" + " End=" + String + " s" + ")" + " End=" + String
.format("%02d", endTime.getHour()) + ":" + String .format("%02d", endTime.getHour()) + ":" + String
.format("%02d", endTime.getMinute()); .format("%02d", endTime.getMinute());
return msg; return msg;
} }

View File

@ -6,10 +6,11 @@ package org.nanoboot.utils.timecalc.swing.progress;
*/ */
public class WeekBattery extends Battery { public class WeekBattery extends Battery {
public static final String WEEK = "Week";
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 final String WEEK = "Week";
public static double getWeekProgress(int weekDayWhenMondayIsOne, public static double getWeekProgress(int weekDayWhenMondayIsOne,
double done) { double done) {
@ -17,7 +18,7 @@ public class WeekBattery extends Battery {
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

@ -8,12 +8,15 @@ import java.util.Calendar;
*/ */
public class YearBattery extends Battery { public class YearBattery extends Battery {
public static final String YEAR = "Year";
public YearBattery(int x, int i, int i1) { public YearBattery(int x, int i, int i1) {
super(YEAR, x, i, i1); super(YEAR, x, i, i1);
} }
public static final String YEAR = "Year";
public static double getYearProgress(Integer year, Integer month, Integer day, Integer hour, Integer minute, Integer second, Integer millisecond) { public static double getYearProgress(Integer year, Integer month,
Integer day, Integer hour, Integer minute, Integer second,
Integer millisecond) {
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, year); cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month - 1); cal.set(Calendar.MONTH, month - 1);
@ -27,12 +30,12 @@ public class YearBattery extends Battery {
double minutes = minute + seconds / 60d; double minutes = minute + seconds / 60d;
double hours = hour + minutes / 60d; double hours = hour + minutes / 60d;
double days = cal.get(Calendar.DAY_OF_YEAR) + hours / 24d; double days = cal.get(Calendar.DAY_OF_YEAR) + hours / 24d;
// System.out.println("millisecond=" + millisecond); // System.out.println("millisecond=" + millisecond);
// System.out.println("seconds=" + seconds); // System.out.println("seconds=" + seconds);
// System.out.println("minutes=" + minutes); // System.out.println("minutes=" + minutes);
// System.out.println("hours=" + hours); // System.out.println("hours=" + hours);
// System.out.println("days=" + days); // System.out.println("days=" + days);
// System.out.println("cal.get(Calendar.DAY_OF_YEAR)=" + cal.get(Calendar.DAY_OF_YEAR)); // System.out.println("cal.get(Calendar.DAY_OF_YEAR)=" + cal.get(Calendar.DAY_OF_YEAR));
double totalCountOfDaysInAYear = getTotalCountOfDaysInAYear(year); double totalCountOfDaysInAYear = getTotalCountOfDaysInAYear(year);
return days / totalCountOfDaysInAYear; return days / totalCountOfDaysInAYear;

View File

@ -8,12 +8,17 @@ import java.io.File;
*/ */
public class FileConstants { public class FileConstants {
public static final File TC_DIRECTORY = new File(".tc"); public static final File TC_DIRECTORY = new File(".tc");
public static final File STARTTIME_TXT = new File(TC_DIRECTORY, "starttime.txt"); public static final File STARTTIME_TXT =
public static final File OVERTIME_TXT = new File(TC_DIRECTORY, "overtime.txt"); new File(TC_DIRECTORY, "starttime.txt");
public static final File OVERTIME_TXT =
new File(TC_DIRECTORY, "overtime.txt");
public static final File TEST_TXT = new File(TC_DIRECTORY, "test.txt"); public static final File TEST_TXT = new File(TC_DIRECTORY, "test.txt");
public static final File TIME_CALC_PROFILES_TXT_FILE = new File(TC_DIRECTORY, "time-calc-profiles.txt"); public static final File TIME_CALC_PROFILES_TXT_FILE =
public static final File TIME_CALC_CURRENT_PROFILE_TXT_FILE = new File(TC_DIRECTORY, "time-calc-current-profile.txt"); new File(TC_DIRECTORY, "time-calc-profiles.txt");
public static final File FILE_WITHOUT_ANY_PROFILE = new File(TC_DIRECTORY, "timecalc.conf"); public static final File TIME_CALC_CURRENT_PROFILE_TXT_FILE =
new File(TC_DIRECTORY, "time-calc-current-profile.txt");
public static final File FILE_WITHOUT_ANY_PROFILE =
new File(TC_DIRECTORY, "timecalc.conf");
private FileConstants() { private FileConstants() {
//Not meant to be instantiated. //Not meant to be instantiated.

View File

@ -17,7 +17,7 @@ public class JokesTxt {
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

@ -38,10 +38,6 @@ public enum ProgressSmiley {
this.description = d; this.description = d;
} }
public int getNumber() {
return Integer.valueOf(this.name().replace("SMILEY_", ""));
}
public static ProgressSmiley forNumber(int number) { public static ProgressSmiley forNumber(int number) {
for (ProgressSmiley s : ProgressSmiley.values()) { for (ProgressSmiley s : ProgressSmiley.values()) {
if (s.getNumber() == number) { if (s.getNumber() == number) {
@ -64,7 +60,8 @@ public enum ProgressSmiley {
public static void main(String[] args) { public static void main(String[] args) {
Arrays.stream(values()).forEach(s -> { Arrays.stream(values()).forEach(s -> {
s.getCharacter().codePoints().mapToObj(Integer::toHexString).forEach(System.out::println); s.getCharacter().codePoints().mapToObj(Integer::toHexString)
.forEach(System.out::println);
}); });
} }
@ -72,4 +69,8 @@ public enum ProgressSmiley {
private static String toUnicode(char ch) { private static String toUnicode(char ch) {
return String.format("\\u%04x", (int) ch); return String.format("\\u%04x", (int) ch);
} }
public int getNumber() {
return Integer.valueOf(this.name().replace("SMILEY_", ""));
}
} }

View File

@ -46,7 +46,7 @@ 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 return (endTime.getHour() * TimeHM.MINUTES_PER_HOUR + endTime
.getMinute()) - (startTime.getHour() * TimeHM.MINUTES_PER_HOUR .getMinute()) - (startTime.getHour() * TimeHM.MINUTES_PER_HOUR
+ startTime.getMinute()); + startTime.getMinute());
} }
public TimeHM cloneInstance() { public TimeHM cloneInstance() {

View File

@ -2,11 +2,8 @@ package org.nanoboot.utils.timecalc.utils.common;
import org.nanoboot.utils.timecalc.app.Main; import org.nanoboot.utils.timecalc.app.Main;
import org.nanoboot.utils.timecalc.swing.common.Toaster; import org.nanoboot.utils.timecalc.swing.common.Toaster;
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
import java.awt.Color; import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -110,7 +107,7 @@ public class Utils {
} }
String manifestPath String manifestPath
= classPath.substring(0, classPath.lastIndexOf("!") + 1) = classPath.substring(0, classPath.lastIndexOf("!") + 1)
+ "/META-INF/MANIFEST.MF"; + "/META-INF/MANIFEST.MF";
Manifest manifest; Manifest manifest;
try { try {
manifest = new Manifest(new URL(manifestPath).openStream()); manifest = new Manifest(new URL(manifestPath).openStream());
@ -128,7 +125,8 @@ public class Utils {
.decode(s.getBytes()); .decode(s.getBytes());
} }
public static String readTextFromTextResourceInJar(String pathToFile) throws IOException { public static String readTextFromTextResourceInJar(String pathToFile)
throws IOException {
InputStream inputStream = ClassLoader.getSystemClassLoader(). InputStream inputStream = ClassLoader.getSystemClassLoader().
getSystemResourceAsStream(pathToFile); getSystemResourceAsStream(pathToFile);
InputStreamReader streamReader = new InputStreamReader(inputStream, InputStreamReader streamReader = new InputStreamReader(inputStream,
@ -136,21 +134,25 @@ public class Utils {
BufferedReader in = new BufferedReader(streamReader); BufferedReader in = new BufferedReader(streamReader);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (String line; (line = in.readLine()) != null;) { for (String line; (line = in.readLine()) != null; ) {
sb.append(line).append("\n"); sb.append(line).append("\n");
} }
return sb.toString(); return sb.toString();
} }
public static void showNotification(String message) { public static void showNotification(String message) {
showNotification(message, 0); showNotification(message, 0);
} }
public static void showNotification(String message, int displayTime) { public static void showNotification(String message, int displayTime) {
showNotification(message, displayTime, 0); showNotification(message, displayTime, 0);
} }
public static void showNotification(String message, int displayTime, int height) {
public static void showNotification(String message, int displayTime,
int height) {
Toaster toaster = new Toaster(); Toaster toaster = new Toaster();
toaster.setDisplayTime(displayTime == 0 ? 15000 : displayTime); toaster.setDisplayTime(displayTime == 0 ? 15000 : displayTime);
if(height != 0) { if (height != 0) {
toaster.setToasterHeight(height); toaster.setToasterHeight(height);
} }
toaster.showToaster(message); toaster.showToaster(message);

View File

@ -14,12 +14,13 @@ public class Property<T> {
@Getter @Getter
private final String name; private final String name;
private final List<InvalidationListener> invalidationListeners
= new ArrayList<>();
private final List<ChangeListener<T>> changeListeners =
new ArrayList<ChangeListener<T>>();
private boolean valid = true; private boolean valid = true;
private T value; private T value;
private Property<T> boundToProperty = null; private Property<T> boundToProperty = null;
private final List<InvalidationListener> invalidationListeners
= new ArrayList<>();
private final List<ChangeListener<T>> changeListeners = new ArrayList<ChangeListener<T>>();
private ChangeListener<T> boundChangeListener = null; private ChangeListener<T> boundChangeListener = null;
public Property(String name, T valueIn) { public Property(String name, T valueIn) {
@ -54,10 +55,10 @@ public class Property<T> {
this.boundToProperty = anotherProperty; this.boundToProperty = anotherProperty;
this.boundChangeListener this.boundChangeListener
= (Property<T> p, T oldValue, T newValue) -> { = (Property<T> p, T oldValue, T newValue) -> {
this.markInvalid(); this.markInvalid();
this.fireValueChangedEvent(oldValue); this.fireValueChangedEvent(oldValue);
//System.out.println("bindTo markInvalid " + p.getName() + " " + p.getValue()); //System.out.println("bindTo markInvalid " + p.getName() + " " + p.getValue());
}; };
this.boundToProperty this.boundToProperty
.addListener(boundChangeListener); .addListener(boundChangeListener);