diff --git a/.gitignore b/.gitignore index 199757e3..48b4d39b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,6 @@ Makefile Makefile.in aclocal.m4 autom4te.cache -config config.h config.h.in config.log diff --git a/corefx/src/main/java/com/core/ui/config/BaseConfigItem.java b/corefx/src/main/java/com/core/ui/config/BaseConfigItem.java new file mode 100644 index 00000000..1a9deb29 --- /dev/null +++ b/corefx/src/main/java/com/core/ui/config/BaseConfigItem.java @@ -0,0 +1,16 @@ +package com.core.ui.config; + +import com.core.client.rest.ConfigOption; +import javafx.scene.control.Label; +import lombok.Data; + +@Data +public abstract class BaseConfigItem implements IConfigItem { + private final Label label; + private final ConfigOption option; + + public BaseConfigItem(ConfigOption option) { + this.option = option; + this.label = new Label(option.getLabel()); + } +} diff --git a/corefx/src/main/java/com/core/ui/config/BooleanConfigItem.java b/corefx/src/main/java/com/core/ui/config/BooleanConfigItem.java new file mode 100644 index 00000000..817ea7f0 --- /dev/null +++ b/corefx/src/main/java/com/core/ui/config/BooleanConfigItem.java @@ -0,0 +1,31 @@ +package com.core.ui.config; + +import com.core.client.rest.ConfigOption; +import com.jfoenix.controls.JFXToggleButton; +import javafx.scene.Node; + +public class BooleanConfigItem extends BaseConfigItem { + private JFXToggleButton button = new JFXToggleButton(); + + public BooleanConfigItem(ConfigOption option) { + super(option); + button.setMaxWidth(Double.MAX_VALUE); + if ("1".equals(option.getValue())) { + button.setSelected(true); + } + button.selectedProperty().addListener(((observable, oldValue, newValue) -> { + String value; + if (newValue) { + value = "1"; + } else { + value = "0"; + } + getOption().setValue(value); + })); + } + + @Override + public Node getNode() { + return button; + } +} diff --git a/corefx/src/main/java/com/core/ui/config/ConfigItemUtils.java b/corefx/src/main/java/com/core/ui/config/ConfigItemUtils.java new file mode 100644 index 00000000..9a30b6ba --- /dev/null +++ b/corefx/src/main/java/com/core/ui/config/ConfigItemUtils.java @@ -0,0 +1,30 @@ +package com.core.ui.config; + +import com.core.client.rest.ConfigOption; +import com.core.data.ConfigDataType; +import javafx.stage.Stage; + +public final class ConfigItemUtils { + private ConfigItemUtils() { + + } + + public static IConfigItem get(Stage stage, ConfigOption option) { + IConfigItem configItem = null; + ConfigDataType dataType = ConfigDataType.get(option.getType()); + switch (dataType) { + case BOOL: + configItem = new BooleanConfigItem(option); + break; + default: + if (!option.getSelect().isEmpty()) { + configItem = new SelectConfigItem(option); + } else { + configItem = new DefaultConfigItem(option); + } + break; + } + + return configItem; + } +} diff --git a/corefx/src/main/java/com/core/ui/config/DefaultConfigItem.java b/corefx/src/main/java/com/core/ui/config/DefaultConfigItem.java new file mode 100644 index 00000000..bfde9b90 --- /dev/null +++ b/corefx/src/main/java/com/core/ui/config/DefaultConfigItem.java @@ -0,0 +1,23 @@ +package com.core.ui.config; + +import com.core.client.rest.ConfigOption; +import com.jfoenix.controls.JFXTextField; +import javafx.scene.Node; + +public class DefaultConfigItem extends BaseConfigItem { + private JFXTextField textField; + + public DefaultConfigItem(ConfigOption option) { + super(option); + textField = new JFXTextField(option.getValue()); + textField.setMaxWidth(Double.MAX_VALUE); + textField.textProperty().addListener(((observable, oldValue, newValue) -> { + getOption().setValue(newValue); + })); + } + + @Override + public Node getNode() { + return textField; + } +} diff --git a/corefx/src/main/java/com/core/ui/config/IConfigItem.java b/corefx/src/main/java/com/core/ui/config/IConfigItem.java new file mode 100644 index 00000000..f815a9d5 --- /dev/null +++ b/corefx/src/main/java/com/core/ui/config/IConfigItem.java @@ -0,0 +1,13 @@ +package com.core.ui.config; + +import com.core.client.rest.ConfigOption; +import javafx.scene.Node; +import javafx.scene.control.Label; + +public interface IConfigItem { + Label getLabel(); + + Node getNode(); + + ConfigOption getOption(); +} diff --git a/corefx/src/main/java/com/core/ui/config/SelectConfigItem.java b/corefx/src/main/java/com/core/ui/config/SelectConfigItem.java new file mode 100644 index 00000000..d61fe194 --- /dev/null +++ b/corefx/src/main/java/com/core/ui/config/SelectConfigItem.java @@ -0,0 +1,28 @@ +package com.core.ui.config; + +import com.core.client.rest.ConfigOption; +import com.jfoenix.controls.JFXComboBox; +import javafx.scene.Node; + +public class SelectConfigItem extends BaseConfigItem { + private JFXComboBox comboBox = new JFXComboBox<>(); + + public SelectConfigItem(ConfigOption option) { + super(option); + comboBox.setMaxWidth(Double.MAX_VALUE); + comboBox.getItems().addAll(option.getSelect()); + comboBox.getSelectionModel().select(option.getValue()); + comboBox.getSelectionModel().selectedItemProperty().addListener(((observable, oldValue, newValue) -> { + if (newValue == null) { + return; + } + + getOption().setValue(newValue); + })); + } + + @Override + public Node getNode() { + return comboBox; + } +}