java类javafx.scene.control.Dialog的实例源码

MainWindowController.java 文件源码 项目:GRIP 阅读 31 收藏 0 点赞 0 评论 0
/**
 * If there are any steps in the pipeline, give the user a chance to cancel an action or save the
 * current project.
 *
 * @return true If the user has not chosen to
 */
private boolean showConfirmationDialogAndWait() {
  if (!pipeline.getSteps().isEmpty() && project.isSaveDirty()) {
    final ButtonType save = new ButtonType("Save");
    final ButtonType dontSave = ButtonType.NO;
    final ButtonType cancel = ButtonType.CANCEL;

    final Dialog<ButtonType> dialog = new Dialog<>();
    dialog.getDialogPane().getStylesheets().addAll(root.getStylesheets());
    dialog.getDialogPane().setStyle(root.getStyle());
    dialog.setTitle("Save Project?");
    dialog.setHeaderText("Save the current project first?");
    dialog.getDialogPane().getButtonTypes().setAll(save, dontSave, cancel);

    if (!dialog.showAndWait().isPresent()) {
      return false;
    } else if (dialog.getResult().equals(cancel)) {
      return false;
    } else if (dialog.getResult().equals(save)) {
      // If the user chose "Save", automatically show a save dialog and block until the user
      // has had a chance to save the project.
      return saveProject();
    }
  }
  return true;
}
MainWindowController.java 文件源码 项目:GRIP 阅读 32 收藏 0 点赞 0 评论 0
@FXML
protected void deploy() {
  eventBus.post(new WarningEvent(
      "Deploy has been deprecated",
      "The deploy tool has been deprecated and is no longer supported. "
          + "It will be removed in a future release.\n\n"
          + "Instead, use code generation to create a Java, C++, or Python class that handles all"
          + " the OpenCV code and can be easily integrated into a WPILib robot program."));

  ImageView graphic = new ImageView(new Image("/edu/wpi/grip/ui/icons/settings.png"));
  graphic.setFitWidth(DPIUtility.SMALL_ICON_SIZE);
  graphic.setFitHeight(DPIUtility.SMALL_ICON_SIZE);

  deployPane.requestFocus();

  Dialog<ButtonType> dialog = new Dialog<>();
  dialog.setTitle("Deploy");
  dialog.setHeaderText("Deploy");
  dialog.setGraphic(graphic);
  dialog.getDialogPane().getButtonTypes().setAll(ButtonType.CLOSE);
  dialog.getDialogPane().styleProperty().bind(root.styleProperty());
  dialog.getDialogPane().getStylesheets().setAll(root.getStylesheets());
  dialog.getDialogPane().setContent(deployPane);
  dialog.setResizable(true);
  dialog.showAndWait();
}
DialogBuilder.java 文件源码 项目:dwoss 阅读 41 收藏 0 点赞 0 评论 0
/**
 * Creates the javafx Dialog via the producer, supplies the consumer part with the result of the preProducer, shows it and returns the evaluated result as
 * Optional.
 *
 * @param <T>            type of the result
 * @param <P>            result type of the preProducer
 * @param <V>
 * @param preProducer    the preproducer, must not be null
 * @param dialogProducer the javafx Dialog producer, must not be null and must not return null.
 * @return the result of the evaluation, never null.
 */
