Search in sources :

Example 91 with FileChooser

use of javafx.stage.FileChooser in project BlocklyArduinoIDEPlugin by technologiescollege.

the class BlocklyArduinoServer method saveWorkspaceCapture.

/**
 * This method is called from javascript. It lets the user select a location
 * where to save the screen capture of the workspace.
 *
 * @param code Thecode generated from Blockly@rduino.
 */
public void saveWorkspaceCapture(String code) {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setInitialDirectory(new File(lastOpenedLocation));
    fileChooser.setTitle("Capture");
    fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("image", "*.svg"));
    File selectedFile = fileChooser.showSaveDialog(ownerWindow);
    if (selectedFile != null) {
        try {
            FileWriter fileWriter = null;
            fileWriter = new FileWriter(selectedFile);
            fileWriter.write(code);
            fileWriter.close();
        } catch (IOException ex) {
        // Logger.getLogger(JavaFX_Text.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
Also used : FileWriter(java.io.FileWriter) FileChooser(javafx.stage.FileChooser) IOException(java.io.IOException) File(java.io.File)

Example 92 with FileChooser

use of javafx.stage.FileChooser in project POL-POM-5 by PhoenicisOrg.

the class LibrarySidebarSkin method createAdvancedToolsGroup.

/**
 * Creates a {@link SidebarGroup} which contains the advanced tool buttons to:
 * <ul>
 * <li>create a new shortcut</li>
 * <li>run a script</li>
 * <li>open a Phoenicis console</li>
 * </ul>
 *
 * @return The created {@link SidebarGroup} object
 */
private SidebarGroup<Button> createAdvancedToolsGroup() {
    final Button createShortcut = new Button(tr("Create shortcut"));
    createShortcut.getStyleClass().addAll("sidebarButton", "openTerminal");
    createShortcut.setOnMouseClicked(event -> Optional.ofNullable(getControl().getOnCreateShortcut()).ifPresent(Runnable::run));
    final Button runScript = new Button(tr("Run a script"));
    runScript.getStyleClass().addAll("sidebarButton", "scriptButton");
    runScript.setOnMouseClicked(event -> {
        final FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle(tr("Open Script..."));
        final File scriptToRun = fileChooser.showOpenDialog(getControl().getScene().getWindow());
        if (scriptToRun != null) {
            Optional.ofNullable(getControl().getOnScriptRun()).ifPresent(onScriptRun -> onScriptRun.accept(scriptToRun));
        }
    });
    final Button runConsole = new Button(tr("{0} console", getControl().getApplicationName()));
    runConsole.getStyleClass().addAll("sidebarButton", "consoleButton");
    runConsole.setOnMouseClicked(event -> Optional.ofNullable(getControl().getOnOpenConsole()).ifPresent(Runnable::run));
    final SidebarGroup<Button> advancedToolsGroup = new SidebarGroup<>(tr("Advanced Tools"));
    advancedToolsGroup.getComponents().addAll(createShortcut, /* runScript, */
    runConsole);
    return advancedToolsGroup;
}
Also used : Button(javafx.scene.control.Button) FileChooser(javafx.stage.FileChooser) File(java.io.File) SidebarGroup(org.phoenicis.javafx.components.common.control.SidebarGroup)

Example 93 with FileChooser

use of javafx.stage.FileChooser in project POL-POM-5 by PhoenicisOrg.

the class ShortcutCreationPanelSkin method addExecutable.

/**
 * Adds the executable selection input to the given {@link GridPane}
 *
 * @param gridPane The grid pane to which the executable selection should be added
 * @return The {@link TextField} containing the executable input
 */
private TextField addExecutable(final GridPane gridPane) {
    final int row = gridPane.getRowCount();
    final Label executableLabel = new Label(tr("Executable:"));
    executableLabel.getStyleClass().add("captionTitle");
    GridPane.setValignment(executableLabel, VPos.TOP);
    final TextField executable = new TextField();
    final Button openExecutableBrowser = new Button(tr("Browse..."));
    openExecutableBrowser.setOnAction(event -> {
        FileChooser chooser = new FileChooser();
        // open in containers directory if it exists
        File containersDir = new File(getControl().getContainersPath());
        if (containersDir.canRead()) {
            chooser.setInitialDirectory(containersDir);
        }
        File newExecutable = chooser.showOpenDialog(getControl().getScene().getWindow());
        if (newExecutable != null) {
            executable.setText(newExecutable.toString());
        }
    });
    final HBox executableHbox = new HBox(executable, openExecutableBrowser);
    executableHbox.getStyleClass().add("file-selection-container");
    HBox.setHgrow(executable, Priority.ALWAYS);
    gridPane.addRow(row, executableLabel, executableHbox);
    return executable;
}
Also used : FileChooser(javafx.stage.FileChooser) File(java.io.File)

Example 94 with FileChooser

use of javafx.stage.FileChooser in project POL-POM-5 by PhoenicisOrg.

the class ContainerToolsPanelSkin method createToolsContainer.

/**
 * Creates the container for the tool buttons
 *
 * @return The container with the tool buttons
 */
private TilePane createToolsContainer() {
    final TilePane toolsContainer = new TilePane();
    final Button runExecutable = new Button(tr("Run executable"));
    runExecutable.getStyleClass().addAll("toolButton", "runExecutable");
    runExecutable.setOnMouseClicked(event -> {
        getControl().setLockTools(true);
        final FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle(tr("Choose executable..."));
        // open in container directory if it exists
        final File containerDir = new File(getControl().getContainer().getPath());
        if (containerDir.canRead()) {
            fileChooser.setInitialDirectory(containerDir);
        }
        final File file = fileChooser.showOpenDialog(getControl().getScene().getWindow());
        if (file != null) {
            final ContainerDTO container = getControl().getContainer();
            final String engineId = container.getEngine().toLowerCase();
            getControl().getEnginesManager().getEngine(engineId, engine -> {
                engine.setWorkingContainer(container.getName());
                engine.run(file.getAbsolutePath(), new String[0], container.getPath(), false, true, new HashMap<>());
                getControl().setLockTools(false);
            }, exception -> Platform.runLater(() -> {
                final ErrorDialog errorDialog = ErrorDialog.builder().withMessage(tr("Error")).withOwner(getControl().getScene().getWindow()).withException(exception).build();
                errorDialog.showAndWait();
            }));
        } else {
            // unlock if file chooser is closed
            getControl().setLockTools(false);
        }
    });
    toolsContainer.getChildren().add(runExecutable);
    return toolsContainer;
}
Also used : Button(javafx.scene.control.Button) TilePane(javafx.scene.layout.TilePane) FileChooser(javafx.stage.FileChooser) ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) File(java.io.File)

Example 95 with FileChooser

use of javafx.stage.FileChooser in project proxyee-down by monkeyWie.

the class Components method fileChooser.

/**
 * 弹出文件选择框
 */
public static File fileChooser() {
    Stage stage = buildBackgroundTopStage();
    FileChooser chooser = new FileChooser();
    chooser.setTitle("选择文件");
    File file = chooser.showOpenDialog(stage);
    stage.close();
    return file;
}
Also used : FileChooser(javafx.stage.FileChooser) Stage(javafx.stage.Stage) File(java.io.File)

Aggregations

FileChooser (javafx.stage.FileChooser)208 File (java.io.File)189 IOException (java.io.IOException)55 FXML (javafx.fxml.FXML)49 Preferences (java.util.prefs.Preferences)24 Button (javafx.scene.control.Button)21 ArrayList (java.util.ArrayList)19 VBox (javafx.scene.layout.VBox)15 ResourceBundle (java.util.ResourceBundle)14 ExtensionFilter (javafx.stage.FileChooser.ExtensionFilter)14 Stage (javafx.stage.Stage)14 Label (javafx.scene.control.Label)13 Alert (javafx.scene.control.Alert)12 List (java.util.List)11 TextField (javafx.scene.control.TextField)11 ScriptException (javax.script.ScriptException)11 Scene (javafx.scene.Scene)10 Map (java.util.Map)9 ObservableList (javafx.collections.ObservableList)9 MenuItem (javafx.scene.control.MenuItem)9