mirror of
https://github.com/robertvokac/time-calc.git
synced 2025-03-25 07:27:49 +01:00
Added new improvements
This commit is contained in:
parent
91cc332912
commit
1ad3ad3e6a
@ -0,0 +1,123 @@
|
|||||||
|
package org.nanoboot.utils.timecalc.app;
|
||||||
|
|
||||||
|
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||||
|
import org.nanoboot.utils.timecalc.swing.common.TimeCalcButton;
|
||||||
|
import org.nanoboot.utils.timecalc.swing.common.TimeCalcWindow;
|
||||||
|
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||||
|
|
||||||
|
import java.awt.event.KeyAdapter;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert
|
||||||
|
* @since 26.02.2024
|
||||||
|
*/
|
||||||
|
public class TimeCalcKeyAdapter extends KeyAdapter {
|
||||||
|
private final TimeCalcConfiguration timeCalcConfiguration;
|
||||||
|
private final TimeCalcApp timeCalcApp;
|
||||||
|
private final TimeCalcButton commandButton;
|
||||||
|
private final TimeCalcWindow window;
|
||||||
|
|
||||||
|
public TimeCalcKeyAdapter(
|
||||||
|
TimeCalcConfiguration timeCalcConfiguration,
|
||||||
|
TimeCalcApp timeCalcApp,
|
||||||
|
TimeCalcButton commandButton,
|
||||||
|
TimeCalcWindow window
|
||||||
|
) {
|
||||||
|
this.timeCalcConfiguration = timeCalcConfiguration;
|
||||||
|
this.timeCalcApp = timeCalcApp;
|
||||||
|
this.commandButton = commandButton;
|
||||||
|
this.window = window;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyPressed(KeyEvent e) {
|
||||||
|
boolean onlyGreyOrNone =
|
||||||
|
timeCalcConfiguration.visibilityOnlyGreyOrNoneEnabledProperty
|
||||||
|
.isEnabled();
|
||||||
|
Visibility visibility = Visibility
|
||||||
|
.valueOf(timeCalcApp.visibilityProperty.getValue());
|
||||||
|
if (e.getKeyCode() == KeyEvent.VK_UP) {
|
||||||
|
timeCalcApp.visibilityProperty
|
||||||
|
.setValue(onlyGreyOrNone ? Visibility.GRAY.name() :
|
||||||
|
Visibility.STRONGLY_COLORED.name());
|
||||||
|
}
|
||||||
|
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
|
||||||
|
timeCalcApp.visibilityProperty
|
||||||
|
.setValue(Visibility.NONE.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.getKeyCode() == KeyEvent.VK_H) {
|
||||||
|
if (visibility.isNone()) {
|
||||||
|
timeCalcApp.visibilityProperty
|
||||||
|
.setValue(onlyGreyOrNone ? Visibility.GRAY.name() :
|
||||||
|
Visibility.STRONGLY_COLORED.name());
|
||||||
|
} else {
|
||||||
|
timeCalcApp.visibilityProperty
|
||||||
|
.setValue(Visibility.NONE.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (e.getKeyCode() == KeyEvent.VK_G) {
|
||||||
|
if (visibility.isGray() && !onlyGreyOrNone) {
|
||||||
|
timeCalcApp.visibilityProperty
|
||||||
|
.setValue(Visibility.WEAKLY_COLORED.name());
|
||||||
|
} else {
|
||||||
|
timeCalcApp.visibilityProperty
|
||||||
|
.setValue(Visibility.GRAY.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (e.getKeyCode() == KeyEvent.VK_C) {
|
||||||
|
if (!onlyGreyOrNone) {
|
||||||
|
if (visibility.isStronglyColored()) {
|
||||||
|
timeCalcApp.visibilityProperty
|
||||||
|
.setValue(Visibility.WEAKLY_COLORED.name());
|
||||||
|
} else {
|
||||||
|
timeCalcApp.visibilityProperty
|
||||||
|
.setValue(
|
||||||
|
Visibility.STRONGLY_COLORED.name());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
timeCalcApp.visibilityProperty.setValue(Visibility.GRAY
|
||||||
|
.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (e.getKeyCode() == KeyEvent.VK_V) {
|
||||||
|
if (visibility.isNone()) {
|
||||||
|
timeCalcApp.visibilityProperty
|
||||||
|
.setValue(onlyGreyOrNone ? Visibility.GRAY.name() :
|
||||||
|
Visibility.STRONGLY_COLORED.name());
|
||||||
|
} else {
|
||||||
|
timeCalcApp.visibilityProperty
|
||||||
|
.setValue(Visibility.NONE.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
|
||||||
|
if (visibility.isStronglyColored()) {
|
||||||
|
timeCalcApp.visibilityProperty
|
||||||
|
.setValue(onlyGreyOrNone ? Visibility.GRAY.name() :
|
||||||
|
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(onlyGreyOrNone ? Visibility.GRAY.name() :
|
||||||
|
Visibility.STRONGLY_COLORED.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (e.getKeyCode() == KeyEvent.VK_R) {
|
||||||
|
commandButton.doClick();
|
||||||
|
}
|
||||||
|
if (e.getKeyCode() == KeyEvent.VK_T) {
|
||||||
|
Utils.toastsAreEnabled.flip();
|
||||||
|
}
|
||||||
|
|
||||||
|
window.repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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.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.SwingUtils;
|
||||||
import org.nanoboot.utils.timecalc.swing.common.TimeCalcButton;
|
import org.nanoboot.utils.timecalc.swing.common.TimeCalcButton;
|
||||||
import org.nanoboot.utils.timecalc.swing.common.TimeCalcWindow;
|
import org.nanoboot.utils.timecalc.swing.common.TimeCalcWindow;
|
||||||
import org.nanoboot.utils.timecalc.swing.common.Toaster;
|
import org.nanoboot.utils.timecalc.swing.common.Toaster;
|
||||||
@ -23,12 +24,11 @@ import org.nanoboot.utils.timecalc.utils.common.Jokes;
|
|||||||
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 javax.swing.JComponent;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.Rectangle;
|
|
||||||
import java.awt.event.KeyAdapter;
|
|
||||||
import java.awt.event.KeyEvent;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@ -47,17 +47,10 @@ import java.util.logging.Logger;
|
|||||||
* @since 08.02.2024
|
* @since 08.02.2024
|
||||||
*/
|
*/
|
||||||
public class TimeCalcManager {
|
public class TimeCalcManager {
|
||||||
public static final Color BG = new Color(238, 238, 238);
|
public static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
|
||||||
public static final Color FG = new Color(210, 210, 210);
|
public static final Color FOREGROUND_COLOR = new Color(210, 210, 210);
|
||||||
public static final int MARGIN = 10;
|
|
||||||
private final String windowTitle;
|
|
||||||
private final int totalMinutes;
|
|
||||||
|
|
||||||
private final TimeHM startTime;
|
|
||||||
private final TimeHM overtime;
|
|
||||||
private final TimeHM endTime;
|
|
||||||
private boolean stopBeforeEnd = false;
|
private boolean stopBeforeEnd = false;
|
||||||
private final Time time = new Time();
|
|
||||||
private final TimeCalcConfiguration timeCalcConfiguration =
|
private final TimeCalcConfiguration timeCalcConfiguration =
|
||||||
new TimeCalcConfiguration();
|
new TimeCalcConfiguration();
|
||||||
|
|
||||||
@ -65,24 +58,20 @@ public class TimeCalcManager {
|
|||||||
TimeCalcApp timeCalcApp) {
|
TimeCalcApp timeCalcApp) {
|
||||||
timeCalcConfiguration
|
timeCalcConfiguration
|
||||||
.setFromTimeCalcProperties(TimeCalcProperties.getInstance());
|
.setFromTimeCalcProperties(TimeCalcProperties.getInstance());
|
||||||
// Utils.everythingHidden
|
|
||||||
// .setValue(TimeCalcConf.getInstance().isEverythingHidden());
|
|
||||||
// Utils.toastsAreEnabled
|
|
||||||
// .setValue(TimeCalcConf.getInstance().areToastsEnabled());
|
|
||||||
|
|
||||||
overTimeIn = (overTimeIn == null || overTimeIn.isEmpty()) ?
|
overTimeIn = (overTimeIn == null || overTimeIn.isEmpty()) ?
|
||||||
Constants.DEFAULT_OVERTIME : overTimeIn;
|
Constants.DEFAULT_OVERTIME : overTimeIn;
|
||||||
|
|
||||||
this.startTime = new TimeHM(startTimeIn);
|
TimeHM startTime = new TimeHM(startTimeIn);
|
||||||
this.overtime = new TimeHM(overTimeIn);
|
TimeHM overtime = new TimeHM(overTimeIn);
|
||||||
|
|
||||||
this.endTime = new TimeHM(
|
TimeHM endTime = new TimeHM(
|
||||||
startTime.getHour() + Constants.WORKING_HOURS_LENGTH + overtime
|
startTime.getHour() + Constants.WORKING_HOURS_LENGTH + overtime
|
||||||
.getHour(),
|
.getHour(),
|
||||||
startTime.getMinute() + Constants.WORKING_MINUTES_LENGTH
|
startTime.getMinute() + Constants.WORKING_MINUTES_LENGTH
|
||||||
+ overtime.getMinute());
|
+ overtime.getMinute());
|
||||||
|
|
||||||
this.totalMinutes = TimeHM.countDiffInMinutes(startTime, endTime);
|
int totalMinutes = TimeHM.countDiffInMinutes(startTime, endTime);
|
||||||
int totalSeconds = totalMinutes * TimeHM.SECONDS_PER_MINUTE;
|
int totalSeconds = totalMinutes * TimeHM.SECONDS_PER_MINUTE;
|
||||||
int totalMilliseconds = totalSeconds * TimeHM.MILLISECONDS_PER_SECOND;
|
int totalMilliseconds = totalSeconds * TimeHM.MILLISECONDS_PER_SECOND;
|
||||||
|
|
||||||
@ -99,105 +88,36 @@ public class TimeCalcManager {
|
|||||||
//window.add(weatherButton);
|
//window.add(weatherButton);
|
||||||
window.addAll(configButton, commandButton, jokeButton, restartButton,
|
window.addAll(configButton, commandButton, jokeButton, restartButton,
|
||||||
exitButton);
|
exitButton);
|
||||||
boolean onlyGreyOrNone = timeCalcConfiguration.visibilityOnlyGreyOrNoneEnabledProperty.isEnabled();
|
|
||||||
if(onlyGreyOrNone) {
|
if(timeCalcConfiguration.visibilityOnlyGreyOrNoneEnabledProperty.isEnabled()) {
|
||||||
timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name());
|
timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name());
|
||||||
}
|
}
|
||||||
window.addKeyListener(new KeyAdapter() {
|
TimeCalcKeyAdapter timeCalcKeyAdapter = new TimeCalcKeyAdapter(timeCalcConfiguration, timeCalcApp, commandButton, window);
|
||||||
// Key Pressed method
|
window.addKeyListener(timeCalcKeyAdapter);
|
||||||
public void keyPressed(KeyEvent e) {
|
|
||||||
Visibility visibility = Visibility
|
|
||||||
.valueOf(timeCalcApp.visibilityProperty.getValue());
|
|
||||||
if (e.getKeyCode() == KeyEvent.VK_UP) {
|
|
||||||
timeCalcApp.visibilityProperty
|
|
||||||
.setValue(onlyGreyOrNone ? Visibility.GRAY.name() : Visibility.STRONGLY_COLORED.name());
|
|
||||||
}
|
|
||||||
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
|
|
||||||
timeCalcApp.visibilityProperty
|
|
||||||
.setValue(Visibility.NONE.name());
|
|
||||||
}
|
|
||||||
if (e.getKeyCode() == KeyEvent.VK_H) {
|
|
||||||
if (visibility.isNone()) {
|
|
||||||
timeCalcApp.visibilityProperty
|
|
||||||
.setValue(onlyGreyOrNone ? Visibility.GRAY.name() : Visibility.STRONGLY_COLORED.name());
|
|
||||||
} else {
|
|
||||||
timeCalcApp.visibilityProperty
|
|
||||||
.setValue(Visibility.NONE.name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (e.getKeyCode() == KeyEvent.VK_G) {
|
|
||||||
if (visibility.isGray() && !onlyGreyOrNone) {
|
|
||||||
timeCalcApp.visibilityProperty
|
|
||||||
.setValue(Visibility.WEAKLY_COLORED.name());
|
|
||||||
} else {
|
|
||||||
timeCalcApp.visibilityProperty
|
|
||||||
.setValue(Visibility.GRAY.name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.getKeyCode() == KeyEvent.VK_C) {
|
AnalogClock analogClock = new AnalogClock(startTime, endTime);
|
||||||
if(!onlyGreyOrNone) {
|
analogClock.setBounds(SwingUtils.MARGIN, SwingUtils.MARGIN, 200);
|
||||||
if (visibility.isStronglyColored()) {
|
window.add(analogClock);
|
||||||
timeCalcApp.visibilityProperty
|
|
||||||
.setValue(Visibility.WEAKLY_COLORED.name());
|
ProgressSquare progressSquare = new ProgressSquare();
|
||||||
} else {
|
progressSquare
|
||||||
timeCalcApp.visibilityProperty
|
.setBounds(analogClock.getX() + analogClock.getWidth() + SwingUtils.MARGIN, analogClock.getY(),
|
||||||
.setValue(
|
200);
|
||||||
Visibility.STRONGLY_COLORED.name());
|
window.add(progressSquare);
|
||||||
}
|
|
||||||
}
|
ProgressCircle progressCircle = new ProgressCircle();
|
||||||
else {
|
progressCircle
|
||||||
timeCalcApp.visibilityProperty.setValue(Visibility.GRAY
|
.setBounds(
|
||||||
.name());
|
progressSquare.getX() + progressSquare.getWidth() + SwingUtils.MARGIN, progressSquare.getY(), 80);
|
||||||
}
|
window.add(progressCircle);
|
||||||
}
|
|
||||||
if (e.getKeyCode() == KeyEvent.VK_V) {
|
|
||||||
if (visibility.isNone()) {
|
|
||||||
timeCalcApp.visibilityProperty
|
|
||||||
.setValue(onlyGreyOrNone ? Visibility.GRAY.name() : Visibility.STRONGLY_COLORED.name());
|
|
||||||
} else {
|
|
||||||
timeCalcApp.visibilityProperty
|
|
||||||
.setValue(Visibility.NONE.name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
|
|
||||||
if (visibility.isStronglyColored()) {
|
|
||||||
timeCalcApp.visibilityProperty
|
|
||||||
.setValue(onlyGreyOrNone ? Visibility.GRAY.name() : 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(onlyGreyOrNone ? Visibility.GRAY.name() : Visibility.STRONGLY_COLORED.name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (e.getKeyCode() == KeyEvent.VK_R) {
|
|
||||||
commandButton.doClick();
|
|
||||||
}
|
|
||||||
if (e.getKeyCode() == KeyEvent.VK_T) {
|
|
||||||
Utils.toastsAreEnabled.flip();
|
|
||||||
}
|
|
||||||
|
|
||||||
window.repaint();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
WalkingHumanProgressAsciiArt walkingHumanProgressAsciiArt =
|
WalkingHumanProgressAsciiArt walkingHumanProgressAsciiArt =
|
||||||
new WalkingHumanProgressAsciiArt();
|
new WalkingHumanProgressAsciiArt(analogClock.getX(), analogClock.getY() + analogClock.getHeight() + SwingUtils.MARGIN, 420, 180);
|
||||||
walkingHumanProgressAsciiArt
|
|
||||||
.setBounds(MARGIN, MARGIN + 210 + MARGIN, 450, 180);
|
|
||||||
|
|
||||||
window.add(walkingHumanProgressAsciiArt);
|
window.add(walkingHumanProgressAsciiArt);
|
||||||
weatherButton
|
weatherButton
|
||||||
.setBounds(MARGIN, walkingHumanProgressAsciiArt.getY()
|
.setBounds(SwingUtils.MARGIN, walkingHumanProgressAsciiArt.getY()
|
||||||
+ walkingHumanProgressAsciiArt.getHeight()
|
+ walkingHumanProgressAsciiArt.getHeight()
|
||||||
+ MARGIN);
|
+ SwingUtils.MARGIN);
|
||||||
configButton.setBoundsFromTop(walkingHumanProgressAsciiArt);
|
configButton.setBoundsFromTop(walkingHumanProgressAsciiArt);
|
||||||
commandButton.setBoundsFromLeft(configButton);
|
commandButton.setBoundsFromLeft(configButton);
|
||||||
|
|
||||||
@ -205,13 +125,12 @@ public class TimeCalcManager {
|
|||||||
restartButton.setBoundsFromLeft(jokeButton);
|
restartButton.setBoundsFromLeft(jokeButton);
|
||||||
exitButton.setBoundsFromLeft(restartButton);
|
exitButton.setBoundsFromLeft(restartButton);
|
||||||
aboutButton.setBounds(exitButton.getX(),
|
aboutButton.setBounds(exitButton.getX(),
|
||||||
exitButton.getY() + exitButton.getHeight() + MARGIN);
|
exitButton.getY() + exitButton.getHeight() + SwingUtils.MARGIN);
|
||||||
|
|
||||||
window.setLayout(null);
|
window.setLayout(null);
|
||||||
|
|
||||||
window.setVisible(true);
|
window.setVisible(true);
|
||||||
|
|
||||||
this.windowTitle = createWindowTitle();
|
String windowTitle = createWindowTitle();
|
||||||
window.setTitle(windowTitle);
|
window.setTitle(windowTitle);
|
||||||
|
|
||||||
weatherButton
|
weatherButton
|
||||||
@ -290,9 +209,6 @@ public class TimeCalcManager {
|
|||||||
Calendar calNow = Calendar.getInstance();
|
Calendar calNow = Calendar.getInstance();
|
||||||
calNow.setTime(new Date());
|
calNow.setTime(new Date());
|
||||||
|
|
||||||
AnalogClock analogClock = new AnalogClock(startTime, endTime);
|
|
||||||
analogClock.setBounds(MARGIN, MARGIN, 200);
|
|
||||||
|
|
||||||
Properties testProperties = new Properties();
|
Properties testProperties = new Properties();
|
||||||
File testPropertiesFile = new File("test.txt");
|
File testPropertiesFile = new File("test.txt");
|
||||||
try {
|
try {
|
||||||
@ -307,6 +223,7 @@ public class TimeCalcManager {
|
|||||||
.log(Level.SEVERE, null, rex);
|
.log(Level.SEVERE, null, rex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Time time = new Time();
|
||||||
if (testProperties.containsKey("current.day")) {
|
if (testProperties.containsKey("current.day")) {
|
||||||
calNow.set(Calendar.DAY_OF_MONTH, Integer.parseInt(
|
calNow.set(Calendar.DAY_OF_MONTH, Integer.parseInt(
|
||||||
(String) testProperties.get("current.day")));
|
(String) testProperties.get("current.day")));
|
||||||
@ -381,31 +298,19 @@ public class TimeCalcManager {
|
|||||||
analogClock.handsLongProperty
|
analogClock.handsLongProperty
|
||||||
.bindTo(timeCalcConfiguration.clockHandLongProperty);
|
.bindTo(timeCalcConfiguration.clockHandLongProperty);
|
||||||
|
|
||||||
window.add(analogClock);
|
Battery hourBattery = new HourBattery(progressCircle.getBounds().x,
|
||||||
|
progressCircle.getY() + SwingUtils.MARGIN + progressCircle.getHeight(),
|
||||||
|
140);
|
||||||
|
window.add(hourBattery);
|
||||||
|
|
||||||
ProgressSquare progressSquare = new ProgressSquare();
|
Battery dayBattery = new DayBattery(hourBattery.getBounds().x + hourBattery.getWidth() + SwingUtils.MARGIN,
|
||||||
progressSquare
|
hourBattery.getY(),
|
||||||
.setBounds(MARGIN + analogClock.getWidth() + MARGIN, MARGIN,
|
|
||||||
200);
|
|
||||||
|
|
||||||
window.add(progressSquare);
|
|
||||||
|
|
||||||
ProgressCircle progressCircle = new ProgressCircle();
|
|
||||||
progressCircle
|
|
||||||
.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);
|
140);
|
||||||
window.add(dayBattery);
|
window.add(dayBattery);
|
||||||
|
|
||||||
Battery weekBattery = new WeekBattery(
|
Battery weekBattery = new WeekBattery(
|
||||||
dayBattery.getBounds().x + dayBattery.getWidth() + MARGIN * 2,
|
hourBattery.getBounds().x,
|
||||||
dayBattery.getY(), 140);
|
dayBattery.getY() + dayBattery.getHeight() + SwingUtils.MARGIN, 140);
|
||||||
window.add(weekBattery);
|
window.add(weekBattery);
|
||||||
|
|
||||||
int currentDayOfMonth = calNow.get(Calendar.DAY_OF_MONTH);
|
int currentDayOfMonth = calNow.get(Calendar.DAY_OF_MONTH);
|
||||||
@ -436,31 +341,10 @@ public class TimeCalcManager {
|
|||||||
workDaysTotal = workDaysDone + (nowIsWeekend ? 0 : 1) + workDaysTodo;
|
workDaysTotal = workDaysDone + (nowIsWeekend ? 0 : 1) + workDaysTodo;
|
||||||
|
|
||||||
Battery monthBattery = new MonthBattery(
|
Battery monthBattery = new MonthBattery(
|
||||||
dayBattery.getBounds().x + dayBattery.getWidth(),
|
dayBattery.getBounds().x,
|
||||||
dayBattery.getY() + weekBattery.getHeight() + MARGIN, 140);
|
weekBattery.getY(), 140);
|
||||||
window.add(monthBattery);
|
window.add(monthBattery);
|
||||||
|
|
||||||
Battery hourBattery = new HourBattery(monthBattery.getBounds().x,
|
|
||||||
monthBattery.getY() + monthBattery.getHeight() + MARGIN, 140);
|
|
||||||
window.add(hourBattery);
|
|
||||||
|
|
||||||
Rectangle dayRectangle = dayBattery.getBounds();
|
|
||||||
hourBattery.setBounds(dayRectangle);
|
|
||||||
hourBattery
|
|
||||||
.setBounds(hourBattery.getX() + 2 * MARGIN, hourBattery.getY(),
|
|
||||||
hourBattery.getWidth(), hourBattery.getHeight());
|
|
||||||
dayBattery
|
|
||||||
.setBounds(hourBattery.getX() + hourBattery.getWidth() + MARGIN,
|
|
||||||
hourBattery.getY(), hourBattery.getWidth(),
|
|
||||||
hourBattery.getHeight());
|
|
||||||
weekBattery.setBounds(hourBattery.getX(),
|
|
||||||
hourBattery.getY() + hourBattery.getHeight() + MARGIN,
|
|
||||||
hourBattery.getWidth(), hourBattery.getHeight());
|
|
||||||
monthBattery
|
|
||||||
.setBounds(hourBattery.getX() + hourBattery.getWidth() + MARGIN,
|
|
||||||
hourBattery.getY() + hourBattery.getHeight() + MARGIN,
|
|
||||||
hourBattery.getWidth(), hourBattery.getHeight());
|
|
||||||
|
|
||||||
hourBattery.wavesProperty
|
hourBattery.wavesProperty
|
||||||
.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
|
.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
|
||||||
dayBattery.wavesProperty
|
dayBattery.wavesProperty
|
||||||
@ -470,7 +354,7 @@ public class TimeCalcManager {
|
|||||||
monthBattery.wavesProperty
|
monthBattery.wavesProperty
|
||||||
.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
|
.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty);
|
||||||
|
|
||||||
ComponentRegistry componentRegistry = new ComponentRegistry();
|
ComponentRegistry<JComponent> componentRegistry = new ComponentRegistry();
|
||||||
componentRegistry.addAll(
|
componentRegistry.addAll(
|
||||||
walkingHumanProgressAsciiArt,
|
walkingHumanProgressAsciiArt,
|
||||||
progressSquare,
|
progressSquare,
|
||||||
@ -486,6 +370,12 @@ public class TimeCalcManager {
|
|||||||
restartButton,
|
restartButton,
|
||||||
exitButton
|
exitButton
|
||||||
);
|
);
|
||||||
|
ComponentRegistry<TimeCalcButton> buttonRegistry = new ComponentRegistry();
|
||||||
|
for(Component c:componentRegistry.getSet()) {
|
||||||
|
if(c instanceof TimeCalcButton) {
|
||||||
|
buttonRegistry.add((TimeCalcButton)c);
|
||||||
|
}
|
||||||
|
}
|
||||||
walkingHumanProgressAsciiArt.visibilityProperty
|
walkingHumanProgressAsciiArt.visibilityProperty
|
||||||
.bindTo(timeCalcApp.visibilityProperty);
|
.bindTo(timeCalcApp.visibilityProperty);
|
||||||
progressSquare.visibilityProperty
|
progressSquare.visibilityProperty
|
||||||
@ -503,30 +393,8 @@ public class TimeCalcManager {
|
|||||||
restartButton.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
restartButton.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||||
exitButton.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
exitButton.visibilityProperty.bindTo(timeCalcApp.visibilityProperty);
|
||||||
|
|
||||||
configButton.setVisible(
|
window.setSize(dayBattery.getX() + dayBattery.getWidth() + 3 * SwingUtils.MARGIN,
|
||||||
!Visibility.valueOf(configButton.visibilityProperty.getValue())
|
exitButton.getY() + 3 * exitButton.getHeight() + SwingUtils.MARGIN);
|
||||||
.isNone());
|
|
||||||
jokeButton.setVisible(
|
|
||||||
!Visibility.valueOf(jokeButton.visibilityProperty.getValue())
|
|
||||||
.isNone());
|
|
||||||
commandButton.setVisible(
|
|
||||||
!Visibility.valueOf(commandButton.visibilityProperty.getValue())
|
|
||||||
.isNone());
|
|
||||||
restartButton.setVisible(
|
|
||||||
!Visibility.valueOf(restartButton.visibilityProperty.getValue())
|
|
||||||
.isNone());
|
|
||||||
exitButton.setVisible(
|
|
||||||
!Visibility.valueOf(exitButton.visibilityProperty.getValue())
|
|
||||||
.isNone());
|
|
||||||
|
|
||||||
// timeCalcApp.visibilityProperty.addListener((Property<String> p, String oldValue, String newValue)-> {
|
|
||||||
// System.out.println("Visibility of timeCalcApp was changed FROM " + oldValue + " TO " + newValue);
|
|
||||||
// } );
|
|
||||||
// analogClock.visibilityProperty.addListener((Property<String> p, String oldValue, String newValue)-> {
|
|
||||||
// System.out.println("Visibility of analogClock was changed FROM " + oldValue + " TO " + newValue);
|
|
||||||
// } );
|
|
||||||
window.setSize(520 + 20 + 100,
|
|
||||||
exitButton.getY() + 3 * exitButton.getHeight() + MARGIN);
|
|
||||||
while (true) {
|
while (true) {
|
||||||
Visibility visibility = Visibility
|
Visibility visibility = Visibility
|
||||||
.valueOf(timeCalcApp.visibilityProperty.getValue());
|
.valueOf(timeCalcApp.visibilityProperty.getValue());
|
||||||
@ -543,17 +411,17 @@ public class TimeCalcManager {
|
|||||||
|
|
||||||
componentRegistry.setVisible(visibility.isNotNone());
|
componentRegistry.setVisible(visibility.isNotNone());
|
||||||
if (!visibility.isStronglyColored() || visibility.isGray()) {
|
if (!visibility.isStronglyColored() || visibility.isGray()) {
|
||||||
configButton.setBackground(BG);
|
configButton.setBackground(BACKGROUND_COLOR);
|
||||||
jokeButton.setBackground(BG);
|
jokeButton.setBackground(BACKGROUND_COLOR);
|
||||||
commandButton.setBackground(BG);
|
commandButton.setBackground(BACKGROUND_COLOR);
|
||||||
restartButton.setBackground(BG);
|
restartButton.setBackground(BACKGROUND_COLOR);
|
||||||
exitButton.setBackground(BG);
|
exitButton.setBackground(BACKGROUND_COLOR);
|
||||||
|
|
||||||
configButton.setForeground(FG);
|
configButton.setForeground(FOREGROUND_COLOR);
|
||||||
jokeButton.setForeground(FG);
|
jokeButton.setForeground(FOREGROUND_COLOR);
|
||||||
commandButton.setForeground(FG);
|
commandButton.setForeground(FOREGROUND_COLOR);
|
||||||
restartButton.setForeground(FG);
|
restartButton.setForeground(FOREGROUND_COLOR);
|
||||||
exitButton.setForeground(FG);
|
exitButton.setForeground(FOREGROUND_COLOR);
|
||||||
} else {
|
} else {
|
||||||
configButton.setOriginalBackground();
|
configButton.setOriginalBackground();
|
||||||
jokeButton.setOriginalBackground();
|
jokeButton.setOriginalBackground();
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.nanoboot.utils.timecalc.swing.common;
|
package org.nanoboot.utils.timecalc.swing.common;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -9,25 +11,26 @@ import java.util.Set;
|
|||||||
* @author Robert Vokac
|
* @author Robert Vokac
|
||||||
* @since 21.02.2024
|
* @since 21.02.2024
|
||||||
*/
|
*/
|
||||||
public class ComponentRegistry {
|
public class ComponentRegistry<T extends Component> {
|
||||||
private final Set<Component> set = new HashSet<>();
|
@Getter
|
||||||
|
private final Set<T> set = new HashSet<>();
|
||||||
|
|
||||||
public ComponentRegistry() {
|
public ComponentRegistry() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(JComponent component) {
|
public void add(T component) {
|
||||||
this.set.add(component);
|
this.set.add(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAll(JComponent... component) {
|
public void addAll(T... component) {
|
||||||
for (JComponent c : component) {
|
for (T c : component) {
|
||||||
add(c);
|
add(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVisible(boolean b) {
|
public void setVisible(boolean b) {
|
||||||
for (Component c : set) {
|
for (T c : set) {
|
||||||
c.setVisible(b);
|
c.setVisible(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package org.nanoboot.utils.timecalc.swing.common;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert
|
||||||
|
* @since 26.02.2024
|
||||||
|
*/
|
||||||
|
public class SwingUtils {
|
||||||
|
private SwingUtils() {
|
||||||
|
//Not meant to be instantiated.
|
||||||
|
}
|
||||||
|
public static final int MARGIN = 10;
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package org.nanoboot.utils.timecalc.swing.common;
|
package org.nanoboot.utils.timecalc.swing.common;
|
||||||
|
|
||||||
import org.nanoboot.utils.timecalc.app.TimeCalcManager;
|
|
||||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||||
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
|
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
|
||||||
|
|
||||||
@ -24,7 +23,7 @@ public class TimeCalcButton extends JButton {
|
|||||||
|
|
||||||
public TimeCalcButton(String label) {
|
public TimeCalcButton(String label) {
|
||||||
super(label);
|
super(label);
|
||||||
new Timer(100, e -> repaint()).start();
|
new Timer(100, e -> setVisible(Visibility.valueOf(visibilityProperty.getValue()).isNotNone())).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBounds(int x, int y) {
|
public void setBounds(int x, int y) {
|
||||||
@ -42,11 +41,11 @@ public class TimeCalcButton extends JButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setBoundsFromLeft(JComponent jComponent) {
|
public void setBoundsFromLeft(JComponent jComponent) {
|
||||||
setBounds(jComponent.getX() + jComponent.getWidth() + TimeCalcManager.MARGIN, jComponent.getY());
|
setBounds(jComponent.getX() + jComponent.getWidth() + SwingUtils.MARGIN, jComponent.getY());
|
||||||
}
|
}
|
||||||
public void setBoundsFromTop(JComponent jComponent) {
|
public void setBoundsFromTop(JComponent jComponent) {
|
||||||
setBounds(TimeCalcManager.MARGIN, jComponent.getY()
|
setBounds(SwingUtils.MARGIN, jComponent.getY()
|
||||||
+ jComponent.getHeight()
|
+ jComponent.getHeight()
|
||||||
+ TimeCalcManager.MARGIN);
|
+ SwingUtils.MARGIN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.nanoboot.utils.timecalc.swing.progress;
|
package org.nanoboot.utils.timecalc.swing.progress;
|
||||||
|
|
||||||
|
import org.nanoboot.utils.timecalc.app.TimeCalcManager;
|
||||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||||
import org.nanoboot.utils.timecalc.swing.common.Toaster;
|
import org.nanoboot.utils.timecalc.swing.common.Toaster;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.Constants;
|
import org.nanoboot.utils.timecalc.utils.common.Constants;
|
||||||
@ -31,12 +32,12 @@ public class WalkingHumanProgressAsciiArt extends JTextPane {
|
|||||||
new StringProperty("visibilityProperty",
|
new StringProperty("visibilityProperty",
|
||||||
Visibility.STRONGLY_COLORED.name());
|
Visibility.STRONGLY_COLORED.name());
|
||||||
|
|
||||||
public WalkingHumanProgressAsciiArt() {
|
public WalkingHumanProgressAsciiArt(int x, int y, int width, int height) {
|
||||||
setFont(new Font(Font.MONOSPACED, Font.PLAIN, 11));
|
setFont(new Font(Font.MONOSPACED, Font.PLAIN, 11));
|
||||||
putClientProperty("mouseEntered", "false");
|
putClientProperty("mouseEntered", "false");
|
||||||
setFocusable(false);
|
setFocusable(false);
|
||||||
setForeground(Color.GRAY);
|
setForeground(Color.GRAY);
|
||||||
setBackground(new Color(238, 238, 238));
|
setBackground(TimeCalcManager.BACKGROUND_COLOR);
|
||||||
addMouseListener(new MouseListener() {
|
addMouseListener(new MouseListener() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
@ -71,6 +72,7 @@ public class WalkingHumanProgressAsciiArt extends JTextPane {
|
|||||||
putClientProperty("mouseEntered", "false");
|
putClientProperty("mouseEntered", "false");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
setBounds(x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String createSpaces(int spaceCount) {
|
private static final String createSpaces(int spaceCount) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user