Java Code Examples for javafx.stage.Stage#setAlwaysOnTop()

The following examples show how to use javafx.stage.Stage#setAlwaysOnTop() . 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: AlarmClockTableController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@FXML
@Override
public void clearAction() {
    Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
    alert.setTitle(getBaseTitle());
    alert.setContentText(AppVariables.message("SureClearAlarmClocks"));
    alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
    ButtonType buttonSure = new ButtonType(AppVariables.message("Sure"));
    ButtonType buttonCancel = new ButtonType(AppVariables.message("Cancel"));
    alert.getButtonTypes().setAll(buttonSure, buttonCancel);
    Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
    stage.setAlwaysOnTop(true);
    stage.toFront();

    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() != buttonSure) {
        return;
    }

    tableData.clear();
    deleteButton.setDisable(true);
    editButton.setDisable(true);
    activeButton.setDisable(true);
    inactiveButton.setDisable(true);
    AlarmClock.clearAllAlarmClocks();
}
 
Example 2
Source File: MyBoxLanguagesController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@FXML
public void plusAction() {
    TextInputDialog dialog = new TextInputDialog("");
    dialog.setTitle(message("ManageLanguages"));
    dialog.setHeaderText(message("InputLangaugeName"));
    dialog.setContentText("");
    dialog.getEditor().setPrefWidth(200);
    Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
    stage.setAlwaysOnTop(true);
    stage.toFront();

    Optional<String> result = dialog.showAndWait();
    if (!result.isPresent() || result.get().trim().isBlank()) {
        return;
    }
    langName = result.get().trim();
    langLabel.setText(langName);
    loadLanguage(null);
}
 
Example 3
Source File: DownloadController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@FXML
protected void plusAction() {
    try {
        TextInputDialog dialog = new TextInputDialog("https://");
        dialog.setTitle(message("DownloadManage"));
        dialog.setHeaderText(message("InputAddress"));
        dialog.setContentText("");
        dialog.getEditor().setPrefWidth(500);
        Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
        stage.setAlwaysOnTop(true);
        stage.toFront();
        Optional<String> result = dialog.showAndWait();
        if (!result.isPresent()) {
            return;
        }
        String address = result.get();
        download(address);

    } catch (Exception e) {
        logger.error(e.toString());
    }
}
 
Example 4
Source File: MediaTableController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@FXML
public void addLinkAction() {
    try {
        // http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8
        TextInputDialog dialog = new TextInputDialog("http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8");
        dialog.setTitle(message("HTTPLiveStreaming"));
        dialog.setHeaderText(message("InputAddress"));
        dialog.setContentText("HLS(.m3u8)");
        dialog.getEditor().setPrefWidth(500);
        Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
        stage.setAlwaysOnTop(true);
        stage.toFront();

        Optional<String> result = dialog.showAndWait();
        if (!result.isPresent()) {
            return;
        }
        String address = result.get();
        addLink(address);

    } catch (Exception e) {
        logger.error(e.toString());
    }

}
 
Example 5
Source File: NotificationView.java    From Maus with GNU General Public License v3.0 6 votes vote down vote up
public static void openNotification(String text) {
    Stage stage = new Stage();
    stage.setWidth(300);
    stage.setHeight(125);
    Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
    NotificationView notificationView = new NotificationView();
    stage.setScene(new Scene(notificationView.getNotificationView(), 300, 125));
    stage.setResizable(false);
    stage.setAlwaysOnTop(true);
    stage.setX(primaryScreenBounds.getMinX() + primaryScreenBounds.getWidth() - 300);
    stage.setY(primaryScreenBounds.getMinY() + primaryScreenBounds.getHeight() - 125);
    stage.initStyle(StageStyle.UNDECORATED);
    notificationView.getNotificationText().setWrapText(true);
    notificationView.getNotificationText().setAlignment(Pos.CENTER);
    notificationView.getNotificationText().setPadding(new Insets(0, 5, 0, 20));
    notificationView.getNotificationText().setText(text);
    stage.show();
    PauseTransition delay = new PauseTransition(Duration.seconds(5));
    delay.setOnFinished(event -> stage.close());
    delay.play();
}
 
