From ff5e9d4ccb92c4c5e431f95b41343c5dbd182c57 Mon Sep 17 00:00:00 2001 From: Robert Vokac Date: Sat, 27 Jan 2024 16:50:19 +0000 Subject: [PATCH] New improvements --- overtime.txt | 2 +- src/main/java/rvc/timecalc/Battery.java | 110 ++++++++++++++++++ .../java/rvc/timecalc/TimeCalcWindow.java | 11 +- starttime.txt | 2 +- 4 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 src/main/java/rvc/timecalc/Battery.java diff --git a/overtime.txt b/overtime.txt index bcb4bda..5b70e78 100644 --- a/overtime.txt +++ b/overtime.txt @@ -1 +1 @@ -0:00 \ No newline at end of file +0:09 \ No newline at end of file diff --git a/src/main/java/rvc/timecalc/Battery.java b/src/main/java/rvc/timecalc/Battery.java new file mode 100644 index 0000000..7e47e7b --- /dev/null +++ b/src/main/java/rvc/timecalc/Battery.java @@ -0,0 +1,110 @@ +package rvc.timecalc; + +import javax.swing.JPanel; +import javax.swing.Timer; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.io.IOException; + +public class Battery extends JPanel { + + private static final Color FOREGROUND_COLOR = new Color(220, 220, 220); + private static final Color BACKGROUND_COLOR = new Color(238, 238, 238); + public static final Color LOW = new Color(255, 102, 102); + 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); + private int height_ = 0; + private int square; + private double donePercent = 0; + + private boolean highlight = false; + private int width_; + + public void setHighlight(boolean highlight) { + this.highlight = highlight; + if(highlight && !Utils.highlightTxt.exists()) { + try { + Utils.highlightTxt.createNewFile(); + } catch (IOException ioException) { + System.out.println(ioException); + } + } + if(!highlight && Utils.highlightTxt.exists()) { + Utils.highlightTxt.delete(); + } + } + + public Battery() { + setPreferredSize(new Dimension(40, 100)); + setBackground(BACKGROUND_COLOR); + new Timer(1000, e -> repaint()).start(); + addMouseListener(new MouseListener() { + @Override + public void mouseClicked(MouseEvent e) { + highlight = !highlight; + if(highlight && !Utils.highlightTxt.exists()) { + try { + Utils.highlightTxt.createNewFile(); + } catch (IOException ioException) { + System.out.println(e); + } + } + if(!highlight && Utils.highlightTxt.exists()) { + Utils.highlightTxt.delete(); + } + } + + @Override + public void mousePressed(MouseEvent e) { + + } + + @Override + public void mouseReleased(MouseEvent e) { + + } + + @Override + public void mouseEntered(MouseEvent e) { + + } + + @Override + public void mouseExited(MouseEvent e) { + + } + }); + } + + public void setDonePercent(double donePercent) { + this.donePercent = donePercent; + } + + @Override + public void paintComponent(Graphics g) { + if (height_ == 0) { + this.height_ = Math.min(getWidth(), getHeight()); + this.width_= (int)(this.height_* 0.6); + } + super.paintComponent(g); + Graphics2D g2d = (Graphics2D) g; + g2d.setColor(FOREGROUND_COLOR); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + 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))); + 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); + + } + +} \ No newline at end of file diff --git a/src/main/java/rvc/timecalc/TimeCalcWindow.java b/src/main/java/rvc/timecalc/TimeCalcWindow.java index 6791203..13c5708 100644 --- a/src/main/java/rvc/timecalc/TimeCalcWindow.java +++ b/src/main/java/rvc/timecalc/TimeCalcWindow.java @@ -122,11 +122,17 @@ public class TimeCalcWindow { .setBounds(10 + progressSquare.getBounds().x + progressSquare.getWidth() + 10, 10, 80, 80); window.add(progressCircle); + Battery battery = new Battery(); + battery.setBounds(progressCircle.getBounds().x, progressCircle.getY() + 10 + progressCircle.getHeight(), 90, 140); + window.add(battery); + + if(Utils.highlightTxt.exists()) { analogClock.setHighlight(true); progressSquare.setHighlight(true); progressCircle.setHighlight(true); + battery.setHighlight(true); } StringBuilder sb = null; while (true) { @@ -183,6 +189,7 @@ public class TimeCalcWindow { / ((double) totalMilliseconds); progressSquare.setDonePercent(done); progressCircle.setDonePercent(done); + battery.setDonePercent(done); int totalSecondsRemains = (hourRemains * 60 * 60 + minuteRemains * 60 + secondsRemains); int totalMillisecondsRemains = totalSecondsRemains * 1000 + millisecondsRemains; @@ -273,12 +280,12 @@ public class TimeCalcWindow { if (!alreadyShownPercents.contains((int) (percent * 100))) { alreadyShownPercents.add((int) (percent * 100)); Toaster toasterManager = new Toaster(); - Font font = new Font("sans", Font.BOLD, 32); + Font font = new Font("sans", Font.PLAIN, 16); toasterManager.setToasterMessageFont(font); toasterManager.setDisplayTime(10000); toasterManager.setToasterWidth(600); toasterManager.setToasterHeight(400); - toasterManager.setToasterColor(new Color(255,255,102)); + toasterManager.setToasterColor(new Color(255,255,204)); Base64.Decoder base64Decoder = Base64.getDecoder(); byte[] btDataFile = base64Decoder diff --git a/starttime.txt b/starttime.txt index e84ee8f..1d467db 100644 --- a/starttime.txt +++ b/starttime.txt @@ -1 +1 @@ -7:00 \ No newline at end of file +6:39 \ No newline at end of file