ConfigWindow III
This commit is contained in:
parent
c59a27d1a1
commit
1ed924fe08
@ -53,7 +53,7 @@ public class CommandActionListener
|
||||
Visibility.WEAKLY_COLORED.name());
|
||||
break;
|
||||
case "waves":
|
||||
timeCalcConfiguration.batteryWavesEnabledProperty
|
||||
timeCalcConfiguration.batteryWavesVisibleProperty
|
||||
.setValue(commandsAsArray[1].equals("1"));
|
||||
break;
|
||||
case "uptime":
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.nanoboot.utils.timecalc.app;
|
||||
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.swing.common.MainWindow;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Constants;
|
||||
import org.nanoboot.utils.timecalc.utils.common.FileConstants;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||
@ -63,8 +64,8 @@ public class TimeCalcApp {
|
||||
Utils.writeTextToFile(FileConstants.STARTTIME_TXT, newStartTime);
|
||||
Utils.writeTextToFile(FileConstants.OVERTIME_TXT, newOvertime);
|
||||
try {
|
||||
TimeCalcManager timeCalc =
|
||||
new TimeCalcManager(newStartTime, newOvertime, this);
|
||||
MainWindow timeCalc =
|
||||
new MainWindow(newStartTime, newOvertime, this);
|
||||
} catch (Exception e) {
|
||||
JOptionPane.showMessageDialog(null, "Error: " + e.getMessage(),
|
||||
e.getMessage(), JOptionPane.ERROR_MESSAGE);
|
||||
|
@ -1,64 +1,100 @@
|
||||
package org.nanoboot.utils.timecalc.app;
|
||||
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
|
||||
import org.nanoboot.utils.timecalc.utils.property.Property;
|
||||
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Robert Vokac
|
||||
* @since 20.02.2024
|
||||
*/
|
||||
public class TimeCalcConfiguration {
|
||||
public final BooleanProperty clockHandLongProperty =
|
||||
new BooleanProperty("clockHandLongProperty", true);
|
||||
public final BooleanProperty clockHandMinuteEnabledProperty =
|
||||
new BooleanProperty("clockHandMinuteEnabledProperty", true);
|
||||
public final BooleanProperty clockHandSecondEnabledProperty =
|
||||
new BooleanProperty("clockHandSecondEnabledProperty", true);
|
||||
public final BooleanProperty clockHandMillisecondEnabledProperty =
|
||||
new BooleanProperty("clockHandMillisecondEnabledProperty", false);
|
||||
public final BooleanProperty batteryWavesEnabledProperty =
|
||||
new BooleanProperty("batteryWavesEnabledProperty", true);
|
||||
public final StringProperty
|
||||
visibilityCurrentProperty =
|
||||
new StringProperty("defaultVisibilityProperty",
|
||||
Visibility.STRONGLY_COLORED.name());
|
||||
public final BooleanProperty visibilityOnlyGreyOrNoneEnabledProperty =
|
||||
new BooleanProperty("visibilityOnlyGreyOrNoneEnabledProperty",
|
||||
false);
|
||||
public final BooleanProperty jokesEnabledProperty =
|
||||
new BooleanProperty("jokesEnabledProperty", true);
|
||||
public final BooleanProperty commandsEnabledProperty =
|
||||
new BooleanProperty("commandsEnabledProperty", true);
|
||||
public final BooleanProperty toastsEnabledProperty =
|
||||
new BooleanProperty("toastsEnabledProperty", true);
|
||||
public final StringProperty visibilityDefaultProperty = new StringProperty(TimeCalcProperty.VISIBILITY_DEFAULT
|
||||
.getKey());
|
||||
public final BooleanProperty visibilitySupportedColoredProperty =
|
||||
new BooleanProperty(TimeCalcProperty.VISIBILITY_SUPPORTED_COLORED
|
||||
.getKey());
|
||||
//
|
||||
public final BooleanProperty clockHandsLongVisibleProperty =
|
||||
new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_LONG_VISIBLE
|
||||
.getKey());
|
||||
public final BooleanProperty clockHandsMinuteVisibleProperty =
|
||||
new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_MINUTE_VISIBLE
|
||||
.getKey());
|
||||
public final BooleanProperty clockHandsSecondVisibleProperty =
|
||||
new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_SECOND_VISIBLE
|
||||
.getKey());
|
||||
public final BooleanProperty clockHandsMillisecondVisibleProperty =
|
||||
new BooleanProperty(TimeCalcProperty.CLOCK_HANDS_MILLISECOND_VISIBLE
|
||||
.getKey());
|
||||
//
|
||||
public final BooleanProperty batteryWavesVisibleProperty =
|
||||
new BooleanProperty(TimeCalcProperty.BATTERY_WAVES_VISIBLE
|
||||
.getKey());
|
||||
|
||||
public final BooleanProperty jokesVisibleProperty =
|
||||
new BooleanProperty(TimeCalcProperty.JOKES_VISIBLE
|
||||
.getKey());
|
||||
public final BooleanProperty commandsVisibleProperty =
|
||||
new BooleanProperty(TimeCalcProperty.COMMANDS_VISIBLE
|
||||
.getKey());
|
||||
public final BooleanProperty notificationsVisibleProperty =
|
||||
new BooleanProperty(TimeCalcProperty.NOTIFICATIONS_VISIBLE
|
||||
.getKey());
|
||||
public final BooleanProperty smileysColoredProperty =
|
||||
new BooleanProperty("smileysColoredProperty", true);
|
||||
new BooleanProperty(TimeCalcProperty.SMILEYS_COLORED.getKey());
|
||||
|
||||
private final Map<TimeCalcProperty, Property> mapOfProperties = new HashMap<>();
|
||||
private List<Property> allProperties = new ArrayList<>();
|
||||
public TimeCalcConfiguration() {
|
||||
for(Property p:new Property[] {
|
||||
visibilityDefaultProperty,
|
||||
visibilitySupportedColoredProperty,
|
||||
clockHandsLongVisibleProperty,
|
||||
clockHandsSecondVisibleProperty,
|
||||
clockHandsMillisecondVisibleProperty,
|
||||
batteryWavesVisibleProperty,
|
||||
jokesVisibleProperty,
|
||||
commandsVisibleProperty,
|
||||
notificationsVisibleProperty,
|
||||
smileysColoredProperty,
|
||||
}) {
|
||||
allProperties.add(p);
|
||||
}
|
||||
allProperties.stream().forEach(p -> mapOfProperties.put(TimeCalcProperty.forKey(p.getName()), p));
|
||||
}
|
||||
|
||||
public Property getProperty(TimeCalcProperty timeCalcProperty) {
|
||||
if(!mapOfProperties.containsKey(timeCalcProperty)) {
|
||||
throw new TimeCalcException("There is no property for : " + timeCalcProperty);
|
||||
}
|
||||
return mapOfProperties.get(timeCalcProperty);
|
||||
}
|
||||
|
||||
public void setFromTimeCalcProperties(
|
||||
TimeCalcProperties timeCalcProperties) {
|
||||
clockHandLongProperty.setValue(timeCalcProperties.areClockHandsLong());
|
||||
clockHandMinuteEnabledProperty
|
||||
.setValue(timeCalcProperties.isMinuteEnabled());
|
||||
clockHandSecondEnabledProperty
|
||||
.setValue(timeCalcProperties.isSecondEnabled());
|
||||
clockHandMillisecondEnabledProperty
|
||||
.setValue(timeCalcProperties.isMillisecondEnabled());
|
||||
batteryWavesEnabledProperty
|
||||
.setValue(timeCalcProperties.areBatteryWavesEnabled());
|
||||
visibilityCurrentProperty
|
||||
.setValue(timeCalcProperties.getVisibilityCurrent().name());
|
||||
visibilityOnlyGreyOrNoneEnabledProperty.setValue(
|
||||
timeCalcProperties.isVisibilityOnlyGreyOrNoneEnabled());
|
||||
jokesEnabledProperty.setValue(timeCalcProperties.areJokesEnabled());
|
||||
commandsEnabledProperty
|
||||
.setValue(timeCalcProperties.areCommandsEnabled());
|
||||
toastsEnabledProperty.setValue(timeCalcProperties.areToastsEnabled());
|
||||
smileysColoredProperty.setValue(timeCalcProperties.areSmileysColored());
|
||||
for(Property p:allProperties) {
|
||||
if(p instanceof BooleanProperty) {
|
||||
((BooleanProperty)p).setValue(timeCalcProperties.getBooleanProperty(TimeCalcProperty.forKey(p.getName())));
|
||||
continue;
|
||||
}
|
||||
|
||||
if(p.getName().equals(TimeCalcProperty.VISIBILITY_DEFAULT.name())) {
|
||||
visibilityDefaultProperty.setValue(timeCalcProperties.getStringProperty(TimeCalcProperty.VISIBILITY_DEFAULT));
|
||||
continue;
|
||||
}
|
||||
if(p instanceof StringProperty) {
|
||||
((StringProperty)p).setValue(timeCalcProperties.getStringProperty(TimeCalcProperty.forKey(p.getName())));
|
||||
continue;
|
||||
}
|
||||
throw new TimeCalcException("Unsupported Property class: " + p.getClass().getName());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
|
||||
|
||||
public void keyPressed(KeyEvent e) {
|
||||
boolean onlyGreyOrNone =
|
||||
timeCalcConfiguration.visibilityOnlyGreyOrNoneEnabledProperty
|
||||
timeCalcConfiguration.visibilitySupportedColoredProperty
|
||||
.isEnabled();
|
||||
Visibility visibility = Visibility
|
||||
.valueOf(timeCalcApp.visibilityProperty.getValue());
|
||||
|
@ -1,10 +1,14 @@
|
||||
package org.nanoboot.utils.timecalc.app;
|
||||
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
@ -12,25 +16,10 @@ import java.util.Properties;
|
||||
* @since 20.02.2024
|
||||
*/
|
||||
public class TimeCalcProperties {
|
||||
private static final String CLOCK_HANDS_LONG = "clock.hands.long";
|
||||
private static final String CLOCK_HANDS_MINUTE_ENABLED =
|
||||
"clock.hands.minute.enabled";
|
||||
private static final String CLOCK_HANDS_SECOND_ENABLED =
|
||||
"clock.hands.second.enabled";
|
||||
private static final String CLOCK_HANDS_MILLISECOND_ENABLED =
|
||||
"clock.hands.millisecond.enabled";
|
||||
private static final String BATTERY_WAVES_ENABLED = "battery.waves.enabled";
|
||||
private static final String VISIBILITY_CURRENT = "visibility.current";
|
||||
private static final String VISIBILITY_ONLY_GREY_OR_NONE_ENABLED =
|
||||
"visibility.only-grey-or-none.enabled";
|
||||
private static final String JOKES_ENABLED = "jokes.enabled";
|
||||
private static final String COMMANDS_ENABLED = "commands-enabled";
|
||||
private static final String TOASTS_ENABLED = "toasts.enabled";
|
||||
private static final String SMILEYS_COLORED = "smileys.colored";
|
||||
|
||||
|
||||
private static TimeCalcProperties INSTANCE;
|
||||
private final Properties properties = new Properties();
|
||||
private final Map<String, String> defaultProperties = new HashMap<>();
|
||||
|
||||
private TimeCalcProperties() {
|
||||
if (!new File("timecalc.conf").exists()) {
|
||||
@ -42,6 +31,22 @@ public class TimeCalcProperties {
|
||||
} catch (IOException e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
try {
|
||||
String defaultConfiguration = Utils.readTextFromTextResourceInJar(
|
||||
"timecalc-default.conf");
|
||||
Arrays.stream(defaultConfiguration.split("\n"))
|
||||
.filter(l -> !l.trim().isEmpty())
|
||||
.filter(l -> !l.trim().startsWith("#"))
|
||||
.filter(l -> l.contains("="))
|
||||
.forEach(l -> {
|
||||
String[] array = l.split("=");
|
||||
defaultProperties.put(array[0], array[1]);
|
||||
});
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new TimeCalcException(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -52,59 +57,59 @@ public class TimeCalcProperties {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public boolean areClockHandsLong() {
|
||||
return getBooleanProperty(CLOCK_HANDS_LONG, true);
|
||||
public boolean getBooleanProperty(TimeCalcProperty timeCalcProperty) {
|
||||
return getBooleanProperty(timeCalcProperty, Boolean.valueOf(
|
||||
getDefaultStringValue(timeCalcProperty)));
|
||||
}
|
||||
|
||||
public boolean isMinuteEnabled() {
|
||||
return getBooleanProperty(CLOCK_HANDS_MINUTE_ENABLED, true);
|
||||
}
|
||||
public boolean isSecondEnabled() {
|
||||
return getBooleanProperty(CLOCK_HANDS_SECOND_ENABLED, true);
|
||||
}
|
||||
|
||||
public boolean isMillisecondEnabled() {
|
||||
return getBooleanProperty(CLOCK_HANDS_MILLISECOND_ENABLED, false);
|
||||
}
|
||||
|
||||
public boolean areJokesEnabled() {
|
||||
return getBooleanProperty(COMMANDS_ENABLED, true);
|
||||
}
|
||||
|
||||
public boolean areBatteryWavesEnabled() {
|
||||
return getBooleanProperty(BATTERY_WAVES_ENABLED, true);
|
||||
}
|
||||
|
||||
public boolean areToastsEnabled() {
|
||||
return getBooleanProperty(TOASTS_ENABLED, true);
|
||||
}
|
||||
|
||||
public boolean areSmileysColored() {
|
||||
return getBooleanProperty(SMILEYS_COLORED, true);
|
||||
}
|
||||
|
||||
public Visibility getVisibilityCurrent() {
|
||||
if (!properties.containsKey(VISIBILITY_CURRENT)) {
|
||||
return Visibility.STRONGLY_COLORED;
|
||||
private String getDefaultStringValue(TimeCalcProperty timeCalcProperty) {
|
||||
if(!defaultProperties.containsKey(timeCalcProperty.getKey())) {
|
||||
throw new TimeCalcException("timecalc-default.conf is missing key: " + timeCalcProperty.getKey());
|
||||
}
|
||||
return Visibility.valueOf((String) properties.get(VISIBILITY_CURRENT));
|
||||
return defaultProperties.get(timeCalcProperty.getKey());
|
||||
}
|
||||
|
||||
public boolean isVisibilityOnlyGreyOrNoneEnabled() {
|
||||
return getBooleanProperty(VISIBILITY_ONLY_GREY_OR_NONE_ENABLED, false);
|
||||
}
|
||||
|
||||
public Boolean areCommandsEnabled() {
|
||||
return getBooleanProperty(COMMANDS_ENABLED, true);
|
||||
}
|
||||
|
||||
private boolean getBooleanProperty(String key, boolean defaultValue) {
|
||||
private boolean getBooleanProperty(TimeCalcProperty timeCalcProperty,
|
||||
Boolean defaultValue) {
|
||||
String key = timeCalcProperty.getKey();
|
||||
if (!properties.containsKey(key)) {
|
||||
return defaultValue;
|
||||
}
|
||||
return properties.get(key).equals("true");
|
||||
}
|
||||
|
||||
public String getStringProperty(TimeCalcProperty timeCalcProperty) {
|
||||
return getStringProperty(timeCalcProperty, getDefaultStringValue(timeCalcProperty));
|
||||
}
|
||||
private String getStringProperty(TimeCalcProperty timeCalcProperty,
|
||||
String defaultValue) {
|
||||
String key = timeCalcProperty.getKey();
|
||||
if (!properties.containsKey(key)) {
|
||||
return defaultValue;
|
||||
}
|
||||
return (String) properties.get(key);
|
||||
}
|
||||
|
||||
private String getVisibilityProperty(TimeCalcProperty timeCalcProperty) {
|
||||
return getStringProperty(timeCalcProperty, Visibility.STRONGLY_COLORED.name());
|
||||
}
|
||||
|
||||
private void setBooleanProperty(TimeCalcProperty timeCalcProperty,
|
||||
Boolean value) {
|
||||
String key = timeCalcProperty.getKey();
|
||||
properties.replace(key, value.toString());
|
||||
}
|
||||
|
||||
private void setStringProperty(TimeCalcProperty timeCalcProperty,
|
||||
String value) {
|
||||
String key = timeCalcProperty.getKey();
|
||||
properties.replace(key, value);
|
||||
}
|
||||
|
||||
private void setVisibilityProperty(TimeCalcProperty timeCalcProperty,
|
||||
Visibility value) {
|
||||
String key = timeCalcProperty.getKey();
|
||||
properties.replace(key, value.name());
|
||||
}
|
||||
|
||||
public void load() {
|
||||
//to be implemented
|
||||
}
|
||||
|
@ -0,0 +1,61 @@
|
||||
package org.nanoboot.utils.timecalc.app;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author Robert Vokac
|
||||
* @since 20.02.2024
|
||||
*/
|
||||
public enum TimeCalcProperty {
|
||||
VISIBILITY_DEFAULT("visibility.default", "Default Visibility"),
|
||||
VISIBILITY_SUPPORTED_COLORED("visibility.supported.colored", "Visibility : Supported : Colored"),
|
||||
//
|
||||
CLOCK_HANDS_LONG_VISIBLE("clock.hands.long.visible", "Visibility : Clock : Hands are long"),
|
||||
CLOCK_HANDS_MINUTE_VISIBLE("clock.hands.minute.visible", "Visibility : Clock : Minute hand"),
|
||||
CLOCK_HANDS_SECOND_VISIBLE("clock.hands.second.visible", "Visibility : Clock : Second hand"),
|
||||
CLOCK_HANDS_MILLISECOND_VISIBLE("clock.hands.millisecond.visible", "Visibility : Clock : Millisecond hand"),
|
||||
//
|
||||
BATTERY_WAVES_VISIBLE("battery.waves.visible", "Visibility : Battery : Waves"),
|
||||
JOKES_VISIBLE("jokes.visible", "Visibility : Jokes"),
|
||||
COMMANDS_VISIBLE("commands.visible", "Visibility : Commands"),
|
||||
NOTIFICATIONS_VISIBLE("notifications.visible", "Visibility : Toasts"),
|
||||
SMILEYS_COLORED("smileys.colored", "Visibility : Smileys");
|
||||
|
||||
@Getter
|
||||
private final String key;
|
||||
@Getter
|
||||
private final String description;
|
||||
@Getter
|
||||
private final Class clazz;
|
||||
|
||||
public static TimeCalcProperty forKey(String key) {
|
||||
Optional<TimeCalcProperty>
|
||||
timeCalcPropertyOptional = Arrays.stream(values()).filter(t -> t.getKey().equals(key)).findFirst();
|
||||
if(timeCalcPropertyOptional.isPresent()) {
|
||||
return timeCalcPropertyOptional.get();
|
||||
} else {
|
||||
TimeCalcException e =
|
||||
new TimeCalcException("There is no key: " + key);
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
TimeCalcProperty(String key, String description, Class clazz) {
|
||||
this.key = key;
|
||||
this.description = description;
|
||||
this.clazz = clazz;
|
||||
}
|
||||
TimeCalcProperty(String key, String description) {
|
||||
this(key, description, Boolean.class);
|
||||
}
|
||||
|
||||
}
|
@ -12,6 +12,7 @@ import lombok.ToString;
|
||||
@Setter
|
||||
@ToString
|
||||
public class Activity {
|
||||
public static final String SUBJECT_FIELD_SEPARATOR = " : ";
|
||||
private int year;
|
||||
private int month;
|
||||
private int day;
|
||||
@ -22,5 +23,11 @@ public class Activity {
|
||||
private int spentMinutes;
|
||||
private boolean jira;
|
||||
private boolean bugzilla;
|
||||
public String createSubject() {
|
||||
return ticket + SUBJECT_FIELD_SEPARATOR + name;
|
||||
}
|
||||
public String createBugzillaComment() {
|
||||
return ticket + SUBJECT_FIELD_SEPARATOR + year + "-" + month + "-" + day + SUBJECT_FIELD_SEPARATOR + ((spentHours + spentMinutes / 60d) + "h") + SUBJECT_FIELD_SEPARATOR + comment;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
package org.nanoboot.utils.timecalc.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ActivityForStats extends Activity {
|
||||
|
||||
private int todaySpentHours;
|
||||
private int todaySpentMinutes;
|
||||
private int todayRemainsHours;
|
||||
private int todayRemainsMinutes;
|
||||
|
||||
public ActivityForStats() {
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package org.nanoboot.utils.timecalc.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* @author Robert Vokac
|
||||
* @since 23.02.2024
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class WorkDay {
|
||||
|
||||
private int year;
|
||||
private int month;
|
||||
private int day;
|
||||
private int arrivalHour;
|
||||
private int arrivalMinute;
|
||||
private int overtimeHour;
|
||||
private int overtimeMinute;
|
||||
private String note;
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package org.nanoboot.utils.timecalc.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class WorkDayForStats extends WorkDay {
|
||||
|
||||
private int departureHour;
|
||||
private int departureMinute;
|
||||
private int dayOfWeek;
|
||||
private int remainingOvertimeHours;
|
||||
private int remainingOvertimeMinutes;
|
||||
private double arrivalTimeMovingAverage7Days;
|
||||
private double arrivalTimeMovingAverage14Days;
|
||||
private double arrivalTimeMovingAverage28Days;
|
||||
private double arrivalTimeMovingAverage56Days;
|
||||
public WorkDayForStats() {
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package org.nanoboot.utils.timecalc.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* @author Robert Vokac
|
||||
* @since 23.02.2024
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class WorkingDay {
|
||||
private int year;
|
||||
private int month;
|
||||
private int day;
|
||||
private int arrivalHour;
|
||||
private int arrivalMinute;
|
||||
private int departureHour;
|
||||
private int departureMinute;
|
||||
private String note;
|
||||
private int overtimeHoursThisDay;
|
||||
private int overtimeMinutesThisDay;
|
||||
private int compensatoryTimeOffHoursThisDay;
|
||||
private int compensatoryTimeOffMinutesThisDay;
|
||||
private int overtimeHoursToBeCompensatedUntilThisDay;
|
||||
private int overtimeMinutesToBeCompensatedUntilThisDay;
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package org.nanoboot.utils.timecalc.swing.common;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
/**
|
||||
* @author Robert Vokac
|
||||
* @since 16.02.2024
|
||||
*/
|
||||
public class ActivitiesWindow extends TimeCalcWindow {
|
||||
|
||||
public ActivitiesWindow() {
|
||||
setSize(800, 600);
|
||||
setTitle("Activities");
|
||||
}
|
||||
}
|
@ -1,112 +1,125 @@
|
||||
package org.nanoboot.utils.timecalc.swing.common;
|
||||
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcConfiguration;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
|
||||
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Robert Vokac
|
||||
* @since 16.02.2024
|
||||
*/
|
||||
public class ConfigWindow extends JFrame {
|
||||
public class ConfigWindow extends TimeCalcWindow {
|
||||
public static final int WIDTH1 = 600;
|
||||
public static final int HEIGHT1 = 30;
|
||||
public static final String CLIENT_PROPERTY_KEY = TimeCalcProperty.class.getName();
|
||||
private final TimeCalcConfiguration timeCalcConfiguration;
|
||||
private int currentY = SwingUtils.MARGIN;;
|
||||
private JCheckBox clockHandLongProperty = new JCheckBox("Visibility : Clock : Hands are long", true);
|
||||
private JCheckBox clockHandMinuteEnabledProperty = new JCheckBox("Visibility : Clock : Minute hand", true);
|
||||
private JCheckBox clockHandSecondEnabledProperty = new JCheckBox("Visibility : Clock : Second hand", true);
|
||||
private JCheckBox clockHandMillisecondEnabledProperty = new JCheckBox("Visibility : Clock : Millisecond hand", false);
|
||||
private JCheckBox batteryWavesEnabledProperty = new JCheckBox("Visibility : Battery : Waves", true);
|
||||
public final JComboBox visibilityCurrentProperty = new JComboBox(
|
||||
Arrays.stream(Visibility.values()).map(v->v.name()).collect(
|
||||
private int currentY = SwingUtils.MARGIN;
|
||||
private List<JComponent> propertiesList = new ArrayList<>();
|
||||
private Map<TimeCalcProperty, JComponent> propertiesMap = new HashMap<>();
|
||||
public final JComboBox visibilityDefaultProperty = new JComboBox(Arrays.stream(Visibility.values()).map(v -> v.name()).collect(
|
||||
Collectors.toList()).toArray());
|
||||
|
||||
private JCheckBox visibilityOnlyGreyOrNoneEnabledProperty = new JCheckBox("Visibility : Only GREY or NONE",
|
||||
false);
|
||||
private JCheckBox jokesEnabledProperty = new JCheckBox("Visibility : Jokes", true);
|
||||
private JCheckBox commandsEnabledProperty = new JCheckBox("Visibility : Commands", true);
|
||||
private JCheckBox toastsEnabledProperty = new JCheckBox("Visibility : Toasts", true);
|
||||
private JCheckBox smileysColoredProperty = new JCheckBox("Visibility : Smileys", true);
|
||||
private JCheckBox visibilitySupportedColoredProperty =
|
||||
new JCheckBox("visibility.supported.colored");
|
||||
private JCheckBox clockHandsLongVisibleProperty =
|
||||
new JCheckBox("clock.hands.long.visible");
|
||||
private JCheckBox clockHandsMinuteVisibleProperty =
|
||||
new JCheckBox("clock.hands.minute.visible");
|
||||
private JCheckBox clockHandsSecondVisibleProperty =
|
||||
new JCheckBox("clock.hands.second.visible");
|
||||
private JCheckBox clockHandsMillisecondVisibleProperty =
|
||||
new JCheckBox("clock.hands.millisecond.visible");
|
||||
private JCheckBox batteryWavesVisibleProperty =
|
||||
new JCheckBox("battery.waves.visible");
|
||||
|
||||
private JCheckBox jokesVisibleProperty =
|
||||
new JCheckBox("jokes.visible");
|
||||
private JCheckBox commandsVisibleProperty =
|
||||
new JCheckBox("commands.visible");
|
||||
private JCheckBox notificationsVisibleProperty =
|
||||
new JCheckBox("notifications.visible");
|
||||
private JCheckBox smileysColoredProperty =
|
||||
new JCheckBox("smileys.colored");
|
||||
|
||||
public ConfigWindow(TimeCalcConfiguration timeCalcConfiguration) {
|
||||
this.timeCalcConfiguration = timeCalcConfiguration;
|
||||
setTitle("Configuration");
|
||||
this.setSize(800, WIDTH1);
|
||||
|
||||
setLayout(null);
|
||||
|
||||
add(clockHandLongProperty);
|
||||
clockHandLongProperty.setBounds(SwingUtils.MARGIN, currentY, WIDTH1,
|
||||
propertiesList.addAll(Arrays.asList(visibilityDefaultProperty,
|
||||
visibilitySupportedColoredProperty,
|
||||
clockHandsLongVisibleProperty,
|
||||
clockHandsMinuteVisibleProperty,
|
||||
clockHandsSecondVisibleProperty,
|
||||
clockHandsMillisecondVisibleProperty,
|
||||
batteryWavesVisibleProperty,
|
||||
jokesVisibleProperty,
|
||||
commandsVisibleProperty,
|
||||
notificationsVisibleProperty,
|
||||
smileysColoredProperty));
|
||||
//
|
||||
propertiesList.stream().forEach(p -> {
|
||||
if(p == visibilityDefaultProperty) {
|
||||
p.putClientProperty(CLIENT_PROPERTY_KEY, TimeCalcProperty.VISIBILITY_DEFAULT.getKey());
|
||||
addToNextRow(new JLabel(TimeCalcProperty.VISIBILITY_DEFAULT.getDescription()));
|
||||
}
|
||||
if(p instanceof JComboBox) {
|
||||
JComboBox jComboBox = ((JComboBox)p);
|
||||
jComboBox.setMaximumSize(new Dimension(150, 25));
|
||||
|
||||
String timeCalcPropertyKey = (String) jComboBox.getClientProperty(
|
||||
CLIENT_PROPERTY_KEY);
|
||||
TimeCalcProperty timeCalcProperty =
|
||||
TimeCalcProperty.forKey(timeCalcPropertyKey);
|
||||
jComboBox.addActionListener(e -> {
|
||||
((StringProperty) timeCalcConfiguration.getProperty(timeCalcProperty))
|
||||
.setValue(
|
||||
(String) jComboBox.getSelectedItem());
|
||||
System.out.println("configWindow.visibilityCurrentProperty="
|
||||
+ visibilityDefaultProperty.getSelectedItem());
|
||||
});
|
||||
}
|
||||
|
||||
if(p instanceof JCheckBox) {
|
||||
JCheckBox checkBox = ((JCheckBox)p);
|
||||
String timeCalcPropertyKey = checkBox.getText();
|
||||
checkBox.putClientProperty(CLIENT_PROPERTY_KEY, timeCalcPropertyKey);
|
||||
TimeCalcProperty timeCalcProperty =
|
||||
TimeCalcProperty.forKey(timeCalcPropertyKey);
|
||||
checkBox.setText(timeCalcProperty.getDescription());
|
||||
checkBox.addActionListener(e -> {
|
||||
((BooleanProperty)timeCalcConfiguration.getProperty(timeCalcProperty))
|
||||
.setValue(checkBox.isSelected());
|
||||
});
|
||||
}
|
||||
propertiesMap.put(TimeCalcProperty.forKey(
|
||||
(String) p.getClientProperty(CLIENT_PROPERTY_KEY)),p);
|
||||
addToNextRow(p);
|
||||
});
|
||||
|
||||
Arrays.stream(getComponents()).forEach(c->c.getClass().getName());
|
||||
|
||||
}
|
||||
|
||||
private void addToNextRow(JComponent jComponent) {
|
||||
jComponent.setBounds(SwingUtils.MARGIN, currentY, WIDTH1,
|
||||
HEIGHT1);
|
||||
nextRow();
|
||||
|
||||
add(clockHandMinuteEnabledProperty);
|
||||
clockHandMinuteEnabledProperty.setBounds(SwingUtils.MARGIN, currentY,
|
||||
WIDTH1, HEIGHT1);
|
||||
nextRow();
|
||||
|
||||
add(clockHandSecondEnabledProperty);
|
||||
clockHandSecondEnabledProperty.setBounds(SwingUtils.MARGIN, currentY,
|
||||
WIDTH1, HEIGHT1);
|
||||
nextRow();
|
||||
|
||||
add(clockHandMillisecondEnabledProperty);
|
||||
clockHandMillisecondEnabledProperty.setBounds(SwingUtils.MARGIN, currentY,
|
||||
WIDTH1, HEIGHT1);
|
||||
nextRow();
|
||||
|
||||
add(batteryWavesEnabledProperty);
|
||||
batteryWavesEnabledProperty.setBounds(SwingUtils.MARGIN, currentY,
|
||||
WIDTH1, HEIGHT1);
|
||||
nextRow();
|
||||
JLabel visibilityCurrentLabel = new JLabel("Visibility : Current");
|
||||
|
||||
add(visibilityCurrentLabel);
|
||||
visibilityCurrentLabel.setBounds(SwingUtils.MARGIN, currentY, WIDTH1,
|
||||
HEIGHT1);
|
||||
nextRow();
|
||||
|
||||
add(visibilityCurrentProperty);
|
||||
visibilityCurrentProperty.setMaximumSize(new Dimension(150, 25));
|
||||
visibilityCurrentProperty.setBounds(SwingUtils.MARGIN, currentY, WIDTH1,
|
||||
HEIGHT1);
|
||||
nextRow();
|
||||
|
||||
clockHandLongProperty.addActionListener(e -> {
|
||||
timeCalcConfiguration.clockHandLongProperty.setValue(clockHandLongProperty.isSelected());
|
||||
});
|
||||
clockHandMinuteEnabledProperty.addActionListener(e -> {
|
||||
timeCalcConfiguration.clockHandMinuteEnabledProperty.setValue(clockHandMinuteEnabledProperty.isSelected());
|
||||
});
|
||||
clockHandSecondEnabledProperty.addActionListener(e -> {
|
||||
timeCalcConfiguration.clockHandSecondEnabledProperty.setValue(clockHandSecondEnabledProperty.isSelected());
|
||||
});
|
||||
clockHandMillisecondEnabledProperty.addActionListener(e -> {
|
||||
timeCalcConfiguration.clockHandMillisecondEnabledProperty.setValue(clockHandMillisecondEnabledProperty.isSelected());
|
||||
});
|
||||
batteryWavesEnabledProperty.addActionListener(e -> {
|
||||
timeCalcConfiguration.batteryWavesEnabledProperty.setValue(batteryWavesEnabledProperty.isSelected());
|
||||
});
|
||||
|
||||
visibilityCurrentProperty.addActionListener(e -> {
|
||||
timeCalcConfiguration.visibilityCurrentProperty.setValue(
|
||||
(String) visibilityCurrentProperty.getSelectedItem());
|
||||
System.out.println("configWindow.visibilityCurrentProperty=" + visibilityCurrentProperty.getSelectedItem());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void nextRow() {
|
||||
|
@ -1,411 +1,451 @@
|
||||
package org.nanoboot.utils.timecalc.app;
|
||||
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.swing.common.AboutButton;
|
||||
import org.nanoboot.utils.timecalc.swing.common.ComponentRegistry;
|
||||
import org.nanoboot.utils.timecalc.swing.common.ConfigWindow;
|
||||
import org.nanoboot.utils.timecalc.swing.common.SwingUtils;
|
||||
import org.nanoboot.utils.timecalc.swing.common.TimeCalcButton;
|
||||
import org.nanoboot.utils.timecalc.swing.common.TimeCalcWindow;
|
||||
import org.nanoboot.utils.timecalc.swing.common.Toaster;
|
||||
import org.nanoboot.utils.timecalc.swing.common.WeatherWindow;
|
||||
import org.nanoboot.utils.timecalc.swing.common.Widget;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.AnalogClock;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.Battery;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.DayBattery;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.HourBattery;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.MonthBattery;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.ProgressCircle;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.ProgressSquare;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.Time;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.WalkingHumanProgressAsciiArt;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.WeekBattery;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Constants;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Jokes;
|
||||
import org.nanoboot.utils.timecalc.utils.common.TimeHM;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||
import org.nanoboot.utils.timecalc.utils.property.IntegerProperty;
|
||||
import org.nanoboot.utils.timecalc.utils.property.Property;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author Robert Vokac
|
||||
* @since 08.02.2024
|
||||
*/
|
||||
public class TimeCalcManager {
|
||||
public static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
|
||||
public static final Color FOREGROUND_COLOR = new Color(210, 210, 210);
|
||||
private ConfigWindow configWindow = null;
|
||||
|
||||
private boolean stopBeforeEnd = false;
|
||||
private final TimeCalcConfiguration timeCalcConfiguration =
|
||||
new TimeCalcConfiguration();
|
||||
|
||||
public TimeCalcManager(String startTimeIn, String overTimeIn,
|
||||
TimeCalcApp timeCalcApp) {
|
||||
timeCalcConfiguration
|
||||
.setFromTimeCalcProperties(TimeCalcProperties.getInstance());
|
||||
|
||||
overTimeIn = (overTimeIn == null || overTimeIn.isEmpty()) ?
|
||||
Constants.DEFAULT_OVERTIME : overTimeIn;
|
||||
|
||||
TimeHM startTime = new TimeHM(startTimeIn);
|
||||
TimeHM overtime = new TimeHM(overTimeIn);
|
||||
|
||||
TimeHM endTime = new TimeHM(
|
||||
startTime.getHour() + Constants.WORKING_HOURS_LENGTH + overtime
|
||||
.getHour(),
|
||||
startTime.getMinute() + Constants.WORKING_MINUTES_LENGTH
|
||||
+ overtime.getMinute());
|
||||
|
||||
int totalMinutes = TimeHM.countDiffInMinutes(startTime, endTime);
|
||||
int totalSeconds = totalMinutes * TimeHM.SECONDS_PER_MINUTE;
|
||||
int totalMilliseconds = totalSeconds * TimeHM.MILLISECONDS_PER_SECOND;
|
||||
|
||||
TimeCalcWindow window = new TimeCalcWindow();
|
||||
|
||||
TimeCalcButton configButton = new TimeCalcButton("Config");
|
||||
TimeCalcButton commandButton = new TimeCalcButton("Command");
|
||||
TimeCalcButton weatherButton = new TimeCalcButton("Weather");
|
||||
TimeCalcButton jokeButton = new TimeCalcButton("Joke");
|
||||
TimeCalcButton restartButton = new TimeCalcButton("Restart");
|
||||
TimeCalcButton exitButton = new TimeCalcButton("Exit");
|
||||
AboutButton aboutButton = new AboutButton();
|
||||
|
||||
//window.add(weatherButton);
|
||||
window.addAll(configButton, commandButton, jokeButton, restartButton,
|
||||
exitButton);
|
||||
|
||||
if(timeCalcConfiguration.visibilityOnlyGreyOrNoneEnabledProperty.isEnabled()) {
|
||||
timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name());
|
||||
}
|
||||
timeCalcApp.visibilityProperty.bindTo(timeCalcConfiguration.visibilityCurrentProperty);
|
||||
TimeCalcKeyAdapter timeCalcKeyAdapter = new TimeCalcKeyAdapter(timeCalcConfiguration, timeCalcApp, commandButton, window);
|
||||
window.addKeyListener(timeCalcKeyAdapter);
|
||||
|
||||
AnalogClock analogClock = new AnalogClock(startTime, endTime);
|
||||
analogClock.setBounds(SwingUtils.MARGIN, SwingUtils.MARGIN, 200);
|
||||
window.add(analogClock);
|
||||
|
||||
ProgressSquare progressSquare = new ProgressSquare();
|
||||
progressSquare
|
||||
.setBounds(analogClock.getX() + analogClock.getWidth() + SwingUtils.MARGIN, analogClock.getY(),
|
||||
200);
|
||||
window.add(progressSquare);
|
||||
|
||||
ProgressCircle progressCircle = new ProgressCircle();
|
||||
progressCircle
|
||||
.setBounds(
|
||||
progressSquare.getX() + progressSquare.getWidth() + SwingUtils.MARGIN, progressSquare.getY(), 80);
|
||||
window.add(progressCircle);
|
||||
|
||||
WalkingHumanProgressAsciiArt walkingHumanProgressAsciiArt =
|
||||
new WalkingHumanProgressAsciiArt(analogClock.getX(), analogClock.getY() + analogClock.getHeight() + SwingUtils.MARGIN, 420, 180);
|
||||
window.add(walkingHumanProgressAsciiArt);
|
||||
weatherButton
|
||||
.setBounds(SwingUtils.MARGIN, walkingHumanProgressAsciiArt.getY()
|
||||
+ walkingHumanProgressAsciiArt.getHeight()
|
||||
+ SwingUtils.MARGIN);
|
||||
|
||||
configButton.setBoundsFromTop(walkingHumanProgressAsciiArt);
|
||||
commandButton.setBoundsFromLeft(configButton);
|
||||
|
||||
jokeButton.setBoundsFromLeft(commandButton);
|
||||
restartButton.setBoundsFromLeft(jokeButton);
|
||||
exitButton.setBoundsFromLeft(restartButton);
|
||||
aboutButton.setBounds(exitButton.getX(),
|
||||
exitButton.getY() + exitButton.getHeight() + SwingUtils.MARGIN);
|
||||
|
||||
window.setLayout(null);
|
||||
window.setVisible(true);
|
||||
|
||||
String windowTitle = "Time Calc " + Utils.getVersion();
|
||||
window.setTitle(windowTitle);
|
||||
|
||||
weatherButton
|
||||
.addActionListener(e -> new WeatherWindow().setVisible(true));
|
||||
commandButton.addActionListener(new CommandActionListener(timeCalcApp, timeCalcConfiguration));
|
||||
|
||||
jokeButton.addActionListener(e -> {
|
||||
for (int i = 1; i <= 1; i++) {
|
||||
Jokes.showRandom();
|
||||
}
|
||||
});
|
||||
exitButton.addActionListener(e -> System.exit(0));
|
||||
restartButton.addActionListener(e -> {
|
||||
window.setVisible(false);
|
||||
stopBeforeEnd = true;
|
||||
});
|
||||
|
||||
configButton.addActionListener(e -> {
|
||||
if(configWindow == null) {
|
||||
this.configWindow = new ConfigWindow(timeCalcConfiguration);
|
||||
}
|
||||
configWindow.setVisible(true);
|
||||
});
|
||||
Calendar calNow = Calendar.getInstance();
|
||||
calNow.setTime(new Date());
|
||||
|
||||
Properties testProperties = new Properties();
|
||||
File testPropertiesFile = new File("test.txt");
|
||||
try {
|
||||
if (testPropertiesFile.exists()) {
|
||||
testProperties.load(new FileInputStream(testPropertiesFile));
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(TimeCalcManager.class.getName())
|
||||
.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
Time time = new Time();
|
||||
|
||||
bindToIfPropertyMissing(testProperties, "test.current.day", calNow, Calendar.DAY_OF_MONTH, analogClock.dayProperty, time.dayProperty);
|
||||
bindToIfPropertyMissing(testProperties, "test.current.month", calNow, Calendar.MONTH, analogClock.monthProperty, time.monthProperty);
|
||||
bindToIfPropertyMissing(testProperties, "test.current.year", calNow, Calendar.YEAR, analogClock.yearProperty, time.yearProperty);
|
||||
bindToIfPropertyMissing(testProperties, "test.current.hour", calNow, Calendar.HOUR, analogClock.hourProperty, time.hourProperty);
|
||||
bindToIfPropertyMissing(testProperties, "test.current.minute", calNow, Calendar.MINUTE, analogClock.minuteProperty, time.minuteProperty);
|
||||
bindToIfPropertyMissing(testProperties, "test.current.second", calNow, Calendar.SECOND, analogClock.secondProperty, time.secondProperty);
|
||||
bindToIfPropertyMissing(testProperties, "test.current.millisecond", calNow, Calendar.MILLISECOND, analogClock.millisecondProperty, time.millisecondProperty);
|
||||
|
||||
if (testProperties.containsKey("test.current.year") || testProperties
|
||||
.containsKey("test.current.month") || testProperties
|
||||
.containsKey("test.current.day")) {
|
||||
analogClock.dayOfWeekProperty
|
||||
.setValue(calNow.get(Calendar.DAY_OF_WEEK));
|
||||
} else {
|
||||
analogClock.dayOfWeekProperty.bindTo(time.dayOfWeek);
|
||||
}
|
||||
|
||||
analogClock.millisecondEnabledProperty
|
||||
.bindTo(timeCalcConfiguration.clockHandMillisecondEnabledProperty);
|
||||
analogClock.secondEnabledProperty
|
||||
.bindTo(timeCalcConfiguration.clockHandSecondEnabledProperty);
|
||||
analogClock.minuteEnabledProperty
|
||||
.bindTo(timeCalcConfiguration.clockHandMinuteEnabledProperty);
|
||||
analogClock.handsLongProperty
|
||||
.bindTo(timeCalcConfiguration.clockHandLongProperty);
|
||||
|
||||
Battery hourBattery = new HourBattery(progressCircle.getBounds().x,
|
||||
progressCircle.getY() + SwingUtils.MARGIN + progressCircle.getHeight(),
|
||||
140);
|
||||
window.add(hourBattery);
|
||||
|
||||
Battery dayBattery = new DayBattery(hourBattery.getBounds().x + hourBattery.getWidth() + SwingUtils.MARGIN,
|
||||
hourBattery.getY(),
|
||||
140);
|
||||
window.add(dayBattery);
|
||||
|
||||
Battery weekBattery = new WeekBattery(
|
||||
hourBattery.getBounds().x,
|
||||
dayBattery.getY() + dayBattery.getHeight() + SwingUtils.MARGIN, 140);
|
||||
window.add(weekBattery);
|
||||
|
||||
int currentDayOfMonth = analogClock.dayProperty.getValue();
|
||||
|
||||
int workDaysDone = 0;
|
||||
int workDaysTodo = 0;
|
||||
int workDaysTotal;
|
||||
for (int dayOfMonth = 1;
|
||||
dayOfMonth <= calNow.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||
dayOfMonth++) {
|
||||
DayOfWeek dayOfWeek = LocalDate.of(analogClock.yearProperty.getValue(),
|
||||
analogClock.monthProperty.getValue(), 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;
|
||||
|
||||
Battery monthBattery = new MonthBattery(
|
||||
dayBattery.getBounds().x,
|
||||
weekBattery.getY(), 140);
|
||||
window.add(monthBattery);
|
||||
|
||||
ComponentRegistry<JComponent> componentRegistry = new ComponentRegistry();
|
||||
componentRegistry.addAll(
|
||||
walkingHumanProgressAsciiArt,
|
||||
progressSquare,
|
||||
progressCircle,
|
||||
analogClock,
|
||||
dayBattery,
|
||||
weekBattery,
|
||||
monthBattery,
|
||||
hourBattery,
|
||||
configButton,
|
||||
jokeButton,
|
||||
commandButton,
|
||||
restartButton,
|
||||
exitButton
|
||||
);
|
||||
ComponentRegistry<TimeCalcButton> buttonRegistry = new ComponentRegistry();
|
||||
componentRegistry.getSet().stream().filter(c-> c instanceof TimeCalcButton).forEach(c->
|
||||
buttonRegistry.add((TimeCalcButton)c));
|
||||
componentRegistry.getSet().stream().filter(c ->
|
||||
GetProperty.class.isAssignableFrom(c.getClass())).forEach(c->
|
||||
((GetProperty<String>)c).getProperty().bindTo(timeCalcApp.visibilityProperty));
|
||||
|
||||
componentRegistry.getSet().stream().filter(c-> c instanceof Battery).forEach(c ->
|
||||
((Battery)c).wavesProperty.bindTo(timeCalcConfiguration.batteryWavesEnabledProperty));
|
||||
|
||||
componentRegistry.getSet().stream().filter(c-> c instanceof Widget).forEach(c ->
|
||||
((Widget)c).smileysColoredProperty.bindTo(timeCalcConfiguration.smileysColoredProperty));
|
||||
window.setSize(dayBattery.getX() + dayBattery.getWidth() + 3 * SwingUtils.MARGIN,
|
||||
exitButton.getY() + 3 * exitButton.getHeight() + SwingUtils.MARGIN);
|
||||
while (true) {
|
||||
//System.out.println("timeCalcConfiguration.handsLongProperty=" + timeCalcConfiguration.clockHandLongProperty.isEnabled());
|
||||
Visibility currentVisibility = Visibility
|
||||
.valueOf(timeCalcApp.visibilityProperty.getValue());
|
||||
if(timeCalcConfiguration.visibilityOnlyGreyOrNoneEnabledProperty.isEnabled() && currentVisibility.isColored() ){
|
||||
timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name());
|
||||
}
|
||||
if (stopBeforeEnd) {
|
||||
if(configWindow != null) {configWindow.setVisible(false);configWindow.dispose();}
|
||||
window.setVisible(false);
|
||||
window.dispose();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
componentRegistry.setVisible(currentVisibility.isNotNone());
|
||||
|
||||
jokeButton.setVisible(
|
||||
TimeCalcProperties.getInstance().areJokesEnabled()
|
||||
&& !currentVisibility.isNone());
|
||||
|
||||
window.setTitle(currentVisibility.isNone() ? "" : windowTitle);
|
||||
|
||||
int hourNow = analogClock.hourProperty.getValue();
|
||||
int minuteNow = analogClock.minuteProperty.getValue();
|
||||
|
||||
int secondNow = analogClock.secondProperty.getValue();
|
||||
int millisecondNow = analogClock.millisecondProperty.getValue();
|
||||
TimeHM timeRemains = new TimeHM(endTime.getHour() - hourNow,
|
||||
endTime.getMinute() - minuteNow);
|
||||
|
||||
int secondsRemains = 60 - secondNow;
|
||||
int millisecondsRemains = 1000 - millisecondNow;
|
||||
|
||||
int hourDone = Constants.WORKING_HOURS_LENGTH + overtime.getHour()
|
||||
- timeRemains.getHour();
|
||||
int minutesDone =
|
||||
Constants.WORKING_MINUTES_LENGTH + overtime.getMinute()
|
||||
- timeRemains.getMinute();
|
||||
int secondsDone = secondNow;
|
||||
int millisecondsDone = millisecondNow;
|
||||
|
||||
int totalMinutesDone = hourDone * 60 + minutesDone;
|
||||
int totalSecondsDone = totalMinutesDone * 60 + secondsDone;
|
||||
int totalMillisecondsDone =
|
||||
totalSecondsDone * 1000 + millisecondsDone;
|
||||
|
||||
double done = ((double) totalMillisecondsDone)
|
||||
/ ((double) totalMilliseconds);
|
||||
progressSquare.setDonePercent(done);
|
||||
progressCircle.setDonePercent(done);
|
||||
dayBattery.setDonePercent(done);
|
||||
|
||||
int weekDayWhenMondayIsOne = calNow.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
weekBattery.setDonePercent(
|
||||
WeekBattery.getWeekProgress(weekDayWhenMondayIsOne, done));
|
||||
weekBattery.setLabel(
|
||||
nowIsWeekend ? "5/5" : (weekDayWhenMondayIsOne + "/5"));
|
||||
|
||||
monthBattery.setDonePercent(MonthBattery
|
||||
.getMonthProgress(weekDayWhenMondayIsOne, workDaysDone,
|
||||
workDaysTotal, done));
|
||||
monthBattery.setLabel(
|
||||
(nowIsWeekend ? workDaysDone : workDaysDone + 1) + "/"
|
||||
+ (workDaysTotal));
|
||||
|
||||
hourBattery.setDonePercent(
|
||||
HourBattery.getHourProgress(timeRemains, secondsRemains,
|
||||
millisecondsRemains));
|
||||
if (!nowIsWeekend) {
|
||||
hourBattery.setLabel(
|
||||
hourDone + "/" + (
|
||||
totalMinutes / 60));
|
||||
}
|
||||
|
||||
int totalSecondsRemains =
|
||||
(timeRemains.getHour() * 60 * 60
|
||||
+ timeRemains.getMinute() * 60
|
||||
+ secondsRemains);
|
||||
int totalMillisecondsRemains =
|
||||
totalSecondsRemains * 1000 + millisecondsRemains;
|
||||
double totalSecondsRemainsDouble =
|
||||
((double) totalMillisecondsRemains) / 1000;
|
||||
|
||||
if (timeRemains.getHour() <= 0 && timeRemains.getMinute() <= 0) {
|
||||
Toaster toasterManager = new Toaster();
|
||||
toasterManager.setDisplayTime(30000);
|
||||
toasterManager.showToaster(
|
||||
"Congratulation :-) It is the time to go home.");
|
||||
walkingHumanProgressAsciiArt
|
||||
.printPercentToAscii(done, timeRemains.getHour(),
|
||||
timeRemains.getMinute(), done,
|
||||
totalSecondsRemainsDouble, endTime);
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
while (!stopBeforeEnd) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
walkingHumanProgressAsciiArt
|
||||
.printPercentToAscii(done, timeRemains.getHour(),
|
||||
timeRemains.getMinute(), done,
|
||||
totalSecondsRemainsDouble, endTime);
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
if(configWindow != null) {configWindow.setVisible(false);configWindow.dispose();}
|
||||
window.setVisible(false);
|
||||
window.dispose();
|
||||
}
|
||||
|
||||
private void bindToIfPropertyMissing(Properties properties, String key, Calendar cal, int timeUnit, IntegerProperty firstProperty, Property secondProperty) {
|
||||
if (properties.containsKey(key)) {
|
||||
cal.set(timeUnit, Integer.parseInt(
|
||||
(String) properties.get(key)) + (timeUnit == Calendar.MONTH ? -1 : 0));
|
||||
firstProperty.setValue(Integer.valueOf(
|
||||
(String) properties.get(key)));
|
||||
} else {
|
||||
firstProperty.bindTo(secondProperty);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package org.nanoboot.utils.timecalc.swing.common;
|
||||
|
||||
import org.nanoboot.utils.timecalc.app.CommandActionListener;
|
||||
import org.nanoboot.utils.timecalc.app.GetProperty;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcApp;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcConfiguration;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcKeyAdapter;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcProperties;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.AnalogClock;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.Battery;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.DayBattery;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.HourBattery;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.MonthBattery;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.ProgressCircle;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.ProgressSquare;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.Time;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.WalkingHumanProgressAsciiArt;
|
||||
import org.nanoboot.utils.timecalc.swing.progress.WeekBattery;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Constants;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Jokes;
|
||||
import org.nanoboot.utils.timecalc.utils.common.TimeHM;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||
import org.nanoboot.utils.timecalc.utils.property.IntegerProperty;
|
||||
import org.nanoboot.utils.timecalc.utils.property.Property;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author Robert Vokac
|
||||
* @since 08.02.2024
|
||||
*/
|
||||
public class MainWindow extends TimeCalcWindow{
|
||||
|
||||
public static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
|
||||
public static final Color FOREGROUND_COLOR = new Color(210, 210, 210);
|
||||
private WorkDaysWindow workDaysWindow = null;
|
||||
private ConfigWindow configWindow = null;
|
||||
private ActivitiesWindow activitiesWindow = null;
|
||||
|
||||
private boolean stopBeforeEnd = false;
|
||||
private final TimeCalcConfiguration timeCalcConfiguration =
|
||||
new TimeCalcConfiguration();
|
||||
|
||||
public MainWindow(String startTimeIn, String overTimeIn,
|
||||
TimeCalcApp timeCalcApp) {
|
||||
setFocusable(true);
|
||||
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new java.awt.event.WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(java.awt.event.WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
timeCalcConfiguration
|
||||
.setFromTimeCalcProperties(TimeCalcProperties.getInstance());
|
||||
|
||||
overTimeIn = (overTimeIn == null || overTimeIn.isEmpty()) ?
|
||||
Constants.DEFAULT_OVERTIME : overTimeIn;
|
||||
|
||||
TimeHM startTime = new TimeHM(startTimeIn);
|
||||
TimeHM overtime = new TimeHM(overTimeIn);
|
||||
|
||||
TimeHM endTime = new TimeHM(
|
||||
startTime.getHour() + Constants.WORKING_HOURS_LENGTH + overtime
|
||||
.getHour(),
|
||||
startTime.getMinute() + Constants.WORKING_MINUTES_LENGTH
|
||||
+ overtime.getMinute());
|
||||
|
||||
int totalMinutes = TimeHM.countDiffInMinutes(startTime, endTime);
|
||||
int totalSeconds = totalMinutes * TimeHM.SECONDS_PER_MINUTE;
|
||||
int totalMilliseconds = totalSeconds * TimeHM.MILLISECONDS_PER_SECOND;
|
||||
|
||||
TimeCalcButton configButton = new TimeCalcButton("Config");
|
||||
TimeCalcButton workDaysButton = new TimeCalcButton("Work Days");
|
||||
TimeCalcButton activitiesButton = new TimeCalcButton("Activities"
|
||||
+ "");
|
||||
TimeCalcButton restartButton = new TimeCalcButton("Restart");
|
||||
TimeCalcButton exitButton = new TimeCalcButton("Exit");
|
||||
TimeCalcButton focusButton = new TimeCalcButton("Focus");
|
||||
TimeCalcButton weatherButton = new TimeCalcButton("Weather");
|
||||
TimeCalcButton commandButton = new TimeCalcButton("Command");
|
||||
TimeCalcButton jokeButton = new TimeCalcButton("Joke");
|
||||
AboutButton aboutButton = new AboutButton();
|
||||
|
||||
//window.add(weatherButton);
|
||||
addAll(configButton, workDaysButton, activitiesButton, restartButton,
|
||||
exitButton, focusButton, commandButton, jokeButton);
|
||||
|
||||
if(timeCalcConfiguration.visibilitySupportedColoredProperty.isEnabled()) {
|
||||
timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name());
|
||||
}
|
||||
timeCalcApp.visibilityProperty.bindTo(timeCalcConfiguration.visibilityDefaultProperty);
|
||||
TimeCalcKeyAdapter timeCalcKeyAdapter = new TimeCalcKeyAdapter(timeCalcConfiguration, timeCalcApp, commandButton, this);
|
||||
addKeyListener(timeCalcKeyAdapter);
|
||||
|
||||
AnalogClock analogClock = new AnalogClock(startTime, endTime);
|
||||
analogClock.setBounds(SwingUtils.MARGIN, SwingUtils.MARGIN, 200);
|
||||
add(analogClock);
|
||||
|
||||
ProgressSquare progressSquare = new ProgressSquare();
|
||||
progressSquare
|
||||
.setBounds(analogClock.getX() + analogClock.getWidth() + SwingUtils.MARGIN, analogClock.getY(),
|
||||
200);
|
||||
add(progressSquare);
|
||||
|
||||
ProgressCircle progressCircle = new ProgressCircle();
|
||||
progressCircle
|
||||
.setBounds(
|
||||
progressSquare.getX() + progressSquare.getWidth() + SwingUtils.MARGIN, progressSquare.getY(), 80);
|
||||
add(progressCircle);
|
||||
|
||||
WalkingHumanProgressAsciiArt walkingHumanProgressAsciiArt =
|
||||
new WalkingHumanProgressAsciiArt(analogClock.getX(), analogClock.getY() + analogClock.getHeight() + SwingUtils.MARGIN, 420, 180);
|
||||
add(walkingHumanProgressAsciiArt);
|
||||
weatherButton
|
||||
.setBounds(SwingUtils.MARGIN, walkingHumanProgressAsciiArt.getY()
|
||||
+ walkingHumanProgressAsciiArt.getHeight()
|
||||
+ SwingUtils.MARGIN);
|
||||
|
||||
configButton.setBoundsFromTop(walkingHumanProgressAsciiArt);
|
||||
workDaysButton.setBoundsFromLeft(configButton);
|
||||
activitiesButton.setBoundsFromLeft(workDaysButton);
|
||||
restartButton.setBoundsFromLeft(activitiesButton);
|
||||
exitButton.setBoundsFromLeft(restartButton);
|
||||
|
||||
//
|
||||
focusButton.setBoundsFromTop(exitButton);
|
||||
commandButton.setBoundsFromLeft(focusButton);
|
||||
jokeButton.setBoundsFromLeft(commandButton);
|
||||
//
|
||||
aboutButton.setBounds(exitButton.getX(),
|
||||
exitButton.getY() + exitButton.getHeight() + SwingUtils.MARGIN);
|
||||
|
||||
setLayout(null);
|
||||
setVisible(true);
|
||||
|
||||
String windowTitle = "Time Calc " + Utils.getVersion();
|
||||
setTitle(windowTitle);
|
||||
|
||||
weatherButton
|
||||
.addActionListener(e -> new WeatherWindow().setVisible(true));
|
||||
commandButton.addActionListener(new CommandActionListener(timeCalcApp, timeCalcConfiguration));
|
||||
|
||||
jokeButton.addActionListener(e -> {
|
||||
for (int i = 1; i <= 1; i++) {
|
||||
Jokes.showRandom();
|
||||
}
|
||||
});
|
||||
exitButton.addActionListener(e -> System.exit(0));
|
||||
focusButton.addActionListener(e -> requestFocus(true));
|
||||
restartButton.addActionListener(e -> {
|
||||
setVisible(false);
|
||||
stopBeforeEnd = true;
|
||||
});
|
||||
workDaysButton.addActionListener(e -> {
|
||||
if(workDaysWindow == null) {
|
||||
this.workDaysWindow = new WorkDaysWindow();
|
||||
}
|
||||
workDaysWindow.setVisible(true);
|
||||
});
|
||||
activitiesButton.addActionListener(e -> {
|
||||
if(activitiesWindow == null) {
|
||||
this.activitiesWindow = new ActivitiesWindow();
|
||||
}
|
||||
activitiesWindow.setVisible(true);
|
||||
});
|
||||
|
||||
configButton.addActionListener(e -> {
|
||||
if(configWindow == null) {
|
||||
this.configWindow = new ConfigWindow(timeCalcConfiguration);
|
||||
}
|
||||
configWindow.setVisible(true);
|
||||
});
|
||||
Calendar calNow = Calendar.getInstance();
|
||||
calNow.setTime(new Date());
|
||||
|
||||
Properties testProperties = new Properties();
|
||||
File testPropertiesFile = new File("test.txt");
|
||||
try {
|
||||
if (testPropertiesFile.exists()) {
|
||||
testProperties.load(new FileInputStream(testPropertiesFile));
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(MainWindow.class.getName())
|
||||
.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
Time time = new Time();
|
||||
|
||||
bindToIfPropertyMissing(testProperties, "test.current.day", calNow, Calendar.DAY_OF_MONTH, analogClock.dayProperty, time.dayProperty);
|
||||
bindToIfPropertyMissing(testProperties, "test.current.month", calNow, Calendar.MONTH, analogClock.monthProperty, time.monthProperty);
|
||||
bindToIfPropertyMissing(testProperties, "test.current.year", calNow, Calendar.YEAR, analogClock.yearProperty, time.yearProperty);
|
||||
bindToIfPropertyMissing(testProperties, "test.current.hour", calNow, Calendar.HOUR, analogClock.hourProperty, time.hourProperty);
|
||||
bindToIfPropertyMissing(testProperties, "test.current.minute", calNow, Calendar.MINUTE, analogClock.minuteProperty, time.minuteProperty);
|
||||
bindToIfPropertyMissing(testProperties, "test.current.second", calNow, Calendar.SECOND, analogClock.secondProperty, time.secondProperty);
|
||||
bindToIfPropertyMissing(testProperties, "test.current.millisecond", calNow, Calendar.MILLISECOND, analogClock.millisecondProperty, time.millisecondProperty);
|
||||
|
||||
if (testProperties.containsKey("test.current.year") || testProperties
|
||||
.containsKey("test.current.month") || testProperties
|
||||
.containsKey("test.current.day")) {
|
||||
analogClock.dayOfWeekProperty
|
||||
.setValue(calNow.get(Calendar.DAY_OF_WEEK));
|
||||
} else {
|
||||
analogClock.dayOfWeekProperty.bindTo(time.dayOfWeek);
|
||||
}
|
||||
|
||||
analogClock.millisecondEnabledProperty
|
||||
.bindTo(timeCalcConfiguration.clockHandsMillisecondVisibleProperty);
|
||||
analogClock.secondEnabledProperty
|
||||
.bindTo(timeCalcConfiguration.clockHandsSecondVisibleProperty);
|
||||
analogClock.minuteEnabledProperty
|
||||
.bindTo(timeCalcConfiguration.clockHandsMinuteVisibleProperty);
|
||||
analogClock.handsLongProperty
|
||||
.bindTo(timeCalcConfiguration.clockHandsLongVisibleProperty);
|
||||
|
||||
Battery hourBattery = new HourBattery(progressCircle.getBounds().x,
|
||||
progressCircle.getY() + SwingUtils.MARGIN + progressCircle.getHeight(),
|
||||
140);
|
||||
add(hourBattery);
|
||||
|
||||
Battery dayBattery = new DayBattery(hourBattery.getBounds().x + hourBattery.getWidth() + SwingUtils.MARGIN,
|
||||
hourBattery.getY(),
|
||||
140);
|
||||
add(dayBattery);
|
||||
|
||||
Battery weekBattery = new WeekBattery(
|
||||
hourBattery.getBounds().x,
|
||||
dayBattery.getY() + dayBattery.getHeight() + SwingUtils.MARGIN, 140);
|
||||
add(weekBattery);
|
||||
|
||||
int currentDayOfMonth = analogClock.dayProperty.getValue();
|
||||
|
||||
int workDaysDone = 0;
|
||||
int workDaysTodo = 0;
|
||||
int workDaysTotal;
|
||||
for (int dayOfMonth = 1;
|
||||
dayOfMonth <= calNow.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||||
dayOfMonth++) {
|
||||
DayOfWeek dayOfWeek = LocalDate.of(analogClock.yearProperty.getValue(),
|
||||
analogClock.monthProperty.getValue(), 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;
|
||||
|
||||
Battery monthBattery = new MonthBattery(
|
||||
dayBattery.getBounds().x,
|
||||
weekBattery.getY(), 140);
|
||||
add(monthBattery);
|
||||
|
||||
ComponentRegistry<JComponent> componentRegistry = new ComponentRegistry();
|
||||
componentRegistry.addAll(
|
||||
walkingHumanProgressAsciiArt,
|
||||
progressSquare,
|
||||
progressCircle,
|
||||
analogClock,
|
||||
dayBattery,
|
||||
weekBattery,
|
||||
monthBattery,
|
||||
hourBattery,
|
||||
configButton,
|
||||
workDaysButton,
|
||||
activitiesButton,
|
||||
restartButton,
|
||||
exitButton,
|
||||
focusButton,
|
||||
jokeButton,
|
||||
commandButton
|
||||
);
|
||||
ComponentRegistry<TimeCalcButton> buttonRegistry = new ComponentRegistry();
|
||||
componentRegistry.getSet().stream().filter(c-> c instanceof TimeCalcButton).forEach(c->
|
||||
buttonRegistry.add((TimeCalcButton)c));
|
||||
componentRegistry.getSet().stream().filter(c ->
|
||||
GetProperty.class.isAssignableFrom(c.getClass())).forEach(c->
|
||||
((GetProperty<String>)c).getProperty().bindTo(timeCalcApp.visibilityProperty));
|
||||
|
||||
componentRegistry.getSet().stream().filter(c-> c instanceof Battery).forEach(c ->
|
||||
((Battery)c).wavesProperty.bindTo(timeCalcConfiguration.batteryWavesVisibleProperty));
|
||||
|
||||
componentRegistry.getSet().stream().filter(c-> c instanceof Widget).forEach(c ->
|
||||
((Widget)c).smileysColoredProperty.bindTo(timeCalcConfiguration.smileysColoredProperty));
|
||||
setSize(dayBattery.getX() + dayBattery.getWidth() + 3 * SwingUtils.MARGIN,
|
||||
focusButton.getY() + focusButton.getHeight() + SwingUtils.MARGIN + focusButton.getHeight() + 2 * SwingUtils.MARGIN);
|
||||
while (true) {
|
||||
//System.out.println("timeCalcConfiguration.handsLongProperty=" + timeCalcConfiguration.clockHandLongProperty.isEnabled());
|
||||
Visibility currentVisibility = Visibility
|
||||
.valueOf(timeCalcApp.visibilityProperty.getValue());
|
||||
if(timeCalcConfiguration.visibilitySupportedColoredProperty.isEnabled() && currentVisibility.isColored() ){
|
||||
timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name());
|
||||
}
|
||||
if (stopBeforeEnd) {
|
||||
if(configWindow != null) {configWindow.setVisible(false);configWindow.dispose();}
|
||||
if(workDaysWindow != null) {workDaysWindow.setVisible(false);workDaysWindow.dispose();}
|
||||
if(activitiesWindow != null) {activitiesWindow.setVisible(false);activitiesWindow.dispose();}
|
||||
|
||||
setVisible(false);
|
||||
dispose();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
componentRegistry.setVisible(currentVisibility.isNotNone());
|
||||
|
||||
jokeButton.setVisible(
|
||||
TimeCalcProperties.getInstance().getBooleanProperty(
|
||||
TimeCalcProperty.JOKES_VISIBLE)
|
||||
&& !currentVisibility.isNone());
|
||||
|
||||
setTitle(currentVisibility.isNone() ? "" : windowTitle);
|
||||
|
||||
int hourNow = analogClock.hourProperty.getValue();
|
||||
int minuteNow = analogClock.minuteProperty.getValue();
|
||||
|
||||
int secondNow = analogClock.secondProperty.getValue();
|
||||
int millisecondNow = analogClock.millisecondProperty.getValue();
|
||||
TimeHM timeRemains = new TimeHM(endTime.getHour() - hourNow,
|
||||
endTime.getMinute() - minuteNow);
|
||||
|
||||
int secondsRemains = 60 - secondNow;
|
||||
int millisecondsRemains = 1000 - millisecondNow;
|
||||
|
||||
int hourDone = Constants.WORKING_HOURS_LENGTH + overtime.getHour()
|
||||
- timeRemains.getHour();
|
||||
int minutesDone =
|
||||
Constants.WORKING_MINUTES_LENGTH + overtime.getMinute()
|
||||
- timeRemains.getMinute();
|
||||
int secondsDone = secondNow;
|
||||
int millisecondsDone = millisecondNow;
|
||||
|
||||
int totalMinutesDone = hourDone * 60 + minutesDone;
|
||||
int totalSecondsDone = totalMinutesDone * 60 + secondsDone;
|
||||
int totalMillisecondsDone =
|
||||
totalSecondsDone * 1000 + millisecondsDone;
|
||||
|
||||
double done = ((double) totalMillisecondsDone)
|
||||
/ ((double) totalMilliseconds);
|
||||
progressSquare.setDonePercent(done);
|
||||
progressCircle.setDonePercent(done);
|
||||
dayBattery.setDonePercent(done);
|
||||
|
||||
int weekDayWhenMondayIsOne = calNow.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
weekBattery.setDonePercent(
|
||||
WeekBattery.getWeekProgress(weekDayWhenMondayIsOne, done));
|
||||
weekBattery.setLabel(
|
||||
nowIsWeekend ? "5/5" : (weekDayWhenMondayIsOne + "/5"));
|
||||
|
||||
monthBattery.setDonePercent(MonthBattery
|
||||
.getMonthProgress(weekDayWhenMondayIsOne, workDaysDone,
|
||||
workDaysTotal, done));
|
||||
monthBattery.setLabel(
|
||||
(nowIsWeekend ? workDaysDone : workDaysDone + 1) + "/"
|
||||
+ (workDaysTotal));
|
||||
|
||||
hourBattery.setDonePercent(
|
||||
HourBattery.getHourProgress(timeRemains, secondsRemains,
|
||||
millisecondsRemains));
|
||||
if (!nowIsWeekend) {
|
||||
hourBattery.setLabel(
|
||||
hourDone + "/" + (
|
||||
totalMinutes / 60));
|
||||
}
|
||||
|
||||
int totalSecondsRemains =
|
||||
(timeRemains.getHour() * 60 * 60
|
||||
+ timeRemains.getMinute() * 60
|
||||
+ secondsRemains);
|
||||
int totalMillisecondsRemains =
|
||||
totalSecondsRemains * 1000 + millisecondsRemains;
|
||||
double totalSecondsRemainsDouble =
|
||||
((double) totalMillisecondsRemains) / 1000;
|
||||
|
||||
if (timeRemains.getHour() <= 0 && timeRemains.getMinute() <= 0) {
|
||||
Toaster toasterManager = new Toaster();
|
||||
toasterManager.setDisplayTime(30000);
|
||||
toasterManager.showToaster(
|
||||
"Congratulation :-) It is the time to go home.");
|
||||
walkingHumanProgressAsciiArt
|
||||
.printPercentToAscii(done, timeRemains.getHour(),
|
||||
timeRemains.getMinute(), done,
|
||||
totalSecondsRemainsDouble, endTime);
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
while (!stopBeforeEnd) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
walkingHumanProgressAsciiArt
|
||||
.printPercentToAscii(done, timeRemains.getHour(),
|
||||
timeRemains.getMinute(), done,
|
||||
totalSecondsRemainsDouble, endTime);
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
}
|
||||
}
|
||||
if(configWindow != null) {configWindow.setVisible(false);configWindow.dispose();}
|
||||
if(workDaysWindow != null) {workDaysWindow.setVisible(false);workDaysWindow.dispose();}
|
||||
if(activitiesWindow != null) {activitiesWindow.setVisible(false);activitiesWindow.dispose();}
|
||||
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
|
||||
private void bindToIfPropertyMissing(Properties properties, String key, Calendar cal, int timeUnit, IntegerProperty firstProperty, Property secondProperty) {
|
||||
if (properties.containsKey(key)) {
|
||||
cal.set(timeUnit, Integer.parseInt(
|
||||
(String) properties.get(key)) + (timeUnit == Calendar.MONTH ? -1 : 0));
|
||||
firstProperty.setValue(Integer.valueOf(
|
||||
(String) properties.get(key)));
|
||||
} else {
|
||||
firstProperty.bindTo(secondProperty);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package org.nanoboot.utils.timecalc.swing.common;
|
||||
|
||||
import org.nanoboot.utils.timecalc.app.GetProperty;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcManager;
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.utils.property.Property;
|
||||
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
|
||||
@ -31,8 +30,8 @@ public class TimeCalcButton extends JButton implements GetProperty {
|
||||
Visibility.valueOf(visibilityProperty.getValue());
|
||||
setVisible(visibility.isNotNone());
|
||||
if (!visibility.isStronglyColored() || visibility.isGray()) {
|
||||
setBackground(TimeCalcManager.BACKGROUND_COLOR);
|
||||
setForeground(TimeCalcManager.FOREGROUND_COLOR);
|
||||
setBackground(MainWindow.BACKGROUND_COLOR);
|
||||
setForeground(MainWindow.FOREGROUND_COLOR);
|
||||
} else {
|
||||
setOriginalBackground();
|
||||
setOriginalForeground();
|
||||
|
@ -10,14 +10,7 @@ import java.awt.HeadlessException;
|
||||
*/
|
||||
public class TimeCalcWindow extends JFrame {
|
||||
public TimeCalcWindow() throws HeadlessException {
|
||||
setFocusable(true);
|
||||
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new java.awt.event.WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(java.awt.event.WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public Component[] addAll(Component... comp) {
|
||||
|
@ -0,0 +1,28 @@
|
||||
package org.nanoboot.utils.timecalc.swing.common;
|
||||
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcConfiguration;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.Dimension;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Robert Vokac
|
||||
* @since 16.02.2024
|
||||
*/
|
||||
public class WorkDaysWindow extends TimeCalcWindow {
|
||||
public WorkDaysWindow() {
|
||||
setSize(800, 600);
|
||||
setTitle("Work Days");
|
||||
}
|
||||
|
||||
}
|
@ -2,15 +2,13 @@ package org.nanoboot.utils.timecalc.swing.progress;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcProperties;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.swing.common.Widget;
|
||||
import org.nanoboot.utils.timecalc.utils.common.ProgressSmiley;
|
||||
import org.nanoboot.utils.timecalc.utils.common.NumberFormats;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JLabel;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
@ -117,7 +115,7 @@ public class Battery extends Widget {
|
||||
int waterSurfaceHeight =
|
||||
(int) (4 * surfacePower);//2 + (int) (Math.random() * 3);
|
||||
if (waterSurfaceHeight <= 2 || !TimeCalcProperties.getInstance()
|
||||
.areBatteryWavesEnabled() || wavesProperty.isDisabled()) {
|
||||
.getBooleanProperty(TimeCalcProperty.BATTERY_WAVES_VISIBLE) || wavesProperty.isDisabled()) {
|
||||
waterSurfaceHeight = 0;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.nanoboot.utils.timecalc.swing.progress;
|
||||
|
||||
import org.nanoboot.utils.timecalc.app.GetProperty;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcManager;
|
||||
import org.nanoboot.utils.timecalc.swing.common.MainWindow;
|
||||
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||
import org.nanoboot.utils.timecalc.swing.common.Toaster;
|
||||
import org.nanoboot.utils.timecalc.utils.common.Constants;
|
||||
@ -41,7 +41,7 @@ public class WalkingHumanProgressAsciiArt extends JTextPane implements
|
||||
putClientProperty("mouseEntered", "false");
|
||||
setFocusable(false);
|
||||
setForeground(Color.GRAY);
|
||||
setBackground(TimeCalcManager.BACKGROUND_COLOR);
|
||||
setBackground(MainWindow.BACKGROUND_COLOR);
|
||||
addMouseListener(new MouseListener() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.nanoboot.utils.timecalc.utils.common;
|
||||
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcProperties;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcProperty;
|
||||
import org.nanoboot.utils.timecalc.swing.common.Toaster;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
@ -63,7 +64,8 @@ public class Jokes {
|
||||
}
|
||||
|
||||
public static void showRandom() {
|
||||
if (!TimeCalcProperties.getInstance().areJokesEnabled()) {
|
||||
if (!TimeCalcProperties.getInstance().getBooleanProperty(
|
||||
TimeCalcProperty.JOKES_VISIBLE)) {
|
||||
//nothing to do
|
||||
return;
|
||||
}
|
||||
|
@ -6,9 +6,12 @@ import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontFormatException;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
@ -125,4 +128,18 @@ public class Utils {
|
||||
return base64Decoder
|
||||
.decode(s.getBytes());
|
||||
}
|
||||
public static String readTextFromTextResourceInJar(String pathToFile) throws IOException {
|
||||
InputStream inputStream = ClassLoader.getSystemClassLoader().
|
||||
getSystemResourceAsStream(pathToFile);
|
||||
InputStreamReader
|
||||
streamReader = new InputStreamReader(inputStream,
|
||||
StandardCharsets.UTF_8);
|
||||
BufferedReader in = new BufferedReader(streamReader);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String line; (line = in.readLine()) != null; ) {
|
||||
sb.append(line).append("\n");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,11 @@ public class StringProperty extends Property<String> {
|
||||
public StringProperty(String name, String valueIn) {
|
||||
super(name, valueIn);
|
||||
}
|
||||
public StringProperty(String name) {
|
||||
this(name, "");
|
||||
}
|
||||
|
||||
public StringProperty() {
|
||||
this("", "");
|
||||
this("");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
visibility.default=STRONGLY_COLORED
|
||||
visibility.supported.colored=true
|
||||
#
|
||||
clock.hands.long.visible=true
|
||||
clock.hands.minute.visible=true
|
||||
clock.hands.second.visible=true
|
||||
clock.hands.millisecond.visible=false
|
||||
#
|
||||
battery.waves.visible=true
|
||||
#
|
||||
jokes.visible=true
|
||||
commands.visible=true
|
||||
notifications.visible=true
|
||||
smileys.colored=false
|
||||
|
||||
#todo
|
||||
visibility.smileys.enabled=true
|
||||
visibility.battery.smileys.enabled=true
|
||||
visibility.progress.square.smileys.enabled=true
|
||||
visibility.progress.circle.smileys.enabled=true
|
||||
visibility.battery.charging-unicode-character.enabled=true
|
||||
battery.percent-precision.count-of-decimal-points=5
|
||||
visibility.battery.label.finished-from-total.enabled=true
|
||||
visibility.widgets.clock.enabled=true
|
||||
visibility.widgets.progress-square.enabled=true
|
||||
visibility.widgets.progress-circle.enabled=true
|
||||
visibility.widgets.walking-human.enabled=true
|
||||
visibility.widgets.battery.hour.enabled=true
|
||||
visibility.widgets.battery.day.enabled=true
|
||||
visibility.widgets.battery.week.enabled=true
|
||||
visibility.widgets.battery.month.enabled=true
|
@ -1,13 +1,16 @@
|
||||
clock.hands.long=true
|
||||
clock.hands.minute.enabled=true
|
||||
clock.hands.second.enabled=true
|
||||
clock.hands.millisecond.enabled=false
|
||||
battery.waves.enabled=true
|
||||
visibility.current=STRONGLY_COLORED
|
||||
visibility.only-grey-or-none.enabled=false
|
||||
jokes.enabled=true
|
||||
commands.enabled=true
|
||||
toasts.enabled=true
|
||||
visibility.default=STRONGLY_COLORED
|
||||
visibility.supported.colored=false
|
||||
#
|
||||
clock.hands.long.visible=true
|
||||
clock.hands.minute.visible=true
|
||||
clock.hands.second.visible=true
|
||||
clock.hands.millisecond.visible=false
|
||||
#
|
||||
battery.waves.visible=true
|
||||
#
|
||||
jokes.visible=true
|
||||
commands.visible=true
|
||||
notifications.visible=true
|
||||
smileys.colored=false
|
||||
|
||||
#todo
|
||||
|
Loading…
x
Reference in New Issue
Block a user