jdk/src/java.desktop/share/classes/javax/imageio/IIOImage.java
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 5506 jdk/src/share/classes/javax/imageio/IIOImage.java@202f599c92aa
child 35667 ed476aba94de
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.imageio;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.image.Raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.image.RenderedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.imageio.metadata.IIOMetadata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * A simple container class to aggregate an image, a set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * thumbnail (preview) images, and an object representing metadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * associated with the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p> The image data may take the form of either a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <code>RenderedImage</code>, or a <code>Raster</code>.  Reader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * methods that return an <code>IIOImage</code> will always return a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <code>BufferedImage</code> using the <code>RenderedImage</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * reference.  Writer methods that accept an <code>IIOImage</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * will always accept a <code>RenderedImage</code>, and may optionally
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * accept a <code>Raster</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p> Exactly one of <code>getRenderedImage</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <code>getRaster</code> will return a non-<code>null</code> value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Subclasses are responsible for ensuring this behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @see ImageReader#readAll(int, ImageReadParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @see ImageReader#readAll(java.util.Iterator)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @see ImageWriter#write(javax.imageio.metadata.IIOMetadata,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *                        IIOImage, ImageWriteParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @see ImageWriter#write(IIOImage)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @see ImageWriter#writeToSequence(IIOImage, ImageWriteParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @see ImageWriter#writeInsert(int, IIOImage, ImageWriteParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public class IIOImage {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * The <code>RenderedImage</code> being referenced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    protected RenderedImage image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * The <code>Raster</code> being referenced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected Raster raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * A <code>List</code> of <code>BufferedImage</code> thumbnails,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * or <code>null</code>.  Non-<code>BufferedImage</code> objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * must not be stored in this <code>List</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    protected List<? extends BufferedImage> thumbnails = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * An <code>IIOMetadata</code> object containing metadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * associated with the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected IIOMetadata metadata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Constructs an <code>IIOImage</code> containing a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * <code>RenderedImage</code>, and thumbnails and metadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * associated with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * <p> All parameters are stored by reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * <p> The <code>thumbnails</code> argument must either be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * <code>null</code> or contain only <code>BufferedImage</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @param image a <code>RenderedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param thumbnails a <code>List</code> of <code>BufferedImage</code>s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param metadata an <code>IIOMetadata</code> object, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @exception IllegalArgumentException if <code>image</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public IIOImage(RenderedImage image,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                    List<? extends BufferedImage> thumbnails,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    IIOMetadata metadata) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if (image == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            throw new IllegalArgumentException("image == null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        this.image = image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        this.raster = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        this.thumbnails = thumbnails;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        this.metadata = metadata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Constructs an <code>IIOImage</code> containing a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * <code>Raster</code>, and thumbnails and metadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * associated with it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * <p> All parameters are stored by reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @param raster a <code>Raster</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @param thumbnails a <code>List</code> of <code>BufferedImage</code>s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @param metadata an <code>IIOMetadata</code> object, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @exception IllegalArgumentException if <code>raster</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public IIOImage(Raster raster,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    List<? extends BufferedImage> thumbnails,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    IIOMetadata metadata) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (raster == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            throw new IllegalArgumentException("raster == null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        this.raster = raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        this.image = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        this.thumbnails = thumbnails;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        this.metadata = metadata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * Returns the currently set <code>RenderedImage</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * <code>null</code> if only a <code>Raster</code> is available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @return a <code>RenderedImage</code>, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @see #setRenderedImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public RenderedImage getRenderedImage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            return image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Sets the current <code>RenderedImage</code>.  The value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * stored by reference.  Any existing <code>Raster</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @param image a <code>RenderedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @exception IllegalArgumentException if <code>image</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @see #getRenderedImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public void setRenderedImage(RenderedImage image) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            if (image == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                throw new IllegalArgumentException("image == null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            this.image = image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            this.raster = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * Returns <code>true</code> if this <code>IIOImage</code> stores
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * a <code>Raster</code> rather than a <code>RenderedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @return <code>true</code> if a <code>Raster</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public boolean hasRaster() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            return (raster != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Returns the currently set <code>Raster</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * <code>null</code> if only a <code>RenderedImage</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @return a <code>Raster</code>, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @see #setRaster
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public Raster getRaster() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            return raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Sets the current <code>Raster</code>.  The value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * stored by reference.  Any existing <code>RenderedImage</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @param raster a <code>Raster</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @exception IllegalArgumentException if <code>raster</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @see #getRaster
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public void setRaster(Raster raster) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            if (raster == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                throw new IllegalArgumentException("raster == null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            this.raster = raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            this.image = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Returns the number of thumbnails stored in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * <code>IIOImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @return the number of thumbnails, as an <code>int</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public int getNumThumbnails() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return thumbnails == null ? 0 : thumbnails.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Returns a thumbnail associated with the main image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @param index the index of the desired thumbnail image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @return a thumbnail image, as a <code>BufferedImage</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @exception IndexOutOfBoundsException if the supplied index is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * negative or larger than the largest valid index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @exception ClassCastException if a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * non-<code>BufferedImage</code> object is encountered in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * list of thumbnails at the given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @see #getThumbnails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @see #setThumbnails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public BufferedImage getThumbnail(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if (thumbnails == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            throw new IndexOutOfBoundsException("No thumbnails available!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return (BufferedImage)thumbnails.get(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Returns the current <code>List</code> of thumbnail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * <code>BufferedImage</code>s, or <code>null</code> if none is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * set.  A live reference is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @return the current <code>List</code> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * <code>BufferedImage</code> thumbnails, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @see #getThumbnail(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @see #setThumbnails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public List<? extends BufferedImage> getThumbnails() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        return thumbnails;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Sets the list of thumbnails to a new <code>List</code> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * <code>BufferedImage</code>s, or to <code>null</code>.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * reference to the previous <code>List</code> is discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * <p> The <code>thumbnails</code> argument must either be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * <code>null</code> or contain only <code>BufferedImage</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @param thumbnails a <code>List</code> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * <code>BufferedImage</code> thumbnails, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @see #getThumbnail(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @see #getThumbnails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public void setThumbnails(List<? extends BufferedImage> thumbnails) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        this.thumbnails = thumbnails;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * Returns a reference to the current <code>IIOMetadata</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * object, or <code>null</code> is none is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @return an <code>IIOMetadata</code> object, or <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @see #setMetadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    public IIOMetadata getMetadata() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        return metadata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * Sets the <code>IIOMetadata</code> to a new object, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @param metadata an <code>IIOMetadata</code> object, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @see #getMetadata
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public void setMetadata(IIOMetadata metadata) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        this.metadata = metadata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
}