01: /*
02: * $RCSfile: AttributedImage.java,v $
03: *
04: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
05: *
06: * Use is subject to license terms.
07: *
08: * $Revision: 1.1 $
09: * $Date: 2005/02/11 04:57:03 $
10: * $State: Exp $
11: */
12: package javax.media.jai;
13:
14: /**
15: * A class which associates a <code>PlanarImage</code> with an attribute
16: * of unspecified type. The class is itself a <code>PlanarImage</code>
17: * equivalent to the one which it wraps.
18: *
19: * @since JAI 1.1
20: */
21: public class AttributedImage extends RenderedImageAdapter {
22: /** The attribute associated with the image. */
23: protected Object attribute;
24:
25: /**
26: * Constructs an <code>AttributedImage</code>. The attribute parameter
27: * may be <code>null</code>
28: *
29: * @throws IllegalArgumentException if <code>theImage</code> is
30: * <code>null</code>.
31: */
32: public AttributedImage(PlanarImage image, Object attribute) {
33: super (image);
34: this .attribute = attribute;
35: }
36:
37: /** Retrieves the wrapped image. */
38: public PlanarImage getImage() {
39: return (PlanarImage) theImage;
40: }
41:
42: /** Stores the attribute. */
43: public void setAttribute(Object attribute) {
44: this .attribute = attribute;
45: }
46:
47: /** Retrieves the attribute. */
48: public Object getAttribute() {
49: return attribute;
50: }
51:
52: /**
53: * Tests for equality. The parameter <code>Object</code> must be
54: * an <code>AttributedImage</code> the image and attribute of which
55: * are equal those of this object according to the <code>equals()</code>
56: * methods of the image and attribute of this image, respectively.
57: * Attributes are also considered equal if they are both <code>null</code>.
58: */
59: public boolean equals(Object o) {
60: if (o != null && o instanceof AttributedImage) {
61: AttributedImage ai = (AttributedImage) o;
62: Object a = ai.getAttribute();
63: return getImage().equals(ai.getImage())
64: && (attribute == null ? a == null
65: : ((a != null) && attribute.equals(a)));
66: }
67:
68: return false;
69: }
70:
71: /** toString() method. */
72: public String toString() {
73: return "Attribute=(" + getAttribute() + ") Image="
74: + getImage();
75: }
76: }
|