Added new improvements

This commit is contained in:
Robert Vokac 2024-02-04 16:08:31 +00:00
parent 5f60f85bff
commit 37aa23baf6
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
25 changed files with 244 additions and 209 deletions

View File

@ -1,10 +1,5 @@
package org.nanoboot.utils.timecalc.main; package org.nanoboot.utils.timecalc.main;
import org.nanoboot.utils.timecalc.utils.Constants;
import org.nanoboot.utils.timecalc.utils.FileConstants;
import org.nanoboot.utils.timecalc.utils.Utils;
import javax.swing.JOptionPane;
import java.io.IOException; import java.io.IOException;
/** /**
@ -14,55 +9,8 @@ import java.io.IOException;
public class Main { public class Main {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
TimeCalcApp timeCalcApp = new TimeCalcApp();
Utils.startApp(); timeCalcApp.start(args);
while (true) {
boolean test = FileConstants.TEST_TXT.exists();
String oldStartTime = Utils.readTextFromFile(
FileConstants.STARTTIME_TXT);
String oldOvertime = Utils.readTextFromFile(
FileConstants.OVERTIME_TXT);
String newStartTime =
test ? (oldStartTime != null ? oldStartTime :
Constants.DEFAULT_START_TIME) :
(String) JOptionPane.showInputDialog(
null,
"Start Time:",
"Start Time",
JOptionPane.PLAIN_MESSAGE,
null,
null,
oldStartTime == null ?
Constants.DEFAULT_START_TIME :
oldStartTime
);
String newOvertime =
test ? (oldOvertime != null ? oldOvertime :
Constants.DEFAULT_OVERTIME) :
(String) JOptionPane.showInputDialog(
null,
"Overtime:",
"Overtime",
JOptionPane.PLAIN_MESSAGE,
null,
null,
oldOvertime == null ?
Constants.DEFAULT_OVERTIME :
oldOvertime
);
Utils.writeTextToFile(FileConstants.STARTTIME_TXT, newStartTime);
Utils.writeTextToFile(FileConstants.OVERTIME_TXT, newOvertime);
try {
TimeCalcManager timeCalc =
new TimeCalcManager(newStartTime, newOvertime);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error: " + e.getMessage(),
e.getMessage(), JOptionPane.ERROR_MESSAGE);
}
}
} }
} }

View File

@ -0,0 +1,86 @@
package org.nanoboot.utils.timecalc.main;
import org.nanoboot.utils.timecalc.utils.Constants;
import org.nanoboot.utils.timecalc.utils.FileConstants;
import org.nanoboot.utils.timecalc.utils.Utils;
import javax.swing.JOptionPane;
import java.io.IOException;
/**
* @author Robert
* @since 31.01.2024
*/
public class TimeCalcApp {
private long startNanoTime = 0l;
public void start(String[] args) throws IOException {
if(startNanoTime != 0l) {
throw new TimeCalcException("TimeCalcApp was already started.");
}
startNanoTime = System.nanoTime();
while (true) {
boolean test = FileConstants.TEST_TXT.exists();
String oldStartTime = Utils.readTextFromFile(
FileConstants.STARTTIME_TXT);
String oldOvertime = Utils.readTextFromFile(
FileConstants.OVERTIME_TXT);
String newStartTime =
test ? (oldStartTime != null ? oldStartTime :
Constants.DEFAULT_START_TIME) :
(String) JOptionPane.showInputDialog(
null,
"Start Time:",
"Start Time",
JOptionPane.PLAIN_MESSAGE,
null,
null,
oldStartTime == null ?
Constants.DEFAULT_START_TIME :
oldStartTime
);
String newOvertime =
test ? (oldOvertime != null ? oldOvertime :
Constants.DEFAULT_OVERTIME) :
(String) JOptionPane.showInputDialog(
null,
"Overtime:",
"Overtime",
JOptionPane.PLAIN_MESSAGE,
null,
null,
oldOvertime == null ?
Constants.DEFAULT_OVERTIME :
oldOvertime
);
Utils.writeTextToFile(FileConstants.STARTTIME_TXT, newStartTime);
Utils.writeTextToFile(FileConstants.OVERTIME_TXT, newOvertime);
try {
TimeCalcManager timeCalc =
new TimeCalcManager(newStartTime, newOvertime);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error: " + e.getMessage(),
e.getMessage(), JOptionPane.ERROR_MESSAGE);
}
}
}
public long getCountOfMinutesSinceAppStarted() {
return getCountOfSecondsSinceAppStarted() / 60l;
}
public long getCountOfSecondsSinceAppStarted() {
return getCountOfMillisecondsSinceAppStarted() / 1000000000l;
}
public long getCountOfMillisecondsSinceAppStarted() {
if(startNanoTime == 0l) {
throw new TimeCalcException("App was not yet started.");
}
return System.nanoTime() - startNanoTime;
}
}

