Added new improvements

This commit is contained in:
Robert Vokac 2024-01-28 15:22:25 +00:00
parent 8901aff6e1
commit a3fe9c0d4c
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
10 changed files with 84 additions and 254 deletions

View File

@ -10,9 +10,6 @@ import java.awt.Font;
import java.awt.Graphics;
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;
@ -21,49 +18,10 @@ import java.util.GregorianCalendar;
import java.util.Locale;
//https://kodejava.org/how-do-i-write-a-simple-analog-clock-using-java-2d/
public class AnalogClock extends JPanel {
private static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
private static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
private boolean coloured = false;
private boolean mouseOver = false;
private int side;
private Color[] colors = Utils.getRandomColors();
public class AnalogClock extends Widget {
public AnalogClock() {
setPreferredSize(new Dimension(400, 300));
setBackground(BACKGROUND_COLOR);
new Timer(20, e -> repaint()).start();
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) {
coloured = true;
mouseOver = true;
}
@Override
public void mouseExited(MouseEvent e) {
coloured = false;
mouseOver = false;
}
});
}
@ -75,34 +33,6 @@ public class AnalogClock extends JPanel {
frame.setVisible(true);
}
private static Color modifyColourALittleBit(Color colorIn) {
int r = colorIn.getRed();
int g = colorIn.getGreen();
int b = colorIn.getBlue();
Color color = new Color(
modifyByteALittleBit(r),
modifyByteALittleBit(g),
modifyByteALittleBit(b)
);
return color;
}
private static int modifyByteALittleBit(int n) {
// if(Math.random() <= 0.75) {
// return n;
// }
boolean negative = Math.random() > 0.5;
int result = n + ((negative ? (-1) : 1)) * ((int) (Math.random() * (
Math.random() * 20)));
if (result > 255) {
return 255;
}
if (result < 0) {
return 0;
}
return result;
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
@ -171,35 +101,12 @@ 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(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) {
colors[i] = modifyColourALittleBit(colors[i]);
//}
}
}
// if(Math.random() > (1 - (1/200))) {
// for(int i = 0; i<12; i++) {
// colors[i] = i == 11 ? colors[0] :colors[i + 1];
// }
// }
DateFormat formatter2 =
new SimpleDateFormat("HH:mm:ss", Locale.ENGLISH);
String now = formatter2.format(new Date());
if (coloured) {
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.BLACK :
FOREGROUND_COLOR);
g2d.setFont(new Font("sans", Font.PLAIN, 12));
DateFormat formatter =
new SimpleDateFormat("EEEE : yyyy-MM-dd", Locale.ENGLISH);
g2d.drawString(formatter.format(new Date()), ((int) (side * 0.25)),
((int) (side * 0.35)));
//
g2d.drawString(now, ((int) (side * 0.25) + 30),
((int) (side * 0.35)) + 60);
}
for (int i = 1; i <= 12; i++) {
double angle = Math.PI * 2 * (i / 12.0 - 0.25);
int dx = centerX + (int) ((radius + 20) * Math.cos(angle)) - 4;
@ -207,12 +114,13 @@ public class AnalogClock extends JPanel {
int seconds = Integer.valueOf(now.split(":")[2]);
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);
}
}
public int getTimerDelay() {
return 20;
}
}

View File

@ -12,7 +12,7 @@ import java.awt.event.MouseListener;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class Battery extends JPanel {
public class Battery extends Widget {
public static final Color LOW = new Color(253, 130, 130);
public static final Color MEDIUM = new Color(255, 204, 153);
@ -22,48 +22,14 @@ public class Battery extends JPanel {
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 static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
private static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
NumberFormat formatter3 = new DecimalFormat("#0.000");
private int totalHeight = 0;
private double donePercent = 0;
private boolean mouseOver = false;
private int width_;
public Battery() {
setPreferredSize(new Dimension(40, 100));
setBackground(BACKGROUND_COLOR);
new Timer(250, e -> repaint()).start();
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) {
mouseOver = true;
}
@Override
public void mouseExited(MouseEvent e) {
mouseOver = false;
}
});
}
public void setDonePercent(double donePercent) {
this.donePercent = donePercent;
}
@Override
@ -141,4 +107,7 @@ public class Battery extends JPanel {
if(Math.random() > 0.7) {randomDoubles[index] = Math.random();}
return randomDoubles[index];
}
public int getTimerDelay() {
return 250;
}
}

View File

