Added new improvements
This commit is contained in:
parent
67a66a60f6
commit
597346e5d8
@ -18,7 +18,7 @@ import java.io.IOException;
|
||||
public class TimeCalcApp {
|
||||
|
||||
private long startNanoTime = 0l;
|
||||
public StringProperty visibilityProperty = new StringProperty("visibilityReadWriteProperty", Visibility.STRONGLY_COLORED.name());
|
||||
public StringProperty visibilityProperty = new StringProperty("timeCalcApp.visibilityReadWriteProperty", Visibility.WEAKLY_COLORED.name());
|
||||
public BooleanProperty
|
||||
wavesProperty = new BooleanProperty("waves", true);
|
||||
|
||||
|
@ -14,6 +14,7 @@ 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;
|
||||
@ -51,6 +52,7 @@ public class TimeCalcManager {
|
||||
private final TimeHM endTime;
|
||||
private final TimeCalcApp timeCalcApp;
|
||||
private boolean stopBeforeEnd = false;
|
||||
private Time time = new Time();
|
||||
|
||||
public TimeCalcManager(String startTimeIn, String overTimeIn,
|
||||
TimeCalcApp timeCalcApp) {
|
||||
@ -170,7 +172,6 @@ public class TimeCalcManager {
|
||||
this.windowTitle = createWindowTitle();
|
||||
window.setTitle(windowTitle);
|
||||
|
||||
|
||||
weatherButton
|
||||
.addActionListener(e -> new WeatherWindow().setVisible(true));
|
||||
commandButton
|
||||
@ -350,8 +351,15 @@ public class TimeCalcManager {
|
||||
restartButton.setVisible(!Visibility.valueOf(restartButton.visibilityProperty.getValue()).isNone());
|
||||
exitButton.setVisible(!Visibility.valueOf(exitButton.visibilityProperty.getValue()).isNone());
|
||||
|
||||
// timeCalcApp.visibilityProperty.addListener((Property<String> p, String oldValue, String newValue)-> {
|
||||
// System.out.println("Visibility of timeCalcApp was changed FROM " + oldValue + " TO " + newValue);
|
||||
// } );
|
||||
// analogClock.visibilityProperty.addListener((Property<String> p, String oldValue, String newValue)-> {
|
||||
// System.out.println("Visibility of analogClock was changed FROM " + oldValue + " TO " + newValue);
|
||||
// } );
|
||||
window.setSize(520 + 20 + 100, exitButton.getY() + 3 * exitButton.getHeight() + MARGIN);
|
||||
while (true) {
|
||||
//time.writeString();
|
||||
if(Math.random() > 0.95) {
|
||||
window.requestFocus();
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public class Widget extends JPanel {
|
||||
protected double donePercent = 0;
|
||||
protected boolean mouseOver = false;
|
||||
|
||||
public StringProperty visibilityProperty = new StringProperty("visibilityProperty", Visibility.STRONGLY_COLORED.name());
|
||||
public StringProperty visibilityProperty = new StringProperty("widget.visibilityProperty", Visibility.STRONGLY_COLORED.name());
|
||||
|
||||
public Widget() {
|
||||
setBackground(BACKGROUND_COLOR);
|
||||
|
@ -0,0 +1,72 @@
|
||||
package org.nanoboot.utils.timecalc.swing.progress;
|
||||
|
||||
import org.nanoboot.utils.timecalc.utils.property.IntegerProperty;
|
||||
import org.nanoboot.utils.timecalc.utils.property.ReadOnlyProperty;
|
||||
|
||||
import javax.swing.Timer;
|
||||
import java.awt.Graphics;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class Time extends Thread {
|
||||
|
||||
private IntegerProperty yearReadWriteProperty = new IntegerProperty("yearProperty");
|
||||
private IntegerProperty monthReadWriteProperty = new IntegerProperty("monthProperty");
|
||||
private IntegerProperty dayReadWriteProperty = new IntegerProperty("dayProperty");
|
||||
private IntegerProperty hourReadWriteProperty = new IntegerProperty("hourProperty");
|
||||
private IntegerProperty minuteReadWriteProperty = new IntegerProperty("minuteProperty");
|
||||
private IntegerProperty secondReadWriteProperty = new IntegerProperty("secondProperty");
|
||||
private IntegerProperty millisecondReadWriteProperty = new IntegerProperty("millisecondProperty");
|
||||
private IntegerProperty dayOfWeekReadWriteProperty = new IntegerProperty("dayOfWeek");
|
||||
public ReadOnlyProperty<Integer> yearProperty = yearReadWriteProperty.asReadOnlyProperty();
|
||||
public ReadOnlyProperty<Integer> monthProperty = monthReadWriteProperty.asReadOnlyProperty();
|
||||
public ReadOnlyProperty<Integer> dayProperty = dayReadWriteProperty.asReadOnlyProperty();
|
||||
public ReadOnlyProperty<Integer> hourProperty = hourReadWriteProperty.asReadOnlyProperty();
|
||||
public ReadOnlyProperty<Integer> minuteProperty = minuteReadWriteProperty.asReadOnlyProperty();
|
||||
public ReadOnlyProperty<Integer> secondProperty = secondReadWriteProperty.asReadOnlyProperty();
|
||||
public ReadOnlyProperty<Integer> millisecondProperty = millisecondReadWriteProperty.asReadOnlyProperty();
|
||||
public ReadOnlyProperty<Integer> dayOfWeek = dayOfWeekReadWriteProperty.asReadOnlyProperty();
|
||||
//private long lastUpdateNanoTime = 0l;
|
||||
|
||||
public Time() {
|
||||
this.setDaemon(true);
|
||||
start();
|
||||
}
|
||||
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));
|
||||
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
|
||||
dayOfWeekReadWriteProperty
|
||||
.setValue(dayOfWeek == 1 ? 7 : dayOfWeek - 1);
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void writeString() {
|
||||
System.out.println(
|
||||
yearProperty.getValue() + " " +
|
||||
monthProperty.getValue() + " " +
|
||||
dayProperty.getValue() + " " +
|
||||
hourProperty.getValue() + " " +
|
||||
minuteProperty.getValue() + " " +
|
||||
secondProperty.getValue() + " " +
|
||||
millisecondProperty.getValue() + " " +
|
||||
dayOfWeek.getValue() + " "
|
||||
|
||||
);
|
||||
}
|
||||
}
|
@ -20,4 +20,6 @@ public class DateFormats {
|
||||
//
|
||||
public static DateFormat DATE_TIME_FORMATTER_TIME =
|
||||
new SimpleDateFormat("HH:mm:ss", Locale.ENGLISH);
|
||||
public static DateFormat DATE_TIME_FORMATTER_VERY_LONG =
|
||||
new SimpleDateFormat("yyyy:MM:dd:HH:mm:ss:EEEE", Locale.ENGLISH);
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
package org.nanoboot.utils.timecalc.utils.property;
|
||||
|
||||
/**
|
||||
* @author Robert
|
||||
* @since 23.02.2024
|
||||
*/
|
||||
public interface ChangeListener<T> {
|
||||
void changed(Property<T> property, T oldValue, T newValue);
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package org.nanoboot.utils.timecalc.utils.property;
|
||||
|
||||
/**
|
||||
* @author Robert
|
||||
* @since 16.02.2024
|
||||
*/
|
||||
public class IntegerProperty extends Property<Integer> {
|
||||
|
||||
public IntegerProperty(String name, Integer valueIn) {
|
||||
super(name, valueIn);
|
||||
}
|
||||
|
||||
public IntegerProperty(String name) {
|
||||
this(name, 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package org.nanoboot.utils.timecalc.utils.property;
|
||||
|
||||
import javafx.beans.Observable;
|
||||
|
||||
/**
|
||||
* @author Robert
|
||||
* @since 23.02.2024
|
||||
*/
|
||||
public interface InvalidationListener {
|
||||
|
||||
void invalidated(Property property);
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package org.nanoboot.utils.timecalc.utils.property;
|
||||
|
||||
/**
|
||||
* @author Robert
|
||||
* @since 16.02.2024
|
||||
*/
|
||||
public class ObjectProperty extends Property<Object> {
|
||||
|
||||
public ObjectProperty(String name, Object valueIn) {
|
||||
super(name, valueIn);
|
||||
}
|
||||
|
||||
public ObjectProperty() {
|
||||
this("", null);
|
||||
}
|
||||
}
|
@ -1,18 +1,25 @@
|
||||
package org.nanoboot.utils.timecalc.utils.property;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.nanoboot.utils.timecalc.app.TimeCalcException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Robert
|
||||
* @since 23.02.2024
|
||||
*/
|
||||
public class Property <T>{
|
||||
private boolean valid = true;
|
||||
@Getter
|
||||
private final String name;
|
||||
private T value;
|
||||
private Property<T> boundToProperty = null;
|
||||
private List<InvalidationListener> invalidationListeners = new ArrayList<>();
|
||||
private List<ChangeListener<T>>
|
||||
changeListeners = new ArrayList<ChangeListener<T>>();
|
||||
|
||||
public Property(String name, T valueIn) {
|
||||
this.name = name; this.value = valueIn;
|
||||
}
|
||||
@ -34,16 +41,51 @@ public class Property <T>{
|
||||
}
|
||||
public void bindTo(Property<T> anotherProperty) {
|
||||
this.boundToProperty = anotherProperty;
|
||||
this.boundToProperty.addListener((Property<T> p, T oldValue, T newValue) -> {this.markInvalid();this.fireValueChangedEvent(oldValue);
|
||||
//System.out.println("bindTo markInvalid " + p.getName() + " " + p.getValue());
|
||||
} );
|
||||
}
|
||||
public T getValue() {
|
||||
return isBound() ? this.boundToProperty.getValue() : value;
|
||||
}
|
||||
|
||||
public void setValue(T value) {
|
||||
public void setValue(T newValue) {
|
||||
if(isBound()) {
|
||||
this.boundToProperty.setValue(value);
|
||||
this.boundToProperty.setValue(newValue);
|
||||
} else {
|
||||
this.value = value;
|
||||
T oldValue = value;
|
||||
this.value = newValue;
|
||||
if(!oldValue.equals(newValue))
|
||||
{
|
||||
fireValueChangedEvent(oldValue);
|
||||
markInvalid();
|
||||
}
|
||||
}
|
||||
}
|
||||
public boolean isValid() {
|
||||
return isBound() ? this.boundToProperty.isValid() : valid;
|
||||
}
|
||||
protected void markInvalid() {
|
||||
// System.out.println(name + " is invalid now");
|
||||
valid = false;
|
||||
for (InvalidationListener listener : invalidationListeners) {
|
||||
listener.invalidated(this);
|
||||
}
|
||||
}
|
||||
protected void fireValueChangedEvent(T oldValue) {
|
||||
// System.out.println(name + " was changed");
|
||||
for (ChangeListener listener : changeListeners) {
|
||||
listener.changed(this, oldValue, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void addListener(InvalidationListener listener) {
|
||||
this.invalidationListeners.add(listener);
|
||||
}
|
||||
public void addListener(ChangeListener<T> listener) {
|
||||
this.changeListeners.add(listener);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -15,8 +15,9 @@ public class ReadOnlyProperty<T> extends Property<T> {
|
||||
public ReadOnlyProperty(Property<T> property) {
|
||||
super(property.getName(), null);
|
||||
this.innerProperty = property;
|
||||
this.innerProperty.addListener((Property p) -> {markInvalid();} );
|
||||
}
|
||||
public final void setValue(T valueIn) {
|
||||
public final void setValue(T newValue) {
|
||||
throw new TimeCalcException("This is a read only property. New value cannot be set.");
|
||||
}
|
||||
|
||||
@ -29,5 +30,9 @@ public class ReadOnlyProperty<T> extends Property<T> {
|
||||
public final void bindTo(Property<T> anotherProperty) {
|
||||
throw new TimeCalcException("This is a write only property. Bounding to another property is forbiden.");
|
||||
}
|
||||
public boolean isValid() {
|
||||
return this.innerProperty.isValid();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ public class WriteOnlyProperty<T> extends Property<T> {
|
||||
super(property.getName(), null);
|
||||
this.innerProperty = property;
|
||||
}
|
||||
public final void setValue(T valueIn) {
|
||||
this.innerProperty.setValue(valueIn);
|
||||
public final void setValue(T newValue) {
|
||||
this.innerProperty.setValue(newValue);
|
||||
}
|
||||
|
||||
public final T getValue(T valueIn) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user