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;
}
Aggregations