Added several improvements

This commit is contained in:
Robert Vokac 2024-03-09 10:28:08 +00:00
parent a92ff1837d
commit efa6e1437e
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
11 changed files with 368 additions and 24 deletions

View File

@ -167,6 +167,10 @@ Smileys can be colored or white-black (can be set in configuration)
* LEFT - switch to previous profile
* RIGHT - switch to next profile
* K - hide or show clock
* SHIFT + {Y,O,D,H,M,S or I} - Increase test time value
* CTRL + {Y,O,D,H,M,S or I} - Decrease test time value
* ALT + {Y,O,D,H,M,S or I} - Rest test time value
* D - Reset custom time values to the real time
## Command button

View File

@ -1,6 +1,7 @@
package org.nanoboot.utils.timecalc.app;
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
import org.nanoboot.utils.timecalc.utils.property.IntegerProperty;
import org.nanoboot.utils.timecalc.utils.property.Property;
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
@ -155,12 +156,30 @@ public class TimeCalcConfiguration {
public final StringProperty mainWindowCustomTitleProperty
= new StringProperty(
TimeCalcProperty.MAIN_WINDOW_CUSTOM_TITLE.getKey());
public final BooleanProperty testModeProperty
= new BooleanProperty("testModeProperty", false);
public final StringProperty profileNameProperty
= new StringProperty(TimeCalcProperty.PROFILE_NAME.getKey());
public final IntegerProperty testYearCustomProperty = new IntegerProperty(TimeCalcProperty.TEST_CLOCK_CUSTOM_YEAR
.getKey(), Integer.MAX_VALUE);
public final IntegerProperty testMonthCustomProperty = new IntegerProperty(TimeCalcProperty.TEST_CLOCK_CUSTOM_MONTH
.getKey(), Integer.MAX_VALUE);
public final IntegerProperty testDayCustomProperty = new IntegerProperty(TimeCalcProperty.TEST_CLOCK_CUSTOM_DAY
.getKey(), Integer.MAX_VALUE);
public final IntegerProperty testHourCustomProperty = new IntegerProperty(TimeCalcProperty.TEST_CLOCK_CUSTOM_HOUR
.getKey(), Integer.MAX_VALUE);
public final IntegerProperty testMinuteCustomProperty = new IntegerProperty(TimeCalcProperty.TEST_CLOCK_CUSTOM_MINUTE
.getKey(), Integer.MAX_VALUE);
public final IntegerProperty testSecondCustomProperty = new IntegerProperty(TimeCalcProperty.TEST_CLOCK_CUSTOM_SECOND
.getKey(), Integer.MAX_VALUE);
public final IntegerProperty testMillisecondCustomProperty = new IntegerProperty(TimeCalcProperty.TEST_CLOCK_CUSTOM_MILLISECOND
.getKey(), Integer.MAX_VALUE);
//
private final Map<TimeCalcProperty, Property> mapOfProperties =
new HashMap<>();
private final List<Property> allProperties = new ArrayList<>();
private TimeCalcProperties timeCalcProperties;
public TimeCalcConfiguration() {
@ -209,6 +228,13 @@ public class TimeCalcConfiguration {
walkingHumanVisibleProperty,
mainWindowCustomTitleProperty,
profileNameProperty,
testYearCustomProperty,
testMonthCustomProperty,
testDayCustomProperty,
testHourCustomProperty,
testMinuteCustomProperty,
testSecondCustomProperty,
testMillisecondCustomProperty,
}) {
allProperties.add(p);
}
@ -238,6 +264,17 @@ public class TimeCalcConfiguration {
}
return mapOfProperties.get(timeCalcProperty);
}
public String print() {
StringBuilder sb = new StringBuilder();
for(Property p: allProperties) {
if(!p.getName().startsWith("test")) {
continue;
}
sb.append(p.getName()).append("=").append(p.getValue())
.append("\n");
}
return sb.toString();
}
public void saveToTimeCalcProperties() {
System.out.println("Going to save properties.");
@ -277,6 +314,12 @@ public class TimeCalcConfiguration {
TimeCalcProperty.forKey(p.getName())));
continue;
}
if (p instanceof IntegerProperty) {
p.setValue(timeCalcProperties
.getIntegerProperty(
TimeCalcProperty.forKey(p.getName())));
continue;
}
throw new TimeCalcException(
"Unsupported Property class: " + p.getClass().getName());

