mirror of
https://github.com/robertvokac/time-calc.git
synced 2025-03-25 07:27:49 +01:00
Added new improvements
This commit is contained in:
parent
51e79d02b0
commit
da901e30e1
3391
src/main/java/rvc/timecalc/A.java
Normal file
3391
src/main/java/rvc/timecalc/A.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -25,7 +25,7 @@ public class Battery extends JPanel {
|
|||||||
private static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
|
private static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
|
||||||
private static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
|
private static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
|
||||||
NumberFormat formatter3 = new DecimalFormat("#0.000");
|
NumberFormat formatter3 = new DecimalFormat("#0.000");
|
||||||
private int height_ = 0;
|
private int totalHeight = 0;
|
||||||
private double donePercent = 0;
|
private double donePercent = 0;
|
||||||
private boolean mouseOver = false;
|
private boolean mouseOver = false;
|
||||||
private int width_;
|
private int width_;
|
||||||
@ -33,7 +33,7 @@ public class Battery extends JPanel {
|
|||||||
public Battery() {
|
public Battery() {
|
||||||
setPreferredSize(new Dimension(40, 100));
|
setPreferredSize(new Dimension(40, 100));
|
||||||
setBackground(BACKGROUND_COLOR);
|
setBackground(BACKGROUND_COLOR);
|
||||||
new Timer(100, e -> repaint()).start();
|
new Timer(250, e -> repaint()).start();
|
||||||
addMouseListener(new MouseListener() {
|
addMouseListener(new MouseListener() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
@ -68,9 +68,9 @@ public class Battery extends JPanel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
if (height_ == 0) {
|
if (totalHeight == 0) {
|
||||||
this.height_ = Math.min(getWidth(), getHeight());
|
this.totalHeight = Math.min(getWidth(), getHeight());
|
||||||
this.width_ = (int) (this.height_ * 0.6);
|
this.width_ = (int) (this.totalHeight * 0.6);
|
||||||
}
|
}
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
Graphics2D g2d = (Graphics2D) g;
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
@ -79,28 +79,65 @@ public class Battery extends JPanel {
|
|||||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
|
||||||
g2d.fillRect(width_ / 4, 1, width_, height_ - 2);
|
g2d.fillRect(width_ / 4, 1, width_, totalHeight - 2);
|
||||||
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.BLACK :
|
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.BLACK :
|
||||||
Color.LIGHT_GRAY);
|
Color.LIGHT_GRAY);
|
||||||
g2d.drawRect(width_ / 4 - 1, 0, width_ + 1, height_ + 0);
|
g2d.drawRect(width_ / 4 - 1, 0, width_ + 1, totalHeight + 0);
|
||||||
if (Utils.highlighted.get() || mouseOver) {
|
if (Utils.highlighted.get() || mouseOver) {
|
||||||
g2d.setColor(
|
g2d.setColor(
|
||||||
donePercent < 0.1 ? LOW_HIGHLIGHTED : (donePercent < 0.75 ?
|
donePercent < 0.1 ? LOW_HIGHLIGHTED : (donePercent < 0.75 ?
|
||||||
MEDIUM_HIGHLIGHTED :
|
MEDIUM_HIGHLIGHTED :
|
||||||
(donePercent < 0.9 ? HIGH_HIGHLIGHTED :
|
(donePercent < 0.9 ? HIGH_HIGHLIGHTED :
|
||||||
HIGHEST_HIGHLIGHTED)));
|
HIGHEST_HIGHLIGHTED)));
|
||||||
} else {
|
} else {
|
||||||
g2d.setColor(donePercent < 0.1 ? LOW : (donePercent < 0.75 ?
|
g2d.setColor(donePercent < 0.1 ? LOW : (donePercent < 0.75 ?
|
||||||
MEDIUM : (donePercent < 0.9 ? HIGH : HIGHEST)));
|
MEDIUM : (donePercent < 0.9 ? HIGH : HIGHEST)));
|
||||||
}
|
}
|
||||||
g2d.fillRect(width_ / 4, height_ - (int) (height_ * donePercent),
|
int doneHeight = (int) (totalHeight * donePercent);
|
||||||
width_, (int) (height_ * donePercent));
|
int intX = width_ / 4;
|
||||||
|
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) {
|
||||||
|
waterSurfaceHeight = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
g2d.fillRect(intX, doneHeight < waterSurfaceHeight || donePercent >= 1 ? todoHeight : todoHeight + waterSurfaceHeight,
|
||||||
|
width_, doneHeight < waterSurfaceHeight || donePercent >= 1 ? doneHeight : doneHeight - waterSurfaceHeight);
|
||||||
|
int pointCount = 8;
|
||||||
|
if(doneHeight >= waterSurfaceHeight && donePercent < 1) {// && todoHeight > waterSurfaceHeight) {
|
||||||
|
//g2d.fillArc(intX, intY, width_, intHeight - waterSurfaceHeight, 30, 60);
|
||||||
|
|
||||||
|
g2d.fillPolygon(
|
||||||
|
new int[]{intX,
|
||||||
|
(int) (intX + width_ / pointCount * 0.5),
|
||||||
|
intX + width_ / pointCount * 3,
|
||||||
|
intX + width_ / pointCount * 4,
|
||||||
|
intX + width_ / pointCount * 5,
|
||||||
|
intX + width_ / pointCount * 6,
|
||||||
|
(int) (intX + width_ / pointCount * 7.9),
|
||||||
|
intX + width_ / pointCount * 8},
|
||||||
|
new int[]{(int) (todoHeight + (waterSurfaceHeight * 1)),
|
||||||
|
todoHeight + (int) (waterSurfaceHeight * getRandom(0)),
|
||||||
|
todoHeight + (int) (waterSurfaceHeight * getRandom(1)),
|
||||||
|
todoHeight + (int) (waterSurfaceHeight * getRandom(2)),
|
||||||
|
todoHeight + (int) (waterSurfaceHeight * getRandom(3)),
|
||||||
|
todoHeight + (int) (waterSurfaceHeight * getRandom(4)),
|
||||||
|
todoHeight + (int) (waterSurfaceHeight * getRandom(5)),
|
||||||
|
(int) (todoHeight + (waterSurfaceHeight * 1))},
|
||||||
|
pointCount);
|
||||||
|
}
|
||||||
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.BLACK :
|
g2d.setColor(Utils.highlighted.get() || mouseOver ? Color.BLACK :
|
||||||
Color.LIGHT_GRAY);
|
Color.LIGHT_GRAY);
|
||||||
g2d.drawString(
|
g2d.drawString(
|
||||||
formatter3.format(donePercent * 100) + "%",
|
formatter3.format(donePercent * 100) + "%",
|
||||||
((int) (width_ * 0.4)), height_ / 2);
|
((int) (width_ * 0.4)), donePercent > 0.5 ? totalHeight / 4 * 3 : totalHeight / 4 * 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private double[] randomDoubles = new double[]{1d,1d,1d,1d,1d,1d,1};
|
||||||
|
private double getRandom(int index) {
|
||||||
|
if(Math.random() > 0.7) {randomDoubles[index] = Math.random();}
|
||||||
|
return randomDoubles[index];
|
||||||
|
}
|
||||||
}
|
}
|
@ -18,7 +18,7 @@ public class Main {
|
|||||||
String lastStartTime = Utils.readTextFromFile(starttimeTxt);
|
String lastStartTime = Utils.readTextFromFile(starttimeTxt);
|
||||||
String lastOvertime = Utils.readTextFromFile(overtimeTxt);
|
String lastOvertime = Utils.readTextFromFile(overtimeTxt);
|
||||||
String startTime =
|
String startTime =
|
||||||
test ? "7:00" : (String) JOptionPane.showInputDialog(
|
test ? (lastStartTime != null ? lastStartTime : "7:00") : (String) JOptionPane.showInputDialog(
|
||||||
null,
|
null,
|
||||||
"Start Time:",
|
"Start Time:",
|
||||||
"Start Time",
|
"Start Time",
|
||||||
@ -28,7 +28,7 @@ public class Main {
|
|||||||
lastStartTime == null ? "7:00" : lastStartTime
|
lastStartTime == null ? "7:00" : lastStartTime
|
||||||
);
|
);
|
||||||
String overTime =
|
String overTime =
|
||||||
test ? "0:00" : (String) JOptionPane.showInputDialog(
|
test ? (lastOvertime != null ? lastOvertime : "0:00") : (String) JOptionPane.showInputDialog(
|
||||||
null,
|
null,
|
||||||
"Overtime:",
|
"Overtime:",
|
||||||
"Overtime",
|
"Overtime",
|
||||||
|
@ -32,7 +32,7 @@ public class TimeCalcWindow {
|
|||||||
private final static DateTimeFormatter DATE_TIME_FORMATTER =
|
private final static DateTimeFormatter DATE_TIME_FORMATTER =
|
||||||
DateTimeFormatter.ofPattern("HH:mm:ss:SSS");
|
DateTimeFormatter.ofPattern("HH:mm:ss:SSS");
|
||||||
private final String startTime;
|
private final String startTime;
|
||||||
private final String overTime;
|
private String overTime;
|
||||||
private final int startHour;
|
private final int startHour;
|
||||||
private final int startMinute;
|
private final int startMinute;
|
||||||
private final int overtimeHour;
|
private final int overtimeHour;
|
||||||
@ -53,11 +53,13 @@ public class TimeCalcWindow {
|
|||||||
this.startHour = Integer.valueOf(startTime.split(":")[0]);
|
this.startHour = Integer.valueOf(startTime.split(":")[0]);
|
||||||
this.startMinute = Integer.valueOf(startTime.split(":")[1]);
|
this.startMinute = Integer.valueOf(startTime.split(":")[1]);
|
||||||
|
|
||||||
this.overtimeHour = Integer.valueOf(overTime.split(":")[0]);
|
boolean overtimeIsNegative = overTime.startsWith("-");
|
||||||
this.overtimeMinute = Integer.valueOf(overTime.split(":")[1]);
|
if(overtimeIsNegative) {overTime = overTime.replace("-","");}
|
||||||
|
this.overtimeHour =(overtimeIsNegative ? (-1) : 1) * Integer.valueOf(overTime.split(":")[0]);
|
||||||
|
this.overtimeMinute = (overtimeIsNegative ? (-1) : 1) * Integer.valueOf(overTime.split(":")[1]);
|
||||||
|
|
||||||
this.endHour = startHour + WORKING_HOURS_LENGTH - overtimeHour;
|
this.endHour = startHour + WORKING_HOURS_LENGTH + overtimeHour;
|
||||||
this.endMinute = startMinute + WORKING_MINUTES_LENGTH - overtimeMinute;
|
this.endMinute = startMinute + WORKING_MINUTES_LENGTH + overtimeMinute;
|
||||||
while (endMinute >= 60) {
|
while (endMinute >= 60) {
|
||||||
endMinute = endMinute - 60;
|
endMinute = endMinute - 60;
|
||||||
endHour = endHour + 1;
|
endHour = endHour + 1;
|
||||||
@ -180,8 +182,8 @@ public class TimeCalcWindow {
|
|||||||
int secondsRemains = 60 - secondNow;
|
int secondsRemains = 60 - secondNow;
|
||||||
int millisecondsRemains = 1000 - millisecondNow;
|
int millisecondsRemains = 1000 - millisecondNow;
|
||||||
|
|
||||||
int hourDone = WORKING_HOURS_LENGTH - overtimeHour - hourRemains;
|
int hourDone = WORKING_HOURS_LENGTH + overtimeHour - hourRemains;
|
||||||
int minutesDone = 30 - overtimeMinute - minuteRemains;
|
int minutesDone = 30 + overtimeMinute - minuteRemains;
|
||||||
int secondsDone = secondNow;
|
int secondsDone = secondNow;
|
||||||
int millisecondsDone = millisecondNow;
|
int millisecondsDone = millisecondNow;
|
||||||
|
|
||||||
@ -207,7 +209,7 @@ public class TimeCalcWindow {
|
|||||||
cal.setTime(new Date());
|
cal.setTime(new Date());
|
||||||
int weekDayWhenMondayIsOne = cal.get(Calendar.DAY_OF_WEEK) - 1;
|
int weekDayWhenMondayIsOne = cal.get(Calendar.DAY_OF_WEEK) - 1;
|
||||||
batteryForWeek.setDonePercent((weekDayWhenMondayIsOne == 0
|
batteryForWeek.setDonePercent((weekDayWhenMondayIsOne == 0
|
||||||
|| weekDayWhenMondayIsOne == 6) ?
|
|| weekDayWhenMondayIsOne == 6) ?
|
||||||
100 : ((weekDayWhenMondayIsOne - 1) * 0.20 + done * 0.20));
|
100 : ((weekDayWhenMondayIsOne - 1) * 0.20 + done * 0.20));
|
||||||
|
|
||||||
int totalSecondsRemains =
|
int totalSecondsRemains =
|
||||||
|
@ -423,7 +423,7 @@ public class Toaster {
|
|||||||
if (currentNumberOfToaster > 0) {
|
if (currentNumberOfToaster > 0) {
|
||||||
stopYPosition =
|
stopYPosition =
|
||||||
stopYPosition - (maxToaster % maxToasterInSceen
|
stopYPosition - (maxToaster % maxToasterInSceen
|
||||||
* toasterHeight);
|
* toasterHeight);
|
||||||
} else {
|
} else {
|
||||||
maxToaster = 0;
|
maxToaster = 0;
|
||||||
}
|
}
|
||||||
@ -434,7 +434,7 @@ public class Toaster {
|
|||||||
if (currentNumberOfToaster > 0) {
|
if (currentNumberOfToaster > 0) {
|
||||||
stopYPosition =
|
stopYPosition =
|
||||||
stopYPosition + (maxToaster % maxToasterInSceen
|
stopYPosition + (maxToaster % maxToasterInSceen
|
||||||
* toasterHeight);
|
* toasterHeight);
|
||||||
} else {
|
} else {
|
||||||
maxToaster = 0;
|
maxToaster = 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user