javafx.scene.control.ChoiceDialog Java Examples
The following examples show how to use
javafx.scene.control.ChoiceDialog.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TraceAUtilityNetworkController.java From arcgis-runtime-samples-java with Apache License 2.0 | 6 votes |
/** * Prompts the user to select a terminal from a provided list. * * @param terminals a list of terminals for the user to choose from * @return the user's selected terminal */ private Optional<UtilityTerminal> promptForTerminalSelection(List<UtilityTerminal> terminals) { // create a dialog for terminal selection ChoiceDialog<UtilityTerminal> utilityTerminalSelectionDialog = new ChoiceDialog<>(terminals.get(0), terminals); utilityTerminalSelectionDialog.initOwner(mapView.getScene().getWindow()); utilityTerminalSelectionDialog.setTitle("Choose Utility Terminal"); utilityTerminalSelectionDialog.setHeaderText("Junction selected. Choose the Utility Terminal to add as the trace element:"); // override the list cell in the dialog's combo box to show the terminal name @SuppressWarnings("unchecked") ComboBox<UtilityTerminal> comboBox = (ComboBox<UtilityTerminal>) ((GridPane) utilityTerminalSelectionDialog.getDialogPane() .getContent()).getChildren().get(1); comboBox.setCellFactory(param -> new UtilityTerminalListCell()); comboBox.setButtonCell(new UtilityTerminalListCell()); // show the terminal selection dialog and capture the user selection return utilityTerminalSelectionDialog.showAndWait(); }
Example #2
Source File: JFXRepresentation.java From phoebus with Eclipse Public License 1.0 | 5 votes |
@Override public String showSelectionDialog(final Widget widget, final String title, final List<String> options) { final Node node = JFXBaseRepresentation.getJFXNode(widget); final CompletableFuture<String> done = new CompletableFuture<>(); execute( ()-> { final ChoiceDialog<String> dialog = new ChoiceDialog<>(null, options); DialogHelper.positionDialog(dialog, node, -100, -50); dialog.setHeaderText(title); final int lines = title.split("\n").length; dialog.setResizable(true); dialog.getDialogPane().setPrefHeight(50+25*lines); dialog.initOwner(node.getScene().getWindow()); final Optional<String> result = dialog.showAndWait(); done.complete(result.orElse(null)); }); try { return done.get(); } catch (Exception ex) { logger.log(Level.WARNING, "Selection dialog ('" + title + ", ..') failed", ex); } return null; }
Example #3
Source File: GroupSamplesByCommand.java From megan-ce with GNU General Public License v3.0 | 5 votes |
public void actionPerformed(ActionEvent event) { final Document doc = ((Director) getDir()).getDocument(); final java.util.List<String> attributes = doc.getSampleAttributeTable().getUnhiddenAttributes(); if (attributes.size() > 0) { final JFrame frame = getViewer().getFrame(); Platform.runLater(() -> { String defaultChoice = ProgramProperties.get("SetByAttribute", ""); if (!attributes.contains(defaultChoice)) defaultChoice = attributes.get(0); ChoiceDialog<String> dialog = new ChoiceDialog<>(defaultChoice, attributes); dialog.setTitle("MEGAN6 " + getViewer().getClassName() + " choice"); dialog.setHeaderText("Select attribute to group by"); dialog.setContentText("Choose attribute:"); if (frame != null) { dialog.setX(frame.getX() + (frame.getWidth() - 200) / 2); dialog.setY(frame.getY() + (frame.getHeight() - 200) / 2); } final Optional<String> result = dialog.showAndWait(); if (result.isPresent()) { final String choice = result.get(); SwingUtilities.invokeLater(() -> execute("groupBy attribute='" + choice + "';show window=groups;")); } }); } }
Example #4
Source File: ColorSamplesByCommand.java From megan-ce with GNU General Public License v3.0 | 5 votes |
public void actionPerformed(ActionEvent event) { final Document doc = ((Director) getDir()).getDocument(); final java.util.List<String> attributes = doc.getSampleAttributeTable().getUnhiddenAttributes(); if (attributes.size() > 0) { final JFrame frame = getViewer().getFrame(); Platform.runLater(() -> { String defaultChoice = ProgramProperties.get("SetByAttribute", ""); if (!attributes.contains(defaultChoice)) defaultChoice = attributes.get(0); final ChoiceDialog<String> dialog = new ChoiceDialog<>(defaultChoice, attributes); dialog.setTitle("MEGAN6 " + getViewer().getClassName() + " choice"); dialog.setHeaderText("Select attribute to color by"); dialog.setContentText("Choose attribute:"); if (frame != null) { dialog.setX(frame.getX() + (frame.getWidth() - 200) / 2); dialog.setY(frame.getY() + (frame.getHeight() - 200) / 2); } final Optional<String> result = dialog.showAndWait(); if (result.isPresent()) { final String choice = result.get(); SwingUtilities.invokeLater(() -> execute("colorBy attribute='" + choice + "';")); } }); } }
Example #5
Source File: ShapeSamplesByCommand.java From megan-ce with GNU General Public License v3.0 | 5 votes |
public void actionPerformed(ActionEvent event) { final Document doc = ((Director) getDir()).getDocument(); final java.util.List<String> attributes = doc.getSampleAttributeTable().getUnhiddenAttributes(); if (attributes.size() > 0) { final JFrame frame = getViewer().getFrame(); Platform.runLater(() -> { String defaultChoice = ProgramProperties.get("SetByAttribute", ""); if (!attributes.contains(defaultChoice)) defaultChoice = attributes.get(0); ChoiceDialog<String> dialog = new ChoiceDialog<>(defaultChoice, attributes); dialog.setTitle("MEGAN6 " + getViewer().getClassName() + " choice"); dialog.setHeaderText("Select attribute to shape by"); dialog.setContentText("Choose attribute:"); if (frame != null) { dialog.setX(frame.getX() + (frame.getWidth() - 200) / 2); dialog.setY(frame.getY() + (frame.getHeight() - 200) / 2); } final Optional<String> result = dialog.showAndWait(); if (result.isPresent()) { final String choice = result.get(); SwingUtilities.invokeLater(() -> execute("shapeBy attribute='" + choice + "';")); } }); } }
Example #6
Source File: LabelSamplesByCommand.java From megan-ce with GNU General Public License v3.0 | 5 votes |
public void actionPerformed(ActionEvent event) { final Document doc = ((Director) getDir()).getDocument(); final java.util.List<String> attributes = doc.getSampleAttributeTable().getUnhiddenAttributes(); if (attributes.size() > 0) { final JFrame frame = getViewer().getFrame(); Platform.runLater(() -> { String defaultChoice = ProgramProperties.get("SetByAttribute", ""); if (!attributes.contains(defaultChoice)) defaultChoice = attributes.get(0); ChoiceDialog<String> dialog = new ChoiceDialog<>(defaultChoice, attributes); dialog.setTitle("MEGAN6 " + getViewer().getClassName() + " choice"); dialog.setHeaderText("Select attribute to label by"); dialog.setContentText("Choose attribute:"); if (frame != null) { dialog.setX(frame.getX() + (frame.getWidth() - 200) / 2); dialog.setY(frame.getY() + (frame.getHeight() - 200) / 2); } final Optional<String> result = dialog.showAndWait(); if (result.isPresent()) { final String choice = result.get(); SwingUtilities.invokeLater(() -> execute("labelBy attribute='" + choice + "';")); } }); } }
Example #7
Source File: PasteByAttributeCommand.java From megan-ce with GNU General Public License v3.0 | 5 votes |
public void actionPerformed(ActionEvent event) { Platform.runLater(() -> { SamplesViewer samplesViewer = (SamplesViewer) getViewer(); final java.util.List<String> list = getDoc().getSampleAttributeTable().getUnhiddenAttributes(); if (list.size() > 0) { String choice = ProgramProperties.get("PasteByAttribute", list.get(0)); if (!list.contains(choice)) choice = list.get(0); final ChoiceDialog<String> dialog = new ChoiceDialog<>(choice, list); dialog.setTitle("Paste By Attribute"); dialog.setHeaderText("Select an attribute to guide paste"); Optional<String> result = dialog.showAndWait(); if (result.isPresent()) { final String selected = result.get(); try { ProgramProperties.put("PasteByAttribute", selected); samplesViewer.getSamplesTableView().pasteClipboardByAttribute(selected); samplesViewer.getSamplesTableView().syncFromViewToDocument(); samplesViewer.getCommandManager().updateEnableStateFXItems(); if (!samplesViewer.getDocument().isDirty() && samplesViewer.getSamplesTableView().isDirty()) { samplesViewer.getDocument().setDirty(true); samplesViewer.setWindowTitle(); } } catch (IOException e) { Basic.caught(e); } } } }); }
Example #8
Source File: SetSampleShapeCommand.java From megan-ce with GNU General Public License v3.0 | 5 votes |
/** * action to be performed * * @param ev */ public void actionPerformed(ActionEvent ev) { final SamplesViewer viewer = (SamplesViewer) getViewer(); final Collection<String> selected = viewer.getSamplesTableView().getSelectedSamples(); if (selected.size() > 0) { String sample = selected.iterator().next(); String shapeLabel = viewer.getSampleAttributeTable().getSampleShape(sample); NodeShape nodeShape = NodeShape.valueOfIgnoreCase(shapeLabel); if (nodeShape == null) nodeShape = NodeShape.Oval; final NodeShape nodeShape1 = nodeShape; Runnable runnable = () -> { final ChoiceDialog<NodeShape> dialog = new ChoiceDialog<>(nodeShape1, NodeShape.values()); dialog.setTitle("MEGAN choice"); dialog.setHeaderText("Choose shape to represent sample(s)"); dialog.setContentText("Shape:"); final Optional<NodeShape> result = dialog.showAndWait(); result.ifPresent(shape -> execute("set nodeShape=" + shape + " sample='" + Basic.toString(selected, "' '") + "';")); }; if (Platform.isFxApplicationThread()) runnable.run(); else Platform.runLater(runnable); } }
Example #9
Source File: AddressDialog.java From chat-socket with MIT License | 5 votes |
public void show() { List<String> addresses = NetworkUtils.getAllAddresses(); if (!addresses.isEmpty()) { ChoiceDialog<String> choiceDialog = new ChoiceDialog<>(addresses.get(0), addresses); choiceDialog.setTitle(AppConfig.getDefault().getAppName()); choiceDialog.setHeaderText("Available Addresses"); Optional<String> result = choiceDialog.showAndWait(); if (onSelectedAddress != null && result.isPresent()) onSelectedAddress.call(result.get()); choiceDialog.close(); } }
Example #10
Source File: MarsNode.java From mars-sim with GNU General Public License v3.0 | 5 votes |
public Button createGreenhouseDialog(Farming farm) { String name = farm.getBuilding().getNickName(); Button b = new Button(name); b.setMaxWidth(Double.MAX_VALUE); List<String> choices = new ArrayList<>(); choices.add("Lettuce"); choices.add("Green Peas"); choices.add("Carrot"); ChoiceDialog<String> dialog = new ChoiceDialog<>("List of Crops", choices); dialog.setTitle(name); dialog.setHeaderText("Plant a Crop"); dialog.setContentText("Choose Your Crop:"); dialog.initOwner(stage); // post the same icon from stage dialog.initStyle(StageStyle.UTILITY); //dialog.initModality(Modality.NONE); b.setPadding(new Insets(20)); b.setId("settlement-node"); b.getStylesheets().add("/fxui/css/settlementnode.css"); b.setOnAction(e->{ // The Java 8 way to get the response value (with lambda expression). Optional<String> selected = dialog.showAndWait(); selected.ifPresent(crop -> System.out.println("Crop added to the queue: " + crop)); }); //ButtonType buttonTypeCancel = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE); //ButtonType buttonTypeOk = new ButtonType("OK", ButtonData.OK_DONE); //dialog.getButtonTypes().setAll(buttonTypeCancel, buttonTypeOk); return b; }
Example #11
Source File: BatchSetupComponent.java From mzmine3 with GNU General Public License v2.0 | 4 votes |
/** * Load a batch queue from a file. * * @param file the file to read. * @throws ParserConfigurationException if there is a parser problem. * @throws SAXException if there is a SAX problem. * @throws IOException if there is an i/o problem. */ public void loadBatchSteps(final File file) throws ParserConfigurationException, IOException, SAXException { final BatchQueue queue = BatchQueue.loadFromXml( DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file).getDocumentElement()); logger.info("Loaded " + queue.size() + " batch step(s) from " + file.getName()); // Append, prepend, insert or replace. List<QueueOperations> operations = List.of(QueueOperations.values()); ChoiceDialog<QueueOperations> choiceDialog = new ChoiceDialog<>(QueueOperations.Replace, operations); choiceDialog.setTitle("Add Batch Steps"); choiceDialog.setContentText("How should the loaded batch steps be added to the queue?"); choiceDialog.showAndWait(); QueueOperations option = choiceDialog.getResult(); if (option == null) return; int index = currentStepsList.getSelectionModel().getSelectedIndex(); switch (option) { case Replace: index = 0; batchQueue.clear(); batchQueue.addAll(queue); break; case Prepend: index = 0; batchQueue.addAll(0, queue); break; case Insert: index = index < 0 ? 0 : index; batchQueue.addAll(index, queue); break; case Append: index = batchQueue.size(); batchQueue.addAll(queue); break; } selectStep(index); // add to last used files addLastUsedFile(file); }
Example #12
Source File: PromptForGit.java From BowlerStudio with GNU General Public License v3.0 | 4 votes |
public static void prompt(String purpose, String defaultID, IGistPromptCompletionListener listener){ Platform.runLater(() -> { TextInputDialog dialog = new TextInputDialog(defaultID); dialog.setTitle(purpose); dialog.setHeaderText("Enter the URL (Clone vie HTTPS)"); dialog.setContentText("Git Clone URL: "); dialog.setResizable(true); dialog.setWidth(800); // Traditional way to get the response value. Optional<String> result = dialog.showAndWait(); if (result.isPresent()){ String gistcode=null; if(result.get().endsWith(".git")) gistcode=result.get(); else gistcode= "https://gist.github.com/"+ScriptingEngine.urlToGist(result.get())+".git"; System.out.println("Creature Git " + gistcode); ArrayList<String> choices; String suggestedChoice=""; int numXml=0; try { choices = ScriptingEngine.filesInGit(gistcode); for(int i=0;i<choices.size();i++){ String s = choices.get(i); suggestedChoice=s; numXml++; } ChoiceDialog<String> d = new ChoiceDialog<>(suggestedChoice, choices); d.setTitle("Choose a file in the git"); d.setHeaderText("Select from the files in the git to pick the Creature File"); d.setContentText("Choose A Creature:"); // Traditional way to get the response value. Optional<String> r = d.showAndWait(); if (r.isPresent()){ System.out.println("Your choice: " + r.get()); listener.done(gistcode,r.get()); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } if(numXml ==1){ //System.out.println("Found just one file at " + suggestedChoice); //loadMobilebaseFromGist(gistcode,suggestedChoice); //return; } } }); }
Example #13
Source File: MultiplayerMode.java From mars-sim with GNU General Public License v3.0 | 4 votes |
public ChoiceDialog<String> getChoiceDialog() { return dialog; }
Example #14
Source File: Dialogs.java From CPUSim with GNU General Public License v3.0 | 3 votes |
/** * Creates choice dialog for saving, closing, new actions. * * @param window owning window or null if there is none * @param header head text of the confirmation dialog * @param content content of the confirmation dialog * @return an dialog object */ public static ChoiceDialog<String> createChoiceDialog(Window window, String header, String content, String initC, List<String> choices) { ChoiceDialog<String> dialog = new ChoiceDialog<>(initC, choices); initializeDialog(dialog, window, header, content); return dialog; }