Added the possibility to set a custom window title
This commit is contained in:
parent
ac3962fe8b
commit
9a7bdb15a1
@ -146,7 +146,8 @@ Smileys can be colored or white-black (can be set in configuration)
|
||||
|
||||
## Todos
|
||||
|
||||
* Config window
|
||||
* Custom main window title
|
||||
* Profiles
|
||||
* Split to Maven modules
|
||||
* Junit, Mockito, etc.
|
||||
* Checkstyle
|
||||
|
@ -139,6 +139,8 @@ public class TimeCalcConfiguration {
|
||||
= new BooleanProperty(TimeCalcProperty.CIRCLE_VISIBLE.getKey());
|
||||
public final BooleanProperty walkingHumanVisibleProperty
|
||||
= 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 List<Property> allProperties = new ArrayList<>();
|
||||
@ -187,7 +189,8 @@ public class TimeCalcConfiguration {
|
||||
smileysColoredProperty,
|
||||
squareVisibleProperty,
|
||||
circleVisibleProperty,
|
||||
walkingHumanVisibleProperty,}) {
|
||||
walkingHumanVisibleProperty,
|
||||
mainWindowCustomTitleProperty,}) {
|
||||
allProperties.add(p);
|
||||
}
|
||||
allProperties.stream().forEach(p -> mapOfProperties.put(TimeCalcProperty.forKey(p.getName()), p));
|
||||
|
@ -61,7 +61,8 @@ public enum TimeCalcProperty {
|
||||
|
||||
SQUARE_VISIBLE("square.visible", "Square"),
|
||||
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
|
||||
private final String key;
|
||||
|
@ -18,6 +18,7 @@ public class WorkDay {
|
||||
private int day;
|
||||
private int arrivalHour;
|
||||
private int arrivalMinute;
|
||||
private boolean halfDay;
|
||||
private int overtimeHour;
|
||||
private int overtimeMinute;
|
||||
private String note;
|
||||
|
@ -29,7 +29,10 @@ import javax.swing.BoxLayout;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
|
||||
/**
|
||||
* @author Robert Vokac
|
||||
@ -40,6 +43,7 @@ public class ConfigWindow extends TWindow {
|
||||
public static final int WIDTH1 = 600;
|
||||
public static final int HEIGHT1 = 30;
|
||||
public static final String CLIENT_PROPERTY_KEY = TimeCalcProperty.class.getName();
|
||||
public static final String THREE_DASHES = "---";
|
||||
private final TimeCalcConfiguration timeCalcConfiguration;
|
||||
private int currentY = SwingUtils.MARGIN;
|
||||
private List<JComponent> propertiesList = new ArrayList<>();
|
||||
@ -131,6 +135,8 @@ public class ConfigWindow extends TWindow {
|
||||
= new JCheckBox(TimeCalcProperty.CIRCLE_VISIBLE.getKey());
|
||||
private JCheckBox walkingHumanVisibleProperty
|
||||
= new JCheckBox(TimeCalcProperty.WALKING_HUMAN_VISIBLE.getKey());
|
||||
private JTextField mainWindowCustomTitleProperty
|
||||
= new JTextField();
|
||||
private final JPanel panelInsideScrollPane;
|
||||
|
||||
public ConfigWindow(TimeCalcConfiguration timeCalcConfiguration) {
|
||||
@ -220,6 +226,7 @@ public class ConfigWindow extends TWindow {
|
||||
circleVisibleProperty.setSelected(enable);
|
||||
walkingHumanVisibleProperty.setSelected(enable);
|
||||
MainWindow.hideShowCheckBox.setSelected(enable);
|
||||
mainWindowCustomTitleProperty.setText(enable ? THREE_DASHES : "");
|
||||
});
|
||||
}
|
||||
|
||||
@ -265,7 +272,8 @@ public class ConfigWindow extends TWindow {
|
||||
notificationsVisibleProperty,
|
||||
squareVisibleProperty,
|
||||
circleVisibleProperty,
|
||||
walkingHumanVisibleProperty));
|
||||
walkingHumanVisibleProperty,
|
||||
mainWindowCustomTitleProperty));
|
||||
//
|
||||
propertiesList.stream().forEach(p -> {
|
||||
p.setAlignmentX(LEFT_ALIGNMENT);
|
||||
@ -277,6 +285,10 @@ public class ConfigWindow extends TWindow {
|
||||
p.putClientProperty(CLIENT_PROPERTY_KEY, TimeCalcProperty.CLOCK_CIRCLE_BORDER_COLOR.getKey());
|
||||
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) {
|
||||
JComboBox jComboBox = ((JComboBox) p);
|
||||
jComboBox.setMaximumSize(new Dimension(150, 25));
|
||||
@ -285,7 +297,7 @@ public class ConfigWindow extends TWindow {
|
||||
CLIENT_PROPERTY_KEY);
|
||||
TimeCalcProperty timeCalcProperty
|
||||
= TimeCalcProperty.forKey(timeCalcPropertyKey);
|
||||
jComboBox.setSelectedItem(timeCalcConfiguration.getProperty(timeCalcProperty));
|
||||
jComboBox.setSelectedItem(timeCalcConfiguration.getProperty(timeCalcProperty).getValue());
|
||||
jComboBox.addPropertyChangeListener(e -> {
|
||||
((StringProperty) timeCalcConfiguration.getProperty(timeCalcProperty))
|
||||
.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(
|
||||
(String) p.getClientProperty(CLIENT_PROPERTY_KEY)), p);
|
||||
addToNextRow(p);
|
||||
|
@ -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.Property;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JFrame;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
@ -38,10 +39,8 @@ import java.time.LocalDate;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JCheckBox;
|
||||
|
||||
/**
|
||||
* @author Robert Vokac
|
||||
@ -85,6 +84,9 @@ public class MainWindow extends TWindow {
|
||||
});
|
||||
timeCalcConfiguration
|
||||
.loadFromTimeCalcProperties(TimeCalcProperties.getInstance());
|
||||
timeCalcConfiguration.mainWindowCustomTitleProperty.addListener(e -> {
|
||||
setTitle(getWindowTitle());
|
||||
});
|
||||
|
||||
overTimeIn = (overTimeIn == null || overTimeIn.isEmpty())
|
||||
? Constants.DEFAULT_OVERTIME : overTimeIn;
|
||||
@ -174,8 +176,7 @@ public class MainWindow extends TWindow {
|
||||
setLayout(null);
|
||||
setVisible(true);
|
||||
|
||||
String windowTitle = "Time Calc " + Utils.getVersion();
|
||||
setTitle(windowTitle);
|
||||
setTitle(getWindowTitle());
|
||||
|
||||
weatherButton
|
||||
.addActionListener(e -> new WeatherWindow().setVisible(true));
|
||||
@ -391,6 +392,7 @@ public class MainWindow extends TWindow {
|
||||
|
||||
while (true) {
|
||||
//System.out.println("timeCalcConfiguration.handsLongProperty=" + timeCalcConfiguration.clockHandLongProperty.isEnabled());
|
||||
|
||||
Visibility currentVisibility = Visibility
|
||||
.valueOf(timeCalcApp.visibilityProperty.getValue());
|
||||
if (!timeCalcConfiguration.visibilitySupportedColoredProperty.isEnabled() && currentVisibility.isColored()) {
|
||||
@ -430,7 +432,7 @@ public class MainWindow extends TWindow {
|
||||
TimeCalcProperty.JOKES_VISIBLE)
|
||||
&& !currentVisibility.isNone() && MainWindow.hideShowCheckBox.isSelected());
|
||||
|
||||
setTitle(currentVisibility.isNone() ? "" : windowTitle);
|
||||
setTitle(currentVisibility.isNone() ? "" : getWindowTitle());
|
||||
|
||||
int hourNow = analogClock.hourProperty.getValue();
|
||||
int minuteNow = analogClock.minuteProperty.getValue();
|
||||
@ -552,6 +554,19 @@ public class MainWindow extends TWindow {
|
||||
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) {
|
||||
if (properties.containsKey(key)) {
|
||||
cal.set(timeUnit, Integer.parseInt(
|
||||
|
@ -48,3 +48,4 @@ walking-human.visible=true
|
||||
#TODO:
|
||||
logs.detailed=false
|
||||
battery.percent-precision.count-of-decimal-points=5
|
||||
main-window.custom-title=---
|
||||
|
Loading…
x
Reference in New Issue
Block a user