Example 6
Source File: GameElimniationController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
protected void promptDeadlock() {
    try {
        FxmlControl.BenWu2();
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setTitle(getBaseTitle());
        alert.setContentText(AppVariables.message("NoValidElimination"));
        alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
        ButtonType buttonRenew = new ButtonType(AppVariables.message("RenewGame"));
        ButtonType buttonChance = new ButtonType(AppVariables.message("MakeChance"));
        alert.getButtonTypes().setAll(buttonRenew, buttonChance);
        Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
        stage.setAlwaysOnTop(true);
        stage.toFront();
        Optional<ButtonType> result = alert.showAndWait();
        if (result.get() == buttonRenew) {
            newGame(false);
            popInformation(message("DeadlockDetectRenew"));
        } else if (result.get() == buttonChance) {
            makeChance();
            popInformation(message("DeadlockDetectChance"));
        }
    } catch (Exception e) {
        logger.debug(e.toString());
    }
}
 
Example 7
Source File: TableManageController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
@FXML
@Override
public void deleteAction() {
    List<P> selected = tableView.getSelectionModel().getSelectedItems();
    if (selected == null || selected.isEmpty()) {
        return;
    }
    if (deleteConfirmCheck != null && deleteConfirmCheck.isSelected()) {
        Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
        alert.setTitle(getBaseTitle());
        alert.setContentText(AppVariables.message("SureDelete"));
        alert.getDialogPane().setMinWidth(Region.USE_PREF_SIZE);
        alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
        ButtonType buttonSure = new ButtonType(AppVariables.message("Sure"));
        ButtonType buttonCancel = new ButtonType(AppVariables.message("Cancel"));
        alert.getButtonTypes().setAll(buttonSure, buttonCancel);
        Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
        stage.setAlwaysOnTop(true);
        stage.toFront();
        Optional<ButtonType> result = alert.showAndWait();
        if (result.get() != buttonSure) {
            return;
        }
    }
    if (deleteSelectedData()) {
        refreshAction();
    }
}
 
Example 8
Source File: ImageManufactureController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
@Override
public boolean checkBeforeNextAction() {
    if (!imageLoaded.get() || !imageUpdated.get()) {
        return true;
    }
    Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
    alert.setTitle(getMyStage().getTitle());
    alert.setContentText(AppVariables.message("ImageChanged"));
    alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
    ButtonType buttonSave = new ButtonType(AppVariables.message("Save"));
    ButtonType buttonSaveAs = new ButtonType(AppVariables.message("SaveAs"));
    ButtonType buttonNotSave = new ButtonType(AppVariables.message("NotSave"));
    ButtonType buttonCancel = new ButtonType(AppVariables.message("Cancel"));
    alert.getButtonTypes().setAll(buttonSave, buttonSaveAs, buttonNotSave, buttonCancel);
    Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
    stage.setAlwaysOnTop(true);
    stage.toFront();

    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() == buttonSave) {
        saveAction();
        return true;
    } else if (result.get() == buttonNotSave) {
        return true;
    } else if (result.get() == buttonSaveAs) {
        saveAsAction();
        return true;
    } else {
        return false;
    }

}
 
Example 9
Source File: MyBoxLanguagesController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
@FXML
@Override
public void deleteAction() {
    List<String> selected = listView.getSelectionModel().getSelectedItems();
    if (selected == null || selected.isEmpty()) {
        return;
    }
    Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
    alert.setTitle(getMyStage().getTitle());
    alert.setContentText(AppVariables.message("SureDelete"));
    alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
    ButtonType buttonSure = new ButtonType(AppVariables.message("Sure"));
    ButtonType buttonCancel = new ButtonType(AppVariables.message("Cancel"));
    alert.getButtonTypes().setAll(buttonSure, buttonCancel);
    Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
    stage.setAlwaysOnTop(true);
    stage.toFront();
    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() != buttonSure) {
        return;
    }
    for (String name : selected) {
        File file = new File(AppVariables.MyBoxLanguagesPath + File.separator + name);
        file.delete();
    }
    isSettingValues = true;
    listView.getItems().removeAll(selected);
    isSettingValues = false;
    langName = null;
    langLabel.setText("");
    checkListSelected();
}
 