public <T, P, V extends Dialog<T> & Consumer<P>> Optional<T> eval(Callable<P> preProducer, Callable<V> dialogProducer) {
    try {
        Objects.requireNonNull(dialogProducer, "The dialogProducer is null, not allowed");

        V dialog = FxSaft.dispatch(dialogProducer);
        Params p = buildParameterBackedUpByDefaults(dialog.getClass());
        P preResult = callWithProgress(preProducer);
        p.optionalSupplyId(preResult);
        if ( isOnceModeAndActiveWithSideeffect(p.key()) ) return Optional.empty();
        dialog.accept(preResult); // Calling the preproducer and setting the result in the panel
        dialog.getDialogPane().getScene().setRoot(new BorderPane()); // Remove the DialogPane form the Scene, otherwise an Exception is thrown
        Window window = constructAndShow(SwingCore.wrap(dialog.getDialogPane()), p, Dialog.class); // Constructing the JFrame/JDialog, setting the parameters and makeing it visible
        dialog.getDialogPane().getButtonTypes().stream().map(t -> dialog.getDialogPane().lookupButton(t)).forEach(b -> { // Add Closing behavior on all buttons.
            ((Button)b).setOnAction(e -> {
                L.debug("Close on Dialog called");
                Ui.closeWindowOf(window);
            });
        });
        wait(window);
        return Optional.ofNullable(dialog.getResult());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Interactions.java 文件源码 项目:systemdesign 阅读 26 收藏 0 点赞 0 评论 0
@Override
public Optional<Color> colorInput(String action, String question, Color _default) {
    Dialog<Color> dialog = new Dialog<>();
    dialog.setTitle(action);
    dialog.setHeaderText(question);
    ColorPicker picker = new ColorPicker(_default);
    Button randomiser = new Button("Mix");
    randomiser.setOnAction(e -> {
        Color current = picker.getValue();
        Color shifted = Item.shiftColor(current);
        picker.setValue(shifted);
    });
    HBox box = new HBox();
    box.getChildren().addAll(picker, randomiser);
    dialog.getDialogPane().setContent(box);

    dialog.getDialogPane().getButtonTypes().addAll(
            ButtonType.OK, ButtonType.CANCEL);

    dialog.setResultConverter(buttonType -> {
        if (buttonType.equals(ButtonType.OK)) {
            return picker.getValue();
        } else {
            return null;
        }
    });
    return dialog.showAndWait();
}
FileMenu.java 文件源码 项目:Matcher 阅读 27 收藏 0 点赞 0 评论 0
private void newProject() {
    ProjectConfig config = ProjectConfig.getLast();

    Dialog<ProjectConfig> dialog = new Dialog<>();
    //dialog.initModality(Modality.APPLICATION_MODAL);
    dialog.setResizable(true);
    dialog.setTitle("Project configuration");
    dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);

    Node okButton = dialog.getDialogPane().lookupButton(ButtonType.OK);

    dialog.getDialogPane().setContent(new NewProjectPane(config, dialog.getOwner(), okButton));
    dialog.setResultConverter(button -> button == ButtonType.OK ? config : null);

    dialog.showAndWait().ifPresent(newConfig -> {
        if (!newConfig.isValid()) return;

        newConfig.saveAsLast();

        gui.getMatcher().reset();
        gui.onProjectChange();

        gui.runProgressTask("Initializing files...",
                progressReceiver -> gui.getMatcher().init(newConfig, progressReceiver),
                () -> gui.onProjectChange(),
                Throwable::printStackTrace);
    });
}
FileMenu.java 文件源码 项目:Matcher 阅读 32 收藏 0 点赞 0 评论 0
private void loadProject() {
    Path file = Gui.requestFile("Select matches file", gui.getScene().getWindow(), getMatchesLoadExtensionFilters(), true);
    if (file == null) return;

    List<Path> paths = new ArrayList<>();

    Dialog<List<Path>> dialog = new Dialog<>();
    //dialog.initModality(Modality.APPLICATION_MODAL);
    dialog.setResizable(true);
    dialog.setTitle("Project paths");
    dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);

    Node okButton = dialog.getDialogPane().lookupButton(ButtonType.OK);

    dialog.getDialogPane().setContent(new LoadProjectPane(paths, dialog.getOwner(), okButton));
    dialog.setResultConverter(button -> button == ButtonType.OK ? paths : null);

    dialog.showAndWait().ifPresent(newConfig -> {
        if (paths.isEmpty()) return;

        gui.getMatcher().reset();
        gui.onProjectChange();

        gui.runProgressTask("Initializing files...",
                progressReceiver -> gui.getMatcher().readMatches(file, paths, progressReceiver),
                () -> gui.onProjectChange(),
                Throwable::printStackTrace);
    });
}
ModelConfigButton.java 文件源码 项目:lttng-scope 阅读 21 收藏 0 点赞 0 评论 0
/**
 * Constructor
 *
 * @param widget
 *            The time graph widget to which this toolbar button is
 *            associated.
 */
