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
|
||||
* New table: YEAR
|
||||
* Text field : +- buttons
|
||||
* Split to Maven modules
|
||||
* Junit, Mockito, etc.
|
||||
* Checkstyle
|
||||
|
@ -23,9 +23,6 @@ import java.util.Properties;
|
||||
*/
|
||||
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 TimeCalcApp timeCalcApp;
|
||||
private final MainWindow mainWindow;
|
||||
@ -81,7 +78,7 @@ public class TimeCalcKeyAdapter extends KeyAdapter {
|
||||
boolean increase = shiftDown;
|
||||
boolean decrease = ctrlDown;
|
||||
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) {
|
||||
case KeyEvent.VK_Y: {
|
||||
//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.Utils;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JFrame;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Insets;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyVetoException;
|
||||
import java.util.Calendar;
|
||||
@ -77,10 +79,10 @@ public class MainWindow extends TWindow {
|
||||
private final WorkingDayRepositorySQLiteImpl workingDayRepository;
|
||||
|
||||
{
|
||||
this.arrivalTextField = new TTextField();
|
||||
this.overtimeTextField = new TTextField();
|
||||
this.workingTimeTextField = new TTextField("8:00");
|
||||
this.pauseTimeTextField = new TTextField("0:30");
|
||||
this.arrivalTextField = new TTextField("", 40);
|
||||
this.overtimeTextField = new TTextField("", 40);
|
||||
this.workingTimeTextField = new TTextField("8:00", 40);
|
||||
this.pauseTimeTextField = new TTextField("0:30", 40);
|
||||
this.noteTextField = new TTextField("", 120);
|
||||
this.departureTextField = new TTextField();
|
||||
this.elapsedTextField = new TTextField("", 100);
|
||||
@ -257,22 +259,42 @@ public class MainWindow extends TWindow {
|
||||
arrivalTextFieldLabel.setBoundsFromTop(clock, 3);
|
||||
|
||||
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:");
|
||||
overtimeTextFieldLabel.setBoundsFromLeft(arrivalTextField);
|
||||
overtimeTextFieldLabel.setBoundsFromLeft(arrivalTextField, 15);
|
||||
|
||||
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);
|
||||
workingTimeInMinutesTextFieldLabel.setBoundsFromLeft(overtimeTextField);
|
||||
workingTimeInMinutesTextFieldLabel.setBoundsFromLeft(overtimeTextField, 15);
|
||||
|
||||
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);
|
||||
pauseTimeInMinutesFieldLabel.setBoundsFromLeft(workingTimeTextField);
|
||||
pauseTimeInMinutesFieldLabel.setBoundsFromLeft(workingTimeTextField, 15);
|
||||
|
||||
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);
|
||||
noteTextFieldLabel.setBoundsFromLeft(pauseTimeTextField);
|
||||
@ -287,13 +309,33 @@ public class MainWindow extends TWindow {
|
||||
|
||||
add(arrivalTextFieldLabel);
|
||||
add(arrivalTextField);
|
||||
add(arrivalIncreaseButton);
|
||||
add(arrivalDecreaseButton);
|
||||
|
||||
add(overtimeTextFieldLabel);
|
||||
add(overtimeTextField);
|
||||
add(overtimeIncreaseButton);
|
||||
add(overtimeDecreaseButton);
|
||||
|
||||
add(workingTimeInMinutesTextFieldLabel);
|
||||
add(workingTimeTextField);
|
||||
add(workingIncreaseButton);
|
||||
add(workingDecreaseButton);
|
||||
|
||||
add(pauseTimeInMinutesFieldLabel);
|
||||
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(noteTextField);
|
||||
add(timeOffCheckBox);
|
||||
@ -948,7 +990,14 @@ public class MainWindow extends TWindow {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -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 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
|
||||
= new Font(Font.MONOSPACED, Font.PLAIN, 12);
|
||||
|
||||
|
@ -29,14 +29,18 @@ public class TButton extends JButton implements GetProperty {
|
||||
private Color originalBackground;
|
||||
private Color originalForeground;
|
||||
private int customWidth = 0;
|
||||
private int customHeight = 0;
|
||||
|
||||
public TButton(String label) {
|
||||
this(label, 0);
|
||||
}
|
||||
|
||||
public TButton(String label, int customWidth) {
|
||||
this(label, customWidth, 0);
|
||||
}
|
||||
public TButton(String label, int customWidth, int customHeight) {
|
||||
super(label);
|
||||
this.customWidth = customWidth;
|
||||
this.customHeight = customHeight;
|
||||
new Timer(100, e -> {
|
||||
if (!MainWindow.hideShowFormsCheckBox.isSelected()) {
|
||||
setVisible(false);
|
||||
@ -58,7 +62,7 @@ public class TButton extends JButton implements GetProperty {
|
||||
}
|
||||
|
||||
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.originalForeground = getForeground();
|
||||
}
|
||||
@ -95,9 +99,4 @@ public class TButton extends JButton implements GetProperty {
|
||||
public Property getVisibilitySupportedColoredProperty() {
|
||||
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) {
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,9 @@ 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;
|
||||
|
||||
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
|
||||
@Setter
|
||||
private boolean negative;
|
||||
@ -144,7 +147,6 @@ public class TTime implements Comparable<TTime> {
|
||||
int seconds = milliseconds / 1000;
|
||||
milliseconds = milliseconds - seconds * 1000;
|
||||
return new TTime(s < 0, Math.abs(hours), Math.abs(minutes), Math.abs(seconds), Math.abs(milliseconds));
|
||||
|
||||
}
|
||||
|
||||
public TTime add(TTime tTimeToBeAdded) {
|
||||
|
@ -184,7 +184,7 @@ Smileys can be colored or white-black (can be set in configuration)
|
||||
## Command button
|
||||
|
||||
## Todos
|
||||
|
||||
* New table: YEAR
|
||||
* Split to Maven modules
|
||||
* Junit, Mockito, etc.
|
||||
* Checkstyle
|
||||
|
Loading…
x
Reference in New Issue
Block a user