From 469c49f62c2c95063436a2a010ffa14ec20ffbe4 Mon Sep 17 00:00:00 2001 From: Robert Vokac Date: Sun, 28 Jan 2024 14:57:31 +0000 Subject: [PATCH] Added new improvements --- .gitignore | 1 + src/main/java/rvc/timecalc/AnalogClock.java | 14 +++-- src/main/java/rvc/timecalc/Battery.java | 3 +- src/main/java/rvc/timecalc/TimeCalcConf.java | 63 +++++++++++++++++++ .../java/rvc/timecalc/TimeCalcWindow.java | 26 ++++++++ src/main/java/rvc/timecalc/Vtipy.java | 4 ++ timecalc.conf | 4 ++ test.txt_ => timecalc.conf.template | 0 8 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 src/main/java/rvc/timecalc/TimeCalcConf.java create mode 100644 timecalc.conf rename test.txt_ => timecalc.conf.template (100%) diff --git a/.gitignore b/.gitignore index b751fe2..4f89d8d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ proxy.txt out.txt pocasi.txt test.txt +timecalc.conf diff --git a/src/main/java/rvc/timecalc/AnalogClock.java b/src/main/java/rvc/timecalc/AnalogClock.java index a241d2b..3fd1b86 100644 --- a/src/main/java/rvc/timecalc/AnalogClock.java +++ b/src/main/java/rvc/timecalc/AnalogClock.java @@ -12,6 +12,7 @@ import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +import java.sql.Time; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -28,7 +29,7 @@ public class AnalogClock extends JPanel { private boolean coloured = false; private boolean mouseOver = false; private int side; - private final Color[] colors = Utils.getRandomColors(); + private Color[] colors = Utils.getRandomColors(); public AnalogClock() { setPreferredSize(new Dimension(400, 300)); @@ -122,14 +123,14 @@ public class AnalogClock extends JPanel { drawClockFace(g2d, centerX, centerY, side / 2 - 40); drawHand(g2d, side / 2 - 10, second / 60.0, 0.5f, Color.RED); - drawHand(g2d, (side / 2 - 10) / 4, + 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); - drawHand(g2d, (side / 2 - 20) / 4, + 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); @@ -138,7 +139,7 @@ public class AnalogClock extends JPanel { drawHand(g2d, side / 2 - 40, hours, 4.0f, Color.BLACK); - drawHand(g2d, (side / 2 - 40) / 4, hours + hours > 0.5 ? hours - 0.5 : + 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); @@ -170,7 +171,7 @@ public class AnalogClock extends JPanel { // g2d.drawOval(3, 3, centerX * 2 - 6, centerY * 2 - 6); // g2d.drawOval(4, 4, centerX * 2 - 8, centerY * 2 - 8); - // if(highlight && Math.random()>0.9) {colors = getRandomColors();} + if(Utils.highlighted.get() && TimeCalcConf.getInstance().isClockColorful() && Math.random()>0.9) {colors = Utils.getRandomColors();} if (Utils.highlighted.get() && coloured) { for (int i = 0; i < 12; i++) { //if(Math.random() > 0.75) { @@ -206,7 +207,8 @@ public class AnalogClock extends JPanel { int seconds = Integer.valueOf(now.split(":")[2]); - //if(Utils.highlighted.get() && coloured && (seconds <= 5 || seconds >= 55)) {g2d.setColor(colors[i - 1]);} + if (Utils.highlighted.get() && coloured && TimeCalcConf.getInstance() + .isClockColorful()) {g2d.setColor(colors[i - 1]);} g2d.setFont(new Font("sans", Font.BOLD, 16)); g2d.drawString(Integer.toString(i), dx, dy); } diff --git a/src/main/java/rvc/timecalc/Battery.java b/src/main/java/rvc/timecalc/Battery.java index ce37144..a874c6c 100644 --- a/src/main/java/rvc/timecalc/Battery.java +++ b/src/main/java/rvc/timecalc/Battery.java @@ -98,7 +98,8 @@ public class Battery extends JPanel { 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) { + if(waterSurfaceHeight <= 2 || !TimeCalcConf.getInstance() + .areBatteryWavesEnabled()) { waterSurfaceHeight = 0; } diff --git a/src/main/java/rvc/timecalc/TimeCalcConf.java b/src/main/java/rvc/timecalc/TimeCalcConf.java new file mode 100644 index 0000000..2feb0b8 --- /dev/null +++ b/src/main/java/rvc/timecalc/TimeCalcConf.java @@ -0,0 +1,63 @@ +package rvc.timecalc; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Properties; + +/** + * @author Robert + * @since 20.02.2024 + */ +public class TimeCalcConf { + private static final String CLOCK_COLORFUL = "clock.colorful"; + private static final String CLOCK_HANDS_LONG = "clock.hands.long"; + private static final String JOKE_VISIBLE = "jokes.visible"; + private static final String BATTERY_WAVES_ENABLED = "battery.waves.enabled"; + + private static TimeCalcConf INSTANCE; + private Properties properties = new Properties(); + public static TimeCalcConf getInstance() { + if(INSTANCE == null) { + INSTANCE = new TimeCalcConf(); + } + return INSTANCE; + } + private TimeCalcConf() { + if(!new File("timecalc.conf").exists()) { + //nothing to do; + return; + } + try { + this.properties.load(new FileInputStream("timecalc.conf")); + } catch (IOException e) { + System.err.println(e); + } + } + public boolean isClockColorful() { + if(!properties.containsKey(CLOCK_COLORFUL)) { + return false; + } + return properties.get(CLOCK_COLORFUL).equals("true"); + } + + public boolean areClockHandsLong() { + if(!properties.containsKey(CLOCK_HANDS_LONG)) { + return true; + } + return properties.get(CLOCK_HANDS_LONG).equals("true"); + } + public boolean isJokeVisible() { + if(!properties.containsKey(JOKE_VISIBLE)) { + return true; + } + return properties.get(JOKE_VISIBLE).equals("true"); + } + public boolean areBatteryWavesEnabled() { + if(!properties.containsKey(BATTERY_WAVES_ENABLED)) { + return true; + } + return properties.get(BATTERY_WAVES_ENABLED).equals("true"); + } + +} diff --git a/src/main/java/rvc/timecalc/TimeCalcWindow.java b/src/main/java/rvc/timecalc/TimeCalcWindow.java index 7fa1861..4d3ff84 100644 --- a/src/main/java/rvc/timecalc/TimeCalcWindow.java +++ b/src/main/java/rvc/timecalc/TimeCalcWindow.java @@ -7,6 +7,8 @@ import javax.swing.JFrame; import javax.swing.JTextPane; import java.awt.Color; import java.awt.Font; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.image.BufferedImage; @@ -46,6 +48,7 @@ public class TimeCalcWindow { private int endMinute; private boolean stopBeforeEnd = false; private boolean vtipyShown = false; + private boolean everythingHidden = false; public TimeCalcWindow(String startTimeIn, String overTimeIn) { this.startTime = startTimeIn; @@ -86,6 +89,19 @@ public class TimeCalcWindow { window.add(jokeButton); window.add(restartButton); window.add(exitButton); + window.setFocusable(true); + window.addKeyListener(new KeyAdapter() { + // Key Pressed method + public void keyPressed(KeyEvent e) { + if(e.getKeyCode() == KeyEvent.VK_UP){ + everythingHidden = false; + } + if(e.getKeyCode() == KeyEvent.VK_DOWN){ + everythingHidden = true; + } + window.repaint(); + } + }); JTextPane text = new JTextPane(); text.setBounds(10, 10 + 210 + 10, 540, 250); text.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); @@ -187,6 +203,16 @@ public class TimeCalcWindow { window.dispose(); break; } + text.setVisible(!everythingHidden); + progressSquare.setVisible(!everythingHidden); + progressCircle.setVisible(!everythingHidden); + analogClock.setVisible(!everythingHidden); + battery.setVisible(!everythingHidden); + batteryForWeek.setVisible(!everythingHidden); + jokeButton.setVisible(!TimeCalcConf.getInstance().isJokeVisible()? false : !everythingHidden); + restartButton.setVisible(!everythingHidden); + exitButton.setVisible(!everythingHidden); + window.setTitle(everythingHidden ? "" : "Time Calc"); sb = new StringBuilder(); LocalDateTime now = LocalDateTime.now(); String nowString = DATE_TIME_FORMATTER.format(now); diff --git a/src/main/java/rvc/timecalc/Vtipy.java b/src/main/java/rvc/timecalc/Vtipy.java index 082501a..597f3b0 100644 --- a/src/main/java/rvc/timecalc/Vtipy.java +++ b/src/main/java/rvc/timecalc/Vtipy.java @@ -60,6 +60,10 @@ public class Vtipy { } public static void showRandom() { + if(!TimeCalcConf.getInstance().isJokeVisible()) { + //nothing to do + return; + } Toaster t = new Toaster(); t.setToasterWidth(800); t.setToasterHeight(800); diff --git a/timecalc.conf b/timecalc.conf new file mode 100644 index 0000000..e76372b --- /dev/null +++ b/timecalc.conf @@ -0,0 +1,4 @@ +clock.colorful=false +clock.hands.long=false +jokes.visible=true +battery.waves.enabled=false \ No newline at end of file diff --git a/test.txt_ b/timecalc.conf.template similarity index 100% rename from test.txt_ rename to timecalc.conf.template