Added new improvements

This commit is contained in:
Robert Vokac 2024-01-28 14:57:31 +00:00
parent d3dcab759c
commit 469c49f62c
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
8 changed files with 108 additions and 7 deletions

1
.gitignore vendored
View File

@ -13,3 +13,4 @@ proxy.txt
out.txt
pocasi.txt
test.txt
timecalc.conf

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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");
}
}

View File

@ -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);

View File

@ -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);

4
timecalc.conf Normal file
View File

@ -0,0 +1,4 @@
clock.colorful=false
clock.hands.long=false
jokes.visible=true
battery.waves.enabled=false