use of javafx.scene.control.ChoiceBox in project selenium_java by sergueik.
the class ConfigFormEx method start.
@SuppressWarnings("restriction")
@Override
public void start(Stage primaryStage) {
Map<String, String> browserOptions = new HashMap<>();
for (String browser : new ArrayList<String>(Arrays.asList(new String[] { "Chrome", "Firefox", "Internet Explorer", "Edge", "Safari" }))) {
browserOptions.put(browser, "unused");
}
configOptions.put("Browser", browserOptions);
// offer templates embedded in the application jar and
// make rest up to customer
configData.put("Template", "Core Selenium Java (embedded)");
configOptions.put("Template", new HashMap<String, String>());
templates = configOptions.get("Template");
primaryStage.setTitle("Session Configuration");
BorderPane root = new BorderPane();
Scene scene = new Scene(root, 480, 250, Color.WHITE);
GridPane gridpane1 = new GridPane();
GridPane gridpane = new GridPane();
GridPane.setRowIndex(gridpane, 0);
GridPane.setColumnIndex(gridpane, 0);
HBox buttonbarHbox = new HBox(10);
buttonbarHbox.setPadding(new Insets(10));
// gridpane.setVgap(5);
GridPane.setRowIndex(buttonbarHbox, 1);
GridPane.setColumnIndex(buttonbarHbox, 0);
// Save button
Button saveButton = new Button("Save");
saveButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Saved");
Stage stage = (Stage) ((Button) (event.getSource())).getScene().getWindow();
stage.close();
}
});
saveButton.setDefaultButton(true);
// Cancel button
Button cancelButton = new Button("Cancel");
cancelButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Cancel");
Stage stage = (Stage) ((Button) (event.getSource())).getScene().getWindow();
stage.close();
}
});
buttonbarHbox.getChildren().addAll(saveButton, cancelButton);
gridpane1.getChildren().addAll(gridpane, buttonbarHbox);
// origin:
gridpane.setPadding(new Insets(5));
gridpane.setHgap(5);
gridpane.setVgap(5);
// https://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html
gridpane.setStyle("-fx-padding: 10; -fx-border-style: solid inside; -fx-border-width: 2; -fx-border-insets: 5; -fx-border-radius: 0; -fx-border-color: darkgray;");
// origin:
// http://www.java2s.com/Tutorials/Java/JavaFX/0340__JavaFX_GridPane.htm
// https://docs.oracle.com/javase/8/javafx/api/javafx/scene/layout/GridPane.html
ColumnConstraints column1 = new ColumnConstraints(150);
ColumnConstraints column2 = new ColumnConstraints(50, 300, 450);
column2.setHgrow(Priority.ALWAYS);
gridpane.getColumnConstraints().addAll(column1, column2);
// First name label
Label baseURLLbl = new Label("Base URL");
GridPane.setHalignment(baseURLLbl, HPos.RIGHT);
// Set one constraint at a time...
// Places the label at the first row and first column
GridPane.setRowIndex(baseURLLbl, 0);
GridPane.setColumnIndex(baseURLLbl, 0);
// Last name label
Label templateDirLabel = new Label("Template directory");
GridPane.setHalignment(templateDirLabel, HPos.RIGHT);
// Set column and row constraint at once...
// Places the label at the third row and first column
gridpane.add(templateDirLabel, 0, 2);
gridpane.getChildren().addAll(baseURLLbl);
// base URL field
TextField baseURLFld = new TextField();
GridPane.setHalignment(baseURLFld, HPos.LEFT);
gridpane.add(baseURLFld, 1, 0);
// tempalteDir field
TextField tempalteDirFld = new TextField();
GridPane.setHalignment(tempalteDirFld, HPos.LEFT);
tempalteDirFld.setMaxWidth(Double.MAX_VALUE);
Button browseButton = new Button("Browse");
GridPane.setHalignment(browseButton, HPos.RIGHT);
browseButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Browse");
}
});
HBox browseButtonbarHbox = new HBox(10);
browseButtonbarHbox.setPadding(new Insets(10));
browseButtonbarHbox.getChildren().addAll(tempalteDirFld, browseButton);
gridpane.add(browseButtonbarHbox, 1, 2);
browseButtonbarHbox.setMaxWidth(Double.MAX_VALUE);
final String[] browsers = new String[] { "Chrome", "Firefox", "Edge", "Internet Explorer" };
ChoiceBox browserChoice = new ChoiceBox();
browserChoice.setItems(FXCollections.observableArrayList(Arrays.asList(browsers)));
browserChoice.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
public void changed(ObservableValue ov, Number index, Number new_index) {
System.err.println("Browser: " + browsers[new_index.intValue()]);
}
});
browserChoice.getSelectionModel().select(0);
browserChoice.setMaxWidth(Double.MAX_VALUE);
gridpane.add(browserChoice, 1, 1);
Label browserLabel = new Label("Browser");
GridPane.setHalignment(browserLabel, HPos.RIGHT);
gridpane.add(browserLabel, 0, 1);
final String[] templates = new String[] { "mockup 1", "mockup 2", "mockup 3" };
ComboBox templateChoice = new ComboBox();
templateChoice.getItems().addAll(Arrays.asList(templates));
templateChoice.setPromptText("template");
templateChoice.setEditable(true);
templateChoice.setOnAction(e -> {
String dummy = templateChoice.getSelectionModel().getSelectedItem().toString();
});
GridPane.setHalignment(templateChoice, HPos.RIGHT);
templateChoice.setValue("mockup 1");
templateChoice.setEditable(true);
templateChoice.getEditor().setEditable(false);
templateChoice.setStyle("-fx-background-color: gray");
templateChoice.setMaxWidth(Double.MAX_VALUE);
// setHgrow(Priority.ALWAYS);
gridpane.add(templateChoice, 1, 3);
Label templateLabel = new Label("Template");
GridPane.setHalignment(templateLabel, HPos.RIGHT);
gridpane.add(templateLabel, 0, 3);
root.setCenter(gridpane1);
primaryStage.setScene(scene);
primaryStage.show();
for (String configKey : Arrays.asList("Browser", "Base URL", "Template Directory", "Template")) {
if (configOptions.containsKey(configKey)) {
} else {
}
}
}
use of javafx.scene.control.ChoiceBox in project FXGL by AlmasB.
the class DialogsSample method initUI.
@Override
protected void initUI() {
Map<String, Runnable> dialogs = new LinkedHashMap<>();
dialogs.put("Message", () -> getDisplay().showMessageBox("This is a simple message box"));
dialogs.put("Error", () -> getDisplay().showErrorBox("This is a scary error box!", () -> {
}));
dialogs.put("Confirmation", () -> getDisplay().showConfirmationBox("This is a confirmation box. Agree?", answer -> System.out.println("You pressed yes? " + answer)));
dialogs.put("Input", () -> getDisplay().showInputBox("This is an input box. You can type stuff...", answer -> System.out.println("You typed: " + answer)));
dialogs.put("Custom", () -> {
VBox content = new VBox(getUIFactory().newText("Line 1"), getUIFactory().newText("Line 2"), getAssetLoader().loadTexture("brick.png"), getUIFactory().newText("Line 3"), getUIFactory().newText("Line 4"));
Button btnClose = getUIFactory().newButton("Press me to close");
btnClose.setPrefWidth(300);
getDisplay().showBox("This is a customizable box", content, btnClose);
});
ChoiceBox<String> cbDialogs = getUIFactory().newChoiceBox(FXCollections.observableArrayList(dialogs.keySet()));
cbDialogs.getSelectionModel().selectFirst();
Button btn = getUIFactory().newButton("Open");
btn.setOnAction(e -> {
String dialogType = cbDialogs.getSelectionModel().getSelectedItem();
if (dialogs.containsKey(dialogType)) {
dialogs.get(dialogType).run();
} else {
System.out.println("Unknown dialog type");
}
});
VBox vbox = new VBox(10);
vbox.setTranslateX(600);
vbox.getChildren().addAll(new Text("Dialog Types"), cbDialogs, btn);
getGameScene().addUINode(vbox);
}
use of javafx.scene.control.ChoiceBox in project DistributedFractalNetwork by Budder21.
the class GradientMenus method displayLayerMenu.
/**
* Used to display the opacity editor that controls the opacity of a whole layer.
* @param t the tree item that connects to a layer whose opacity is being modified
* @return a new metalayer containing the layer's metadata
*/
public static MetaLayer displayLayerMenu(TreeItem<MetaLayer> t) {
Stage window = new Stage();
Slider opacityLevel = new Slider(0, 1, (Double) t.getValue().getOpacity());
Label opacityCaption = new Label("Opacity Level:");
Label opacityValue = new Label(Double.toString(opacityLevel.getValue()));
opacityValue.setText(String.format("%.2f", opacityLevel.getValue()));
opacityLevel.valueProperty().addListener(new ChangeListener<Number>() {
public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) {
DecimalFormat df = new DecimalFormat("0.00");
opacityValue.setText((df.format(opacityLevel.getValue())));
}
});
// Block events to other windows
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle("Edit Layer");
window.setMinWidth(250);
window.setMinHeight(210);
VBox layout = new VBox(10);
Label name = new Label();
name.setText("Enter Name of Layer:");
TextField nameIn = new TextField();
nameIn.setPromptText("Layer Name");
nameIn.minWidthProperty().bind(window.minWidthProperty().divide(2));
nameIn.maxWidthProperty().bind(window.minWidthProperty().multiply(.75));
Label type = new Label();
type.setText("Select a Layer Type:");
ChoiceBox typeIn = new ChoiceBox();
typeIn.getItems().addAll(Layer.getLayerTypes());
typeIn.minWidthProperty().bind(window.minWidthProperty().divide(2));
typeIn.maxWidthProperty().bind(window.minWidthProperty().multiply(.75));
typeIn.getSelectionModel().selectFirst();
HBox hbox = new HBox();
Button closeButton = new Button("Submit");
closeButton.setOnAction(e -> window.close());
CheckBox delete = new CheckBox("Delete");
Canvas spacer = new Canvas();
spacer.setWidth(30);
Canvas push = new Canvas();
push.setWidth(50);
hbox.getChildren().addAll(push, closeButton, spacer, delete);
HBox opacityBox = new HBox();
opacityBox.maxWidthProperty().bind(window.minWidthProperty().multiply(.75));
opacityLevel.maxWidthProperty().bind(window.minWidthProperty().multiply(.75));
Canvas opacitySpacer = new Canvas();
opacitySpacer.setWidth(10);
opacityBox.getChildren().addAll(opacityCaption, opacitySpacer, opacityValue);
Canvas vspace = new Canvas();
vspace.setHeight(10);
layout.getChildren().addAll(name, nameIn, type, typeIn, opacityBox, opacityLevel, hbox, vspace);
layout.setAlignment(Pos.CENTER);
if (((MetaLayer) t.getValue()).getName() != null)
nameIn.setText(((MetaLayer) t.getValue()).getName());
if (((MetaLayer) t.getValue()).getType() != null) {
typeIn.getSelectionModel().select(((MetaLayer) t.getValue()).getType());
}
// Display window and wait for it to be closed before returning
Scene scene = new Scene(layout);
window.setScene(scene);
window.showAndWait();
if (delete.isSelected())
return new MetaLayer(nameIn.getText(), typeIn.getSelectionModel().getSelectedItem().toString(), opacityLevel.getValue(), true);
return new MetaLayer(nameIn.getText(), typeIn.getSelectionModel().getSelectedItem().toString(), opacityLevel.getValue());
}
use of javafx.scene.control.ChoiceBox in project DistributedFractalNetwork by Budder21.
the class LayerBox method display.
public static MetaLayer display(TreeItem<MetaLayer> t) {
Stage window = new Stage();
//Block events to other windows
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle("Edit Layer");
window.setMinWidth(250);
window.setMinHeight(200);
VBox layout = new VBox(10);
Label name = new Label();
name.setText("Enter Name of Layer:");
TextField nameIn = new TextField();
nameIn.setPromptText("Layer Name");
nameIn.minWidthProperty().bind(window.minWidthProperty().divide(2));
nameIn.maxWidthProperty().bind(window.minWidthProperty().multiply(.75));
Label type = new Label();
type.setText("Select a Layer Type:");
ChoiceBox typeIn = new ChoiceBox();
typeIn.getItems().addAll(Layer.getLayerTypes());
typeIn.minWidthProperty().bind(window.minWidthProperty().divide(2));
typeIn.maxWidthProperty().bind(window.minWidthProperty().multiply(.75));
typeIn.getSelectionModel().selectFirst();
HBox hbox = new HBox();
Button closeButton = new Button("Submit");
closeButton.setOnAction(e -> window.close());
CheckBox delete = new CheckBox("Delete");
Canvas spacer = new Canvas();
spacer.setWidth(30);
Canvas push = new Canvas();
push.setWidth(50);
hbox.getChildren().addAll(push, closeButton, spacer, delete);
layout.getChildren().addAll(name, nameIn, type, typeIn, hbox);
layout.setAlignment(Pos.CENTER);
if (((MetaLayer) t.getValue()).getName() != null)
nameIn.setText(((MetaLayer) t.getValue()).getName());
if (((MetaLayer) t.getValue()).getType() != null) {
typeIn.getSelectionModel().select(((MetaLayer) t.getValue()).getType());
}
//Display window and wait for it to be closed before returning
Scene scene = new Scene(layout);
window.setScene(scene);
window.showAndWait();
if (delete.isSelected())
return new MetaLayer("DELETE", "DELETE", true);
return new MetaLayer(nameIn.getText(), typeIn.getSelectionModel().getSelectedItem().toString());
}
use of javafx.scene.control.ChoiceBox in project ParadoxosModManager by ThibautSF.
the class ModManager method initApp.
/**
* @param docUserPath
* @param exeUserPath
* @return
*/
private boolean initApp(String docUserPath, String exeUserPath) {
Dialog<List<String>> dialog = new Dialog<>();
dialog.setTitle(APP_NAME);
dialog.setHeaderText("Choose a game");
// Set the button types.
ButtonType okButtonType = new ButtonType("OK", ButtonData.OK_DONE);
dialog.getDialogPane().getButtonTypes().addAll(okButtonType, ButtonType.CANCEL);
GridPane grid = new GridPane();
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(20, 10, 10, 10));
// grid.setGridLinesVisible(true);
ChoiceBox<String> choiceGame = new ChoiceBox<String>(SUPPORTED_GAMES);
TextField docPath = new TextField();
docPath.setMinWidth(500);
DirectoryChooser dirDocChooser = new DirectoryChooser();
Button openDirDocButton = new Button("...");
TextField gamePath = new TextField();
docPath.setMinWidth(500);
// FileChooser exeGameChooser = new FileChooser();
// Button openExeGameButton = new Button("...");
choiceGame.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
String newGame = SUPPORTED_GAMES.get((int) newValue);
Integer newSteamID = GAMES_STEAM_ID.get((int) newValue);
String docPathParam = null;
try {
// ModManager.APP_PARAMS = settingsXML.getGameSettings(newSteamID);
docPathParam = settingsXML.getOneGameSetting(newSteamID, "docfolderpath");
} catch (DataConversionException e) {
ErrorPrint.printError(e, "Error reading the saved params for gameID : '" + newSteamID + "'");
e.printStackTrace();
}
String newPath;
// String docPathParam = ModManager.APP_PARAMS.get("docfolderpath");
if (docPathParam != null) {
newPath = docPathParam;
} else {
newPath = generatePath(newGame);
}
docPath.setText(newPath);
gamePath.setText("Steam launch | steam://run/" + newSteamID);
dirDocChooser.setTitle("Choose document path for " + newGame);
File f = new File(newPath);
if (f.isDirectory())
dirDocChooser.setInitialDirectory(f);
else
dirDocChooser.setInitialDirectory(new File(File.separator));
// exeGameChooser.setTitle("Choose exe path for "+newGame);
// exeGameChooser.setInitialDirectory(new File(File.separator));
// "steam://run/"+ModManager.STEAM_ID
}
});
openDirDocButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(final ActionEvent e) {
File file = dirDocChooser.showDialog(dialog.getOwner());
if (file != null && file.isDirectory()) {
// System.out.println(file.toString());
String newPath = file.getAbsolutePath() + File.separator;
dirDocChooser.setInitialDirectory(new File(newPath));
docPath.setText(newPath);
}
}
});
/*
openExeGameButton.setOnAction(
new EventHandler<ActionEvent>() {
@Override
public void handle(final ActionEvent e) {
File file = exeGameChooser.showOpenDialog(dialog.getOwner());
if (file!=null && !file.isDirectory()){
//System.out.println(file.toString());
String newPath = file.getAbsolutePath()+File.separator;
exeGameChooser.setInitialDirectory(new File(newPath));
gamePath.setText(newPath);
}
}
}
);
*/
Label lbl = new Label("--- Change if different from default ---");
lbl.setMaxWidth(Double.MAX_VALUE);
lbl.setAlignment(Pos.CENTER);
// Choice Game
grid.add(new Label("Game :"), 0, 0);
grid.add(choiceGame, 1, 0);
// Detect conflicts option
CheckBox cbConflict = new CheckBox("Active conflict detection (longer loading)");
if (APP_PARAMS.containsKey("DetectConflict")) {
if (APP_PARAMS.get("DetectConflict").equals("true"))
cbConflict.setSelected(true);
}
grid.add(cbConflict, 0, 1, 2, 1);
// Label game config
grid.add(lbl, 0, 2, 3, 1);
// Game configs
grid.add(new Label("Doc path :"), 0, 3);
grid.add(docPath, 1, 3);
grid.add(openDirDocButton, 2, 3);
/*
grid.add(new Label("Game (exe) path :"), 0, 4);
grid.add(gamePath, 1, 4);
grid.add(openExeGameButton, 2, 4);
*/
dialog.getDialogPane().setContent(grid);
choiceGame.getSelectionModel().selectFirst();
if (docUserPath != null) {
// System.out.println(userPath);
docPath.setText(docUserPath);
File f = new File(docUserPath);
if (f.isDirectory())
dirDocChooser.setInitialDirectory(f);
else
dirDocChooser.setInitialDirectory(new File(File.separator));
}
Platform.runLater(() -> choiceGame.requestFocus());
dialog.setResultConverter(dialogButton -> {
if (dialogButton == okButtonType) {
return Arrays.asList(choiceGame.getSelectionModel().getSelectedItem(), docPath.getText(), gamePath.getText(), "" + cbConflict.isSelected());
}
return null;
});
Optional<List<String>> result = dialog.showAndWait();
if (result.isPresent()) {
List<String> result_list = result.get();
GAME = result_list.get(0);
STEAM_ID = GAMES_STEAM_ID.get(SUPPORTED_GAMES.indexOf(GAME));
String docPathStr = result_list.get(1);
String exePathStr = result_list.get(2);
String detectConflict = result_list.get(3);
APP_PARAMS.put("DetectConflict", detectConflict);
// In case the user write wrong separator
docPathStr = docPathStr.replaceAll("(\\\\+|/+)", Matcher.quoteReplacement(File.separator));
if (!(docPathStr.lastIndexOf(File.separator) == docPathStr.length() - 1))
docPathStr += File.separator;
if (checkPath(docPathStr)) {
PATH = docPathStr;
return true;
} else {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Error Dialog");
alert.setHeaderText(null);
alert.setContentText("The document path is not correct !");
alert.showAndWait();
return initApp(docPathStr, exePathStr);
}
}
return false;
}
Aggregations