Added the possibility to set a custom window title

This commit is contained in:
Robert Vokac 2024-03-03 12:05:40 +00:00
parent ac3962fe8b
commit 9a7bdb15a1
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
7 changed files with 67 additions and 10 deletions

View File

@ -146,7 +146,8 @@ Smileys can be colored or white-black (can be set in configuration)
## Todos ## Todos
* Config window * Custom main window title
* Profiles
* Split to Maven modules * Split to Maven modules
* Junit, Mockito, etc. * Junit, Mockito, etc.
* Checkstyle * Checkstyle

View File

@ -139,6 +139,8 @@ public class TimeCalcConfiguration {
= new BooleanProperty(TimeCalcProperty.CIRCLE_VISIBLE.getKey()); = new BooleanProperty(TimeCalcProperty.CIRCLE_VISIBLE.getKey());
public final BooleanProperty walkingHumanVisibleProperty public final BooleanProperty walkingHumanVisibleProperty
= new BooleanProperty(TimeCalcProperty.WALKING_HUMAN_VISIBLE.getKey()); = new BooleanProperty(TimeCalcProperty.WALKING_HUMAN_VISIBLE.getKey());
public final StringProperty mainWindowCustomTitleProperty
= new StringProperty(TimeCalcProperty.MAIN_WINDOW_CUSTOM_TITLE.getKey());
private final Map<TimeCalcProperty, Property> mapOfProperties = new HashMap<>(); private final Map<TimeCalcProperty, Property> mapOfProperties = new HashMap<>();
private List<Property> allProperties = new ArrayList<>(); private List<Property> allProperties = new ArrayList<>();
@ -187,7 +189,8 @@ public class TimeCalcConfiguration {
smileysColoredProperty, smileysColoredProperty,
squareVisibleProperty, squareVisibleProperty,
circleVisibleProperty, circleVisibleProperty,
walkingHumanVisibleProperty,}) { walkingHumanVisibleProperty,
mainWindowCustomTitleProperty,}) {
allProperties.add(p); allProperties.add(p);
} }
allProperties.stream().forEach(p -> mapOfProperties.put(TimeCalcProperty.forKey(p.getName()), p)); allProperties.stream().forEach(p -> mapOfProperties.put(TimeCalcProperty.forKey(p.getName()), p));

View File

