Search in sources :

Example 1 with ExtensionFileFilter

use of artisynth.core.util.ExtensionFileFilter in project artisynth_core by artisynth.

the class MenuBarHandler method saveViewerImage.

private void saveViewerImage() {
    JFileChooser chooser;
    if ((chooser = myViewerImageFileChooser) == null) {
        chooser = new JFileChooser();
        chooser.setApproveButtonText("Save");
        chooser.setCurrentDirectory(ArtisynthPath.getWorkingDir());
        for (FileFilter ff : chooser.getChoosableFileFilters()) {
            chooser.removeChoosableFileFilter(ff);
        }
        // create filters
        String[] fmts = ImageIO.getWriterFormatNames();
        for (String fmt : fmts) {
            ExtensionFileFilter filter = new ExtensionFileFilter("." + fmt + " files", fmt);
            chooser.addChoosableFileFilter(filter);
        }
        chooser.setFileFilter(chooser.getChoosableFileFilters()[0]);
        myViewerImageFileChooser = chooser;
    }
    int returnVal = chooser.showSaveDialog(myFrame);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        ExtensionFileFilter filter = (ExtensionFileFilter) chooser.getFileFilter();
        String ext = filter.getExtensions()[0];
        File file = chooser.getSelectedFile();
        if (!file.getName().toLowerCase().endsWith(ext.toLowerCase())) {
            file = new File(file.getPath() + "." + ext);
        }
        int confirmation = JOptionPane.YES_OPTION;
        if (file.exists()) {
            confirmation = JOptionPane.showConfirmDialog(myFrame, "File " + file.getName() + " aleady exists. Proceed?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        }
        if (confirmation == JOptionPane.YES_OPTION) {
            GLViewer viewer = myMain.getViewer();
            viewer.setupScreenShot(viewer.getScreenWidth(), viewer.getScreenHeight(), file, ext);
            viewer.repaint();
        // while (viewer.grabPending()) {
        // try {
        // Thread.sleep (10);
        // }
        // catch (Exception e){
        // }
        // }
        }
    }
}
Also used : GLViewer(maspack.render.GL.GLViewer) JFileChooser(javax.swing.JFileChooser) ExtensionFileFilter(artisynth.core.util.ExtensionFileFilter) GenericFileFilter(maspack.util.GenericFileFilter) FileFilter(javax.swing.filechooser.FileFilter) ExtensionFileFilter(artisynth.core.util.ExtensionFileFilter) File(java.io.File)

Aggregations

ExtensionFileFilter (artisynth.core.util.ExtensionFileFilter)1 File (java.io.File)1 JFileChooser (javax.swing.JFileChooser)1 FileFilter (javax.swing.filechooser.FileFilter)1 GLViewer (maspack.render.GL.GLViewer)1 GenericFileFilter (maspack.util.GenericFileFilter)1