time-calc/src/main/java/rvc/timecalc/TimeCalcWindow.java

585 lines
69 KiB
Java
Raw Normal View History

2024-01-14 14:27:59 +00:00
package rvc.timecalc;
2024-01-14 16:01:43 +00:00
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
2024-01-14 14:27:59 +00:00
import javax.swing.JButton;
import javax.swing.JFrame;
2024-01-28 17:08:13 +00:00
import javax.swing.JOptionPane;
2024-01-14 14:27:59 +00:00
import javax.swing.JTextPane;
import java.awt.Color;
import java.awt.Font;
2024-01-03 20:11:31 +00:00
import java.awt.Rectangle;
2024-01-28 14:57:31 +00:00
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
2024-01-28 14:30:03 +00:00
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
2024-01-14 16:01:43 +00:00
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
2024-01-03 19:38:45 +00:00
import java.io.File;
2024-01-14 14:27:59 +00:00
import java.text.DecimalFormat;
import java.text.NumberFormat;
2024-01-28 15:21:23 +00:00
import java.time.DayOfWeek;
import java.time.LocalDate;
2024-01-14 14:27:59 +00:00
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
2024-01-14 16:01:43 +00:00
import java.util.Base64;
2024-01-27 17:41:31 +00:00
import java.util.Calendar;
import java.util.Date;
2024-01-14 14:27:59 +00:00
import java.util.HashSet;
import java.util.Set;
/**
2024-01-20 17:52:25 +00:00
* @author pc00289
2024-01-14 14:27:59 +00:00
* @since 08.02.2024
*/
2024-01-20 17:52:25 +00:00
public class TimeCalcWindow {
2024-01-21 09:14:47 +00:00
public static final String WALL = "||";
2024-01-14 14:27:59 +00:00
private static final String DEFAULT_OVERTIME = "0:00";
private static final int WORKING_HOURS_LENGTH = 8;
private static final int WORKING_MINUTES_LENGTH = 30;
private static final String NEW_LINE = "\n";
2024-01-21 09:14:47 +00:00
private final static DateTimeFormatter DATE_TIME_FORMATTER =
DateTimeFormatter.ofPattern("HH:mm:ss:SSS");
2024-01-14 14:27:59 +00:00
private final String startTime;
2024-01-28 14:17:30 +00:00
private String overTime;
2024-01-14 14:27:59 +00:00
private final int startHour;
private final int startMinute;
private final int overtimeHour;
private final int overtimeMinute;
private final int totalMinutes;
private final Set<String> alreadyShownTimes = new HashSet<>();
2024-01-14 16:01:43 +00:00
private final Set<Integer> alreadyShownPercents = new HashSet<>();
2024-01-21 09:14:47 +00:00
private int endHour;
private int endMinute;
2024-01-14 14:27:59 +00:00
private boolean stopBeforeEnd = false;
2024-01-20 18:23:40 +00:00
private boolean vtipyShown = false;
2024-01-14 14:27:59 +00:00
2024-01-20 17:52:25 +00:00
public TimeCalcWindow(String startTimeIn, String overTimeIn) {
2024-01-28 17:31:24 +00:00
Utils.everythingHidden.set(TimeCalcConf.getInstance().isEverythingHidden());
Utils.toastsAreEnabled.set(TimeCalcConf.getInstance().areToastsEnabled());
2024-01-28 18:46:19 +00:00
2024-01-14 14:27:59 +00:00
this.startTime = startTimeIn;
2024-01-21 09:14:47 +00:00
this.overTime = (overTimeIn == null || overTimeIn.isEmpty()) ?
DEFAULT_OVERTIME : overTimeIn;
2024-01-14 14:27:59 +00:00
this.startHour = Integer.valueOf(startTime.split(":")[0]);
this.startMinute = Integer.valueOf(startTime.split(":")[1]);
2024-01-28 14:17:30 +00:00
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]);
2024-01-14 14:27:59 +00:00
2024-01-28 14:17:30 +00:00
this.endHour = startHour + WORKING_HOURS_LENGTH + overtimeHour;
this.endMinute = startMinute + WORKING_MINUTES_LENGTH + overtimeMinute;
2024-01-14 14:27:59 +00:00
while (endMinute >= 60) {
endMinute = endMinute - 60;
endHour = endHour + 1;
}
2024-01-21 09:14:47 +00:00
this.totalMinutes =
(endHour * 60 + endMinute) - (startHour * 60 + startMinute);
2024-01-20 16:43:32 +00:00
int totalSeconds = totalMinutes * 60;
2024-01-20 16:58:32 +00:00
int totalMilliseconds = totalSeconds * 1000;
2024-01-14 14:27:59 +00:00
2024-01-27 14:07:04 +00:00
NumberFormat formatter5 = new DecimalFormat("#0.00000");
NumberFormat formatter3 = new DecimalFormat("#0.000");
2024-01-14 14:27:59 +00:00
2024-01-21 09:14:47 +00:00
JFrame window = new JFrame();
2024-01-14 14:27:59 +00:00
2024-01-28 18:43:17 +00:00
JButton focusButton = new JButton("F");
2024-01-28 17:08:13 +00:00
JButton commandButton = new JButton("Command");
2024-01-27 20:28:21 +00:00
JButton weatherButton = new JButton("Weather");
2024-01-21 12:33:07 +00:00
JButton jokeButton = new JButton("Joke");
2024-01-21 09:14:47 +00:00
JButton restartButton = new JButton("Restart");
JButton exitButton = new JButton("Exit");
2024-01-14 14:27:59 +00:00
2024-01-27 20:28:21 +00:00
//window.add(weatherButton);
2024-01-28 17:08:13 +00:00
window.add(commandButton);
2024-02-03 20:08:12 +00:00
window.add(focusButton);
2024-01-27 21:09:21 +00:00
2024-01-21 12:33:07 +00:00
window.add(jokeButton);
2024-01-14 14:27:59 +00:00
window.add(restartButton);
window.add(exitButton);
2024-01-28 14:57:31 +00:00
window.setFocusable(true);
window.addKeyListener(new KeyAdapter() {
// Key Pressed method
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_UP){
2024-01-28 17:31:24 +00:00
Utils.everythingHidden.set(false);
2024-01-28 14:57:31 +00:00
}
if(e.getKeyCode() == KeyEvent.VK_DOWN){
2024-01-28 17:31:24 +00:00
Utils.everythingHidden.set(true);
2024-01-28 14:57:31 +00:00
}
2024-01-28 15:48:24 +00:00
if(e.getKeyCode() == KeyEvent.VK_G){
Utils.ultraLight.flip();
}
2024-01-28 16:13:44 +00:00
if(e.getKeyCode() == KeyEvent.VK_C){
Utils.highlighted.flip();
}
if(e.getKeyCode() == KeyEvent.VK_V){
2024-01-28 17:31:24 +00:00
Utils.everythingHidden.flip();
2024-01-28 16:13:44 +00:00
}
2024-01-28 17:08:13 +00:00
if(e.getKeyCode() == KeyEvent.VK_R){
commandButton.doClick();
}
2024-01-28 17:31:24 +00:00
if(e.getKeyCode() == KeyEvent.VK_T){
Utils.toastsAreEnabled.flip();
}
2024-01-28 16:13:44 +00:00
2024-01-28 14:57:31 +00:00
window.repaint();
}
});
2024-01-21 09:14:47 +00:00
JTextPane text = new JTextPane();
2024-01-28 15:21:23 +00:00
text.setBounds(10, 10 + 210 + 10, 500, 250);
2024-01-14 14:27:59 +00:00
text.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
text.setForeground(Color.GRAY);
2024-01-21 09:14:47 +00:00
text.setBackground(new Color(238, 238, 238));
2024-01-28 14:30:03 +00:00
text.putClientProperty("mouseEntered", "false");
2024-01-28 15:09:21 +00:00
text.setFocusable(false);
2024-01-28 14:30:03 +00:00
text.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
Utils.highlighted.flip();
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
text.putClientProperty("mouseEntered", "true");
}
@Override
public void mouseExited(MouseEvent e) {
text.putClientProperty("mouseEntered", "false");
}
});
2024-01-14 14:27:59 +00:00
window.add(text);
2024-01-27 23:41:48 +00:00
weatherButton
.setBounds(20, text.getY() + text.getHeight() + 10, 100, 30);
2024-01-28 17:08:13 +00:00
commandButton.setBounds(20, text.getY() + text.getHeight() + 10, 100, 30);
2024-01-28 18:43:17 +00:00
2024-01-27 20:28:21 +00:00
jokeButton.setBounds(140, text.getY() + text.getHeight() + 10, 100, 30);
2024-01-27 23:41:48 +00:00
restartButton
.setBounds(280, text.getY() + text.getHeight() + 10, 100, 30);
2024-01-21 11:15:46 +00:00
exitButton.setBounds(390, text.getY() + text.getHeight() + 10, 100, 30);
2024-01-14 14:27:59 +00:00
2024-02-03 23:15:17 +00:00
focusButton.setBounds(exitButton.getX() + 10 + 10 + 10 + exitButton.getWidth() + 20, 10, 60, 30);
2024-01-28 18:43:17 +00:00
2024-01-27 17:41:31 +00:00
window.setSize(520 + 20 + 100, 580);
2024-01-14 14:27:59 +00:00
window.setLayout(null);
window.setVisible(true);
window.setTitle("Time Calc");
window.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
window.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
2024-01-27 23:41:48 +00:00
weatherButton
.addActionListener(e -> new WeatherWindow().setVisible(true));
2024-01-28 17:08:13 +00:00
commandButton
.addActionListener(e ->
{
String commands = (String) JOptionPane.showInputDialog(
null,
"Run a command:",
"Command launching",
JOptionPane.PLAIN_MESSAGE,
null,
null,
"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;
2024-01-28 18:12:19 +00:00
case "uptime": JOptionPane.showMessageDialog(null, ((int)((System.nanoTime() - Main.startNanoTime) / 1000000000 / 60)) + " minutes");break;
2024-01-28 17:31:24 +00:00
case "toast":
Toaster t = new Toaster();
t.setToasterWidth(800);
t.setToasterHeight(800);
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;
2024-01-28 17:08:13 +00:00
default: JOptionPane.showMessageDialog(null, "Unknown command: " + commandsAsArray[0]);
}
});
2024-01-28 18:43:17 +00:00
focusButton.addActionListener(e -> {
window.requestFocus();
});
2024-01-27 23:41:48 +00:00
jokeButton.addActionListener(e -> {
for (int i = 1; i <= 1; i++) {
2024-01-28 15:22:25 +00:00
Jokes.showRandom();
2024-01-27 23:41:48 +00:00
}
});
2024-01-14 14:27:59 +00:00
exitButton.addActionListener(e -> System.exit(0));
2024-01-21 09:14:47 +00:00
restartButton.addActionListener(e -> {
window.setVisible(false);
stopBeforeEnd = true;
});
2024-01-14 14:27:59 +00:00
2024-01-20 14:30:23 +00:00
AnalogClock analogClock = new AnalogClock();
2024-01-21 11:15:46 +00:00
analogClock.setBounds(10, 10, 200, 200);
2024-01-20 14:30:23 +00:00
window.add(analogClock);
2024-01-14 14:27:59 +00:00
2024-01-20 17:52:25 +00:00
ProgressSquare progressSquare = new ProgressSquare();
2024-01-27 23:41:48 +00:00
progressSquare
.setBounds(10 + analogClock.getWidth() + 10, 10, 200, 200);
2024-01-20 17:52:25 +00:00
window.add(progressSquare);
2024-01-27 16:07:03 +00:00
ProgressCircle progressCircle = new ProgressCircle();
progressCircle
2024-01-27 23:41:48 +00:00
.setBounds(10 + progressSquare.getBounds().x + progressSquare
.getWidth() + 10, 10, 80, 80);
2024-01-27 16:07:03 +00:00
window.add(progressCircle);
2024-01-03 20:11:31 +00:00
Battery batteryForDay = new Battery();
batteryForDay.setBounds(progressCircle.getBounds().x,
2024-01-27 23:41:48 +00:00
progressCircle.getY() + 10 + progressCircle.getHeight(), 90,
140);
2024-01-03 20:11:31 +00:00
window.add(batteryForDay);
2024-01-27 16:50:19 +00:00
2024-01-27 17:41:31 +00:00
Battery batteryForWeek = new Battery();
2024-01-03 20:11:31 +00:00
batteryForWeek.setBounds(batteryForDay.getBounds().x + batteryForDay.getWidth(),
batteryForDay.getY(), 90, 140);
2024-01-27 17:41:31 +00:00
window.add(batteryForWeek);
2024-01-28 15:21:23 +00:00
Calendar calNow = Calendar.getInstance();
calNow.setTime(new Date());
LocalDate ld = LocalDate.of(calNow.get(Calendar.YEAR),calNow.get(Calendar.MONTH) + 1,1);
2024-01-03 20:11:31 +00:00
2024-01-28 15:21:23 +00:00
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) {
++workDaysDone;
}
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");
workDaysTotal = workDaysDone + (nowIsWeekend ? 0 : 1) + workDaysTodo;
2024-01-28 15:22:25 +00:00
// System.out.println("workDaysDone" + workDaysDone);
// System.out.println("workDaysTodo" + workDaysTodo);
// System.out.println("currentDayOfMonth" + currentDayOfMonth);
2024-01-28 15:21:23 +00:00
Battery batteryForMonth = new Battery();
2024-01-03 20:11:31 +00:00
batteryForMonth.setBounds(batteryForDay.getBounds().x + batteryForDay.getWidth(),
batteryForDay.getY() + batteryForWeek.getHeight() + 10, 90, 140);
2024-01-28 15:21:23 +00:00
window.add(batteryForMonth);
2024-01-03 20:11:31 +00:00
Battery batteryForHour = new Battery();
batteryForHour.setBounds(batteryForMonth.getBounds().x,
batteryForMonth.getY() + batteryForMonth.getHeight() + 10, 90, 140);
window.add(batteryForHour);
Rectangle hourRectangle = batteryForHour.getBounds();
Rectangle dayRectangle = batteryForDay.getBounds();
Rectangle weekRectangle = batteryForWeek.getBounds();
Rectangle monthRectangle = batteryForMonth.getBounds();
batteryForHour.setBounds(dayRectangle);
batteryForDay.setBounds(weekRectangle);
batteryForWeek.setBounds(monthRectangle);
batteryForMonth.setBounds(hourRectangle);
2024-01-14 14:27:59 +00:00
StringBuilder sb = null;
2024-01-03 19:38:45 +00:00
File focusTxt = new File("focus.txt");
2024-01-14 14:27:59 +00:00
while (true) {
2024-01-21 09:14:47 +00:00
if (stopBeforeEnd) {
2024-01-14 14:27:59 +00:00
window.setVisible(false);
window.dispose();
break;
}
2024-01-28 15:48:24 +00:00
2024-01-03 19:38:45 +00:00
if(Math.random() > 0.9) {
if(focusTxt.exists()) {
window.requestFocus();
focusTxt.delete();
}
}
2024-01-28 18:46:19 +00:00
if(Utils.highlighted.get()) {
Utils.ultraLight.set(false);
}
2024-01-28 17:31:24 +00:00
text.setVisible(!Utils.everythingHidden.get());
progressSquare.setVisible(!Utils.everythingHidden.get());
progressCircle.setVisible(!Utils.everythingHidden.get());
analogClock.setVisible(!Utils.everythingHidden.get());
2024-01-03 20:11:31 +00:00
batteryForDay.setVisible(!Utils.everythingHidden.get());
2024-01-28 17:31:24 +00:00
batteryForWeek.setVisible(!Utils.everythingHidden.get());
batteryForMonth.setVisible(!Utils.everythingHidden.get());
2024-01-03 20:11:31 +00:00
batteryForHour.setVisible(!Utils.everythingHidden.get());
2024-01-28 17:31:24 +00:00
jokeButton.setVisible(!TimeCalcConf.getInstance().isJokeVisible()? false : !Utils.everythingHidden.get());
2024-01-28 18:43:17 +00:00
focusButton.setVisible(!Utils.everythingHidden.get());
2024-01-28 17:31:24 +00:00
commandButton.setVisible(!Utils.everythingHidden.get());
restartButton.setVisible(!Utils.everythingHidden.get());
exitButton.setVisible(!Utils.everythingHidden.get());
window.setTitle(Utils.everythingHidden.get() ? "" : "Time Calc");
2024-01-14 14:27:59 +00:00
sb = new StringBuilder();
LocalDateTime now = LocalDateTime.now();
String nowString = DATE_TIME_FORMATTER.format(now);
2024-01-21 09:14:47 +00:00
// if (alreadyShownTimes.contains(nowString)) {
// //nothing to do
// try {
// Thread.sleep(100);
// } catch (InterruptedException e) {
//
// }
// continue;
// } else {
// alreadyShownTimes.add(nowString);
// }
2024-01-14 14:27:59 +00:00
int hourNow = Integer.parseInt(nowString.split(":")[0]);
int minuteNow = Integer.parseInt(nowString.split(":")[1]);
2024-01-20 16:43:32 +00:00
int secondNow = Integer.parseInt(nowString.split(":")[2]);
2024-01-20 16:58:32 +00:00
int millisecondNow = Integer.parseInt(nowString.split(":")[3]);
2024-01-14 14:27:59 +00:00
int hourRemains = endHour - hourNow;
int minuteRemains = endMinute - minuteNow;
if (minuteRemains < 0) {
minuteRemains = minuteRemains + 60;
hourRemains = hourRemains - 1;
}
2024-01-20 16:43:32 +00:00
int secondsRemains = 60 - secondNow;
2024-01-20 16:58:32 +00:00
int millisecondsRemains = 1000 - millisecondNow;
2024-01-20 16:43:32 +00:00
2024-01-28 14:17:30 +00:00
int hourDone = WORKING_HOURS_LENGTH + overtimeHour - hourRemains;
int minutesDone = 30 + overtimeMinute - minuteRemains;
2024-01-20 16:43:32 +00:00
int secondsDone = secondNow;
2024-01-20 16:58:32 +00:00
int millisecondsDone = millisecondNow;
2024-01-20 16:43:32 +00:00
2024-01-14 14:27:59 +00:00
int totalMinutesDone = hourDone * 60 + minutesDone;
2024-01-20 16:43:32 +00:00
int totalSecondsDone = totalMinutesDone * 60 + secondsDone;
2024-01-21 09:14:47 +00:00
int totalMillisecondsDone =
totalSecondsDone * 1000 + millisecondsDone;
// System.out.println(hourNow + " " + minuteNow + " " + secondNow + " " + millisecondNow);
// System.out.println(hourRemains + " " + minuteRemains + " " + secondsRemains + " " + millisecondsRemains);
// System.out.println(hourDone + " " + minutesDone + " " + secondsDone + " " + totalMillisecondsDone + "\n");
// System.out.println("totalSecondsDone=" + totalSecondsDone);
// System.out.println("totalMillisecondsDone=" + totalMillisecondsDone);
// double done = ((double)totalMinutesDone)/((double)totalMinutes);
double done = ((double) totalMillisecondsDone)
/ ((double) totalMilliseconds);
progressSquare.setDonePercent(done);
2024-01-27 16:07:03 +00:00
progressCircle.setDonePercent(done);
2024-01-03 20:11:31 +00:00
batteryForDay.setDonePercent(done);
2024-01-21 09:14:47 +00:00
2024-01-28 15:21:23 +00:00
int weekDayWhenMondayIsOne = calNow.get(Calendar.DAY_OF_WEEK) - 1;
2024-01-27 23:41:48 +00:00
batteryForWeek.setDonePercent((weekDayWhenMondayIsOne == 0
2024-01-28 14:17:30 +00:00
|| weekDayWhenMondayIsOne == 6) ?
2024-01-27 23:41:48 +00:00
100 : ((weekDayWhenMondayIsOne - 1) * 0.20 + done * 0.20));
2024-02-03 22:07:51 +00:00
batteryForWeek.setLabel(nowIsWeekend ? "5/5" : (weekDayWhenMondayIsOne + "/5"));
2024-01-27 23:41:48 +00:00
2024-01-28 15:21:23 +00:00
batteryForMonth.setDonePercent(weekDayWhenMondayIsOne == 0
|| weekDayWhenMondayIsOne == 6 ? workDaysDone/workDaysTotal : (workDaysDone + done) / workDaysTotal);
2024-02-03 22:07:51 +00:00
batteryForMonth.setLabel((nowIsWeekend ? workDaysDone : workDaysDone + 1) + "/" + (workDaysTotal));
2024-01-28 15:21:23 +00:00
2024-01-03 20:11:31 +00:00
double minutesRemainsD = (double) minuteRemains;
double secondsRemainsD = (double) secondsRemains;
double millisecondsRemainsD = (double) millisecondsRemains;
minutesRemainsD = minutesRemainsD + secondsRemainsD / 60d;
minutesRemainsD = minutesRemainsD + millisecondsRemainsD / 1000d / 60d;
2024-02-03 20:39:20 +00:00
if(secondsRemainsD > 0) {
minutesRemainsD = minutesRemainsD - 1d;
}
if(millisecondsRemainsD > 0) {
minutesRemainsD = minutesRemainsD - 1d/1000d;
}
2024-02-03 22:31:23 +00:00
batteryForHour.setDonePercent(done >= 1 ? 1 :(1 - ((minutesRemainsD%60d)/60d)));
if(!nowIsWeekend) {
2024-02-03 22:07:51 +00:00
int hoursForLabel = (minuteRemains == 0 ? minuteRemains / 60 + 1 : minuteRemains/ 60);
batteryForHour.setLabel( ((totalMinutes / 60) - hoursForLabel) + "/" + (totalMinutes / 60));
2024-02-03 21:04:01 +00:00
}
2024-01-03 20:11:31 +00:00
2024-01-27 23:41:48 +00:00
int totalSecondsRemains =
(hourRemains * 60 * 60 + minuteRemains * 60
+ secondsRemains);
int totalMillisecondsRemains =
totalSecondsRemains * 1000 + millisecondsRemains;
double totalSecondsRemainsDouble =
((double) totalMillisecondsRemains) / 1000;
2024-01-27 14:07:04 +00:00
String msg = "Done=" + formatter5.format(done * 100) + "% Remains="
2024-01-21 09:14:47 +00:00
+ String.format("%02d", hourRemains) + ":" + String
2024-01-27 23:41:48 +00:00
.format("%02d", minuteRemains)
+ /*":" + String.format("%02d", secondsRemains)+ */ " ("
+ formatter3
2024-01-27 14:51:58 +00:00
.format(totalSecondsRemainsDouble - 60)
2024-01-27 14:07:04 +00:00
+ " s" + ")" + " End=" + String
2024-01-14 14:27:59 +00:00
.format("%02d", endHour) + ":" + String
.format("%02d", endMinute);
//if(System.getProperty("progress")!=null) {
2024-01-21 09:14:47 +00:00
printPercentToAscii(done, msg, sb);
// } else {
// sb.append(msg);
// }
if (hourRemains == 0 && minuteRemains == 1 && !vtipyShown) {
2024-01-20 18:23:40 +00:00
vtipyShown = true;
2024-01-28 15:22:25 +00:00
Jokes.showRandom();
2024-01-20 13:13:59 +00:00
}
2024-01-21 09:14:47 +00:00
if (hourRemains == 0 && minuteRemains <= 3) {
2024-01-27 19:40:45 +00:00
Utils.highlighted.set(true);
2024-01-20 16:13:23 +00:00
text.setForeground(Color.BLUE);
}
2024-01-21 09:14:47 +00:00
if (hourRemains <= 0 && minuteRemains <= 0) {
2024-01-14 14:27:59 +00:00
sb.append("\nCongratulation :-) It is the time to go home.");
2024-01-14 16:01:43 +00:00
Toaster toasterManager = new Toaster();
2024-01-14 18:06:23 +00:00
toasterManager.setDisplayTime(30000);
2024-01-21 09:14:47 +00:00
toasterManager.showToaster(
"Congratulation :-) It is the time to go home.");
2024-01-14 14:27:59 +00:00
//System.out.println(sb.toString());
text.setText(sb.toString());
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
2024-01-21 09:14:47 +00:00
while (!stopBeforeEnd) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
2024-01-14 14:27:59 +00:00
2024-01-21 09:14:47 +00:00
}
2024-01-14 14:27:59 +00:00
}
} else {
//System.out.println(sb.toString());
text.setText(sb.toString());
}
try {
2024-01-20 16:43:32 +00:00
Thread.sleep(100);
2024-01-14 14:27:59 +00:00
} catch (InterruptedException e) {
}
2024-01-27 13:40:23 +00:00
2024-01-27 23:41:48 +00:00
text.setForeground(
2024-01-28 14:30:03 +00:00
Utils.highlighted.get() || text.getClientProperty("mouseEntered").equals("true") ? Color.BLACK : Color.LIGHT_GRAY);
2024-01-14 14:27:59 +00:00
}
window.setVisible(false);
window.dispose();
}
2024-01-21 09:14:47 +00:00
private static final String createSpaces(int spaceCount) {
return create(spaceCount, ' ');
}
private static final String create(int count, char ch) {
StringBuilder sb = new StringBuilder();
for (int i = 1; i <= count; i++) {
sb.append(ch);
}
return sb.toString();
}
2024-01-14 16:01:43 +00:00
private void printPercentToAscii(double percent,
2024-01-14 14:27:59 +00:00
String msg, StringBuilder sb) {
NumberFormat formatter = new DecimalFormat("#00.00");
2024-01-14 16:01:43 +00:00
NumberFormat formatter2 = new DecimalFormat("##.##");
2024-01-14 14:27:59 +00:00
String s = formatter.format(percent * 100);
2024-01-21 09:14:47 +00:00
s = s.replace(",", "");
2024-01-14 14:27:59 +00:00
2024-01-21 09:14:47 +00:00
int percentInt = (int) (percent * 100);
if (!alreadyShownPercents.contains((int) (percent * 100))) {
alreadyShownPercents.add((int) (percent * 100));
2024-01-14 16:01:43 +00:00
Toaster toasterManager = new Toaster();
2024-01-27 16:50:19 +00:00
Font font = new Font("sans", Font.PLAIN, 16);
2024-01-14 16:25:05 +00:00
toasterManager.setToasterMessageFont(font);
2024-01-14 16:02:37 +00:00
toasterManager.setDisplayTime(10000);
2024-01-14 18:06:23 +00:00
toasterManager.setToasterWidth(600);
toasterManager.setToasterHeight(400);
2024-01-27 23:41:48 +00:00
toasterManager.setToasterColor(new Color(255, 255, 204));
2024-01-14 16:01:43 +00:00
Base64.Decoder base64Decoder = Base64.getDecoder();
2024-01-21 09:14:47 +00:00
byte[] btDataFile = base64Decoder
.decode("/9j/4AAQSkZJRgABAQEAYABgAAD/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAEAAAAAAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCADFARQDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD9/KKKKACivPfGX7U/w8+Hnxv8M/DfW/F+hab488Y2013ouhz3SreahFEQGZE6922g4L+X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AC5bj8Ll1XmlPEXUXCLlFWjzPmktI2216+V2fK4PmxFKVVRceVtWlo3Z2ul1T3XlqdrRQv3aK9ooK83+PHxD8Z+A9R8Knwv4Zsdc0281JY/EF3dXqWqaNYgb5LjLMuSFV8A8ZxkjofRZn2RsQMkAkV+cX/Bcn9sLWPDn7NNv4P0KWLSf+E01F7HUme5CXk1jGgaWGNF5KvIVWRgdojGw583FehkuVyzXM6GU058sq0rJ9ktW/krnVlmDWYZjQyqM+WdaVk/TVv5K58y/8FRP+Ciuk/tbfGK1g8E6fp9vpXg9Lmy07xT9lX+174TKYrkW1wR5lrazISjJGVM6cSEqQg+W/DdncW2p2v2Uva3Mbq8Lp8rRMOQw9CP6Vzuj7QffHpXffDZFvfFNr5nzc1/oFwzwxQyHCfVsCr0rO/NZu9vTVN3bvezbtZaH9rZDw3QybDfVcHFOk0+e6XM3ZLtqnrfmvbZaaH1d4U07WPjvqWnX+vfZ5ri0h8iJo4trbflzk98sC2fVj2wB794I/Zva0to7iGHbIgyrFQf6Vzf7LOlW7w2u5V28V9yfDLwpp9xo43bV+Xjiv59414ongJ/V6CtBbJbH4JnlTB5JhFk+WUI0sNFNKnFWik220l5tt+rZ8N/HT4FSazAz3kPmPHF5eSONuc4/U1nfsr/8ABQPWv2Q/FVl4X8bXl5qvw7mcQpPKWluPDwPAdDyzQD+KPnaBlOm1vq/9oPQLO3tpvL2tweRX5z/tZ6dCsN104B/rXp8K/VeJMJ/Z2YwvCW3eL7xfRr/h7o93hDC4HNcBHKcTT/dWtHvF94t6pr/h9D9Fv2Zv2rPHvxh/aJ8RaDq3hW1tPCtrbibTNUgkkit7uBJZIxdQNIgNzHOdhUqQqqoOTuyfaPiX8btH+HCiGZmutSkUGO0hILgerHoo+vJ7A1+ef/
.getBytes());
2024-01-14 16:01:43 +00:00
BufferedImage image = null;
try {
2024-01-21 09:14:47 +00:00
image = percentInt == 100 ?
ImageIO.read(new ByteArrayInputStream(btDataFile)) :
null;
2024-01-14 16:01:43 +00:00
} catch (Exception e) {
System.out.println(e);
}
2024-01-21 09:14:47 +00:00
if (image != null) {
// toasterManager.setToasterWidth(600);
// toasterManager.setToasterHeight(400);
toasterManager.showToaster(new ImageIcon(image),
"Progress: " + (percentInt) + "%");
2024-01-14 16:01:43 +00:00
} else {
2024-01-21 09:14:47 +00:00
toasterManager.showToaster("Progress: " + (percentInt) + "%");
2024-01-14 16:01:43 +00:00
}
}
2024-01-27 23:41:48 +00:00
sb.append("\n" + msg + "\n\n");
2024-01-14 14:27:59 +00:00
2024-02-03 22:31:23 +00:00
int spacesTotal = 48;
2024-01-27 14:07:04 +00:00
int spacesDone = (int) (percent * spacesTotal);
2024-02-03 23:15:17 +00:00
if(spacesDone > spacesTotal) {
spacesDone = spacesTotal;
}
2024-01-14 14:42:52 +00:00
int spacesTodo = spacesTotal - (spacesDone < 0 ? 0 : spacesDone);
2024-01-27 14:07:04 +00:00
2024-02-03 22:31:23 +00:00
sb.append("||" + createSpaces(spacesTotal + 6 - 2) + (spacesTodo == 0 ?
2024-01-27 23:41:48 +00:00
" \n" : "||======||\n"));
sb.append("||").append(createSpaces(spacesTotal + 4))
.append(spacesTodo == 0 ? "" : "| |").append("\n");
2024-01-21 09:23:30 +00:00
2024-01-27 14:02:25 +00:00
NumberFormat formatter3 = new DecimalFormat("#0.00000");
2024-01-14 14:27:59 +00:00
sb.append(
2024-01-21 09:14:47 +00:00
WALL + createSpaces(spacesDone) + " () " + createSpaces(
2024-01-27 23:41:48 +00:00
spacesTodo) + /*WALL +*/ (spacesTodo == 0 ?
" \\☼☼☼☼/ " :
2024-01-21 09:23:30 +00:00
"| _ |") + /*WALL +*/ NEW_LINE +
2024-01-21 09:14:47 +00:00
WALL + createSpaces(spacesDone) + "/||\\" + createSpaces(
2024-01-27 23:41:48 +00:00
spacesTodo) + /*WALL +*/ (spacesTodo == 0 ?
" ☼☼☼☼☼☼ " :
2024-01-21 09:23:30 +00:00
"| | |") + /*WALL +*/ NEW_LINE +
2024-01-21 09:14:47 +00:00
WALL + createSpaces(spacesDone) + " /\\ " + createSpaces(
2024-01-27 23:41:48 +00:00
spacesTodo) + /*WALL +*/ (spacesTodo == 0 ?
" /☼☼☼☼\\ " :
2024-01-21 09:23:30 +00:00
"| |") + /*WALL +*/ NEW_LINE +
2024-02-03 22:31:23 +00:00
"================================================================"
2024-01-27 23:41:48 +00:00
+ NEW_LINE + "Steps: " + formatter3
2024-02-03 22:31:23 +00:00
.format(percent * ((double) spacesTotal)) + "/" + spacesTotal
2024-01-14 14:27:59 +00:00
);
}
}