server

Clone or download

Replaced ToggleButton with ToggleSwitch in Helper

Modified Files

package com.stream_pi.server.window.helper;
package com.stream_pi.server.window.helper;
import com.stream_pi.action_api.actionproperty.property.ControlType;
import com.stream_pi.action_api.actionproperty.property.ControlType;
import com.stream_pi.action_api.actionproperty.property.FileExtensionFilter;
import com.stream_pi.action_api.actionproperty.property.FileExtensionFilter;
import com.stream_pi.action_api.actionproperty.property.ListValue;
import com.stream_pi.action_api.actionproperty.property.ListValue;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.uihelper.HBoxInputBoxWithFileChooser;
import com.stream_pi.util.uihelper.HBoxInputBoxWithFileChooser;
import com.stream_pi.util.uihelper.HBoxWithSpaceBetween;
import com.stream_pi.util.uihelper.HBoxWithSpaceBetween;
import javafx.scene.Node;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.control.*;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser;
import javafx.util.Callback;
import javafx.util.Callback;
import org.controlsfx.control.ToggleSwitch;
public class Helper
public class Helper
{
{
public class ControlNodePair
public class ControlNodePair
{
{
private Node controlNode = null;
private Node controlNode = null;
private Node UINode = null;
private Node UINode = null;
public ControlNodePair(Node controlNode, Node UINode)
public ControlNodePair(Node controlNode, Node UINode)
{
{
this.controlNode = controlNode;
this.controlNode = controlNode;
this.UINode = UINode;
this.UINode = UINode;
}
}
public Node getUINode()
public Node getUINode()
{
{
return UINode;
return UINode;
}
}
public Node getControlNode()
public Node getControlNode()
{
{
return controlNode;
return controlNode;
}
}
}
}
public ControlNodePair getControlNode(Property property) throws MinorException
public ControlNodePair getControlNode(Property property) throws MinorException
{
{
Node UINode = null, controlNode = null;
Node UINode = null, controlNode = null;
if(property.getControlType() == ControlType.COMBO_BOX)
if(property.getControlType() == ControlType.COMBO_BOX)
{
{
ComboBox<ListValue> comboBox = new ComboBox<>();
ComboBox<ListValue> comboBox = new ComboBox<>();
comboBox.getItems().addAll(property.getListValue());
comboBox.getItems().addAll(property.getListValue());
Callback<ListView<ListValue>, ListCell<ListValue>> clientsComboBoxFactory = new Callback<>() {
Callback<ListView<ListValue>, ListCell<ListValue>> clientsComboBoxFactory = new Callback<>() {
@Override
@Override
public ListCell<ListValue> call(ListView<ListValue> clientConnectionListView) {
public ListCell<ListValue> call(ListView<ListValue> clientConnectionListView) {
return new ListCell<>() {
return new ListCell<>() {
@Override
@Override
protected void updateItem(ListValue listValue, boolean b)
protected void updateItem(ListValue listValue, boolean b)
{
{
super.updateItem(listValue, b);
super.updateItem(listValue, b);
if(listValue == null)
if(listValue == null)
{
{
setText("Choose value");
setText("Choose value");
}
}
else
else
{
{
setText(listValue.getDisplayName());
setText(listValue.getDisplayName());
}
}
}
}
};
};
}
}
};
};
comboBox.setCellFactory(clientsComboBoxFactory);
comboBox.setCellFactory(clientsComboBoxFactory);
comboBox.setButtonCell(clientsComboBoxFactory.call(null));
comboBox.setButtonCell(clientsComboBoxFactory.call(null));
comboBox.getSelectionModel().select(property.getSelectedIndex());
comboBox.getSelectionModel().select(property.getSelectedIndex());
controlNode = comboBox;
controlNode = comboBox;
}
}
else if(property.getControlType() == ControlType.TEXT_FIELD)
else if(property.getControlType() == ControlType.TEXT_FIELD)
{
{
controlNode = new TextField(property.getRawValue());
controlNode = new TextField(property.getRawValue());
}
}
else if(property.getControlType() == ControlType.TEXT_FIELD_MASKED)
else if(property.getControlType() == ControlType.TEXT_FIELD_MASKED)
{
{
PasswordField textField = new PasswordField();
PasswordField textField = new PasswordField();
textField.setText(property.getRawValue());
textField.setText(property.getRawValue());
controlNode = textField;
controlNode = textField;
}
}
else if(property.getControlType() == ControlType.TOGGLE)
else if(property.getControlType() == ControlType.TOGGLE)
{
{
ToggleButton toggleButton = new ToggleButton();
ToggleSwitch toggleSwitch = new ToggleSwitch();
toggleButton.setSelected(property.getBoolValue());
toggleSwitch.setSelected(property.getBoolValue());
if(property.getBoolValue())
controlNode = toggleSwitch;
toggleButton.setText("ON");
else
toggleButton.setText("OFF");
toggleButton.selectedProperty().addListener((observableValue, aBoolean, t1) -> {
if(t1)
toggleButton.setText("ON");
else
toggleButton.setText("OFF");
});
controlNode = toggleButton;
}
}
else if(property.getControlType() == ControlType.SLIDER_DOUBLE)
else if(property.getControlType() == ControlType.SLIDER_DOUBLE)
{
{
Slider slider = new Slider();
Slider slider = new Slider();
slider.setValue(property.getDoubleValue());
slider.setValue(property.getDoubleValue());
slider.setMax(property.getMaxDoubleValue());
slider.setMax(property.getMaxDoubleValue());
slider.setMin(property.getMinDoubleValue());
slider.setMin(property.getMinDoubleValue());
controlNode = slider;
controlNode = slider;
}
}
else if(property.getControlType() == ControlType.SLIDER_INTEGER)
else if(property.getControlType() == ControlType.SLIDER_INTEGER)
{
{
Slider slider = new Slider();
Slider slider = new Slider();
slider.setValue(property.getIntValue());
slider.setValue(property.getIntValue());
slider.setMax(property.getMaxIntValue());
slider.setMax(property.getMaxIntValue());
slider.setMin(property.getMinIntValue());
slider.setMin(property.getMinIntValue());
slider.setBlockIncrement(1.0);
slider.setBlockIncrement(1.0);
slider.setSnapToTicks(true);
slider.setSnapToTicks(true);
controlNode = slider;
controlNode = slider;
}
}
else if(property.getControlType() == ControlType.FILE_PATH)
else if(property.getControlType() == ControlType.FILE_PATH)
{
{
TextField textField = new TextField(property.getRawValue());
TextField textField = new TextField(property.getRawValue());
FileExtensionFilter[] fileExtensionFilters = property.getExtensionFilters();
FileExtensionFilter[] fileExtensionFilters = property.getExtensionFilters();
FileChooser.ExtensionFilter[] extensionFilters = new FileChooser.ExtensionFilter[fileExtensionFilters.length];
FileChooser.ExtensionFilter[] extensionFilters = new FileChooser.ExtensionFilter[fileExtensionFilters.length];
for(int x = 0;x<fileExtensionFilters.length;x++)
for(int x = 0;x<fileExtensionFilters.length;x++)
{
{
extensionFilters[x] = new FileChooser.ExtensionFilter(
extensionFilters[x] = new FileChooser.ExtensionFilter(
fileExtensionFilters[x].getDescription(),
fileExtensionFilters[x].getDescription(),
fileExtensionFilters[x].getExtensions()
fileExtensionFilters[x].getExtensions()
);
);
}
}
UINode = new HBoxInputBoxWithFileChooser(property.getDisplayName(), textField, null,
UINode = new HBoxInputBoxWithFileChooser(property.getDisplayName(), textField, null,
extensionFilters);
extensionFilters);
controlNode =textField;
controlNode =textField;
}
}
if(property.getControlType() != ControlType.FILE_PATH)
if(property.getControlType() != ControlType.FILE_PATH)
{
{
UINode = new HBoxWithSpaceBetween(new Label(property.getDisplayName()), controlNode);
UINode = new HBoxWithSpaceBetween(new Label(property.getDisplayName()), controlNode);
}
}
return new ControlNodePair(controlNode, UINode);
return new ControlNodePair(controlNode, UINode);
}
}
}
}