mirror of
https://github.com/robertvokac/time-calc.git
synced 2025-03-25 07:27:49 +01:00
Added sqlite support - wip 2
This commit is contained in:
parent
9c4577dddd
commit
32fc2a338d
10
Readme.md
10
Readme.md
@ -165,10 +165,14 @@ Smileys can be colored or white-black (can be set in configuration)
|
|||||||
* LEFT - switch to previous profile
|
* LEFT - switch to previous profile
|
||||||
* RIGHT - switch to next profile
|
* RIGHT - switch to next profile
|
||||||
* K - hide or show clock
|
* K - hide or show clock
|
||||||
* SHIFT + {Y,O,D,H,M,S or I} - Increase test time value
|
* SHIFT + {Y,N,D,H,M,S or I} - Increase test time value
|
||||||
* CTRL + {Y,O,D,H,M,S or I} - Decrease test time value
|
* CTRL + {Y,N,D,H,M,S or I} - Decrease test time value
|
||||||
* ALT + {Y,O,D,H,M,S or I} - Rest test time value
|
* ALT + {Y,N,D,H,M,S or I} - Rest test time value
|
||||||
* D - Reset custom time values to the real time
|
* D - Reset custom time values to the real time
|
||||||
|
* SHIFT + A - Increase arrival time by 1 minute
|
||||||
|
* CTRL + A - Decrease arrival time by 1 minute
|
||||||
|
* SHIFT + O - Increase overtime by 1 minute
|
||||||
|
* CTRL + O - Decrease overtime time by 1 minute
|
||||||
|
|
||||||
## Command button
|
## Command button
|
||||||
|
|
||||||
|
@ -69,6 +69,7 @@ public class TimeCalcApp {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
JOptionPane.showMessageDialog(null, "Error: " + e.getMessage(),
|
JOptionPane.showMessageDialog(null, "Error: " + e.getMessage(),
|
||||||
e.getMessage(), JOptionPane.ERROR_MESSAGE);
|
e.getMessage(), JOptionPane.ERROR_MESSAGE);
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,12 +55,15 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
|
|||||||
private void processTestModeKeyCode(int keyCode, boolean shiftDown,
|
private void processTestModeKeyCode(int keyCode, boolean shiftDown,
|
||||||
boolean ctrlDown, boolean altDown) {
|
boolean ctrlDown, boolean altDown) {
|
||||||
if (shiftDown && ctrlDown) {
|
if (shiftDown && ctrlDown) {
|
||||||
|
Utils.showNotification("Following key shortcut is not supported: SHIFT + CTRL");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (shiftDown && altDown) {
|
if (shiftDown && altDown) {
|
||||||
|
Utils.showNotification("Following key shortcut is not supported: SHIFT + ALT");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ctrlDown && altDown) {
|
if (ctrlDown && altDown) {
|
||||||
|
Utils.showNotification("Following key shortcut is not supported: CTRL + ALT");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean increase = shiftDown;
|
boolean increase = shiftDown;
|
||||||
@ -73,7 +76,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
|
|||||||
Calendar.YEAR);
|
Calendar.YEAR);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case KeyEvent.VK_O: {
|
case KeyEvent.VK_N: {
|
||||||
//Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " month.");
|
//Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " month.");
|
||||||
updateProperty(timeCalcConfiguration.testMonthCustomProperty, increase, decrease, reset,
|
updateProperty(timeCalcConfiguration.testMonthCustomProperty, increase, decrease, reset,
|
||||||
Calendar.MONTH);
|
Calendar.MONTH);
|
||||||
@ -109,10 +112,30 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
|
|||||||
Calendar.MILLISECOND);
|
Calendar.MILLISECOND);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case KeyEvent.VK_A: {
|
||||||
|
//Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " millisecond.");
|
||||||
|
if(increase) {
|
||||||
|
window.increaseArrivalByOneMinute();
|
||||||
|
}
|
||||||
|
if(decrease) {
|
||||||
|
window.decreaseArrivalByOneMinute();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case KeyEvent.VK_O: {
|
||||||
|
//Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " millisecond.");
|
||||||
|
if(increase) {
|
||||||
|
window.increaseOvertimeByOneMinute();
|
||||||
|
}
|
||||||
|
if(decrease) {
|
||||||
|
window.decreaseOvertimeByOneMinute();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
Utils.showNotification(
|
// Utils.showNotification(
|
||||||
"Unsupported key was pressed. There is no key shortcut for this key: "
|
// "Unsupported key was pressed. There is no key shortcut for this key: "
|
||||||
+ keyCode);
|
// + keyCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,7 +252,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
|
|||||||
} else {
|
} else {
|
||||||
timeCalcApp.visibilityProperty
|
timeCalcApp.visibilityProperty
|
||||||
.setValue(Visibility.GRAY.name());
|
.setValue(Visibility.GRAY.name());
|
||||||
MainWindow.hideShowCheckBox.setSelected(false);
|
MainWindow.hideShowFormsCheckBox.setSelected(false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -341,8 +364,8 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case KeyEvent.VK_B: {
|
case KeyEvent.VK_B: {
|
||||||
MainWindow.hideShowCheckBox
|
MainWindow.hideShowFormsCheckBox
|
||||||
.setSelected(!MainWindow.hideShowCheckBox.isSelected());
|
.setSelected(!MainWindow.hideShowFormsCheckBox.isSelected());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case KeyEvent.VK_F: {
|
case KeyEvent.VK_F: {
|
||||||
|
@ -33,10 +33,12 @@ class WorkingDayTable {
|
|||||||
public static final String YEAR = "YEAR";
|
public static final String YEAR = "YEAR";
|
||||||
public static final String MONTH = "MONTH";
|
public static final String MONTH = "MONTH";
|
||||||
public static final String DAY = "DAY";
|
public static final String DAY = "DAY";
|
||||||
|
|
||||||
public static final String ARRIVAL_HOUR = "ARRIVAL_HOUR";
|
public static final String ARRIVAL_HOUR = "ARRIVAL_HOUR";
|
||||||
public static final String ARRIVAL_MINUTE = "ARRIVAL_MINUTE";
|
public static final String ARRIVAL_MINUTE = "ARRIVAL_MINUTE";
|
||||||
public static final String HALF_DAY = "HALF_DAY";
|
public static final String HALF_DAY = "HALF_DAY";
|
||||||
public static final String OVERTIME_HOUR = "OVERTIME_HOUR";
|
public static final String OVERTIME_HOUR = "OVERTIME_HOUR";
|
||||||
|
|
||||||
public static final String OVERTIME_MINUTE = "OVERTIME_MINUTE";
|
public static final String OVERTIME_MINUTE = "OVERTIME_MINUTE";
|
||||||
public static final String PAUSE_TIME_IN_MINUTES = "PAUSE_TIME_IN_MINUTES";
|
public static final String PAUSE_TIME_IN_MINUTES = "PAUSE_TIME_IN_MINUTES";
|
||||||
public static final String NOTE = "NOTE";
|
public static final String NOTE = "NOTE";
|
||||||
|
@ -36,8 +36,8 @@ public class ComponentRegistry<T extends Component> {
|
|||||||
|
|
||||||
public void setVisible(Predicate<Component> predicate, boolean b) {
|
public void setVisible(Predicate<Component> predicate, boolean b) {
|
||||||
for (T c : set) {
|
for (T c : set) {
|
||||||
if (c instanceof TButton) {
|
if (c instanceof TButton || c instanceof TTextField || c instanceof TLabel || c instanceof TCheckBox) {
|
||||||
if (!MainWindow.hideShowCheckBox.isSelected() && b) {
|
if (!MainWindow.hideShowFormsCheckBox.isSelected() && b) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -281,7 +281,7 @@ public class ConfigWindow extends TWindow {
|
|||||||
squareVisibleProperty.setSelected(enable);
|
squareVisibleProperty.setSelected(enable);
|
||||||
circleVisibleProperty.setSelected(enable);
|
circleVisibleProperty.setSelected(enable);
|
||||||
walkingHumanVisibleProperty.setSelected(enable);
|
walkingHumanVisibleProperty.setSelected(enable);
|
||||||
MainWindow.hideShowCheckBox.setSelected(enable);
|
MainWindow.hideShowFormsCheckBox.setSelected(enable);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,16 +22,15 @@ import org.nanoboot.utils.timecalc.swing.progress.WeekBattery;
|
|||||||
import org.nanoboot.utils.timecalc.swing.progress.YearBattery;
|
import org.nanoboot.utils.timecalc.swing.progress.YearBattery;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.Constants;
|
import org.nanoboot.utils.timecalc.utils.common.Constants;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.Jokes;
|
import org.nanoboot.utils.timecalc.utils.common.Jokes;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.TimeHM;
|
import org.nanoboot.utils.timecalc.utils.common.TTime;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||||
|
|
||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.time.DayOfWeek;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.time.LocalDate;
|
import java.beans.PropertyVetoException;
|
||||||
import java.util.Calendar;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert Vokac
|
* @author Robert Vokac
|
||||||
@ -41,7 +40,7 @@ public class MainWindow extends TWindow {
|
|||||||
|
|
||||||
public static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
|
public static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
|
||||||
public static final Color FOREGROUND_COLOR = new Color(210, 210, 210);
|
public static final Color FOREGROUND_COLOR = new Color(210, 210, 210);
|
||||||
public static final JCheckBox hideShowCheckBox = new JCheckBox();
|
public static final JCheckBox hideShowFormsCheckBox = new JCheckBox();
|
||||||
private final TButton workDaysButton;
|
private final TButton workDaysButton;
|
||||||
private final TButton activitiesButton;
|
private final TButton activitiesButton;
|
||||||
private final TButton exitButton;
|
private final TButton exitButton;
|
||||||
@ -55,12 +54,30 @@ public class MainWindow extends TWindow {
|
|||||||
private final AboutButton aboutButton;
|
private final AboutButton aboutButton;
|
||||||
private final TimeCalcConfiguration timeCalcConfiguration
|
private final TimeCalcConfiguration timeCalcConfiguration
|
||||||
= new TimeCalcConfiguration();
|
= new TimeCalcConfiguration();
|
||||||
|
private final TTextField arrivalTextField;
|
||||||
|
private final TTextField overtimeTextField;
|
||||||
|
private final TCheckBox halfDayCheckBox;
|
||||||
|
private final TTextField pauseTimeInMinutesTextField;
|
||||||
|
private final TTextField noteTextField;
|
||||||
|
private final TTextField departureTextField;
|
||||||
|
private final TTextField elapsedTextField;
|
||||||
|
private final TTextField remainingTextField;
|
||||||
private HelpWindow helpWindow = null;
|
private HelpWindow helpWindow = null;
|
||||||
private ConfigWindow configWindow = null;
|
private ConfigWindow configWindow = null;
|
||||||
private ActivitiesWindow activitiesWindow = null;
|
private ActivitiesWindow activitiesWindow = null;
|
||||||
private WorkingDaysWindow workingDaysWindow = null;
|
private WorkingDaysWindow workingDaysWindow = null;
|
||||||
private boolean stopBeforeEnd = false;
|
private boolean stopBeforeEnd = false;
|
||||||
|
|
||||||
|
{
|
||||||
|
this.arrivalTextField = new TTextField();
|
||||||
|
this.overtimeTextField = new TTextField();
|
||||||
|
this.halfDayCheckBox = new TCheckBox("Half day:", false);
|
||||||
|
this.pauseTimeInMinutesTextField = new TTextField("30");
|
||||||
|
this.noteTextField = new TTextField();
|
||||||
|
this.departureTextField = new TTextField();
|
||||||
|
this.elapsedTextField = new TTextField("", 100);
|
||||||
|
this.remainingTextField = new TTextField("", 100);
|
||||||
|
}
|
||||||
public MainWindow(String startTimeIn, String overTimeIn,
|
public MainWindow(String startTimeIn, String overTimeIn,
|
||||||
TimeCalcApp timeCalcApp) {
|
TimeCalcApp timeCalcApp) {
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
@ -77,23 +94,25 @@ public class MainWindow extends TWindow {
|
|||||||
timeCalcConfiguration.mainWindowCustomTitleProperty.addListener(e -> {
|
timeCalcConfiguration.mainWindowCustomTitleProperty.addListener(e -> {
|
||||||
setTitle(getWindowTitle());
|
setTitle(getWindowTitle());
|
||||||
});
|
});
|
||||||
|
|
||||||
overTimeIn = (overTimeIn == null || overTimeIn.isEmpty())
|
overTimeIn = (overTimeIn == null || overTimeIn.isEmpty())
|
||||||
? Constants.DEFAULT_OVERTIME : overTimeIn;
|
? Constants.DEFAULT_OVERTIME : overTimeIn;
|
||||||
|
|
||||||
TimeHM startTime = new TimeHM(startTimeIn);
|
arrivalTextField.valueProperty.setValue(startTimeIn);
|
||||||
TimeHM overtime = new TimeHM(overTimeIn);
|
overtimeTextField.valueProperty.setValue(overTimeIn);
|
||||||
|
|
||||||
TimeHM endTime = new TimeHM(
|
arrivalTextField.addVetoableChangeListener(e -> {
|
||||||
startTime.getHour() + Constants.WORKING_HOURS_LENGTH + overtime
|
String newValue = (String) e.getNewValue();
|
||||||
.getHour(),
|
if(newValue.isEmpty()) {
|
||||||
startTime.getMinute() + Constants.WORKING_MINUTES_LENGTH
|
throw new PropertyVetoException("Arrival must not be empty.", new PropertyChangeEvent(e.getSource(), e.getPropertyName(), e.getOldValue(), e.getNewValue()));
|
||||||
+ overtime.getMinute());
|
}
|
||||||
|
});
|
||||||
int totalMinutes = TimeHM.countDiffInMinutes(startTime, endTime);
|
|
||||||
int totalSeconds = totalMinutes * TimeHM.SECONDS_PER_MINUTE;
|
|
||||||
int totalMilliseconds = totalSeconds * TimeHM.MILLISECONDS_PER_SECOND;
|
|
||||||
|
|
||||||
|
overtimeTextField.addVetoableChangeListener(e -> {
|
||||||
|
String newValue = (String) e.getNewValue();
|
||||||
|
if(newValue.isEmpty()) {
|
||||||
|
throw new PropertyVetoException("Overtime must not be empty.", new PropertyChangeEvent(e.getSource(), e.getPropertyName(), e.getOldValue(), e.getNewValue()));
|
||||||
|
}
|
||||||
|
});
|
||||||
this.configButton = new TButton("Config");
|
this.configButton = new TButton("Config");
|
||||||
this.workDaysButton = new TButton("Work Days");
|
this.workDaysButton = new TButton("Work Days");
|
||||||
this.activitiesButton = new TButton("Activities"
|
this.activitiesButton = new TButton("Activities"
|
||||||
@ -110,7 +129,7 @@ public class MainWindow extends TWindow {
|
|||||||
//window.add(weatherButton);
|
//window.add(weatherButton);
|
||||||
addAll(configButton, workDaysButton, activitiesButton, restartButton,
|
addAll(configButton, workDaysButton, activitiesButton, restartButton,
|
||||||
exitButton, focusButton, helpButton, commandButton, jokeButton,
|
exitButton, focusButton, helpButton, commandButton, jokeButton,
|
||||||
hideShowCheckBox);
|
hideShowFormsCheckBox);
|
||||||
|
|
||||||
timeCalcApp.visibilityProperty
|
timeCalcApp.visibilityProperty
|
||||||
.bindTo(timeCalcConfiguration.visibilityDefaultProperty);
|
.bindTo(timeCalcConfiguration.visibilityDefaultProperty);
|
||||||
@ -124,7 +143,29 @@ public class MainWindow extends TWindow {
|
|||||||
this, time);
|
this, time);
|
||||||
addKeyListener(timeCalcKeyAdapter);
|
addKeyListener(timeCalcKeyAdapter);
|
||||||
|
|
||||||
AnalogClock analogClock = new AnalogClock(startTime, endTime);
|
AnalogClock analogClock = new AnalogClock();
|
||||||
|
|
||||||
|
{
|
||||||
|
arrivalTextField.valueProperty.addListener(e -> {
|
||||||
|
if (!arrivalTextField.valueProperty.getValue().isEmpty()) {
|
||||||
|
TTime startTime_ = arrivalTextField.asTimeHM();
|
||||||
|
analogClock.startHourProperty
|
||||||
|
.setValue(startTime_.getHour());
|
||||||
|
analogClock.startMinuteProperty
|
||||||
|
.setValue(startTime_.getMinute());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
departureTextField.valueProperty.addListener(e -> {
|
||||||
|
if (!departureTextField.valueProperty.getValue().isEmpty()) {
|
||||||
|
TTime endTime = arrivalTextField.asTimeHM();
|
||||||
|
analogClock.endHourProperty
|
||||||
|
.setValue(endTime.getHour());
|
||||||
|
analogClock.endMinuteProperty
|
||||||
|
.setValue(endTime.getMinute());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
analogClock.setBounds(SwingUtils.MARGIN, SwingUtils.MARGIN, 200);
|
analogClock.setBounds(SwingUtils.MARGIN, SwingUtils.MARGIN, 200);
|
||||||
add(analogClock);
|
add(analogClock);
|
||||||
|
|
||||||
@ -160,7 +201,71 @@ public class MainWindow extends TWindow {
|
|||||||
+ walkingHumanProgress.getHeight()
|
+ walkingHumanProgress.getHeight()
|
||||||
+ SwingUtils.MARGIN);
|
+ SwingUtils.MARGIN);
|
||||||
|
|
||||||
configButton.setBoundsFromTop(walkingHumanProgress);
|
TLabel arrivalTextFieldLabel = new TLabel("Arrival:");
|
||||||
|
arrivalTextFieldLabel.setBoundsFromTop(walkingHumanProgress);
|
||||||
|
|
||||||
|
arrivalTextField.setBoundsFromLeft(arrivalTextFieldLabel);
|
||||||
|
//
|
||||||
|
TLabel overtimeTextFieldLabel = new TLabel("Overtime:");
|
||||||
|
overtimeTextFieldLabel.setBoundsFromLeft(arrivalTextField);
|
||||||
|
|
||||||
|
overtimeTextField.setBoundsFromLeft(overtimeTextFieldLabel);
|
||||||
|
//
|
||||||
|
|
||||||
|
halfDayCheckBox.setBoundsFromLeft(overtimeTextField);
|
||||||
|
//
|
||||||
|
TLabel pauseTimeInMinutesFieldLabel = new TLabel("Pause:");
|
||||||
|
pauseTimeInMinutesFieldLabel.setBoundsFromLeft(halfDayCheckBox);
|
||||||
|
|
||||||
|
pauseTimeInMinutesTextField.setBoundsFromLeft(pauseTimeInMinutesFieldLabel);
|
||||||
|
//
|
||||||
|
TLabel noteTextFieldLabel = new TLabel("Note:");
|
||||||
|
noteTextFieldLabel.setBoundsFromLeft(pauseTimeInMinutesTextField);
|
||||||
|
|
||||||
|
noteTextField.setBoundsFromLeft(noteTextFieldLabel);
|
||||||
|
//half day, pause time in minutes, note
|
||||||
|
arrivalTextField.setEditable(false);
|
||||||
|
overtimeTextField.setEditable(false);
|
||||||
|
|
||||||
|
add(arrivalTextFieldLabel);
|
||||||
|
add(arrivalTextField);
|
||||||
|
add(overtimeTextFieldLabel);
|
||||||
|
add(overtimeTextField);
|
||||||
|
add(halfDayCheckBox);
|
||||||
|
|
||||||
|
add(pauseTimeInMinutesFieldLabel);
|
||||||
|
add(pauseTimeInMinutesTextField);
|
||||||
|
add(noteTextFieldLabel);
|
||||||
|
add(noteTextField);
|
||||||
|
//
|
||||||
|
TLabel departureTextFieldLabel = new TLabel("Departure:");
|
||||||
|
departureTextFieldLabel.setBoundsFromTop(arrivalTextFieldLabel);
|
||||||
|
|
||||||
|
departureTextField.setBoundsFromLeft(departureTextFieldLabel);
|
||||||
|
departureTextField.setEditable(false);
|
||||||
|
//
|
||||||
|
TLabel elapsedTextFieldLabel = new TLabel("Elapsed:");
|
||||||
|
elapsedTextFieldLabel.setBoundsFromLeft(departureTextField);
|
||||||
|
|
||||||
|
elapsedTextField.setBoundsFromLeft(elapsedTextFieldLabel);
|
||||||
|
elapsedTextField.setEditable(false);
|
||||||
|
elapsedTextField.setEditable(false);
|
||||||
|
//
|
||||||
|
TLabel remainingTextFieldLabel = new TLabel("Remaining:", 100);
|
||||||
|
remainingTextFieldLabel.setBoundsFromLeft(elapsedTextField);
|
||||||
|
|
||||||
|
remainingTextField.setBoundsFromLeft(remainingTextFieldLabel);
|
||||||
|
remainingTextField.setEditable(false);
|
||||||
|
//
|
||||||
|
|
||||||
|
add(departureTextFieldLabel);
|
||||||
|
add(departureTextField);
|
||||||
|
add(elapsedTextFieldLabel);
|
||||||
|
add(elapsedTextField);
|
||||||
|
add(remainingTextFieldLabel);
|
||||||
|
add(remainingTextField);
|
||||||
|
//
|
||||||
|
configButton.setBoundsFromTop(departureTextFieldLabel);
|
||||||
workDaysButton.setBoundsFromLeft(configButton);
|
workDaysButton.setBoundsFromLeft(configButton);
|
||||||
activitiesButton.setBoundsFromLeft(workDaysButton);
|
activitiesButton.setBoundsFromLeft(workDaysButton);
|
||||||
restartButton.setBoundsFromLeft(activitiesButton);
|
restartButton.setBoundsFromLeft(activitiesButton);
|
||||||
@ -171,8 +276,8 @@ public class MainWindow extends TWindow {
|
|||||||
focusButton.setBoundsFromLeft(helpButton);
|
focusButton.setBoundsFromLeft(helpButton);
|
||||||
commandButton.setBoundsFromLeft(focusButton);
|
commandButton.setBoundsFromLeft(focusButton);
|
||||||
jokeButton.setBoundsFromLeft(commandButton);
|
jokeButton.setBoundsFromLeft(commandButton);
|
||||||
hideShowCheckBox.setSelected(true);
|
hideShowFormsCheckBox.setSelected(true);
|
||||||
hideShowCheckBox.setBounds(
|
hideShowFormsCheckBox.setBounds(
|
||||||
jokeButton.getX() + jokeButton.getWidth() + SwingUtils.MARGIN,
|
jokeButton.getX() + jokeButton.getWidth() + SwingUtils.MARGIN,
|
||||||
jokeButton.getY(), 20, 20);
|
jokeButton.getY(), 20, 20);
|
||||||
//
|
//
|
||||||
@ -194,11 +299,7 @@ public class MainWindow extends TWindow {
|
|||||||
Jokes.showRandom();
|
Jokes.showRandom();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
hideShowCheckBox.addItemListener(e ->
|
hideShowFormsCheckBox.addItemListener(e -> this.requestFocus());
|
||||||
|
|
||||||
{
|
|
||||||
this.requestFocus();
|
|
||||||
});
|
|
||||||
exitButton.addActionListener(e
|
exitButton.addActionListener(e
|
||||||
-> {
|
-> {
|
||||||
timeCalcConfiguration.saveToTimeCalcProperties();
|
timeCalcConfiguration.saveToTimeCalcProperties();
|
||||||
@ -422,9 +523,20 @@ public class MainWindow extends TWindow {
|
|||||||
focusButton.getY() + focusButton.getHeight() + SwingUtils.MARGIN
|
focusButton.getY() + focusButton.getHeight() + SwingUtils.MARGIN
|
||||||
+ focusButton.getHeight() + 2 * SwingUtils.MARGIN);
|
+ focusButton.getHeight() + 2 * SwingUtils.MARGIN);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
//System.out.println("timeCalcConfiguration.handsLongProperty=" + timeCalcConfiguration.clockHandLongProperty.isEnabled());
|
//System.out.println("timeCalcConfiguration.handsLongProperty=" + timeCalcConfiguration.clockHandLongProperty.isEnabled());
|
||||||
|
|
||||||
|
{
|
||||||
|
TTime startTime = arrivalTextField.asTimeHM();
|
||||||
|
TTime overtime = overtimeTextField.asTimeHM();
|
||||||
|
departureTextField.valueProperty.setValue(new TTime(
|
||||||
|
startTime.getHour() + Constants.WORKING_HOURS_LENGTH + overtime
|
||||||
|
.getHour(),
|
||||||
|
startTime.getMinute() + Constants.WORKING_MINUTES_LENGTH
|
||||||
|
+ overtime.getMinute()).toString().substring(0, 5));
|
||||||
|
}
|
||||||
Visibility currentVisibility = Visibility
|
Visibility currentVisibility = Visibility
|
||||||
.valueOf(timeCalcApp.visibilityProperty.getValue());
|
.valueOf(timeCalcApp.visibilityProperty.getValue());
|
||||||
if (!timeCalcConfiguration.visibilitySupportedColoredProperty
|
if (!timeCalcConfiguration.visibilitySupportedColoredProperty
|
||||||
@ -465,7 +577,7 @@ public class MainWindow extends TWindow {
|
|||||||
TimeCalcProperties.getInstance().getBooleanProperty(
|
TimeCalcProperties.getInstance().getBooleanProperty(
|
||||||
TimeCalcProperty.JOKES_VISIBLE)
|
TimeCalcProperty.JOKES_VISIBLE)
|
||||||
&& !currentVisibility.isNone()
|
&& !currentVisibility.isNone()
|
||||||
&& MainWindow.hideShowCheckBox.isSelected());
|
&& MainWindow.hideShowFormsCheckBox.isSelected());
|
||||||
|
|
||||||
setTitle(currentVisibility.isNone() ? "" : getWindowTitle());
|
setTitle(currentVisibility.isNone() ? "" : getWindowTitle());
|
||||||
|
|
||||||
@ -474,17 +586,39 @@ public class MainWindow extends TWindow {
|
|||||||
|
|
||||||
int secondNow = analogClock.secondProperty.getValue();
|
int secondNow = analogClock.secondProperty.getValue();
|
||||||
int millisecondNow = analogClock.millisecondProperty.getValue();
|
int millisecondNow = analogClock.millisecondProperty.getValue();
|
||||||
TimeHM timeRemains = new TimeHM(endTime.getHour() - hourNow,
|
|
||||||
endTime.getMinute() - minuteNow);
|
TTime startTime = arrivalTextField.asTimeHM();
|
||||||
|
TTime endTime = departureTextField.asTimeHM();
|
||||||
|
TTime nowTime = TTime.of(time.asCalendar());
|
||||||
|
TTime timeElapsed = TTime
|
||||||
|
.computeTimeDiff(startTime, nowTime);
|
||||||
|
TTime timeRemains = TTime.computeTimeDiff(nowTime, endTime);
|
||||||
|
String timeElapsedString = timeElapsed.toString();
|
||||||
|
String timeRemainsString = timeRemains.toString();
|
||||||
|
|
||||||
int secondsRemains = 60 - secondNow;
|
int secondsRemains = 60 - secondNow;
|
||||||
int millisecondsRemains = 1000 - millisecondNow;
|
int millisecondsRemains = 1000 - millisecondNow;
|
||||||
|
if (!remainingTextField.valueProperty.getValue()
|
||||||
|
.equals(timeRemainsString)) {
|
||||||
|
remainingTextField.valueProperty.setValue(timeRemainsString);
|
||||||
|
}
|
||||||
|
if (!elapsedTextField.valueProperty.getValue()
|
||||||
|
.equals(timeElapsedString)) {
|
||||||
|
elapsedTextField.valueProperty.setValue(timeElapsedString);
|
||||||
|
}
|
||||||
|
// if (!elapsedTextField.valueProperty.getValue()
|
||||||
|
// .equals(timeElapsed.remove(new TimeHM(0,1)).toString())) {
|
||||||
|
// String s = timeElapsed.remove(new TimeHM(0,1)).toString();
|
||||||
|
// elapsedTextField.valueProperty.setValue(s + ":" + (secondNow < 10 ? "0" : "") + secondNow + ":" + (millisecondNow < 10 ? "00" : (millisecondNow < 100 ? "0" : millisecondNow)) + millisecondNow);
|
||||||
|
// }
|
||||||
|
|
||||||
int hourDone = Constants.WORKING_HOURS_LENGTH + overtime.getHour()
|
|
||||||
- timeRemains.getHour();
|
TTime overtime = overtimeTextField.asTimeHM();
|
||||||
|
int hourDone = (int) (Constants.WORKING_HOURS_LENGTH + overtime.getHour()
|
||||||
|
- timeRemains.getHour());
|
||||||
int minutesDone
|
int minutesDone
|
||||||
= Constants.WORKING_MINUTES_LENGTH + overtime.getMinute()
|
= (int) (Constants.WORKING_MINUTES_LENGTH + overtime.getMinute()
|
||||||
- timeRemains.getMinute();
|
- timeRemains.getMinute());
|
||||||
int secondsDone = secondNow;
|
int secondsDone = secondNow;
|
||||||
int millisecondsDone = millisecondNow;
|
int millisecondsDone = millisecondNow;
|
||||||
|
|
||||||
@ -493,6 +627,13 @@ public class MainWindow extends TWindow {
|
|||||||
int totalMillisecondsDone
|
int totalMillisecondsDone
|
||||||
= totalSecondsDone * 1000 + millisecondsDone;
|
= totalSecondsDone * 1000 + millisecondsDone;
|
||||||
|
|
||||||
|
|
||||||
|
int totalMinutes = TTime.countDiffInMinutes(arrivalTextField.asTimeHM(),
|
||||||
|
departureTextField.asTimeHM());
|
||||||
|
|
||||||
|
int totalSeconds = totalMinutes * TTime.SECONDS_PER_MINUTE;
|
||||||
|
int totalMilliseconds = totalSeconds * TTime.MILLISECONDS_PER_SECOND;
|
||||||
|
|
||||||
double done = ((double) totalMillisecondsDone)
|
double done = ((double) totalMillisecondsDone)
|
||||||
/ ((double) totalMilliseconds);
|
/ ((double) totalMilliseconds);
|
||||||
progressSquare.setDonePercent(done);
|
progressSquare.setDonePercent(done);
|
||||||
@ -532,9 +673,9 @@ public class MainWindow extends TWindow {
|
|||||||
yearBattery.setLabel("");
|
yearBattery.setLabel("");
|
||||||
//yearBattery.setDonePercent(YearBattery.getYearProgress(2024,0,1,0,0,0,0));
|
//yearBattery.setDonePercent(YearBattery.getYearProgress(2024,0,1,0,0,0,0));
|
||||||
int totalSecondsRemains
|
int totalSecondsRemains
|
||||||
= (timeRemains.getHour() * 60 * 60
|
= (int) (timeRemains.getHour() * 60 * 60
|
||||||
+ timeRemains.getMinute() * 60
|
+ timeRemains.getMinute() * 60
|
||||||
+ secondsRemains);
|
+ secondsRemains);
|
||||||
int totalMillisecondsRemains
|
int totalMillisecondsRemains
|
||||||
= totalSecondsRemains * 1000 + millisecondsRemains;
|
= totalSecondsRemains * 1000 + millisecondsRemains;
|
||||||
double totalSecondsRemainsDouble
|
double totalSecondsRemainsDouble
|
||||||
@ -655,4 +796,18 @@ public class MainWindow extends TWindow {
|
|||||||
|
|
||||||
this.configWindow.doDisableAlmostEverything();
|
this.configWindow.doDisableAlmostEverything();
|
||||||
}
|
}
|
||||||
|
public void increaseArrivalByOneMinute() {
|
||||||
|
arrivalTextField.valueProperty.setValue(new TTime(this.arrivalTextField.valueProperty.getValue()).add(new TTime(0, 1)).toString().substring(0, 5));
|
||||||
|
}
|
||||||
|
public void decreaseArrivalByOneMinute() {
|
||||||
|
arrivalTextField.valueProperty.setValue(new TTime(this.arrivalTextField.valueProperty.getValue()).remove(new TTime(0, 1)).toString().substring(0, 5));
|
||||||
|
}
|
||||||
|
public void increaseOvertimeByOneMinute() {
|
||||||
|
TTime newOvertime = new TTime(this.overtimeTextField.valueProperty.getValue()).add(new TTime(0, 1));
|
||||||
|
overtimeTextField.valueProperty.setValue(newOvertime.toString().substring(0, newOvertime.isNegative() ? 6 :5));
|
||||||
|
}
|
||||||
|
public void decreaseOvertimeByOneMinute() {
|
||||||
|
TTime newOvertime = new TTime(this.overtimeTextField.valueProperty.getValue()).remove(new TTime(0, 1));
|
||||||
|
overtimeTextField.valueProperty.setValue(newOvertime.toString().substring(0, newOvertime.isNegative() ? 6 :5));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ public class TButton extends JButton implements GetProperty {
|
|||||||
public TButton(String label) {
|
public TButton(String label) {
|
||||||
super(label);
|
super(label);
|
||||||
new Timer(100, e -> {
|
new Timer(100, e -> {
|
||||||
if (!MainWindow.hideShowCheckBox.isSelected()) {
|
if (!MainWindow.hideShowFormsCheckBox.isSelected()) {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
@ -0,0 +1,104 @@
|
|||||||
|
package org.nanoboot.utils.timecalc.swing.common;
|
||||||
|
|
||||||
|
import org.nanoboot.utils.timecalc.app.GetProperty;
|
||||||
|
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 javax.swing.JCheckBox;
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.Timer;
|
||||||
|
import java.awt.Color;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert Vokac
|
||||||
|
* @since 21.02.2024
|
||||||
|
*/
|
||||||
|
public class TCheckBox extends JCheckBox implements GetProperty {
|
||||||
|
|
||||||
|
private static final int WIDTH = 100;
|
||||||
|
private static final int HEIGHT = 30;
|
||||||
|
private Color originalBackground;
|
||||||
|
private Color originalForeground;
|
||||||
|
public TCheckBox(String text) {
|
||||||
|
this(text, false);
|
||||||
|
}
|
||||||
|
public final BooleanProperty visibilitySupportedColoredProperty
|
||||||
|
= new BooleanProperty("visibilitySupportedColoredProperty", true);
|
||||||
|
public final BooleanProperty visibleProperty
|
||||||
|
= new BooleanProperty("visibleProperty", true);
|
||||||
|
public StringProperty visibilityProperty
|
||||||
|
= new StringProperty("visibilityProperty",
|
||||||
|
Visibility.STRONGLY_COLORED.name());
|
||||||
|
public TCheckBox(String text, boolean b) {
|
||||||
|
super(text, b);
|
||||||
|
|
||||||
|
valueProperty.setValue(b);
|
||||||
|
|
||||||
|
addActionListener( e -> valueProperty.setValue(isSelected()));
|
||||||
|
valueProperty.addListener(e ->
|
||||||
|
{
|
||||||
|
if (valueProperty.getValue().equals(getText())) {
|
||||||
|
setSelected(valueProperty.isEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
new Timer(100, e -> {
|
||||||
|
if (!MainWindow.hideShowFormsCheckBox.isSelected()) {
|
||||||
|
setVisible(false);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
//setVisible(true);
|
||||||
|
}
|
||||||
|
Visibility visibility
|
||||||
|
= Visibility.valueOf(visibilityProperty.getValue());
|
||||||
|
setVisible(visibility.isNotNone() && visibleProperty.isEnabled());
|
||||||
|
if (!visibility.isStronglyColored() || visibility.isGray()) {
|
||||||
|
setBackground(MainWindow.BACKGROUND_COLOR);
|
||||||
|
setForeground(MainWindow.FOREGROUND_COLOR);
|
||||||
|
} else {
|
||||||
|
setOriginalBackground();
|
||||||
|
setOriginalForeground();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
public final BooleanProperty valueProperty = new BooleanProperty("");
|
||||||
|
public void setBounds(int x, int y) {
|
||||||
|
setBounds(x, y, WIDTH, HEIGHT);
|
||||||
|
this.originalBackground = getBackground();
|
||||||
|
this.originalForeground = getForeground();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoundsFromLeft(JComponent jComponent) {
|
||||||
|
setBounds(jComponent.getX() + jComponent.getWidth() + SwingUtils.MARGIN,
|
||||||
|
jComponent.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoundsFromTop(JComponent jComponent) {
|
||||||
|
setBoundsFromTop(jComponent, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoundsFromTop(JComponent jComponent, int marginCount) {
|
||||||
|
setBounds(SwingUtils.MARGIN, jComponent.getY()
|
||||||
|
+ jComponent.getHeight()
|
||||||
|
+ marginCount * SwingUtils.MARGIN);
|
||||||
|
}
|
||||||
|
public void setOriginalBackground() {
|
||||||
|
this.setBackground(originalBackground);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOriginalForeground() {
|
||||||
|
this.setForeground(originalForeground);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Property getVisibilityProperty() {
|
||||||
|
return visibilityProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Property getVisibilitySupportedColoredProperty() {
|
||||||
|
return visibilitySupportedColoredProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
package org.nanoboot.utils.timecalc.swing.common;
|
||||||
|
|
||||||
|
import org.nanoboot.utils.timecalc.app.GetProperty;
|
||||||
|
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 javax.swing.JComponent;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.Timer;
|
||||||
|
import java.awt.Color;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert Vokac
|
||||||
|
* @since 21.02.2024
|
||||||
|
*/
|
||||||
|
public class TLabel extends JLabel implements GetProperty {
|
||||||
|
|
||||||
|
private static final int WIDTH = 60;
|
||||||
|
private static final int HEIGHT = 30;
|
||||||
|
private int customWidth = 0;
|
||||||
|
private Color originalBackground;
|
||||||
|
private Color originalForeground;
|
||||||
|
public final BooleanProperty visibilitySupportedColoredProperty
|
||||||
|
= new BooleanProperty("visibilitySupportedColoredProperty", true);
|
||||||
|
public final BooleanProperty visibleProperty
|
||||||
|
= new BooleanProperty("visibleProperty", true);
|
||||||
|
public StringProperty visibilityProperty
|
||||||
|
= new StringProperty("visibilityProperty",
|
||||||
|
Visibility.STRONGLY_COLORED.name());
|
||||||
|
public TLabel(String text) {
|
||||||
|
this(text, 0);
|
||||||
|
}
|
||||||
|
public TLabel(String text, int customWidth) {
|
||||||
|
super(text);
|
||||||
|
this.customWidth = customWidth;
|
||||||
|
new Timer(100, e -> {
|
||||||
|
if (!MainWindow.hideShowFormsCheckBox.isSelected()) {
|
||||||
|
setVisible(false);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
//setVisible(true);
|
||||||
|
}
|
||||||
|
Visibility visibility
|
||||||
|
= Visibility.valueOf(visibilityProperty.getValue());
|
||||||
|
setVisible(visibility.isNotNone() && visibleProperty.isEnabled());
|
||||||
|
if (!visibility.isStronglyColored() || visibility.isGray()) {
|
||||||
|
setBackground(MainWindow.BACKGROUND_COLOR);
|
||||||
|
setForeground(MainWindow.FOREGROUND_COLOR);
|
||||||
|
} else {
|
||||||
|
setOriginalBackground();
|
||||||
|
setOriginalForeground();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBounds(int x, int y) {
|
||||||
|
setBounds(x, y, customWidth == 0 ? WIDTH : customWidth, HEIGHT);
|
||||||
|
this.originalBackground = getBackground();
|
||||||
|
this.originalForeground = getForeground();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setBoundsFromLeft(JComponent jComponent) {
|
||||||
|
setBounds(jComponent.getX() + jComponent.getWidth() + SwingUtils.MARGIN,
|
||||||
|
jComponent.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoundsFromTop(JComponent jComponent) {
|
||||||
|
setBoundsFromTop(jComponent, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoundsFromTop(JComponent jComponent, int marginCount) {
|
||||||
|
setBounds(SwingUtils.MARGIN, jComponent.getY()
|
||||||
|
+ jComponent.getHeight()
|
||||||
|
+ marginCount * SwingUtils.MARGIN);
|
||||||
|
}
|
||||||
|
public void setOriginalBackground() {
|
||||||
|
this.setBackground(originalBackground);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOriginalForeground() {
|
||||||
|
this.setForeground(originalForeground);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Property getVisibilityProperty() {
|
||||||
|
return visibilityProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Property getVisibilitySupportedColoredProperty() {
|
||||||
|
return visibilitySupportedColoredProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,132 @@
|
|||||||
|
package org.nanoboot.utils.timecalc.swing.common;
|
||||||
|
|
||||||
|
import org.nanoboot.utils.timecalc.app.GetProperty;
|
||||||
|
import org.nanoboot.utils.timecalc.entity.Visibility;
|
||||||
|
import org.nanoboot.utils.timecalc.utils.common.TTime;
|
||||||
|
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 javax.swing.JComponent;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.Timer;
|
||||||
|
import javax.swing.event.DocumentEvent;
|
||||||
|
import javax.swing.event.DocumentListener;
|
||||||
|
import java.awt.Color;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert Vokac
|
||||||
|
* @since 21.02.2024
|
||||||
|
*/
|
||||||
|
public class TTextField extends JTextField implements GetProperty {
|
||||||
|
|
||||||
|
private static final int WIDTH = 50;
|
||||||
|
private static final int HEIGHT = 30;
|
||||||
|
private int customWidth = 0;
|
||||||
|
private Color originalBackground;
|
||||||
|
private Color originalForeground;
|
||||||
|
public final BooleanProperty visibilitySupportedColoredProperty
|
||||||
|
= new BooleanProperty("visibilitySupportedColoredProperty", true);
|
||||||
|
public final BooleanProperty visibleProperty
|
||||||
|
= new BooleanProperty("visibleProperty", true);
|
||||||
|
public StringProperty visibilityProperty
|
||||||
|
= new StringProperty("visibilityProperty",
|
||||||
|
Visibility.STRONGLY_COLORED.name());
|
||||||
|
public final StringProperty valueProperty = new StringProperty();
|
||||||
|
public TTextField() {
|
||||||
|
this("", 0);
|
||||||
|
}
|
||||||
|
public TTextField(String s) {
|
||||||
|
this(s, 0);
|
||||||
|
}
|
||||||
|
public TTextField(String s, int customWidth) {
|
||||||
|
super(s);
|
||||||
|
this.customWidth = customWidth;
|
||||||
|
valueProperty.setValue(s);
|
||||||
|
getDocument()
|
||||||
|
.addDocumentListener(new DocumentListener() {
|
||||||
|
public void changedUpdate(DocumentEvent e) {
|
||||||
|
update(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeUpdate(DocumentEvent e) {
|
||||||
|
update(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insertUpdate(DocumentEvent e) {
|
||||||
|
update(e);
|
||||||
|
}
|
||||||
|
private void update(DocumentEvent e) {
|
||||||
|
valueProperty.setValue(getText());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
valueProperty.addListener(e ->
|
||||||
|
{
|
||||||
|
if (!valueProperty.getValue().equals(getText())) {
|
||||||
|
setText(valueProperty.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
new Timer(100, e -> {
|
||||||
|
if (!MainWindow.hideShowFormsCheckBox.isSelected()) {
|
||||||
|
setVisible(false);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
//setVisible(true);
|
||||||
|
}
|
||||||
|
Visibility visibility
|
||||||
|
= Visibility.valueOf(visibilityProperty.getValue());
|
||||||
|
setVisible(visibility.isNotNone() && visibleProperty.isEnabled());
|
||||||
|
if (!visibility.isStronglyColored() || visibility.isGray()) {
|
||||||
|
setBackground(MainWindow.BACKGROUND_COLOR);
|
||||||
|
setForeground(MainWindow.FOREGROUND_COLOR);
|
||||||
|
} else {
|
||||||
|
setOriginalBackground();
|
||||||
|
setOriginalForeground();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBounds(int x, int y) {
|
||||||
|
setBounds(x, y, customWidth == 0 ? WIDTH : customWidth, HEIGHT);
|
||||||
|
this.originalBackground = getBackground();
|
||||||
|
this.originalForeground = getForeground();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoundsFromLeft(JComponent jComponent) {
|
||||||
|
setBounds(jComponent.getX() + jComponent.getWidth() + SwingUtils.MARGIN,
|
||||||
|
jComponent.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoundsFromTop(JComponent jComponent) {
|
||||||
|
setBoundsFromTop(jComponent, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoundsFromTop(JComponent jComponent, int marginCount) {
|
||||||
|
setBounds(SwingUtils.MARGIN, jComponent.getY()
|
||||||
|
+ jComponent.getHeight()
|
||||||
|
+ marginCount * SwingUtils.MARGIN);
|
||||||
|
}
|
||||||
|
public void setOriginalBackground() {
|
||||||
|
this.setBackground(originalBackground);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOriginalForeground() {
|
||||||
|
this.setForeground(originalForeground);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Property getVisibilityProperty() {
|
||||||
|
return visibilityProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Property getVisibilitySupportedColoredProperty() {
|
||||||
|
return visibilitySupportedColoredProperty;
|
||||||
|
}
|
||||||
|
public TTime asTimeHM() {
|
||||||
|
return new TTime(valueProperty.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -5,7 +5,7 @@ import org.nanoboot.utils.timecalc.entity.Visibility;
|
|||||||
import org.nanoboot.utils.timecalc.swing.common.SwingUtils;
|
import org.nanoboot.utils.timecalc.swing.common.SwingUtils;
|
||||||
import org.nanoboot.utils.timecalc.swing.common.Widget;
|
import org.nanoboot.utils.timecalc.swing.common.Widget;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.DateFormats;
|
import org.nanoboot.utils.timecalc.utils.common.DateFormats;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.TimeHM;
|
import org.nanoboot.utils.timecalc.utils.common.TTime;
|
||||||
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
|
import org.nanoboot.utils.timecalc.utils.property.BooleanProperty;
|
||||||
import org.nanoboot.utils.timecalc.utils.property.IntegerProperty;
|
import org.nanoboot.utils.timecalc.utils.property.IntegerProperty;
|
||||||
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
|
import org.nanoboot.utils.timecalc.utils.property.StringProperty;
|
||||||
@ -59,8 +59,7 @@ public class AnalogClock extends Widget {
|
|||||||
= new BooleanProperty(
|
= new BooleanProperty(
|
||||||
TimeCalcProperty.CLOCK_DATE_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER
|
TimeCalcProperty.CLOCK_DATE_VISIBLE_ONLY_IF_MOUSE_MOVING_OVER
|
||||||
.getKey());
|
.getKey());
|
||||||
private final TimeHM endTime;
|
|
||||||
private final int endAngle;
|
|
||||||
public IntegerProperty startHourProperty
|
public IntegerProperty startHourProperty
|
||||||
= new IntegerProperty("startHourProperty");
|
= new IntegerProperty("startHourProperty");
|
||||||
public IntegerProperty startMinuteProperty
|
public IntegerProperty startMinuteProperty
|
||||||
@ -93,25 +92,9 @@ public class AnalogClock extends Widget {
|
|||||||
= new BooleanProperty("handsLongProperty", true);
|
= new BooleanProperty("handsLongProperty", true);
|
||||||
public BooleanProperty handsColoredProperty
|
public BooleanProperty handsColoredProperty
|
||||||
= new BooleanProperty("handsColoredProperty", true);
|
= new BooleanProperty("handsColoredProperty", true);
|
||||||
private TimeHM startTime;
|
|
||||||
private int startAngle;
|
|
||||||
private Color customCircleColor = null;
|
private Color customCircleColor = null;
|
||||||
|
|
||||||
public AnalogClock(TimeHM startTimeIn,
|
public AnalogClock() {
|
||||||
TimeHM endTimeIn) {
|
|
||||||
|
|
||||||
this.endTime = endTimeIn.cloneInstance();
|
|
||||||
this.endAngle
|
|
||||||
= (int) ((endTime.getHour() + endTime.getMinute() / 60d) / 12d
|
|
||||||
* 360d);
|
|
||||||
if (endTime.getHour() > 12) {
|
|
||||||
endTime.setHour(endTime.getHour() - 12);
|
|
||||||
}
|
|
||||||
this.startTime = startTimeIn.cloneInstance();
|
|
||||||
this.startAngle
|
|
||||||
=
|
|
||||||
(int) ((startTime.getHour() + startTime.getMinute() / 60d) / 12d
|
|
||||||
* 360d);
|
|
||||||
|
|
||||||
setPreferredSize(new Dimension(200, 200));
|
setPreferredSize(new Dimension(200, 200));
|
||||||
|
|
||||||
@ -119,12 +102,31 @@ public class AnalogClock extends Widget {
|
|||||||
-> customCircleColor = SwingUtils.getColorFromString(
|
-> customCircleColor = SwingUtils.getColorFromString(
|
||||||
centreCircleBorderColorProperty.getValue()));
|
centreCircleBorderColorProperty.getValue()));
|
||||||
}
|
}
|
||||||
|
private int computeStartAngle() {
|
||||||
|
return computeAngle(startHourProperty.getValue(), startMinuteProperty.getValue());
|
||||||
|
}
|
||||||
|
private int computeEndAngle() {
|
||||||
|
return computeAngle(endHourProperty.getValue(), endMinuteProperty.getValue());
|
||||||
|
}
|
||||||
|
private int computeAngle(TTime TTime) {
|
||||||
|
if (TTime.getHour() > 12) {
|
||||||
|
TTime.setHour(TTime.getHour() - 12);
|
||||||
|
}
|
||||||
|
return computeAngle(TTime.getHour(), TTime.getMinute());
|
||||||
|
}
|
||||||
|
private int computeAngle(int hour, int minute) {
|
||||||
|
return (int) ((hour + minute / 60d) / 12d
|
||||||
|
* 360d);
|
||||||
|
}
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
JFrame window = new JFrame("Analog Clock");
|
JFrame window = new JFrame("Analog Clock");
|
||||||
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
AnalogClock clock
|
AnalogClock clock
|
||||||
= new AnalogClock(new TimeHM("6:30"), new TimeHM("19:00"));
|
= new AnalogClock();
|
||||||
|
clock.startHourProperty.setValue(6);
|
||||||
|
clock.startMinuteProperty.setValue(30);
|
||||||
|
clock.endHourProperty.setValue(19);
|
||||||
|
clock.endMinuteProperty.setValue(0);
|
||||||
window.add(clock);
|
window.add(clock);
|
||||||
window.pack();
|
window.pack();
|
||||||
Time time = new Time();
|
Time time = new Time();
|
||||||
@ -184,15 +186,13 @@ public class AnalogClock extends Widget {
|
|||||||
}
|
}
|
||||||
if ((mouseOver || progressVisibleOnlyIfMouseMovingOverProperty
|
if ((mouseOver || progressVisibleOnlyIfMouseMovingOverProperty
|
||||||
.isDisabled()) && visibility.isStronglyColored()) {
|
.isDisabled()) && visibility.isStronglyColored()) {
|
||||||
this.startTime = new TimeHM(hour, minute);
|
|
||||||
this.startAngle
|
|
||||||
= (int) ((startTime.getHour() + startTime.getMinute() / 60d)
|
|
||||||
/ 12d * 360d);
|
|
||||||
|
|
||||||
Color currentColor = g2d.getColor();
|
Color currentColor = g2d.getColor();
|
||||||
g2d.setColor(Color.YELLOW);
|
g2d.setColor(Color.YELLOW);
|
||||||
|
int startAngle = computeStartAngle();
|
||||||
g2d.fillArc(0, 0, side, side, -startAngle + 90,
|
g2d.fillArc(0, 0, side, side, -startAngle + 90,
|
||||||
startAngle - endAngle);
|
startAngle - computeEndAngle());
|
||||||
|
|
||||||
//System.out.println("ANGLES: " + startAngle + " " + endAngle + " " + angleDiff );
|
//System.out.println("ANGLES: " + startAngle + " " + endAngle + " " + angleDiff );
|
||||||
g2d.setColor(currentColor);
|
g2d.setColor(currentColor);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package org.nanoboot.utils.timecalc.swing.progress;
|
package org.nanoboot.utils.timecalc.swing.progress;
|
||||||
|
|
||||||
import org.nanoboot.utils.timecalc.utils.common.TimeHM;
|
import org.nanoboot.utils.timecalc.utils.common.TTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert Vokac
|
* @author Robert Vokac
|
||||||
@ -14,7 +14,7 @@ public class HourBattery extends Battery {
|
|||||||
super(HOUR, x, i, i1);
|
super(HOUR, x, i, i1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getHourProgress(TimeHM timeRemains, int secondsRemains,
|
public static double getHourProgress(TTime timeRemains, int secondsRemains,
|
||||||
int millisecondsRemains) {
|
int millisecondsRemains) {
|
||||||
if (secondsRemains < 0 || millisecondsRemains < 0
|
if (secondsRemains < 0 || millisecondsRemains < 0
|
||||||
|| timeRemains.getHour() < 0 || timeRemains.getMinute() < 0) {
|
|| timeRemains.getHour() < 0 || timeRemains.getMinute() < 0) {
|
||||||
|
@ -8,7 +8,7 @@ import org.nanoboot.utils.timecalc.swing.common.Toaster;
|
|||||||
import org.nanoboot.utils.timecalc.swing.common.Widget;
|
import org.nanoboot.utils.timecalc.swing.common.Widget;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.Constants;
|
import org.nanoboot.utils.timecalc.utils.common.Constants;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.NumberFormats;
|
import org.nanoboot.utils.timecalc.utils.common.NumberFormats;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.TimeHM;
|
import org.nanoboot.utils.timecalc.utils.common.TTime;
|
||||||
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||||
import org.nanoboot.utils.timecalc.utils.property.Property;
|
import org.nanoboot.utils.timecalc.utils.property.Property;
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ public class WalkingHumanProgress extends Widget implements
|
|||||||
private int minuteRemains;
|
private int minuteRemains;
|
||||||
private double done;
|
private double done;
|
||||||
private double totalSecondsRemainsDouble;
|
private double totalSecondsRemainsDouble;
|
||||||
private TimeHM endTime;
|
private TTime endTime;
|
||||||
|
|
||||||
public WalkingHumanProgress() {
|
public WalkingHumanProgress() {
|
||||||
setFont(new Font(Font.MONOSPACED, Font.PLAIN, 11));
|
setFont(new Font(Font.MONOSPACED, Font.PLAIN, 11));
|
||||||
@ -214,12 +214,12 @@ public class WalkingHumanProgress extends Widget implements
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printPercentToAscii(double percent, int hourRemains,
|
public void printPercentToAscii(double percent, long hourRemains,
|
||||||
int minuteRemains, double done,
|
long minuteRemains, double done,
|
||||||
double totalSecondsRemainsDouble, TimeHM endTime) {
|
double totalSecondsRemainsDouble, TTime endTime) {
|
||||||
this.percent = percent;
|
this.percent = percent;
|
||||||
this.hourRemains = hourRemains;
|
this.hourRemains = (int) hourRemains;
|
||||||
this.minuteRemains = minuteRemains;
|
this.minuteRemains = (int) minuteRemains;
|
||||||
this.done = done;
|
this.done = done;
|
||||||
this.totalSecondsRemainsDouble = totalSecondsRemainsDouble;
|
this.totalSecondsRemainsDouble = totalSecondsRemainsDouble;
|
||||||
this.endTime = endTime;
|
this.endTime = endTime;
|
||||||
@ -227,7 +227,7 @@ public class WalkingHumanProgress extends Widget implements
|
|||||||
|
|
||||||
private String createMessage(int hourRemains, int minuteRemains,
|
private String createMessage(int hourRemains, int minuteRemains,
|
||||||
double done,
|
double done,
|
||||||
double totalSecondsRemainsDouble, TimeHM endTime) {
|
double totalSecondsRemainsDouble, TTime endTime) {
|
||||||
String msg
|
String msg
|
||||||
= "Done=" + NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES.format(
|
= "Done=" + NumberFormats.FORMATTER_FIVE_DECIMAL_PLACES.format(
|
||||||
done * 100) + "% Remains="
|
done * 100) + "% Remains="
|
||||||
|
@ -0,0 +1,195 @@
|
|||||||
|
package org.nanoboot.utils.timecalc.utils.common;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert Vokac
|
||||||
|
* @since 21.02.2024
|
||||||
|
*/
|
||||||
|
public class TTime implements Comparable<TTime> {
|
||||||
|
|
||||||
|
public static final int MINUTES_PER_HOUR = 60;
|
||||||
|
public static final int MILLISECONDS_PER_SECOND = 1000;
|
||||||
|
public static final int SECONDS_PER_MINUTE = 60;
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private boolean negative;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private Integer hour;
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private Integer minute;
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private Integer second;
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private Integer millisecond;
|
||||||
|
|
||||||
|
public TTime(long hour, long minute, long second, long millisecond) {
|
||||||
|
this((int)hour, (int)minute, (int)second, (int)millisecond);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TTime(int hour, int minute) {
|
||||||
|
this(hour, minute, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TTime computeTimeDiff(TTime tTime1, TTime tTime2) {
|
||||||
|
return tTime2.remove(tTime1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String printDuration(Duration duration) {
|
||||||
|
long hour = duration.get(ChronoUnit.HOURS);
|
||||||
|
long minute = duration.get(ChronoUnit.MINUTES);
|
||||||
|
long second = duration.get(ChronoUnit.SECONDS);
|
||||||
|
long millisecond = duration.get(ChronoUnit.MILLIS);
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
if (hour < 10) {
|
||||||
|
sb.append("0");
|
||||||
|
}
|
||||||
|
sb.append(minute).append(":");
|
||||||
|
if (minute < 10) {
|
||||||
|
sb.append("0");
|
||||||
|
}
|
||||||
|
sb.append(minute).append(":");
|
||||||
|
if (second < 10) {
|
||||||
|
sb.append("0");
|
||||||
|
}
|
||||||
|
sb.append(second).append(":");
|
||||||
|
if (millisecond < 10) {
|
||||||
|
sb.append("00");
|
||||||
|
} else {
|
||||||
|
if (millisecond < 100) {
|
||||||
|
sb.append("0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
|
||||||
|
}
|
||||||
|
public static TTime of(Calendar cal) {
|
||||||
|
return new TTime(
|
||||||
|
cal.get(Calendar.HOUR_OF_DAY),
|
||||||
|
cal.get(Calendar.MINUTE),
|
||||||
|
cal.get(Calendar.SECOND),
|
||||||
|
cal.get(Calendar.MILLISECOND));
|
||||||
|
}
|
||||||
|
public static TTime of(Duration duration) {
|
||||||
|
return new TTime(
|
||||||
|
duration.get(ChronoUnit.HOURS),
|
||||||
|
duration.get(ChronoUnit.MINUTES),
|
||||||
|
duration.get(ChronoUnit.SECONDS),
|
||||||
|
duration.get(ChronoUnit.MILLIS));
|
||||||
|
}
|
||||||
|
public TTime(String string) {
|
||||||
|
this.negative = string.startsWith("-");
|
||||||
|
if (negative) {
|
||||||
|
string = string.replace("-", "");
|
||||||
|
}
|
||||||
|
String[] array = string.split(":");
|
||||||
|
this.hour = (negative ? (1) : 1) * Integer.valueOf(array[0]);
|
||||||
|
this.minute = (negative ? (1) : 1) * Integer.valueOf(array[1]);
|
||||||
|
this.second = array.length >= 3 ? ((negative ? (1) : 1) * Integer.valueOf(array[2])) : 0;
|
||||||
|
this.millisecond = array.length >= 4 ? ((negative ? (1) : 1) * Integer.valueOf(array[3])) : 0;
|
||||||
|
}
|
||||||
|
public TTime(int hourIn, int minuteIn, int secondIn, int millisecondIn) {
|
||||||
|
this(false, hourIn, minuteIn, secondIn, millisecondIn);
|
||||||
|
}
|
||||||
|
public TTime(boolean negative, int hourIn, int minuteIn, int secondIn, int millisecondIn) {
|
||||||
|
this.hour = hourIn;
|
||||||
|
this.minute = minuteIn;
|
||||||
|
this.second = secondIn;
|
||||||
|
this.millisecond = millisecondIn;
|
||||||
|
this.negative = negative;
|
||||||
|
while (minute >= MINUTES_PER_HOUR) {
|
||||||
|
minute = minute - MINUTES_PER_HOUR;
|
||||||
|
hour = hour + 1;
|
||||||
|
}
|
||||||
|
if (minute < 0) {
|
||||||
|
minute = minute + 60;
|
||||||
|
hour = hour - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public TTime remove(TTime tTimeToBeRemoved) {
|
||||||
|
TTime firstTime = this;
|
||||||
|
TTime secondTime = tTimeToBeRemoved;
|
||||||
|
boolean negative = false;
|
||||||
|
if (firstTime.compareTo(secondTime) < 0) {
|
||||||
|
secondTime = firstTime;
|
||||||
|
firstTime = tTimeToBeRemoved;
|
||||||
|
negative = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Calendar cal = firstTime.asCalendar();
|
||||||
|
cal.add(Calendar.HOUR_OF_DAY, -secondTime.hour);
|
||||||
|
cal.add(Calendar.MINUTE, -secondTime.minute);
|
||||||
|
cal.add(Calendar.SECOND, -secondTime.second);
|
||||||
|
cal.add(Calendar.MILLISECOND, -secondTime.millisecond);
|
||||||
|
TTime result = TTime.of(cal);
|
||||||
|
result.setNegative(negative);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public TTime add(TTime tTimeToBeAdded) {
|
||||||
|
TTime result = this.cloneInstance();
|
||||||
|
// if(result.isNegative()) {
|
||||||
|
// result.setNegative(false);
|
||||||
|
// result.remove(tTimeToBeAdded);
|
||||||
|
// result.setNegative(true);
|
||||||
|
// return result;
|
||||||
|
// }
|
||||||
|
Calendar cal = asCalendar();
|
||||||
|
cal.add(Calendar.HOUR_OF_DAY, tTimeToBeAdded.hour);
|
||||||
|
cal.add(Calendar.MINUTE, tTimeToBeAdded.minute);
|
||||||
|
cal.add(Calendar.SECOND, tTimeToBeAdded.second);
|
||||||
|
cal.add(Calendar.MILLISECOND, tTimeToBeAdded.millisecond);
|
||||||
|
result = TTime.of(cal);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int countDiffInMinutes(TTime startTime, TTime endTime) {
|
||||||
|
return (endTime.getHour() * TTime.MINUTES_PER_HOUR + endTime
|
||||||
|
.getMinute()) - (startTime.getHour() * TTime.MINUTES_PER_HOUR
|
||||||
|
+ startTime.getMinute());
|
||||||
|
}
|
||||||
|
|
||||||
|
public TTime cloneInstance() {
|
||||||
|
return new TTime(negative, hour, minute, second, millisecond);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return (negative ? "-" : "") + (hour < 10 ? "0" : "") + hour + ":" + (minute < 10 ? "0" : "") + minute + ":" + (second < 10 ? "0" : "") + second + ":" + (millisecond < 10 ? "00" : (millisecond < 100 ? "0": "")) + millisecond;
|
||||||
|
}
|
||||||
|
public Calendar asCalendar() {
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.set(Calendar.HOUR_OF_DAY, hour);
|
||||||
|
cal.set(Calendar.MINUTE, minute);
|
||||||
|
cal.set(Calendar.SECOND, second);
|
||||||
|
cal.set(Calendar.MILLISECOND, millisecond);
|
||||||
|
return cal;
|
||||||
|
}
|
||||||
|
public Date asDate() {
|
||||||
|
return asCalendar().getTime();
|
||||||
|
}
|
||||||
|
public int toTotalMilliseconds() {
|
||||||
|
return ((negative ? (-1) : 1)) * (hour * 60 * 60 * 1000 + minute * 60 * 1000 + second * 1000 + millisecond) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(TTime o) {
|
||||||
|
int result = Integer.valueOf(toTotalMilliseconds()).compareTo(o.toTotalMilliseconds());
|
||||||
|
if(this.isNegative()) {
|
||||||
|
System.out.println("this.toTotalMilliseconds()=" + this.toTotalMilliseconds());
|
||||||
|
System.out.println("o.toTotalMilliseconds()=" + o.toTotalMilliseconds());
|
||||||
|
System.out.println("comparing: " + this + " " + o + " = " + result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -1,55 +0,0 @@
|
|||||||
package org.nanoboot.utils.timecalc.utils.common;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Robert Vokac
|
|
||||||
* @since 21.02.2024
|
|
||||||
*/
|
|
||||||
public class TimeHM {
|
|
||||||
|
|
||||||
public static final int MINUTES_PER_HOUR = 60;
|
|
||||||
public static final int MILLISECONDS_PER_SECOND = 1000;
|
|
||||||
public static final int SECONDS_PER_MINUTE = 60;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private Integer hour;
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private Integer minute;
|
|
||||||
|
|
||||||
public TimeHM(String string) {
|
|
||||||
boolean isNegative = string.startsWith("-");
|
|
||||||
if (isNegative) {
|
|
||||||
string = string.replace("-", "");
|
|
||||||
}
|
|
||||||
String[] array = string.split(":");
|
|
||||||
this.hour = (isNegative ? (-1) : 1) * Integer.valueOf(array[0]);
|
|
||||||
this.minute = (isNegative ? (-1) : 1) * Integer.valueOf(array[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TimeHM(int hourIn, int minuteIn) {
|
|
||||||
this.hour = hourIn;
|
|
||||||
this.minute = minuteIn;
|
|
||||||
while (minute >= MINUTES_PER_HOUR) {
|
|
||||||
minute = minute - MINUTES_PER_HOUR;
|
|
||||||
hour = hour + 1;
|
|
||||||
}
|
|
||||||
if (minute < 0) {
|
|
||||||
minute = minute + 60;
|
|
||||||
hour = hour - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int countDiffInMinutes(TimeHM startTime, TimeHM endTime) {
|
|
||||||
return (endTime.getHour() * TimeHM.MINUTES_PER_HOUR + endTime
|
|
||||||
.getMinute()) - (startTime.getHour() * TimeHM.MINUTES_PER_HOUR
|
|
||||||
+ startTime.getMinute());
|
|
||||||
}
|
|
||||||
|
|
||||||
public TimeHM cloneInstance() {
|
|
||||||
return new TimeHM(hour, minute);
|
|
||||||
}
|
|
||||||
}
|
|
@ -51,6 +51,10 @@ public class Property<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void bindTo(Property<T> anotherProperty) {
|
public void bindTo(Property<T> anotherProperty) {
|
||||||
|
if(this == anotherProperty) {
|
||||||
|
new RuntimeException().printStackTrace();
|
||||||
|
throw new TimeCalcException("Cannot bind to self: " + getName());
|
||||||
|
}
|
||||||
fireValueChangedEvent(value);
|
fireValueChangedEvent(value);
|
||||||
this.boundToProperty = anotherProperty;
|
this.boundToProperty = anotherProperty;
|
||||||
this.boundChangeListener
|
this.boundChangeListener
|
||||||
@ -93,7 +97,12 @@ public class Property<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void fireValueChangedEvent(T oldValue) {
|
public void fireValueChangedEvent(T oldValue) {
|
||||||
|
// if (isBound()) {
|
||||||
|
// System.out.println("Property " + getName() + " calling boundProperty fire event for: " + this.boundToProperty.getName());
|
||||||
|
// this.boundToProperty.fireValueChangedEvent(oldValue);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
// System.out.println(name + " was changed");
|
// System.out.println(name + " was changed");
|
||||||
for (ChangeListener listener : changeListeners) {
|
for (ChangeListener listener : changeListeners) {
|
||||||
listener.changed(this, oldValue, value);
|
listener.changed(this, oldValue, value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user