@ -61,7 +61,8 @@ public enum TimeCalcProperty {
SQUARE_VISIBLE("square.visible", "Square"), SQUARE_VISIBLE("square.visible", "Square"),
CIRCLE_VISIBLE("circle.visible", "Circle"), CIRCLE_VISIBLE("circle.visible", "Circle"),
WALKING_HUMAN_VISIBLE("walking-human.visible", "Walking Human"); WALKING_HUMAN_VISIBLE("walking-human.visible", "Walking Human"),
MAIN_WINDOW_CUSTOM_TITLE("main-window.custom-title", "Main Window : Custom Title");
@Getter @Getter
private final String key; private final String key;

View File

@ -18,6 +18,7 @@ public class WorkDay {
private int day; private int day;
private int arrivalHour; private int arrivalHour;
private int arrivalMinute; private int arrivalMinute;
private boolean halfDay;
private int overtimeHour; private int overtimeHour;
private int overtimeMinute; private int overtimeMinute;
private String note; private String note;

View File

@ -29,7 +29,10 @@ import javax.swing.BoxLayout;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JSeparator; import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
/** /**
* @author Robert Vokac * @author Robert Vokac
@ -40,6 +43,7 @@ public class ConfigWindow extends TWindow {
public static final int WIDTH1 = 600; public static final int WIDTH1 = 600;
public static final int HEIGHT1 = 30; public static final int HEIGHT1 = 30;
public static final String CLIENT_PROPERTY_KEY = TimeCalcProperty.class.getName(); public static final String CLIENT_PROPERTY_KEY = TimeCalcProperty.class.getName();
public static final String THREE_DASHES = "---";
private final TimeCalcConfiguration timeCalcConfiguration; private final TimeCalcConfiguration timeCalcConfiguration;
private int currentY = SwingUtils.MARGIN; private int currentY = SwingUtils.MARGIN;
private List<JComponent> propertiesList = new ArrayList<>(); private List<JComponent> propertiesList = new ArrayList<>();
@ -131,6 +135,8 @@ public class ConfigWindow extends TWindow {
= new JCheckBox(TimeCalcProperty.CIRCLE_VISIBLE.getKey()); = new JCheckBox(TimeCalcProperty.CIRCLE_VISIBLE.getKey());
private JCheckBox walkingHumanVisibleProperty private JCheckBox walkingHumanVisibleProperty
= new JCheckBox(TimeCalcProperty.WALKING_HUMAN_VISIBLE.getKey()); = new JCheckBox(TimeCalcProperty.WALKING_HUMAN_VISIBLE.getKey());
private JTextField mainWindowCustomTitleProperty
= new JTextField();
private final JPanel panelInsideScrollPane; private final JPanel panelInsideScrollPane;
public ConfigWindow(TimeCalcConfiguration timeCalcConfiguration) { public ConfigWindow(TimeCalcConfiguration timeCalcConfiguration) {
@ -220,6 +226,7 @@ public class ConfigWindow extends TWindow {
circleVisibleProperty.setSelected(enable); circleVisibleProperty.setSelected(enable);
walkingHumanVisibleProperty.setSelected(enable); walkingHumanVisibleProperty.setSelected(enable);
MainWindow.hideShowCheckBox.setSelected(enable); MainWindow.hideShowCheckBox.setSelected(enable);
mainWindowCustomTitleProperty.setText(enable ? THREE_DASHES : "");
}); });
} }
@ -265,7 +272,8 @@ public class ConfigWindow extends TWindow {
notificationsVisibleProperty, notificationsVisibleProperty,
squareVisibleProperty, squareVisibleProperty,
circleVisibleProperty, circleVisibleProperty,
walkingHumanVisibleProperty)); walkingHumanVisibleProperty,
mainWindowCustomTitleProperty));
// //
propertiesList.stream().forEach(p -> { propertiesList.stream().forEach(p -> {
p.setAlignmentX(LEFT_ALIGNMENT); p.setAlignmentX(LEFT_ALIGNMENT);
@ -277,6 +285,10 @@ public class ConfigWindow extends TWindow {
p.putClientProperty(CLIENT_PROPERTY_KEY, TimeCalcProperty.CLOCK_CIRCLE_BORDER_COLOR.getKey()); p.putClientProperty(CLIENT_PROPERTY_KEY, TimeCalcProperty.CLOCK_CIRCLE_BORDER_COLOR.getKey());
addToNextRow(new JLabel(TimeCalcProperty.CLOCK_CIRCLE_BORDER_COLOR.getDescription().replace("Clock : ", ""))); addToNextRow(new JLabel(TimeCalcProperty.CLOCK_CIRCLE_BORDER_COLOR.getDescription().replace("Clock : ", "")));
} }
if (p == mainWindowCustomTitleProperty) {
addToNextRow(new JLabel(TimeCalcProperty.MAIN_WINDOW_CUSTOM_TITLE.getDescription()));
p.putClientProperty(CLIENT_PROPERTY_KEY, TimeCalcProperty.MAIN_WINDOW_CUSTOM_TITLE.getKey());
}
if (p instanceof JComboBox) { if (p instanceof JComboBox) {
JComboBox jComboBox = ((JComboBox) p); JComboBox jComboBox = ((JComboBox) p);
jComboBox.setMaximumSize(new Dimension(150, 25)); jComboBox.setMaximumSize(new Dimension(150, 25));
@ -285,7 +297,7 @@ public class ConfigWindow extends TWindow {
CLIENT_PROPERTY_KEY); CLIENT_PROPERTY_KEY);
TimeCalcProperty timeCalcProperty TimeCalcProperty timeCalcProperty
= TimeCalcProperty.forKey(timeCalcPropertyKey); = TimeCalcProperty.forKey(timeCalcPropertyKey);
jComboBox.setSelectedItem(timeCalcConfiguration.getProperty(timeCalcProperty)); jComboBox.setSelectedItem(timeCalcConfiguration.getProperty(timeCalcProperty).getValue());
jComboBox.addPropertyChangeListener(e -> { jComboBox.addPropertyChangeListener(e -> {
((StringProperty) timeCalcConfiguration.getProperty(timeCalcProperty)) ((StringProperty) timeCalcConfiguration.getProperty(timeCalcProperty))
.setValue( .setValue(
@ -389,6 +401,29 @@ public class ConfigWindow extends TWindow {
}); });
} }
if (p instanceof JTextField) {
JTextField jTextField = ((JTextField) p);
jTextField.setMaximumSize(new Dimension(150, 25));
String timeCalcPropertyKey = (String) jTextField.getClientProperty(
CLIENT_PROPERTY_KEY);
TimeCalcProperty timeCalcProperty
= TimeCalcProperty.forKey(timeCalcPropertyKey);
jTextField.setText((String) timeCalcConfiguration.getProperty(timeCalcProperty).getValue());
jTextField.getDocument().addDocumentListener(new DocumentListener() {
public void changedUpdate(DocumentEvent e) {
}
public void removeUpdate(DocumentEvent e) {
}
public void insertUpdate(DocumentEvent e) {
((StringProperty) timeCalcConfiguration.getProperty(timeCalcProperty))
.setValue(
(String) jTextField.getText());
}
});
}
propertiesMap.put(TimeCalcProperty.forKey( propertiesMap.put(TimeCalcProperty.forKey(
(String) p.getClientProperty(CLIENT_PROPERTY_KEY)), p); (String) p.getClientProperty(CLIENT_PROPERTY_KEY)), p);
addToNextRow(p); addToNextRow(p);

View File

@ -27,6 +27,7 @@ import org.nanoboot.utils.timecalc.utils.common.Utils;
import org.nanoboot.utils.timecalc.utils.property.IntegerProperty; import org.nanoboot.utils.timecalc.utils.property.IntegerProperty;
import org.nanoboot.utils.timecalc.utils.property.Property; import org.nanoboot.utils.timecalc.utils.property.Property;
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;
@ -38,10 +39,8 @@ import java.time.LocalDate;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Properties; import java.util.Properties;
import java.util.function.Predicate;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.swing.JCheckBox;
/** /**
* @author Robert Vokac * @author Robert Vokac
@ -85,6 +84,9 @@ public class MainWindow extends TWindow {
}); });
timeCalcConfiguration timeCalcConfiguration
.loadFromTimeCalcProperties(TimeCalcProperties.getInstance()); .loadFromTimeCalcProperties(TimeCalcProperties.getInstance());
timeCalcConfiguration.mainWindowCustomTitleProperty.addListener(e -> {
setTitle(getWindowTitle());
});
overTimeIn = (overTimeIn == null || overTimeIn.isEmpty()) overTimeIn = (overTimeIn == null || overTimeIn.isEmpty())
? Constants.DEFAULT_OVERTIME : overTimeIn; ? Constants.DEFAULT_OVERTIME : overTimeIn;
@ -174,8 +176,7 @@ public class MainWindow extends TWindow {
setLayout(null); setLayout(null);
setVisible(true); setVisible(true);
String windowTitle = "Time Calc " + Utils.getVersion(); setTitle(getWindowTitle());
setTitle(windowTitle);
weatherButton weatherButton
.addActionListener(e -> new WeatherWindow().setVisible(true)); .addActionListener(e -> new WeatherWindow().setVisible(true));
@ -391,6 +392,7 @@ public class MainWindow extends TWindow {
while (true) { while (true) {
//System.out.println("timeCalcConfiguration.handsLongProperty=" + timeCalcConfiguration.clockHandLongProperty.isEnabled()); //System.out.println("timeCalcConfiguration.handsLongProperty=" + timeCalcConfiguration.clockHandLongProperty.isEnabled());
Visibility currentVisibility = Visibility Visibility currentVisibility = Visibility
.valueOf(timeCalcApp.visibilityProperty.getValue()); .valueOf(timeCalcApp.visibilityProperty.getValue());
if (!timeCalcConfiguration.visibilitySupportedColoredProperty.isEnabled() && currentVisibility.isColored()) { if (!timeCalcConfiguration.visibilitySupportedColoredProperty.isEnabled() && currentVisibility.isColored()) {
@ -430,7 +432,7 @@ public class MainWindow extends TWindow {
TimeCalcProperty.JOKES_VISIBLE) TimeCalcProperty.JOKES_VISIBLE)
&& !currentVisibility.isNone() && MainWindow.hideShowCheckBox.isSelected()); && !currentVisibility.isNone() && MainWindow.hideShowCheckBox.isSelected());
setTitle(currentVisibility.isNone() ? "" : windowTitle); setTitle(currentVisibility.isNone() ? "" : getWindowTitle());
int hourNow = analogClock.hourProperty.getValue(); int hourNow = analogClock.hourProperty.getValue();
int minuteNow = analogClock.minuteProperty.getValue(); int minuteNow = analogClock.minuteProperty.getValue();
@ -552,6 +554,19 @@ public class MainWindow extends TWindow {
dispose(); dispose();
} }
private String getWindowTitle() {
if (timeCalcConfiguration.mainWindowCustomTitleProperty.getValue()
.equals(ConfigWindow.THREE_DASHES)) {
return "Time Calc " + Utils.getVersion();
} else {
return String.valueOf(
timeCalcConfiguration.mainWindowCustomTitleProperty
.getValue());
}
}
private void bindToIfPropertyMissing(Properties properties, String key, Calendar cal, int timeUnit, IntegerProperty firstProperty, Property secondProperty) { private void bindToIfPropertyMissing(Properties properties, String key, Calendar cal, int timeUnit, IntegerProperty firstProperty, Property secondProperty) {
if (properties.containsKey(key)) { if (properties.containsKey(key)) {
cal.set(timeUnit, Integer.parseInt( cal.set(timeUnit, Integer.parseInt(

View File

@ -48,3 +48,4 @@ walking-human.visible=true
#TODO: #TODO:
logs.detailed=false logs.detailed=false
battery.percent-precision.count-of-decimal-points=5 battery.percent-precision.count-of-decimal-points=5
main-window.custom-title=---