From 5c67a2da5bd7aa6e35fc429812853e3126315d0d Mon Sep 17 00:00:00 2001 From: Robert Vokac Date: Sun, 3 Mar 2024 15:04:36 +0000 Subject: [PATCH] Formatted code --- .../timecalc/app/CommandActionListener.java | 15 +- .../utils/timecalc/app/TimeCalcApp.java | 50 +- .../timecalc/app/TimeCalcConfiguration.java | 256 +++++---- .../utils/timecalc/app/TimeCalcException.java | 2 - .../timecalc/app/TimeCalcKeyAdapter.java | 102 ++-- .../timecalc/app/TimeCalcProperties.java | 57 +- .../utils/timecalc/app/TimeCalcProperty.java | 91 ++-- .../utils/timecalc/entity/Activity.java | 5 +- .../swing/common/ComponentRegistry.java | 9 +- .../timecalc/swing/common/ConfigWindow.java | 507 ++++++++++-------- .../timecalc/swing/common/HelpWindow.java | 9 +- .../timecalc/swing/common/MainWindow.java | 323 +++++++---- .../timecalc/swing/common/SwingUtils.java | 37 +- .../utils/timecalc/swing/common/TButton.java | 24 +- .../utils/timecalc/swing/common/Toaster.java | 19 +- .../timecalc/swing/common/WeatherWindow.java | 2 +- .../utils/timecalc/swing/common/Widget.java | 60 ++- .../timecalc/swing/progress/AnalogClock.java | 128 +++-- .../timecalc/swing/progress/Battery.java | 178 +++--- .../timecalc/swing/progress/DayBattery.java | 3 +- .../timecalc/swing/progress/HourBattery.java | 5 +- .../swing/progress/MinuteBattery.java | 5 +- .../timecalc/swing/progress/MonthBattery.java | 9 +- .../swing/progress/ProgressCircle.java | 5 +- .../swing/progress/ProgressSmileyIcon.java | 19 +- .../swing/progress/ProgressSquare.java | 2 +- .../utils/timecalc/swing/progress/Time.java | 28 +- .../swing/progress/WalkingHumanProgress.java | 27 +- .../timecalc/swing/progress/WeekBattery.java | 7 +- .../timecalc/swing/progress/YearBattery.java | 19 +- .../timecalc/utils/common/FileConstants.java | 15 +- .../utils/timecalc/utils/common/JokesTxt.java | 2 +- .../timecalc/utils/common/ProgressSmiley.java | 11 +- .../utils/timecalc/utils/common/TimeHM.java | 2 +- .../utils/timecalc/utils/common/Utils.java | 18 +- .../timecalc/utils/property/Property.java | 15 +- 36 files changed, 1206 insertions(+), 860 deletions(-) diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/CommandActionListener.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/CommandActionListener.java index a9b6a5b..d1406c0 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/CommandActionListener.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/CommandActionListener.java @@ -2,7 +2,6 @@ package org.nanoboot.utils.timecalc.app; import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.swing.common.Toaster; -import org.nanoboot.utils.timecalc.utils.common.Utils; import javax.swing.JOptionPane; import java.awt.Color; @@ -20,7 +19,8 @@ public class CommandActionListener private final TimeCalcApp timeCalcApp; private final TimeCalcConfiguration timeCalcConfiguration; - public CommandActionListener(TimeCalcApp timeCalcApp, TimeCalcConfiguration timeCalcConfiguration) { + public CommandActionListener(TimeCalcApp timeCalcApp, + TimeCalcConfiguration timeCalcConfiguration) { this.timeCalcApp = timeCalcApp; this.timeCalcConfiguration = timeCalcConfiguration; } @@ -44,14 +44,14 @@ public class CommandActionListener case "color": timeCalcApp.visibilityProperty.setValue( commandsAsArray[1].equals("1") - ? Visibility.STRONGLY_COLORED.name() - : Visibility.WEAKLY_COLORED.name()); + ? Visibility.STRONGLY_COLORED.name() + : Visibility.WEAKLY_COLORED.name()); break; case "gray": timeCalcApp.visibilityProperty.setValue( commandsAsArray[1].equals("1") - ? Visibility.GRAY.name() - : Visibility.WEAKLY_COLORED.name()); + ? Visibility.GRAY.name() + : Visibility.WEAKLY_COLORED.name()); break; case "waves": timeCalcConfiguration.batteryWavesVisibleProperty @@ -75,7 +75,8 @@ public class CommandActionListener t.showToaster(commands.substring(6)); break; case "toasts": - timeCalcConfiguration.notificationsVisibleProperty.setValue(commandsAsArray[1].equals("1")); + timeCalcConfiguration.notificationsVisibleProperty + .setValue(commandsAsArray[1].equals("1")); break; default: JOptionPane.showMessageDialog(null, diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcApp.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcApp.java index 6052fe2..69cf129 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcApp.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcApp.java @@ -18,7 +18,7 @@ public class TimeCalcApp { public StringProperty visibilityProperty = new StringProperty("timeCalcApp.visibilityProperty", - Visibility.WEAKLY_COLORED.name()); + Visibility.WEAKLY_COLORED.name()); private long startNanoTime = 0l; public void start(String[] args) throws IOException { @@ -34,32 +34,32 @@ public class TimeCalcApp { FileConstants.OVERTIME_TXT); String newStartTime = test ? (oldStartTime != null ? oldStartTime - : Constants.DEFAULT_START_TIME) - : (String) JOptionPane.showInputDialog( - null, - "Start Time:", - "Start Time", - JOptionPane.PLAIN_MESSAGE, - null, - null, - oldStartTime == null - ? Constants.DEFAULT_START_TIME - : oldStartTime - ); + : Constants.DEFAULT_START_TIME) + : (String) JOptionPane.showInputDialog( + null, + "Start Time:", + "Start Time", + JOptionPane.PLAIN_MESSAGE, + null, + null, + oldStartTime == null + ? Constants.DEFAULT_START_TIME + : oldStartTime + ); String newOvertime = test ? (oldOvertime != null ? oldOvertime - : Constants.DEFAULT_OVERTIME) - : (String) JOptionPane.showInputDialog( - null, - "Overtime:", - "Overtime", - JOptionPane.PLAIN_MESSAGE, - null, - null, - oldOvertime == null - ? Constants.DEFAULT_OVERTIME - : oldOvertime - ); + : Constants.DEFAULT_OVERTIME) + : (String) JOptionPane.showInputDialog( + null, + "Overtime:", + "Overtime", + JOptionPane.PLAIN_MESSAGE, + null, + null, + oldOvertime == null + ? Constants.DEFAULT_OVERTIME + : oldOvertime + ); Utils.writeTextToFile(FileConstants.STARTTIME_TXT, newStartTime); Utils.writeTextToFile(FileConstants.OVERTIME_TXT, newOvertime); diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcConfiguration.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcConfiguration.java index 7912779..1a33650 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcConfiguration.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcConfiguration.java @@ -16,202 +16,225 @@ import java.util.Properties; */ public class TimeCalcConfiguration { - public final StringProperty visibilityDefaultProperty = new StringProperty(TimeCalcProperty.VISIBILITY_DEFAULT - .getKey()); + public final StringProperty visibilityDefaultProperty = + new StringProperty(TimeCalcProperty.VISIBILITY_DEFAULT + .getKey()); public final BooleanProperty visibilitySupportedColoredProperty = new BooleanProperty(TimeCalcProperty.VISIBILITY_SUPPORTED_COLORED - .getKey()); + .getKey()); // - public final BooleanProperty clockVisibleProperty + public final BooleanProperty clockVisibleProperty = new BooleanProperty(TimeCalcProperty.CLOCK_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty clockHandsLongVisibleProperty = new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_LONG_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty clockHandsColoredProperty = new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_COLORED - .getKey()); + .getKey()); public final BooleanProperty clockHandsHourVisibleProperty - = new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_HOUR_VISIBLE.getKey()); + = new BooleanProperty( + TimeCalcProperty.CLOCK_HANDS_HOUR_VISIBLE.getKey()); public final BooleanProperty clockHandsMinuteVisibleProperty = new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_MINUTE_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty clockHandsSecondVisibleProperty = new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_SECOND_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty clockHandsMillisecondVisibleProperty - = new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_MILLISECOND_VISIBLE + = + new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_MILLISECOND_VISIBLE .getKey()); public final BooleanProperty clockBorderVisibleProperty = new BooleanProperty(TimeCalcProperty.CLOCK_BORDER_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty clockBorderOnlyHoursProperty = new BooleanProperty(TimeCalcProperty.CLOCK_BORDER_ONLY_HOURS - .getKey()); + .getKey()); public final BooleanProperty clockNumbersVisibleProperty = new BooleanProperty(TimeCalcProperty.CLOCK_NUMBERS_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty clockCircleVisibleProperty = new BooleanProperty(TimeCalcProperty.CLOCK_CIRCLE_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty clockCircleStrongBorderProperty = new BooleanProperty(TimeCalcProperty.CLOCK_CIRCLE_STRONG_BORDER - .getKey()); + .getKey()); public final StringProperty clockCircleBorderColorProperty = new StringProperty(TimeCalcProperty.CLOCK_CIRCLE_BORDER_COLOR - .getKey()); + .getKey()); public final BooleanProperty clockCentreCircleVisibleProperty = new BooleanProperty(TimeCalcProperty.CLOCK_CENTRE_CIRCLE_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty clockCentreCircleBlackProperty = new BooleanProperty(TimeCalcProperty.CLOCK_CENTRE_CIRCLE_BLACK - .getKey()); - public final BooleanProperty clockProgressVisibleOnlyIfMouseMovingOverProperty - = new BooleanProperty(TimeCalcProperty.CLOCK_PROGRESS_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER + .getKey()); + public final BooleanProperty + clockProgressVisibleOnlyIfMouseMovingOverProperty + = new BooleanProperty( + TimeCalcProperty.CLOCK_PROGRESS_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER .getKey()); 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()); // public final BooleanProperty batteryWavesVisibleProperty = new BooleanProperty(TimeCalcProperty.BATTERY_WAVES_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty batteryCircleProgressProperty - = new BooleanProperty(TimeCalcProperty.BATTERY_CIRCLE_PROGRESS_VISIBLE + = + new BooleanProperty(TimeCalcProperty.BATTERY_CIRCLE_PROGRESS_VISIBLE .getKey()); public final BooleanProperty batteryPercentProgressProperty - = new BooleanProperty(TimeCalcProperty.BATTERY_PERCENT_PROGRESS_VISIBLE + = new BooleanProperty( + TimeCalcProperty.BATTERY_PERCENT_PROGRESS_VISIBLE .getKey()); public final BooleanProperty batteryChargingCharacterVisibleProperty - = new BooleanProperty(TimeCalcProperty.BATTERY_CHARGING_CHARACTER_VISIBLE + = new BooleanProperty( + TimeCalcProperty.BATTERY_CHARGING_CHARACTER_VISIBLE .getKey()); public final BooleanProperty batteryNameVisibleProperty = new BooleanProperty(TimeCalcProperty.BATTERY_NAME_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty batteryLabelVisibleProperty = new BooleanProperty(TimeCalcProperty.BATTERY_LABEL_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty batteryVisibleProperty = new BooleanProperty(TimeCalcProperty.BATTERY_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty batteryMinuteVisibleProperty = new BooleanProperty(TimeCalcProperty.BATTERY_MINUTE_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty batteryHourVisibleProperty = new BooleanProperty(TimeCalcProperty.BATTERY_HOUR_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty batteryDayVisibleProperty = new BooleanProperty(TimeCalcProperty.BATTERY_DAY_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty batteryWeekVisibleProperty = new BooleanProperty(TimeCalcProperty.BATTERY_WEEK_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty batteryMonthVisibleProperty = new BooleanProperty(TimeCalcProperty.BATTERY_MONTH_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty batteryYearVisibleProperty = new BooleanProperty(TimeCalcProperty.BATTERY_YEAR_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty batteryBlinkingIfCriticalLowVisibleProperty - = new BooleanProperty(TimeCalcProperty.BATTERY_BLINKING_IF_CRITICAL_LOW + = new BooleanProperty( + TimeCalcProperty.BATTERY_BLINKING_IF_CRITICAL_LOW .getKey()); - + public final BooleanProperty jokesVisibleProperty = new BooleanProperty(TimeCalcProperty.JOKES_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty commandsVisibleProperty = new BooleanProperty(TimeCalcProperty.COMMANDS_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty notificationsVisibleProperty = new BooleanProperty(TimeCalcProperty.NOTIFICATIONS_VISIBLE - .getKey()); + .getKey()); public final BooleanProperty smileysVisibleProperty = new BooleanProperty(TimeCalcProperty.SMILEYS_VISIBLE.getKey()); 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 = new BooleanProperty(TimeCalcProperty.SMILEYS_COLORED.getKey()); - + public final BooleanProperty squareVisibleProperty = new BooleanProperty(TimeCalcProperty.SQUARE_VISIBLE.getKey()); public final BooleanProperty circleVisibleProperty = new BooleanProperty(TimeCalcProperty.CIRCLE_VISIBLE.getKey()); public final BooleanProperty walkingHumanVisibleProperty - = new BooleanProperty(TimeCalcProperty.WALKING_HUMAN_VISIBLE.getKey()); + = new BooleanProperty( + TimeCalcProperty.WALKING_HUMAN_VISIBLE.getKey()); public final StringProperty mainWindowCustomTitleProperty - = new StringProperty(TimeCalcProperty.MAIN_WINDOW_CUSTOM_TITLE.getKey()); + = new StringProperty( + TimeCalcProperty.MAIN_WINDOW_CUSTOM_TITLE.getKey()); public final StringProperty profileNameProperty = new StringProperty(TimeCalcProperty.PROFILE_NAME.getKey()); - private final Map mapOfProperties = new HashMap<>(); - private List allProperties = new ArrayList<>(); + private final Map mapOfProperties = + new HashMap<>(); + private final List allProperties = new ArrayList<>(); private TimeCalcProperties timeCalcProperties; public TimeCalcConfiguration() { - for (Property p : new Property[]{ - visibilityDefaultProperty, - visibilitySupportedColoredProperty, - clockVisibleProperty, - clockHandsLongVisibleProperty, - clockHandsColoredProperty, - clockHandsHourVisibleProperty, - clockHandsMinuteVisibleProperty, - clockHandsSecondVisibleProperty, - clockHandsMillisecondVisibleProperty, - clockBorderVisibleProperty, - clockBorderOnlyHoursProperty, - clockNumbersVisibleProperty, - clockCircleVisibleProperty, - clockCircleStrongBorderProperty, - clockCircleBorderColorProperty, - clockCentreCircleVisibleProperty, - clockCentreCircleBlackProperty, - clockProgressVisibleOnlyIfMouseMovingOverProperty, - clockDateVisibleOnlyIfMouseMovingOverProperty, - batteryWavesVisibleProperty, - batteryCircleProgressProperty, - batteryPercentProgressProperty, - batteryChargingCharacterVisibleProperty, - batteryNameVisibleProperty, - batteryLabelVisibleProperty, - batteryVisibleProperty, - batteryMinuteVisibleProperty, - batteryHourVisibleProperty, - batteryDayVisibleProperty, - batteryWeekVisibleProperty, - batteryMonthVisibleProperty, - batteryYearVisibleProperty, - batteryBlinkingIfCriticalLowVisibleProperty, - jokesVisibleProperty, - commandsVisibleProperty, - notificationsVisibleProperty, - smileysVisibleProperty, - smileysVisibleOnlyIfMouseMovingOverProperty, - smileysColoredProperty, - squareVisibleProperty, - circleVisibleProperty, - walkingHumanVisibleProperty, - mainWindowCustomTitleProperty, - profileNameProperty, + for (Property p : new Property[] { + visibilityDefaultProperty, + visibilitySupportedColoredProperty, + clockVisibleProperty, + clockHandsLongVisibleProperty, + clockHandsColoredProperty, + clockHandsHourVisibleProperty, + clockHandsMinuteVisibleProperty, + clockHandsSecondVisibleProperty, + clockHandsMillisecondVisibleProperty, + clockBorderVisibleProperty, + clockBorderOnlyHoursProperty, + clockNumbersVisibleProperty, + clockCircleVisibleProperty, + clockCircleStrongBorderProperty, + clockCircleBorderColorProperty, + clockCentreCircleVisibleProperty, + clockCentreCircleBlackProperty, + clockProgressVisibleOnlyIfMouseMovingOverProperty, + clockDateVisibleOnlyIfMouseMovingOverProperty, + batteryWavesVisibleProperty, + batteryCircleProgressProperty, + batteryPercentProgressProperty, + batteryChargingCharacterVisibleProperty, + batteryNameVisibleProperty, + batteryLabelVisibleProperty, + batteryVisibleProperty, + batteryMinuteVisibleProperty, + batteryHourVisibleProperty, + batteryDayVisibleProperty, + batteryWeekVisibleProperty, + batteryMonthVisibleProperty, + batteryYearVisibleProperty, + batteryBlinkingIfCriticalLowVisibleProperty, + jokesVisibleProperty, + commandsVisibleProperty, + notificationsVisibleProperty, + smileysVisibleProperty, + smileysVisibleOnlyIfMouseMovingOverProperty, + smileysColoredProperty, + squareVisibleProperty, + circleVisibleProperty, + walkingHumanVisibleProperty, + mainWindowCustomTitleProperty, + profileNameProperty, }) { 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 -> { - - batteryMinuteVisibleProperty.setValue(batteryVisibleProperty.getValue()); - batteryHourVisibleProperty.setValue(batteryVisibleProperty.getValue()); - batteryDayVisibleProperty.setValue(batteryVisibleProperty.getValue()); - batteryWeekVisibleProperty.setValue(batteryVisibleProperty.getValue()); - batteryMonthVisibleProperty.setValue(batteryVisibleProperty.getValue()); - batteryYearVisibleProperty.setValue(batteryVisibleProperty.getValue()); + + batteryMinuteVisibleProperty + .setValue(batteryVisibleProperty.getValue()); + batteryHourVisibleProperty + .setValue(batteryVisibleProperty.getValue()); + batteryDayVisibleProperty + .setValue(batteryVisibleProperty.getValue()); + batteryWeekVisibleProperty + .setValue(batteryVisibleProperty.getValue()); + batteryMonthVisibleProperty + .setValue(batteryVisibleProperty.getValue()); + batteryYearVisibleProperty + .setValue(batteryVisibleProperty.getValue()); }); } public Property getProperty(TimeCalcProperty 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); } @@ -219,11 +242,14 @@ public class TimeCalcConfiguration { public void saveToTimeCalcProperties() { System.out.println("Going to save properties."); 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(); - this.allProperties.stream().forEach(p -> properties.put(p.getName(), p.getValue())); - this.timeCalcProperties.save(properties, this.profileNameProperty.getValue()); + this.allProperties.stream() + .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; for (Property p : allProperties) { if (p instanceof BooleanProperty) { - ((BooleanProperty) p).setValue(timeCalcProperties.getBooleanProperty(TimeCalcProperty.forKey(p.getName()))); + p.setValue(timeCalcProperties + .getBooleanProperty( + TimeCalcProperty.forKey(p.getName()))); continue; } - if (p.getName().equals(TimeCalcProperty.VISIBILITY_DEFAULT.name())) { - visibilityDefaultProperty.setValue(timeCalcProperties.getStringProperty(TimeCalcProperty.VISIBILITY_DEFAULT)); + if (p.getName() + .equals(TimeCalcProperty.VISIBILITY_DEFAULT.name())) { + visibilityDefaultProperty.setValue(timeCalcProperties + .getStringProperty( + TimeCalcProperty.VISIBILITY_DEFAULT)); continue; } if (p instanceof StringProperty) { - ((StringProperty) p).setValue(timeCalcProperties.getStringProperty(TimeCalcProperty.forKey(p.getName()))); + p.setValue(timeCalcProperties + .getStringProperty( + TimeCalcProperty.forKey(p.getName()))); continue; } - throw new TimeCalcException("Unsupported Property class: " + p.getClass().getName()); + throw new TimeCalcException( + "Unsupported Property class: " + p.getClass().getName()); } -// for(Property p:allProperties) { -// System.out.println(p.getName() + "=" + p.getValue()); -// } + // for(Property p:allProperties) { + // System.out.println(p.getName() + "=" + p.getValue()); + // } } } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcException.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcException.java index ef77d5e..d8ce099 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcException.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcException.java @@ -1,7 +1,5 @@ package org.nanoboot.utils.timecalc.app; -import java.io.IOException; - /** * @author Robert Vokac * @since 21.02.2024 diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcKeyAdapter.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcKeyAdapter.java index 2cec3d9..ab50b7d 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcKeyAdapter.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcKeyAdapter.java @@ -35,7 +35,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter { public void keyPressed(KeyEvent e) { boolean onlyGreyOrNone = timeCalcConfiguration.visibilitySupportedColoredProperty - .isDisabled(); + .isDisabled(); Visibility visibility = Visibility .valueOf(timeCalcApp.visibilityProperty.getValue()); @@ -52,9 +52,10 @@ public class TimeCalcKeyAdapter extends KeyAdapter { keyCode == KeyEvent.VK_8 || keyCode == KeyEvent.VK_9; - - if(numberKeyWasPressed && !FileConstants.TIME_CALC_PROFILES_TXT_FILE.exists()) { - Utils.showNotification("Warning: There is no profile assigned to Key with number, you pressed."); + if (numberKeyWasPressed && !FileConstants.TIME_CALC_PROFILES_TXT_FILE + .exists()) { + Utils.showNotification( + "Warning: There is no profile assigned to Key with number, you pressed."); } switch (keyCode) { @@ -207,59 +208,97 @@ public class TimeCalcKeyAdapter extends KeyAdapter { } case KeyEvent.VK_F: { - if(FileConstants.TIME_CALC_PROFILES_TXT_FILE.exists()) { + if (FileConstants.TIME_CALC_PROFILES_TXT_FILE.exists()) { 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) { ioException.printStackTrace(); - Utils.showNotification("Error: " + ioException.getMessage()); + Utils.showNotification( + "Error: " + ioException.getMessage()); } } 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; } case KeyEvent.VK_Q: { - timeCalcConfiguration.squareVisibleProperty.flip();break; + timeCalcConfiguration.squareVisibleProperty.flip(); + break; } case KeyEvent.VK_L: { - timeCalcConfiguration.circleVisibleProperty.flip();break; + timeCalcConfiguration.circleVisibleProperty.flip(); + break; } case KeyEvent.VK_Y: { - timeCalcConfiguration.smileysVisibleOnlyIfMouseMovingOverProperty.flip();break; + timeCalcConfiguration.smileysVisibleOnlyIfMouseMovingOverProperty + .flip(); + break; } 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(); try { - properties.load(new FileInputStream(FileConstants.TIME_CALC_PROFILES_TXT_FILE)); + properties.load(new FileInputStream( + FileConstants.TIME_CALC_PROFILES_TXT_FILE)); } catch (IOException ioException) { ioException.printStackTrace(); } int profileNumber = 0; - switch(keyCode) { - case KeyEvent.VK_0: profileNumber = 0;break; - case KeyEvent.VK_1: profileNumber = 1;break; - case KeyEvent.VK_2: profileNumber = 2;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; + switch (keyCode) { + case KeyEvent.VK_0: + profileNumber = 0; + break; + case KeyEvent.VK_1: + profileNumber = 1; + break; + case KeyEvent.VK_2: + profileNumber = 2; + 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); - if(properties.containsKey(key)) { + if (properties.containsKey(key)) { String profileName = (String) properties.get(key); - if(profileName.equals( timeCalcConfiguration.profileNameProperty)) { - Utils.showNotification("Profile \"" + profileName + "\" is already active. Nothing to do", 5000); + if (profileName + .equals(timeCalcConfiguration.profileNameProperty)) { + Utils.showNotification("Profile \"" + profileName + + "\" is already active. Nothing to do", + 5000); } else { Utils.showNotification("Info: Changing profile to: " + (( profileName.isEmpty() ? "{Default profile}" : @@ -270,11 +309,12 @@ public class TimeCalcKeyAdapter extends KeyAdapter { } } 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(); } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperties.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperties.java index b72357c..3646bbe 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperties.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperties.java @@ -19,7 +19,6 @@ import java.util.Properties; */ public class TimeCalcProperties { - private static TimeCalcProperties INSTANCE; private final Properties properties = new Properties(); @@ -29,14 +28,17 @@ public class TimeCalcProperties { System.out.println("Loading configuration - start"); String profileName = ""; try { - profileName = FileConstants.TIME_CALC_CURRENT_PROFILE_TXT_FILE.exists() ? Utils.readTextFromFile( - FileConstants.TIME_CALC_CURRENT_PROFILE_TXT_FILE) : ""; + profileName = + FileConstants.TIME_CALC_CURRENT_PROFILE_TXT_FILE.exists() ? + Utils.readTextFromFile( + FileConstants.TIME_CALC_CURRENT_PROFILE_TXT_FILE) : + ""; } catch (IOException e) { e.printStackTrace(); throw new TimeCalcException(e); } File file = getFile(profileName); - if(file.exists()) { + if (file.exists()) { try { this.properties.load(new FileInputStream(file)); } catch (IOException e) { @@ -55,7 +57,8 @@ public class TimeCalcProperties { .filter(l -> l.contains("=")) .forEach(l -> { 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) { @@ -81,8 +84,11 @@ public class TimeCalcProperties { } private String getDefaultStringValue(TimeCalcProperty timeCalcProperty) { - if (!defaultProperties.containsKey((String) timeCalcProperty.getKey())) { - throw new TimeCalcException("timecalc-default.conf is missing key: \"" + timeCalcProperty.getKey() + "\""); + if (!defaultProperties + .containsKey(timeCalcProperty.getKey())) { + throw new TimeCalcException( + "timecalc-default.conf is missing key: \"" + + timeCalcProperty.getKey() + "\""); } return defaultProperties.get(timeCalcProperty.getKey()); } @@ -97,7 +103,8 @@ public class TimeCalcProperties { } public String getStringProperty(TimeCalcProperty timeCalcProperty) { - return getStringProperty(timeCalcProperty, getDefaultStringValue(timeCalcProperty)); + return getStringProperty(timeCalcProperty, + getDefaultStringValue(timeCalcProperty)); } private String getStringProperty(TimeCalcProperty timeCalcProperty, @@ -110,7 +117,8 @@ public class TimeCalcProperties { } private String getVisibilityProperty(TimeCalcProperty timeCalcProperty) { - return getStringProperty(timeCalcProperty, Visibility.STRONGLY_COLORED.name()); + return getStringProperty(timeCalcProperty, + Visibility.STRONGLY_COLORED.name()); } private void setBooleanProperty(TimeCalcProperty timeCalcProperty, @@ -133,15 +141,15 @@ public class TimeCalcProperties { public void save(Properties properties, String profileName) { properties.entrySet().stream().forEach(e - -> { - if (this.properties.containsKey(e.getKey())) { - this.properties - .replace(e.getKey(), e.getValue().toString()); - } else { - this.properties - .put(e.getKey(), e.getValue().toString()); - } - } + -> { + if (this.properties.containsKey(e.getKey())) { + this.properties + .replace(e.getKey(), e.getValue().toString()); + } else { + this.properties + .put(e.getKey(), e.getValue().toString()); + } + } ); File file = getFile(profileName); try { @@ -153,23 +161,26 @@ public class TimeCalcProperties { "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) { return profileName == null || profileName.isEmpty() ? 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) { File file = getFile(profileName); - if(!file.exists()) { - Utils.showNotification("There is no profile with name: " + profileName); + if (!file.exists()) { + Utils.showNotification( + "There is no profile with name: " + profileName); return; } try { - this.properties.load( new FileInputStream(file)); + this.properties.load(new FileInputStream(file)); } catch (IOException e) { System.err.println(e); } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperty.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperty.java index d5724f3..c08e686 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperty.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcProperty.java @@ -12,36 +12,52 @@ import java.util.Optional; */ public enum TimeCalcProperty { 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_HANDS_LONG_VISIBLE("clock.hands.long.visible", "Clock : Long Hands"), CLOCK_HANDS_COLORED("clock.hands.colored", "Clock : Colored Hands"), CLOCK_HANDS_HOUR_VISIBLE("clock.hands.hour.visible", "Clock : Hour hand"), - CLOCK_HANDS_MINUTE_VISIBLE("clock.hands.minute.visible", "Clock : Minute hand"), - CLOCK_HANDS_SECOND_VISIBLE("clock.hands.second.visible", "Clock : Second hand"), - CLOCK_HANDS_MILLISECOND_VISIBLE("clock.hands.millisecond.visible", "Clock : Millisecond hand"), + CLOCK_HANDS_MINUTE_VISIBLE("clock.hands.minute.visible", + "Clock : Minute 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_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_CIRCLE_VISIBLE("clock.circle.visible", "Clock : Circle"), - 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.strong-border", + "Clock : Circle : Strong border"), + CLOCK_CIRCLE_BORDER_COLOR("clock.circle.border-color", + "Clock : Circle : Border color", Color.class), - CLOCK_CENTRE_CIRCLE_VISIBLE("clock.centre-circle.visible", "Clock : Centre circle"), - CLOCK_CENTRE_CIRCLE_BLACK("clock.centre-circle.black", "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"), - + CLOCK_CENTRE_CIRCLE_VISIBLE("clock.centre-circle.visible", + "Clock : Centre circle"), + CLOCK_CENTRE_CIRCLE_BLACK("clock.centre-circle.black", + "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_CIRCLE_PROGRESS_VISIBLE("battery.circle-progress.visible", "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_CIRCLE_PROGRESS_VISIBLE("battery.circle-progress.visible", + "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_NAME_VISIBLE("battery.name.visible", "Battery : Name"), BATTERY_LABEL_VISIBLE("battery.label.visible", "Battery : Label"), - + BATTERY_VISIBLE("battery.visible", "Battery"), BATTERY_MINUTE_VISIBLE("battery.minute.visible", "Battery : Minute"), BATTERY_HOUR_VISIBLE("battery.hour.visible", "Battery : Hour"), @@ -49,20 +65,23 @@ public enum TimeCalcProperty { BATTERY_WEEK_VISIBLE("battery.week.visible", "Battery : Week"), BATTERY_MONTH_VISIBLE("battery.month.visible", "Battery : Month"), 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"), COMMANDS_VISIBLE("commands.visible", "Commands"), NOTIFICATIONS_VISIBLE("notifications.visible", "Notifications"), 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"), - - + SQUARE_VISIBLE("square.visible", "Square"), CIRCLE_VISIBLE("circle.visible", "Circle"), 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"); @Getter @@ -72,18 +91,6 @@ public enum TimeCalcProperty { @Getter private final Class clazz; - public static TimeCalcProperty forKey(String key) { - Optional 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) { this.key = key; this.description = description; @@ -94,4 +101,18 @@ public enum TimeCalcProperty { this(key, description, Boolean.class); } + public static TimeCalcProperty forKey(String key) { + Optional 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; + } + } + } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/entity/Activity.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/entity/Activity.java index 800f7be..562cbb4 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/entity/Activity.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/entity/Activity.java @@ -30,7 +30,10 @@ public class Activity { } 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; } } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/ComponentRegistry.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/ComponentRegistry.java index 455738e..61e9c37 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/ComponentRegistry.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/ComponentRegistry.java @@ -29,19 +29,20 @@ public class ComponentRegistry { add(c); } } + public void setVisible(boolean b) { setVisible(null, b); } public void setVisible(Predicate predicate, boolean b) { for (T c : set) { - if(c instanceof TButton) { - if(!MainWindow.hideShowCheckBox.isSelected() && b) { + if (c instanceof TButton) { + if (!MainWindow.hideShowCheckBox.isSelected() && b) { continue; } } - if(predicate != null) { - if(!predicate.test(c)) { + if (predicate != null) { + if (!predicate.test(c)) { continue; } } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/ConfigWindow.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/ConfigWindow.java index e74e834..828a01a 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/ConfigWindow.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/ConfigWindow.java @@ -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.StringProperty; +import javax.swing.Box; +import javax.swing.BoxLayout; import javax.swing.JCheckBox; import javax.swing.JColorChooser; import javax.swing.JComboBox; import javax.swing.JComponent; 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.Dimension; import java.awt.Font; @@ -24,15 +33,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; 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 @@ -42,149 +42,184 @@ public class ConfigWindow extends TWindow { public static final int WIDTH1 = 600; 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 = "---"; + 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 int currentY = SwingUtils.MARGIN; - private List propertiesList = new ArrayList<>(); - private Map 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 int currentY = SwingUtils.MARGIN; + private final List propertiesList = new ArrayList<>(); + private final Map 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) { this.timeCalcConfiguration = timeCalcConfiguration; setTitle("Configuration"); this.setSize(800, 800); - + 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(); - final BoxLayout boxLayout = new BoxLayout(panelInsideScrollPane, BoxLayout.Y_AXIS); + final BoxLayout boxLayout = + new BoxLayout(panelInsideScrollPane, BoxLayout.Y_AXIS); panelInsideScrollPane.setAlignmentX(LEFT_ALIGNMENT); mainPanel.setAlignmentX(LEFT_ALIGNMENT); - + panelInsideScrollPane.setLayout(boxLayout); - panelInsideScrollPane.setMinimumSize(new Dimension(Integer.MAX_VALUE, 400)); - + panelInsideScrollPane + .setMinimumSize(new Dimension(Integer.MAX_VALUE, 400)); + JScrollPane scrollPane = new JScrollPane(panelInsideScrollPane); - scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - scrollPane.setPreferredSize(new Dimension(getWidth() - 50, getHeight() - 100)); + scrollPane.setVerticalScrollBarPolicy( + JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + scrollPane.setPreferredSize( + new Dimension(getWidth() - 50, getHeight() - 100)); scrollPane.setWheelScrollingEnabled(true); scrollPane.setBorder(null); -// mainPanel.setBackground(Color.red); -// scrollPane.setBackground(Color.green); -// panelInsideScrollPane.setBackground(Color.blue); - + // mainPanel.setBackground(Color.red); + // scrollPane.setBackground(Color.green); + // panelInsideScrollPane.setBackground(Color.blue); + add(mainPanel); //mainPanel.setLayout(null); mainPanel.add(enableAsMuchAsPossible); - enableAsMuchAsPossible.setBounds(SwingUtils.MARGIN, SwingUtils.MARGIN, 250, - HEIGHT1); - + enableAsMuchAsPossible + .setBounds(SwingUtils.MARGIN, SwingUtils.MARGIN, 250, + HEIGHT1); + 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); - 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); - - for(boolean enable:new boolean[]{true, false}) { - TButton button = enable ? enableAsMuchAsPossible : disableAsMuchAsPossible; - + + for (boolean enable : new boolean[] {true, false}) { + TButton button = + enable ? enableAsMuchAsPossible : disableAsMuchAsPossible; + button.addActionListener(e -> { - visibilityDefaultProperty.setSelectedItem(Visibility.STRONGLY_COLORED.name()); - clockVisibleProperty.setSelected(true); - clockHandsHourVisibleProperty.setSelected(enable); + visibilityDefaultProperty + .setSelectedItem(Visibility.STRONGLY_COLORED.name()); + clockVisibleProperty.setSelected(true); + clockHandsHourVisibleProperty.setSelected(enable); clockHandsMinuteVisibleProperty.setSelected(enable); clockHandsSecondVisibleProperty.setSelected(enable); clockHandsMillisecondVisibleProperty.setSelected(enable); @@ -195,14 +230,18 @@ public class ConfigWindow extends TWindow { clockNumbersVisibleProperty.setSelected(enable); clockCircleVisibleProperty.setSelected(enable); clockCircleStrongBorderProperty.setSelected(!enable); - - clockCircleBorderColorProperty.setColor(enable ? Color.BLUE : Color.BLACK); - timeCalcConfiguration.clockCircleBorderColorProperty.setValue(enable ? "0,0,255" : "0,0,0"); - + + clockCircleBorderColorProperty + .setColor(enable ? Color.BLUE : Color.BLACK); + timeCalcConfiguration.clockCircleBorderColorProperty + .setValue(enable ? "0,0,255" : "0,0,0"); + clockCentreCircleVisibleProperty.setSelected(enable); clockCentreCircleBlackProperty.setSelected(!enable); - clockProgressVisibleOnlyIfMouseMovingOverProperty.setSelected(!enable); - clockDateVisibleOnlyIfMouseMovingOverProperty.setSelected(false); + clockProgressVisibleOnlyIfMouseMovingOverProperty + .setSelected(!enable); + clockDateVisibleOnlyIfMouseMovingOverProperty + .setSelected(false); batteryVisibleProperty.setSelected(true); batteryWavesVisibleProperty.setSelected(enable); batteryCircleProgressVisibleProperty.setSelected(enable); @@ -217,20 +256,21 @@ public class ConfigWindow extends TWindow { batteryMonthVisibleProperty.setSelected(enable); batteryYearVisibleProperty.setSelected(enable); batteryBlinkingIfCriticalLowVisibleProperty.setSelected(enable); -// + // jokesVisibleProperty.setSelected(true); commandsVisibleProperty.setSelected(enable); notificationsVisibleProperty.setSelected(enable); smileysVisibleProperty.setSelected(enable); smileysColoredProperty.setSelected(enable); - smileysVisibleOnlyIfMouseMovingOverProperty.setSelected(!enable); + smileysVisibleOnlyIfMouseMovingOverProperty + .setSelected(!enable); squareVisibleProperty.setSelected(enable); circleVisibleProperty.setSelected(enable); walkingHumanVisibleProperty.setSelected(enable); MainWindow.hideShowCheckBox.setSelected(enable); - }); + }); } - + propertiesList.addAll(Arrays.asList(visibilityDefaultProperty, visibilitySupportedColoredProperty, clockVisibleProperty, @@ -280,32 +320,46 @@ public class ConfigWindow extends TWindow { propertiesList.stream().forEach(p -> { p.setAlignmentX(LEFT_ALIGNMENT); if (p == visibilityDefaultProperty) { - p.putClientProperty(CLIENT_PROPERTY_KEY, TimeCalcProperty.VISIBILITY_DEFAULT.getKey()); - addToNextRow(new JLabel(TimeCalcProperty.VISIBILITY_DEFAULT.getDescription())); + p.putClientProperty(CLIENT_PROPERTY_KEY, + TimeCalcProperty.VISIBILITY_DEFAULT.getKey()); + addToNextRow(new JLabel( + TimeCalcProperty.VISIBILITY_DEFAULT.getDescription())); } if (p == clockCircleBorderColorProperty) { - p.putClientProperty(CLIENT_PROPERTY_KEY, TimeCalcProperty.CLOCK_CIRCLE_BORDER_COLOR.getKey()); - addToNextRow(new JLabel(TimeCalcProperty.CLOCK_CIRCLE_BORDER_COLOR.getDescription().replace("Clock : ", ""))); + p.putClientProperty(CLIENT_PROPERTY_KEY, + TimeCalcProperty.CLOCK_CIRCLE_BORDER_COLOR.getKey()); + addToNextRow(new JLabel( + TimeCalcProperty.CLOCK_CIRCLE_BORDER_COLOR + .getDescription().replace("Clock : ", ""))); } if (p == mainWindowCustomTitleProperty) { - addToNextRow(new JLabel(TimeCalcProperty.MAIN_WINDOW_CUSTOM_TITLE.getDescription())); - p.putClientProperty(CLIENT_PROPERTY_KEY, TimeCalcProperty.MAIN_WINDOW_CUSTOM_TITLE.getKey()); + addToNextRow(new JLabel( + TimeCalcProperty.MAIN_WINDOW_CUSTOM_TITLE + .getDescription())); + p.putClientProperty(CLIENT_PROPERTY_KEY, + TimeCalcProperty.MAIN_WINDOW_CUSTOM_TITLE.getKey()); } if (p == profileNameProperty) { - addToNextRow(new JLabel(TimeCalcProperty.PROFILE_NAME.getDescription())); - p.putClientProperty(CLIENT_PROPERTY_KEY, TimeCalcProperty.PROFILE_NAME.getKey()); + addToNextRow(new JLabel( + TimeCalcProperty.PROFILE_NAME.getDescription())); + p.putClientProperty(CLIENT_PROPERTY_KEY, + TimeCalcProperty.PROFILE_NAME.getKey()); } if (p instanceof JComboBox) { JComboBox jComboBox = ((JComboBox) p); jComboBox.setMaximumSize(new Dimension(150, 25)); - String timeCalcPropertyKey = (String) jComboBox.getClientProperty( - CLIENT_PROPERTY_KEY); + String timeCalcPropertyKey = + (String) jComboBox.getClientProperty( + CLIENT_PROPERTY_KEY); TimeCalcProperty timeCalcProperty = TimeCalcProperty.forKey(timeCalcPropertyKey); - jComboBox.setSelectedItem(timeCalcConfiguration.getProperty(timeCalcProperty).getValue()); + jComboBox.setSelectedItem( + timeCalcConfiguration.getProperty(timeCalcProperty) + .getValue()); jComboBox.addActionListener(e -> { - ((StringProperty) timeCalcConfiguration.getProperty(timeCalcProperty)) + timeCalcConfiguration + .getProperty(timeCalcProperty) .setValue( (String) jComboBox.getSelectedItem()); }); @@ -314,7 +368,8 @@ public class ConfigWindow extends TWindow { if (p instanceof JCheckBox) { JCheckBox checkBox = ((JCheckBox) p); String timeCalcPropertyKey = checkBox.getText(); - checkBox.putClientProperty(CLIENT_PROPERTY_KEY, timeCalcPropertyKey); + checkBox.putClientProperty(CLIENT_PROPERTY_KEY, + timeCalcPropertyKey); TimeCalcProperty timeCalcProperty = TimeCalcProperty.forKey(timeCalcPropertyKey); @@ -322,8 +377,9 @@ public class ConfigWindow extends TWindow { BooleanProperty property = (BooleanProperty) timeCalcConfiguration - .getProperty(timeCalcProperty); - property.addListener(e -> checkBox.setSelected(property.isEnabled())); + .getProperty(timeCalcProperty); + property.addListener( + e -> checkBox.setSelected(property.isEnabled())); checkBox.setSelected(property.isEnabled()); checkBox.addItemListener(e -> { property @@ -331,36 +387,41 @@ public class ConfigWindow extends TWindow { }); String[] array = checkBox.getText().split(" : "); String groupName = array[0]; - if(groupName.equals("Clock") ||groupName.equals("Battery") ||groupName.equals("Smileys")) { - - checkBox.setText(array.length > 1 ? (checkBox.getText().substring(groupName.length() + 3)) : "Visible"); - if(array.length == 1) { - panelInsideScrollPane.add(new JSeparator(SwingConstants.VERTICAL)); + if (groupName.equals("Clock") || groupName.equals("Battery") + || groupName.equals("Smileys")) { + + checkBox.setText(array.length > 1 ? (checkBox.getText() + .substring(groupName.length() + 3)) : "Visible"); + if (array.length == 1) { + panelInsideScrollPane + .add(new JSeparator(SwingConstants.VERTICAL)); JLabel label = new JLabel(groupName); label.setFont(BIG_FONT); panelInsideScrollPane.add(label); } } - if( + if ( timeCalcProperty == TimeCalcProperty.VISIBILITY_DEFAULT || timeCalcProperty == TimeCalcProperty.JOKES_VISIBLE - ) { + ) { JLabel label = new JLabel("Misc"); - label.setFont(BIG_FONT); - panelInsideScrollPane.add(label); + label.setFont(BIG_FONT); + panelInsideScrollPane.add(label); } } if (p instanceof JColorChooser) { JColorChooser colorChooser = ((JColorChooser) p); //jColorChooser.setMaximumSize(new Dimension(150, 25)); - String timeCalcPropertyKey = (String) colorChooser.getClientProperty( - CLIENT_PROPERTY_KEY); + String timeCalcPropertyKey = + (String) colorChooser.getClientProperty( + CLIENT_PROPERTY_KEY); TimeCalcProperty timeCalcProperty = TimeCalcProperty.forKey(timeCalcPropertyKey); - String currentColor = ((StringProperty) timeCalcConfiguration.getProperty(timeCalcProperty)).getValue(); + String currentColor = ((StringProperty) timeCalcConfiguration + .getProperty(timeCalcProperty)).getValue(); String[] currentColorAsStringArray = currentColor.split(","); int red = Integer.valueOf(currentColorAsStringArray[0]); int green = Integer.valueOf(currentColorAsStringArray[1]); @@ -373,11 +434,12 @@ public class ConfigWindow extends TWindow { public void mouseClicked(MouseEvent e) { Color selectedColor = colorChooser.getSelectionModel() .getSelectedColor(); - selectedColor = JColorChooser.showDialog(null, "Choose a color", color); + selectedColor = JColorChooser + .showDialog(null, "Choose a color", color); if (selectedColor != null) { colorChooser.setColor(selectedColor); - ((StringProperty) timeCalcConfiguration - .getProperty(timeCalcProperty)) + timeCalcConfiguration + .getProperty(timeCalcProperty) .setValue( selectedColor.getRed() + "," + selectedColor.getGreen() + "," @@ -411,23 +473,29 @@ public class ConfigWindow extends TWindow { JTextField jTextField = ((JTextField) p); jTextField.setMaximumSize(new Dimension(150, 25)); - String timeCalcPropertyKey = (String) jTextField.getClientProperty( - CLIENT_PROPERTY_KEY); + String timeCalcPropertyKey = + (String) jTextField.getClientProperty( + CLIENT_PROPERTY_KEY); TimeCalcProperty timeCalcProperty = TimeCalcProperty.forKey(timeCalcPropertyKey); - jTextField.setText((String) timeCalcConfiguration.getProperty(timeCalcProperty).getValue()); + jTextField.setText((String) timeCalcConfiguration + .getProperty(timeCalcProperty).getValue()); - jTextField.getDocument().addDocumentListener(new DocumentListener() { - public void changedUpdate(DocumentEvent e) { - } - public void removeUpdate(DocumentEvent e) { - } - public void insertUpdate(DocumentEvent e) { - ((StringProperty) timeCalcConfiguration.getProperty(timeCalcProperty)) - .setValue( - (String) jTextField.getText()); - } - }); + jTextField.getDocument() + .addDocumentListener(new DocumentListener() { + public void changedUpdate(DocumentEvent e) { + } + + public void removeUpdate(DocumentEvent e) { + } + + public void insertUpdate(DocumentEvent e) { + timeCalcConfiguration + .getProperty(timeCalcProperty) + .setValue( + jTextField.getText()); + } + }); } propertiesMap.put(TimeCalcProperty.forKey( @@ -437,39 +505,39 @@ public class ConfigWindow extends TWindow { Arrays.stream(getComponents()).forEach(c -> c.getClass().getName()); ConfigWindow configWindow = this; -// class ConfigThread implements Runnable { -// public final AtomicBoolean stopped = new AtomicBoolean(); -// -// public void run() { -// while (true) { -// if (stopped.get()) { -// System.out.println("stopping thread"); -// break; -// } -// if (!configWindow.visibilitySupportedColoredProperty -// .isSelected() -// && configWindow.visibilityDefaultProperty.isEnabled()) { -// configWindow.visibilityDefaultProperty.disable(); -// } -// if (configWindow.visibilitySupportedColoredProperty -// .isSelected() -// && !configWindow.visibilityDefaultProperty -// .isEnabled()) { -// configWindow.visibilityDefaultProperty.enable(); -// } -// } -// try { -// Thread.sleep(100); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// System.out.println(e); -// } -// } -// } -// ConfigThread configThread = new ConfigThread(); -// Thread thread = new Thread(configThread); -// -// thread.start(); + // class ConfigThread implements Runnable { + // public final AtomicBoolean stopped = new AtomicBoolean(); + // + // public void run() { + // while (true) { + // if (stopped.get()) { + // System.out.println("stopping thread"); + // break; + // } + // if (!configWindow.visibilitySupportedColoredProperty + // .isSelected() + // && configWindow.visibilityDefaultProperty.isEnabled()) { + // configWindow.visibilityDefaultProperty.disable(); + // } + // if (configWindow.visibilitySupportedColoredProperty + // .isSelected() + // && !configWindow.visibilityDefaultProperty + // .isEnabled()) { + // configWindow.visibilityDefaultProperty.enable(); + // } + // } + // try { + // Thread.sleep(100); + // } catch (InterruptedException e) { + // e.printStackTrace(); + // System.out.println(e); + // } + // } + // } + // ConfigThread configThread = new ConfigThread(); + // Thread thread = new Thread(configThread); + // + // thread.start(); addWindowListener(new WindowAdapter() { @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) { panelInsideScrollPane.add(jComponent); @@ -497,10 +563,11 @@ public class ConfigWindow extends TWindow { private void nextRow() { currentY = (int) (currentY + 3.0d * SwingUtils.MARGIN); } - + public void doEnableEverything() { this.enableAsMuchAsPossible.doClick(); } + public void doDisableAlmostEverything() { this.disableAsMuchAsPossible.doClick(); } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/HelpWindow.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/HelpWindow.java index 5c967de..dc7b786 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/HelpWindow.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/HelpWindow.java @@ -29,10 +29,13 @@ public class HelpWindow extends TWindow { return; } - helpHtml = "
" + helpHtml + "
"; - + helpHtml = "
" + + helpHtml + "
"; + 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, getWidth() - 2 * SwingUtils.MARGIN, getHeight() - 4 * SwingUtils.MARGIN); diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/MainWindow.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/MainWindow.java index 96a2e9a..d7ff5a3 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/MainWindow.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/MainWindow.java @@ -50,6 +50,7 @@ public class MainWindow extends TWindow { 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 JCheckBox hideShowCheckBox = new JCheckBox(); private final TButton workDaysButton; private final TButton activitiesButton; private final TButton exitButton; @@ -61,15 +62,13 @@ public class MainWindow extends TWindow { private final TButton commandButton; private final TButton jokeButton; private final AboutButton aboutButton; - public static final JCheckBox hideShowCheckBox = new JCheckBox(); + private final TimeCalcConfiguration timeCalcConfiguration + = new TimeCalcConfiguration(); private HelpWindow helpWindow = null; private ConfigWindow configWindow = null; private ActivitiesWindow activitiesWindow = null; private WorkDaysWindow workDaysWindow = null; - private boolean stopBeforeEnd = false; - private final TimeCalcConfiguration timeCalcConfiguration - = new TimeCalcConfiguration(); public MainWindow(String startTimeIn, String overTimeIn, TimeCalcApp timeCalcApp) { @@ -96,7 +95,7 @@ public class MainWindow extends TWindow { TimeHM endTime = new TimeHM( startTime.getHour() + Constants.WORKING_HOURS_LENGTH + overtime - .getHour(), + .getHour(), startTime.getMinute() + Constants.WORKING_MINUTES_LENGTH + overtime.getMinute()); @@ -107,7 +106,7 @@ public class MainWindow extends TWindow { this.configButton = new TButton("Config"); this.workDaysButton = new TButton("Work Days"); this.activitiesButton = new TButton("Activities" - + ""); + + ""); this.restartButton = new TButton("Restart"); this.exitButton = new TButton("Exit"); this.focusButton = new TButton("Focus"); @@ -119,13 +118,18 @@ public class MainWindow extends TWindow { //window.add(weatherButton); addAll(configButton, workDaysButton, activitiesButton, restartButton, - exitButton, focusButton, helpButton, commandButton, jokeButton, hideShowCheckBox); + exitButton, focusButton, helpButton, commandButton, jokeButton, + hideShowCheckBox); - timeCalcApp.visibilityProperty.bindTo(timeCalcConfiguration.visibilityDefaultProperty); - if (!timeCalcConfiguration.visibilitySupportedColoredProperty.isEnabled()) { + timeCalcApp.visibilityProperty + .bindTo(timeCalcConfiguration.visibilityDefaultProperty); + if (!timeCalcConfiguration.visibilitySupportedColoredProperty + .isEnabled()) { timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name()); } - TimeCalcKeyAdapter timeCalcKeyAdapter = new TimeCalcKeyAdapter(timeCalcConfiguration, timeCalcApp, this); + TimeCalcKeyAdapter timeCalcKeyAdapter = + new TimeCalcKeyAdapter(timeCalcConfiguration, timeCalcApp, + this); addKeyListener(timeCalcKeyAdapter); AnalogClock analogClock = new AnalogClock(startTime, endTime); @@ -134,24 +138,31 @@ public class MainWindow extends TWindow { ProgressSquare progressSquare = new ProgressSquare(); progressSquare - .setBounds(analogClock.getX() + analogClock.getWidth() + SwingUtils.MARGIN, analogClock.getY(), + .setBounds(analogClock.getX() + analogClock.getWidth() + + SwingUtils.MARGIN, analogClock.getY(), 200); add(progressSquare); - progressSquare.visibleProperty.bindTo(timeCalcConfiguration.squareVisibleProperty); + progressSquare.visibleProperty + .bindTo(timeCalcConfiguration.squareVisibleProperty); ProgressCircle progressCircle = new ProgressCircle(); progressCircle .setBounds( - progressSquare.getX() + progressSquare.getWidth() + SwingUtils.MARGIN, progressSquare.getY(), 80); + progressSquare.getX() + progressSquare.getWidth() + + SwingUtils.MARGIN, progressSquare.getY(), 80); add(progressCircle); - progressCircle.visibleProperty.bindTo(timeCalcConfiguration.circleVisibleProperty); - + progressCircle.visibleProperty + .bindTo(timeCalcConfiguration.circleVisibleProperty); + WalkingHumanProgress 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); - walkingHumanProgress.visibleProperty.bindTo(timeCalcConfiguration.walkingHumanVisibleProperty); - + walkingHumanProgress.visibleProperty + .bindTo(timeCalcConfiguration.walkingHumanVisibleProperty); + weatherButton .setBounds(SwingUtils.MARGIN, walkingHumanProgress.getY() + walkingHumanProgress.getHeight() @@ -169,7 +180,9 @@ public class MainWindow extends TWindow { commandButton.setBoundsFromLeft(focusButton); jokeButton.setBoundsFromLeft(commandButton); 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(), exitButton.getY() + exitButton.getHeight() + SwingUtils.MARGIN); @@ -181,14 +194,15 @@ public class MainWindow extends TWindow { weatherButton .addActionListener(e -> new WeatherWindow().setVisible(true)); - commandButton.addActionListener(new CommandActionListener(timeCalcApp, timeCalcConfiguration)); + commandButton.addActionListener( + new CommandActionListener(timeCalcApp, timeCalcConfiguration)); jokeButton.addActionListener(e -> { for (int i = 1; i <= 1; i++) { Jokes.showRandom(); } }); - hideShowCheckBox.addItemListener(e -> + hideShowCheckBox.addItemListener(e -> { }); exitButton.addActionListener(e @@ -246,17 +260,28 @@ public class MainWindow extends TWindow { Time time = new Time(); - bindToIfPropertyMissing(testProperties, "test.current.day", calNow, Calendar.DAY_OF_MONTH, analogClock.dayProperty, time.dayProperty); - bindToIfPropertyMissing(testProperties, "test.current.month", calNow, Calendar.MONTH, analogClock.monthProperty, time.monthProperty); - bindToIfPropertyMissing(testProperties, "test.current.year", calNow, 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); + bindToIfPropertyMissing(testProperties, "test.current.day", calNow, + Calendar.DAY_OF_MONTH, analogClock.dayProperty, + time.dayProperty); + bindToIfPropertyMissing(testProperties, "test.current.month", calNow, + Calendar.MONTH, analogClock.monthProperty, time.monthProperty); + bindToIfPropertyMissing(testProperties, "test.current.year", calNow, + 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 .containsKey("test.current.month") || testProperties - .containsKey("test.current.day")) { + .containsKey("test.current.day")) { analogClock.dayOfWeekProperty .setValue(calNow.get(Calendar.DAY_OF_WEEK)); } else { @@ -273,35 +298,54 @@ public class MainWindow extends TWindow { .bindTo(timeCalcConfiguration.clockHandsHourVisibleProperty); analogClock.handsLongProperty .bindTo(timeCalcConfiguration.clockHandsLongVisibleProperty); - analogClock.borderVisibleProperty.bindTo(timeCalcConfiguration.clockBorderVisibleProperty); - analogClock.borderOnlyHoursProperty.bindTo(timeCalcConfiguration.clockBorderOnlyHoursProperty); - analogClock.numbersVisibleProperty.bindTo(timeCalcConfiguration.clockNumbersVisibleProperty); - analogClock.circleVisibleProperty.bindTo(timeCalcConfiguration.clockCircleVisibleProperty); - analogClock.circleStrongBorderProperty.bindTo(timeCalcConfiguration.clockCircleStrongBorderProperty); - analogClock.centreCircleVisibleProperty.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, - progressCircle.getY() + SwingUtils.MARGIN + progressCircle.getHeight(), 140); + analogClock.borderVisibleProperty + .bindTo(timeCalcConfiguration.clockBorderVisibleProperty); + analogClock.borderOnlyHoursProperty + .bindTo(timeCalcConfiguration.clockBorderOnlyHoursProperty); + analogClock.numbersVisibleProperty + .bindTo(timeCalcConfiguration.clockNumbersVisibleProperty); + analogClock.circleVisibleProperty + .bindTo(timeCalcConfiguration.clockCircleVisibleProperty); + analogClock.circleStrongBorderProperty + .bindTo(timeCalcConfiguration.clockCircleStrongBorderProperty); + analogClock.centreCircleVisibleProperty + .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, + progressCircle.getY() + SwingUtils.MARGIN + + progressCircle.getHeight(), 140); 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(), 140); 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(), 140); add(dayBattery); Battery weekBattery = new WeekBattery( minuteBattery.getBounds().x, - dayBattery.getY() + dayBattery.getHeight() + SwingUtils.MARGIN, 140); + dayBattery.getY() + dayBattery.getHeight() + SwingUtils.MARGIN, + 140); add(weekBattery); int currentDayOfMonth = analogClock.dayProperty.getValue(); @@ -310,10 +354,12 @@ public class MainWindow extends TWindow { int workDaysTodo = 0; int workDaysTotal; for (int dayOfMonth = 1; - dayOfMonth <= calNow.getActualMaximum(Calendar.DAY_OF_MONTH); - dayOfMonth++) { - DayOfWeek dayOfWeek = LocalDate.of(analogClock.yearProperty.getValue(), - analogClock.monthProperty.getValue(), dayOfMonth).getDayOfWeek(); + dayOfMonth <= calNow.getActualMaximum(Calendar.DAY_OF_MONTH); + dayOfMonth++) { + DayOfWeek dayOfWeek = + LocalDate.of(analogClock.yearProperty.getValue(), + analogClock.monthProperty.getValue(), dayOfMonth) + .getDayOfWeek(); boolean weekend = dayOfWeek.toString().equals("SATURDAY") || dayOfWeek .toString().equals("SUNDAY"); @@ -328,75 +374,114 @@ public class MainWindow extends TWindow { .of(calNow.get(Calendar.YEAR), calNow.get(Calendar.MONTH) + 1, currentDayOfMonth).getDayOfWeek().toString(); boolean nowIsWeekend = currentDayOfWeekAsString.equals("SATURDAY") - || currentDayOfWeekAsString.equals("SUNDAY"); + || currentDayOfWeekAsString.equals("SUNDAY"); workDaysTotal = workDaysDone + (nowIsWeekend ? 0 : 1) + workDaysTodo; Battery monthBattery = new MonthBattery( - weekBattery.getBounds().x + weekBattery.getWidth() + SwingUtils.MARGIN, + weekBattery.getBounds().x + weekBattery.getWidth() + + SwingUtils.MARGIN, weekBattery.getY(), 140); add(monthBattery); Battery yearBattery = new YearBattery( - monthBattery.getBounds().x + monthBattery.getWidth() + SwingUtils.MARGIN, + monthBattery.getBounds().x + monthBattery.getWidth() + + SwingUtils.MARGIN, monthBattery.getY(), 140); add(yearBattery); - ComponentRegistry componentRegistry = new ComponentRegistry(); + ComponentRegistry componentRegistry = + new ComponentRegistry(); componentRegistry.addAll(this.getContentPane().getComponents()); ComponentRegistry buttonRegistry = new ComponentRegistry(); - componentRegistry.getSet().stream().filter(c -> c instanceof TButton).forEach(c - -> { - buttonRegistry.add((TButton) c); - - }); -// commandButton.visibleProperty.bindTo(timeCalcConfiguration.commandsVisibleProperty); -// jokeButton.visibleProperty.bindTo(timeCalcConfiguration.jokesVisibleProperty); + componentRegistry.getSet().stream().filter(c -> c instanceof TButton) + .forEach(c + -> { + buttonRegistry.add((TButton) c); + + }); + // commandButton.visibleProperty.bindTo(timeCalcConfiguration.commandsVisibleProperty); + // jokeButton.visibleProperty.bindTo(timeCalcConfiguration.jokesVisibleProperty); componentRegistry.getSet().stream().filter(c -> GetProperty.class.isAssignableFrom(c.getClass())).forEach(c -> { - ((GetProperty) c).getVisibilityProperty().bindTo(timeCalcApp.visibilityProperty); - ((GetProperty) c).getVisibilitySupportedColoredProperty().bindTo(timeCalcConfiguration.visibilitySupportedColoredProperty); + ((GetProperty) c).getVisibilityProperty() + .bindTo(timeCalcApp.visibilityProperty); + ((GetProperty) c).getVisibilitySupportedColoredProperty() + .bindTo(timeCalcConfiguration.visibilitySupportedColoredProperty); }); - componentRegistry.getSet().stream().filter(c -> c instanceof Battery).forEach(c - -> { - Battery battery = ((Battery) c); - battery.wavesVisibleProperty.bindTo(timeCalcConfiguration.batteryWavesVisibleProperty); - battery.circleProgressVisibleProperty.bindTo(timeCalcConfiguration.batteryCircleProgressProperty); - battery.percentProgressVisibleProperty.bindTo(timeCalcConfiguration.batteryPercentProgressProperty); - battery.chargingCharacterVisibleProperty.bindTo(timeCalcConfiguration.batteryChargingCharacterVisibleProperty); - battery.nameVisibleProperty.bindTo(timeCalcConfiguration.batteryNameVisibleProperty); - battery.labelVisibleProperty.bindTo(timeCalcConfiguration.batteryLabelVisibleProperty); - battery.blinkingIfCriticalLowVisibleProperty.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 Battery) + .forEach(c + -> { + Battery battery = ((Battery) c); + battery.wavesVisibleProperty + .bindTo(timeCalcConfiguration.batteryWavesVisibleProperty); + battery.circleProgressVisibleProperty + .bindTo(timeCalcConfiguration.batteryCircleProgressProperty); + battery.percentProgressVisibleProperty + .bindTo(timeCalcConfiguration.batteryPercentProgressProperty); + battery.chargingCharacterVisibleProperty + .bindTo(timeCalcConfiguration.batteryChargingCharacterVisibleProperty); + battery.nameVisibleProperty + .bindTo(timeCalcConfiguration.batteryNameVisibleProperty); + battery.labelVisibleProperty + .bindTo(timeCalcConfiguration.batteryLabelVisibleProperty); + battery.blinkingIfCriticalLowVisibleProperty + .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) + .forEach(c + -> { + Widget widget = (Widget) c; + widget.smileysVisibleProperty + .bindTo(timeCalcConfiguration.smileysVisibleProperty); + widget.smileysVisibleOnlyIfMouseMovingOverProperty + .bindTo(timeCalcConfiguration.smileysVisibleOnlyIfMouseMovingOverProperty); + widget.smileysColoredProperty + .bindTo(timeCalcConfiguration.smileysColoredProperty); + } + ); + setSize(dayBattery.getX() + dayBattery.getWidth() + + 3 * SwingUtils.MARGIN, + focusButton.getY() + focusButton.getHeight() + SwingUtils.MARGIN + + focusButton.getHeight() + 2 * SwingUtils.MARGIN); - componentRegistry.getSet().stream().filter(c -> c instanceof Widget).forEach(c - -> { - Widget widget = (Widget) c; - widget.smileysVisibleProperty.bindTo(timeCalcConfiguration.smileysVisibleProperty); - widget.smileysVisibleOnlyIfMouseMovingOverProperty.bindTo(timeCalcConfiguration.smileysVisibleOnlyIfMouseMovingOverProperty); - widget.smileysColoredProperty.bindTo(timeCalcConfiguration.smileysColoredProperty); - } - ); - setSize(dayBattery.getX() + dayBattery.getWidth() + 3 * SwingUtils.MARGIN, - focusButton.getY() + focusButton.getHeight() + SwingUtils.MARGIN + focusButton.getHeight() + 2 * SwingUtils.MARGIN); - while (true) { //System.out.println("timeCalcConfiguration.handsLongProperty=" + timeCalcConfiguration.clockHandLongProperty.isEnabled()); Visibility currentVisibility = Visibility .valueOf(timeCalcApp.visibilityProperty.getValue()); - if (!timeCalcConfiguration.visibilitySupportedColoredProperty.isEnabled() && currentVisibility.isColored()) { + if (!timeCalcConfiguration.visibilitySupportedColoredProperty + .isEnabled() && currentVisibility.isColored()) { timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name()); } if (stopBeforeEnd) { @@ -424,14 +509,16 @@ public class MainWindow extends TWindow { break; } - componentRegistry.setVisible(c -> (c instanceof Widget ? ((Widget)c).visibleProperty.isEnabled() - : true) /*|| (c instanceof TButton ? ((Widget)c).visibleProperty.isEnabled() + componentRegistry.setVisible(c -> (!(c instanceof Widget) + || ((Widget) c).visibleProperty + .isEnabled()) /*|| (c instanceof TButton ? ((Widget)c).visibleProperty.isEnabled() : true)*/, currentVisibility.isNotNone()); jokeButton.setVisible( TimeCalcProperties.getInstance().getBooleanProperty( TimeCalcProperty.JOKES_VISIBLE) - && !currentVisibility.isNone() && MainWindow.hideShowCheckBox.isSelected()); + && !currentVisibility.isNone() + && MainWindow.hideShowCheckBox.isSelected()); setTitle(currentVisibility.isNone() ? "" : getWindowTitle()); @@ -447,10 +534,10 @@ public class MainWindow extends TWindow { int millisecondsRemains = 1000 - millisecondNow; int hourDone = Constants.WORKING_HOURS_LENGTH + overtime.getHour() - - timeRemains.getHour(); + - timeRemains.getHour(); int minutesDone = Constants.WORKING_MINUTES_LENGTH + overtime.getMinute() - - timeRemains.getMinute(); + - timeRemains.getMinute(); int secondsDone = secondNow; int millisecondsDone = millisecondNow; @@ -460,7 +547,7 @@ public class MainWindow extends TWindow { = totalSecondsDone * 1000 + millisecondsDone; double done = ((double) totalMillisecondsDone) - / ((double) totalMilliseconds); + / ((double) totalMilliseconds); progressSquare.setDonePercent(done); progressCircle.setDonePercent(done); dayBattery.setDonePercent(done); @@ -486,14 +573,16 @@ public class MainWindow extends TWindow { hourBattery.setLabel( hourDone + "/" + (totalMinutes / 60)); } - minuteBattery.setDonePercent(MinuteBattery.getMinuteProgress(secondNow, millisecondNow)); - yearBattery.setDonePercent(YearBattery.getYearProgress(analogClock)); + minuteBattery.setDonePercent( + MinuteBattery.getMinuteProgress(secondNow, millisecondNow)); + yearBattery + .setDonePercent(YearBattery.getYearProgress(analogClock)); yearBattery.setLabel(""); //yearBattery.setDonePercent(YearBattery.getYearProgress(2024,0,1,0,0,0,0)); int totalSecondsRemains = (timeRemains.getHour() * 60 * 60 - + timeRemains.getMinute() * 60 - + secondsRemains); + + timeRemains.getMinute() * 60 + + secondsRemains); int totalMillisecondsRemains = totalSecondsRemains * 1000 + millisecondsRemains; 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)) { 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( (String) properties.get(key))); } else { @@ -606,22 +698,23 @@ public class MainWindow extends TWindow { public void openHelpWindow() { helpButton.doClick(); } - + public void doEnableEverything() { - if(this.configWindow == null) { + if (this.configWindow == null) { openConfigWindow(); this.configWindow.setVisible(false); } - + this.configWindow.doEnableEverything(); } + public void doDisableAlmostEverything() { - - if(this.configWindow == null) { + + if (this.configWindow == null) { openConfigWindow(); this.configWindow.setVisible(false); } - + this.configWindow.doDisableAlmostEverything(); } } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/SwingUtils.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/SwingUtils.java index 73e1229..a0ee857 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/SwingUtils.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/SwingUtils.java @@ -5,6 +5,7 @@ import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; + 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 static void paintCloseIcon(Graphics brush, int width) { - 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 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 final Font MEDIUM_MONOSPACE_FONT = + new Font(Font.MONOSPACED, Font.PLAIN, 12); private SwingUtils() { //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 final Font MEDIUM_MONOSPACE_FONT = new Font(Font.MONOSPACED, Font.PLAIN, 12); + + public static void paintCloseIcon(Graphics brush, int width) { + 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) { if (s.isEmpty()) { System.out.println("error: empty string for color"); diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/TButton.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/TButton.java index 094ef3a..95b1cee 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/TButton.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/TButton.java @@ -19,22 +19,20 @@ public class TButton extends JButton implements GetProperty { private static final int BUTTON_WIDTH = 100; private static final int BUTTON_HEIGHT = 30; - public StringProperty visibilityProperty - = new StringProperty("visibilityProperty", - Visibility.STRONGLY_COLORED.name()); - public final BooleanProperty visibilitySupportedColoredProperty = new BooleanProperty("visibilitySupportedColoredProperty", true); - private Color originalBackground; - private Color originalForeground; - public final BooleanProperty visibleProperty = new BooleanProperty("visibleProperty", true); + public StringProperty visibilityProperty + = new StringProperty("visibilityProperty", + Visibility.STRONGLY_COLORED.name()); + private Color originalBackground; + private Color originalForeground; public TButton(String label) { super(label); new Timer(100, e -> { - if(!MainWindow.hideShowCheckBox.isSelected()) { + if (!MainWindow.hideShowCheckBox.isSelected()) { setVisible(false); return; } else { @@ -68,7 +66,8 @@ public class TButton extends JButton implements GetProperty { } 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) { @@ -77,8 +76,8 @@ public class TButton extends JButton implements GetProperty { public void setBoundsFromTop(JComponent jComponent, int marginCount) { setBounds(SwingUtils.MARGIN, jComponent.getY() - + jComponent.getHeight() - + marginCount * SwingUtils.MARGIN); + + jComponent.getHeight() + + marginCount * SwingUtils.MARGIN); } @Override @@ -92,6 +91,7 @@ public class TButton extends JButton implements GetProperty { } 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 } } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/Toaster.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/Toaster.java index 7a45dff..3866d65 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/Toaster.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/Toaster.java @@ -24,7 +24,6 @@ package org.nanoboot.utils.timecalc.swing.common; * // Show a simple toaster toasterManager.showToaster( new ImageIcon( * "mylogo.gif" ), "A simple toaster with an image" ); } } */ -import org.nanoboot.utils.timecalc.utils.common.Utils; import javax.swing.BorderFactory; import javax.swing.Icon; @@ -110,10 +109,10 @@ public class Toaster { * Show a toaster with the specified message and the associated icon. */ public void showToaster(Icon icon, String msg) { -// if (!Utils.toastsAreEnabled.getValue()) { -// //nothing to do -// return; -// } + // if (!Utils.toastsAreEnabled.getValue()) { + // //nothing to do + // return; + // } SingleToaster singleToaster = new SingleToaster(); if (icon != null) { singleToaster.iconLabel.setIcon(icon); @@ -431,8 +430,9 @@ public class Toaster { stopYPosition = startYPosition - toasterHeight - 1; if (currentNumberOfToaster > 0) { stopYPosition - = stopYPosition - (maxToaster % maxToasterInSceen - * toasterHeight); + = + stopYPosition - (maxToaster % maxToasterInSceen + * toasterHeight); } else { maxToaster = 0; } @@ -442,8 +442,9 @@ public class Toaster { if (currentNumberOfToaster > 0) { stopYPosition - = stopYPosition + (maxToaster % maxToasterInSceen - * toasterHeight); + = + stopYPosition + (maxToaster % maxToasterInSceen + * toasterHeight); } else { maxToaster = 0; } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/WeatherWindow.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/WeatherWindow.java index b9ca30c..bca0e58 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/WeatherWindow.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/WeatherWindow.java @@ -86,7 +86,7 @@ public class WeatherWindow extends JFrame { jep.setContentType("text/html"); jep.setText("" - + pocasiHtml + ""); + + pocasiHtml + ""); Utils.writeTextToFile(new File("aaa"), "" + pocasiHtml + ""); diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/Widget.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/Widget.java index 51e693b..7f42d28 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/Widget.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/Widget.java @@ -1,6 +1,7 @@ package org.nanoboot.utils.timecalc.swing.common; 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.swing.progress.ProgressSmileyIcon; import org.nanoboot.utils.timecalc.utils.common.ProgressSmiley; @@ -12,7 +13,6 @@ import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.Timer; -import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; @@ -20,7 +20,6 @@ import java.awt.Graphics2D; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; -import org.nanoboot.utils.timecalc.app.TimeCalcProperty; /** * @author Robert Vokac @@ -29,16 +28,12 @@ import org.nanoboot.utils.timecalc.app.TimeCalcProperty; public class Widget extends JPanel implements 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_COLOR2 = new Color(210, 210, 210); 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 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 = new BooleanProperty("visibilitySupportedColoredProperty", true); public final BooleanProperty visibleProperty @@ -46,9 +41,14 @@ public class Widget extends JPanel implements public final BooleanProperty smileysVisibleProperty = new BooleanProperty(TimeCalcProperty.SMILEYS_VISIBLE.getKey()); 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 = new BooleanProperty("smileysColoredProperty", true); + public StringProperty visibilityProperty + = new StringProperty("widget.visibilityProperty", + Visibility.STRONGLY_COLORED.name()); protected int side = 0; protected double donePercent = 0; protected boolean mouseOver = false; @@ -69,7 +69,8 @@ public class Widget extends JPanel implements int x = e.getX(); 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() { @@ -124,16 +125,16 @@ public class Widget extends JPanel implements return 100; } -// @Override -// public void setVisible(boolean aFlag) { -// if(visibleProperty.isEnabled() && !aFlag) { -// super.setVisible(false); -// } -// if(visibleProperty.isDisabled() && aFlag) { -// super.setVisible(false); -// } -// -// } + // @Override + // public void setVisible(boolean aFlag) { + // if(visibleProperty.isEnabled() && !aFlag) { + // super.setVisible(false); + // } + // if(visibleProperty.isDisabled() && aFlag) { + // super.setVisible(false); + // } + // + // } public final void setDonePercent(double donePercent) { if (donePercent > 1) { donePercent = 1; @@ -153,14 +154,15 @@ public class Widget extends JPanel implements super.paintComponent(brush); setVisible(visibleProperty.isEnabled()); - - if(visibleProperty.isDisabled()) { + + if (visibleProperty.isDisabled()) { //nothing to do return; } Visibility visibility = Visibility.valueOf(visibilityProperty.getValue()); - super.setVisible(visibility != Visibility.NONE && visibleProperty.isEnabled()); + super.setVisible( + visibility != Visibility.NONE && visibleProperty.isEnabled()); paintWidget(brush); if (mouseOver && mouseOverCloseButton) { @@ -182,8 +184,11 @@ public class Widget extends JPanel implements return visibilitySupportedColoredProperty; } - protected void paintSmiley(Visibility visibility, Graphics2D brush, int x, int y) { - if (smileysVisibleProperty.isDisabled() || (!mouseOver && smileysVisibleOnlyIfMouseMovingOverProperty.isEnabled())) { + protected void paintSmiley(Visibility visibility, Graphics2D brush, int x, + int y) { + if (smileysVisibleProperty.isDisabled() || (!mouseOver + && smileysVisibleOnlyIfMouseMovingOverProperty + .isEnabled())) { if (this.smileyIcon != null) { this.remove(smileyIcon); this.smileyIcon = null; @@ -212,7 +217,8 @@ public class Widget extends JPanel implements brush.setColor(Color.BLACK); } Color currentColor = brush.getColor(); - brush.setColor(visibility.isStronglyColored() ? Color.WHITE : BACKGROUND_COLOR); + brush.setColor(visibility.isStronglyColored() ? Color.WHITE : + BACKGROUND_COLOR); brush.fillRect( x, y, 20, @@ -226,7 +232,9 @@ public class Widget extends JPanel implements ); } if (colored) { - ImageIcon imageIcon = ProgressSmileyIcon.forSmiley(ProgressSmiley.forProgress(donePercent)).getIcon(); + ImageIcon imageIcon = ProgressSmileyIcon + .forSmiley(ProgressSmiley.forProgress(donePercent)) + .getIcon(); if (this.smileyIcon != null) { this.remove(smileyIcon); this.smileyIcon = null; diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/AnalogClock.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/AnalogClock.java index 104755e..0fd2b97 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/AnalogClock.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/AnalogClock.java @@ -26,7 +26,41 @@ public class AnalogClock extends Widget { public static final Color COLOR_FOR_MILLISECOND_HAND_STRONGLY_COLORED = 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 = new IntegerProperty("startHourProperty"); public IntegerProperty startMinuteProperty @@ -59,39 +93,8 @@ public class AnalogClock extends Widget { = new BooleanProperty("handsLongProperty", true); public BooleanProperty handsColoredProperty = 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 final TimeHM endTime; private int startAngle; - private final int endAngle; private Color customCircleColor = null; public AnalogClock(TimeHM startTimeIn, @@ -100,19 +103,21 @@ public class AnalogClock extends Widget { this.endTime = endTimeIn.cloneInstance(); this.endAngle = (int) ((endTime.getHour() + endTime.getMinute() / 60d) / 12d - * 360d); + * 360d); if (endTime.getHour() > 12) { endTime.setHour(endTime.getHour() - 12); } this.startTime = startTimeIn.cloneInstance(); this.startAngle - = (int) ((startTime.getHour() + startTime.getMinute() / 60d) / 12d - * 360d); + = + (int) ((startTime.getHour() + startTime.getMinute() / 60d) / 12d + * 360d); setPreferredSize(new Dimension(200, 200)); centreCircleBorderColorProperty.addListener(property - -> customCircleColor = SwingUtils.getColorFromString(centreCircleBorderColorProperty.getValue())); + -> customCircleColor = SwingUtils.getColorFromString( + centreCircleBorderColorProperty.getValue())); } public static void main(String[] args) { @@ -163,13 +168,15 @@ public class AnalogClock extends Widget { int hour = hourProperty.getValue(); 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.startAngle = (int) ((startTime.getHour() + startTime.getMinute() / 60d) - / 12d * 360d); + / 12d * 360d); Color currentColor = g2d.getColor(); 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, 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, visibility); @@ -204,7 +214,8 @@ public class AnalogClock extends Widget { Color.RED, visibility); } } - if (minuteEnabledProperty.isEnabled() && hourEnabledProperty.isEnabled()) { + if (minuteEnabledProperty.isEnabled() && hourEnabledProperty + .isEnabled()) { double minutes = minute / 60.0 + second / 60.0 / 60.0; drawHand(g2d, side / 2 - 20, minutes, 2.0f, Color.BLUE, visibility); @@ -217,7 +228,8 @@ public class AnalogClock extends Widget { } } 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, hours, 4.0f, Color.BLACK, visibility); @@ -233,7 +245,8 @@ public class AnalogClock extends Widget { if (borderOnlyHoursProperty.isEnabled() && minuteI % 5 != 0) { 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); } } @@ -249,7 +262,9 @@ public class AnalogClock extends Widget { Color currentColor = brush.getColor(); Visibility visibility = 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); brush.fillOval(centerX - 3, centerY - 3, 8, 8); brush.setColor(currentColor); @@ -259,12 +274,19 @@ public class AnalogClock extends Widget { float stroke, Color color, Visibility visibility) { double value = ((double) forMinute) / 60d; 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); - int startX = (int) (getWidth() / 2 + (side / 2 - length) * Math.cos(angle)); - int startY = (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)); + int startX = + (int) (getWidth() / 2 + (side / 2 - length) * Math.cos(angle)); + int startY = + (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 : FOREGROUND_COLOR); @@ -279,7 +301,8 @@ public class AnalogClock extends Widget { int endX = (int) (getWidth() / 2 + length * Math.cos(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); brush.setStroke(new BasicStroke(stroke)); brush.drawLine(getWidth() / 2, getHeight() / 2, endX, endY); @@ -306,7 +329,8 @@ public class AnalogClock extends Widget { brush.setColor(currentColor); } - if (this.mouseOver || dateVisibleOnlyIfMouseMovingOverProperty.isDisabled()) { + if (this.mouseOver || dateVisibleOnlyIfMouseMovingOverProperty + .isDisabled()) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, yearProperty.getValue()); cal.set(Calendar.MONTH, monthProperty.getValue() - 1); diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/Battery.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/Battery.java index cc142e9..10a0d0c 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/Battery.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/Battery.java @@ -37,23 +37,31 @@ public class Battery extends Widget { @Getter private final String name; private final double[] randomDoubles - = 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); + = new double[] {1d, 1d, 1d, 1d, 1d, 1d, 1}; 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 int totalHeight = 0; private int totalWidth; @@ -77,7 +85,7 @@ public class Battery extends Widget { } if (blinkingIfCriticalLowVisibleProperty.isEnabled()) { if (donePercent > 0 && donePercent <= CRITICAL_LOW_ENERGY - && (System.nanoTime() - tmpNanoTime) > (1000000000l) / 2l) { + && (System.nanoTime() - tmpNanoTime) > (1000000000l) / 2l) { blinking.flip(); tmpNanoTime = System.nanoTime(); } @@ -99,7 +107,7 @@ public class Battery extends Widget { = Visibility.valueOf(visibilityProperty.getValue()); brush.setColor( visibility.isStronglyColored() || mouseOver ? Color.YELLOW - : FOREGROUND_COLOR); + : FOREGROUND_COLOR); brush.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); @@ -111,15 +119,15 @@ public class Battery extends Widget { brush.setColor( donePercent < LOW_ENERGY ? LOW_HIGHLIGHTED : (donePercent < HIGH_ENERGY - ? MEDIUM_HIGHLIGHTED - : (donePercent < VERY_HIGH_ENERGY - ? HIGH_HIGHLIGHTED - : HIGHEST_HIGHLIGHTED))); + ? MEDIUM_HIGHLIGHTED + : (donePercent < VERY_HIGH_ENERGY + ? HIGH_HIGHLIGHTED + : HIGHEST_HIGHLIGHTED))); } else { brush.setColor(donePercent < LOW_ENERGY ? LOW : (donePercent < HIGH_ENERGY - ? MEDIUM - : (donePercent < VERY_HIGH_ENERGY ? HIGH : HIGHEST))); + ? MEDIUM + : (donePercent < VERY_HIGH_ENERGY ? HIGH : HIGHEST))); } if (visibility.isGray()) { brush.setColor(Utils.ULTRA_LIGHT_GRAY); @@ -131,7 +139,8 @@ public class Battery extends Widget { int intX = 1; int todoHeight = totalHeight - doneHeight; 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) (4 * surfacePower);//2 + (int) (Math.random() * 3); if (waterSurfaceHeight <= 2 || wavesVisibleProperty.isDisabled()) { @@ -146,32 +155,32 @@ public class Battery extends Widget { ? doneHeight : doneHeight - waterSurfaceHeight + 1); int pointCount = 8; if (doneHeight >= waterSurfaceHeight - && donePercent < 1) {// && todoHeight > waterSurfaceHeight) { + && donePercent < 1) {// && todoHeight > waterSurfaceHeight) { //g2d.fillArc(intX, intY, width_, intHeight - waterSurfaceHeight, 30, 60); brush.fillPolygon( - new int[]{intX, - (int) (intX + totalWidth / pointCount * 0.5), - intX + totalWidth / pointCount * 3, - intX + totalWidth / pointCount * 4, - intX + totalWidth / pointCount * 5, - intX + totalWidth / pointCount * 6, - intX + totalWidth / pointCount * 7, - intX + totalWidth / pointCount * 8}, - new int[]{todoHeight + (waterSurfaceHeight * 1), - todoHeight + (int) (waterSurfaceHeight * getRandom( - 0)), - todoHeight + (int) (waterSurfaceHeight * getRandom( - 1)), - todoHeight + (int) (waterSurfaceHeight * getRandom( - 2)), - todoHeight + (int) (waterSurfaceHeight * getRandom( - 3)), - todoHeight + (int) (waterSurfaceHeight * getRandom( - 4)), - todoHeight + (int) (waterSurfaceHeight * getRandom( - 5)), - todoHeight + (waterSurfaceHeight * 1)}, + new int[] {intX, + (int) (intX + totalWidth / pointCount * 0.5), + intX + totalWidth / pointCount * 3, + intX + totalWidth / pointCount * 4, + intX + totalWidth / pointCount * 5, + intX + totalWidth / pointCount * 6, + intX + totalWidth / pointCount * 7, + intX + totalWidth / pointCount * 8}, + new int[] {todoHeight + (waterSurfaceHeight * 1), + todoHeight + (int) (waterSurfaceHeight * getRandom( + 0)), + todoHeight + (int) (waterSurfaceHeight * getRandom( + 1)), + todoHeight + (int) (waterSurfaceHeight * getRandom( + 2)), + todoHeight + (int) (waterSurfaceHeight * getRandom( + 3)), + todoHeight + (int) (waterSurfaceHeight * getRandom( + 4)), + todoHeight + (int) (waterSurfaceHeight * getRandom( + 5)), + todoHeight + (waterSurfaceHeight * 1)}, pointCount); brush.setColor( @@ -181,28 +190,28 @@ public class Battery extends Widget { brush.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); brush.drawPolyline( - new int[]{intX, - (int) (intX + totalWidth / pointCount * 0.5), - intX + totalWidth / pointCount * 3, - intX + totalWidth / pointCount * 4, - intX + totalWidth / pointCount * 5, - intX + totalWidth / pointCount * 6, - intX + totalWidth / pointCount * 7, - intX + totalWidth / pointCount * 8}, - new int[]{todoHeight + (waterSurfaceHeight * 1), - todoHeight + (int) (waterSurfaceHeight * getRandom( - 0, true)), - todoHeight + (int) (waterSurfaceHeight * getRandom( - 1, true)), - todoHeight + (int) (waterSurfaceHeight * getRandom( - 2, true)), - todoHeight + (int) (waterSurfaceHeight * getRandom( - 3, true)), - todoHeight + (int) (waterSurfaceHeight * getRandom( - 4, true)), - todoHeight + (int) (waterSurfaceHeight * getRandom( - 5, true)), - todoHeight + (waterSurfaceHeight * 1)}, + new int[] {intX, + (int) (intX + totalWidth / pointCount * 0.5), + intX + totalWidth / pointCount * 3, + intX + totalWidth / pointCount * 4, + intX + totalWidth / pointCount * 5, + intX + totalWidth / pointCount * 6, + intX + totalWidth / pointCount * 7, + intX + totalWidth / pointCount * 8}, + new int[] {todoHeight + (waterSurfaceHeight * 1), + todoHeight + (int) (waterSurfaceHeight * getRandom( + 0, true)), + todoHeight + (int) (waterSurfaceHeight * getRandom( + 1, true)), + todoHeight + (int) (waterSurfaceHeight * getRandom( + 2, true)), + todoHeight + (int) (waterSurfaceHeight * getRandom( + 3, true)), + todoHeight + (int) (waterSurfaceHeight * getRandom( + 4, true)), + todoHeight + (int) (waterSurfaceHeight * getRandom( + 5, true)), + todoHeight + (waterSurfaceHeight * 1)}, pointCount); brush.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); @@ -227,10 +236,12 @@ public class Battery extends Widget { brush.setFont(currentFont); } - if(circleProgressVisibleProperty.isEnabled()) { + if (circleProgressVisibleProperty.isEnabled()) { Color currentColor = brush.getColor(); brush.setColor( - visibility.isStronglyColored() ? HIGH_HIGHLIGHTED : (visibility.isWeaklyColored() ? HIGH : Color.lightGray)); + visibility.isStronglyColored() ? HIGH_HIGHLIGHTED : + (visibility.isWeaklyColored() ? HIGH : + Color.lightGray)); double angleDouble = donePercent * 360; @@ -239,7 +250,9 @@ public class Battery extends Widget { 15, 15, 90, -(int) angleDouble); brush.setColor( 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, totalHeight / 4 * 3 + 28, 15, 15, 90, +(int) (360 - angleDouble)); @@ -247,22 +260,25 @@ public class Battery extends Widget { brush.setColor(currentColor); } } - if(percentProgressVisibleProperty.isEnabled()) { - brush.drawString( - NumberFormats.FORMATTER_THREE_DECIMAL_PLACES - .format(donePercent * 100) + "%", - ((int) (totalWidth * 0.15)), - donePercent > 0.5 ? totalHeight / 4 * 3 : totalHeight / 4 * 1); + if (percentProgressVisibleProperty.isEnabled()) { + brush.drawString( + NumberFormats.FORMATTER_THREE_DECIMAL_PLACES + .format(donePercent * 100) + "%", + ((int) (totalWidth * 0.15)), + 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( label, ((int) (totalWidth * 0.15)), (donePercent > 0.5 ? totalHeight / 4 * 3 : totalHeight / 4 * 1) + 20); } - if (nameVisibleProperty.isEnabled() && name != null && !name.isEmpty()) { + if (nameVisibleProperty.isEnabled() && name != null && !name + .isEmpty()) { brush.drawString( name, ((int) (totalWidth * 0.10)), diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/DayBattery.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/DayBattery.java index 174aebf..c77d33b 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/DayBattery.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/DayBattery.java @@ -6,8 +6,9 @@ package org.nanoboot.utils.timecalc.swing.progress; */ public class DayBattery extends Battery { + public static final String DAY = "Day"; + public DayBattery(int x, int i, int i1) { super(DAY, x, i, i1); } - public static final String DAY = "Day"; } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/HourBattery.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/HourBattery.java index 775ac64..e20a0cf 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/HourBattery.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/HourBattery.java @@ -8,15 +8,16 @@ import org.nanoboot.utils.timecalc.utils.common.TimeHM; */ public class HourBattery extends Battery { + public static final String HOUR = "Hour"; + public HourBattery(int x, int i, int i1) { super(HOUR, x, i, i1); } - public static final String HOUR = "Hour"; public static double getHourProgress(TimeHM timeRemains, int secondsRemains, int millisecondsRemains) { if (secondsRemains < 0 || millisecondsRemains < 0 - || timeRemains.getHour() < 0 || timeRemains.getMinute() < 0) { + || timeRemains.getHour() < 0 || timeRemains.getMinute() < 0) { return 1; } double minutesRemainsD = timeRemains.getMinute(); diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/MinuteBattery.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/MinuteBattery.java index c4d12f2..b92bf5d 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/MinuteBattery.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/MinuteBattery.java @@ -1,17 +1,16 @@ package org.nanoboot.utils.timecalc.swing.progress; -import org.nanoboot.utils.timecalc.utils.common.TimeHM; - /** * @author Robert Vokac * @since 21.02.2024 */ public class MinuteBattery extends Battery { + public static final String MINUTE = "Minute"; + public MinuteBattery(int x, int i, int i1) { super(MINUTE, x, i, i1); } - public static final String MINUTE = "Minute"; public static double getMinuteProgress(int secondNow, int millisecondNow) { return millisecondNow / 60d / 1000d + secondNow / 60d; diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/MonthBattery.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/MonthBattery.java index 7c4f68f..cab8e6e 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/MonthBattery.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/MonthBattery.java @@ -6,10 +6,11 @@ package org.nanoboot.utils.timecalc.swing.progress; */ public class MonthBattery extends Battery { + public static final String MONTH = "Month"; + public MonthBattery(int x, int i, int i1) { super(MONTH, x, i, i1); } - public static final String MONTH = "Month"; public static double getMonthProgress(int weekDayWhenMondayIsOne, int workDaysDone, int workDaysTotal, double done) { @@ -17,8 +18,8 @@ public class MonthBattery extends Battery { done = 1; } return weekDayWhenMondayIsOne == 0 - || weekDayWhenMondayIsOne == 6 - ? workDaysDone / workDaysTotal - : (workDaysDone + done) / workDaysTotal; + || weekDayWhenMondayIsOne == 6 + ? workDaysDone / workDaysTotal + : (workDaysDone + done) / workDaysTotal; } } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressCircle.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressCircle.java index 7356e78..316449e 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressCircle.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressCircle.java @@ -2,11 +2,8 @@ package org.nanoboot.utils.timecalc.swing.progress; import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.swing.common.Widget; -import org.nanoboot.utils.timecalc.utils.common.ProgressSmiley; import org.nanoboot.utils.timecalc.utils.common.NumberFormats; -import javax.swing.ImageIcon; -import javax.swing.JLabel; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; @@ -29,7 +26,7 @@ public class ProgressCircle extends Widget { Graphics2D brush = (Graphics2D) g; brush.setColor( visibility.isStronglyColored() || mouseOver ? Color.darkGray - : FOREGROUND_COLOR); + : FOREGROUND_COLOR); brush.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressSmileyIcon.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressSmileyIcon.java index 743b549..02851b7 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressSmileyIcon.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressSmileyIcon.java @@ -14,12 +14,22 @@ import java.util.Map; */ public class ProgressSmileyIcon extends javax.swing.ImageIcon { - private static final Map cache = new HashMap<>(); + private static final Map cache = + new HashMap<>(); @Getter private final ProgressSmiley progressSmiley; @Getter 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) { if (!cache.containsKey(progressSmiley)) { cache.put(progressSmiley, new ProgressSmileyIcon(progressSmiley)); @@ -27,11 +37,4 @@ public class ProgressSmileyIcon extends javax.swing.ImageIcon { 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)); - } - } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressSquare.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressSquare.java index 0e96da5..3484c03 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressSquare.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/ProgressSquare.java @@ -78,7 +78,7 @@ public class ProgressSquare extends Widget { : BACKGROUND_COLOR); brush.drawString(NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES - .format(donePercent * 100) + "%", + .format(donePercent * 100) + "%", (int) (side / 8d * 3d), (int) (side / 8d * (donePercent > 0.5 ? 3d : 5d))); paintSmiley(visibility, brush, (int) (side / 8d * 3d) + 65, diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/Time.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/Time.java index 0251ce6..f341d71 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/Time.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/Time.java @@ -10,34 +10,34 @@ public class Time extends Thread { private final IntegerProperty yearReadWriteProperty = new IntegerProperty("yearProperty"); - public ReadOnlyProperty yearProperty - = yearReadWriteProperty.asReadOnlyProperty(); private final IntegerProperty monthReadWriteProperty = new IntegerProperty("monthProperty"); - public ReadOnlyProperty monthProperty - = monthReadWriteProperty.asReadOnlyProperty(); private final IntegerProperty dayReadWriteProperty = new IntegerProperty("dayProperty"); - public ReadOnlyProperty dayProperty - = dayReadWriteProperty.asReadOnlyProperty(); private final IntegerProperty hourReadWriteProperty = new IntegerProperty("hourProperty"); - public ReadOnlyProperty hourProperty - = hourReadWriteProperty.asReadOnlyProperty(); private final IntegerProperty minuteReadWriteProperty = new IntegerProperty("minuteProperty"); - public ReadOnlyProperty minuteProperty - = minuteReadWriteProperty.asReadOnlyProperty(); private final IntegerProperty secondReadWriteProperty = new IntegerProperty("secondProperty"); - public ReadOnlyProperty secondProperty - = secondReadWriteProperty.asReadOnlyProperty(); private final IntegerProperty millisecondReadWriteProperty = new IntegerProperty("millisecondProperty"); - public ReadOnlyProperty millisecondProperty - = millisecondReadWriteProperty.asReadOnlyProperty(); private final IntegerProperty dayOfWeekReadWriteProperty = new IntegerProperty("dayOfWeek"); + public ReadOnlyProperty yearProperty + = yearReadWriteProperty.asReadOnlyProperty(); + public ReadOnlyProperty monthProperty + = monthReadWriteProperty.asReadOnlyProperty(); + public ReadOnlyProperty dayProperty + = dayReadWriteProperty.asReadOnlyProperty(); + public ReadOnlyProperty hourProperty + = hourReadWriteProperty.asReadOnlyProperty(); + public ReadOnlyProperty minuteProperty + = minuteReadWriteProperty.asReadOnlyProperty(); + public ReadOnlyProperty secondProperty + = secondReadWriteProperty.asReadOnlyProperty(); + public ReadOnlyProperty millisecondProperty + = millisecondReadWriteProperty.asReadOnlyProperty(); public ReadOnlyProperty dayOfWeek = dayOfWeekReadWriteProperty.asReadOnlyProperty(); //private long lastUpdateNanoTime = 0l; diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/WalkingHumanProgress.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/WalkingHumanProgress.java index d3e1031..0c67474 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/WalkingHumanProgress.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/WalkingHumanProgress.java @@ -20,7 +20,6 @@ import java.awt.Font; import java.awt.Graphics; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; -import java.awt.font.LineBreakMeasurer; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.util.HashSet; @@ -42,6 +41,7 @@ public class WalkingHumanProgress extends Widget implements private double done; private double totalSecondsRemainsDouble; private TimeHM endTime; + public WalkingHumanProgress() { setFont(new Font(Font.MONOSPACED, Font.PLAIN, 11)); putClientProperty("mouseEntered", "false"); @@ -92,7 +92,7 @@ public class WalkingHumanProgress extends Widget implements setForeground( visibility.isStronglyColored() || getClientProperty("mouseEntered").equals("true") - ? Color.BLACK : Color.LIGHT_GRAY); + ? Color.BLACK : Color.LIGHT_GRAY); }).start(); } @@ -117,11 +117,12 @@ public class WalkingHumanProgress extends Widget implements } else { String[] lines = string.split("\n"); - Visibility visibility = 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); int y = SwingUtils.MARGIN; for (String line : lines) { @@ -228,15 +229,15 @@ public class WalkingHumanProgress extends Widget implements double totalSecondsRemainsDouble, TimeHM endTime) { String msg = "Done=" + NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES.format( - done * 100) + "% Remains=" - + String.format("%02d", hourRemains) + ":" + String - .format("%02d", minuteRemains) - + /*":" + String.format("%02d", secondsRemains)+ */ " (" - + NumberFormats.FORMATTER_THREE_DECIMAL_PLACES - .format(totalSecondsRemainsDouble - 60) - + " s" + ")" + " End=" + String - .format("%02d", endTime.getHour()) + ":" + String - .format("%02d", endTime.getMinute()); + done * 100) + "% Remains=" + + String.format("%02d", hourRemains) + ":" + String + .format("%02d", minuteRemains) + + /*":" + String.format("%02d", secondsRemains)+ */ " (" + + NumberFormats.FORMATTER_THREE_DECIMAL_PLACES + .format(totalSecondsRemainsDouble - 60) + + " s" + ")" + " End=" + String + .format("%02d", endTime.getHour()) + ":" + String + .format("%02d", endTime.getMinute()); return msg; } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/WeekBattery.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/WeekBattery.java index 7a91bb3..4e48a08 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/WeekBattery.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/WeekBattery.java @@ -6,10 +6,11 @@ package org.nanoboot.utils.timecalc.swing.progress; */ public class WeekBattery extends Battery { + public static final String WEEK = "Week"; + public WeekBattery(int x, int i, int i1) { super(WEEK, x, i, i1); } - public static final String WEEK = "Week"; public static double getWeekProgress(int weekDayWhenMondayIsOne, double done) { @@ -17,7 +18,7 @@ public class WeekBattery extends Battery { done = 1; } return weekDayWhenMondayIsOne == 0 - || weekDayWhenMondayIsOne == 6 - ? 100 : ((weekDayWhenMondayIsOne - 1) * 0.20 + done * 0.20); + || weekDayWhenMondayIsOne == 6 + ? 100 : ((weekDayWhenMondayIsOne - 1) * 0.20 + done * 0.20); } } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/YearBattery.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/YearBattery.java index b2e3864..d57c272 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/YearBattery.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/YearBattery.java @@ -8,12 +8,15 @@ import java.util.Calendar; */ public class YearBattery extends Battery { + public static final String YEAR = "Year"; + public YearBattery(int x, int i, int 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(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month - 1); @@ -27,12 +30,12 @@ public class YearBattery extends Battery { double minutes = minute + seconds / 60d; double hours = hour + minutes / 60d; double days = cal.get(Calendar.DAY_OF_YEAR) + hours / 24d; -// System.out.println("millisecond=" + millisecond); -// System.out.println("seconds=" + seconds); -// System.out.println("minutes=" + minutes); -// System.out.println("hours=" + hours); -// System.out.println("days=" + days); -// System.out.println("cal.get(Calendar.DAY_OF_YEAR)=" + cal.get(Calendar.DAY_OF_YEAR)); + // System.out.println("millisecond=" + millisecond); + // System.out.println("seconds=" + seconds); + // System.out.println("minutes=" + minutes); + // System.out.println("hours=" + hours); + // System.out.println("days=" + days); + // System.out.println("cal.get(Calendar.DAY_OF_YEAR)=" + cal.get(Calendar.DAY_OF_YEAR)); double totalCountOfDaysInAYear = getTotalCountOfDaysInAYear(year); return days / totalCountOfDaysInAYear; diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/FileConstants.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/FileConstants.java index 6d4b7f3..3e8f9b2 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/FileConstants.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/FileConstants.java @@ -8,12 +8,17 @@ import java.io.File; */ public class FileConstants { 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 OVERTIME_TXT = new File(TC_DIRECTORY, "overtime.txt"); + public static final File STARTTIME_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 TIME_CALC_PROFILES_TXT_FILE = new File(TC_DIRECTORY, "time-calc-profiles.txt"); - 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"); + public static final File TIME_CALC_PROFILES_TXT_FILE = + new File(TC_DIRECTORY, "time-calc-profiles.txt"); + 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() { //Not meant to be instantiated. diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/JokesTxt.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/JokesTxt.java index 00a4141..f1743c0 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/JokesTxt.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/JokesTxt.java @@ -17,7 +17,7 @@ public class JokesTxt { File jokeTxtFile = new File("jokes.txt"); if (!jokeTxtFile.exists()) { //nothing to do - return new String[]{"A", "B", "C"}; + return new String[] {"A", "B", "C"}; } return Utils.readTextFromFile(jokeTxtFile).split("-----SEPARATOR-----"); } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/ProgressSmiley.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/ProgressSmiley.java index cd93937..702e378 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/ProgressSmiley.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/ProgressSmiley.java @@ -38,10 +38,6 @@ public enum ProgressSmiley { this.description = d; } - public int getNumber() { - return Integer.valueOf(this.name().replace("SMILEY_", "")); - } - public static ProgressSmiley forNumber(int number) { for (ProgressSmiley s : ProgressSmiley.values()) { if (s.getNumber() == number) { @@ -64,7 +60,8 @@ public enum ProgressSmiley { public static void main(String[] args) { 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) { return String.format("\\u%04x", (int) ch); } + + public int getNumber() { + return Integer.valueOf(this.name().replace("SMILEY_", "")); + } } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/TimeHM.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/TimeHM.java index 5ec0a16..293d7b3 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/TimeHM.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/TimeHM.java @@ -46,7 +46,7 @@ public class TimeHM { public static int countDiffInMinutes(TimeHM startTime, TimeHM endTime) { return (endTime.getHour() * TimeHM.MINUTES_PER_HOUR + endTime .getMinute()) - (startTime.getHour() * TimeHM.MINUTES_PER_HOUR - + startTime.getMinute()); + + startTime.getMinute()); } public TimeHM cloneInstance() { diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/Utils.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/Utils.java index 2d99156..60bce9b 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/Utils.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/common/Utils.java @@ -2,11 +2,8 @@ package org.nanoboot.utils.timecalc.utils.common; import org.nanoboot.utils.timecalc.app.Main; import org.nanoboot.utils.timecalc.swing.common.Toaster; -import org.nanoboot.utils.timecalc.utils.property.BooleanProperty; import java.awt.Color; -import java.awt.Font; -import java.awt.FontFormatException; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; @@ -110,7 +107,7 @@ public class Utils { } String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) - + "/META-INF/MANIFEST.MF"; + + "/META-INF/MANIFEST.MF"; Manifest manifest; try { manifest = new Manifest(new URL(manifestPath).openStream()); @@ -128,7 +125,8 @@ public class Utils { .decode(s.getBytes()); } - public static String readTextFromTextResourceInJar(String pathToFile) throws IOException { + public static String readTextFromTextResourceInJar(String pathToFile) + throws IOException { InputStream inputStream = ClassLoader.getSystemClassLoader(). getSystemResourceAsStream(pathToFile); InputStreamReader streamReader = new InputStreamReader(inputStream, @@ -136,21 +134,25 @@ public class Utils { BufferedReader in = new BufferedReader(streamReader); StringBuilder sb = new StringBuilder(); - for (String line; (line = in.readLine()) != null;) { + for (String line; (line = in.readLine()) != null; ) { sb.append(line).append("\n"); } return sb.toString(); } + public static void showNotification(String message) { showNotification(message, 0); } + public static void showNotification(String message, int displayTime) { 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.setDisplayTime(displayTime == 0 ? 15000 : displayTime); - if(height != 0) { + if (height != 0) { toaster.setToasterHeight(height); } toaster.showToaster(message); diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/Property.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/Property.java index 26d6adb..9e31b49 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/Property.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/Property.java @@ -14,12 +14,13 @@ public class Property { @Getter private final String name; + private final List invalidationListeners + = new ArrayList<>(); + private final List> changeListeners = + new ArrayList>(); private boolean valid = true; private T value; private Property boundToProperty = null; - private final List invalidationListeners - = new ArrayList<>(); - private final List> changeListeners = new ArrayList>(); private ChangeListener boundChangeListener = null; public Property(String name, T valueIn) { @@ -54,10 +55,10 @@ public class Property { this.boundToProperty = anotherProperty; this.boundChangeListener = (Property p, T oldValue, T newValue) -> { - this.markInvalid(); - this.fireValueChangedEvent(oldValue); - //System.out.println("bindTo markInvalid " + p.getName() + " " + p.getValue()); - }; + this.markInvalid(); + this.fireValueChangedEvent(oldValue); + //System.out.println("bindTo markInvalid " + p.getName() + " " + p.getValue()); + }; this.boundToProperty .addListener(boundChangeListener);