Example 10
Source File: ImagesListController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public boolean checkSaving() {
    if (imageChanged && !tableController.tableData.isEmpty()) {
        Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
        alert.setTitle(getMyStage().getTitle());
        alert.setContentText(AppVariables.message("ImageChanged"));
        alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
        ButtonType buttonSave = new ButtonType(AppVariables.message("Save"));
        ButtonType buttonNotSave = new ButtonType(AppVariables.message("NotSave"));
        ButtonType buttonCancel = new ButtonType(AppVariables.message("Cancel"));
        alert.getButtonTypes().setAll(buttonSave, buttonNotSave, buttonCancel);
        Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
        stage.setAlwaysOnTop(true);
        stage.toFront();

        Optional<ButtonType> result = alert.showAndWait();
        if (result.get() == buttonSave) {
            saveAction();
            return true;
        } else if (result.get() == buttonNotSave) {
            return true;
        } else {
            return false;
        }
    } else {
        return true;
    }
}
 
Example 11
Source File: ImageViewerController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public boolean deleteFile(File sfile) {
    if (sfile == null) {
        return false;
    }
    if (deleteConfirmCheck != null && deleteConfirmCheck.isSelected()) {
        Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
        alert.setTitle(getMyStage().getTitle());
        alert.setContentText(AppVariables.message("SureDelete"));
        alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
        ButtonType buttonSure = new ButtonType(AppVariables.message("Sure"));
        ButtonType buttonCancel = new ButtonType(AppVariables.message("Cancel"));
        alert.getButtonTypes().setAll(buttonSure, buttonCancel);
        Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
        stage.setAlwaysOnTop(true);
        stage.toFront();

        Optional<ButtonType> result = alert.showAndWait();
        if (result.get() != buttonSure) {
            return false;
        }
    }
    if (sfile.delete()) {
        popSuccessful();
        return true;
    } else {
        popFailed();
        return false;
    }
}
 
Example 12
Source File: PlatformUtils.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Same as setFullScreenWindow but modified to take a javafx Stage Also sets
 * up always on top
 */
public static boolean setFullScreenAlwaysOnTop(Stage stage, boolean fullScreen) {
    if (!Utils.isLinux()) {
        return false;
    }

    stage.setFullScreenExitHint("");
    stage.setFullScreenExitKeyCombination(null);
    stage.setFullScreen(fullScreen);
    stage.setAlwaysOnTop(fullScreen);

    return setFullScreenWindow(getWindowID(stage), fullScreen);
}
 
