mirror of
https://github.com/robertvokac/time-calc.git
synced 2025-03-26 15:59:24 +01:00
Added new improvements
This commit is contained in:
parent
41aa6f3489
commit
8901aff6e1
@ -14,6 +14,7 @@ public class TimeCalcConf {
|
|||||||
private static final String CLOCK_HANDS_LONG = "clock.hands.long";
|
private static final String CLOCK_HANDS_LONG = "clock.hands.long";
|
||||||
private static final String JOKE_VISIBLE = "jokes.visible";
|
private static final String JOKE_VISIBLE = "jokes.visible";
|
||||||
private static final String BATTERY_WAVES_ENABLED = "battery.waves.enabled";
|
private static final String BATTERY_WAVES_ENABLED = "battery.waves.enabled";
|
||||||
|
private static final String EVERYTHING_HIDDEN = "everything-hidden";
|
||||||
|
|
||||||
private static TimeCalcConf INSTANCE;
|
private static TimeCalcConf INSTANCE;
|
||||||
private Properties properties = new Properties();
|
private Properties properties = new Properties();
|
||||||
@ -59,5 +60,11 @@ public class TimeCalcConf {
|
|||||||
}
|
}
|
||||||
return properties.get(BATTERY_WAVES_ENABLED).equals("true");
|
return properties.get(BATTERY_WAVES_ENABLED).equals("true");
|
||||||
}
|
}
|
||||||
|
public boolean isEverythingHidden() {
|
||||||
|
if(!properties.containsKey(EVERYTHING_HIDDEN)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return properties.get(EVERYTHING_HIDDEN).equals("true");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@ import java.awt.image.BufferedImage;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
|
import java.time.DayOfWeek;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
@ -51,6 +53,7 @@ public class TimeCalcWindow {
|
|||||||
private boolean everythingHidden = false;
|
private boolean everythingHidden = false;
|
||||||
|
|
||||||
public TimeCalcWindow(String startTimeIn, String overTimeIn) {
|
public TimeCalcWindow(String startTimeIn, String overTimeIn) {
|
||||||
|
everythingHidden = TimeCalcConf.getInstance().isEverythingHidden();
|
||||||
this.startTime = startTimeIn;
|
this.startTime = startTimeIn;
|
||||||
this.overTime = (overTimeIn == null || overTimeIn.isEmpty()) ?
|
this.overTime = (overTimeIn == null || overTimeIn.isEmpty()) ?
|
||||||
DEFAULT_OVERTIME : overTimeIn;
|
DEFAULT_OVERTIME : overTimeIn;
|
||||||
@ -103,7 +106,7 @@ public class TimeCalcWindow {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
JTextPane text = new JTextPane();
|
JTextPane text = new JTextPane();
|
||||||
text.setBounds(10, 10 + 210 + 10, 540, 250);
|
text.setBounds(10, 10 + 210 + 10, 500, 250);
|
||||||
text.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
|
text.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
|
||||||
text.setForeground(Color.GRAY);
|
text.setForeground(Color.GRAY);
|
||||||
text.setBackground(new Color(238, 238, 238));
|
text.setBackground(new Color(238, 238, 238));
|
||||||
@ -196,6 +199,41 @@ public class TimeCalcWindow {
|
|||||||
battery.getY(), 90, 140);
|
battery.getY(), 90, 140);
|
||||||
window.add(batteryForWeek);
|
window.add(batteryForWeek);
|
||||||
|
|
||||||
|
Calendar calNow = Calendar.getInstance();
|
||||||
|
calNow.setTime(new Date());
|
||||||
|
LocalDate ld = LocalDate.of(calNow.get(Calendar.YEAR),calNow.get(Calendar.MONTH) + 1,1);
|
||||||
|
DayOfWeek firstDayOfMonth = ld.getDayOfWeek();
|
||||||
|
System.out.println("dow=" + firstDayOfMonth);
|
||||||
|
int currentDayOfMonth = calNow.get(Calendar.DAY_OF_MONTH);
|
||||||
|
|
||||||
|
int workDaysDone = 0;
|
||||||
|
int workDaysTodo = 0;
|
||||||
|
int workDaysTotal;
|
||||||
|
for(int dayOfMonth=1; dayOfMonth <= calNow.getActualMaximum(Calendar.DAY_OF_MONTH); dayOfMonth++) {
|
||||||
|
DayOfWeek dayOfWeek = LocalDate.of(calNow.get(Calendar.YEAR), calNow.get(Calendar.MONTH) + 1, dayOfMonth).getDayOfWeek();
|
||||||
|
boolean weekend = dayOfWeek.toString().equals("SATURDAY") || dayOfWeek.toString().equals("SUNDAY");
|
||||||
|
if(dayOfMonth < currentDayOfMonth && !weekend) {
|
||||||
|
++workDaysDone;
|
||||||
|
}
|
||||||
|
if(dayOfMonth > currentDayOfMonth && !weekend) {
|
||||||
|
++workDaysTodo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String currentDayOfWeekAsString = LocalDate.of(calNow.get(Calendar.YEAR), calNow.get(Calendar.MONTH) + 1, currentDayOfMonth).getDayOfWeek().toString();
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Battery batteryForMonth = new Battery();
|
||||||
|
batteryForMonth.setBounds(battery.getBounds().x + battery.getWidth(),
|
||||||
|
battery.getY() + batteryForWeek.getHeight() + 10, 90, 140);
|
||||||
|
window.add(batteryForMonth);
|
||||||
|
|
||||||
StringBuilder sb = null;
|
StringBuilder sb = null;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (stopBeforeEnd) {
|
if (stopBeforeEnd) {
|
||||||
@ -209,6 +247,7 @@ public class TimeCalcWindow {
|
|||||||
analogClock.setVisible(!everythingHidden);
|
analogClock.setVisible(!everythingHidden);
|
||||||
battery.setVisible(!everythingHidden);
|
battery.setVisible(!everythingHidden);
|
||||||
batteryForWeek.setVisible(!everythingHidden);
|
batteryForWeek.setVisible(!everythingHidden);
|
||||||
|
batteryForMonth.setVisible(!everythingHidden);
|
||||||
jokeButton.setVisible(!TimeCalcConf.getInstance().isJokeVisible()? false : !everythingHidden);
|
jokeButton.setVisible(!TimeCalcConf.getInstance().isJokeVisible()? false : !everythingHidden);
|
||||||
restartButton.setVisible(!everythingHidden);
|
restartButton.setVisible(!everythingHidden);
|
||||||
exitButton.setVisible(!everythingHidden);
|
exitButton.setVisible(!everythingHidden);
|
||||||
@ -263,13 +302,14 @@ public class TimeCalcWindow {
|
|||||||
progressCircle.setDonePercent(done);
|
progressCircle.setDonePercent(done);
|
||||||
battery.setDonePercent(done);
|
battery.setDonePercent(done);
|
||||||
|
|
||||||
Calendar cal = Calendar.getInstance();
|
int weekDayWhenMondayIsOne = calNow.get(Calendar.DAY_OF_WEEK) - 1;
|
||||||
cal.setTime(new Date());
|
|
||||||
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));
|
||||||
|
|
||||||
|
batteryForMonth.setDonePercent(weekDayWhenMondayIsOne == 0
|
||||||
|
|| weekDayWhenMondayIsOne == 6 ? workDaysDone/workDaysTotal : (workDaysDone + done) / workDaysTotal);
|
||||||
|
|
||||||
int totalSecondsRemains =
|
int totalSecondsRemains =
|
||||||
(hourRemains * 60 * 60 + minuteRemains * 60
|
(hourRemains * 60 * 60 + minuteRemains * 60
|
||||||
+ secondsRemains);
|
+ secondsRemains);
|
||||||
|
@ -111,6 +111,10 @@ public class Toaster {
|
|||||||
* Show a toaster with the specified message and the associated icon.
|
* Show a toaster with the specified message and the associated icon.
|
||||||
*/
|
*/
|
||||||
public void showToaster(Icon icon, String msg) {
|
public void showToaster(Icon icon, String msg) {
|
||||||
|
if(TimeCalcConf.getInstance().isEverythingHidden()) {
|
||||||
|
//nothing to do
|
||||||
|
return;
|
||||||
|
}
|
||||||
SingleToaster singleToaster = new SingleToaster();
|
SingleToaster singleToaster = new SingleToaster();
|
||||||
if (icon != null) {
|
if (icon != null) {
|
||||||
singleToaster.iconLabel.setIcon(icon);
|
singleToaster.iconLabel.setIcon(icon);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
clock.colorful=false
|
clock.colorful=false
|
||||||
clock.hands.long=false
|
clock.hands.long=true
|
||||||
jokes.visible=true
|
jokes.visible=true
|
||||||
battery.waves.enabled=false
|
battery.waves.enabled=true
|
||||||
|
everything-hidden=true
|
@ -0,0 +1,4 @@
|
|||||||
|
clock.colorful=false
|
||||||
|
clock.hands.long=false
|
||||||
|
jokes.visible=true
|
||||||
|
battery.waves.enabled=false
|
Loading…
x
Reference in New Issue
Block a user