Search in sources :

Example 31 with FileChooser

use of javafx.stage.FileChooser in project bitsquare by bitsquare.

the class TraderDisputeView method onOpenAttachment.

private void onOpenAttachment(Attachment attachment) {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Save file to disk");
    fileChooser.setInitialFileName(attachment.getFileName());
    /* if (Utilities.isUnix())
            fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));*/
    File file = fileChooser.showSaveDialog(stage);
    if (file != null) {
        try (FileOutputStream fileOutputStream = new FileOutputStream(file.getAbsolutePath())) {
            fileOutputStream.write(attachment.getBytes());
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) FileChooser(javafx.stage.FileChooser) IOException(java.io.IOException) File(java.io.File)

Example 32 with FileChooser

use of javafx.stage.FileChooser in project mybatis-generator-gui-extension by spawpaw.

the class FileChooserControl method bindProperties.

@Override
protected void bindProperties() {
    label.setMinWidth(MIN_WIDTH_LEFT);
    textField.textProperty().bindBidirectional(value);
    label.textProperty().bindBidirectional(this.labelTextProperty);
    button.setOnMouseClicked((event -> {
        FileChooser fileChooser = new FileChooser();
        File selectedFile = fileChooser.showOpenDialog(BaseController.primaryStage);
        if (selectedFile != null) {
            value.setValue(selectedFile.getAbsolutePath());
        }
    }));
}
Also used : Button(javafx.scene.control.Button) FileChooser(javafx.stage.FileChooser) TextField(javafx.scene.control.TextField) Label(javafx.scene.control.Label) BaseController(com.spawpaw.mybatis.generator.gui.controller.BaseController) File(java.io.File) FileChooser(javafx.stage.FileChooser) File(java.io.File)

Example 33 with FileChooser

use of javafx.stage.FileChooser in project bitsquare by bitsquare.

the class GUIUtil method exportCSV.

public static <T> void exportCSV(String fileName, CSVEntryConverter<T> headerConverter, CSVEntryConverter<T> contentConverter, T emptyItem, List<T> list, Stage stage) {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setInitialFileName(fileName);
    File file = fileChooser.showSaveDialog(stage);
    try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(file, false), Charsets.UTF_8)) {
        CSVWriter<T> headerWriter = new CSVWriterBuilder<T>(outputStreamWriter).strategy(CSVStrategy.UK_DEFAULT).entryConverter(headerConverter).build();
        headerWriter.write(emptyItem);
        CSVWriter<T> contentWriter = new CSVWriterBuilder<T>(outputStreamWriter).strategy(CSVStrategy.UK_DEFAULT).entryConverter(contentConverter).build();
        contentWriter.writeAll(list);
    } catch (RuntimeException | IOException e) {
        e.printStackTrace();
        log.error(e.getMessage());
        new Popup().error("Exporting to CSV failed because of an error.\n" + "Error = " + e.getMessage());
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) Popup(io.bitsquare.gui.main.overlays.popups.Popup) FileChooser(javafx.stage.FileChooser) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File)

Example 34 with FileChooser

use of javafx.stage.FileChooser in project jgnash by ccavanaugh.

the class BudgetViewController method handleExportAction.

@FXML
private void handleExportAction() {
    Objects.requireNonNull(budgetTableController);
    final Preferences pref = Preferences.userNodeForPackage(BudgetViewController.class);
    final FileChooser fileChooser = new FileChooser();
    fileChooser.setInitialDirectory(new File(pref.get(EXPORT_DIR, System.getProperty("user.home"))));
    fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter(resources.getString("Label.SpreadsheetFiles") + " (*.xls, *.xlsx)", "*.xls", "*.xlsx"));
    final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
    if (file != null) {
        pref.put(EXPORT_DIR, file.getParentFile().getAbsolutePath());
        final Task<Void> exportTask = new Task<Void>() {

            @Override
            protected Void call() throws Exception {
                updateMessage(resources.getString("Message.PleaseWait"));
                updateProgress(-1, Long.MAX_VALUE);
                BudgetResultsExport.exportBudgetResultsModel(file.toPath(), budgetTableController.getBudgetResultsModel());
                return null;
            }
        };
        new Thread(exportTask).start();
        StaticUIMethods.displayTaskProgress(exportTask);
    }
}
Also used : Task(javafx.concurrent.Task) FileChooser(javafx.stage.FileChooser) Preferences(java.util.prefs.Preferences) File(java.io.File) FXML(javafx.fxml.FXML)