Example 13
Source File: GameElimniationController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
@FXML
protected void okRulersAction() {
    if (isSettingValues) {
        return;
    }
    catButton.setSelected(false);
    try {
        countedChesses.clear();
        String s = "";
        for (Node node : countedImagesPane.getChildren()) {
            CheckBox cbox = (CheckBox) node;
            if (cbox.isSelected()) {
                int index = (int) cbox.getUserData();
                countedChesses.add(index);
                ImageItem item = getImageItem(index);
                if (s.isBlank()) {
                    s += item.getAddress();
                } else {
                    s += "," + item.getAddress();
                }
            }
        }
        if (countedChesses.isEmpty()) {
            Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
            alert.setTitle(getBaseTitle());
            alert.setContentText(AppVariables.message("SureNoScore"));
            alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
            ButtonType buttonSure = new ButtonType(AppVariables.message("Sure"));
            ButtonType buttonCancel = new ButtonType(AppVariables.message("Cancel"));
            alert.getButtonTypes().setAll(buttonSure, buttonCancel);
            Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
            stage.setAlwaysOnTop(true);
            stage.toFront();
            Optional<ButtonType> result = alert.showAndWait();
            if (result.get() != buttonSure) {
                return;
            }
        }
        AppVariables.setUserConfigValue("GameEliminationCountedImages", s);

        scoreRulers.clear();
        s = "";
        for (int i = 0; i < scoreRulersData.size(); ++i) {
            ScoreRuler r = scoreRulersData.get(i);
            scoreRulers.put(r.adjacentNumber, r.score);
            if (!s.isEmpty()) {
                s += ",";
            }
            s += r.adjacentNumber + "," + r.score;
        }
        AppVariables.setUserConfigValue("GameElimniationScoreRulers", s);

        tabPane.getSelectionModel().select(playTab);
        newGame(true);

    } catch (Exception e) {
        logger.debug(e.toString());
    }
}
 
Example 14
Source File: GameElimniationController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
protected void makeChesses() {
    if (isSettingValues) {
        return;
    }
    catButton.setSelected(false);
    try {
        chessSize = Integer.parseInt(chessSizeSelector.getValue());
        if (chessSize < 20) {
            chessSize = 20;
        }
    } catch (Exception e) {
        chessSize = 50;
    }
    AppVariables.setUserConfigValue("GameEliminationChessImageSize", chessSize + "");
    AppVariables.setUserConfigValue("GameEliminationShadow", shadowCheck.isSelected());
    AppVariables.setUserConfigValue("GameEliminationArc", arcCheck.isSelected());

    selectedChesses.clear();
    String s = "";
    for (int i = 0; i < imagesListview.getItems().size(); ++i) {
        ImageItem item = imagesListview.getItems().get(i);
        item.setIndex(i);
        if (item.isSelected()) {
            selectedChesses.add(i);
            if (s.isBlank()) {
                s += item.getAddress() + "";
            } else {
                s += "," + item.getAddress();
            }
        }
    }
    if (selectedChesses.size() <= minimumAdjacent) {
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setTitle(getBaseTitle());
        alert.setContentText(MessageFormat.format(message("ChessesNumberTooSmall"), minimumAdjacent + ""));
        alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
        Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
        stage.setAlwaysOnTop(true);
        stage.toFront();
        alert.showAndWait();
        return;
    }
    AppVariables.setUserConfigValue("GameEliminationChessImages", s);
    boardSize = selectedChesses.size();
    tabPane.getSelectionModel().select(playTab);
    makeChessBoard();
    makeRulers();
    newGame(true);
}
 
Example 15
Source File: Main.java    From logbook-kai with MIT License 4 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {
    String fxmlName = "main";
    if (AppConfig.get().getWindowStyle() != null) {
        fxmlName = AppConfig.get().getWindowStyle();
    }
    FXMLLoader loader = InternalFXMLLoader.load("logbook/gui/" + fxmlName + ".fxml"); //$NON-NLS-1$
    Parent root = InternalFXMLLoader.setGlobal(loader.load());
    stage.setScene(new Scene(root));

    WindowController controller = loader.getController();
    controller.initWindow(stage);
    // アイコンの設定
    Tools.Windows.setIcon(stage);
    // 最前面に表示する
    stage.setAlwaysOnTop(AppConfig.get().isOnTop());

    stage.setTitle("航海日誌 " + Version.getCurrent());

    stage.addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, e -> {
        if (AppConfig.get().isCheckDoit()) {
            Alert alert = new Alert(AlertType.INFORMATION);
            alert.getDialogPane().getStylesheets().add("logbook/gui/application.css");
            InternalFXMLLoader.setGlobal(alert.getDialogPane());
            alert.initOwner(stage);
            alert.setTitle("終了の確認");
            alert.setHeaderText("終了の確認");
            alert.setContentText("航海日誌を終了しますか?");
            alert.getButtonTypes().clear();
            alert.getButtonTypes().addAll(ButtonType.YES, ButtonType.NO);
            alert.showAndWait()
                    .filter(ButtonType.NO::equals)
                    .ifPresent(t -> e.consume());
        }
        if (!e.isConsumed()) {
            AppConfig.get()
                    .getWindowLocationMap()
                    .put(controller.getClass().getCanonicalName(), controller.getWindowLocation());
        }
    });
    Tools.Windows.defaultOpenAction(controller);

    stage.show();
}
 
