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.jfoenix.controls.JFXButton;
|
||||
import com.jfoenix.controls.JFXTextField;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
|
@ -29,33 +30,40 @@ public class BackgroundDialog extends StageDialog {
|
|||
super(controller, "/fxml/background_dialog.fxml");
|
||||
setTitle("Background Configuration");
|
||||
saveButton = createButton("Save");
|
||||
saveButton.setOnAction(event -> {
|
||||
controller.getNetworkGraph().setBackground(fileTextField.getText());
|
||||
close();
|
||||
});
|
||||
saveButton.setOnAction(this::saveAction);
|
||||
|
||||
clearButton = createButton("Clear");
|
||||
clearButton.setOnAction(event -> {
|
||||
controller.getNetworkGraph().removeBackground();
|
||||
close();
|
||||
});
|
||||
clearButton.setOnAction(this::clearAction);
|
||||
addCancelButton();
|
||||
|
||||
HBox parent = (HBox) imageView.getParent();
|
||||
imageView.fitHeightProperty().bind(parent.heightProperty());
|
||||
|
||||
fileButton.setOnAction(event -> {
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
fileChooser.setTitle("Select Background");
|
||||
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
|
||||
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("PNG", "*.png"));
|
||||
File file = fileChooser.showOpenDialog(getStage());
|
||||
if (file != null) {
|
||||
String uri = file.toURI().toString();
|
||||
imageView.setImage(new Image(uri));
|
||||
fileTextField.setText(file.getPath());
|
||||
saveButton.setDisable(false);
|
||||
}
|
||||
});
|
||||
fileButton.setOnAction(this::fileAction);
|
||||
}
|
||||
|
||||
private void fileAction(ActionEvent event) {
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
fileChooser.setTitle("Select Background");
|
||||
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
|
||||
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("PNG", "*.png"));
|
||||
File file = fileChooser.showOpenDialog(getStage());
|
||||
if (file != null) {
|
||||
String uri = file.toURI().toString();
|
||||
imageView.setImage(new Image(uri));
|
||||
fileTextField.setText(file.getPath());
|
||||
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() {
|
||||
|
|
|
@ -67,7 +67,7 @@ public class ConfigDialog extends StageDialog {
|
|||
tabPane.getTabs().add(tab);
|
||||
|
||||
for (ConfigOption option : group.getOptions()) {
|
||||
ConfigItem configItem = new ConfigItem(option);
|
||||
ConfigItem configItem = new ConfigItem(getStage(), option);
|
||||
gridPane.addRow(index, configItem.getLabel(), configItem.getNode());
|
||||
configItems.add(configItem);
|
||||
index += 1;
|
||||
|
|
|
@ -1,21 +1,31 @@
|
|||
package com.core.ui;
|
||||
|
||||
import com.core.data.ConfigDataType;
|
||||
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.JFXTextField;
|
||||
import com.jfoenix.controls.JFXToggleButton;
|
||||
import javafx.scene.Node;
|
||||
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 java.io.File;
|
||||
|
||||
@Data
|
||||
public class ConfigItem {
|
||||
private final Window window;
|
||||
private ConfigOption option;
|
||||
private Label label;
|
||||
private Node node;
|
||||
|
||||
public ConfigItem(ConfigOption option) {
|
||||
public ConfigItem(Stage window, ConfigOption option) {
|
||||
this.window = window;
|
||||
this.option = option;
|
||||
label = new Label(option.getLabel());
|
||||
createNode();
|
||||
|
@ -30,6 +40,8 @@ public class ConfigItem {
|
|||
default:
|
||||
if (!option.getSelect().isEmpty()) {
|
||||
node = optionsConfig();
|
||||
} else if (option.getLabel().contains("file")) {
|
||||
node = fileConfigItem();
|
||||
} else {
|
||||
node = defaultConfigItem();
|
||||
}
|
||||
|
@ -63,6 +75,33 @@ public class ConfigItem {
|
|||
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() {
|
||||
JFXTextField textField = new JFXTextField(option.getValue());
|
||||
textField.setMaxWidth(Double.MAX_VALUE);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue