Search in sources :

Example 1 with WriterWrapper

use of loci.formats.WriterWrapper in project bioformats by openmicroscopy.

the class GUITools method buildFileFilters.

// -- File chooser --
/**
 * Constructs a list of file filters for the given file format handler.
 */
public static FileFilter[] buildFileFilters(IFormatHandler handler) {
    FileFilter[] filters = null;
    // unwrap reader
    while (true) {
        if (handler instanceof ReaderWrapper) {
            handler = ((ReaderWrapper) handler).getReader();
        } else if (handler instanceof FileStitcher) {
            handler = ((FileStitcher) handler).getReader();
        } else if (handler instanceof WriterWrapper) {
            handler = ((WriterWrapper) handler).getWriter();
        } else
            break;
    }
    // handle special cases of ImageReader and ImageWriter
    if (handler instanceof ImageReader) {
        ImageReader imageReader = (ImageReader) handler;
        IFormatReader[] readers = imageReader.getReaders();
        Vector filterList = new Vector();
        Vector comboList = new Vector();
        for (int i = 0; i < readers.length; i++) {
            filterList.add(new FormatFileFilter(readers[i]));
            // NB: Some readers need to open a file to determine if it is the
            // proper type, when the extension alone is insufficient to
            // distinguish. This behavior is fine for individual filters, but not
            // for ImageReader's combination filter, because it makes the combo
            // filter too slow. So rather than composing the combo filter from
            // FormatFileFilters, we use faster but less accurate
            // ExtensionFileFilters instead.
            String[] suffixes = readers[i].getSuffixes();
            String format = readers[i].getFormat();
            comboList.add(new ExtensionFileFilter(suffixes, format));
        }
        comboList.add(new NoExtensionFileFilter());
        FileFilter combo = makeComboFilter(sortFilters(comboList));
        if (combo != null)
            filterList.add(combo);
        filters = sortFilters(filterList);
    } else if (handler instanceof ImageWriter) {
        IFormatWriter[] writers = ((ImageWriter) handler).getWriters();
        Vector filterList = new Vector();
        for (int i = 0; i < writers.length; i++) {
            String[] suffixes = writers[i].getSuffixes();
            String format = writers[i].getFormat();
            filterList.add(new ExtensionFileFilter(suffixes, format));
        }
        filters = sortFilters(filterList);
    } else // handle default reader and writer cases
    if (handler instanceof IFormatReader) {
        IFormatReader reader = (IFormatReader) handler;
        filters = new FileFilter[] { new FormatFileFilter(reader) };
    } else {
        String[] suffixes = handler.getSuffixes();
        String format = handler.getFormat();
        filters = new FileFilter[] { new ExtensionFileFilter(suffixes, format) };
    }
    return filters;
}
Also used : IFormatReader(loci.formats.IFormatReader) ImageWriter(loci.formats.ImageWriter) ReaderWrapper(loci.formats.ReaderWrapper) WriterWrapper(loci.formats.WriterWrapper) FileStitcher(loci.formats.FileStitcher) FileFilter(javax.swing.filechooser.FileFilter) ImageReader(loci.formats.ImageReader) Vector(java.util.Vector)

Aggregations

Vector (java.util.Vector)1 FileFilter (javax.swing.filechooser.FileFilter)1 FileStitcher (loci.formats.FileStitcher)1 IFormatReader (loci.formats.IFormatReader)1 ImageReader (loci.formats.ImageReader)1 ImageWriter (loci.formats.ImageWriter)1 ReaderWrapper (loci.formats.ReaderWrapper)1 WriterWrapper (loci.formats.WriterWrapper)1