List of usage examples for javafx.stage FileChooser FileChooser
FileChooser
From source file:com.coolchick.translatortemplater.Main.java
public boolean spitNewDatabase() { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Choose destination"); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JSON file(*.json)", "*.json")); File file = fileChooser.showSaveDialog(getStage()); return file != null && spitDatabase(file); }
From source file:com.esri.geoevent.test.performance.ui.ReportOptionsController.java
/** * Allows the user to select a report file to used when the reporting is * done./*from w w w . jav a2 s. co m*/ * * @param event {@link ActionEvent} not used. */ @FXML private void chooseReportFile(final ActionEvent event) { File currentDir = Paths.get("").toAbsolutePath().toFile(); String reportTypeStr = report.getType().toString(); FileChooser fileChooser = new FileChooser(); fileChooser.setTitle(UIMessages.getMessage("UI_REPORT_FILE_CHOOSER_TITLE")); fileChooser.setInitialDirectory(currentDir); fileChooser.getExtensionFilters() .add(new FileChooser.ExtensionFilter(reportTypeStr, "*." + reportTypeStr.toLowerCase())); fileChooser.setInitialFileName(DEFAULT_REPORT_FILE_NAME + "." + reportTypeStr.toLowerCase()); File file = fileChooser.showSaveDialog(dialogStage); if (file != null) { updateSelectedReportFile(file.getAbsolutePath()); } }
From source file:com.mycompany.trafficimportfileconverter2.Main2Controller.java
/** * Initializes the controller class.// w ww. j a v a2 s.c om */ @Override public void initialize(URL url, ResourceBundle rb) { prefs = Preferences.userNodeForPackage(this.getClass()); initDateArrays(); dirchooser = new DirectoryChooser(); outputDir.addListener(new ChangeListener<File>() { @Override public void changed(ObservableValue<? extends File> observable, File oldValue, File newValue) { lblOutputLoc.setText(newValue.getAbsolutePath()); prefs.put(OUTPUT_DIR_LOC, newValue.getAbsolutePath()); } }); setOutputDir(safeFileSet(new File(prefs.get(OUTPUT_DIR_LOC, "./")))); try { dirchooser.setInitialDirectory(getOutputDir()); } catch (Exception e) { System.out.println("Error setting init dir: " + e); e.printStackTrace(); } filechooser = new FileChooser(); try { filechooser.setInitialDirectory(new File(prefs.get(INPUT_DIR_LOC, "./"))); } catch (Exception e) { System.out.println("Error setting init directory of file chooser: " + e); e.printStackTrace(); } setExtension(prefs.get(EXTENSION, ".gen")); /* Save in preferences default getting file location every time the input file is reselected. */ inputFile.addListener(new ChangeListener<File>() { @Override public void changed(ObservableValue<? extends File> observable, File oldValue, File newValue) { lblInputFile.setText(newValue.getAbsolutePath()); prefs.put(INPUT_DIR_LOC, newValue.getParent()); reloadFileData(newValue); } }); txtAreaOutput.textProperty().addListener(new ChangeListener<Object>() { @Override public void changed(ObservableValue<?> observable, Object oldValue, Object newValue) { txtAreaOutput.setScrollTop(Double.MAX_VALUE); //this will scroll to the bottom //use Double.MIN_VALUE to scroll to the top } }); filechooser.getExtensionFilters().add(new ExtensionFilter("Tab Separated Values", "*.tsv", "*.TSV")); autoSearch(); log("Help document located:"); log(helpurl); }
From source file:com.rvantwisk.cnctools.operations.customgcode.CustomGCodeController.java
public void selectFile(ActionEvent actionEvent) { FileChooser fileChooser = new FileChooser(); fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("NC File", "*.tap", "*.ngc")); fileChooser.setTitle("Load GCode"); File file = fileChooser.showOpenDialog(null); if (file != null) { try {/* w w w. j a v a2s. c om*/ model.setGcode(ProjectModel.readFileIntoString(file)); model.setgCodeFile(file.getAbsolutePath()); iFileName.setText(model.getgCodeFile()); gCodeText.setText(model.getGcode()); } catch (IOException ex) { System.out.println(ex.getMessage()); } } }
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();/*from w w w. j ava 2 s .c om*/ } 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:ipat_fx.FXMLDocumentController.java
@FXML private void chooseFiles(ActionEvent event) { int numOfProfiles = Integer.parseInt(noOfProfiles.getText()); if (numOfProfiles > 8) { JOptionPane.showMessageDialog(null, "Please set the number of Profiles to be less than 8."); } else if (problemDataFolderName == null) { JOptionPane.showMessageDialog(null, "Please first select a case from the cases tab in the menu bar.\n" + "If no cases exist, ensure the candidate solutions are correctly entered in the /web/data folder."); } else {/* w w w.ja va 2 s. co m*/ FileChooser chooser = new FileChooser(); List<File> uploads = chooser.showOpenMultipleDialog(null); uploads.stream().forEach((fi) -> { File file; String fileName = fi.getName(); File input = new File(dataPath + "/input/"); input.mkdirs(); File output = new File(dataPath + "/output/"); output.mkdirs(); if (fileName.lastIndexOf("\\") >= 0) { file = new File(input.getAbsolutePath() + "/" + fileName.substring(fileName.lastIndexOf("/"))); } else { file = new File( input.getAbsolutePath() + "/" + fileName.substring(fileName.lastIndexOf("/") + 1)); } try { OutputStream outStream; try (InputStream inStream = new FileInputStream(fi)) { outStream = new FileOutputStream(file); byte[] buffer = new byte[1024]; int fileLength; while ((fileLength = inStream.read(buffer)) > 0) { outStream.write(buffer, 0, fileLength); } } outStream.close(); } catch (IOException ex) { Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, "Error loading file see mainframe ", ex); } }); try { controller = new Controller(inputFolder, outputFolder, profilePath, hintsXML, problemDataFolderName); HashMap<String, Object> display = controller.initialisation(); WebView previewView = (WebView) display.get("previewView"); previewPane.getChildren().add(previewView); @SuppressWarnings("unchecked") HashMap<String, ArrayList<GridPane>> map = (HashMap<String, ArrayList<GridPane>>) display .get("results"); byProfileTab = getByProfile(map, numOfProfiles); byProfilePane.setCenter(byProfileTab); tabPane.getSelectionModel().select(0); tabFlag = "byProfile"; tabPane.getSelectionModel().selectedIndexProperty() .addListener((ObservableValue<? extends Number> ov, Number oldValue, Number newValue) -> { if (newValue == Number.class.cast(1)) { tabFlag = "byImage"; byImageTab = getByImage(map); byImagePane.setCenter(byImageTab); } else if (newValue == Number.class.cast(0)) { tabFlag = "byProfile"; byProfileTab = getByProfile(map, numOfProfiles); byProfilePane.setCenter(byProfileTab); } else { System.out.println("Error this tab has not been created."); } }); } catch (IOException ex) { Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:org.craftercms.social.migration.controllers.MainController.java
@Override public void initialize(final URL location, final ResourceBundle resources) { configTable();// w w w . j a va 2 s . co m mnuQuit.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { stopTasks(); Platform.exit(); } }); ctxClearLog.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { logTable.getItems().clear(); } }); ctxClearProfileSelection.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { lstProfileScripts.getSelectionModel().clearSelection(); } }); ctxClearSocialSelection.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { lstSocialScripts.getSelectionModel().clearSelection(); } }); lstProfileScripts.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); lstSocialScripts.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); lstProfileScripts.setCellFactory(new Callback<ListView, ListCell>() { @Override public ListCell call(final ListView listView) { return new FileListCell(); } }); lstSocialScripts.setCellFactory(new Callback<ListView, ListCell>() { @Override public ListCell call(final ListView listView) { return new FileListCell(); } }); ctxReloadProfileScrp.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { lstProfileScripts.getItems().clear(); try { extractBuildInScripts("profile", lstProfileScripts); } catch (MigrationException e) { log.error("Unable to extract BuildIn scripts"); } loadScripts(MigrationTool.systemProperties.getString("crafter.migration.profile.scripts"), lstProfileScripts); } }); ctxReloadSocialScrp.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { lstSocialScripts.getItems().clear(); try { extractBuildInScripts("profile", lstSocialScripts); } catch (MigrationException e) { log.error("Unable to extract BuildIn scripts"); } loadScripts(MigrationTool.systemProperties.getString("crafter.migration.social.scripts"), lstSocialScripts); } }); final MigrationSelectionAction selectionEventHandler = new MigrationSelectionAction(); rbtMigrateProfile.setOnAction(selectionEventHandler); rbtMigrateSocial.setOnAction(selectionEventHandler); loadScripts(); loadDefaultValues(); saveLog.setAccelerator(new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN)); saveLog.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent event) { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Save Migration Log"); fileChooser.setInitialFileName("Crafter-Migration-" + new SimpleDateFormat("yyyy-MM-dd@HH_mm").format(new Date()) + ".html"); final File savedFile = fileChooser.showSaveDialog(scene.getWindow()); if (savedFile == null) { return; } try { getHtml(new FileWriter(savedFile)); log.info("Saved Html log file"); } catch (IOException | TransformerException ex) { log.error("Unable to save file", ex); } } }); mnuStart.setAccelerator(new KeyCodeCombination(KeyCode.F5)); mnuStart.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent event) { if (currentTask == null || !currentTask.isRunning()) { ObservableList scriptsToRun; if (rbtMigrateProfile.isSelected()) { scriptsToRun = lstProfileScripts.getSelectionModel().getSelectedItems(); } else { scriptsToRun = lstSocialScripts.getSelectionModel().getSelectedItems(); } currentTask = new MigrationPipeService(logTable, pgbTaskProgress, srcHost.getText(), srcPort.getText(), srcDb.getText(), dstHost.getText(), dstPort.getText(), dstDb.getText(), scriptsToRun); } if (!currentTask.isRunning()) { final Thread t = new Thread(currentTask, "Migration Task"); t.start(); } } }); }
From source file:org.cryptomator.ui.controllers.MainController.java
@FXML private void didClickCreateNewVault(ActionEvent event) { final FileChooser fileChooser = new FileChooser(); final File file = fileChooser.showSaveDialog(mainWindow); if (file == null) { return;/*from w w w . j av a 2 s . com*/ } try { final Path vaultDir = file.toPath(); if (!Files.exists(vaultDir)) { Files.createDirectory(vaultDir); } addVault(vaultDir, true); } catch (IOException e) { LOG.error("Unable to create vault", e); } }
From source file:de.ks.file.FileViewController.java
@FXML void addNewFile(ActionEvent event) { FileChooser fileChooser = new FileChooser(); File file = fileChooser.showOpenDialog(edit.getScene().getWindow()); if (file != null) { addFiles(Arrays.asList(file)); }/*from w w w .j a v a 2 s . c om*/ }
From source file:org.cryptomator.ui.controllers.MainController.java
@FXML private void didClickAddExistingVaults(ActionEvent event) { final FileChooser fileChooser = new FileChooser(); fileChooser.getExtensionFilters()/*from www.jav a 2s . c o m*/ .add(new FileChooser.ExtensionFilter("Cryptomator Masterkey", "*" + Vault.VAULT_FILE_EXTENSION)); final List<File> files = fileChooser.showOpenMultipleDialog(mainWindow); if (files != null) { for (final File file : files) { addVault(file.toPath(), false); } } }