mirror of
https://github.com/robertvokac/time-calc.git
synced 2025-03-25 07:27:49 +01:00
Added ProgressSquare
This commit is contained in:
parent
f77f871089
commit
8e152189e4
@ -71,9 +71,9 @@ public class AnalogClock extends JPanel {
|
|||||||
int radius) {
|
int radius) {
|
||||||
g2d.setStroke(new BasicStroke(2.0f));
|
g2d.setStroke(new BasicStroke(2.0f));
|
||||||
g2d.setColor(highlight ? Color.BLUE : FOREGROUND_COLOR);
|
g2d.setColor(highlight ? Color.BLUE : FOREGROUND_COLOR);
|
||||||
System.out.println("centerX=" + centerX);
|
// System.out.println("centerX=" + centerX);
|
||||||
System.out.println("centerY=" + centerY);
|
// System.out.println("centerY=" + centerY);
|
||||||
System.out.println("radius=" + radius);
|
// System.out.println("radius=" + radius);
|
||||||
g2d.drawOval(1, 1, centerX * 2 - 4, centerY * 2 - 4);
|
g2d.drawOval(1, 1, centerX * 2 - 4, centerY * 2 - 4);
|
||||||
g2d.drawOval(2, 2, centerX * 2 - 4, centerY * 2 - 4);
|
g2d.drawOval(2, 2, centerX * 2 - 4, centerY * 2 - 4);
|
||||||
// g2d.drawOval(3, 3, centerX * 2 - 6, centerY * 2 - 6);
|
// g2d.drawOval(3, 3, centerX * 2 - 6, centerY * 2 - 6);
|
||||||
|
@ -32,8 +32,8 @@ public class Main {
|
|||||||
"0:00"
|
"0:00"
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
TimeCalc timeCalc =
|
TimeCalcWindow timeCalc =
|
||||||
new TimeCalc(startTime, overTime);
|
new TimeCalcWindow(startTime, overTime);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
JOptionPane.showMessageDialog(null, "Error: " + e.getMessage(), e.getMessage(), JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Error: " + e.getMessage(), e.getMessage(), JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
|
63
src/main/java/rvc/timecalc/ProgressSquare.java
Normal file
63
src/main/java/rvc/timecalc/ProgressSquare.java
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
public class ProgressSquare 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 int side = 0;
|
||||||
|
private int square;
|
||||||
|
|
||||||
|
|
||||||
|
private double donePercent = 0;
|
||||||
|
|
||||||
|
public void setDonePercent(double donePercent) {
|
||||||
|
this.donePercent = donePercent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ProgressSquare() {
|
||||||
|
setPreferredSize(new Dimension(400, 400));
|
||||||
|
setBackground(BACKGROUND_COLOR);
|
||||||
|
new Timer(1000, e -> repaint()).start();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
|
||||||
|
if(side == 0) {
|
||||||
|
this.side = Math.min(getWidth(), getHeight());
|
||||||
|
this.square = side * side;
|
||||||
|
}
|
||||||
|
super.paintComponent(g);
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
g2d.setColor(FOREGROUND_COLOR);
|
||||||
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||||
|
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("square=" + square);
|
||||||
|
int dotNumber = (int)(donePercent * square);
|
||||||
|
int y = dotNumber / side;
|
||||||
|
int x = dotNumber - y * side;
|
||||||
|
|
||||||
|
System.out.println("dotNumber=" + dotNumber);
|
||||||
|
System.out.println("x=" + x);
|
||||||
|
System.out.println("y=" + y);
|
||||||
|
if(y > 1) {
|
||||||
|
g2d.fillRect(side - 4, side - 4, 4, 4);
|
||||||
|
g2d.fillRect(1, side - 4, 4, 4);
|
||||||
|
g2d.fillRect(1, 1, side, y - 1);
|
||||||
|
g2d.drawRect(1, y, x, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -18,10 +18,10 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert
|
* @author pc00289
|
||||||
* @since 08.02.2024
|
* @since 08.02.2024
|
||||||
*/
|
*/
|
||||||
public class TimeCalc {
|
public class TimeCalcWindow {
|
||||||
private static final String DEFAULT_OVERTIME = "0:00";
|
private static final String DEFAULT_OVERTIME = "0:00";
|
||||||
private static final int WORKING_HOURS_LENGTH = 8;
|
private static final int WORKING_HOURS_LENGTH = 8;
|
||||||
private static final int WORKING_MINUTES_LENGTH = 30;
|
private static final int WORKING_MINUTES_LENGTH = 30;
|
||||||
@ -41,7 +41,7 @@ public class TimeCalc {
|
|||||||
private final Set<Integer> alreadyShownPercents = new HashSet<>();
|
private final Set<Integer> alreadyShownPercents = new HashSet<>();
|
||||||
private boolean stopBeforeEnd = false;
|
private boolean stopBeforeEnd = false;
|
||||||
|
|
||||||
public TimeCalc(String startTimeIn, String overTimeIn) {
|
public TimeCalcWindow(String startTimeIn, String overTimeIn) {
|
||||||
this.startTime = startTimeIn;
|
this.startTime = startTimeIn;
|
||||||
this.overTime = (overTimeIn == null || overTimeIn.isEmpty()) ? DEFAULT_OVERTIME : overTimeIn;
|
this.overTime = (overTimeIn == null || overTimeIn.isEmpty()) ? DEFAULT_OVERTIME : overTimeIn;
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ public class TimeCalc {
|
|||||||
text.setBackground(new Color(238,238,238));
|
text.setBackground(new Color(238,238,238));
|
||||||
window.add(text);
|
window.add(text);
|
||||||
|
|
||||||
window.setSize(800,350);
|
window.setSize(1050,350);
|
||||||
window.setLayout(null);
|
window.setLayout(null);
|
||||||
window.setVisible(true);
|
window.setVisible(true);
|
||||||
window.setTitle("Time Calc");
|
window.setTitle("Time Calc");
|
||||||
@ -100,6 +100,10 @@ public class TimeCalc {
|
|||||||
analogClock.setBounds(550,10,200, 200);
|
analogClock.setBounds(550,10,200, 200);
|
||||||
window.add(analogClock);
|
window.add(analogClock);
|
||||||
|
|
||||||
|
ProgressSquare progressSquare = new ProgressSquare();
|
||||||
|
progressSquare.setBounds(550 + analogClock.getWidth() + 10,10,200, 200);
|
||||||
|
window.add(progressSquare);
|
||||||
|
|
||||||
StringBuilder sb = null;
|
StringBuilder sb = null;
|
||||||
while (true) {
|
while (true) {
|
||||||
if(stopBeforeEnd) {
|
if(stopBeforeEnd) {
|
||||||
@ -153,6 +157,7 @@ public class TimeCalc {
|
|||||||
|
|
||||||
// double done = ((double)totalMinutesDone)/((double)totalMinutes);
|
// double done = ((double)totalMinutesDone)/((double)totalMinutes);
|
||||||
double done = ((double)totalMillisecondsDone)/((double)totalMilliseconds);
|
double done = ((double)totalMillisecondsDone)/((double)totalMilliseconds);
|
||||||
|
progressSquare.setDonePercent(done);
|
||||||
|
|
||||||
String msg = "Done=" + formatter.format(done * 100) + "% Remains=" + String.format("%02d", hourRemains) + ":" + String
|
String msg = "Done=" + formatter.format(done * 100) + "% Remains=" + String.format("%02d", hourRemains) + ":" + String
|
||||||
.format("%02d", minuteRemains) + " (" + String.format("%03d", (hourRemains * 60 + minuteRemains)) + " minute" + ((hourRemains * 60 + minuteRemains) > 1 ? "s" : " ") + ")" + " End=" + String
|
.format("%02d", minuteRemains) + " (" + String.format("%03d", (hourRemains * 60 + minuteRemains)) + " minute" + ((hourRemains * 60 + minuteRemains) > 1 ? "s" : " ") + ")" + " End=" + String
|
Loading…
x
Reference in New Issue
Block a user