001: /*
002: * $RCSfile: WritableRenderedImageAdapter.java,v $
003: *
004: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Use is subject to license terms.
007: *
008: * $Revision: 1.1 $
009: * $Date: 2005/02/11 04:57:25 $
010: * $State: Exp $
011: */
012: package javax.media.jai;
013:
014: import java.awt.Point;
015: import java.awt.image.Raster;
016: import java.awt.image.WritableRaster;
017: import java.awt.image.WritableRenderedImage;
018: import java.awt.image.TileObserver;
019:
020: /**
021: * A <code>PlanarImage</code> wrapper for a
022: * <code>WritableRenderedImage</code>. The tile layout, sample model,
023: * and so forth are preserved. Calls to <code>getTile()</code> and so
024: * forth are forwarded.
025: *
026: * <p> From JAI's point of view, this image is a
027: * <code>PlanarImage</code> of unknown type, with no sources, and
028: * additionally an implementer of the
029: * <code>WritableRenderedImage</code> interface. The image's pixel
030: * data appear to be variable.
031: *
032: * <p> The class and all its methods are marked <code>final</code> in
033: * order to allow dynamic inlining to take place. This should
034: * eliminate any performance penalty associated with the use of an
035: * adapter class.
036: *
037: * @see PlanarImage
038: * @see RenderedImageAdapter
039: * @see java.awt.image.RenderedImage
040: * @see java.awt.image.WritableRenderedImage
041: *
042: */
043: public final class WritableRenderedImageAdapter extends
044: RenderedImageAdapter implements WritableRenderedImage {
045:
046: /** The WritableRenderedImage being adapted. */
047: private WritableRenderedImage theWritableImage;
048:
049: /**
050: * Constructs a <code>WritableRenderedImageAdapter</code>.
051: *
052: * @param im A <code>WritableRenderedImage</code> to be `wrapped'
053: * as a <code>PlanarImage</code>.
054: * @throws <code>IllegalArgumentException</code> if <code>im</code> is
055: * <code>null</code>.
056: */
057: public WritableRenderedImageAdapter(WritableRenderedImage im) {
058: super (im);
059: theWritableImage = im;
060: }
061:
062: /**
063: * Adds an observer. If the observer is already present,
064: * it will receive multiple notifications.
065: *
066: * @param tileObserver The <code>TileObserver</code> to be added.
067: * @throws <code>IllegalArgumentException</code> if
068: * <code>tileObserver</code> is <code>null</code>.
069: */
070: public final void addTileObserver(TileObserver tileObserver) {
071: if (tileObserver == null) {
072: throw new IllegalArgumentException(JaiI18N
073: .getString("WritableRenderedImageAdapter0"));
074: }
075: theWritableImage.addTileObserver(tileObserver);
076: }
077:
078: /**
079: * Removes an observer. If the observer was not registered,
080: * nothing happens. If the observer was registered for multiple
081: * notifications, it will now be registered for one fewer.
082: *
083: * @param tileObserver The <code>TileObserver</code> to be removed.
084: * @throws <code>IllegalArgumentException</code> if
085: * <code>tileObserver</code> is <code>null</code>.
086: */
087: public final void removeTileObserver(TileObserver tileObserver) {
088: if (tileObserver == null) {
089: throw new IllegalArgumentException(JaiI18N
090: .getString("WritableRenderedImageAdapter0"));
091: }
092: theWritableImage.removeTileObserver(tileObserver);
093: }
094:
095: /**
096: * Checks out a tile for writing.
097: *
098: * <p> The <code>WritableRenderedImage</code> is responsible for
099: * notifying all of its <code>TileObservers</code> when a tile
100: * goes from having no writers to having one writer.
101: *
102: * @param tileX The X index of the tile.
103: * @param tileY The Y index of the tile.
104: * @return The tile as a <code>WritableRaster</code>.
105: */
106: public final WritableRaster getWritableTile(int tileX, int tileY) {
107: return theWritableImage.getWritableTile(tileX, tileY);
108: }
109:
110: /**
111: * Relinquishes the right to write to a tile. If the caller
112: * continues to write to the tile, the results are undefined.
113: * Calls to this method should only appear in matching pairs with
114: * calls to <code>getWritableTile()</code>; any other use will
115: * lead to undefined results.
116: *
117: * <p> The <code>WritableRenderedImage</code> is responsible for
118: * notifying all of its <code>TileObserver</code>s when a tile
119: * goes from having one writer to having no writers.
120: *
121: * @param tileX The X index of the tile.
122: * @param tileY The Y index of the tile.
123: */
124: public final void releaseWritableTile(int tileX, int tileY) {
125: theWritableImage.releaseWritableTile(tileX, tileY);
126: }
127:
128: /**
129: * Returns whether a tile is currently checked out for writing.
130: *
131: * @param tileX The X index of the tile.
132: * @param tileY The Y index of the tile.
133: *
134: * @return <code>true</code> if the tile currently has writers.
135: */
136: public final boolean isTileWritable(int tileX, int tileY) {
137: return theWritableImage.isTileWritable(tileX, tileY);
138: }
139:
140: /**
141: * Returns an array of <code>Point</code> objects indicating which tiles
142: * are checked out for writing.
143: *
144: * @return an array of <code>Point</code>s or <code>null</code> if no
145: * tiles are checked out for writing.
146: */
147: public final Point[] getWritableTileIndices() {
148: return theWritableImage.getWritableTileIndices();
149: }
150:
151: /**
152: * Returns whether any tile is checked out for writing.
153: * Semantically equivalent to (getWritableTiles().size() != 0).
154: *
155: * @return <code>true</code> if any tile currently has writers.
156: */
157: public final boolean hasTileWriters() {
158: return theWritableImage.hasTileWriters();
159: }
160:
161: /**
162: * Sets a rectangular region of the image to the contents of
163: * <code>raster</code>.
164: *
165: * @param raster A <code>Raster</code>.
166: * @throws <code>IllegalArgumentException</code> if <code>raster</code> is
167: * <code>null</code>.
168: */
169: public final void setData(Raster raster) {
170: if (raster == null) {
171: throw new IllegalArgumentException(JaiI18N
172: .getString("WritableRenderedImageAdapter1"));
173: }
174: theWritableImage.setData(raster);
175: }
176: }
|