gui - updated dynamic config dialogs to support file picking
This commit is contained in:
parent
1a8618ebde
commit
b87dc6c6c1
3 changed files with 71 additions and 24 deletions
|
@ -6,6 +6,7 @@ import com.core.data.CoreNode;
|
||||||
import com.core.graph.BackgroundPaintable;
|
import com.core.graph.BackgroundPaintable;
|
||||||
import com.jfoenix.controls.JFXButton;
|
import com.jfoenix.controls.JFXButton;
|
||||||
import com.jfoenix.controls.JFXTextField;
|
import com.jfoenix.controls.JFXTextField;
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
|
@ -29,21 +30,19 @@ public class BackgroundDialog extends StageDialog {
|
||||||
super(controller, "/fxml/background_dialog.fxml");
|
super(controller, "/fxml/background_dialog.fxml");
|
||||||
setTitle("Background Configuration");
|
setTitle("Background Configuration");
|
||||||
saveButton = createButton("Save");
|
saveButton = createButton("Save");
|
||||||
saveButton.setOnAction(event -> {
|
saveButton.setOnAction(this::saveAction);
|
||||||
controller.getNetworkGraph().setBackground(fileTextField.getText());
|
|
||||||
close();
|
|
||||||
});
|
|
||||||
clearButton = createButton("Clear");
|
clearButton = createButton("Clear");
|
||||||
clearButton.setOnAction(event -> {
|
clearButton.setOnAction(this::clearAction);
|
||||||
controller.getNetworkGraph().removeBackground();
|
|
||||||
close();
|
|
||||||
});
|
|
||||||
addCancelButton();
|
addCancelButton();
|
||||||
|
|
||||||
HBox parent = (HBox) imageView.getParent();
|
HBox parent = (HBox) imageView.getParent();
|
||||||
imageView.fitHeightProperty().bind(parent.heightProperty());
|
imageView.fitHeightProperty().bind(parent.heightProperty());
|
||||||
|
|
||||||
fileButton.setOnAction(event -> {
|
fileButton.setOnAction(this::fileAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fileAction(ActionEvent event) {
|
||||||
FileChooser fileChooser = new FileChooser();
|
FileChooser fileChooser = new FileChooser();
|
||||||
fileChooser.setTitle("Select Background");
|
fileChooser.setTitle("Select Background");
|
||||||
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
|
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
|
||||||
|
@ -55,7 +54,16 @@ public class BackgroundDialog extends StageDialog {
|
||||||
fileTextField.setText(file.getPath());
|
fileTextField.setText(file.getPath());
|
||||||
saveButton.setDisable(false);
|
saveButton.setDisable(false);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
private void saveAction(ActionEvent event) {
|
||||||
|
getController().getNetworkGraph().setBackground(fileTextField.getText());
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearAction(ActionEvent event) {
|
||||||
|
getController().getNetworkGraph().removeBackground();
|
||||||
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showDialog() {
|
public void showDialog() {
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class ConfigDialog extends StageDialog {
|
||||||
tabPane.getTabs().add(tab);
|
tabPane.getTabs().add(tab);
|
||||||
|
|
||||||
for (ConfigOption option : group.getOptions()) {
|
for (ConfigOption option : group.getOptions()) {
|
||||||
ConfigItem configItem = new ConfigItem(option);
|
ConfigItem configItem = new ConfigItem(getStage(), option);
|
||||||
gridPane.addRow(index, configItem.getLabel(), configItem.getNode());
|
gridPane.addRow(index, configItem.getLabel(), configItem.getNode());
|
||||||
configItems.add(configItem);
|
configItems.add(configItem);
|
||||||
index += 1;
|
index += 1;
|
||||||
|
|
|
@ -1,21 +1,31 @@
|
||||||
package com.core.ui;
|
package com.core.ui;
|
||||||
|
|
||||||
import com.core.data.ConfigDataType;
|
|
||||||
import com.core.client.rest.ConfigOption;
|
import com.core.client.rest.ConfigOption;
|
||||||
|
import com.core.data.ConfigDataType;
|
||||||
|
import com.jfoenix.controls.JFXButton;
|
||||||
import com.jfoenix.controls.JFXComboBox;
|
import com.jfoenix.controls.JFXComboBox;
|
||||||
import com.jfoenix.controls.JFXTextField;
|
import com.jfoenix.controls.JFXTextField;
|
||||||
import com.jfoenix.controls.JFXToggleButton;
|
import com.jfoenix.controls.JFXToggleButton;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.layout.ColumnConstraints;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
|
import javafx.stage.FileChooser;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import javafx.stage.Window;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class ConfigItem {
|
public class ConfigItem {
|
||||||
|
private final Window window;
|
||||||
private ConfigOption option;
|
private ConfigOption option;
|
||||||
private Label label;
|
private Label label;
|
||||||
private Node node;
|
private Node node;
|
||||||
|
|
||||||
public ConfigItem(ConfigOption option) {
|
public ConfigItem(Stage window, ConfigOption option) {
|
||||||
|
this.window = window;
|
||||||
this.option = option;
|
this.option = option;
|
||||||
label = new Label(option.getLabel());
|
label = new Label(option.getLabel());
|
||||||
createNode();
|
createNode();
|
||||||
|
@ -30,6 +40,8 @@ public class ConfigItem {
|
||||||
default:
|
default:
|
||||||
if (!option.getSelect().isEmpty()) {
|
if (!option.getSelect().isEmpty()) {
|
||||||
node = optionsConfig();
|
node = optionsConfig();
|
||||||
|
} else if (option.getLabel().contains("file")) {
|
||||||
|
node = fileConfigItem();
|
||||||
} else {
|
} else {
|
||||||
node = defaultConfigItem();
|
node = defaultConfigItem();
|
||||||
}
|
}
|
||||||
|
@ -63,6 +75,33 @@ public class ConfigItem {
|
||||||
return option;
|
return option;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private GridPane fileConfigItem() {
|
||||||
|
GridPane gridPane = new GridPane();
|
||||||
|
gridPane.setHgap(10);
|
||||||
|
JFXTextField textField = new JFXTextField(option.getValue());
|
||||||
|
textField.setMaxWidth(Double.MAX_VALUE);
|
||||||
|
gridPane.addColumn(0, textField);
|
||||||
|
JFXButton button = new JFXButton("File");
|
||||||
|
button.setMaxWidth(Double.MAX_VALUE);
|
||||||
|
button.getStyleClass().add("core-button");
|
||||||
|
gridPane.addColumn(1, button);
|
||||||
|
ColumnConstraints firstColumn = new ColumnConstraints(10);
|
||||||
|
firstColumn.setPercentWidth(80);
|
||||||
|
ColumnConstraints secondColumn = new ColumnConstraints(10);
|
||||||
|
secondColumn.setPercentWidth(20);
|
||||||
|
gridPane.getColumnConstraints().addAll(firstColumn, secondColumn);
|
||||||
|
button.setOnAction(event -> {
|
||||||
|
FileChooser fileChooser = new FileChooser();
|
||||||
|
fileChooser.setTitle("Select File");
|
||||||
|
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
|
||||||
|
File file = fileChooser.showOpenDialog(window);
|
||||||
|
if (file != null) {
|
||||||
|
textField.setText(file.getPath());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return gridPane;
|
||||||
|
}
|
||||||
|
|
||||||
private JFXTextField defaultConfigItem() {
|
private JFXTextField defaultConfigItem() {
|
||||||
JFXTextField textField = new JFXTextField(option.getValue());
|
JFXTextField textField = new JFXTextField(option.getValue());
|
||||||
textField.setMaxWidth(Double.MAX_VALUE);
|
textField.setMaxWidth(Double.MAX_VALUE);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue