Example usage for javax.imageio ImageIO getWriterFileSuffixes

List of usage examples for javax.imageio ImageIO getWriterFileSuffixes

Introduction

In this page you can find the example usage for javax.imageio ImageIO getWriterFileSuffixes.

Prototype

public static String[] getWriterFileSuffixes() 

Source Link

Document

Returns an array of String s listing all of the file suffixes associated with the formats understood by the current set of registered writers.

Usage

From source file:com.googlecode.bpmn_simulator.gui.dialogs.ImageExportChooser.java

public ImageExportChooser() {
    super();/*from w  w w. java2s.  c  o  m*/
    setFileSelectionMode(JFileChooser.FILES_ONLY);
    setMultiSelectionEnabled(false);
    setAcceptAllFileFilterUsed(false);
    for (final String suffix : ImageIO.getWriterFileSuffixes()) {
        addChoosableFileFilter(new FileNameExtensionFilter(suffix, suffix));
    }
}

From source file:eu.esdihumboldt.hale.ui.util.graph.ExportGraphAction.java

/**
 * @see Action#run()//www  . ja  va 2  s .com
 */
@Override
public void run() {
    FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
    // XXX if called from TTreeExporter during transformation, the active
    // shell may be null!

    dialog.setOverwrite(true);
    dialog.setText("Export graph to file");

    String[] imageExtensions = ImageIO.getWriterFileSuffixes();

    StringBuffer extensions = new StringBuffer("*.svg;*.gv;*.dot");
    for (String imageExt : imageExtensions) {
        extensions.append(";*.");
        extensions.append(imageExt);
    }

    dialog.setFilterExtensions(new String[] { extensions.toString() });

    dialog.setFilterNames(new String[] { "Image, SVG or dot file (" + extensions + ")" });

    String fileName = dialog.open();
    if (fileName != null) {
        final File file = new File(fileName);

        //         //XXX use an off-screen graph (testing)
        //         OffscreenGraph graph = new OffscreenGraph(1000, 1000) {
        //            
        //            @Override
        //            protected void configureViewer(GraphViewer viewer) {
        //               viewer.setContentProvider(RenderAction.this.viewer.getContentProvider());
        //               viewer.setLabelProvider(RenderAction.this.viewer.getLabelProvider());
        //               viewer.setInput(RenderAction.this.viewer.getInput());
        //               viewer.setLayoutAlgorithm(new TreeLayoutAlgorithm(TreeLayoutAlgorithm.LEFT_RIGHT), false);
        //            }
        //         };

        // get the graph
        final Graph graph = viewer.getGraphControl();

        final String ext = FilenameUtils.getExtension(file.getAbsolutePath());
        final IFigure root = graph.getRootLayer();

        ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
        try {
            progress.run(false, false, new IRunnableWithProgress() {

                @Override
                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    try {
                        OutputStream out = new BufferedOutputStream(new FileOutputStream(file));

                        if (ext.equalsIgnoreCase("gv") || ext.equalsIgnoreCase("dot")) {
                            OffscreenGraph.saveDot(graph, out);
                        }
                        //                     else if (ext.equalsIgnoreCase("svg")) {
                        //                        OffscreenGraph.saveSVG(root, out);
                        //                     }
                        else {
                            OffscreenGraph.saveImage(root, out, ext);
                        }
                    } catch (Throwable e) {
                        log.userError("Error saving graph to file", e);
                    }
                }

            });
        } catch (Throwable e) {
            log.error("Error launching graph export", e);
        }
    }
}