Example usage for javafx.stage FileChooser setSelectedExtensionFilter

List of usage examples for javafx.stage FileChooser setSelectedExtensionFilter

Introduction

In this page you can find the example usage for javafx.stage FileChooser setSelectedExtensionFilter.

Prototype

public final void setSelectedExtensionFilter(ExtensionFilter filter) 

Source Link

Usage

From source file:com.advos.notehub.client.util.sandsoft.CustomHTMLEditor.java

/**
 * Action to do on Import Image button click
 *//*from  w  w  w.j a  v a2  s.  c om*/
private void onImportFileButtonAction() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Select a file to import");
    fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("All Files", "*.*"));
    File selectedFile = fileChooser.showOpenDialog(this.getScene().getWindow());
    if (selectedFile != null) {
        importDataFile(selectedFile);
    }
}

From source file:de.halirutan.spectralis.examples.sloexporter.Controller.java

private List<File> showFileSelectDialog() {
    Window window = root.getScene().getWindow();
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Select .vol files or directories");
    fileChooser.setSelectedExtensionFilter(new ExtensionFilter("Raw Volume files", "vol"));
    return fileChooser.showOpenMultipleDialog(window);
}

From source file:de.hs.mannheim.modUro.controller.diagram.fx.ChartViewer.java

/**
 * A handler for the export to PDF option in the context menu.
 *//*from w  w w. jav  a2 s.  c  om*/
private void handleExportToPDF() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setSelectedExtensionFilter(
            new FileChooser.ExtensionFilter("Portable Document Format (PDF)", "pdf"));
    fileChooser.setTitle("Export to PDF");
    File file = fileChooser.showSaveDialog(this.getScene().getWindow());
    if (file != null) {
        ExportUtils.writeAsPDF(this.chart, (int) getWidth(), (int) getHeight(), file);
    }
}

From source file:de.hs.mannheim.modUro.controller.diagram.fx.ChartViewer.java

/**
 * A handler for the export to SVG option in the context menu.
 *//*w w  w  . j av  a  2 s  .  c o m*/
private void handleExportToSVG() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export to SVG");
    fileChooser.setSelectedExtensionFilter(
            new FileChooser.ExtensionFilter("Scalable Vector Graphics (SVG)", "svg"));
    File file = fileChooser.showSaveDialog(this.getScene().getWindow());
    if (file != null) {
        ExportUtils.writeAsSVG(this.chart, (int) getWidth(), (int) getHeight(), file);
    }
}

From source file:de.hs.mannheim.modUro.controller.diagram.fx.ChartViewer.java

/**
 * A handler for the export to PNG option in the context menu.
 */// ww w.  ja va  2 s . c  om
private void handleExportToPNG() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export to PNG");
    fileChooser.setSelectedExtensionFilter(
            new FileChooser.ExtensionFilter("Portable Network Graphics (PNG)", "png"));
    File file = fileChooser.showSaveDialog(this.getScene().getWindow());
    if (file != null) {
        try {
            ExportUtils.writeAsPNG(this.chart, (int) getWidth(), (int) getHeight(), file);
        } catch (IOException ex) {
            // FIXME: show a dialog with the error
        }
    }
}

From source file:de.hs.mannheim.modUro.controller.diagram.fx.ChartViewer.java

/**
 * A handler for the export to JPEG option in the context menu.
 */// w ww  . ja  v a2  s. co m
private void handleExportToJPEG() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export to JPEG");
    fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("JPEG", "jpg"));
    File file = fileChooser.showSaveDialog(this.getScene().getWindow());
    if (file != null) {
        try {
            ExportUtils.writeAsJPEG(this.chart, (int) getWidth(), (int) getHeight(), file);
        } catch (IOException ex) {
            // FIXME: show a dialog with the error
        }
    }
}

From source file:com.ggvaidya.scinames.ui.BulkChangeEditorController.java

@FXML
private void backupCurrentDataset(ActionEvent evt) {
    // We just need to save this somewhere that isn't the project's actual file location.
    File currentFile = project.getFile();

    FileChooser chooser = new FileChooser();
    chooser.setTitle("Save project to ...");
    chooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("Project XML.gz file", "*.xml.gz"));
    File f = chooser.showSaveDialog(bulkChangeEditor.getStage());
    if (f != null) {
        project.setFile(f);/* w w w.  ja va 2  s. c  o m*/

        try {
            SciNames.reportMemoryStatus("Saving project " + project + " to disk");
            project.saveToFile();
            SciNames.reportMemoryStatus("Project saved to disk");

            new Alert(Alert.AlertType.INFORMATION,
                    "Project saved as " + f + "; subsequent saves will return to " + currentFile).showAndWait();
        } catch (IOException ex) {
            new Alert(Alert.AlertType.ERROR, "Could not save project to file '" + f + "': " + ex).showAndWait();
        }
    }

    project.setFile(currentFile);
}

