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);
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations