Code was formatted

This commit is contained in:
Robert Vokac 2024-02-03 00:47:02 +00:00
parent 43324c8f03
commit a10faea532
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
14 changed files with 280 additions and 168 deletions

View File

@ -9,9 +9,11 @@ import javax.swing.JButton;
public class TimeCalcButton extends JButton {
private static final int BUTTON_WIDTH = 100;
private static final int BUTTON_HEIGHT = 30;
public TimeCalcButton(String label) {
super(label);
}
public void setBounds(int x, int y) {
setBounds(x, y, BUTTON_WIDTH, BUTTON_HEIGHT);
}

View File

@ -113,7 +113,7 @@ public class Toaster {
* Show a toaster with the specified message and the associated icon.
*/
public void showToaster(Icon icon, String msg) {
if(Utils.everythingHidden.get() || !Utils.toastsAreEnabled.get()) {
if (Utils.everythingHidden.get() || !Utils.toastsAreEnabled.get()) {
//nothing to do
return;
}
@ -429,7 +429,7 @@ public class Toaster {
if (currentNumberOfToaster > 0) {
stopYPosition =
stopYPosition - (maxToaster % maxToasterInSceen
* toasterHeight);
* toasterHeight);
} else {
maxToaster = 0;
}
@ -440,7 +440,7 @@ public class Toaster {
if (currentNumberOfToaster > 0) {
stopYPosition =
stopYPosition + (maxToaster % maxToasterInSceen
* toasterHeight);
* toasterHeight);
} else {
maxToaster = 0;
}

View File

@ -13,12 +13,13 @@ import java.awt.event.MouseListener;
* @since 20.02.2024
*/
public class Widget extends JPanel {
protected int side = 0;
protected double donePercent = 0;
protected boolean mouseOver = false;
protected static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
protected static final Color FOREGROUND_COLOR2 = new Color(210, 210, 210);
protected static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
protected int side = 0;
protected double donePercent = 0;
protected boolean mouseOver = false;
public Widget() {
setBackground(BACKGROUND_COLOR);
new Timer(getTimerDelay(), e -> repaint()).start();
@ -49,15 +50,18 @@ public class Widget extends JPanel {
}
});
}
public int getTimerDelay() {
return 100;
}
public final void setDonePercent(double donePercent) {
if(donePercent > 1) {
if (donePercent > 1) {
donePercent = 1;
}
this.donePercent = donePercent;
}
public void setBounds(int x, int y, int side) {
setBounds(x, y, side, side);
}

View File

@ -56,25 +56,32 @@ public class AnalogClock extends Widget {
drawHand(g2d, side / 2 - 10, second / 60.0, 0.5f, Color.RED);
if(TimeCalcConf.getInstance().areClockHandsLong()) drawHand(g2d, (side / 2 - 10) / 4,
(second > 30 ? second - 30 : second + 30) / 60.0, 0.5f,
Color.RED);
if (TimeCalcConf.getInstance().areClockHandsLong()) {
drawHand(g2d, (side / 2 - 10) / 4,
(second > 30 ? second - 30 : second + 30) / 60.0, 0.5f,
Color.RED);
}
//
double minutes = minute / 60.0 + second / 60.0 / 60.0;
drawHand(g2d, side / 2 - 20, minutes, 2.0f,
Color.BLUE);
if(TimeCalcConf.getInstance().areClockHandsLong()) drawHand(g2d, (side / 2 - 20) / 4,
minutes + minutes > 0.5 ? minutes - 0.5 :
minutes + (minutes > 0.5 ? (-1) : 1) * 0.5, 2.0f,
Color.BLUE);
if (TimeCalcConf.getInstance().areClockHandsLong()) {
drawHand(g2d, (side / 2 - 20) / 4,
minutes + minutes > 0.5 ? minutes - 0.5 :
minutes + (minutes > 0.5 ? (-1) : 1) * 0.5, 2.0f,
Color.BLUE);
}
//
double hours = hour / 12.0 + minute / 60.0 / 12 + second / 60 / 60 / 12;
drawHand(g2d, side / 2 - 40,
hours, 4.0f,
Color.BLACK);
if(TimeCalcConf.getInstance().areClockHandsLong()) drawHand(g2d, (side / 2 - 40) / 4, hours + hours > 0.5 ? hours - 0.5 :
hours + (hours > 0.5 ? (-1) : 1) * 0.5, 4.0f,
Color.BLACK);
if (TimeCalcConf.getInstance().areClockHandsLong()) {
drawHand(g2d, (side / 2 - 40) / 4,
hours + hours > 0.5 ? hours - 0.5 :
hours + (hours > 0.5 ? (-1) : 1) * 0.5, 4.0f,
Color.BLACK);
}
drawCentre(g2d, centerX, centerY);
}
@ -125,12 +132,12 @@ public class AnalogClock extends Widget {
int seconds = Integer.valueOf(now.split(":")[2]);
g2d.setFont(new Font("sans", Font.BOLD, 16));
g2d.drawString(Integer.toString(i), dx, dy);
}
}
public int getTimerDelay() {
return 20;
}

View File

@ -13,7 +13,6 @@ import java.text.DecimalFormat;
import java.text.NumberFormat;
public class Battery extends Widget {
public static boolean wavesOff = false;
public static final Color LOW = new Color(253, 130, 130);
public static final Color MEDIUM = new Color(255, 204, 153);
public static final Color HIGH = new Color(204, 255, 204);
@ -22,12 +21,13 @@ public class Battery extends Widget {
public static final Color MEDIUM_HIGHLIGHTED = Color.ORANGE;
public static final Color HIGH_HIGHLIGHTED = new Color(158, 227, 158);
public static final Color HIGHEST_HIGHLIGHTED = Color.green;
public static boolean wavesOff = false;
NumberFormat formatter3 = new DecimalFormat("#0.000");
private int totalHeight = 0;
private int width_;
private String label = null;
private final double[] randomDoubles = new double[] {1d, 1d, 1d, 1d, 1d, 1d, 1};
public Battery() {
setPreferredSize(new Dimension(40, 100));
@ -46,7 +46,7 @@ public class Battery extends Widget {
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
if(!Utils.ultraLight.get()) {
if (!Utils.ultraLight.get()) {
g2d.fillRect(width_ / 4, 1, width_, totalHeight - 2);
}
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.BLACK :
@ -57,77 +57,93 @@ public class Battery extends Widget {
donePercent < 0.1 ? LOW_HIGHLIGHTED : (donePercent < 0.75 ?
MEDIUM_HIGHLIGHTED :
(donePercent < 0.9 ? HIGH_HIGHLIGHTED :
HIGHEST_HIGHLIGHTED)));
HIGHEST_HIGHLIGHTED)));
} else {
g2d.setColor(donePercent < 0.1 ? LOW : (donePercent < 0.75 ?
MEDIUM : (donePercent < 0.9 ? HIGH : HIGHEST)));
}
if(Utils.ultraLight.get()) {
if (Utils.ultraLight.get()) {
g2d.setColor(Utils.ULTRA_LIGHT_GRAY);
}
int doneHeight = (int) (totalHeight * donePercent);
int intX = width_ / 4;
int todoHeight = totalHeight - doneHeight;
double surfacePower = 1;//donePercent < 0.5 ? 0.5 : donePercent;// (donePercent * 100 - ((int)(donePercent * 100)));
int waterSurfaceHeight = (int) (4 * surfacePower);//2 + (int) (Math.random() * 3);
if(waterSurfaceHeight <= 2 || !TimeCalcConf.getInstance()
double surfacePower =
1;//donePercent < 0.5 ? 0.5 : donePercent;// (donePercent * 100 - ((int)(donePercent * 100)));
int waterSurfaceHeight =
(int) (4 * surfacePower);//2 + (int) (Math.random() * 3);
if (waterSurfaceHeight <= 2 || !TimeCalcConf.getInstance()
.areBatteryWavesEnabled() || wavesOff) {
waterSurfaceHeight = 0;
}
g2d.fillRect(intX, doneHeight < waterSurfaceHeight || donePercent >= 1 ? todoHeight : todoHeight + waterSurfaceHeight,
width_, doneHeight < waterSurfaceHeight || donePercent >= 1 ? doneHeight : doneHeight - waterSurfaceHeight);
g2d.fillRect(intX, doneHeight < waterSurfaceHeight || donePercent >= 1 ?
todoHeight : todoHeight + waterSurfaceHeight,
width_, doneHeight < waterSurfaceHeight || donePercent >= 1 ?
doneHeight : doneHeight - waterSurfaceHeight);
int pointCount = 8;
if(doneHeight >= waterSurfaceHeight && donePercent < 1) {// && todoHeight > waterSurfaceHeight) {
if (doneHeight >= waterSurfaceHeight
&& donePercent < 1) {// && todoHeight > waterSurfaceHeight) {
//g2d.fillArc(intX, intY, width_, intHeight - waterSurfaceHeight, 30, 60);
g2d.fillPolygon(
new int[]{intX,
new int[] {intX,
(int) (intX + width_ / pointCount * 0.5),
intX + width_ / pointCount * 3,
intX + width_ / pointCount * 4,
intX + width_ / pointCount * 5,
intX + width_ / pointCount * 6,
(int) (intX + width_ / pointCount * 7),
intX + width_ / pointCount * 7,
intX + width_ / pointCount * 8},
new int[]{(int) (todoHeight + (waterSurfaceHeight * 1)),
todoHeight + (int) (waterSurfaceHeight * getRandom(0)),
todoHeight + (int) (waterSurfaceHeight * getRandom(1)),
todoHeight + (int) (waterSurfaceHeight * getRandom(2)),
todoHeight + (int) (waterSurfaceHeight * getRandom(3)),
todoHeight + (int) (waterSurfaceHeight * getRandom(4)),
todoHeight + (int) (waterSurfaceHeight * getRandom(5)),
(int) (todoHeight + (waterSurfaceHeight * 1))},
new int[] {todoHeight + (waterSurfaceHeight * 1),
todoHeight + (int) (waterSurfaceHeight * getRandom(
0)),
todoHeight + (int) (waterSurfaceHeight * getRandom(
1)),
todoHeight + (int) (waterSurfaceHeight * getRandom(
2)),
todoHeight + (int) (waterSurfaceHeight * getRandom(
3)),
todoHeight + (int) (waterSurfaceHeight * getRandom(
4)),
todoHeight + (int) (waterSurfaceHeight * getRandom(
5)),
todoHeight + (waterSurfaceHeight * 1)},
pointCount);
}
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.BLACK :
Color.LIGHT_GRAY);
g2d.drawString(
formatter3.format(donePercent * 100) + "%",
((int) (width_ * 0.4)), donePercent > 0.5 ? totalHeight / 4 * 3 : totalHeight / 4 * 1);
((int) (width_ * 0.4)),
donePercent > 0.5 ? totalHeight / 4 * 3 : totalHeight / 4 * 1);
if(label!= null && !label.isEmpty()) {
if (label != null && !label.isEmpty()) {
g2d.drawString(
label,
((int) (width_ * 0.4)),
(donePercent > 0.5 ? totalHeight / 4 * 3 :
totalHeight / 4 * 1)+ 20);
totalHeight / 4 * 1) + 20);
}
}
private double[] randomDoubles = new double[]{1d,1d,1d,1d,1d,1d,1};
private double getRandom(int index) {
if(Math.random() > 0.7) {randomDoubles[index] = Math.random();}
if (Math.random() > 0.7) {
randomDoubles[index] = Math.random();
}
return randomDoubles[index];
}
public int getTimerDelay() {
return 250;
}
public void setLabel(String label) {
this.label = label;
}
public String getLabel() {
return this.label;
}
public void setLabel(String label) {
this.label = label;
}
}

View File

@ -29,7 +29,6 @@ public class ProgressSquare extends Widget {
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
int dotNumber = (int) (donePercent * square);
int y = dotNumber / side;
int yOrig = y;

View File

@ -1,8 +1,8 @@
package org.nanoboot.utils.timecalc.main;
import org.nanoboot.utils.timecalc.utils.Constants;
import org.nanoboot.utils.timecalc.utils.Utils;
import org.nanoboot.utils.timecalc.utils.FileConstants;
import org.nanoboot.utils.timecalc.utils.Utils;
import javax.swing.JOptionPane;
import java.io.IOException;
@ -13,7 +13,6 @@ import java.io.IOException;
*/
public class Main {
public static void main(String[] args) throws IOException {
while (true) {
@ -23,25 +22,33 @@ public class Main {
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
);
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
);
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);

View File

@ -17,15 +17,10 @@ public class TimeCalcConf {
private static final String TOASTS_ENABLED = "toasts.enabled";
private static TimeCalcConf INSTANCE;
private Properties properties = new Properties();
public static TimeCalcConf getInstance() {
if(INSTANCE == null) {
INSTANCE = new TimeCalcConf();
}
return INSTANCE;
}
private final Properties properties = new Properties();
private TimeCalcConf() {
if(!new File("timecalc.conf").exists()) {
if (!new File("timecalc.conf").exists()) {
//nothing to do;
return;
}
@ -36,23 +31,35 @@ public class TimeCalcConf {
}
}
public static TimeCalcConf getInstance() {
if (INSTANCE == null) {
INSTANCE = new TimeCalcConf();
}
return INSTANCE;
}
public boolean areClockHandsLong() {
return getBooleanProperty(CLOCK_HANDS_LONG, true);
}
public boolean isJokeVisible() {
return getBooleanProperty(JOKE_VISIBLE, true);
}
public boolean areBatteryWavesEnabled() {
return getBooleanProperty(BATTERY_WAVES_ENABLED, true);
}
public boolean isEverythingHidden() {
return getBooleanProperty(EVERYTHING_HIDDEN, false);
}
public boolean areToastsEnabled() {
return getBooleanProperty(TOASTS_ENABLED, true);
}
private boolean getBooleanProperty(String key, boolean defaultValue) {
if(!properties.containsKey(key)) {
if (!properties.containsKey(key)) {
return defaultValue;
}
return properties.get(key).equals("true");

View File

@ -4,7 +4,7 @@ package org.nanoboot.utils.timecalc.main;
* @author Robert
* @since 21.02.2024
*/
public class TimeCalcException extends RuntimeException{
public class TimeCalcException extends RuntimeException {
public TimeCalcException(String msg) {
super(msg);
}

View File

@ -26,7 +26,6 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.time.DayOfWeek;
@ -55,21 +54,23 @@ public class TimeCalcWindow {
private final String startTime;
private final String windowTitle;
private String overTime;
private final int startHour;
private final int startMinute;
private final int overtimeHour;
private final int overtimeMinute;
private final int totalMinutes;
private final Set<Integer> alreadyShownPercents = new HashSet<>();
private String overTime;
private int endHour;
private int endMinute;
private boolean stopBeforeEnd = false;
private boolean vtipyShown = false;
public TimeCalcWindow(String startTimeIn, String overTimeIn) {
Utils.everythingHidden.set(TimeCalcConf.getInstance().isEverythingHidden());
Utils.toastsAreEnabled.set(TimeCalcConf.getInstance().areToastsEnabled());
Utils.everythingHidden
.set(TimeCalcConf.getInstance().isEverythingHidden());
Utils.toastsAreEnabled
.set(TimeCalcConf.getInstance().areToastsEnabled());
this.startTime = startTimeIn;
this.overTime = (overTimeIn == null || overTimeIn.isEmpty()) ?
@ -80,9 +81,13 @@ public class TimeCalcWindow {
this.startMinute = Integer.valueOf(startTimeAsArray[1]);
boolean overtimeIsNegative = overTime.startsWith("-");
if(overtimeIsNegative) {overTime = overTime.replace("-","");}
this.overtimeHour =(overtimeIsNegative ? (-1) : 1) * Integer.valueOf(overTime.split(":")[0]);
this.overtimeMinute = (overtimeIsNegative ? (-1) : 1) * Integer.valueOf(overTime.split(":")[1]);
if (overtimeIsNegative) {
overTime = overTime.replace("-", "");
}
this.overtimeHour = (overtimeIsNegative ? (-1) : 1) * Integer
.valueOf(overTime.split(":")[0]);
this.overtimeMinute = (overtimeIsNegative ? (-1) : 1) * Integer
.valueOf(overTime.split(":")[1]);
this.endHour = startHour + WORKING_HOURS_LENGTH + overtimeHour;
this.endMinute = startMinute + WORKING_MINUTES_LENGTH + overtimeMinute;
@ -117,7 +122,10 @@ public class TimeCalcWindow {
if (buildDate == null) {
buildDate = "unknown";
}
JOptionPane.showMessageDialog(null, "Version: " + version + "\n" + "Built on (universal time): " + buildDate, "About \"Pdf DME Downloader\"", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,
"Version: " + version + "\n" + "Built on (universal time): "
+ buildDate, "About \"Pdf DME Downloader\"",
JOptionPane.INFORMATION_MESSAGE);
});
//window.add(weatherButton);
@ -131,27 +139,27 @@ public class TimeCalcWindow {
window.addKeyListener(new KeyAdapter() {
// Key Pressed method
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_UP){
if (e.getKeyCode() == KeyEvent.VK_UP) {
Utils.everythingHidden.set(false);
}
if(e.getKeyCode() == KeyEvent.VK_DOWN){
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
Utils.everythingHidden.set(true);
}
if(e.getKeyCode() == KeyEvent.VK_G){
if (e.getKeyCode() == KeyEvent.VK_G) {
Utils.ultraLight.flip();
}
if(e.getKeyCode() == KeyEvent.VK_C){
if (e.getKeyCode() == KeyEvent.VK_C) {
Utils.highlighted.flip();
}
if(e.getKeyCode() == KeyEvent.VK_V){
if (e.getKeyCode() == KeyEvent.VK_V) {
Utils.everythingHidden.flip();
}
if(e.getKeyCode() == KeyEvent.VK_R){
if (e.getKeyCode() == KeyEvent.VK_R) {
commandButton.doClick();
}
if(e.getKeyCode() == KeyEvent.VK_T){
if (e.getKeyCode() == KeyEvent.VK_T) {
Utils.toastsAreEnabled.flip();
}
@ -202,9 +210,12 @@ public class TimeCalcWindow {
restartButton
.setBounds(280, text.getY() + text.getHeight() + MARGIN);
exitButton.setBounds(390, text.getY() + text.getHeight() + MARGIN);
aboutButton.setBounds(exitButton.getX(), exitButton.getY() + exitButton.getHeight() + MARGIN);
aboutButton.setBounds(exitButton.getX(),
exitButton.getY() + exitButton.getHeight() + MARGIN);
focusButton.setBounds(exitButton.getX() + 3 * MARGIN + exitButton.getWidth() + 20, MARGIN, 60, aboutButton.getHeight());
focusButton.setBounds(
exitButton.getX() + 3 * MARGIN + exitButton.getWidth() + 20,
MARGIN, 60, aboutButton.getHeight());
window.setSize(520 + 20 + 100, 580 + MARGIN + aboutButton.getHeight());
window.setLayout(null);
@ -234,12 +245,26 @@ public class TimeCalcWindow {
"test"
);
String[] commandsAsArray = commands.split(" ");
switch(commandsAsArray[0]) {
case "test": JOptionPane.showMessageDialog(null, "Test");break;
case "color": Utils.highlighted.set(commandsAsArray[1].equals("1"));break;
case "gray": Utils.ultraLight.set(commandsAsArray[1].equals("1"));break;
case "waves": Battery.wavesOff = commandsAsArray[1].equals("0");break;
case "uptime": JOptionPane.showMessageDialog(null, Utils.getCountOfMinutesSinceAppStarted() + " minutes");break;
switch (commandsAsArray[0]) {
case "test":
JOptionPane.showMessageDialog(null, "Test");
break;
case "color":
Utils.highlighted
.set(commandsAsArray[1].equals("1"));
break;
case "gray":
Utils.ultraLight
.set(commandsAsArray[1].equals("1"));
break;
case "waves":
Battery.wavesOff = commandsAsArray[1].equals("0");
break;
case "uptime":
JOptionPane.showMessageDialog(null,
Utils.getCountOfMinutesSinceAppStarted()
+ " minutes");
break;
case "toast":
Toaster t = new Toaster();
t.setToasterWidth(800);
@ -247,9 +272,17 @@ public class TimeCalcWindow {
t.setDisplayTime(60000 * 5);
t.setToasterColor(Color.GRAY);
Font font = new Font("sans", Font.PLAIN, 12);
t.setToasterMessageFont(font);t.setDisplayTime(5000); t.showToaster(commands.substring(6));break;
case "toasts": Utils.toastsAreEnabled.set(commandsAsArray[1].equals("1"));break;
default: JOptionPane.showMessageDialog(null, "Unknown command: " + commandsAsArray[0]);
t.setToasterMessageFont(font);
t.setDisplayTime(5000);
t.showToaster(commands.substring(6));
break;
case "toasts":
Utils.toastsAreEnabled
.set(commandsAsArray[1].equals("1"));
break;
default:
JOptionPane.showMessageDialog(null,
"Unknown command: " + commandsAsArray[0]);
}
});
@ -273,13 +306,15 @@ public class TimeCalcWindow {
ProgressSquare progressSquare = new ProgressSquare();
progressSquare
.setBounds(MARGIN + analogClock.getWidth() + MARGIN, MARGIN, 200);
.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);
.setBounds(
MARGIN + progressSquare.getBounds().x + progressSquare
.getWidth() + MARGIN, MARGIN, 80);
window.add(progressCircle);
Battery batteryForDay = new Battery();
@ -289,47 +324,59 @@ public class TimeCalcWindow {
window.add(batteryForDay);
Battery batteryForWeek = new Battery();
batteryForWeek.setBounds(batteryForDay.getBounds().x + batteryForDay.getWidth(),
batteryForWeek.setBounds(
batteryForDay.getBounds().x + batteryForDay.getWidth(),
batteryForDay.getY(), 90, 140);
window.add(batteryForWeek);
Calendar calNow = Calendar.getInstance();
calNow.setTime(new Date());
LocalDate ld = LocalDate.of(calNow.get(Calendar.YEAR),calNow.get(Calendar.MONTH) + 1,1);
LocalDate ld = LocalDate
.of(calNow.get(Calendar.YEAR), calNow.get(Calendar.MONTH) + 1,
1);
int currentDayOfMonth = calNow.get(Calendar.DAY_OF_MONTH);
int workDaysDone = 0;
int workDaysTodo = 0;
int workDaysTotal;
for(int dayOfMonth=1; dayOfMonth <= calNow.getActualMaximum(Calendar.DAY_OF_MONTH); dayOfMonth++) {
DayOfWeek dayOfWeek = LocalDate.of(calNow.get(Calendar.YEAR), calNow.get(Calendar.MONTH) + 1, dayOfMonth).getDayOfWeek();
boolean weekend = dayOfWeek.toString().equals("SATURDAY") || dayOfWeek.toString().equals("SUNDAY");
if(dayOfMonth < currentDayOfMonth && !weekend) {
for (int dayOfMonth = 1;
dayOfMonth <= calNow.getActualMaximum(Calendar.DAY_OF_MONTH);
dayOfMonth++) {
DayOfWeek dayOfWeek = LocalDate.of(calNow.get(Calendar.YEAR),
calNow.get(Calendar.MONTH) + 1, dayOfMonth).getDayOfWeek();
boolean weekend =
dayOfWeek.toString().equals("SATURDAY") || dayOfWeek
.toString().equals("SUNDAY");
if (dayOfMonth < currentDayOfMonth && !weekend) {
++workDaysDone;
}
if(dayOfMonth > currentDayOfMonth && !weekend) {
if (dayOfMonth > currentDayOfMonth && !weekend) {
++workDaysTodo;
}
}
String currentDayOfWeekAsString = LocalDate.of(calNow.get(Calendar.YEAR), calNow.get(Calendar.MONTH) + 1, currentDayOfMonth).getDayOfWeek().toString();
boolean nowIsWeekend = currentDayOfWeekAsString.equals("SATURDAY") || currentDayOfWeekAsString.equals("SUNDAY");
String currentDayOfWeekAsString = LocalDate
.of(calNow.get(Calendar.YEAR), calNow.get(Calendar.MONTH) + 1,
currentDayOfMonth).getDayOfWeek().toString();
boolean nowIsWeekend = currentDayOfWeekAsString.equals("SATURDAY")
|| currentDayOfWeekAsString.equals("SUNDAY");
workDaysTotal = workDaysDone + (nowIsWeekend ? 0 : 1) + workDaysTodo;
// System.out.println("workDaysDone" + workDaysDone);
// System.out.println("workDaysTodo" + workDaysTodo);
// System.out.println("currentDayOfMonth" + currentDayOfMonth);
// System.out.println("workDaysDone" + workDaysDone);
// System.out.println("workDaysTodo" + workDaysTodo);
// System.out.println("currentDayOfMonth" + currentDayOfMonth);
Battery batteryForMonth = new Battery();
batteryForMonth.setBounds(batteryForDay.getBounds().x + batteryForDay.getWidth(),
batteryForDay.getY() + batteryForWeek.getHeight() + MARGIN, 90, 140);
batteryForMonth.setBounds(
batteryForDay.getBounds().x + batteryForDay.getWidth(),
batteryForDay.getY() + batteryForWeek.getHeight() + MARGIN, 90,
140);
window.add(batteryForMonth);
Battery batteryForHour = new Battery();
batteryForHour.setBounds(batteryForMonth.getBounds().x,
batteryForMonth.getY() + batteryForMonth.getHeight() + MARGIN, 90, 140);
batteryForMonth.getY() + batteryForMonth.getHeight() + MARGIN,
90, 140);
window.add(batteryForHour);
Rectangle hourRectangle = batteryForHour.getBounds();
Rectangle dayRectangle = batteryForDay.getBounds();
@ -349,13 +396,13 @@ public class TimeCalcWindow {
break;
}
if(Math.random() > 0.9) {
if(FOCUS_TXT.exists()) {
if (Math.random() > 0.9) {
if (FOCUS_TXT.exists()) {
window.requestFocus();
FOCUS_TXT.delete();
}
}
if(Utils.highlighted.get()) {
if (Utils.highlighted.get()) {
Utils.ultraLight.set(false);
}
@ -367,7 +414,9 @@ public class TimeCalcWindow {
batteryForWeek.setVisible(!Utils.everythingHidden.get());
batteryForMonth.setVisible(!Utils.everythingHidden.get());
batteryForHour.setVisible(!Utils.everythingHidden.get());
jokeButton.setVisible(!TimeCalcConf.getInstance().isJokeVisible()? false : !Utils.everythingHidden.get());
jokeButton.setVisible(
TimeCalcConf.getInstance().isJokeVisible()
&& !Utils.everythingHidden.get());
focusButton.setVisible(!Utils.everythingHidden.get());
commandButton.setVisible(!Utils.everythingHidden.get());
@ -376,7 +425,8 @@ public class TimeCalcWindow {
window.setTitle(Utils.everythingHidden.get() ? "" : windowTitle);
sb = new StringBuilder();
LocalDateTime now = LocalDateTime.now();
String nowString = DateFormats.DATE_TIME_FORMATTER_HHmmssSSS.format(now);
String nowString =
DateFormats.DATE_TIME_FORMATTER_HHmmssSSS.format(now);
// if (alreadyShownTimes.contains(nowString)) {
// //nothing to do
// try {
@ -426,30 +476,40 @@ public class TimeCalcWindow {
int weekDayWhenMondayIsOne = calNow.get(Calendar.DAY_OF_WEEK) - 1;
batteryForWeek.setDonePercent((weekDayWhenMondayIsOne == 0
|| weekDayWhenMondayIsOne == 6) ?
|| weekDayWhenMondayIsOne == 6) ?
100 : ((weekDayWhenMondayIsOne - 1) * 0.20 + done * 0.20));
batteryForWeek.setLabel(nowIsWeekend ? "5/5" : (weekDayWhenMondayIsOne + "/5"));
batteryForWeek.setLabel(
nowIsWeekend ? "5/5" : (weekDayWhenMondayIsOne + "/5"));
batteryForMonth.setDonePercent(weekDayWhenMondayIsOne == 0
|| weekDayWhenMondayIsOne == 6 ? workDaysDone/workDaysTotal : (workDaysDone + done) / workDaysTotal);
batteryForMonth.setLabel((nowIsWeekend ? workDaysDone : workDaysDone + 1) + "/" + (workDaysTotal));
|| weekDayWhenMondayIsOne == 6 ?
workDaysDone / workDaysTotal :
(workDaysDone + done) / workDaysTotal);
batteryForMonth.setLabel(
(nowIsWeekend ? workDaysDone : workDaysDone + 1) + "/"
+ (workDaysTotal));
double minutesRemainsD = (double) minuteRemains;
double secondsRemainsD = (double) secondsRemains;
double millisecondsRemainsD = (double) millisecondsRemains;
double minutesRemainsD = minuteRemains;
double secondsRemainsD = secondsRemains;
double millisecondsRemainsD = millisecondsRemains;
minutesRemainsD = minutesRemainsD + secondsRemainsD / 60d;
minutesRemainsD = minutesRemainsD + millisecondsRemainsD / 1000d / 60d;
if(secondsRemainsD > 0) {
minutesRemainsD =
minutesRemainsD + millisecondsRemainsD / 1000d / 60d;
if (secondsRemainsD > 0) {
minutesRemainsD = minutesRemainsD - 1d;
}
if(millisecondsRemainsD > 0) {
minutesRemainsD = minutesRemainsD - 1d/1000d;
if (millisecondsRemainsD > 0) {
minutesRemainsD = minutesRemainsD - 1d / 1000d;
}
batteryForHour.setDonePercent(done >= 1 ? 1 :(1 - ((minutesRemainsD%60d)/60d)));
if(!nowIsWeekend) {
int hoursForLabel = (minuteRemains == 0 ? minuteRemains / 60 + 1 : minuteRemains/ 60);
batteryForHour.setLabel( ((totalMinutes / 60) - hoursForLabel) + "/" + (totalMinutes / 60));
batteryForHour.setDonePercent(
done >= 1 ? 1 : (1 - ((minutesRemainsD % 60d) / 60d)));
if (!nowIsWeekend) {
int hoursForLabel =
(minuteRemains == 0 ? minuteRemains / 60 + 1 :
minuteRemains / 60);
batteryForHour.setLabel(
((totalMinutes / 60) - hoursForLabel) + "/" + (
totalMinutes / 60));
}
int totalSecondsRemains =
@ -515,16 +575,14 @@ public class TimeCalcWindow {
}
text.setForeground(
Utils.highlighted.get() || text.getClientProperty("mouseEntered").equals("true") ? Color.BLACK : Color.LIGHT_GRAY);
Utils.highlighted.get() || text
.getClientProperty("mouseEntered").equals("true") ?
Color.BLACK : Color.LIGHT_GRAY);
}
window.setVisible(false);
window.dispose();
}
private String createWindowTitle() {
return "Time Calc " + Utils.getVersion();
}
private static final String createSpaces(int spaceCount) {
return create(spaceCount, ' ');
}
@ -537,6 +595,10 @@ public class TimeCalcWindow {
return sb.toString();
}
private String createWindowTitle() {
return "Time Calc " + Utils.getVersion();
}
private void printPercentToAscii(double percent,
String msg, StringBuilder sb) {
NumberFormat formatter = new DecimalFormat("#00.00");
@ -582,7 +644,7 @@ public class TimeCalcWindow {
int spacesTotal = 48;
int spacesDone = (int) (percent * spacesTotal);
if(spacesDone > spacesTotal) {
if (spacesDone > spacesTotal) {
spacesDone = spacesTotal;
}
int spacesTodo = spacesTotal - (spacesDone < 0 ? 0 : spacesDone);
@ -608,7 +670,8 @@ public class TimeCalcWindow {
"| |") + /*WALL +*/ NEW_LINE +
"================================================================"
+ NEW_LINE + "Steps: " + formatter3
.format(percent * ((double) spacesTotal)) + "/" + spacesTotal
.format(percent * ((double) spacesTotal)) + "/"
+ spacesTotal
);
}

View File

@ -7,9 +7,10 @@ import java.time.format.DateTimeFormatter;
* @since 21.02.2024
*/
public class DateFormats {
public final static DateTimeFormatter DATE_TIME_FORMATTER_HHmmssSSS =
DateTimeFormatter.ofPattern("HH:mm:ss:SSS");
private DateFormats() {
//Not meant to be instantiated.
}
public final static DateTimeFormatter DATE_TIME_FORMATTER_HHmmssSSS =
DateTimeFormatter.ofPattern("HH:mm:ss:SSS");
}

View File

@ -7,11 +7,11 @@ import java.io.File;
* @since 21.02.2024
*/
public class FileConstants {
private FileConstants() {
//Not meant to be instantiated.
}
public static final File STARTTIME_TXT = new File("starttime.txt");
public static final File OVERTIME_TXT = new File("overtime.txt");
public static final File TEST_TXT = new File("test.txt");
public static final File FOCUS_TXT = new File("focus.txt");
private FileConstants() {
//Not meant to be instantiated.
}
}

View File

@ -63,7 +63,7 @@ public class Jokes {
}
public static void showRandom() {
if(!TimeCalcConf.getInstance().isJokeVisible()) {
if (!TimeCalcConf.getInstance().isJokeVisible()) {
//nothing to do
return;
}

View File

@ -18,25 +18,28 @@ import java.util.jar.Manifest;
* @since 15.02.2024
*/
public class Utils {
private static long startNanoTime;
public static final BooleanHolder highlighted = new BooleanHolder();
public static final BooleanHolder ultraLight = new BooleanHolder();
public static final BooleanHolder everythingHidden = new BooleanHolder();
public static final BooleanHolder toastsAreEnabled = new BooleanHolder(true);
public static final Color ULTRA_LIGHT_GRAY = new Color(216,216,216);
public static final BooleanHolder toastsAreEnabled =
new BooleanHolder(true);
public static final Color ULTRA_LIGHT_GRAY = new Color(216, 216, 216);
/**
* Count of bytes per one kilobyte.
*/
private static final int COUNT_OF_BYTES_PER_ONE_KILOBYTE = 1024;
private static long startNanoTime;
private Utils() {
//Not meant to be instantiated.
}
public static void startApp() {
if(startNanoTime == 0) {
if (startNanoTime == 0) {
throw new TimeCalcException("App is already started.");
}
startNanoTime = System.nanoTime();
}
private Utils() {
//Not meant to be instantiated.
}
/**
* Writes text to a file.
@ -89,11 +92,12 @@ public class Utils {
}
public static int getCountOfMinutesSinceAppStarted() {
return ((int)((System.nanoTime() - startNanoTime) / 1000000000 / 60));
return ((int) ((System.nanoTime() - startNanoTime) / 1000000000 / 60));
}
/**
* Returns version of "Time Calc" from jar file.
*
* @return version
*/
public static String getVersion() {
@ -103,6 +107,7 @@ public class Utils {
/**
* Returns build date of "Time Calc" from jar file.
*
* @return build date
*/
public static String getBuildDate() {
@ -112,8 +117,9 @@ public class Utils {
if (!classPath.startsWith("jar")) {
return null;
}
String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1)
+ "/META-INF/MANIFEST.MF";
String manifestPath =
classPath.substring(0, classPath.lastIndexOf("!") + 1)
+ "/META-INF/MANIFEST.MF";
Manifest manifest;
try {
manifest = new Manifest(new URL(manifestPath).openStream());