From source file:fr.amap.commons.javafx.chart.ChartViewer.java

/**
 * A handler for the export to PDF option in the context menu.
 *//*from   ww  w  .j a  va  2 s .  c o  m*/
private void handleExportToPDF() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setSelectedExtensionFilter(
            new FileChooser.ExtensionFilter("Portable Document Format (PDF)", "pdf"));
    fileChooser.setTitle("Export to PDF");
    File file = fileChooser.showSaveDialog(stage);
    if (file != null) {

        try {

            CanvasPositionsAndSize canvasPositionAndSize = getCanvasPositionAndSize();

            PDDocument doc = new PDDocument();

            PDPage page = new PDPage(new PDRectangle((float) canvasPositionAndSize.totalWidth,
                    (float) canvasPositionAndSize.totalHeight));
            doc.addPage(page);

            BufferedImage image = new BufferedImage((int) canvasPositionAndSize.totalWidth,
                    (int) canvasPositionAndSize.totalHeight, BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2 = image.createGraphics();

            int index = 0;
            for (ChartCanvas canvas : chartCanvasList) {

                Rectangle2D rectangle2D = canvasPositionAndSize.positionsAndSizes.get(index);

                ((Drawable) canvas.chart).draw(g2, new Rectangle((int) rectangle2D.getX(),
                        (int) rectangle2D.getY(), (int) rectangle2D.getWidth(), (int) rectangle2D.getHeight()));
                index++;
            }

            PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false);
            PDXObjectImage pdImage = new PDPixelMap(doc, image);
            contentStream.drawImage(pdImage, 0, 0);

            PDPageContentStream cos = new PDPageContentStream(doc, page);
            cos.drawXObject(pdImage, 0, 0, pdImage.getWidth(), pdImage.getHeight());
            cos.close();

            doc.save(file);

        } catch (IOException | COSVisitorException ex) {
            Logger.getLogger(ChartViewer.class.getName()).log(Level.SEVERE, null, ex);
        }
        /*ExportUtils.writeAsPDF(this.chart, (int)canvas.getWidth(),
        (int)canvas.getHeight(), file);*/

        /*ExportUtils.writeAsPDF(this.chart, (int)canvas.getWidth(),
                (int)canvas.getHeight(), file);*/
    }
}

From source file:fr.amap.commons.javafx.chart.ChartViewer.java

/**
* A handler for the export to SVG option in the context menu.
*///from w  ww  .  j  ava 2s .c om
private void handleExportToSVG() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export to SVG");
    fileChooser.setSelectedExtensionFilter(
            new FileChooser.ExtensionFilter("Scalable Vector Graphics (SVG)", "svg"));
    File file = fileChooser.showSaveDialog(stage);
    if (file != null) {

        CanvasPositionsAndSize canvasPositionAndSize = getCanvasPositionAndSize();

        SVGGraphics2D sVGGraphics2D = new SVGGraphics2D((int) canvasPositionAndSize.totalWidth,
                (int) canvasPositionAndSize.totalHeight);

        Graphics2D graphics2D = (Graphics2D) sVGGraphics2D.create();

        int index = 0;
        for (ChartCanvas canvas : chartCanvasList) {

            ((Drawable) canvas.chart).draw(graphics2D, canvasPositionAndSize.positionsAndSizes.get(index));
            index++;
        }

        try {
            SVGUtils.writeToSVG(file, sVGGraphics2D.getSVGElement());
        } catch (IOException ex) {
            Logger.getLogger(ChartViewer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:fr.amap.commons.javafx.chart.ChartViewer.java

/**
 * A handler for the export to PNG option in the context menu.
 *//*  w ww. j av a  2s .  c o m*/
private void handleExportToPNG() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export to PNG");
    fileChooser.setSelectedExtensionFilter(
            new FileChooser.ExtensionFilter("Portable Network Graphics (PNG)", "png"));
    File file = fileChooser.showSaveDialog(stage);

    if (file != null) {
        try {

            CanvasPositionsAndSize canvasPositionAndSize = getCanvasPositionAndSize();

            BufferedImage image = new BufferedImage((int) canvasPositionAndSize.totalWidth,
                    (int) canvasPositionAndSize.totalHeight, BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2 = image.createGraphics();

            int index = 0;
            for (ChartCanvas canvas : chartCanvasList) {

                Rectangle2D rectangle2D = canvasPositionAndSize.positionsAndSizes.get(index);

                ((Drawable) canvas.chart).draw(g2, new Rectangle((int) rectangle2D.getX(),
                        (int) rectangle2D.getY(), (int) rectangle2D.getWidth(), (int) rectangle2D.getHeight()));
                index++;
            }

            try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) {
                ImageIO.write(image, "png", out);
            }

        } catch (IOException ex) {
            // FIXME: show a dialog with the error
        }
    }
}