@ -10,10 +10,10 @@ import java.util.HashSet;
import java.util.Set;
/**
* @author Robert
* @author pc00289
* @since 09.02.2024
*/
public class Vtipy {
public class Jokes {
/**
* https://bestvtip.cz/
* https://www.vtipbaze.cz/
@ -29,7 +29,7 @@ public class Vtipy {
static {
try {
array = VtipyTxt.getAsArray();
array = JokesTxt.getAsArray();
Set<String> set = new HashSet<>();
for (String vtip : array) {
if (vtip.trim().isEmpty()) {

View File

@ -7,11 +7,11 @@ import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
/**
* @author Robert
* @author pc00289
* @since 15.02.2024
*/
public class VtipyTxt {
private VtipyTxt() {
public class JokesTxt {
private JokesTxt() {
//Not meant to be instantiated.
}

View File

@ -1,58 +1,15 @@
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;
public class ProgressCircle extends JPanel {
private static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
private static final Color FOREGROUND_COLOR2 = new Color(210, 210, 210);
private static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
private int side = 0;
private double donePercent = 0;
private boolean mouseOver = false;
public class ProgressCircle extends Widget {
public ProgressCircle() {
setPreferredSize(new Dimension(200, 200));
setBackground(BACKGROUND_COLOR);
new Timer(100, e -> repaint()).start();
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) {
mouseOver = true;
}
@Override
public void mouseExited(MouseEvent e) {
mouseOver = false;
}
});
}
public void setDonePercent(double donePercent) {
this.donePercent = donePercent;
}
@Override
@ -66,14 +23,8 @@ public class ProgressCircle extends JPanel {
FOREGROUND_COLOR);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
// if (highlight) {
// g2d.setColor(Color.BLUE);
// }
double angleDouble = donePercent * 360;
// System.out.println("angleDouble=" + angleDouble);
////
double angleDouble2 = (angleDouble - (int) (angleDouble)) * 360;
// System.out.println("remainingAngle=" + angleDouble2);

View File

@ -10,49 +10,12 @@ import java.awt.RenderingHints;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class ProgressSquare extends JPanel {
public class ProgressSquare extends Widget {
private static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
private static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
private int side = 0;
private int square;
private double donePercent = 0;
private boolean mouseOver = false;
public ProgressSquare() {
setPreferredSize(new Dimension(400, 400));
setBackground(BACKGROUND_COLOR);
new Timer(100, e -> repaint()).start();
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) {
mouseOver = true;
}
@Override
public void mouseExited(MouseEvent e) {
mouseOver = false;
}
});
}
public void setDonePercent(double donePercent) {
this.donePercent = donePercent;
}
@Override
@ -67,7 +30,7 @@ public class ProgressSquare extends JPanel {
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
// System.out.println("square=" + square);
int dotNumber = (int) (donePercent * square);
int y = dotNumber / side;
int yOrig = y;
@ -111,16 +74,6 @@ public class ProgressSquare extends JPanel {
}
g2d.setColor(FOREGROUND_COLOR);
}
// int nextX = (int) (Math.random() * 200);
// int nextY = (int) (Math.random() * (yOrig- 1));
// for(int i = 0;i< yOrig / 8;i++) {
// g2d.setColor(Color.GRAY/*Utils.getRandomColor()*/);
// g2d.drawLine(x, y, nextX, nextY);
// x = nextX;
// y = nextY;
// nextX = (int) (Math.random() * 200);
// nextY = (int) (Math.random() * (yOrig - 1));
// }
}

View File

@ -10,7 +10,6 @@ import java.util.Properties;
* @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";
@ -35,12 +34,6 @@ public class TimeCalcConf {
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)) {

View File

@ -164,7 +164,7 @@ public class TimeCalcWindow {
.addActionListener(e -> new WeatherWindow().setVisible(true));
jokeButton.addActionListener(e -> {
for (int i = 1; i <= 1; i++) {
Vtipy.showRandom();
Jokes.showRandom();
}
});
exitButton.addActionListener(e -> System.exit(0));
@ -223,9 +223,9 @@ public class TimeCalcWindow {
boolean nowIsWeekend = currentDayOfWeekAsString.equals("SATURDAY") || currentDayOfWeekAsString.equals("SUNDAY");
workDaysTotal = workDaysDone + (nowIsWeekend ? 0 : 1) + workDaysTodo;
System.out.println("workDaysDone" + workDaysDone);
System.out.println("workDaysTodo" + workDaysTodo);
System.out.println("currentDayOfMonth" + currentDayOfMonth);
// System.out.println("workDaysDone" + workDaysDone);
// System.out.println("workDaysTodo" + workDaysTodo);
// System.out.println("currentDayOfMonth" + currentDayOfMonth);
@ -334,7 +334,7 @@ public class TimeCalcWindow {
// }
if (hourRemains == 0 && minuteRemains == 1 && !vtipyShown) {
vtipyShown = true;
Vtipy.showRandom();
Jokes.showRandom();
}
if (hourRemains == 0 && minuteRemains <= 3) {
Utils.highlighted.set(true);

View File

@ -39,7 +39,6 @@ public class Utils {
System.err.println(e);
throw new RuntimeException(e);
}
}
/**

View File

@ -0,0 +1,57 @@
package rvc.timecalc;
import javax.swing.JPanel;
import javax.swing.Timer;
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/**
* @author Robert
* @since 20.02.2024
*/
public class Widget extends JPanel {
protected int side = 0;
protected double donePercent = 0;
protected boolean mouseOver = false;
protected static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
protected static final Color FOREGROUND_COLOR2 = new Color(210, 210, 210);
protected static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
public Widget() {
setBackground(BACKGROUND_COLOR);
new Timer(getTimerDelay(), e -> repaint()).start();
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) {
mouseOver = true;
}
@Override
public void mouseExited(MouseEvent e) {
mouseOver = false;
}
});
}
public int getTimerDelay() {
return 100;
}
public final void setDonePercent(double donePercent) {
this.donePercent = donePercent;
}
}