OSDN Git Service

libjava/ChangeLog:
[pf3gnuchains/gcc-fork.git] / libjava / classpath / java / awt / AlphaComposite.java
index 435cfd0..a668fda 100644 (file)
@@ -1,5 +1,5 @@
 /* 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.
 
@@ -38,6 +38,8 @@ exception statement from your version. */
 
 package java.awt;
 
+import gnu.java.awt.java2d.AlphaCompositeContext;
+
 import java.awt.image.ColorModel;
 import java.util.LinkedHashMap;
 import java.util.Map;
@@ -60,7 +62,7 @@ public final class AlphaComposite implements Composite
 
     /** 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;
     }
   };
@@ -137,26 +139,72 @@ public final class AlphaComposite implements Composite
       }
     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))