Example 16
Source File: DataAnalysisController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public void clear() {
    if (clearCondition == null) {
        popError(message("SetConditionsComments"));
        return;
    }
    setClearSQL();
    Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
    alert.setTitle(getBaseTitle());
    alert.setContentText(AppVariables.message("SureClearConditions")
            + "\n\n" + clearCondition.getTitle().replaceAll("</br>", "\n")
            + "\n\n" + clearSQL
            + "\n\n" + message("DataDeletedComments")
    );
    alert.getDialogPane().setMinWidth(Region.USE_PREF_SIZE);
    alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
    ButtonType buttonSure = new ButtonType(AppVariables.message("Sure"));
    ButtonType buttonCancel = new ButtonType(AppVariables.message("Cancel"));
    alert.getButtonTypes().setAll(buttonSure, buttonCancel);
    Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
    stage.setAlwaysOnTop(true);
    stage.toFront();

    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() != buttonSure) {
        return;
    }
    synchronized (this) {
        if (task != null) {
            return;
        }
        task = new SingletonTask<Void>() {
            private int count = 0;

            @Override
            protected boolean handle() {
                count = dataTable().update(clearSQL);

                return true;
            }

            @Override
            protected void whenSucceeded() {
                alertInformation(message("Deleted") + ": " + count);
                refreshAction();
            }

        };
        openHandlingStage(task, Modality.WINDOW_MODAL);
        Thread thread = new Thread(task);
        thread.setDaemon(true);
        thread.start();
    }
}
 
Example 17
Source File: SecurityCertificatesAddController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
@FXML
@Override
public void okAction() {
    if (certController == null) {
        return;
    }
    if (addressRadio.isSelected()) {
        if (addressInput.getText().isEmpty()) {
            popError(message("NotExist"));
            return;
        }
    } else {
        sourceFile = new File(sourceFileInput.getText());
        if (!sourceFile.exists() || !sourceFile.isFile()) {
            popError(message("NotExist"));
            return;
        }
    }

    File ksFile = new File(certController.getSourceFileInput().getText());
    if (!ksFile.exists() || !ksFile.isFile()) {
        popError(message("NotExist"));
        return;
    }
    String password = certController.getPasswordInput().getText();

    TextInputDialog dialog = new TextInputDialog("");
    dialog.setTitle(message("SecurityCertificates"));
    dialog.setHeaderText(message("Alias"));
    dialog.setContentText("");
    dialog.getEditor().setPrefWidth(300);
    Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
    stage.setAlwaysOnTop(true);
    stage.toFront();
    Optional<String> result = dialog.showAndWait();
    if (!result.isPresent() || result.get().trim().isBlank()) {
        return;
    }
    final String alias = result.get().trim();
    if (!certController.backupKeyStore()) {
        return;
    }
    try {
        synchronized (this) {
            if (task != null) {
                return;
            }
            task = new SingletonTask<Void>() {

                @Override
                protected boolean handle() {
                    error = null;

                    if (addressRadio.isSelected()) {
                        try {
                            error = NetworkTools.installCertificateByHost(
                                    ksFile.getAbsolutePath(), password,
                                    addressInput.getText(), alias);
                        } catch (Exception e) {
                            error = e.toString();
                        }
                    } else if (fileRadio.isSelected()) {
                        try {
                            error = NetworkTools.installCertificateByFile(
                                    ksFile.getAbsolutePath(), password,
                                    sourceFile, alias);
                        } catch (Exception e) {
                            error = e.toString();
                        }
                    }
                    return true;
                }

                @Override
                protected void whenSucceeded() {
                    if (error == null) {
                        certController.loadAll(alias);
                        if (saveCloseCheck.isSelected()) {
                            closeStage();
                        }
                        popSuccessful();
                    } else {
                        popError(error);
                    }
                }
            };
            openHandlingStage(task, Modality.WINDOW_MODAL);
            Thread thread = new Thread(task);
            thread.setDaemon(true);
            thread.start();
        }

    } catch (Exception e) {
        logger.error(e.toString());
    }
}
 