public ModelConfigButton(TimeGraphWidget widget) {
    Image icon = JfxImageFactory.instance().getImageFromResource(LEGEND_ICON_PATH);
    setGraphic(new ImageView(icon));
    setTooltip(new Tooltip(Messages.modelConfigButtonName));

    setOnAction(e -> {
        Dialog<?> dialog = new ModelConfigDialog(widget);
        dialog.show();
        JfxUtils.centerDialogOnScreen(dialog, ModelConfigButton.this);
    });
}
DebugOptionsButton.java 文件源码 项目:lttng-scope 阅读 20 收藏 0 点赞 0 评论 0
/**
 * Constructor
 *
 * @param widget
 *            The time graph widget to which this toolbar button is
 *            associated.
 */
public DebugOptionsButton(TimeGraphWidget widget) {
    Image icon = JfxImageFactory.instance().getImageFromResource(CONFIG_ICON_PATH);
    setGraphic(new ImageView(icon));
    setTooltip(new Tooltip(Messages.debugOptionsDialogName));

    fOpts = widget.getDebugOptions();

    setOnAction(e -> {
        Dialog<Void> dialog = new DebugOptionsDialog(this);
        dialog.show();
        JfxUtils.centerDialogOnScreen(dialog, DebugOptionsButton.this);
    });
}
Dialogs.java 文件源码 项目:qiniu 阅读 32 收藏 0 点赞 0 评论 0
public Dialog<String[]> getDialog(ButtonType ok) {
    Dialog<String[]> dialog = new Dialog<String[]>();
    dialog.setTitle(Values.MAIN_TITLE);
    dialog.setHeaderText(null);

    dialog.initModality(Modality.APPLICATION_MODAL);

    // 自定义确认和取消按钮
    ButtonType cancel = new ButtonType(Values.CANCEL, ButtonData.CANCEL_CLOSE);
    dialog.getDialogPane().getButtonTypes().addAll(ok, cancel);
    return dialog;
}
GamepaneController.java 文件源码 项目:javaGMR 阅读 23 收藏 0 点赞 0 评论 0
@FXML
protected void uploadGame() {
    if (!new File(JGMRConfig.getInstance().getPath() + "/.jgmrlock.lock").exists()) {
        FileChooser directoryChooser = new FileChooser();
        if (JGMRConfig.getInstance().getPath() != null) {
            directoryChooser.setInitialDirectory(new File(JGMRConfig.getInstance().getPath()));
        }
        Stage stage = new Stage();
        File fileResult = directoryChooser.showOpenDialog(stage);
        if (fileResult != null) {
            Alert alert = new Alert(AlertType.CONFIRMATION);
            alert.setTitle("Upload to " + game.getName());
            alert.setHeaderText("Upload to " + game.getName());
            alert.setContentText("Are you sure you wish to upload " + fileResult.getName() + " to the game " + game.getName());
            Optional<ButtonType> result = alert.showAndWait();
            if (result.get() == ButtonType.OK) {
                uploadGame(fileResult);
            }
        }
    } else {
        Dialog dg = new Dialog();
        dg.setContentText("An upload or download is already in progress, please wait for the previous operation to finish.");
        dg.setTitle("Download or Upload already in progress.");
        dg.getDialogPane().getButtonTypes().add(new ButtonType("Ok", ButtonBar.ButtonData.OK_DONE));
        Platform.runLater(() -> {
            dg.showAndWait();
        });
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号