Example 35 with FileChooser

use of javafx.stage.FileChooser in project jgnash by ccavanaugh.

the class AttachmentPane method attachmentAction.

private void attachmentAction() {
    final Preferences pref = Preferences.userNodeForPackage(this.getClass());
    final String baseFile = EngineFactory.getActiveDatabase();
    final List<String> extensions = new ArrayList<>();
    for (final String suffix : ImageIO.getReaderFileSuffixes()) {
        extensions.add("*." + suffix);
    }
    final FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle(resources.getString("Title.SelFile"));
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(resources.getString("Title.ImageFiles"), extensions));
    final String lastDirectory = pref.get(LAST_DIR, null);
    if (lastDirectory != null) {
        fileChooser.setInitialDirectory(new File(lastDirectory));
    }
    if (attachment.get() != null) {
        final Path path = attachment.get().getFileName();
        if (path != null) {
            fileChooser.setInitialFileName(path.toString());
        }
    }
    final File selectedFile = fileChooser.showOpenDialog(MainView.getPrimaryStage());
    if (selectedFile != null) {
        // save last good directory location
        pref.put(LAST_DIR, selectedFile.getParent());
        boolean result = true;
        // TODO, add option to copy the file instead of moving it
        final Path attachmentDirectory = AttachmentUtils.getAttachmentDirectory(Paths.get(baseFile));
        if (baseFile.startsWith(EngineFactory.REMOTE_PREFIX)) {
            // working remotely
            moveAttachment = true;
        } else if (attachmentDirectory != null && !attachmentDirectory.toString().equals(selectedFile.getParent())) {
            String message = ResourceUtils.getString("Message.Warn.MoveFile", selectedFile.toString(), attachmentDirectory.toString());
            if (!StaticUIMethods.showConfirmationDialog(resources.getString("Title.MoveFile"), message).getButtonData().isCancelButton()) {
                moveAttachment = true;
                final Path newPath = Paths.get(AttachmentUtils.getAttachmentDirectory(Paths.get(baseFile)) + FileUtils.separator + selectedFile.getName());
                if (Files.exists(newPath)) {
                    message = ResourceUtils.getString("Message.Warn.SameFile", selectedFile.toString(), attachmentDirectory.toString());
                    StaticUIMethods.displayWarning(message);
                    moveAttachment = false;
                    result = false;
                }
            } else {
                result = false;
            }
        }
        if (result) {
            attachment.set(selectedFile.toPath());
        }
    }
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) FileChooser(javafx.stage.FileChooser) Preferences(java.util.prefs.Preferences) File(java.io.File)

Aggregations

FileChooser (javafx.stage.FileChooser)65 File (java.io.File)60 Preferences (java.util.prefs.Preferences)21 IOException (java.io.IOException)17 ResourceBundle (java.util.ResourceBundle)11 FXML (javafx.fxml.FXML)11 FileOutputStream (java.io.FileOutputStream)5 ArrayList (java.util.ArrayList)5 Alert (javafx.scene.control.Alert)5 Button (javafx.scene.control.Button)5 Popup (io.bitsquare.gui.main.overlays.popups.Popup)3 List (java.util.List)3 GargoyleFileAlreadyExistException (com.kyj.fx.voeditor.visual.exceptions.GargoyleFileAlreadyExistException)2 Palette (fractal.Palette)2 Path (java.nio.file.Path)2 ObservableList (javafx.collections.ObservableList)2 FilteredList (javafx.collections.transformation.FilteredList)2 SortedList (javafx.collections.transformation.SortedList)2 Task (javafx.concurrent.Task)2 Insets (javafx.geometry.Insets)2