From 477950eb4937a506b4d88844fc6bb2a0ad6e43d0 Mon Sep 17 00:00:00 2001 From: Robert Vokac Date: Sat, 27 Jan 2024 17:41:31 +0000 Subject: [PATCH] New improvements --- src/main/java/rvc/timecalc/Battery.java | 17 ++++++++++++++--- .../java/rvc/timecalc/ProgressSquare.java | 2 +- .../java/rvc/timecalc/TimeCalcWindow.java | 19 ++++++++++++++----- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/java/rvc/timecalc/Battery.java b/src/main/java/rvc/timecalc/Battery.java index 7e47e7b..4451bc9 100644 --- a/src/main/java/rvc/timecalc/Battery.java +++ b/src/main/java/rvc/timecalc/Battery.java @@ -19,6 +19,10 @@ public class Battery extends JPanel { public static final Color MEDIUM = new Color(255, 204, 153); public static final Color HIGH = new Color(204, 255, 204); public static final Color HIGHEST = new Color(153, 255, 153); + public static final Color LOW_HIGHLIGHTED = Color.red; + 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; private int height_ = 0; private int square; private double donePercent = 0; @@ -43,7 +47,7 @@ public class Battery extends JPanel { public Battery() { setPreferredSize(new Dimension(40, 100)); setBackground(BACKGROUND_COLOR); - new Timer(1000, e -> repaint()).start(); + new Timer(100, e -> repaint()).start(); addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { @@ -88,6 +92,8 @@ public class Battery extends JPanel { @Override public void paintComponent(Graphics g) { + if(Math.random() > 0.9) + {highlight = Utils.highlightTxt.exists();} if (height_ == 0) { this.height_ = Math.min(getWidth(), getHeight()); this.width_= (int)(this.height_* 0.6); @@ -99,8 +105,13 @@ public class Battery extends JPanel { RenderingHints.VALUE_ANTIALIAS_ON); g2d.fillRect(width_/4,0,width_, height_); - g2d.setColor(donePercent < 0.1 ? LOW : (donePercent < 0.75 ? - MEDIUM : (donePercent < 0.9 ? HIGH : HIGHEST))); + if(highlight) { + g2d.setColor(donePercent < 0.1 ? LOW_HIGHLIGHTED : (donePercent < 0.75 ? + MEDIUM_HIGHLIGHTED : (donePercent < 0.9 ? HIGH_HIGHLIGHTED : HIGHEST_HIGHLIGHTED))); + } else { + g2d.setColor(donePercent < 0.1 ? LOW : (donePercent < 0.75 ? + MEDIUM : (donePercent < 0.9 ? HIGH : HIGHEST))); + } g2d.fillRect(width_/4,height_ - (int)(height_ * donePercent),width_, (int)(height_ * donePercent)); g2d.setColor(Color.LIGHT_GRAY); g2d.drawString(String.valueOf((int)(donePercent * 100)) + "%",width_/2, height_/2); diff --git a/src/main/java/rvc/timecalc/ProgressSquare.java b/src/main/java/rvc/timecalc/ProgressSquare.java index 9a446ba..1198bcc 100644 --- a/src/main/java/rvc/timecalc/ProgressSquare.java +++ b/src/main/java/rvc/timecalc/ProgressSquare.java @@ -38,7 +38,7 @@ public class ProgressSquare extends JPanel { public ProgressSquare() { setPreferredSize(new Dimension(400, 400)); setBackground(BACKGROUND_COLOR); - new Timer(1000, e -> repaint()).start(); + new Timer(100, e -> repaint()).start(); addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { diff --git a/src/main/java/rvc/timecalc/TimeCalcWindow.java b/src/main/java/rvc/timecalc/TimeCalcWindow.java index 13c5708..a0e3a7f 100644 --- a/src/main/java/rvc/timecalc/TimeCalcWindow.java +++ b/src/main/java/rvc/timecalc/TimeCalcWindow.java @@ -14,6 +14,8 @@ import java.text.NumberFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Base64; +import java.util.Calendar; +import java.util.Date; import java.util.HashSet; import java.util.Set; @@ -74,8 +76,6 @@ public class TimeCalcWindow { JButton restartButton = new JButton("Restart"); JButton exitButton = new JButton("Exit"); - - window.add(jokeButton); window.add(restartButton); window.add(exitButton); @@ -89,7 +89,7 @@ public class TimeCalcWindow { restartButton.setBounds(280, text.getY() + text.getHeight() + 10, 100, 30); exitButton.setBounds(390, text.getY() + text.getHeight() + 10, 100, 30); - window.setSize(520 + 20, 580); + window.setSize(520 + 20 + 100, 580); window.setLayout(null); window.setVisible(true); window.setTitle("Time Calc"); @@ -113,8 +113,7 @@ public class TimeCalcWindow { window.add(analogClock); ProgressSquare progressSquare = new ProgressSquare(); - progressSquare - .setBounds(10 + analogClock.getWidth() + 10, 10, 200, 200); + progressSquare.setBounds(10 + analogClock.getWidth() + 10, 10, 200, 200); window.add(progressSquare); ProgressCircle progressCircle = new ProgressCircle(); @@ -126,6 +125,10 @@ public class TimeCalcWindow { battery.setBounds(progressCircle.getBounds().x, progressCircle.getY() + 10 + progressCircle.getHeight(), 90, 140); window.add(battery); + Battery batteryForWeek = new Battery(); + batteryForWeek.setBounds(battery.getBounds().x + battery.getWidth(), battery.getY(), 90, 140); + window.add(batteryForWeek); + if(Utils.highlightTxt.exists()) { @@ -133,6 +136,7 @@ public class TimeCalcWindow { progressSquare.setHighlight(true); progressCircle.setHighlight(true); battery.setHighlight(true); + batteryForWeek.setHighlight(true); } StringBuilder sb = null; while (true) { @@ -191,6 +195,11 @@ public class TimeCalcWindow { progressCircle.setDonePercent(done); battery.setDonePercent(done); + Calendar cal = Calendar.getInstance(); + cal.setTime(new Date()); + int weekDayWhenMondayIsOne = cal.get(Calendar.DAY_OF_WEEK) - 1; + batteryForWeek.setDonePercent((weekDayWhenMondayIsOne == 0 || weekDayWhenMondayIsOne == 6) ? 100 : ((weekDayWhenMondayIsOne - 1) * 0.20 + done * 0.20)); + int totalSecondsRemains = (hourRemains * 60 * 60 + minuteRemains * 60 + secondsRemains); int totalMillisecondsRemains = totalSecondsRemains * 1000 + millisecondsRemains; double totalSecondsRemainsDouble = ((double)totalMillisecondsRemains)/1000;