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