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 a7d273e..99d3bff 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 @@ -3,6 +3,7 @@ package org.nanoboot.utils.timecalc.app; import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.utils.common.Constants; import org.nanoboot.utils.timecalc.utils.common.FileConstants; +import org.nanoboot.utils.timecalc.utils.property.BooleanProperty; import org.nanoboot.utils.timecalc.utils.property.ReadOnlyProperty; import org.nanoboot.utils.timecalc.utils.property.StringProperty; import org.nanoboot.utils.timecalc.utils.common.Utils; @@ -17,11 +18,11 @@ import java.io.IOException; public class TimeCalcApp { private long startNanoTime = 0l; - private StringProperty visibilityReadWriteProperty = new StringProperty(Visibility.STRONGLY_COLORED.name()); - public ReadOnlyProperty visibilityProperty = visibilityReadWriteProperty.asReadOnlyProperty(); + public StringProperty visibilityProperty = new StringProperty("visibilityReadWriteProperty", Visibility.STRONGLY_COLORED.name()); + public BooleanProperty + wavesProperty = new BooleanProperty("waves", true); public void start(String[] args) throws IOException { - if(startNanoTime != 0l) { throw new TimeCalcException("TimeCalcApp was already started."); } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcManager.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcManager.java index a4531d7..4baccdb 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcManager.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/app/TimeCalcManager.java @@ -1,5 +1,6 @@ package org.nanoboot.utils.timecalc.app; +import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.swing.common.AboutButton; import org.nanoboot.utils.timecalc.swing.common.ComponentRegistry; import org.nanoboot.utils.timecalc.swing.common.TimeCalcButton; @@ -54,10 +55,10 @@ public class TimeCalcManager { public TimeCalcManager(String startTimeIn, String overTimeIn, TimeCalcApp timeCalcApp) { this.timeCalcApp = timeCalcApp; - Utils.everythingHidden - .setValue(TimeCalcConf.getInstance().isEverythingHidden()); - Utils.toastsAreEnabled - .setValue(TimeCalcConf.getInstance().areToastsEnabled()); +// Utils.everythingHidden +// .setValue(TimeCalcConf.getInstance().isEverythingHidden()); +// Utils.toastsAreEnabled +// .setValue(TimeCalcConf.getInstance().areToastsEnabled()); overTimeIn = (overTimeIn == null || overTimeIn.isEmpty()) ? Constants.DEFAULT_OVERTIME : overTimeIn; @@ -87,43 +88,54 @@ public class TimeCalcManager { window.addKeyListener(new KeyAdapter() { // Key Pressed method public void keyPressed(KeyEvent e) { + Visibility visibility = Visibility.valueOf(timeCalcApp.visibilityProperty.getValue()); if (e.getKeyCode() == KeyEvent.VK_UP) { - Utils.everythingHidden.setValue(false); + timeCalcApp.visibilityProperty.setValue(Visibility.STRONGLY_COLORED.name()); } if (e.getKeyCode() == KeyEvent.VK_DOWN) { - Utils.everythingHidden.setValue(true); + timeCalcApp.visibilityProperty.setValue(Visibility.NONE.name()); } if (e.getKeyCode() == KeyEvent.VK_H) { - Utils.everythingHidden.flip(); + if(visibility.isNone()) { + timeCalcApp.visibilityProperty.setValue(Visibility.STRONGLY_COLORED.name()); + } else { + timeCalcApp.visibilityProperty.setValue(Visibility.NONE.name()); + } } if (e.getKeyCode() == KeyEvent.VK_G) { - if(!Utils.ultraLight.getValue() && Utils.highlighted.isEnabled()) { - Utils.highlighted.disable(); + if(visibility.isGray()) { + timeCalcApp.visibilityProperty.setValue(Visibility.WEAKLY_COLORED.name()); + } else { + timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name()); } - Utils.ultraLight.flip(); } if (e.getKeyCode() == KeyEvent.VK_C) { - if(Utils.ultraLight.getValue() && !Utils.highlighted.isEnabled()) { - Utils.ultraLight.disable(); + if(visibility.isStronglyColored()) { + timeCalcApp.visibilityProperty.setValue(Visibility.WEAKLY_COLORED.name()); + } else { + timeCalcApp.visibilityProperty.setValue(Visibility.STRONGLY_COLORED.name()); } - Utils.highlighted.flip(); } if (e.getKeyCode() == KeyEvent.VK_V) { - Utils.everythingHidden.flip(); + if(visibility.isNone()) { + timeCalcApp.visibilityProperty.setValue(Visibility.STRONGLY_COLORED.name()); + } else { + timeCalcApp.visibilityProperty.setValue(Visibility.NONE.name()); + } } if (e.getKeyCode() == KeyEvent.VK_SPACE) { - if(Utils.everythingHidden.isEnabled()) { - Utils.everythingHidden.disable(); - Utils.highlighted.enable(); - Utils.ultraLight.disable(); - } else { - if(Utils.highlighted.isEnabled()) { - Utils.ultraLight.enable(); - Utils.highlighted.disable(); - } else { - Utils.everythingHidden.enable(); - } + if(visibility.isStronglyColored()) { + timeCalcApp.visibilityProperty.setValue(Visibility.WEAKLY_COLORED.name()); + } + if(visibility.isWeaklyColored()) { + timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name()); + } + if(visibility.isGray()) { + timeCalcApp.visibilityProperty.setValue(Visibility.NONE.name()); + } + if(visibility.isNone()) { + timeCalcApp.visibilityProperty.setValue(Visibility.STRONGLY_COLORED.name()); } } if (e.getKeyCode() == KeyEvent.VK_R) { @@ -179,15 +191,13 @@ public class TimeCalcManager { JOptionPane.showMessageDialog(null, "Test"); break; case "color": - Utils.highlighted - .setValue(commandsAsArray[1].equals("1")); + timeCalcApp.visibilityProperty.setValue(commandsAsArray[1].equals("1") ? Visibility.STRONGLY_COLORED.name() : Visibility.WEAKLY_COLORED.name()); break; case "gray": - Utils.ultraLight - .setValue(commandsAsArray[1].equals("1")); + timeCalcApp.visibilityProperty.setValue(commandsAsArray[1].equals("1") ? Visibility.GRAY.name() : Visibility.WEAKLY_COLORED.name()); break; case "waves": - Battery.wavesOff = commandsAsArray[1].equals("0"); + timeCalcApp.wavesProperty.setValue(commandsAsArray[1].equals("1")); break; case "uptime": JOptionPane.showMessageDialog(null, @@ -228,12 +238,14 @@ public class TimeCalcManager { AnalogClock analogClock = new AnalogClock(startTime, endTime); analogClock.setBounds(MARGIN, MARGIN, 200); + window.add(analogClock); ProgressSquare progressSquare = new ProgressSquare(); progressSquare .setBounds(MARGIN + analogClock.getWidth() + MARGIN, MARGIN, 200); + window.add(progressSquare); ProgressCircle progressCircle = new ProgressCircle(); @@ -241,12 +253,14 @@ public class TimeCalcManager { .setBounds( MARGIN + progressSquare.getBounds().x + progressSquare .getWidth() + MARGIN, MARGIN, 80); + window.add(progressCircle); Battery dayBattery = new DayBattery(progressCircle.getBounds().x, progressCircle.getY() + MARGIN + progressCircle.getHeight(), 140); window.add(dayBattery); + Battery weekBattery = new WeekBattery( dayBattery.getBounds().x + dayBattery.getWidth() + MARGIN * 2, dayBattery.getY(), 140); @@ -298,6 +312,10 @@ public class TimeCalcManager { weekBattery.setBounds(hourBattery.getX(), hourBattery.getY() + hourBattery.getHeight() + MARGIN, hourBattery.getWidth(), hourBattery.getHeight()); monthBattery.setBounds(hourBattery.getX() + hourBattery.getWidth() + MARGIN, hourBattery.getY() + hourBattery.getHeight() + MARGIN, hourBattery.getWidth(), hourBattery.getHeight()); + hourBattery.wavesProperty.bindTo(timeCalcApp.wavesProperty.asReadOnlyProperty()); + dayBattery.wavesProperty.bindTo(timeCalcApp.wavesProperty.asReadOnlyProperty()); + weekBattery.wavesProperty.bindTo(timeCalcApp.wavesProperty.asReadOnlyProperty()); + monthBattery.wavesProperty.bindTo(timeCalcApp.wavesProperty.asReadOnlyProperty()); ComponentRegistry componentRegistry = new ComponentRegistry(); componentRegistry.addAll( @@ -314,6 +332,24 @@ public class TimeCalcManager { restartButton, exitButton ); + walkingHumanProgressAsciiArt.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); + progressSquare.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); + progressCircle.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); + analogClock.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); + dayBattery.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); + weekBattery.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); + monthBattery.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); + hourBattery.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); + jokeButton.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); + commandButton.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); + restartButton.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); + exitButton.visibilityProperty.bindTo(timeCalcApp.visibilityProperty); + + jokeButton.setVisible(!Visibility.valueOf(jokeButton.visibilityProperty.getValue()).isNone()); + commandButton.setVisible(!Visibility.valueOf(commandButton.visibilityProperty.getValue()).isNone()); + restartButton.setVisible(!Visibility.valueOf(restartButton.visibilityProperty.getValue()).isNone()); + exitButton.setVisible(!Visibility.valueOf(exitButton.visibilityProperty.getValue()).isNone()); + window.setSize(520 + 20 + 100, exitButton.getY() + 3 * exitButton.getHeight() + MARGIN); while (true) { if(Math.random() > 0.95) { @@ -325,8 +361,9 @@ public class TimeCalcManager { break; } - componentRegistry.setVisible(!Utils.everythingHidden.getValue()); - if (!Utils.highlighted.getValue() || Utils.ultraLight.getValue()) { + Visibility visibility = Visibility.valueOf(timeCalcApp.visibilityProperty.getValue()); + componentRegistry.setVisible(visibility.isNotNone()); + if (!visibility.isStronglyColored() || visibility.isGray()) { jokeButton.setBackground(BG); commandButton.setBackground(BG); restartButton.setBackground(BG); @@ -349,9 +386,9 @@ public class TimeCalcManager { } jokeButton.setVisible( TimeCalcConf.getInstance().isJokeVisible() - && !Utils.everythingHidden.getValue()); + && !visibility.isNone()); - window.setTitle(Utils.everythingHidden.getValue() ? "" : windowTitle); + window.setTitle(visibility.isNone() ? "" : windowTitle); LocalDateTime now = LocalDateTime.now(); String nowString = @@ -443,7 +480,7 @@ public class TimeCalcManager { } walkingHumanProgressAsciiArt.setForeground( - Utils.highlighted.getValue() || walkingHumanProgressAsciiArt + visibility.isStronglyColored() || walkingHumanProgressAsciiArt .getClientProperty("mouseEntered").equals("true") ? Color.BLACK : Color.LIGHT_GRAY); } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/entity/Visibility.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/entity/Visibility.java index 6f08b10..e477b0b 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/entity/Visibility.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/entity/Visibility.java @@ -1,9 +1,29 @@ package org.nanoboot.utils.timecalc.entity; +import org.nanoboot.utils.timecalc.utils.property.StringProperty; + /** * @author Robert * @since 23.02.2024 */ public enum Visibility { STRONGLY_COLORED, WEAKLY_COLORED, GRAY, NONE; + public boolean isStronglyColored() { + return this == STRONGLY_COLORED; + } + public boolean isWeaklyColored() { + return this == WEAKLY_COLORED; + } + public boolean isGray() { + return this == GRAY; + } + public boolean isNone() { + return this == NONE; + } + public boolean isNotNone() { + return !isNone(); + } + public static Visibility ofProperty(StringProperty stringProperty) { + return Visibility.valueOf(stringProperty.getValue()); + } } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/TimeCalcButton.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/TimeCalcButton.java index 34a295d..af53ef3 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/TimeCalcButton.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/common/TimeCalcButton.java @@ -1,5 +1,8 @@ package org.nanoboot.utils.timecalc.swing.common; +import org.nanoboot.utils.timecalc.entity.Visibility; +import org.nanoboot.utils.timecalc.utils.property.StringProperty; + import javax.swing.JButton; import javax.swing.Timer; import java.awt.Color; @@ -14,6 +17,8 @@ public class TimeCalcButton extends JButton { private Color originalBackground; private Color originalForeground; + public StringProperty visibilityProperty = new StringProperty("visibilityProperty", Visibility.STRONGLY_COLORED.name()); + public TimeCalcButton(String label) { super(label); } 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 eb85659..6bbf952 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 @@ -116,7 +116,7 @@ public class Toaster { * Show a toaster with the specified message and the associated icon. */ public void showToaster(Icon icon, String msg) { - if (Utils.everythingHidden.getValue() || !Utils.toastsAreEnabled.getValue()) { + if (!Utils.toastsAreEnabled.getValue()) { //nothing to do return; } 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 37c42ef..bce3442 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,8 +1,6 @@ package org.nanoboot.utils.timecalc.swing.common; -import org.nanoboot.utils.timecalc.app.TimeCalcConf; import org.nanoboot.utils.timecalc.entity.Visibility; -import org.nanoboot.utils.timecalc.utils.common.TimeHM; import org.nanoboot.utils.timecalc.utils.property.StringProperty; import org.nanoboot.utils.timecalc.utils.common.Utils; @@ -10,12 +8,8 @@ import javax.swing.JPanel; import javax.swing.Timer; import java.awt.Color; import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.RenderingHints; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; -import java.util.Calendar; -import java.util.GregorianCalendar; /** * @author Robert @@ -29,7 +23,7 @@ public class Widget extends JPanel { protected double donePercent = 0; protected boolean mouseOver = false; - public StringProperty visibilityProperty = new StringProperty(Visibility.STRONGLY_COLORED.name()); + public StringProperty visibilityProperty = new StringProperty("visibilityProperty", Visibility.STRONGLY_COLORED.name()); public Widget() { setBackground(BACKGROUND_COLOR); @@ -37,7 +31,12 @@ public class Widget extends JPanel { addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { - Utils.highlighted.flip(); + Visibility visibility = Visibility.valueOf(visibilityProperty.getValue()); + if(visibility.isStronglyColored()) { + visibilityProperty.setValue(Visibility.WEAKLY_COLORED.name()); + } else { + visibilityProperty.setValue(Visibility.STRONGLY_COLORED.name()); + } } @Override @@ -83,6 +82,7 @@ public class Widget extends JPanel { @Override public final void paintComponent(Graphics g) { super.paintComponent(g); + Visibility visibility = Visibility.valueOf(visibilityProperty.getValue()); this.setVisible(visibility != Visibility.NONE); paintWidget(g); 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 764ffd0..2366036 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 @@ -5,7 +5,6 @@ import org.nanoboot.utils.timecalc.swing.common.Widget; import org.nanoboot.utils.timecalc.app.TimeCalcConf; import org.nanoboot.utils.timecalc.utils.common.DateFormats; import org.nanoboot.utils.timecalc.utils.common.TimeHM; -import org.nanoboot.utils.timecalc.utils.common.Utils; import javax.swing.JFrame; import java.awt.BasicStroke; @@ -24,7 +23,6 @@ public class AnalogClock extends Widget { private TimeHM startTime; private TimeHM endTime; - private int angleDiff; private int startAngle; private int endAngle; @@ -77,7 +75,7 @@ public class AnalogClock extends Widget { @Override public void paintWidget(Graphics g) { - super.paintComponent(g); + Visibility visibility = Visibility.valueOf(visibilityProperty.getValue()); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, @@ -92,7 +90,7 @@ public class AnalogClock extends Widget { int minute = time.get(Calendar.MINUTE); int hour = time.get(Calendar.HOUR_OF_DAY); - if(mouseOver && Utils.highlighted.isEnabled()) { + if(mouseOver && visibility.isStronglyColored()) { this.startTime = new TimeHM(hour, minute); this.startAngle = (int) ((startTime.getHour() + startTime.getMinute() / 60d) / 12d * 360d); @@ -107,35 +105,35 @@ public class AnalogClock extends Widget { } // Draw clock numbers and circle - drawClockFace(g2d, centerX, centerY, side / 2 - 40); + drawClockFace(g2d, centerX, centerY, side / 2 - 40, visibility); - drawHand(g2d, side / 2 - 10, second / 60.0, 0.5f, Color.RED); + drawHand(g2d, side / 2 - 10, second / 60.0, 0.5f, Color.RED, visibility); if (TimeCalcConf.getInstance().areClockHandsLong()) { drawHand(g2d, (side / 2 - 10) / 4, (second > 30 ? second - 30 : second + 30) / 60.0, 0.5f, - Color.RED); + Color.RED, visibility); } // double minutes = minute / 60.0 + second / 60.0 / 60.0; drawHand(g2d, side / 2 - 20, minutes, 2.0f, - Color.BLUE); + Color.BLUE, visibility); if (TimeCalcConf.getInstance().areClockHandsLong()) { drawHand(g2d, (side / 2 - 20) / 4, minutes + minutes > 0.5 ? minutes - 0.5 : minutes + (minutes > 0.5 ? (-1) : 1) * 0.5, 2.0f, - Color.BLUE); + Color.BLUE, visibility); } // double hours = hour / 12.0 + minute / 60.0 / 12 + second / 60 / 60 / 12; drawHand(g2d, side / 2 - 40, hours, 4.0f, - Color.BLACK); + Color.BLACK, visibility); if (TimeCalcConf.getInstance().areClockHandsLong()) { drawHand(g2d, (side / 2 - 40) / 4, hours + hours > 0.5 ? hours - 0.5 : hours + (hours > 0.5 ? (-1) : 1) * 0.5, 4.0f, - Color.BLACK); + Color.BLACK, visibility); } drawCentre(g2d, centerX, centerY); @@ -143,29 +141,30 @@ public class AnalogClock extends Widget { private void drawCentre(Graphics2D g2d, int centerX, int centerY) { Color currentColor = g2d.getColor(); - g2d.setColor(Utils.highlighted.getValue() || mouseOver ? Color.RED : + Visibility visibility = Visibility.valueOf(visibilityProperty.getValue()); + g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.RED : FOREGROUND_COLOR); g2d.fillOval(centerX - 3, centerY - 3, 8, 8); g2d.setColor(currentColor); } private void drawHand(Graphics2D g2d, int length, double value, - float stroke, Color color) { + float stroke, Color color, Visibility visibility) { length = length - 4; double angle = Math.PI * 2 * (value - 0.25); int endX = (int) (getWidth() / 2 + length * Math.cos(angle)); int endY = (int) (getHeight() / 2 + length * Math.sin(angle)); - g2d.setColor((Utils.highlighted.getValue() || mouseOver) ? color : + g2d.setColor((visibility.isStronglyColored() || mouseOver) ? color : FOREGROUND_COLOR); g2d.setStroke(new BasicStroke(stroke)); g2d.drawLine(getWidth() / 2, getHeight() / 2, endX, endY); } private void drawClockFace(Graphics2D g2d, int centerX, int centerY, - int radius) { + int radius, Visibility visibility) { g2d.setStroke(new BasicStroke(2.0f)); - g2d.setColor(Utils.highlighted.getValue() || mouseOver ? Color.BLACK : + g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.BLACK : FOREGROUND_COLOR); // System.out.println("centerX=" + centerX); // System.out.println("centerY=" + centerY); 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 dc0ba70..003877b 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 @@ -1,6 +1,7 @@ package org.nanoboot.utils.timecalc.swing.progress; import lombok.Getter; +import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.swing.common.Widget; import org.nanoboot.utils.timecalc.app.TimeCalcConf; import org.nanoboot.utils.timecalc.utils.property.BooleanProperty; @@ -27,9 +28,9 @@ public class Battery extends Widget { public static final double LOW_ENERGY = 0.15; public static final double HIGH_ENERGY = 0.75; public static final double VERY_HIGH_ENERGY = 0.9; - public static boolean wavesOff = false; + public BooleanProperty wavesProperty = new BooleanProperty("waves", true); private static final Font bigFont = new Font("sans", Font.BOLD, 24); - private BooleanProperty blinking = new BooleanProperty(); + private BooleanProperty blinking = new BooleanProperty("blinking"); private long tmpNanoTime = 0l; @Getter @@ -64,19 +65,20 @@ public class Battery extends Widget { if(donePercent <= 0 && blinking.getValue()){ blinking.setValue(false); } - super.paintComponent(g); + Graphics2D g2d = (Graphics2D) g; - g2d.setColor(Utils.highlighted.getValue() || mouseOver ? Color.YELLOW : + Visibility visibility = Visibility.valueOf(visibilityProperty.getValue()); + g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.YELLOW : FOREGROUND_COLOR); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - if (!Utils.ultraLight.getValue()) { + if (!visibility.isGray()) { g2d.fillRect(1, 1, totalWidth, totalHeight); } - if (Utils.highlighted.getValue() || mouseOver) { + if (visibility.isStronglyColored() || mouseOver) { g2d.setColor( donePercent < LOW_ENERGY ? LOW_HIGHLIGHTED : (donePercent < HIGH_ENERGY ? MEDIUM_HIGHLIGHTED : @@ -86,7 +88,7 @@ public class Battery extends Widget { g2d.setColor(donePercent < LOW_ENERGY ? LOW : (donePercent < HIGH_ENERGY ? MEDIUM : (donePercent < VERY_HIGH_ENERGY ? HIGH : HIGHEST))); } - if (Utils.ultraLight.getValue()) { + if (visibility.isGray()) { g2d.setColor(Utils.ULTRA_LIGHT_GRAY); } if(blinking.getValue()) { @@ -100,7 +102,7 @@ public class Battery extends Widget { int waterSurfaceHeight = (int) (4 * surfacePower);//2 + (int) (Math.random() * 3); if (waterSurfaceHeight <= 2 || !TimeCalcConf.getInstance() - .areBatteryWavesEnabled() || wavesOff) { + .areBatteryWavesEnabled() || wavesProperty.isDisabled()) { waterSurfaceHeight = 0; } @@ -138,7 +140,7 @@ public class Battery extends Widget { todoHeight + (waterSurfaceHeight * 1)}, pointCount); - g2d.setColor((Utils.ultraLight.getValue() || !Utils.highlighted.getValue()) && !mouseOver ? Utils.ULTRA_LIGHT_GRAY : Color.DARK_GRAY); + g2d.setColor((visibility.isGray() || !visibility.isStronglyColored()) && !mouseOver ? Utils.ULTRA_LIGHT_GRAY : Color.DARK_GRAY); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); @@ -169,7 +171,7 @@ public class Battery extends Widget { g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } - g2d.setColor(Utils.highlighted.getValue() || mouseOver ? Color.BLACK : + g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.BLACK : Color.LIGHT_GRAY); if(donePercent <1) { @@ -199,7 +201,7 @@ public class Battery extends Widget { ((int) (totalWidth * 0.15)), (totalHeight / 4 * 3) + 20 + 20); } - g2d.setColor(Utils.highlighted.getValue() || mouseOver ? Color.BLACK : + g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.BLACK : Color.LIGHT_GRAY); g2d.drawRect(1, 1, totalWidth - 2, totalHeight); 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 d6c3bab..c46f3c9 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 @@ -1,5 +1,6 @@ package org.nanoboot.utils.timecalc.swing.progress; +import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.swing.common.Widget; import org.nanoboot.utils.timecalc.utils.common.NumberFormats; import org.nanoboot.utils.timecalc.utils.common.Utils; @@ -21,9 +22,9 @@ public class ProgressCircle extends Widget { if (side == 0) { this.side = Math.min(getWidth(), getHeight()); } - super.paintComponent(g); + Visibility visibility = Visibility.valueOf(visibilityProperty.getValue()); Graphics2D g2d = (Graphics2D) g; - g2d.setColor(Utils.highlighted.getValue() || mouseOver ? Color.darkGray : + g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.darkGray : FOREGROUND_COLOR); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); @@ -34,11 +35,11 @@ public class ProgressCircle extends Widget { g2d.fillArc(0, 0, side, side, 90, -(int) angleDouble); int side2 = side / 2; - g2d.setColor(Utils.highlighted.getValue() || mouseOver ? + g2d.setColor(visibility.isStronglyColored() || mouseOver ? new Color(105, 175, 236) : FOREGROUND_COLOR2); g2d.fillArc(0 + (side2 / 2), 0 + (side2 / 2), side2, side2, 90, -(int) angleDouble2); - g2d.setColor(Utils.highlighted.getValue() || mouseOver ? Color.blue :FOREGROUND_COLOR); + g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.blue :FOREGROUND_COLOR); g2d.drawString( NumberFormats.FORMATTER_ZERO_DECIMAL_PLACES.format(donePercent * 100) + "%", (int)(side / 8d * 0d),(int)(side / 8d * 7.5d)); 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 3f9c365..7c799a2 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 @@ -1,5 +1,6 @@ package org.nanoboot.utils.timecalc.swing.progress; +import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.swing.common.Widget; import org.nanoboot.utils.timecalc.utils.common.NumberFormats; import org.nanoboot.utils.timecalc.utils.common.Utils; @@ -24,7 +25,7 @@ public class ProgressSquare extends Widget { this.side = Math.min(getWidth(), getHeight()); this.square = side * side; } - super.paintComponent(g); + Graphics2D g2d = (Graphics2D) g; g2d.setColor(FOREGROUND_COLOR); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, @@ -38,8 +39,9 @@ public class ProgressSquare extends Widget { // System.out.println("dotNumber=" + dotNumber); // System.out.println("x=" + x); // System.out.println("y=" + y); + Visibility visibility = Visibility.ofProperty(visibilityProperty); if (y > 1) { - if (Utils.highlighted.getValue() || mouseOver) { + if (visibility.isStronglyColored() || mouseOver) { g2d.setColor(Color.GRAY); } g2d.fillRect(side - 4, side - 4, 4, 4); @@ -48,32 +50,32 @@ public class ProgressSquare extends Widget { g2d.setColor(FOREGROUND_COLOR); g2d.fillRect(1, 1, side, y - 1); if (x > 1) { - if (Utils.highlighted.getValue() || mouseOver) { + if (visibility.isStronglyColored() || mouseOver) { g2d.setColor(Color.GRAY); } g2d.drawRect(1, y, x - 1, 1); } - if (Utils.highlighted.getValue() || mouseOver) { + if (visibility.isStronglyColored() || mouseOver) { g2d.setColor(Color.GRAY); } g2d.fillRect(side - 4, 1, 4, 4); g2d.fillRect(1, 1, 4, 4); - if (Utils.highlighted.getValue() || mouseOver) { + if (visibility.isStronglyColored() || mouseOver) { g2d.setColor(Color.GRAY); } g2d.drawLine(1, 1, x, y); // g2d.drawLine(1+1, 1+1, x+1, y+1); g2d.drawLine(1, 1 + 1, x, y + 1); g2d.drawLine(1, 1 + 1, x, y + 1); - if (Utils.highlighted.getValue() || mouseOver) { + if (visibility.isStronglyColored() || mouseOver) { g2d.setColor(Color.BLUE); g2d.drawLine(x - 10, y - 10, x + 10, y + 10); g2d.drawLine(x + 10, y - 10, x - 10, y + 10); } g2d.setColor(FOREGROUND_COLOR); } - g2d.setColor(Utils.highlighted.getValue() || mouseOver ? Color.BLACK : BACKGROUND_COLOR); + g2d.setColor(visibility.isStronglyColored() || mouseOver ? Color.BLACK : BACKGROUND_COLOR); g2d.drawString(NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES.format(donePercent * 100) + "%", (int)(side/8d*3d),(int)(side/8d*(donePercent > 0.5 ? 3d : 5d))); diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/WalkingHumanProgressAsciiArt.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/WalkingHumanProgressAsciiArt.java index 2db826e..8db3bc0 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/WalkingHumanProgressAsciiArt.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/swing/progress/WalkingHumanProgressAsciiArt.java @@ -1,10 +1,12 @@ package org.nanoboot.utils.timecalc.swing.progress; +import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.swing.common.Toaster; import org.nanoboot.utils.timecalc.utils.common.Constants; import org.nanoboot.utils.timecalc.utils.common.NumberFormats; import org.nanoboot.utils.timecalc.utils.common.TimeHM; import org.nanoboot.utils.timecalc.utils.common.Utils; +import org.nanoboot.utils.timecalc.utils.property.StringProperty; import javax.imageio.ImageIO; import javax.swing.ImageIcon; @@ -25,6 +27,7 @@ import java.util.Set; public class WalkingHumanProgressAsciiArt extends JTextPane { private final Set alreadyShownPercents = new HashSet<>(); private static final String WALL = "||"; + public StringProperty visibilityProperty = new StringProperty("visibilityProperty", Visibility.STRONGLY_COLORED.name()); public WalkingHumanProgressAsciiArt() { setFont(new Font(Font.MONOSPACED, Font.PLAIN, 11)); putClientProperty("mouseEntered", "false"); @@ -34,7 +37,12 @@ public class WalkingHumanProgressAsciiArt extends JTextPane { addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { - Utils.highlighted.flip(); + Visibility visibility = Visibility.valueOf(visibilityProperty.getValue()); + if(visibility.isStronglyColored()) { + visibilityProperty.setValue(Visibility.WEAKLY_COLORED.name()); + } else { + visibilityProperty.setValue(Visibility.STRONGLY_COLORED.name()); + } } @Override @@ -60,6 +68,10 @@ public class WalkingHumanProgressAsciiArt extends JTextPane { } public void printPercentToAscii(double percent, int hourRemains, int minuteRemains, double done, double totalSecondsRemainsDouble, TimeHM endTime) { + + Visibility visibility = Visibility.valueOf(visibilityProperty.getValue()); + this.setVisible(visibility != Visibility.NONE); + StringBuilder sb = new StringBuilder(); String msg = createMessage(hourRemains, minuteRemains, done, totalSecondsRemainsDouble, endTime); int percentInt = (int) (percent * 100); 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 4e60051..3d1d556 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 @@ -20,10 +20,7 @@ import java.util.jar.Manifest; */ public class Utils { - public static final BooleanProperty highlighted = new BooleanProperty(); - public static final BooleanProperty ultraLight = new BooleanProperty(); - public static final BooleanProperty everythingHidden = new BooleanProperty(); - public static final BooleanProperty toastsAreEnabled = new BooleanProperty(true); + public static final BooleanProperty toastsAreEnabled = new BooleanProperty("toastsAreEnabled", true); public static final Color ULTRA_LIGHT_GRAY = new Color(216,216,216); /** * Count of bytes per one kilobyte. diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/BooleanProperty.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/BooleanProperty.java index 281cd65..36108fa 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/BooleanProperty.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/BooleanProperty.java @@ -6,14 +6,14 @@ package org.nanoboot.utils.timecalc.utils.property; */ public class BooleanProperty extends Property { - public BooleanProperty() { - super(Boolean.FALSE); + public BooleanProperty(String name) { + super(name, Boolean.FALSE); } - public BooleanProperty(boolean valueIn) { - this(Boolean.valueOf(valueIn)); + public BooleanProperty(String name, boolean valueIn) { + this(name, Boolean.valueOf(valueIn)); } - public BooleanProperty(Boolean valueIn) { - super(valueIn); + public BooleanProperty(String name, Boolean valueIn) { + super(name, valueIn); } public boolean isEnabled() { diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/BooleanReadOnlyProperty.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/BooleanReadOnlyProperty.java index 3989d82..bab2e83 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/BooleanReadOnlyProperty.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/BooleanReadOnlyProperty.java @@ -6,8 +6,8 @@ package org.nanoboot.utils.timecalc.utils.property; */ public class BooleanReadOnlyProperty extends ReadOnlyProperty { - public BooleanReadOnlyProperty(Boolean valueIn) { - super(valueIn); + public BooleanReadOnlyProperty(String name, Boolean valueIn) { + super(name, valueIn); } public BooleanReadOnlyProperty(Property property) { super(property); 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 8e9aee6..66c8ae5 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 @@ -3,18 +3,18 @@ package org.nanoboot.utils.timecalc.utils.property; import lombok.Getter; import lombok.Setter; import org.nanoboot.utils.timecalc.app.TimeCalcException; -import org.nanoboot.utils.timecalc.utils.property.ReadOnlyProperty; -import org.nanoboot.utils.timecalc.utils.property.WriteOnlyProperty; /** * @author Robert * @since 23.02.2024 */ public class Property { + @Getter + private final String name; private T value; private Property boundToProperty = null; - public Property(T valueIn) { - this.value = valueIn; + public Property(String name, T valueIn) { + this.name = name; this.value = valueIn; } public ReadOnlyProperty asReadOnlyProperty() { return new ReadOnlyProperty<>(this); @@ -41,7 +41,7 @@ public class Property { public void setValue(T value) { if(isBound()) { - throw new TimeCalcException("Cannot set value, because property is bound."); + this.boundToProperty.setValue(value); } else { this.value = value; } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/ReadOnlyProperty.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/ReadOnlyProperty.java index 36a6013..c6aa81c 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/ReadOnlyProperty.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/ReadOnlyProperty.java @@ -8,19 +8,19 @@ import org.nanoboot.utils.timecalc.app.TimeCalcException; */ public class ReadOnlyProperty extends Property { private Property innerProperty; - public ReadOnlyProperty(T valueIn) { - super(valueIn); + public ReadOnlyProperty(String name, T valueIn) { + super(name, valueIn); throw new TimeCalcException("This constructor is forbidden in class " + getClass().getName() + "."); } public ReadOnlyProperty(Property property) { - super(null); + super(property.getName(), null); this.innerProperty = property; } public final void setValue(T valueIn) { throw new TimeCalcException("This is a read only property. New value cannot be set."); } - public final T getValue(T valueIn) { + public final T getValue() { return innerProperty.getValue(); } public final void unBound() { diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/StringProperty.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/StringProperty.java index 2ce6618..44ac56e 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/StringProperty.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/StringProperty.java @@ -6,11 +6,11 @@ package org.nanoboot.utils.timecalc.utils.property; */ public class StringProperty extends Property { - public StringProperty(String valueIn) { - super(valueIn); + public StringProperty(String name, String valueIn) { + super(name, valueIn); } public StringProperty() { - this(""); + this("", ""); } } diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/StringReadOnlyProperty.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/StringReadOnlyProperty.java index 2f13b77..fea750e 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/StringReadOnlyProperty.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/StringReadOnlyProperty.java @@ -6,8 +6,8 @@ package org.nanoboot.utils.timecalc.utils.property; */ public class StringReadOnlyProperty extends ReadOnlyProperty { - public StringReadOnlyProperty(String valueIn) { - super(valueIn); + public StringReadOnlyProperty(String name, String valueIn) { + super(name, valueIn); } public StringReadOnlyProperty(Property property) { super(property); diff --git a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/WriteOnlyProperty.java b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/WriteOnlyProperty.java index a9f7a30..50e45d5 100644 --- a/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/WriteOnlyProperty.java +++ b/modules/time-calc-app/src/main/java/org/nanoboot/utils/timecalc/utils/property/WriteOnlyProperty.java @@ -8,12 +8,12 @@ import org.nanoboot.utils.timecalc.app.TimeCalcException; */ public class WriteOnlyProperty extends Property { private Property innerProperty; - public WriteOnlyProperty(T valueIn) { - super(valueIn); + public WriteOnlyProperty(String name, T valueIn) { + super(name, valueIn); throw new TimeCalcException("This constructor is forbidden in class " + getClass().getName() + "."); } public WriteOnlyProperty(Property property) { - super(null); + super(property.getName(), null); this.innerProperty = property; } public final void setValue(T valueIn) {