ConfigWindow II

This commit is contained in:
Robert Vokac 2024-02-11 15:02:21 +00:00
parent ad8b49ee2d
commit c59a27d1a1
No known key found for this signature in database
GPG Key ID: 693D30BEE3329055
5 changed files with 65 additions and 20 deletions

View File

@ -20,7 +20,7 @@ public class TimeCalcConfiguration {
public final BooleanProperty batteryWavesEnabledProperty =
new BooleanProperty("batteryWavesEnabledProperty", true);
public final StringProperty
defaultVisibilityProperty =
visibilityCurrentProperty =
new StringProperty("defaultVisibilityProperty",
Visibility.STRONGLY_COLORED.name());
public final BooleanProperty visibilityOnlyGreyOrNoneEnabledProperty =
@ -50,8 +50,8 @@ public class TimeCalcConfiguration {
.setValue(timeCalcProperties.isMillisecondEnabled());
batteryWavesEnabledProperty
.setValue(timeCalcProperties.areBatteryWavesEnabled());
defaultVisibilityProperty
.setValue(timeCalcProperties.getDefaultVisibility().name());
visibilityCurrentProperty
.setValue(timeCalcProperties.getVisibilityCurrent().name());
visibilityOnlyGreyOrNoneEnabledProperty.setValue(
timeCalcProperties.isVisibilityOnlyGreyOrNoneEnabled());
jokesEnabledProperty.setValue(timeCalcProperties.areJokesEnabled());

View File

@ -91,6 +91,7 @@ public class TimeCalcManager {
if(timeCalcConfiguration.visibilityOnlyGreyOrNoneEnabledProperty.isEnabled()) {
timeCalcApp.visibilityProperty.setValue(Visibility.GRAY.name());
}
timeCalcApp.visibilityProperty.bindTo(timeCalcConfiguration.visibilityCurrentProperty);
TimeCalcKeyAdapter timeCalcKeyAdapter = new TimeCalcKeyAdapter(timeCalcConfiguration, timeCalcApp, commandButton, window);
window.addKeyListener(timeCalcKeyAdapter);

View File

@ -20,7 +20,7 @@ public class TimeCalcProperties {
private static final String CLOCK_HANDS_MILLISECOND_ENABLED =
"clock.hands.millisecond.enabled";
private static final String BATTERY_WAVES_ENABLED = "battery.waves.enabled";
private static final String DEFAULT_VISIBILITY = "default-visibility";
private static final String VISIBILITY_CURRENT = "visibility.current";
private static final String VISIBILITY_ONLY_GREY_OR_NONE_ENABLED =
"visibility.only-grey-or-none.enabled";
private static final String JOKES_ENABLED = "jokes.enabled";
@ -83,11 +83,11 @@ public class TimeCalcProperties {
return getBooleanProperty(SMILEYS_COLORED, true);
}
public Visibility getDefaultVisibility() {
if (!properties.containsKey(DEFAULT_VISIBILITY)) {
public Visibility getVisibilityCurrent() {
if (!properties.containsKey(VISIBILITY_CURRENT)) {
return Visibility.STRONGLY_COLORED;
}
return Visibility.valueOf((String) properties.get(DEFAULT_VISIBILITY));
return Visibility.valueOf((String) properties.get(VISIBILITY_CURRENT));
}
public boolean isVisibilityOnlyGreyOrNoneEnabled() {

View File

@ -3,25 +3,35 @@ package org.nanoboot.utils.timecalc.swing.common;
import org.nanoboot.utils.timecalc.app.TimeCalcConfiguration;
import org.nanoboot.utils.timecalc.entity.Visibility;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.FlowLayout;
import java.awt.LayoutManager;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.util.Arrays;
import java.util.stream.Collectors;
/**
* @author Robert Vokac
* @since 16.02.2024
*/
public class ConfigWindow extends JFrame {
public static final int WIDTH1 = 600;
public static final int HEIGHT1 = 30;
private final TimeCalcConfiguration timeCalcConfiguration;
private int currentY = SwingUtils.MARGIN;;
private JCheckBox clockHandLongProperty = new JCheckBox("Visibility : Clock : Hands are long", true);
private JCheckBox clockHandMinuteEnabledProperty = new JCheckBox("Visibility : Clock : Minute hand", true);
private JCheckBox clockHandSecondEnabledProperty = new JCheckBox("Visibility : Clock : Second hand", true);
private JCheckBox clockHandMillisecondEnabledProperty = new JCheckBox("Visibility : Clock : Millisecond hand", false);
private JCheckBox batteryWavesEnabledProperty = new JCheckBox("Visibility : Battery : Waves", true);
public final JTextField defaultVisibilityProperty = new JTextField(Visibility.STRONGLY_COLORED.name());
public final JComboBox visibilityCurrentProperty = new JComboBox(
Arrays.stream(Visibility.values()).map(v->v.name()).collect(
Collectors.toList()).toArray());
private JCheckBox visibilityOnlyGreyOrNoneEnabledProperty = new JCheckBox("Visibility : Only GREY or NONE",
false);
@ -34,17 +44,46 @@ public class ConfigWindow extends JFrame {
public ConfigWindow(TimeCalcConfiguration timeCalcConfiguration) {
this.timeCalcConfiguration = timeCalcConfiguration;
setTitle("Configuration");
this.setSize(800, 600);
LayoutManager flowLayout = new FlowLayout(FlowLayout.LEFT);
setLayout(flowLayout);
this.setSize(800, WIDTH1);
setLayout(null);
add(clockHandLongProperty);
clockHandLongProperty.setBounds(SwingUtils.MARGIN, currentY, WIDTH1,
HEIGHT1);
nextRow();
add(clockHandMinuteEnabledProperty);
clockHandMinuteEnabledProperty.setBounds(SwingUtils.MARGIN, currentY,
WIDTH1, HEIGHT1);
nextRow();
add(clockHandSecondEnabledProperty);
clockHandSecondEnabledProperty.setBounds(SwingUtils.MARGIN, currentY,
WIDTH1, HEIGHT1);
nextRow();
add(clockHandMillisecondEnabledProperty);
clockHandMillisecondEnabledProperty.setBounds(SwingUtils.MARGIN, currentY,
WIDTH1, HEIGHT1);
nextRow();
add(batteryWavesEnabledProperty);
add(new JLabel("Visibility : Default"));
add(defaultVisibilityProperty);
batteryWavesEnabledProperty.setBounds(SwingUtils.MARGIN, currentY,
WIDTH1, HEIGHT1);
nextRow();
JLabel visibilityCurrentLabel = new JLabel("Visibility : Current");
add(visibilityCurrentLabel);
visibilityCurrentLabel.setBounds(SwingUtils.MARGIN, currentY, WIDTH1,
HEIGHT1);
nextRow();
add(visibilityCurrentProperty);
visibilityCurrentProperty.setMaximumSize(new Dimension(150, 25));
visibilityCurrentProperty.setBounds(SwingUtils.MARGIN, currentY, WIDTH1,
HEIGHT1);
nextRow();
clockHandLongProperty.addActionListener(e -> {
timeCalcConfiguration.clockHandLongProperty.setValue(clockHandLongProperty.isSelected());
@ -62,10 +101,15 @@ public class ConfigWindow extends JFrame {
timeCalcConfiguration.batteryWavesEnabledProperty.setValue(batteryWavesEnabledProperty.isSelected());
});
defaultVisibilityProperty.addActionListener(e -> {
timeCalcConfiguration.defaultVisibilityProperty.setValue(defaultVisibilityProperty.getText());
visibilityCurrentProperty.addActionListener(e -> {
timeCalcConfiguration.visibilityCurrentProperty.setValue(
(String) visibilityCurrentProperty.getSelectedItem());
System.out.println("configWindow.visibilityCurrentProperty=" + visibilityCurrentProperty.getSelectedItem());
});
}
private void nextRow() {
currentY = currentY + 3 * SwingUtils.MARGIN;
}
}

View File

@ -3,8 +3,8 @@ clock.hands.minute.enabled=true
clock.hands.second.enabled=true
clock.hands.millisecond.enabled=false
battery.waves.enabled=true
default-visibility=STRONGLY_COLORED
visibility.only-grey-or-none.enabled=true
visibility.current=STRONGLY_COLORED
visibility.only-grey-or-none.enabled=false
jokes.enabled=true
commands.enabled=true
toasts.enabled=true