mirror of
https://github.com/robertvokac/time-calc.git
synced 2025-03-25 07:27:49 +01:00
Added + and - small buttons for arrival, overtime, work and pause
This commit is contained in:
parent
d53818010a
commit
4983528417
@ -185,7 +185,6 @@ Smileys can be colored or white-black (can be set in configuration)
|
|||||||
|
|
||||||
## Todos
|
## Todos
|
||||||
* New table: YEAR
|
* New table: YEAR
|
||||||
* Text field : +- buttons
|
|
||||||
* Split to Maven modules
|
* Split to Maven modules
|
||||||
* Junit, Mockito, etc.
|
* Junit, Mockito, etc.
|
||||||
* Checkstyle
|
* Checkstyle
|
||||||
|
@ -23,9 +23,6 @@ import java.util.Properties;
|
|||||||
*/
|
*/
|
||||||
public class TimeCalcKeyAdapter extends KeyAdapter {
|
public class TimeCalcKeyAdapter extends KeyAdapter {
|
||||||
|
|
||||||
private static final TTime T_TIME_ONE_MINUTE = new TTime(0, 1);
|
|
||||||
private static final TTime T_TIME_ONE_HOUR = new TTime(1,0);
|
|
||||||
|
|
||||||
private final TimeCalcConfiguration timeCalcConfiguration;
|
private final TimeCalcConfiguration timeCalcConfiguration;
|
||||||
private final TimeCalcApp timeCalcApp;
|
private final TimeCalcApp timeCalcApp;
|
||||||
private final MainWindow mainWindow;
|
private final MainWindow mainWindow;
|
||||||
@ -81,7 +78,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
|
|||||||
boolean increase = shiftDown;
|
boolean increase = shiftDown;
|
||||||
boolean decrease = ctrlDown;
|
boolean decrease = ctrlDown;
|
||||||
boolean reset = altDown;
|
boolean reset = altDown;
|
||||||
TTime changeTTime = changeByOneHour ? T_TIME_ONE_HOUR : T_TIME_ONE_MINUTE;
|
TTime changeTTime = changeByOneHour ? TTime.T_TIME_ONE_HOUR : TTime.T_TIME_ONE_MINUTE;
|
||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
case KeyEvent.VK_Y: {
|
case KeyEvent.VK_Y: {
|
||||||
//Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " year.");
|
//Utils.showNotification((increase ? "Increasing" : (decrease ? "Decreasing" : "Reseting")) + " year.");
|
||||||
|
@ -26,10 +26,12 @@ import org.nanoboot.utils.timecalc.utils.common.Jokes;
|
|||||||
import org.nanoboot.utils.timecalc.utils.common.TTime;
|
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.JButton;
|
||||||
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.awt.Insets;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyVetoException;
|
import java.beans.PropertyVetoException;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@ -77,10 +79,10 @@ public class MainWindow extends TWindow {
|
|||||||
private final WorkingDayRepositorySQLiteImpl workingDayRepository;
|
private final WorkingDayRepositorySQLiteImpl workingDayRepository;
|
||||||
|
|
||||||
{
|
{
|
||||||
this.arrivalTextField = new TTextField();
|
this.arrivalTextField = new TTextField("", 40);
|
||||||
this.overtimeTextField = new TTextField();
|
this.overtimeTextField = new TTextField("", 40);
|
||||||
this.workingTimeTextField = new TTextField("8:00");
|
this.workingTimeTextField = new TTextField("8:00", 40);
|
||||||
this.pauseTimeTextField = new TTextField("0:30");
|
this.pauseTimeTextField = new TTextField("0:30", 40);
|
||||||
this.noteTextField = new TTextField("", 120);
|
this.noteTextField = new TTextField("", 120);
|
||||||
this.departureTextField = new TTextField();
|
this.departureTextField = new TTextField();
|
||||||
this.elapsedTextField = new TTextField("", 100);
|
this.elapsedTextField = new TTextField("", 100);
|
||||||
@ -257,22 +259,42 @@ public class MainWindow extends TWindow {
|
|||||||
arrivalTextFieldLabel.setBoundsFromTop(clock, 3);
|
arrivalTextFieldLabel.setBoundsFromTop(clock, 3);
|
||||||
|
|
||||||
arrivalTextField.setBoundsFromLeft(arrivalTextFieldLabel);
|
arrivalTextField.setBoundsFromLeft(arrivalTextFieldLabel);
|
||||||
|
TButton arrivalIncreaseButton = new SmallTButton('+');
|
||||||
|
TButton arrivalDecreaseButton = new SmallTButton('-');
|
||||||
|
arrivalIncreaseButton.setBounds(arrivalTextField.getX() + arrivalTextField.getWidth(), arrivalTextField.getY(), 15, 15);
|
||||||
|
arrivalDecreaseButton.setBounds(arrivalTextField.getX() + arrivalTextField.getWidth(), arrivalTextField.getY() + 15, 15, 15);
|
||||||
|
|
||||||
//
|
//
|
||||||
TLabel overtimeTextFieldLabel = new TLabel("Overtime:");
|
TLabel overtimeTextFieldLabel = new TLabel("Overtime:");
|
||||||
overtimeTextFieldLabel.setBoundsFromLeft(arrivalTextField);
|
overtimeTextFieldLabel.setBoundsFromLeft(arrivalTextField, 15);
|
||||||
|
|
||||||
overtimeTextField.setBoundsFromLeft(overtimeTextFieldLabel);
|
overtimeTextField.setBoundsFromLeft(overtimeTextFieldLabel);
|
||||||
|
TButton overtimeIncreaseButton = new SmallTButton('+');
|
||||||
|
TButton overtimeDecreaseButton = new SmallTButton('-');
|
||||||
|
overtimeIncreaseButton.setBounds(overtimeTextField.getX() + overtimeTextField.getWidth(), overtimeTextField.getY(), 15, 15);
|
||||||
|
overtimeDecreaseButton.setBounds(overtimeTextField.getX() + overtimeTextField.getWidth(), overtimeTextField.getY() + 15, 15, 15);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
TLabel workingTimeInMinutesTextFieldLabel = new TLabel("Work:", 40);
|
TLabel workingTimeInMinutesTextFieldLabel = new TLabel("Work:", 40);
|
||||||
workingTimeInMinutesTextFieldLabel.setBoundsFromLeft(overtimeTextField);
|
workingTimeInMinutesTextFieldLabel.setBoundsFromLeft(overtimeTextField, 15);
|
||||||
|
|
||||||
workingTimeTextField.setBoundsFromLeft(workingTimeInMinutesTextFieldLabel);
|
workingTimeTextField.setBoundsFromLeft(workingTimeInMinutesTextFieldLabel);
|
||||||
|
TButton workingIncreaseButton = new SmallTButton('+');
|
||||||
|
TButton workingDecreaseButton = new SmallTButton('-');
|
||||||
|
workingIncreaseButton.setBounds(workingTimeTextField.getX() + workingTimeTextField.getWidth(), workingTimeTextField.getY(), 15, 15);
|
||||||
|
workingDecreaseButton.setBounds(workingTimeTextField.getX() + workingTimeTextField.getWidth(), workingTimeTextField.getY() + 15, 15, 15);
|
||||||
|
|
||||||
//
|
//
|
||||||
TLabel pauseTimeInMinutesFieldLabel = new TLabel("Pause:", 40);
|
TLabel pauseTimeInMinutesFieldLabel = new TLabel("Pause:", 40);
|
||||||
pauseTimeInMinutesFieldLabel.setBoundsFromLeft(workingTimeTextField);
|
pauseTimeInMinutesFieldLabel.setBoundsFromLeft(workingTimeTextField, 15);
|
||||||
|
|
||||||
pauseTimeTextField.setBoundsFromLeft(pauseTimeInMinutesFieldLabel);
|
pauseTimeTextField.setBoundsFromLeft(pauseTimeInMinutesFieldLabel);
|
||||||
|
TButton pauseIncreaseButton = new SmallTButton('+');
|
||||||
|
TButton pauseDecreaseButton = new SmallTButton('-');
|
||||||
|
pauseIncreaseButton.setBounds(pauseTimeTextField.getX() + pauseTimeTextField.getWidth(), pauseTimeTextField.getY(), 15, 15);
|
||||||
|
pauseDecreaseButton.setBounds(pauseTimeTextField.getX() + pauseTimeTextField.getWidth(), pauseTimeTextField.getY() + 15, 15, 15);
|
||||||
|
|
||||||
//
|
//
|
||||||
TLabel noteTextFieldLabel = new TLabel("Note:", 40);
|
TLabel noteTextFieldLabel = new TLabel("Note:", 40);
|
||||||
noteTextFieldLabel.setBoundsFromLeft(pauseTimeTextField);
|
noteTextFieldLabel.setBoundsFromLeft(pauseTimeTextField);
|
||||||
@ -287,13 +309,33 @@ public class MainWindow extends TWindow {
|
|||||||
|
|
||||||
add(arrivalTextFieldLabel);
|
add(arrivalTextFieldLabel);
|
||||||
add(arrivalTextField);
|
add(arrivalTextField);
|
||||||
|
add(arrivalIncreaseButton);
|
||||||
|
add(arrivalDecreaseButton);
|
||||||
|
|
||||||
add(overtimeTextFieldLabel);
|
add(overtimeTextFieldLabel);
|
||||||
add(overtimeTextField);
|
add(overtimeTextField);
|
||||||
|
add(overtimeIncreaseButton);
|
||||||
|
add(overtimeDecreaseButton);
|
||||||
|
|
||||||
add(workingTimeInMinutesTextFieldLabel);
|
add(workingTimeInMinutesTextFieldLabel);
|
||||||
add(workingTimeTextField);
|
add(workingTimeTextField);
|
||||||
|
add(workingIncreaseButton);
|
||||||
|
add(workingDecreaseButton);
|
||||||
|
|
||||||
add(pauseTimeInMinutesFieldLabel);
|
add(pauseTimeInMinutesFieldLabel);
|
||||||
add(pauseTimeTextField);
|
add(pauseTimeTextField);
|
||||||
|
add(pauseIncreaseButton);
|
||||||
|
add(pauseDecreaseButton);
|
||||||
|
|
||||||
|
arrivalIncreaseButton.addActionListener(e -> increaseArrival(TTime.T_TIME_ONE_MINUTE));
|
||||||
|
arrivalDecreaseButton.addActionListener(e -> decreaseArrival(TTime.T_TIME_ONE_MINUTE));
|
||||||
|
overtimeIncreaseButton.addActionListener(e -> increaseOvertime(TTime.T_TIME_ONE_MINUTE));
|
||||||
|
overtimeDecreaseButton.addActionListener(e -> decreaseOvertime(TTime.T_TIME_ONE_MINUTE));
|
||||||
|
workingIncreaseButton.addActionListener(e -> increaseWork(TTime.T_TIME_ONE_MINUTE));
|
||||||
|
workingDecreaseButton.addActionListener(e -> decreaseWork(TTime.T_TIME_ONE_MINUTE));
|
||||||
|
pauseIncreaseButton.addActionListener(e -> increasePause(TTime.T_TIME_ONE_MINUTE));
|
||||||
|
pauseDecreaseButton.addActionListener(e -> decreasePause(TTime.T_TIME_ONE_MINUTE));
|
||||||
|
|
||||||
add(noteTextFieldLabel);
|
add(noteTextFieldLabel);
|
||||||
add(noteTextField);
|
add(noteTextField);
|
||||||
add(timeOffCheckBox);
|
add(timeOffCheckBox);
|
||||||
@ -948,7 +990,14 @@ public class MainWindow extends TWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void increaseArrival(TTime tTime) {
|
public void increaseArrival(TTime tTime) {
|
||||||
arrivalTextField.valueProperty.setValue(new TTime(this.arrivalTextField.valueProperty.getValue()).add(tTime).toString().substring(0, 5));
|
TTime oldTime =
|
||||||
|
new TTime(this.arrivalTextField.valueProperty.getValue());
|
||||||
|
TTime newTime = oldTime.add(tTime);
|
||||||
|
// System.out.println("oldTime=" + oldTime);
|
||||||
|
// System.out.println("newTime=" + newTime);
|
||||||
|
// System.out.println("tTime=" + tTime);
|
||||||
|
arrivalTextField.valueProperty.setValue(
|
||||||
|
newTime.toString().substring(0, 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void decreaseArrival(TTime tTime) {
|
public void decreaseArrival(TTime tTime) {
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package org.nanoboot.utils.timecalc.swing.common;
|
||||||
|
|
||||||
|
import java.awt.Insets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert
|
||||||
|
* @since 11.03.2024
|
||||||
|
*/
|
||||||
|
public class SmallTButton extends TButton {
|
||||||
|
|
||||||
|
private static final Insets INSETS = new Insets(1, 1, 1, 1);
|
||||||
|
|
||||||
|
public SmallTButton(char character) {
|
||||||
|
super(String.valueOf(character), 15, 15);
|
||||||
|
//setFont(SwingUtils.SMALL_FONT);
|
||||||
|
setMargin(INSETS);
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ public class SwingUtils {
|
|||||||
|
|
||||||
public static final int MARGIN = 10;
|
public static final int MARGIN = 10;
|
||||||
public static final Font SMALL_FONT = new Font("sans", Font.BOLD, 10);
|
public static final Font SMALL_FONT = new Font("sans", Font.BOLD, 10);
|
||||||
|
public static final Font VERY_SMALL_FONT = new Font("sans", Font.PLAIN, 8);
|
||||||
public static final Font MEDIUM_MONOSPACE_FONT
|
public static final Font MEDIUM_MONOSPACE_FONT
|
||||||
= new Font(Font.MONOSPACED, Font.PLAIN, 12);
|
= new Font(Font.MONOSPACED, Font.PLAIN, 12);
|
||||||
|
|
||||||
|
@ -29,14 +29,18 @@ public class TButton extends JButton implements GetProperty {
|
|||||||
private Color originalBackground;
|
private Color originalBackground;
|
||||||
private Color originalForeground;
|
private Color originalForeground;
|
||||||
private int customWidth = 0;
|
private int customWidth = 0;
|
||||||
|
private int customHeight = 0;
|
||||||
|
|
||||||
public TButton(String label) {
|
public TButton(String label) {
|
||||||
this(label, 0);
|
this(label, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TButton(String label, int customWidth) {
|
public TButton(String label, int customWidth) {
|
||||||
|
this(label, customWidth, 0);
|
||||||
|
}
|
||||||
|
public TButton(String label, int customWidth, int customHeight) {
|
||||||
super(label);
|
super(label);
|
||||||
this.customWidth = customWidth;
|
this.customWidth = customWidth;
|
||||||
|
this.customHeight = customHeight;
|
||||||
new Timer(100, e -> {
|
new Timer(100, e -> {
|
||||||
if (!MainWindow.hideShowFormsCheckBox.isSelected()) {
|
if (!MainWindow.hideShowFormsCheckBox.isSelected()) {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
@ -58,7 +62,7 @@ public class TButton extends JButton implements GetProperty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setBounds(int x, int y) {
|
public void setBounds(int x, int y) {
|
||||||
setBounds(x, y, customWidth == 0 ? BUTTON_WIDTH : customWidth, BUTTON_HEIGHT);
|
setBounds(x, y, customWidth == 0 ? BUTTON_WIDTH : customWidth, customHeight == 0 ? BUTTON_HEIGHT : customHeight);
|
||||||
this.originalBackground = getBackground();
|
this.originalBackground = getBackground();
|
||||||
this.originalForeground = getForeground();
|
this.originalForeground = getForeground();
|
||||||
}
|
}
|
||||||
@ -95,9 +99,4 @@ public class TButton extends JButton implements GetProperty {
|
|||||||
public Property getVisibilitySupportedColoredProperty() {
|
public Property getVisibilitySupportedColoredProperty() {
|
||||||
return visibilitySupportedColoredProperty;
|
return visibilitySupportedColoredProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addActionListener() {
|
|
||||||
throw new UnsupportedOperationException(
|
|
||||||
"Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,10 @@ public class TLabel extends JLabel implements GetProperty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setBoundsFromLeft(JComponent jComponent) {
|
public void setBoundsFromLeft(JComponent jComponent) {
|
||||||
setBounds(jComponent.getX() + jComponent.getWidth() + SwingUtils.MARGIN,
|
setBoundsFromLeft(jComponent, 0);
|
||||||
|
}
|
||||||
|
public void setBoundsFromLeft(JComponent jComponent, int additionalX) {
|
||||||
|
setBounds(jComponent.getX() + jComponent.getWidth() + SwingUtils.MARGIN + additionalX,
|
||||||
jComponent.getY());
|
jComponent.getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,9 @@ public class TTime implements Comparable<TTime> {
|
|||||||
public static final int MINUTES_PER_HOUR = 60;
|
public static final int MINUTES_PER_HOUR = 60;
|
||||||
public static final int MILLISECONDS_PER_SECOND = 1000;
|
public static final int MILLISECONDS_PER_SECOND = 1000;
|
||||||
public static final int SECONDS_PER_MINUTE = 60;
|
public static final int SECONDS_PER_MINUTE = 60;
|
||||||
|
|
||||||
|
public static final TTime T_TIME_ONE_MINUTE = new TTime(0, 1);
|
||||||
|
public static final TTime T_TIME_ONE_HOUR = new TTime(1,0);
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private boolean negative;
|
private boolean negative;
|
||||||
@ -144,7 +147,6 @@ public class TTime implements Comparable<TTime> {
|
|||||||
int seconds = milliseconds / 1000;
|
int seconds = milliseconds / 1000;
|
||||||
milliseconds = milliseconds - seconds * 1000;
|
milliseconds = milliseconds - seconds * 1000;
|
||||||
return new TTime(s < 0, Math.abs(hours), Math.abs(minutes), Math.abs(seconds), Math.abs(milliseconds));
|
return new TTime(s < 0, Math.abs(hours), Math.abs(minutes), Math.abs(seconds), Math.abs(milliseconds));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TTime add(TTime tTimeToBeAdded) {
|
public TTime add(TTime tTimeToBeAdded) {
|
||||||
|
@ -184,7 +184,7 @@ Smileys can be colored or white-black (can be set in configuration)
|
|||||||
## Command button
|
## Command button
|
||||||
|
|
||||||
## Todos
|
## Todos
|
||||||
|
* New table: YEAR
|
||||||
* Split to Maven modules
|
* Split to Maven modules
|
||||||
* Junit, Mockito, etc.
|
* Junit, Mockito, etc.
|
||||||
* Checkstyle
|
* Checkstyle
|
||||||
|
Loading…
x
Reference in New Issue
Block a user