View File

@ -64,5 +64,11 @@ public class TimeCalcConf {
} }
return properties.get(key).equals("true"); return properties.get(key).equals("true");
} }
public void load() {
//to be implemented
}
public void save() {
//to be implemented
}
} }

View File

@ -1,19 +1,20 @@
package org.nanoboot.utils.timecalc.main; package org.nanoboot.utils.timecalc.main;
import org.nanoboot.utils.timecalc.gui.common.ComponentRegistry; import org.nanoboot.utils.timecalc.swing.common.AboutButton;
import org.nanoboot.utils.timecalc.gui.common.TimeCalcButton; import org.nanoboot.utils.timecalc.swing.common.ComponentRegistry;
import org.nanoboot.utils.timecalc.gui.common.TimeCalcWindow; import org.nanoboot.utils.timecalc.swing.common.TimeCalcButton;
import org.nanoboot.utils.timecalc.gui.common.Toaster; import org.nanoboot.utils.timecalc.swing.common.TimeCalcWindow;
import org.nanoboot.utils.timecalc.gui.common.WeatherWindow; import org.nanoboot.utils.timecalc.swing.common.Toaster;
import org.nanoboot.utils.timecalc.gui.progress.AnalogClock; import org.nanoboot.utils.timecalc.swing.common.WeatherWindow;
import org.nanoboot.utils.timecalc.gui.progress.Battery; import org.nanoboot.utils.timecalc.swing.progress.AnalogClock;
import org.nanoboot.utils.timecalc.gui.progress.DayBattery; import org.nanoboot.utils.timecalc.swing.progress.Battery;
import org.nanoboot.utils.timecalc.gui.progress.HourBattery; import org.nanoboot.utils.timecalc.swing.progress.DayBattery;
import org.nanoboot.utils.timecalc.gui.progress.MonthBattery; import org.nanoboot.utils.timecalc.swing.progress.HourBattery;
import org.nanoboot.utils.timecalc.gui.progress.ProgressCircle; import org.nanoboot.utils.timecalc.swing.progress.MonthBattery;
import org.nanoboot.utils.timecalc.gui.progress.ProgressSquare; import org.nanoboot.utils.timecalc.swing.progress.ProgressCircle;
import org.nanoboot.utils.timecalc.gui.progress.WalkingHumanProgressAsciiArt; import org.nanoboot.utils.timecalc.swing.progress.ProgressSquare;
import org.nanoboot.utils.timecalc.gui.progress.WeekBattery; import org.nanoboot.utils.timecalc.swing.progress.WalkingHumanProgressAsciiArt;
import org.nanoboot.utils.timecalc.swing.progress.WeekBattery;
import org.nanoboot.utils.timecalc.utils.Constants; import org.nanoboot.utils.timecalc.utils.Constants;
import org.nanoboot.utils.timecalc.utils.DateFormats; import org.nanoboot.utils.timecalc.utils.DateFormats;
import org.nanoboot.utils.timecalc.utils.Jokes; import org.nanoboot.utils.timecalc.utils.Jokes;
@ -52,9 +53,9 @@ public class TimeCalcManager {
public TimeCalcManager(String startTimeIn, String overTimeIn) { public TimeCalcManager(String startTimeIn, String overTimeIn) {
Utils.everythingHidden Utils.everythingHidden
.set(TimeCalcConf.getInstance().isEverythingHidden()); .setValue(TimeCalcConf.getInstance().isEverythingHidden());
Utils.toastsAreEnabled Utils.toastsAreEnabled
.set(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;
@ -85,23 +86,23 @@ public class TimeCalcManager {
// Key Pressed method // Key Pressed method
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_UP) { if (e.getKeyCode() == KeyEvent.VK_UP) {
Utils.everythingHidden.set(false); Utils.everythingHidden.setValue(false);
} }
if (e.getKeyCode() == KeyEvent.VK_DOWN) { if (e.getKeyCode() == KeyEvent.VK_DOWN) {
Utils.everythingHidden.set(true); Utils.everythingHidden.setValue(true);
} }
if (e.getKeyCode() == KeyEvent.VK_H) { if (e.getKeyCode() == KeyEvent.VK_H) {
Utils.everythingHidden.flip(); Utils.everythingHidden.flip();
} }
if (e.getKeyCode() == KeyEvent.VK_G) { if (e.getKeyCode() == KeyEvent.VK_G) {
if(!Utils.ultraLight.get() && Utils.highlighted.isEnabled()) { if(!Utils.ultraLight.getValue() && Utils.highlighted.isEnabled()) {
Utils.highlighted.disable(); Utils.highlighted.disable();
} }
Utils.ultraLight.flip(); Utils.ultraLight.flip();
} }
if (e.getKeyCode() == KeyEvent.VK_C) { if (e.getKeyCode() == KeyEvent.VK_C) {
if(Utils.ultraLight.get() && !Utils.highlighted.isEnabled()) { if(Utils.ultraLight.getValue() && !Utils.highlighted.isEnabled()) {
Utils.ultraLight.disable(); Utils.ultraLight.disable();
} }
Utils.highlighted.flip(); Utils.highlighted.flip();
@ -177,11 +178,11 @@ public class TimeCalcManager {
break; break;
case "color": case "color":
Utils.highlighted Utils.highlighted
.set(commandsAsArray[1].equals("1")); .setValue(commandsAsArray[1].equals("1"));
break; break;
case "gray": case "gray":
Utils.ultraLight Utils.ultraLight
.set(commandsAsArray[1].equals("1")); .setValue(commandsAsArray[1].equals("1"));
break; break;
case "waves": case "waves":
Battery.wavesOff = commandsAsArray[1].equals("0"); Battery.wavesOff = commandsAsArray[1].equals("0");
@ -204,7 +205,7 @@ public class TimeCalcManager {
break; break;
case "toasts": case "toasts":
Utils.toastsAreEnabled Utils.toastsAreEnabled
.set(commandsAsArray[1].equals("1")); .setValue(commandsAsArray[1].equals("1"));
break; break;
default: default:
JOptionPane.showMessageDialog(null, JOptionPane.showMessageDialog(null,
@ -322,8 +323,8 @@ public class TimeCalcManager {
break; break;
} }
componentRegistry.setVisible(!Utils.everythingHidden.get()); componentRegistry.setVisible(!Utils.everythingHidden.getValue());
if (!Utils.highlighted.get() || Utils.ultraLight.get()) { if (!Utils.highlighted.getValue() || Utils.ultraLight.getValue()) {
jokeButton.setBackground(BG); jokeButton.setBackground(BG);
commandButton.setBackground(BG); commandButton.setBackground(BG);
restartButton.setBackground(BG); restartButton.setBackground(BG);
@ -346,9 +347,9 @@ public class TimeCalcManager {
} }
jokeButton.setVisible( jokeButton.setVisible(
TimeCalcConf.getInstance().isJokeVisible() TimeCalcConf.getInstance().isJokeVisible()
&& !Utils.everythingHidden.get()); && !Utils.everythingHidden.getValue());
window.setTitle(Utils.everythingHidden.get() ? "" : windowTitle); window.setTitle(Utils.everythingHidden.getValue() ? "" : windowTitle);
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
String nowString = String nowString =
@ -444,7 +445,7 @@ public class TimeCalcManager {
} }
walkingHumanProgressAsciiArt.setForeground( walkingHumanProgressAsciiArt.setForeground(
Utils.highlighted.get() || walkingHumanProgressAsciiArt Utils.highlighted.getValue() || walkingHumanProgressAsciiArt
.getClientProperty("mouseEntered").equals("true") ? .getClientProperty("mouseEntered").equals("true") ?
Color.BLACK : Color.LIGHT_GRAY); Color.BLACK : Color.LIGHT_GRAY);
} }

View File

@ -1,12 +1,12 @@
package org.nanoboot.utils.timecalc.main; package org.nanoboot.utils.timecalc.swing.common;
import org.nanoboot.utils.timecalc.gui.common.TimeCalcButton; import org.nanoboot.utils.timecalc.swing.common.TimeCalcButton;
import org.nanoboot.utils.timecalc.utils.Utils; import org.nanoboot.utils.timecalc.utils.Utils;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
/** /**
* @author pc00289 * @author Robert
* @since 21.02.2024 * @since 21.02.2024
*/ */
public class AboutButton extends TimeCalcButton { public class AboutButton extends TimeCalcButton {

View File

@ -1,4 +1,4 @@
package org.nanoboot.utils.timecalc.gui.common; package org.nanoboot.utils.timecalc.swing.common;
import javax.swing.JComponent; import javax.swing.JComponent;
import java.awt.Component; import java.awt.Component;
@ -6,7 +6,7 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
/** /**
* @author pc00289 * @author Robert
* @since 21.02.2024 * @since 21.02.2024
*/ */
public class ComponentRegistry { public class ComponentRegistry {

View File

@ -1,11 +1,11 @@
package org.nanoboot.utils.timecalc.gui.common; package org.nanoboot.utils.timecalc.swing.common;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.Timer; import javax.swing.Timer;
import java.awt.Color; import java.awt.Color;
/** /**
* @author pc00289 * @author Robert
* @since 21.02.2024 * @since 21.02.2024
*/ */
public class TimeCalcButton extends JButton { public class TimeCalcButton extends JButton {

View File

@ -1,11 +1,11 @@
package org.nanoboot.utils.timecalc.gui.common; package org.nanoboot.utils.timecalc.swing.common;
import javax.swing.JFrame; import javax.swing.JFrame;
import java.awt.Component; import java.awt.Component;
import java.awt.HeadlessException; import java.awt.HeadlessException;
/** /**
* @author pc00289 * @author Robert
* @since 21.02.2024 * @since 21.02.2024
*/ */
public class TimeCalcWindow extends JFrame { public class TimeCalcWindow extends JFrame {

View File

@ -1,7 +1,7 @@
/** /**
* This Java class named Toaster is licence under this licence: Apache License V2.0 * This Java class named Toaster is licence under this licence: Apache License V2.0
*/ */
package org.nanoboot.utils.timecalc.gui.common; package org.nanoboot.utils.timecalc.swing.common;
/** /**
* Java Toaster is a java utility class for your swing applications * Java Toaster is a java utility class for your swing applications
* that show an animate box coming from the bottom of your screen * that show an animate box coming from the bottom of your screen
@ -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.get() || !Utils.toastsAreEnabled.get()) { if (Utils.everythingHidden.getValue() || !Utils.toastsAreEnabled.getValue()) {
//nothing to do //nothing to do
return; return;
} }

View File

@ -1,4 +1,4 @@
package org.nanoboot.utils.timecalc.gui.common; package org.nanoboot.utils.timecalc.swing.common;
import org.nanoboot.utils.timecalc.utils.Utils; import org.nanoboot.utils.timecalc.utils.Utils;
@ -21,7 +21,7 @@ import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
/** /**
* @author pc00289 * @author Robert
* @since 16.02.2024 * @since 16.02.2024
*/ */
public class WeatherWindow extends JFrame { public class WeatherWindow extends JFrame {

View File

@ -1,4 +1,4 @@
package org.nanoboot.utils.timecalc.gui.common; package org.nanoboot.utils.timecalc.swing.common;
import org.nanoboot.utils.timecalc.utils.Utils; import org.nanoboot.utils.timecalc.utils.Utils;
@ -9,7 +9,7 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
/** /**
* @author pc00289 * @author Robert
* @since 20.02.2024 * @since 20.02.2024
*/ */
public class Widget extends JPanel { public class Widget extends JPanel {

View File

@ -1,6 +1,6 @@
package org.nanoboot.utils.timecalc.gui.progress; package org.nanoboot.utils.timecalc.swing.progress;
import org.nanoboot.utils.timecalc.gui.common.Widget; import org.nanoboot.utils.timecalc.swing.common.Widget;
import org.nanoboot.utils.timecalc.main.TimeCalcConf; import org.nanoboot.utils.timecalc.main.TimeCalcConf;
import org.nanoboot.utils.timecalc.utils.DateFormats; import org.nanoboot.utils.timecalc.utils.DateFormats;
import org.nanoboot.utils.timecalc.utils.TimeHM; import org.nanoboot.utils.timecalc.utils.TimeHM;
@ -141,7 +141,7 @@ 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.get() || mouseOver ? Color.RED : g2d.setColor(Utils.highlighted.getValue() || 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);
@ -154,7 +154,7 @@ public class AnalogClock extends Widget {
int endX = (int) (getWidth() / 2 + length * Math.cos(angle)); int endX = (int) (getWidth() / 2 + length * Math.cos(angle));
int endY = (int) (getHeight() / 2 + length * Math.sin(angle)); int endY = (int) (getHeight() / 2 + length * Math.sin(angle));
g2d.setColor((Utils.highlighted.get() || mouseOver) ? color : g2d.setColor((Utils.highlighted.getValue() || 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);
@ -163,7 +163,7 @@ public class AnalogClock extends Widget {
private void drawClockFace(Graphics2D g2d, int centerX, int centerY, private void drawClockFace(Graphics2D g2d, int centerX, int centerY,
int radius) { int radius) {
g2d.setStroke(new BasicStroke(2.0f)); g2d.setStroke(new BasicStroke(2.0f));
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.BLACK : g2d.setColor(Utils.highlighted.getValue() || 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);

View File

@ -1,9 +1,9 @@
package org.nanoboot.utils.timecalc.gui.progress; package org.nanoboot.utils.timecalc.swing.progress;
import lombok.Getter; import lombok.Getter;
import org.nanoboot.utils.timecalc.gui.common.Widget; import org.nanoboot.utils.timecalc.swing.common.Widget;
import org.nanoboot.utils.timecalc.main.TimeCalcConf; import org.nanoboot.utils.timecalc.main.TimeCalcConf;
import org.nanoboot.utils.timecalc.utils.BooleanHolder; import org.nanoboot.utils.timecalc.utils.BooleanProperty;
import org.nanoboot.utils.timecalc.utils.NumberFormats; import org.nanoboot.utils.timecalc.utils.NumberFormats;
import org.nanoboot.utils.timecalc.utils.Utils; import org.nanoboot.utils.timecalc.utils.Utils;
@ -29,7 +29,7 @@ public class Battery extends Widget {
public static final double VERY_HIGH_ENERGY = 0.9; public static final double VERY_HIGH_ENERGY = 0.9;
public static boolean wavesOff = false; public static boolean wavesOff = false;
private static final Font bigFont = new Font("sans", Font.BOLD, 24); private static final Font bigFont = new Font("sans", Font.BOLD, 24);
private BooleanHolder blinking = new BooleanHolder(); private BooleanProperty blinking = new BooleanProperty();
private long tmpNanoTime = 0l; private long tmpNanoTime = 0l;
@Getter @Getter
@ -61,22 +61,22 @@ public class Battery extends Widget {
blinking.flip(); blinking.flip();
tmpNanoTime = System.nanoTime(); tmpNanoTime = System.nanoTime();
} }
if(donePercent <= 0 && blinking.get()){ if(donePercent <= 0 && blinking.getValue()){
blinking.set(false); blinking.setValue(false);
} }
super.paintComponent(g); super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.YELLOW : g2d.setColor(Utils.highlighted.getValue() || 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.get()) { if (!Utils.ultraLight.getValue()) {
g2d.fillRect(1, 1, totalWidth, totalHeight); g2d.fillRect(1, 1, totalWidth, totalHeight);
} }
if (Utils.highlighted.get() || mouseOver) { if (Utils.highlighted.getValue() || 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,10 +86,10 @@ 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.get()) { if (Utils.ultraLight.getValue()) {
g2d.setColor(Utils.ULTRA_LIGHT_GRAY); g2d.setColor(Utils.ULTRA_LIGHT_GRAY);
} }
if(blinking.get()) { if(blinking.getValue()) {
g2d.setColor(BACKGROUND_COLOR); g2d.setColor(BACKGROUND_COLOR);
} }
int doneHeight = (int) (totalHeight * donePercent); int doneHeight = (int) (totalHeight * donePercent);
@ -138,7 +138,7 @@ public class Battery extends Widget {
todoHeight + (waterSurfaceHeight * 1)}, todoHeight + (waterSurfaceHeight * 1)},
pointCount); pointCount);
g2d.setColor((Utils.ultraLight.get() || !Utils.highlighted.get()) && !mouseOver ? Utils.ULTRA_LIGHT_GRAY : Color.DARK_GRAY); g2d.setColor((Utils.ultraLight.getValue() || !Utils.highlighted.getValue()) && !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 +169,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.get() || mouseOver ? Color.BLACK : g2d.setColor(Utils.highlighted.getValue() || mouseOver ? Color.BLACK :
Color.LIGHT_GRAY); Color.LIGHT_GRAY);
if(donePercent <1) { if(donePercent <1) {
@ -199,7 +199,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.get() || mouseOver ? Color.BLACK : g2d.setColor(Utils.highlighted.getValue() || mouseOver ? Color.BLACK :
Color.LIGHT_GRAY); Color.LIGHT_GRAY);
g2d.drawRect(1, 1, totalWidth - 2, totalHeight); g2d.drawRect(1, 1, totalWidth - 2, totalHeight);

View File

@ -1,7 +1,7 @@
package org.nanoboot.utils.timecalc.gui.progress; package org.nanoboot.utils.timecalc.swing.progress;
/** /**
* @author pc00289 * @author Robert
* @since 21.02.2024 * @since 21.02.2024
*/ */
public class DayBattery extends Battery{ public class DayBattery extends Battery{

View File

@ -1,9 +1,9 @@
package org.nanoboot.utils.timecalc.gui.progress; package org.nanoboot.utils.timecalc.swing.progress;
import org.nanoboot.utils.timecalc.utils.TimeHM; import org.nanoboot.utils.timecalc.utils.TimeHM;
/** /**
* @author pc00289 * @author Robert
* @since 21.02.2024 * @since 21.02.2024
*/ */
public class HourBattery extends Battery{ public class HourBattery extends Battery{

View File

@ -1,7 +1,7 @@
package org.nanoboot.utils.timecalc.gui.progress; package org.nanoboot.utils.timecalc.swing.progress;
/** /**
* @author pc00289 * @author Robert
* @since 21.02.2024 * @since 21.02.2024
*/ */
public class MonthBattery extends Battery{ public class MonthBattery extends Battery{

View File

@ -1,6 +1,6 @@
package org.nanoboot.utils.timecalc.gui.progress; package org.nanoboot.utils.timecalc.swing.progress;
import org.nanoboot.utils.timecalc.gui.common.Widget; import org.nanoboot.utils.timecalc.swing.common.Widget;
import org.nanoboot.utils.timecalc.utils.NumberFormats; import org.nanoboot.utils.timecalc.utils.NumberFormats;
import org.nanoboot.utils.timecalc.utils.Utils; import org.nanoboot.utils.timecalc.utils.Utils;
@ -23,7 +23,7 @@ public class ProgressCircle extends Widget {
} }
super.paintComponent(g); super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.darkGray : g2d.setColor(Utils.highlighted.getValue() || 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 +34,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.get() || mouseOver ? g2d.setColor(Utils.highlighted.getValue() || 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.get() || mouseOver ? Color.blue :FOREGROUND_COLOR); g2d.setColor(Utils.highlighted.getValue() || 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));

View File

@ -1,6 +1,6 @@
package org.nanoboot.utils.timecalc.gui.progress; package org.nanoboot.utils.timecalc.swing.progress;
import org.nanoboot.utils.timecalc.gui.common.Widget; import org.nanoboot.utils.timecalc.swing.common.Widget;
import org.nanoboot.utils.timecalc.utils.NumberFormats; import org.nanoboot.utils.timecalc.utils.NumberFormats;
import org.nanoboot.utils.timecalc.utils.Utils; import org.nanoboot.utils.timecalc.utils.Utils;
@ -39,7 +39,7 @@ public class ProgressSquare extends Widget {
// System.out.println("x=" + x); // System.out.println("x=" + x);
// System.out.println("y=" + y); // System.out.println("y=" + y);
if (y > 1) { if (y > 1) {
if (Utils.highlighted.get() || mouseOver) { if (Utils.highlighted.getValue() || 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 +48,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.get() || mouseOver) { if (Utils.highlighted.getValue() || 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.get() || mouseOver) { if (Utils.highlighted.getValue() || 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.get() || mouseOver) { if (Utils.highlighted.getValue() || 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.get() || mouseOver) { if (Utils.highlighted.getValue() || 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.get() || mouseOver ? Color.BLACK : BACKGROUND_COLOR); g2d.setColor(Utils.highlighted.getValue() || 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)));

View File

@ -1,6 +1,6 @@
package org.nanoboot.utils.timecalc.gui.progress; package org.nanoboot.utils.timecalc.swing.progress;
import org.nanoboot.utils.timecalc.gui.common.Toaster; import org.nanoboot.utils.timecalc.swing.common.Toaster;
import org.nanoboot.utils.timecalc.utils.Constants; import org.nanoboot.utils.timecalc.utils.Constants;
import org.nanoboot.utils.timecalc.utils.NumberFormats; import org.nanoboot.utils.timecalc.utils.NumberFormats;
import org.nanoboot.utils.timecalc.utils.TimeHM; import org.nanoboot.utils.timecalc.utils.TimeHM;
@ -15,12 +15,11 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.util.Base64;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
/** /**
* @author pc00289 * @author Robert
* @since 21.02.2024 * @since 21.02.2024
*/ */
public class WalkingHumanProgressAsciiArt extends JTextPane { public class WalkingHumanProgressAsciiArt extends JTextPane {

View File

@ -1,9 +1,7 @@
package org.nanoboot.utils.timecalc.gui.progress; package org.nanoboot.utils.timecalc.swing.progress;
import org.nanoboot.utils.timecalc.utils.TimeHM;
/** /**
* @author pc00289 * @author Robert
* @since 21.02.2024 * @since 21.02.2024
*/ */
public class WeekBattery extends Battery{ public class WeekBattery extends Battery{

View File

@ -1,41 +0,0 @@
package org.nanoboot.utils.timecalc.utils;
/**
* @author Robert
* @since 16.02.2024
*/
public class BooleanHolder {
private boolean b;
public BooleanHolder(boolean b) {
this.b = b;
}
public BooleanHolder() {
this(false);
}
public void set(boolean b) {
this.b = b;
}
public boolean isEnabled() {
return get();
}
public boolean isDisabled() {
return !get();
}
public boolean get() {
return b;
}
public void flip() {
this.b = !b;
}
public void enable() {
set(true);
}
public void disable() {
set(false);
}
}

View File

@ -0,0 +1,39 @@
package org.nanoboot.utils.timecalc.utils;
/**
* @author Robert
* @since 16.02.2024
*/
public class BooleanProperty extends Property<Boolean> {
public BooleanProperty() {
super(Boolean.FALSE);
}
public BooleanProperty(boolean valueIn) {
this(Boolean.valueOf(valueIn));
}
public BooleanProperty(Boolean valueIn) {
super(valueIn);
}
public boolean isEnabled() {
return getValue();
}
public boolean isDisabled() {
return !getValue();
}
public void flip() {
setValue(!getValue());
}
public void inverse() {
flip();
}
public void enable() {
setValue(true);
}
public void disable() {
setValue(false);
}
}

View File

@ -1,6 +1,6 @@
package org.nanoboot.utils.timecalc.utils; package org.nanoboot.utils.timecalc.utils;
import org.nanoboot.utils.timecalc.gui.common.Toaster; import org.nanoboot.utils.timecalc.swing.common.Toaster;
import org.nanoboot.utils.timecalc.main.TimeCalcConf; import org.nanoboot.utils.timecalc.main.TimeCalcConf;
import javax.swing.JFrame; import javax.swing.JFrame;

View File

@ -0,0 +1,16 @@
package org.nanoboot.utils.timecalc.utils;
import lombok.Getter;
import lombok.Setter;
/**
* @author Robert
* @since 23.02.2024
*/
public class Property <T>{
@Getter @Setter
private T value;
public Property(T valueIn) {
this.value = valueIn;
}
}

View File

@ -1,7 +1,6 @@
package org.nanoboot.utils.timecalc.utils; package org.nanoboot.utils.timecalc.utils;
import org.nanoboot.utils.timecalc.main.Main; import org.nanoboot.utils.timecalc.main.Main;
import org.nanoboot.utils.timecalc.main.TimeCalcException;
import java.awt.Color; import java.awt.Color;
import java.io.File; import java.io.File;
@ -19,22 +18,17 @@ import java.util.jar.Manifest;
* @since 15.02.2024 * @since 15.02.2024
*/ */
public class Utils { public class Utils {
private static long startNanoTime = 0l;
public static final BooleanHolder highlighted = new BooleanHolder(); public static final BooleanProperty highlighted = new BooleanProperty();
public static final BooleanHolder ultraLight = new BooleanHolder(); public static final BooleanProperty ultraLight = new BooleanProperty();
public static final BooleanHolder everythingHidden = new BooleanHolder(); public static final BooleanProperty everythingHidden = new BooleanProperty();
public static final BooleanHolder toastsAreEnabled = new BooleanHolder(true); 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.
*/ */
private static final int COUNT_OF_BYTES_PER_ONE_KILOBYTE = 1024; private static final int COUNT_OF_BYTES_PER_ONE_KILOBYTE = 1024;
public static void startApp() {
if(startNanoTime != 0) {
throw new TimeCalcException("App is already started.");
}
startNanoTime = System.nanoTime();
}
private Utils() { private Utils() {
//Not meant to be instantiated. //Not meant to be instantiated.
} }
@ -89,18 +83,7 @@ public class Utils {
((int) (Math.random() * 256)), ((int) (Math.random() * 256))); ((int) (Math.random() * 256)), ((int) (Math.random() * 256)));
} }
public static long getCountOfMinutesSinceAppStarted() {
return getCountOfSecondsSinceAppStarted() / 60l;
}
public static long getCountOfSecondsSinceAppStarted() {
return getCountOfMillisecondsSinceAppStarted() / 1000000000l;
}
public static long getCountOfMillisecondsSinceAppStarted() {
if(startNanoTime == 0l) {
throw new TimeCalcException("App was not yet started.");
}
return System.nanoTime() - startNanoTime;
}
/** /**
* Returns version of "Time Calc" from jar file. * Returns version of "Time Calc" from jar file.