List of usage examples for javafx.stage FileChooser getExtensionFilters
public ObservableList<ExtensionFilter> getExtensionFilters()
From source file:dpfmanager.shell.interfaces.gui.fragment.wizard.Wizard1Fragment.java
@FXML protected void importIso() { File file;/*from www .jav a 2s . co m*/ String value = GuiWorkbench.getTestParams("importIso"); if (value != null) { //Test mode file = new File(value); } else { //Ask for file String configDir = DPFManagerProperties.getDefaultDirConfig(); FileChooser fileChooser = new FileChooser(); fileChooser.setTitle(bundle.getString("w1Import")); fileChooser.setInitialDirectory(new File(configDir)); FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter(bundle.getString("w1XmlFiles"), "*.xml"); fileChooser.getExtensionFilters().add(extFilter); file = fileChooser.showOpenDialog(GuiWorkbench.getMyStage()); } addIsoFile(file, true); }
From source file:com.ggvaidya.scinames.ui.DatasetDiffController.java
@FXML private void exportToCSV(ActionEvent evt) { FileChooser chooser = new FileChooser(); chooser.getExtensionFilters().setAll(new FileChooser.ExtensionFilter("CSV file", "*.csv"), new FileChooser.ExtensionFilter("Tab-delimited file", "*.txt")); File file = chooser.showSaveDialog(datasetDiffView.getStage()); if (file != null) { CSVFormat format = CSVFormat.RFC4180; String outputFormat = chooser.getSelectedExtensionFilter().getDescription(); if (outputFormat.equalsIgnoreCase("Tab-delimited file")) format = CSVFormat.TDF;/*from w ww . j a v a2 s .c o m*/ try { List<List<String>> dataAsTable = getDataAsTable(); fillCSVFormat(format, new FileWriter(file), dataAsTable); Alert window = new Alert(Alert.AlertType.CONFIRMATION, "CSV file '" + file + "' saved with " + (dataAsTable.get(0).size() - 1) + " rows."); window.showAndWait(); } catch (IOException e) { Alert window = new Alert(Alert.AlertType.ERROR, "Could not save CSV to '" + file + "': " + e); window.showAndWait(); } } }
From source file:jp.ac.tohoku.ecei.sb.metabolome.lims.gui.MainWindowController.java
@FXML void onOpen(ActionEvent event) { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Open Metabolome Analysis File"); fileChooser.getExtensionFilters() .addAll(new FileChooser.ExtensionFilter("Supported Files", Arrays.asList("*.zip", "*.csv"))); File file = fileChooser.showOpenDialog(stage); if (file == null) return;// w w w. j a va2 s . c o m if (!opened) { openData(file); } else { try { Stage primaryStage = new Stage(); FXMLLoader loader = new FXMLLoader(getClass().getResource("mainwindow.fxml")); loader.load(); MainWindowController controller = loader.getController(); controller.setStage(primaryStage); VBox root = loader.getRoot(); Scene scene = new Scene(root); primaryStage.setScene(scene); controller.openData(file); primaryStage.show(); } catch (IOException e) { e.printStackTrace(); AlertHelper.showExceptionAlert("Cannot open", null, e); } } }
From source file:tachyon.view.ProjectProperties.java
public ProjectProperties(JavaProject project, Window w) { this.project = project; stage = new Stage(); stage.initOwner(w);/* ww w . j a v a 2s . c o m*/ stage.initModality(Modality.APPLICATION_MODAL); stage.setWidth(600); stage.setTitle("Project Properties - " + project.getProjectName()); stage.getIcons().add(tachyon.Tachyon.icon); stage.setResizable(false); HBox mai, libs, one, two, thr, fou; ListView<String> compileList, runtimeList; Button compileAdd, compileRemove, preview, selectIm, runtimeAdd, runtimeRemove; TextField iconField; stage.setScene(new Scene(new VBox(5, pane = new TabPane( new Tab("Library Settings", box1 = new VBox(15, libs = new HBox(10, new Label("External Libraries"), libsView = new ListView<>(), new VBox(5, addJar = new Button("Add Jar"), removeJar = new Button("Remove Jar"))))), new Tab("Program Settings", new ScrollPane(box2 = new VBox(15, one = new HBox(10, new Label("Main-Class"), mainClass = new TextField(project.getMainClassName()), select = new Button("Select")), two = new HBox(10, new Label("Compile-Time Arguments"), compileList = new ListView<>(), new VBox(5, compileAdd = new Button("Add Argument"), compileRemove = new Button("Remove Argument")))))), new Tab("Deployment Settings", box3 = new VBox(15, thr = new HBox(10, new Label("Icon File"), iconField = new TextField(project.getFileIconPath()), preview = new Button("Preview Image"), selectIm = new Button("Select Icon")), fou = new HBox(10, new Label("Runtime Arguments"), runtimeList = new ListView<>(), new VBox(5, runtimeAdd = new Button("Add Argument"), runtimeRemove = new Button("Remove Argument")))))), new VBox(15, mai = new HBox(10, cancel = new Button("Cancel"), confirm = new Button("Confirm")))))); if (applyCss.get()) { stage.getScene().getStylesheets().add(css); } for (Tab b : pane.getTabs()) { b.setClosable(false); } mainClass.setPromptText("Main-Class"); box1.setPadding(new Insets(5, 10, 5, 10)); mai.setAlignment(Pos.CENTER_RIGHT); mai.setPadding(box1.getPadding()); libs.setAlignment(Pos.CENTER); one.setAlignment(Pos.CENTER); two.setAlignment(Pos.CENTER); thr.setAlignment(Pos.CENTER); fou.setAlignment(Pos.CENTER); box1.setAlignment(Pos.CENTER); box2.setPadding(box1.getPadding()); box2.setAlignment(Pos.CENTER); box3.setPadding(box1.getPadding()); box3.setAlignment(Pos.CENTER); mainClass.setEditable(false); mainClass.setPrefWidth(200); for (JavaLibrary lib : project.getAllLibs()) { libsView.getItems().add(lib.getBinaryAbsolutePath()); } for (String sa : project.getCompileTimeArguments().keySet()) { compileList.getItems().add(sa + ":" + project.getCompileTimeArguments().get(sa)); } for (String sa : project.getRuntimeArguments()) { runtimeList.getItems().add(sa); } compileAdd.setOnAction((e) -> { Dialog<Pair<String, String>> dialog = new Dialog<>(); dialog.setTitle("Compiler Argument"); dialog.initOwner(stage); dialog.setHeaderText("Entry the argument"); ButtonType loginButtonType = new ButtonType("Done", ButtonData.OK_DONE); dialog.getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL); GridPane grid = new GridPane(); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(20, 150, 10, 10)); TextField username = new TextField(); username.setPromptText("Key"); TextField password = new TextField(); password.setPromptText("Value"); grid.add(new Label("Key:"), 0, 0); grid.add(username, 1, 0); grid.add(new Label("Value:"), 0, 1); grid.add(password, 1, 1); Node loginButton = dialog.getDialogPane().lookupButton(loginButtonType); loginButton.setDisable(true); username.textProperty().addListener((observable, oldValue, newValue) -> { loginButton.setDisable(newValue.trim().isEmpty()); }); dialog.getDialogPane().setContent(grid); Platform.runLater(() -> username.requestFocus()); dialog.setResultConverter(dialogButton -> { if (dialogButton == loginButtonType) { return new Pair<>(username.getText(), password.getText()); } return null; }); Optional<Pair<String, String>> result = dialog.showAndWait(); if (result.isPresent()) { compileList.getItems().add(result.get().getKey() + ":" + result.get().getValue()); } }); compileRemove.setOnAction((e) -> { if (compileList.getSelectionModel().getSelectedItem() != null) { compileList.getItems().remove(compileList.getSelectionModel().getSelectedItem()); } }); runtimeAdd.setOnAction((e) -> { TextInputDialog dia = new TextInputDialog(); dia.setTitle("Add Runtime Argument"); dia.setHeaderText("Enter an argument"); dia.initOwner(stage); Optional<String> res = dia.showAndWait(); if (res.isPresent()) { runtimeList.getItems().add(res.get()); } }); runtimeRemove.setOnAction((e) -> { if (runtimeList.getSelectionModel().getSelectedItem() != null) { runtimeList.getItems().remove(runtimeList.getSelectionModel().getSelectedItem()); } }); preview.setOnAction((e) -> { if (!iconField.getText().isEmpty()) { if (iconField.getText().endsWith(".ico")) { List<BufferedImage> read = new ArrayList<>(); try { read.addAll(ICODecoder.read(new File(iconField.getText()))); } catch (IOException ex) { } if (read.size() >= 1) { Image im = SwingFXUtils.toFXImage(read.get(0), null); Stage st = new Stage(); st.initOwner(stage); st.initModality(Modality.APPLICATION_MODAL); st.setTitle("Icon Preview"); st.getIcons().add(Tachyon.icon); st.setScene(new Scene(new BorderPane(new ImageView(im)))); if (applyCss.get()) { st.getScene().getStylesheets().add(css); } st.showAndWait(); } } else if (iconField.getText().endsWith(".icns")) { try { BufferedImage ima = Imaging.getBufferedImage(new File(iconField.getText())); if (ima != null) { Image im = SwingFXUtils.toFXImage(ima, null); Stage st = new Stage(); st.initOwner(stage); st.initModality(Modality.APPLICATION_MODAL); st.setTitle("Icon Preview"); st.getIcons().add(Tachyon.icon); st.setScene(new Scene(new BorderPane(new ImageView(im)))); if (applyCss.get()) { st.getScene().getStylesheets().add(css); } st.showAndWait(); } } catch (ImageReadException | IOException ex) { } } else { Image im = new Image(new File(iconField.getText()).toURI().toString()); Stage st = new Stage(); st.initOwner(stage); st.initModality(Modality.APPLICATION_MODAL); st.setTitle("Icon Preview"); st.getIcons().add(Tachyon.icon); st.setScene(new Scene(new BorderPane(new ImageView(im)))); if (applyCss.get()) { st.getScene().getStylesheets().add(css); } st.showAndWait(); } } }); selectIm.setOnAction((e) -> { FileChooser fc = new FileChooser(); fc.setTitle("Icon File"); String OS = System.getProperty("os.name").toLowerCase(); fc.getExtensionFilters().add(new ExtensionFilter("Icon File", OS.contains("win") ? getWindowsImageExtensions() : getMacImageExtensions())); fc.setSelectedExtensionFilter(fc.getExtensionFilters().get(0)); File lf = fc.showOpenDialog(stage); if (lf != null) { iconField.setText(lf.getAbsolutePath()); } }); addJar.setOnAction((e) -> { FileChooser f = new FileChooser(); f.setTitle("External Libraries"); f.setSelectedExtensionFilter(new ExtensionFilter("Jar Files", "*.jar")); List<File> showOpenMultipleDialog = f.showOpenMultipleDialog(stage); if (showOpenMultipleDialog != null) { for (File fi : showOpenMultipleDialog) { if (!libsView.getItems().contains(fi.getAbsolutePath())) { libsView.getItems().add(fi.getAbsolutePath()); } } } }); removeJar.setOnAction((e) -> { String selected = libsView.getSelectionModel().getSelectedItem(); if (selected != null) { libsView.getItems().remove(selected); } }); select.setOnAction((e) -> { List<String> all = getAll(); ChoiceDialog<String> di = new ChoiceDialog<>(project.getMainClassName(), all); di.setTitle("Select Main Class"); di.initOwner(stage); di.setHeaderText("Select A Main Class"); Optional<String> show = di.showAndWait(); if (show.isPresent()) { mainClass.setText(show.get()); } }); cancel.setOnAction((e) -> { stage.close(); }); confirm.setOnAction((e) -> { project.setMainClassName(mainClass.getText()); project.setFileIconPath(iconField.getText()); project.setRuntimeArguments(runtimeList.getItems()); HashMap<String, String> al = new HashMap<>(); for (String s : compileList.getItems()) { String[] spl = s.split(":"); al.put(spl[0], spl[1]); } project.setCompileTimeArguments(al); project.setAllLibs(libsView.getItems()); stage.close(); }); }
From source file:com.esri.geoevent.test.performance.ui.OrchestratorController.java
/** * Displays a file chooser to select a file location to save the * configuration file./*from w w w. ja va2s . c o m*/ */ private void saveFixturesFile() { File currentDir = Paths.get("").toAbsolutePath().toFile(); FileChooser fileChooser = new FileChooser(); fileChooser.setTitle(UIMessages.getMessage("UI_SAVE_FILE_CHOOSER_TITLE")); fileChooser.setInitialDirectory(currentDir); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("XML", "*.xml")); fileChooser.setInitialFileName(DEFAULT_FIXTURES_FILE); File file = fileChooser.showSaveDialog(stage); if (file != null) { try { saveFile(file); } catch (Exception error) { //TODO: Improve error handling and reporting error.printStackTrace(); } } }
From source file:com.esri.geoevent.test.performance.ui.OrchestratorController.java
/** * Displays a file chooser to select a file to open *//* w w w. j av a2 s . co m*/ private void openFixturesFile() { File currentDir = Paths.get("").toAbsolutePath().toFile(); FileChooser fileChooser = new FileChooser(); fileChooser.setTitle(UIMessages.getMessage("UI_OPEN_FILE_CHOOSER_TITLE")); fileChooser.setInitialDirectory(currentDir); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("XML", "*.xml")); fileChooser.setInitialFileName(DEFAULT_FIXTURES_FILE); File file = fileChooser.showOpenDialog(stage); if (file != null) { try { loadFile(file); setupTabs(); } catch (Exception error) { //TODO: Improve error handling and reporting error.printStackTrace(); } } }
From source file:de.ks.text.AsciiDocEditor.java
@FXML void saveToFile() { FileChooser fileChooser = new FileChooser(); FileChooser.ExtensionFilter htmlFilter = new FileChooser.ExtensionFilter("html", "html"); FileChooser.ExtensionFilter adocFilter = new FileChooser.ExtensionFilter("adoc", "adoc"); fileChooser.getExtensionFilters().add(htmlFilter); fileChooser.getExtensionFilters().add(adocFilter); if (lastFile != null) { fileChooser.setInitialDirectory(lastFile.getParentFile()); fileChooser.setInitialFileName(lastFile.getName()); if (lastFile.getName().endsWith(".html")) { fileChooser.setSelectedExtensionFilter(htmlFilter); } else {//from w w w . j ava 2 s. c o m fileChooser.setSelectedExtensionFilter(adocFilter); } } else { fileChooser.setInitialFileName("export.html"); } File file = fileChooser.showSaveDialog(saveToFileButton.getScene().getWindow()); if (file == null) { return; } this.lastFile = file; String extension = fileChooser.getSelectedExtensionFilter().getExtensions().get(0); if (!file.getName().endsWith(extension)) { file = new File(file.getPath() + extension); } if (extension.endsWith("adoc")) { try { Files.write(editor.getText(), file, Charsets.UTF_8); } catch (IOException e) { log.error("Could not write file {}", file, e); } } else { this.parser.renderToFile(editor.getText(), AsciiDocBackend.HTML5, file); } }
From source file:acmi.l2.clientmod.xdat.Controller.java
@FXML private void saveAs() { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Save"); fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("XDAT (*.xdat)", "*.xdat"), new FileChooser.ExtensionFilter("All files", "*.*")); fileChooser.setInitialFileName(xdatFile.getValue().getName()); if (initialDirectory.getValue() != null && initialDirectory.getValue().exists() && initialDirectory.getValue().isDirectory()) fileChooser.setInitialDirectory(initialDirectory.getValue()); File file = fileChooser.showSaveDialog(editor.getStage()); if (file == null) return;/*from ww w . j a va 2s . c om*/ this.xdatFile.setValue(file); initialDirectory.setValue(file.getParentFile()); save(); }
From source file:com.rvantwisk.cnctools.controllers.CNCToolsController.java
@FXML public void generateGCode(ActionEvent event) throws Exception { if (v_projectList.getSelectionModel().selectedItemProperty().get() != null) { final Project p = v_projectList.getSelectionModel().selectedItemProperty().get(); if (p.postProcessorProperty().get() == null) { MonologFX dialog = new MonologFX(MonologFX.Type.QUESTION); dialog.setTitleText("No postprocessor"); dialog.setMessage("No post processor configured, please select a post processor first!"); dialog.show();/* www. j a v a 2 s .c o m*/ } else { final GCodeCollection gCode = p.getGCode(toolDBManager); gCode.merge(); FileChooser fileChooser = new FileChooser(); fileChooser.getExtensionFilters() .addAll(new FileChooser.ExtensionFilter("NC File", "*.tap", "*.ngc")); fileChooser.setTitle("Save GCode"); File choosenName = fileChooser.showSaveDialog(null); if (choosenName != null) { choosenName.delete(); if (!p.getPostProcessor().isHasToolChanger()) { final GCodeCollection.GeneratedGCode preAmble = gCode.get(0); final GCodeCollection.GeneratedGCode postAmble = gCode.get(gCode.size() - 1); for (int i = 1; i <= (gCode.size() - 2); i++) { final String[] path = choosenName.getPath().split("\\.(?=[^\\.]+$)"); File thisSet = new File(path[0] + "-" + i + "." + path[1]); thisSet.delete(); // Concate all g-code String file = preAmble.getGCode().toString() + SEPERATOR + gCode.get(i).getGCode().toString() + SEPERATOR + postAmble.getGCode().toString() + SEPERATOR; saveGCode(file, thisSet); } } else { saveGCode(gCode.concate().toString(), choosenName); } } } } }
From source file:mesclasses.view.RapportEleveController.java
@FXML public void importFile() { FileChooser chooser = new FileChooser(); PropertiesCache cache = PropertiesCache.getInstance(); String lastDir = cache.getProperty(PropertiesCache.LAST_UPLOAD_DIR); if (lastDir != null && new File(lastDir).exists()) { chooser.setInitialDirectory(new File(lastDir)); }/*w ww .ja va2s . c o m*/ chooser.getExtensionFilters().addAll(new ExtensionFilter("All Files", "*.*")); chooser.setTitle("Slectionnez un fichier"); File file = chooser.showOpenDialog(primaryStage); if (file == null) { return; } cache.setProperty(PropertiesCache.LAST_UPLOAD_DIR, file.getParent()); try { EleveFileUtil.copyFileForEleve(eleve, file, selectedFileType.get()); } catch (IOException e) { ModalUtil.alert("Erreur lors de l'import du fichier", e.getMessage()); return; } refreshGrid(); }