View File

@ -2,14 +2,17 @@ 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.swing.progress.Time;
import org.nanoboot.utils.timecalc.utils.common.FileConstants;
import org.nanoboot.utils.timecalc.utils.common.Jokes;
import org.nanoboot.utils.timecalc.utils.common.Utils;
import org.nanoboot.utils.timecalc.utils.property.IntegerProperty;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Calendar;
import java.util.Properties;
/**
@ -21,20 +24,162 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
private final TimeCalcConfiguration timeCalcConfiguration;
private final TimeCalcApp timeCalcApp;
private final MainWindow window;
private final Time time;
public TimeCalcKeyAdapter(
TimeCalcConfiguration timeCalcConfiguration,
TimeCalcApp timeCalcApp,
MainWindow window
MainWindow window,
Time time
) {
this.timeCalcConfiguration = timeCalcConfiguration;
this.timeCalcApp = timeCalcApp;
this.window = window;
this.time = time;
}
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
processKeyCode(keyCode);
boolean shiftDown = e.isShiftDown();
boolean ctrlDown = e.isControlDown();
boolean altDown = e.isAltDown();
boolean metaDown = e.isMetaDown();
if(!shiftDown && !ctrlDown && !altDown) {
processKeyCode(keyCode);
} else {
processTestModeKeyCode(keyCode, shiftDown, ctrlDown, altDown);
}
//meta key ???
}
private void processTestModeKeyCode(int keyCode, boolean shiftDown,
boolean ctrlDown, boolean altDown) {
if (shiftDown && ctrlDown) {
return;
}
if (shiftDown && altDown) {
return;
}
if (ctrlDown && altDown) {
return;
}
boolean increase = shiftDown;
boolean decrease = ctrlDown;
boolean reset = altDown;
switch (keyCode) {
case KeyEvent.VK_Y: {
Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " year.");
updateProperty(timeCalcConfiguration.testYearCustomProperty, increase, decrease, reset,
Calendar.YEAR);
break;
}
case KeyEvent.VK_O: {
Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " month.");
updateProperty(timeCalcConfiguration.testMonthCustomProperty, increase, decrease, reset,
Calendar.MONTH);
break;
}
case KeyEvent.VK_D: {
Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " day.");
updateProperty(timeCalcConfiguration.testDayCustomProperty, increase, decrease, reset,
Calendar.DAY_OF_MONTH);
break;
}
case KeyEvent.VK_H: {
Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " hour.");
updateProperty(timeCalcConfiguration.testHourCustomProperty, increase, decrease, reset,
Calendar.HOUR_OF_DAY);
break;
}
case KeyEvent.VK_M: {
Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " minute.");
updateProperty(timeCalcConfiguration.testMinuteCustomProperty, increase, decrease, reset,
Calendar.MINUTE);
break;
}
case KeyEvent.VK_S: {
Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " second.");
updateProperty(timeCalcConfiguration.testSecondCustomProperty, increase, decrease, reset,
Calendar.SECOND);
break;
}
case KeyEvent.VK_I: {
Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " millisecond.");
updateProperty(timeCalcConfiguration.testMillisecondCustomProperty, increase, decrease, reset,
Calendar.MILLISECOND);
break;
}
default:
Utils.showNotification(
"Unsupported key was pressed. There is no key shortcut for this key: "
+ keyCode);
}
}
private void updateProperty(IntegerProperty integerProperty,
boolean increase, boolean decrease, boolean reset, int timeUnit) {
int currentValue = integerProperty.getValue();
if((increase || decrease) && currentValue == Integer.MAX_VALUE) {
switch(timeUnit) {
case Calendar.YEAR: integerProperty.setValue(time.yearProperty.getValue());break;
case Calendar.MONTH:integerProperty.setValue(time.monthProperty.getValue());break;
case Calendar.DAY_OF_MONTH:integerProperty.setValue(time.dayProperty.getValue());break;
case Calendar.HOUR_OF_DAY:integerProperty.setValue(time.hourProperty.getValue());break;
case Calendar.MINUTE:integerProperty.setValue(time.minuteProperty.getValue());break;
case Calendar.SECOND:integerProperty.setValue(time.secondProperty.getValue());break;
case Calendar.MILLISECOND:integerProperty.setValue(time.millisecondProperty.getValue());break;
default: throw new TimeCalcException("Unsupported time unit: " + timeUnit);
}
}
Calendar cal = time.asCalendar();
int oldYear = cal.get(Calendar.YEAR);
int oldMonth = cal.get(Calendar.MONTH) + 1;
int oldDay = cal.get(Calendar.DAY_OF_MONTH);
int oldHour = cal.get(Calendar.HOUR_OF_DAY);
int oldMinute = cal.get(Calendar.MINUTE);
int oldSecond = cal.get(Calendar.SECOND);
int oldMillisecond = cal.get(Calendar.MILLISECOND);
cal.add(timeUnit, increase ? 1 : (-1));
int newValue = cal.get(timeUnit);
if(Calendar.MONTH == timeUnit) {
newValue ++;
}
int newYear = cal.get(Calendar.YEAR);
int newMonth = cal.get(Calendar.MONTH) + 1;
int newDay = cal.get(Calendar.DAY_OF_MONTH);
int newHour = cal.get(Calendar.HOUR_OF_DAY);
int newMinute = cal.get(Calendar.MINUTE);
int newSecond = cal.get(Calendar.SECOND);
int newMillisecond = cal.get(Calendar.MILLISECOND);
if(increase){
switch(timeUnit) {
case Calendar.YEAR: break;
case Calendar.MONTH: if(oldYear != newYear) { updateProperty(timeCalcConfiguration.testYearCustomProperty, increase, decrease, reset, Calendar.YEAR);}break;
case Calendar.DAY_OF_MONTH:if(oldMonth != newMonth) { updateProperty(timeCalcConfiguration.testMonthCustomProperty, increase, decrease, reset, Calendar.MONTH);}break;
case Calendar.HOUR_OF_DAY:if(oldDay != newDay) { updateProperty(timeCalcConfiguration.testDayCustomProperty, increase, decrease, reset, Calendar.DAY_OF_MONTH);}break;
case Calendar.MINUTE:if(oldHour != newHour) { updateProperty(timeCalcConfiguration.testHourCustomProperty, increase, decrease, reset, Calendar.HOUR_OF_DAY);}break;
case Calendar.SECOND:if(oldMinute != newMinute) { updateProperty(timeCalcConfiguration.testMinuteCustomProperty, increase, decrease, reset, Calendar.MINUTE);}break;
case Calendar.MILLISECOND:if(oldSecond != newSecond) { updateProperty(timeCalcConfiguration.testSecondCustomProperty, increase, decrease, reset, Calendar.MILLISECOND);}break;
default: throw new TimeCalcException("Unsupported time unit: " + timeUnit);
}
}
if(decrease){
switch(timeUnit) {
case Calendar.YEAR: if(oldMonth != newMonth) { updateProperty(timeCalcConfiguration.testMonthCustomProperty, increase, decrease, reset, Calendar.MONTH);}break;
case Calendar.MONTH:if(oldDay != newDay) { updateProperty(timeCalcConfiguration.testDayCustomProperty, increase, decrease, reset, Calendar.DAY_OF_MONTH);}break;
case Calendar.DAY_OF_MONTH:if(oldHour != newHour) { updateProperty(timeCalcConfiguration.testHourCustomProperty, increase, decrease, reset, Calendar.HOUR_OF_DAY);}break;
case Calendar.HOUR_OF_DAY:if(oldMinute != newMinute) { updateProperty(timeCalcConfiguration.testMinuteCustomProperty, increase, decrease, reset, Calendar.MINUTE);}break;
case Calendar.MINUTE:if(oldSecond != newSecond) { updateProperty(timeCalcConfiguration.testSecondCustomProperty, increase, decrease, reset, Calendar.SECOND);}break;
case Calendar.SECOND:if(oldMillisecond != newMillisecond) { updateProperty(timeCalcConfiguration.testMillisecondCustomProperty, increase, decrease, reset, Calendar.MILLISECOND);}break;
case Calendar.MILLISECOND: break;
default: throw new TimeCalcException("Unsupported time unit: " + timeUnit);
}
}
if(reset) {
newValue = Integer.MAX_VALUE;
}
integerProperty.setValue(newValue);
}
private void processKeyCode(int keyCode) {
@ -247,6 +392,18 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
switchProfile(false, true);
break;
}
case KeyEvent.VK_D: {
System.out.println("D");
timeCalcConfiguration.testYearCustomProperty.setValue(Integer.MAX_VALUE);
timeCalcConfiguration.testMonthCustomProperty.setValue(Integer.MAX_VALUE);
timeCalcConfiguration.testDayCustomProperty.setValue(Integer.MAX_VALUE);
timeCalcConfiguration.testHourCustomProperty.setValue(Integer.MAX_VALUE);
timeCalcConfiguration.testMinuteCustomProperty.setValue(Integer.MAX_VALUE);
timeCalcConfiguration.testSecondCustomProperty.setValue(Integer.MAX_VALUE);
timeCalcConfiguration.testMillisecondCustomProperty.setValue(Integer.MAX_VALUE);
Utils.showNotification(timeCalcConfiguration.print(), 15000, 400);
break;
}
case KeyEvent.VK_K: {
if(timeCalcConfiguration.clockVisibleProperty.isEnabled()) {

View File

@ -115,7 +115,19 @@ public class TimeCalcProperties {
}
return (String) properties.get(key);
}
public int getIntegerProperty(TimeCalcProperty timeCalcProperty) {
return getIntegerProperty(timeCalcProperty,
Integer.valueOf(getDefaultStringValue(timeCalcProperty)));
}
private int getIntegerProperty(TimeCalcProperty timeCalcProperty,
int defaultValue) {
String key = timeCalcProperty.getKey();
if (!properties.containsKey(key)) {
return defaultValue;
}
return Integer.valueOf((String) properties.get(key));
}
private String getVisibilityProperty(TimeCalcProperty timeCalcProperty) {
return getStringProperty(timeCalcProperty,
Visibility.STRONGLY_COLORED.name());

View File

@ -82,7 +82,14 @@ public enum TimeCalcProperty {
WALKING_HUMAN_VISIBLE("walking-human.visible", "Walking Human"),
MAIN_WINDOW_CUSTOM_TITLE("main-window.custom-title",
"Main Window : Custom Title"),
PROFILE_NAME("profile.name", "Profile : Name");
PROFILE_NAME("profile.name", "Profile : Name"),
TEST_CLOCK_CUSTOM_YEAR("test.clock.custom.year", "Test : Clock : Custom : Year", Integer.class),
TEST_CLOCK_CUSTOM_MONTH("test.clock.custom.month", "Test : Clock : Custom : Month", Integer.class),
TEST_CLOCK_CUSTOM_DAY("test.clock.custom.day", "Test : Clock : Custom : Day", Integer.class),
TEST_CLOCK_CUSTOM_HOUR("test.clock.custom.hour", "Test : Clock : Custom : Hour", Integer.class),
TEST_CLOCK_CUSTOM_MINUTE("test.clock.custom.minute", "Test : Clock : Custom : Minute", Integer.class),
TEST_CLOCK_CUSTOM_SECOND("test.clock.custom.second", "Test : Clock : Custom : Second", Integer.class),
TEST_CLOCK_CUSTOM_MILLISECOND("test.clock.custom.millisecond", "Test : Clock : Custom : Millisecond", Integer.class);
@Getter
private final String key;

View File

@ -163,6 +163,20 @@ public class ConfigWindow extends TWindow {
= new JTextField();
private final JTextField profileNameProperty
= new JTextField();
private final JTextField testClockCustomYearProperty
= new JTextField(TimeCalcProperty.TEST_CLOCK_CUSTOM_YEAR.getKey());
private final JTextField testClockCustomMonthProperty
= new JTextField(TimeCalcProperty.TEST_CLOCK_CUSTOM_MONTH.getKey());
private final JTextField testClockCustomDayProperty
= new JTextField(TimeCalcProperty.TEST_CLOCK_CUSTOM_DAY.getKey());
private final JTextField testClockCustomHourProperty
= new JTextField(TimeCalcProperty.TEST_CLOCK_CUSTOM_HOUR.getKey());
private final JTextField testClockCustomMinuteProperty
= new JTextField(TimeCalcProperty.TEST_CLOCK_CUSTOM_MINUTE.getKey());
private final JTextField testClockCustomSecondProperty
= new JTextField(TimeCalcProperty.TEST_CLOCK_CUSTOM_SECOND.getKey());
private final JTextField testClockCustomMillisecondProperty
= new JTextField(TimeCalcProperty.TEST_CLOCK_CUSTOM_MILLISECOND.getKey());
public ConfigWindow(TimeCalcConfiguration timeCalcConfiguration) {
this.timeCalcConfiguration = timeCalcConfiguration;
setTitle("Configuration");
@ -308,6 +322,13 @@ public class ConfigWindow extends TWindow {
smileysVisibleProperty,
smileysVisibleOnlyIfMouseMovingOverProperty,
smileysColoredProperty,
testClockCustomYearProperty,
testClockCustomMonthProperty,
testClockCustomDayProperty,
testClockCustomHourProperty,
testClockCustomMinuteProperty,
testClockCustomSecondProperty,
testClockCustomMillisecondProperty,
jokesVisibleProperty,
commandsVisibleProperty,
notificationsVisibleProperty,
@ -345,6 +366,10 @@ public class ConfigWindow extends TWindow {
p.putClientProperty(CLIENT_PROPERTY_KEY,
TimeCalcProperty.PROFILE_NAME.getKey());
}
if (p == testClockCustomYearProperty) {
addToNextRow(new JLabel("Test"));
}
if (p instanceof JComboBox) {
JComboBox jComboBox = ((JComboBox) p);
jComboBox.setMaximumSize(new Dimension(150, 25));
@ -388,7 +413,8 @@ public class ConfigWindow extends TWindow {
String[] array = checkBox.getText().split(" : ");
String groupName = array[0];
if (groupName.equals("Clock") || groupName.equals("Battery")
|| groupName.equals("Smileys")) {
|| groupName.equals("Smileys")
|| groupName.equals("Test")) {
checkBox.setText(array.length > 1 ? (checkBox.getText()
.substring(groupName.length() + 3)) : "Visible");
@ -470,30 +496,61 @@ public class ConfigWindow extends TWindow {
}
if (p instanceof JTextField) {
JTextField jTextField = ((JTextField) p);
jTextField.setMaximumSize(new Dimension(150, 25));
JTextField textField = ((JTextField) p);
if(textField.getText().startsWith("test.clock.custom.")) {
String key = textField.getText();
textField.setText("");
textField.putClientProperty(CLIENT_PROPERTY_KEY, key);
addToNextRow(new JLabel(TimeCalcProperty.forKey(key).getDescription()));
}
textField.setMaximumSize(new Dimension(150, 25));
String timeCalcPropertyKey =
(String) jTextField.getClientProperty(
(String) textField.getClientProperty(
CLIENT_PROPERTY_KEY);
TimeCalcProperty timeCalcProperty
= TimeCalcProperty.forKey(timeCalcPropertyKey);
jTextField.setText((String) timeCalcConfiguration
boolean isInteger = Integer.class == timeCalcProperty.getClazz();
timeCalcConfiguration
.getProperty(timeCalcProperty).addListener(e -> {
System.out.println("JTextField was changed: " + timeCalcPropertyKey);
textField.setText(isInteger
?
String.valueOf(timeCalcConfiguration
.getProperty(timeCalcProperty).getValue())
:
(String) timeCalcConfiguration
.getProperty(timeCalcProperty).getValue());
});
textField.setText(isInteger
?
String.valueOf(timeCalcConfiguration
.getProperty(timeCalcProperty).getValue())
:
(String) timeCalcConfiguration
.getProperty(timeCalcProperty).getValue());
jTextField.getDocument()
textField.getDocument()
.addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
System.out.println("changedUpdate");
}
public void removeUpdate(DocumentEvent e) {
System.out.println("removeUpdate");
}
public void insertUpdate(DocumentEvent e) {
System.out.println("insertUpdate");
update(e);
}
private void update(DocumentEvent e) {
String text = textField.getText();
boolean isInteger = Integer.class == timeCalcProperty.getClazz();
timeCalcConfiguration
.getProperty(timeCalcProperty)
.setValue(
jTextField.getText());
.setValue(isInteger ? Integer.valueOf(text):
text);
}
});
}

View File

@ -127,9 +127,10 @@ public class MainWindow extends TWindow {
.isEnabled()) {
timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name());
}
Time time = new Time();
TimeCalcKeyAdapter timeCalcKeyAdapter =
new TimeCalcKeyAdapter(timeCalcConfiguration, timeCalcApp,
this);
this, time);
addKeyListener(timeCalcKeyAdapter);
AnalogClock analogClock = new AnalogClock(startTime, endTime);
@ -258,8 +259,14 @@ public class MainWindow extends TWindow {
.log(Level.SEVERE, null, ex);
}
Time time = new Time();
time.yearCustomProperty.bindTo(timeCalcConfiguration.testYearCustomProperty);
time.monthCustomProperty.bindTo(timeCalcConfiguration.testMonthCustomProperty);
time.dayCustomProperty.bindTo(timeCalcConfiguration.testDayCustomProperty);
time.hourCustomProperty.bindTo(timeCalcConfiguration.testHourCustomProperty);
time.minuteCustomProperty.bindTo(timeCalcConfiguration.testMinuteCustomProperty);
time.secondCustomProperty.bindTo(timeCalcConfiguration.testSecondCustomProperty);
time.millisecondCustomProperty.bindTo(timeCalcConfiguration.testMillisecondCustomProperty);
time.allowCustomValuesProperty.setValue(true);
bindToIfPropertyMissing(testProperties, "test.current.day", calNow,
Calendar.DAY_OF_MONTH, analogClock.dayProperty,
time.dayProperty);

View File

@ -1,5 +1,6 @@
package org.nanoboot.utils.timecalc.swing.progress;
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
import org.nanoboot.utils.timecalc.utils.property.IntegerProperty;
import org.nanoboot.utils.timecalc.utils.property.ReadOnlyProperty;
@ -7,7 +8,6 @@ import java.util.Calendar;
import java.util.Date;
public class Time extends Thread {
private final IntegerProperty yearReadWriteProperty
= new IntegerProperty("yearProperty");
private final IntegerProperty monthReadWriteProperty
@ -40,6 +40,22 @@ public class Time extends Thread {
= millisecondReadWriteProperty.asReadOnlyProperty();
public ReadOnlyProperty<Integer> dayOfWeek
= dayOfWeekReadWriteProperty.asReadOnlyProperty();
public final IntegerProperty yearCustomProperty
= new IntegerProperty("yearCustomProperty", Integer.MAX_VALUE);
public final IntegerProperty monthCustomProperty
= new IntegerProperty("monthCustomProperty", Integer.MAX_VALUE);
public final IntegerProperty dayCustomProperty
= new IntegerProperty("dayCustomProperty", Integer.MAX_VALUE);
public final IntegerProperty hourCustomProperty
= new IntegerProperty("hourCustomProperty", Integer.MAX_VALUE);
public final IntegerProperty minuteCustomProperty
= new IntegerProperty("minuteCustomProperty", Integer.MAX_VALUE);
public final IntegerProperty secondCustomProperty
= new IntegerProperty("secondCustomProperty", Integer.MAX_VALUE);
public final IntegerProperty millisecondCustomProperty
= new IntegerProperty("millisecondCustomProperty", Integer.MAX_VALUE);
public final BooleanProperty allowCustomValuesProperty
= new BooleanProperty("allowCustomValuesProperty", false);
//private long lastUpdateNanoTime = 0l;
public Time() {
@ -47,19 +63,31 @@ public class Time extends Thread {
start();
}
public Calendar asCalendar() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, yearProperty.getValue());
cal.set(Calendar.MONTH, monthProperty.getValue() -1);
cal.set(Calendar.DAY_OF_MONTH, dayProperty.getValue());
cal.set(Calendar.HOUR_OF_DAY, hourProperty.getValue());
cal.set(Calendar.MINUTE, minuteProperty.getValue());
cal.set(Calendar.SECOND, secondProperty.getValue());
cal.set(Calendar.MILLISECOND, millisecondProperty.getValue());
return cal;
}
public void run() {
while (true) {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
yearReadWriteProperty.setValue(cal.get(Calendar.YEAR));
monthReadWriteProperty.setValue(cal.get(Calendar.MONTH) + 1);
dayReadWriteProperty.setValue(cal.get(Calendar.DAY_OF_MONTH));
hourReadWriteProperty.setValue(cal.get(Calendar.HOUR_OF_DAY));
minuteReadWriteProperty.setValue(cal.get(Calendar.MINUTE));
secondReadWriteProperty.setValue(cal.get(Calendar.SECOND));
millisecondReadWriteProperty
.setValue(cal.get(Calendar.MILLISECOND));
yearReadWriteProperty.setValue(returnCustomValueIfNeeded(cal, Calendar.YEAR, yearCustomProperty, yearProperty));
monthReadWriteProperty.setValue(returnCustomValueIfNeeded(cal, Calendar.MONTH, monthCustomProperty, monthProperty));
dayReadWriteProperty.setValue(returnCustomValueIfNeeded(cal, Calendar.DAY_OF_MONTH, dayCustomProperty, dayProperty));
hourReadWriteProperty.setValue(returnCustomValueIfNeeded(cal, Calendar.HOUR_OF_DAY, hourCustomProperty, hourProperty));
minuteReadWriteProperty.setValue(returnCustomValueIfNeeded(cal, Calendar.MINUTE, minuteCustomProperty, minuteProperty));
secondReadWriteProperty.setValue(returnCustomValueIfNeeded(cal, Calendar.SECOND, secondCustomProperty, secondProperty));
millisecondReadWriteProperty.setValue(returnCustomValueIfNeeded(cal, Calendar.MILLISECOND, millisecondCustomProperty, millisecondProperty));
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
dayOfWeekReadWriteProperty
.setValue(dayOfWeek == 1 ? 7 : dayOfWeek - 1);
@ -83,4 +111,17 @@ public class Time extends Thread {
+ dayOfWeek.getValue() + " "
);
}
private int returnCustomValueIfNeeded(Calendar cal, int timeUnit,
IntegerProperty custom,
ReadOnlyProperty<Integer> real) {
boolean allow = allowCustomValuesProperty.isEnabled();
Integer customValue = custom.getValue();
if(allow && customValue != Integer.MAX_VALUE) {
return custom.getValue();
} else {
return timeUnit == Calendar.MONTH ? (cal.get(timeUnit) + 1) : cal.get(timeUnit);
}
}
}

View File

@ -13,4 +13,7 @@ public class IntegerProperty extends Property<Integer> {
public IntegerProperty(String name) {
this(name, 0);
}
public void increment() {this.setValue(getValue() + 1);}
public void decrement() {this.setValue(getValue() - 1);}
}

View File

@ -164,6 +164,13 @@ Smileys can be colored or white-black (can be set in configuration)
* L - hide or show progress circle
* M - hide or show walking human
* Y - hide or show smileys
* LEFT - switch to previous profile
* RIGHT - switch to next profile
* K - hide or show clock
* SHIFT + {Y,O,D,H,M,S or I} - Increase test time value
* CTRL + {Y,O,D,H,M,S or I} - Decrease test time value
* ALT + {Y,O,D,H,M,S or I} - Rest test time value
* D - Reset custom time values to the real time
## Command button

View File

@ -46,7 +46,13 @@ circle.visible=true
walking-human.visible=true
main-window.custom-title=---
profile.name=
test.clock.custom.year=2147483647
test.clock.custom.month=2147483647
test.clock.custom.day=2147483647
test.clock.custom.hour=2147483647
test.clock.custom.minute=2147483647
test.clock.custom.second=2147483647
test.clock.custom.millisecond=2147483647
#TODO:
logs.detailed=false
battery.percent-precision.count-of-decimal-points=5