001/**
002 * 
003 */
004package icy.plugin.abstract_;
005
006import icy.common.exception.UnsupportedFormatException;
007import icy.common.listener.ProgressListener;
008import icy.file.SequenceFileImporter;
009import icy.image.AbstractImageProvider;
010import icy.image.IcyBufferedImage;
011import icy.plugin.interface_.PluginNoEDTConstructor;
012import icy.sequence.SequenceIdImporter;
013
014import java.awt.Rectangle;
015import java.io.IOException;
016
017import loci.formats.ome.OMEXMLMetadataImpl;
018import ome.xml.meta.OMEXMLMetadata;
019
020/**
021 * Plugin specialized for Sequence file import operation (see the {@link SequenceFileImporter} interface)
022 * 
023 * @see PluginImporter
024 * @see PluginFileImporter
025 * @see PluginSequenceIdImporter
026 * @see PluginSequenceImporter
027 * @author Stephane
028 */
029public abstract class PluginSequenceFileImporter extends Plugin implements SequenceFileImporter, PluginNoEDTConstructor
030{
031    // default helper
032    protected class InternalSequenceIdImporterHelper extends AbstractImageProvider implements SequenceIdImporter
033    {
034        @Override
035        public String getOpened()
036        {
037            return PluginSequenceFileImporter.this.getOpened();
038        }
039
040        @Override
041        public boolean open(String id, int flags) throws UnsupportedFormatException, IOException
042        {
043            return PluginSequenceFileImporter.this.open(id, flags);
044        }
045
046        @Override
047        public void close() throws IOException
048        {
049            PluginSequenceFileImporter.this.close();
050        }
051
052        @Deprecated
053        @Override
054        public OMEXMLMetadataImpl getMetaData() throws UnsupportedFormatException, IOException
055        {
056            return PluginSequenceFileImporter.this.getMetaData();
057        }
058
059        @Override
060        public IcyBufferedImage getImage(int series, int resolution, Rectangle rectangle, int z, int t, int c)
061                throws UnsupportedFormatException, IOException
062        {
063            return PluginSequenceFileImporter.this.getImage(series, resolution, rectangle, z, t, c);
064        }
065    }
066
067    protected final InternalSequenceIdImporterHelper interfaceHelper;
068
069    public PluginSequenceFileImporter()
070    {
071        super();
072
073        interfaceHelper = new InternalSequenceIdImporterHelper();
074    }
075
076    // default implementation as ImageProvider interface changed
077    @Override
078    public OMEXMLMetadata getOMEXMLMetaData() throws UnsupportedFormatException, IOException
079    {
080        return interfaceHelper.getOMEXMLMetaData();
081    }
082
083    // default implementation, override it if you need specific value for faster tile access
084    @Override
085    public int getTileWidth(int series) throws UnsupportedFormatException, IOException
086    {
087        return interfaceHelper.getTileWidth(series);
088    }
089
090    // default implementation, override it if you need specific value for faster tile access
091    @Override
092    public int getTileHeight(int series) throws UnsupportedFormatException, IOException
093    {
094        return interfaceHelper.getTileHeight(series);
095    }
096
097    // default implementation, override it if you need specific value for faster tile access
098    @Override
099    public boolean isResolutionAvailable(int series, int resolution) throws UnsupportedFormatException, IOException
100    {
101        return interfaceHelper.isResolutionAvailable(series, resolution);
102    }
103
104    // default implementation
105    @Override
106    public IcyBufferedImage getThumbnail(int series) throws UnsupportedFormatException, IOException
107    {
108        return interfaceHelper.getThumbnail(series);
109    }
110
111    // default implementation: use the getImage(..) method then return data.
112    // It should be the opposite side for performance reason, override this method if possible
113    @Override
114    public Object getPixels(int series, int resolution, Rectangle rectangle, int z, int t, int c)
115            throws UnsupportedFormatException, IOException
116    {
117        return interfaceHelper.getPixels(series, resolution, rectangle, z, t, c);
118    }
119
120    @Override
121    public IcyBufferedImage getImage(int series, int resolution, Rectangle rectangle, int z, int t)
122            throws UnsupportedFormatException, IOException
123    {
124        return interfaceHelper.getImage(series, resolution, rectangle, z, t);
125    }
126
127    // default implementation using the region getImage(..) method, better to override
128    @Override
129    public IcyBufferedImage getImage(int series, int resolution, int z, int t, int c)
130            throws UnsupportedFormatException, IOException
131    {
132        return interfaceHelper.getImage(series, resolution, z, t, c);
133    }
134
135    @Override
136    public IcyBufferedImage getImage(int series, int resolution, int z, int t)
137            throws UnsupportedFormatException, IOException
138    {
139        return interfaceHelper.getImage(series, resolution, z, t);
140    }
141
142    @Override
143    public IcyBufferedImage getImage(int series, int z, int t) throws UnsupportedFormatException, IOException
144    {
145        return interfaceHelper.getImage(series, z, t);
146    }
147
148    @Override
149    public IcyBufferedImage getImage(int z, int t) throws UnsupportedFormatException, IOException
150    {
151        return interfaceHelper.getImage(z, t);
152    }
153
154    /**
155     * See {@link AbstractImageProvider#getPixelsByTile(int, int, Rectangle, int, int, int, int, int, ProgressListener)}
156     */
157    public Object getPixelsByTile(int series, int resolution, Rectangle region, int z, int t, int c, int tileW,
158            int tileH, ProgressListener listener) throws UnsupportedFormatException, IOException
159    {
160        return interfaceHelper.getPixelsByTile(series, resolution, region, z, t, c, tileW, tileH, listener);
161    }
162
163    /**
164     * See {@link AbstractImageProvider#getResolutionFactor(int, int)}
165     */
166    public int getResolutionFactor(int series, int wantedSize) throws UnsupportedFormatException, IOException
167    {
168        return interfaceHelper.getResolutionFactor(series, wantedSize);
169    }
170}