Search in sources :

Example 26 with FileChooser

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

the class JasperViewerDialogController method handleSaveAction.

@FXML
private void handleSaveAction() {
    Preferences preferences = Preferences.userNodeForPackage(JasperViewerDialogController.class);
    final String lastDir = preferences.get(LAST_DIR, null);
    final FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle(ResourceUtils.getString("Title.SaveFile"));
    if (lastDir != null) {
        fileChooser.setInitialDirectory(new File(lastDir));
    }
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("PDF Document", "*.pdf", "*.PDF"));
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("ODT Document", "*.odt", "*.ODT"));
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("DOCX Document", "*.docx", "*.DOCX"));
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("XLSX Document", "*.xlsx", "*.XLSX"));
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("CSV Document", "*.csv", "*.CSV"));
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("RTF Document", "*.rtf", "*.RTF"));
    final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
    if (file != null) {
        preferences.put(LAST_DIR, file.getParent());
        switch(FileUtils.getFileExtension(file.getAbsolutePath()).toLowerCase(Locale.ROOT)) {
            case "pdf":
                try {
                    JasperExportManager.exportReportToPdfFile(jasperPrint.get(), file.getAbsolutePath());
                } catch (final JRException e) {
                    StaticUIMethods.displayException(e);
                }
                break;
            case "odt":
                try {
                    final JROdtExporter exporter = new JROdtExporter();
                    exporter.setExporterInput(new SimpleExporterInput(jasperPrint.get()));
                    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(file));
                    exporter.exportReport();
                } catch (final JRException e) {
                    StaticUIMethods.displayException(e);
                }
                break;
            case "docx":
                try {
                    final JRDocxExporter exporter = new JRDocxExporter();
                    exporter.setExporterInput(new SimpleExporterInput(jasperPrint.get()));
                    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(file));
                    exporter.exportReport();
                } catch (final JRException e) {
                    StaticUIMethods.displayException(e);
                }
                break;
            case "xlsx":
                try {
                    final JRXlsExporter exporter = new JRXlsExporter();
                    exporter.setExporterInput(new SimpleExporterInput(jasperPrint.get()));
                    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(file));
                    final SimpleXlsReportConfiguration configuration = new SimpleXlsReportConfiguration();
                    configuration.setOnePagePerSheet(false);
                    exporter.setConfiguration(configuration);
                    exporter.exportReport();
                } catch (final JRException e) {
                    StaticUIMethods.displayException(e);
                }
                break;
            case "csv":
                try {
                    final JRCsvExporter exporter = new JRCsvExporter();
                    exporter.setExporterInput(new SimpleExporterInput(jasperPrint.get()));
                    exporter.setExporterOutput(new SimpleWriterExporterOutput(file));
                    exporter.exportReport();
                } catch (final JRException e) {
                    StaticUIMethods.displayException(e);
                }
                break;
            case "rtf":
                try {
                    final JRRtfExporter exporter = new JRRtfExporter();
                    exporter.setExporterInput(new SimpleExporterInput(jasperPrint.get()));
                    exporter.setExporterOutput(new SimpleWriterExporterOutput(file));
                    exporter.exportReport();
                } catch (final JRException e) {
                    StaticUIMethods.displayException(e);
                }
                break;
            default:
        }
    }
}
Also used : SimpleXlsReportConfiguration(net.sf.jasperreports.export.SimpleXlsReportConfiguration) JROdtExporter(net.sf.jasperreports.engine.export.oasis.JROdtExporter) JRException(net.sf.jasperreports.engine.JRException) SimpleOutputStreamExporterOutput(net.sf.jasperreports.export.SimpleOutputStreamExporterOutput) JRCsvExporter(net.sf.jasperreports.engine.export.JRCsvExporter) SimpleExporterInput(net.sf.jasperreports.export.SimpleExporterInput) JRXlsExporter(net.sf.jasperreports.engine.export.JRXlsExporter) SimpleWriterExporterOutput(net.sf.jasperreports.export.SimpleWriterExporterOutput) FileChooser(javafx.stage.FileChooser) Preferences(java.util.prefs.Preferences) JRDocxExporter(net.sf.jasperreports.engine.export.ooxml.JRDocxExporter) File(java.io.File) JRRtfExporter(net.sf.jasperreports.engine.export.JRRtfExporter) FXML(javafx.fxml.FXML) InjectFXML(jgnash.uifx.util.InjectFXML)

Example 27 with FileChooser

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

the class ReportActions method exportBalanceByMonthCSVReport.

public static void exportBalanceByMonthCSVReport() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    final Preferences preferences = Preferences.userNodeForPackage(ReportActions.class);
    final FXMLUtils.Pair<BalanceByMonthOptionsDialogController> pair = FXMLUtils.load(BalanceByMonthOptionsDialogController.class.getResource("BalanceByMonthOptionsDialog.fxml"), ResourceUtils.getString("Title.ReportOptions"));
    pair.getController().forceDefaultCurrencyProperty().set(preferences.getBoolean(FORCE_CURRENCY, false));
    pair.getStage().setResizable(false);
    pair.getStage().showAndWait();
    final boolean vertical = pair.getController().isVertical();
    final boolean forceCurrency = pair.getController().forceDefaultCurrencyProperty().get();
    final Optional<LocalDate[]> optional = pair.getController().getDates();
    optional.ifPresent(localDates -> {
        final String lastDir = preferences.get(LAST_DIR, null);
        preferences.putBoolean(FORCE_CURRENCY, forceCurrency);
        final FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle(ResourceUtils.getString("Title.SaveFile"));
        if (lastDir != null) {
            fileChooser.setInitialDirectory(new File(lastDir));
        }
        fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("CSV", "*.csv"));
        final File file = fileChooser.showSaveDialog(MainView.getPrimaryStage());
        if (file != null) {
            preferences.put(LAST_DIR, file.getParent());
            final BalanceByMonthCSVReport report;
            if (forceCurrency) {
                report = new BalanceByMonthCSVReport(file.getAbsolutePath(), localDates[0], localDates[1], engine.getDefaultCurrency(), vertical, AccountBalanceDisplayManager::convertToSelectedBalanceMode);
            } else {
                report = new BalanceByMonthCSVReport(file.getAbsolutePath(), localDates[0], localDates[1], null, vertical, AccountBalanceDisplayManager::convertToSelectedBalanceMode);
            }
            report.run();
        }
    });
}
Also used : FXMLUtils(jgnash.uifx.util.FXMLUtils) BalanceByMonthCSVReport(jgnash.report.BalanceByMonthCSVReport) FileChooser(javafx.stage.FileChooser) Preferences(java.util.prefs.Preferences) File(java.io.File) Engine(jgnash.engine.Engine)

Example 28 with FileChooser

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

the class ImportMt940FxAction method showAndWait.

static void showAndWait() {
    final ResourceBundle resources = ResourceUtils.getBundle();
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    if (engine == null || engine.getRootAccount().getChildCount() == 0) {
        jgnash.ui.StaticUIMethods.displayError(resources.getString("Message.Error.CreateBasicAccounts"));
        return;
    }
    final FileChooser fileChooser = configureFileChooser();
    fileChooser.setTitle(resources.getString("Title.SelFile"));
    final File file = fileChooser.showOpenDialog(MainView.getPrimaryStage());
    if (file != null) {
        Preferences pref = Preferences.userNodeForPackage(ImportMt940FxAction.class);
        pref.put(LAST_DIR, file.getParentFile().getAbsolutePath());
        new Thread(new ImportTask(file)).start();
    }
}
Also used : FileChooser(javafx.stage.FileChooser) ResourceBundle(java.util.ResourceBundle) Preferences(java.util.prefs.Preferences) File(java.io.File) Engine(jgnash.engine.Engine)

Example 29 with FileChooser

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

the class ImportMt940FxAction method configureFileChooser.

private static FileChooser configureFileChooser() {
    final Preferences pref = Preferences.userNodeForPackage(ImportMt940FxAction.class);
    final FileChooser fileChooser = new FileChooser();
    fileChooser.setInitialDirectory(new File(pref.get(LAST_DIR, System.getProperty("user.home"))));
    fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("All Files (*.*)", "*.*"));
    return fileChooser;
}
Also used : FileChooser(javafx.stage.FileChooser) Preferences(java.util.prefs.Preferences) File(java.io.File)

Example 30 with FileChooser

use of javafx.stage.FileChooser in project trex-stateless-gui by cisco-system-traffic-generator.

the class FileManager method getSelectedFile.

/**
     * Return selected file
     *
     * @param windowTitle
     * @param fileName
     * @param window
     * @param type
     * @param filePath
     * @param isExport
     * @return
     */
public static File getSelectedFile(String windowTitle, String fileName, Window window, FileType type, String filePath, boolean isExport) {
    FileChooser fileChooser = FileChooserFactory.get();
    fileChooser.setTitle(windowTitle);
    fileChooser.setInitialFileName(fileName);
    FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter(type.getFilterDescription(), type.getFilterExtension());
    fileChooser.getExtensionFilters().add(extFilter);
    FileChooser.ExtensionFilter allFilesFilter = new FileChooser.ExtensionFilter("All files ", "*.*");
    fileChooser.getExtensionFilters().add(allFilesFilter);
    if (!Util.isNullOrEmpty(filePath) && new File(filePath).exists()) {
        fileChooser.setInitialDirectory(new File(filePath));
    }
    if (isExport) {
        return fileChooser.showSaveDialog(window);
    } else {
        return fileChooser.showOpenDialog(window);
    }
}
Also used : FileChooser(javafx.stage.FileChooser) File(java.io.File)

Aggregations

FileChooser (javafx.stage.FileChooser)64 File (java.io.File)59 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)4 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