/* AlphaComposite.java -- provides a context for performing alpha compositing
- Copyright (C) 2002, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
package java.awt;
+import gnu.java.awt.java2d.AlphaCompositeContext;
+
import java.awt.image.ColorModel;
import java.util.LinkedHashMap;
import java.util.Map;
/** Prune stale entries. */
protected boolean removeEldestEntry(Map.Entry eldest)
- { // XXX - FIXME Use Map.Entry, not just Entry as gcj 3.1 workaround.
+ {
return size() > MAX_CACHE_SIZE;
}
};
}
return a;
}
+
+ /**
+ * Creates a {@link CompositeContext} that can be used to perform
+ * compositing operations according to this AlphaComposite settings.
+ *
+ * @param srcColorModel the color model of the source raster
+ * @param dstColorModel the color model of the destination raster
+ * @param hints the rendering hints to use
+ *
+ * @return a {@link CompositeContext} that can be used to perform
+ * compositing operations according to this AlphaComposite settings
+ */
public CompositeContext createContext(ColorModel srcColorModel,
ColorModel dstColorModel,
RenderingHints hints)
{
- // XXX Implement. Sun uses undocumented implementation class
- // sun.java2d.SunCompositeContext.
- throw new Error("not implemented");
+ return new AlphaCompositeContext(this, srcColorModel, dstColorModel);
+ }
+
+ /**
+ * Return an <code>AlphaComposite</code> similar to <code>this</code>,
+ * that uses the specified rule. If <code>rule</code> is the same as
+ * <code>this.rule</code>, then <code>this</code> is returned.
+ *
+ * @since 1.6
+ */
+ public AlphaComposite derive(int rule)
+ {
+ if (this.rule == rule)
+ return this;
+ else
+ return AlphaComposite.getInstance(rule, this.getAlpha());
+ }
+
+ /**
+ * Return an <code>AlphaComposite</code> similar to <code>this</code>,
+ * that uses the specified <code>alpha</code>.
+ *
+ * If <code>alph</code> is the same as <code>this.alpha</code>,
+ * then <code>this</code> is returned.
+ *
+ * @since 1.6
+ */
+ public AlphaComposite derive(float alpha)
+ {
+ if (this.getAlpha() == alpha)
+ return this;
+ else
+ return AlphaComposite.getInstance(this.getRule(), alpha);
}
+
public float getAlpha()
{
return alpha;
}
+
public int getRule()
{
return rule;
}
+
public int hashCode()
{
return 31 * Float.floatToIntBits(alpha) + rule;
}
+
public boolean equals(Object o)
{
if (! (o instanceof AlphaComposite))