Example 18
Source File: FileEditerController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
@FXML
protected void replaceAllAction() {
    final String text = mainArea.getText();
    if (replaceAllButton.isDisabled() || text.isEmpty()) {
        return;
    }
    final String findString = findInput.getText();
    if (findString.isEmpty()) {
        return;
    }
    final String replaceString = replaceInput.getText();
    sourceInformation.setFindString(findString);
    sourceInformation.setReplaceString(replaceString);
    final boolean whole = findWhole && (sourceInformation.getPagesNumber() > 1);
    if (whole) {
        if (!checkBeforeNextAction()) {
            return;
        }
        Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
        alert.setTitle(getMyStage().getTitle());
        alert.setContentText(AppVariables.message("SureReplaceAll"));
        alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
        ButtonType buttonSure = new ButtonType(AppVariables.message("Sure"));
        ButtonType buttonCancel = new ButtonType(AppVariables.message("Cancel"));
        alert.getButtonTypes().setAll(buttonSure, buttonCancel);
        Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
        stage.setAlwaysOnTop(true);
        stage.toFront();

        Optional<ButtonType> result = alert.showAndWait();
        if (result.get() != buttonSure) {
            return;
        }
    }
    synchronized (this) {
        if (task != null) {
            return;
        }
        task = new SingletonTask<Void>() {

            private String replaced;
            private int num;

            @Override
            protected boolean handle() {
                boolean regex = regexCheck != null && regexCheck.isSelected();
                if (whole) {
                    sourceInformation.setFindRegex(regex);
                    num = sourceInformation.replaceAll();
                } else {
                    if (regex) {
                        num = StringTools.countNumberRegex(text, findString);
                        if (num > 0) {
                            replaced = text.replaceAll(findString, replaceString);
                        }
                    } else {
                        num = StringTools.countNumber(text, findString);
                        if (num > 0) {
                            replaced = StringTools.replaceAll(text, findString, replaceString);
                        }
                    }
                }

                return true;
            }

            @Override
            protected void whenSucceeded() {
                if (num > 0) {
                    sourceInformation.setCurrentFound(-1);
                    currentFound = -1;
                    if (whole) {
                        openFile(sourceFile);
                    } else {
                        isSettingValues = true;
                        mainArea.setText(replaced);
                        isSettingValues = false;
                        updateInterface(true);
                    }
                    popInformation(MessageFormat.format(AppVariables.message("ReplaceAllOk"), num));
                } else {
                    popInformation(AppVariables.message("NotFound"));
                    findPreviousButton.setDisable(true);
                    findNextButton.setDisable(true);
                    findLastButton.setDisable(true);
                    replaceButton.setDisable(true);
                    replaceAllButton.setDisable(true);
                    currentFound = -1;
                }
            }
        };
        openHandlingStage(task, Modality.WINDOW_MODAL);
        Thread thread = new Thread(task);
        thread.setDaemon(true);
        thread.start();
    }
}
 
Example 19
Source File: FFmpegInformationController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
@Override
public boolean checkBeforeNextAction() {
    if ((formatsTask != null && formatsTask.isRunning())
            || (codecsTask != null && codecsTask.isRunning())
            || (queryTask != null && queryTask.isRunning())
            || (filtersTask != null && filtersTask.isRunning())) {
        Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
        alert.setTitle(getMyStage().getTitle());
        alert.setContentText(AppVariables.message("TaskRunning"));
        alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
        ButtonType buttonSure = new ButtonType(AppVariables.message("Sure"));
        ButtonType buttonCancel = new ButtonType(AppVariables.message("Cancel"));
        alert.getButtonTypes().setAll(buttonSure, buttonCancel);
        Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
        stage.setAlwaysOnTop(true);
        stage.toFront();

        Optional<ButtonType> result = alert.showAndWait();
        if (result.get() == buttonSure) {
            if (formatsTask != null) {
                formatsTask.cancel();
                formatsTask = null;
            }
            if (codecsTask != null) {
                codecsTask.cancel();
                codecsTask = null;
            }
            if (filtersTask != null) {
                filtersTask.cancel();
                filtersTask = null;
            }
            if (queryTask != null) {
                queryTask.cancel();
                queryTask = null;
            }
        } else {
            return false;
        }
    }
    return true;
}
 
Example 20
Source File: PdfAttributesController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
@FXML
@Override
public void saveAction() {
    if (sourceFile == null) {
        return;
    }
    if ((userPasswordInput.getText() != null && !userPasswordInput.getText().isEmpty())
            || (ownerPasswordInput.getText() != null && !ownerPasswordInput.getText().isEmpty())) {
        Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
        alert.setTitle(myStage.getTitle());
        alert.setContentText(AppVariables.message("SureSetPassword"));
        alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
        ButtonType buttonSure = new ButtonType(AppVariables.message("Sure"));
        ButtonType buttonCancel = new ButtonType(AppVariables.message("Cancel"));
        alert.getButtonTypes().setAll(buttonSure, buttonCancel);
        Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
        stage.setAlwaysOnTop(true);
        stage.toFront();
        Optional<ButtonType> result = alert.showAndWait();
        if (result.get() != buttonSure) {
            return;
        }
    }

    final PdfInformation modify = new PdfInformation(sourceFile);
    modify.setAuthor(authorInput.getText());
    modify.setTitle(titleInput.getText());
    modify.setSubject(subjectInput.getText());
    modify.setCreator(creatorInput.getText());
    modify.setProducer(producerInput.getText());
    modify.setKeywords(keywordInput.getText());
    if (modifyTime != null) {
        modify.setModifyTime(modifyTime.getTime());
    }
    if (createTime != null) {
        modify.setCreateTime(createTime.getTime());
    }
    if (version > 0) {
        modify.setVersion(version);
    }
    modify.setUserPassword(userPasswordInput.getText());
    modify.setOwnerPassword(ownerPasswordInput.getText());
    AccessPermission acc = AccessPermission.getOwnerAccessPermission();
    acc.setCanAssembleDocument(assembleCheck.isSelected());
    acc.setCanExtractContent(extractCheck.isSelected());
    acc.setCanExtractForAccessibility(extractCheck.isSelected());
    acc.setCanFillInForm(fillCheck.isSelected());
    acc.setCanModify(modifyCheck.isSelected());
    acc.setCanModifyAnnotations(modifyCheck.isSelected());
    acc.setCanPrint(printCheck.isSelected());
    acc.setCanPrintDegraded(printCheck.isSelected());
    modify.setAccess(acc);

    synchronized (this) {
        if (task != null) {
            return;
        }
        task = new SingletonTask<Void>() {

            private boolean pop;

            @Override
            protected boolean handle() {
                return PdfTools.setAttributes(sourceFile, pdfInfo.getOwnerPassword(), modify);
            }

            @Override
            protected void whenSucceeded() {
                loadPdfInformation(ownerPasswordInput.getText());
                popSuccessful();
            }

        };
        openHandlingStage(task, Modality.WINDOW_MODAL);
        Thread thread = new Thread(task);
        thread.setDaemon(true);
        thread.start();
    }
}