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

View File

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

View File

@ -20,7 +20,7 @@ public class TimeCalcProperties {
private static final String CLOCK_HANDS_MILLISECOND_ENABLED = private static final String CLOCK_HANDS_MILLISECOND_ENABLED =
"clock.hands.millisecond.enabled"; "clock.hands.millisecond.enabled";
private static final String BATTERY_WAVES_ENABLED = "battery.waves.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 = private static final String VISIBILITY_ONLY_GREY_OR_NONE_ENABLED =
"visibility.only-grey-or-none.enabled"; "visibility.only-grey-or-none.enabled";
private static final String JOKES_ENABLED = "jokes.enabled"; private static final String JOKES_ENABLED = "jokes.enabled";
@ -83,11 +83,11 @@ public class TimeCalcProperties {
return getBooleanProperty(SMILEYS_COLORED, true); return getBooleanProperty(SMILEYS_COLORED, true);
} }
public Visibility getDefaultVisibility() { public Visibility getVisibilityCurrent() {
if (!properties.containsKey(DEFAULT_VISIBILITY)) { if (!properties.containsKey(VISIBILITY_CURRENT)) {
return Visibility.STRONGLY_COLORED; return Visibility.STRONGLY_COLORED;
} }
return Visibility.valueOf((String) properties.get(DEFAULT_VISIBILITY)); return Visibility.valueOf((String) properties.get(VISIBILITY_CURRENT));
} }
public boolean isVisibilityOnlyGreyOrNoneEnabled() { 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.app.TimeCalcConfiguration;
import org.nanoboot.utils.timecalc.entity.Visibility; import org.nanoboot.utils.timecalc.entity.Visibility;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JTextField; import javax.swing.JPanel;
import java.awt.FlowLayout; import java.awt.Color;
import java.awt.LayoutManager; import java.awt.Component;
import java.awt.Dimension;
import java.util.Arrays;
import java.util.stream.Collectors;
/** /**
* @author Robert Vokac * @author Robert Vokac
* @since 16.02.2024 * @since 16.02.2024
*/ */
public class ConfigWindow extends JFrame { public class ConfigWindow extends JFrame {
public static final int WIDTH1 = 600;
public static final int HEIGHT1 = 30;
private final TimeCalcConfiguration timeCalcConfiguration; private final TimeCalcConfiguration timeCalcConfiguration;
private int currentY = SwingUtils.MARGIN;;
private JCheckBox clockHandLongProperty = new JCheckBox("Visibility : Clock : Hands are long", true); private JCheckBox clockHandLongProperty = new JCheckBox("Visibility : Clock : Hands are long", true);
private JCheckBox clockHandMinuteEnabledProperty = new JCheckBox("Visibility : Clock : Minute hand", true); private JCheckBox clockHandMinuteEnabledProperty = new JCheckBox("Visibility : Clock : Minute hand", true);
private JCheckBox clockHandSecondEnabledProperty = new JCheckBox("Visibility : Clock : Second hand", true); private JCheckBox clockHandSecondEnabledProperty = new JCheckBox("Visibility : Clock : Second hand", true);
private JCheckBox clockHandMillisecondEnabledProperty = new JCheckBox("Visibility : Clock : Millisecond hand", false); private JCheckBox clockHandMillisecondEnabledProperty = new JCheckBox("Visibility : Clock : Millisecond hand", false);
private JCheckBox batteryWavesEnabledProperty = new JCheckBox("Visibility : Battery : Waves", true); 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", private JCheckBox visibilityOnlyGreyOrNoneEnabledProperty = new JCheckBox("Visibility : Only GREY or NONE",
false); false);
@ -34,17 +44,46 @@ public class ConfigWindow extends JFrame {
public ConfigWindow(TimeCalcConfiguration timeCalcConfiguration) { public ConfigWindow(TimeCalcConfiguration timeCalcConfiguration) {
this.timeCalcConfiguration = timeCalcConfiguration; this.timeCalcConfiguration = timeCalcConfiguration;
setTitle("Configuration"); setTitle("Configuration");
this.setSize(800, 600); this.setSize(800, WIDTH1);
LayoutManager flowLayout = new FlowLayout(FlowLayout.LEFT);
setLayout(flowLayout); setLayout(null);
add(clockHandLongProperty); add(clockHandLongProperty);
clockHandLongProperty.setBounds(SwingUtils.MARGIN, currentY, WIDTH1,
HEIGHT1);
nextRow();
add(clockHandMinuteEnabledProperty); add(clockHandMinuteEnabledProperty);
clockHandMinuteEnabledProperty.setBounds(SwingUtils.MARGIN, currentY,
WIDTH1, HEIGHT1);
nextRow();
add(clockHandSecondEnabledProperty); add(clockHandSecondEnabledProperty);
clockHandSecondEnabledProperty.setBounds(SwingUtils.MARGIN, currentY,
WIDTH1, HEIGHT1);
nextRow();
add(clockHandMillisecondEnabledProperty); add(clockHandMillisecondEnabledProperty);
clockHandMillisecondEnabledProperty.setBounds(SwingUtils.MARGIN, currentY,
WIDTH1, HEIGHT1);
nextRow();
add(batteryWavesEnabledProperty); add(batteryWavesEnabledProperty);
add(new JLabel("Visibility : Default")); batteryWavesEnabledProperty.setBounds(SwingUtils.MARGIN, currentY,
add(defaultVisibilityProperty); 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 -> { clockHandLongProperty.addActionListener(e -> {
timeCalcConfiguration.clockHandLongProperty.setValue(clockHandLongProperty.isSelected()); timeCalcConfiguration.clockHandLongProperty.setValue(clockHandLongProperty.isSelected());
@ -62,10 +101,15 @@ public class ConfigWindow extends JFrame {
timeCalcConfiguration.batteryWavesEnabledProperty.setValue(batteryWavesEnabledProperty.isSelected()); timeCalcConfiguration.batteryWavesEnabledProperty.setValue(batteryWavesEnabledProperty.isSelected());
}); });
defaultVisibilityProperty.addActionListener(e -> { visibilityCurrentProperty.addActionListener(e -> {
timeCalcConfiguration.defaultVisibilityProperty.setValue(defaultVisibilityProperty.getText()); 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.second.enabled=true
clock.hands.millisecond.enabled=false clock.hands.millisecond.enabled=false
battery.waves.enabled=true battery.waves.enabled=true
default-visibility=STRONGLY_COLORED visibility.current=STRONGLY_COLORED
visibility.only-grey-or-none.enabled=true visibility.only-grey-or-none.enabled=false
jokes.enabled=true jokes.enabled=true
commands.enabled=true commands.enabled=true
toasts.enabled=true toasts.enabled=true