List of usage examples for javafx.stage FileChooser FileChooser
FileChooser
From source file:org.noroomattheinn.visibletesla.MainController.java
private void exportCycles(String cycleType) { String initialDir = prefs.storage().get(App.LastExportDirKey, System.getProperty("user.home")); FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export " + cycleType + " Data"); fileChooser.setInitialDirectory(new File(initialDir)); Stage stage = app.stage;//from w w w. j a v a2 s .c o m File file = fileChooser.showSaveDialog(stage); if (file != null) { String enclosingDirectory = file.getParent(); if (enclosingDirectory != null) prefs.storage().put(App.LastExportDirKey, enclosingDirectory); Range<Long> exportPeriod = DateRangeDialog.getExportPeriod(stage); if (exportPeriod == null) return; boolean exported; if (cycleType.equals("Charge")) { exported = vtData.exportCharges(file, exportPeriod); } else { exported = vtData.exportRests(file, exportPeriod); } if (exported) { Dialogs.showInformationDialog(stage, "Your data has been exported", "Data Export Process", "Export Complete"); } else { Dialogs.showErrorDialog(stage, "Unable to save to: " + file, "Data Export Process", "Export Failed"); } } }
From source file:view.FXApplicationController.java
@FXML protected void exportHypnogrammAction() { FileChooser fileChooser = new FileChooser(); //Open directory from existing directory File dir = null;//from w w w. j ava 2 s . c om dir = tools.Util.loadDir(new File( new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile(), "LastDirectory.txt")); if (dir != null) { fileChooser.setInitialDirectory(dir); } //Set extension filter FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("TXT files (*.txt)", "*.txt"); fileChooser.getExtensionFilters().add(extFilter); //Show save file dialog File file = fileChooser.showSaveDialog(primaryStage); Util.saveDir(file, new File( new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile(), "LastDirectory.txt")); if (file != null) { featureController.saveFile(file); } }
From source file:com.github.drbookings.ui.controller.MainController.java
private void openFile() { if (logger.isDebugEnabled()) { logger.debug("Opening DrBookings xml"); }/*from www . j av a 2 s. co m*/ final FileChooser fileChooser = new FileChooser(); final File file = SettingsManager.getInstance().getDataFile(); fileChooser.setInitialDirectory(file.getParentFile()); fileChooser.getExtensionFilters().addAll( new FileChooser.ExtensionFilter("Dr.BookingBean BookingBean Data", Arrays.asList("*.xml", "*.XML")), new FileChooser.ExtensionFilter("All Files", "*")); fileChooser.setTitle("Open Resource File"); fileChooser.setInitialFileName(file.getName()); final File file2 = fileChooser.showOpenDialog(node.getScene().getWindow()); if (file2 != null) { readDataFile(file2); } }
From source file:ui.main.MainViewController.java
private void sendImage() { if (!contactsManager.getAvailabilityforSharing(currentChat.getParticipant())) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Attention!"); alert.setHeaderText("The user is not available!"); alert.setContentText("The file receiving user should be available online to receive the file."); alert.showAndWait();// www . j a va 2s . c o m return; } ItemType type = contactsManager.getUserType(currentChat.getParticipant()); if (type.equals(ItemType.none)) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Attention!"); alert.setHeaderText("The is not available for you!"); alert.setContentText( "The user has not accepted the Friend Request." + " The user is not available for you."); alert.showAndWait(); return; } else if (type.equals(ItemType.from)) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Attention!"); alert.setHeaderText("The user has not accepted!"); alert.setContentText("The user has not accepted the Friend Request." + " You can not send any messages until the user accepts the friend request."); alert.showAndWait(); return; } else if (type.equals(ItemType.to)) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle("Attention!"); alert.setHeaderText("The user has not accepted!"); alert.setContentText("The user has not accepted the Friend Request." + " You can not send any messages until the user accepts the friend request."); alert.showAndWait(); return; } try { FileChooser fc = new FileChooser(); fc.setTitle("Choose an image to send"); fc.getExtensionFilters().addAll( new FileChooser.ExtensionFilter("All Images", "*.jpg*", "*.png", "*.bmp"), new FileChooser.ExtensionFilter("JPG", "*.jpg"), new FileChooser.ExtensionFilter("PNG", "*.png"), new FileChooser.ExtensionFilter("BMP", "*.bmp")); File file = fc.showOpenDialog(presence.getScene().getWindow()); if (file == null) { return; } BufferedImage image = ImageIO.read(file); Thread t = new Thread(new Runnable() { @Override public void run() { try { fileManager.sendFile(file, currentChat.getParticipant()); if (history.isSelected()) { Timestamp time = new Timestamp(System.currentTimeMillis()); DBSingleChat.savePictureMessage(currentChat.getParticipant(), false, file.getPath(), time); } paintSentPhoto(currentChat, file, dtfT.print(DateTime.now())); Task tt = new Task() { @Override protected Object call() throws Exception { Thread.sleep(500); return new Object(); } }; tt.setOnSucceeded(value -> scrollPane.setVvalue(scrollPane.getHmax())); Thread thread1 = new Thread(tt); thread1.start(); } catch (FileNotFoundException ex) { Alert alert = new Alert(Alert.AlertType.ERROR); alert.setTitle("IMP"); alert.setHeaderText("File is not Found!"); alert.setContentText("File you selected does not exist."); alert.showAndWait(); return; } } }); t.start(); } catch (IOException ex) { Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:view.FXApplicationController.java
@FXML protected void saveAsAction() { FileChooser fileChooser = new FileChooser(); //Open directory from existing directory File dir = null;/*from w w w .java 2s . c o m*/ dir = tools.Util.loadDir(new File( new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile(), "LastDirectory.txt")); if (dir != null) { fileChooser.setInitialDirectory(dir); } //Set extension filter FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("AS files (*.as)", "*.as"); fileChooser.getExtensionFilters().add(extFilter); //Show save file dialog File file = fileChooser.showSaveDialog(primaryStage); Util.saveDir(file, new File( new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile(), "LastDirectory.txt")); if (file != null) { featureModel.setProjectFile(file); ModelReaderWriterController modelReaderWriter = new ModelReaderWriterController(featureModel, file, true); modelReaderWriter.start(); } }
From source file:org.noroomattheinn.visibletesla.MainController.java
private void exportStats(String[] columns) { String initialDir = prefs.storage().get(App.LastExportDirKey, System.getProperty("user.home")); FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export Data"); fileChooser.setInitialDirectory(new File(initialDir)); File file = fileChooser.showSaveDialog(app.stage); if (file != null) { String enclosingDirectory = file.getParent(); if (enclosingDirectory != null) prefs.storage().put(App.LastExportDirKey, enclosingDirectory); Range<Long> exportPeriod = DateRangeDialog.getExportPeriod(app.stage); if (exportPeriod == null) return; if (vtData.export(file, exportPeriod, columns)) { Dialogs.showInformationDialog(app.stage, "Your data has been exported", "Data Export Process", "Export Complete"); } else {/* www . j a va 2s.co m*/ Dialogs.showErrorDialog(app.stage, "Unable to save to: " + file, "Data Export Process", "Export Failed"); } } }
From source file:com.cdd.bao.editor.EditSchema.java
public void actionFileSave(boolean promptNew) { pullDetail();/* w w w.j av a 2 s . c o m*/ // dialog in case filename is missing or requested as save-to-other if (promptNew || schemaFile == null) { FileChooser chooser = new FileChooser(); chooser.setTitle("Save Schema Template"); if (schemaFile != null) chooser.setInitialDirectory(schemaFile.getParentFile()); File file = chooser.showSaveDialog(stage); if (file == null) return; if (!file.getName().endsWith(".ttl")) file = new File(file.getAbsolutePath() + ".ttl"); schemaFile = file; updateTitle(); } // validity checking if (schemaFile == null) return; if (!schemaFile.getAbsoluteFile().getParentFile().canWrite() || (schemaFile.exists() && !schemaFile.canWrite())) { Util.informMessage("Cannot Save", "Not able to write to file: " + schemaFile.getAbsolutePath()); return; } // serialise-to-file Schema schema = stack.peekSchema(); try { //schema.serialise(System.out); OutputStream ostr = new FileOutputStream(schemaFile); ModelSchema.serialise(schema, ostr); ostr.close(); stack.setDirty(false); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
private void saveLayoutAsImage() { FileChooser fc = new FileChooser(); fc.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Portable Network Graphics(*.png)", Collections.singletonList("*.png"))); File output = fc.showSaveDialog(boundsLayoutNode.getScene().getWindow()); if (output == null) { return;//from ww w .j a v a 2 s . com } else { String fn = output.getName(); if (!fn.toLowerCase().endsWith(".png")) { output = new File(output.getParent(), fn + ".png"); } } try { WritableImage wImg = boundsLayoutNode.snapshot(null, null); //WritableImage wImg = mainRect.snapshot(null, null); BufferedImage bImg = SwingFXUtils.fromFXImage(wImg, null); ImageIO.write(bImg, "png", output); } catch (IOException e) { e.printStackTrace(); } }
From source file:acmi.l2.clientmod.xdat.Controller.java
@FXML private void open() { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Open interface.xdat"); fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("XDAT (*.xdat)", "*.xdat"), new FileChooser.ExtensionFilter("All files", "*.*")); if (initialDirectory.getValue() != null && initialDirectory.getValue().exists() && initialDirectory.getValue().isDirectory()) fileChooser.setInitialDirectory(initialDirectory.getValue()); File selected = fileChooser.showOpenDialog(editor.getStage()); if (selected == null) return;//from w w w . j a va 2 s. c o m xdatFile.setValue(selected); initialDirectory.setValue(selected.getParentFile()); try { IOEntity xdat = editor.getXdatClass().getConstructor().newInstance(); editor.execute(() -> { CountingInputStream cis = new CountingInputStream( new BufferedInputStream(new FileInputStream(selected))); try (InputStream is = cis) { xdat.read(is); Platform.runLater(() -> editor.setXdatObject(xdat)); } catch (Exception e) { log.log(Level.WARNING, String.format("Read error before offset 0x%x", cis.getCount()), e); throw e; } return null; }, e -> Platform.runLater(() -> Dialogs.show(Alert.AlertType.ERROR, "Read error", null, "Try to choose another version"))); } catch (ReflectiveOperationException e) { log.log(Level.WARNING, "XDAT class should have empty public constructor", e); Dialogs.show(Alert.AlertType.ERROR, "ReflectiveOperationException", null, "XDAT class should have empty public constructor"); } }
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 w w.j a v a2s . 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(); } } }