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