src/share/classes/java/awt/AlphaComposite.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 604     int rule;
 605 
 606     private AlphaComposite(int rule) {
 607         this(rule, 1.0f);
 608     }
 609 
 610     private AlphaComposite(int rule, float alpha) {
 611         if (rule < MIN_RULE || rule > MAX_RULE) {
 612             throw new IllegalArgumentException("unknown composite rule");
 613         }
 614         if (alpha >= 0.0f && alpha <= 1.0f) {
 615             this.rule = rule;
 616             this.extraAlpha = alpha;
 617         } else {
 618             throw new IllegalArgumentException("alpha value out of range");
 619         }
 620     }
 621 
 622     /**
 623      * Creates an <code>AlphaComposite</code> object with the specified rule.

 624      * @param rule the compositing rule

 625      * @throws IllegalArgumentException if <code>rule</code> is not one of
 626      *         the following:  {@link #CLEAR}, {@link #SRC}, {@link #DST},
 627      *         {@link #SRC_OVER}, {@link #DST_OVER}, {@link #SRC_IN},
 628      *         {@link #DST_IN}, {@link #SRC_OUT}, {@link #DST_OUT},
 629      *         {@link #SRC_ATOP}, {@link #DST_ATOP}, or {@link #XOR}
 630      */
 631     public static AlphaComposite getInstance(int rule) {
 632         switch (rule) {
 633         case CLEAR:
 634             return Clear;
 635         case SRC:
 636             return Src;
 637         case DST:
 638             return Dst;
 639         case SRC_OVER:
 640             return SrcOver;
 641         case DST_OVER:
 642             return DstOver;
 643         case SRC_IN:
 644             return SrcIn;


 647         case SRC_OUT:
 648             return SrcOut;
 649         case DST_OUT:
 650             return DstOut;
 651         case SRC_ATOP:
 652             return SrcAtop;
 653         case DST_ATOP:
 654             return DstAtop;
 655         case XOR:
 656             return Xor;
 657         default:
 658             throw new IllegalArgumentException("unknown composite rule");
 659         }
 660     }
 661 
 662     /**
 663      * Creates an <code>AlphaComposite</code> object with the specified rule and
 664      * the constant alpha to multiply with the alpha of the source.
 665      * The source is multiplied with the specified alpha before being composited
 666      * with the destination.

 667      * @param rule the compositing rule
 668      * @param alpha the constant alpha to be multiplied with the alpha of
 669      * the source. <code>alpha</code> must be a floating point number in the
 670      * inclusive range [0.0,&nbsp;1.0].

 671      * @throws IllegalArgumentException if
 672      *         <code>alpha</code> is less than 0.0 or greater than 1.0, or if
 673      *         <code>rule</code> is not one of
 674      *         the following:  {@link #CLEAR}, {@link #SRC}, {@link #DST},
 675      *         {@link #SRC_OVER}, {@link #DST_OVER}, {@link #SRC_IN},
 676      *         {@link #DST_IN}, {@link #SRC_OUT}, {@link #DST_OUT},
 677      *         {@link #SRC_ATOP}, {@link #DST_ATOP}, or {@link #XOR}
 678      */
 679     public static AlphaComposite getInstance(int rule, float alpha) {
 680         if (alpha == 1.0f) {
 681             return getInstance(rule);
 682         }
 683         return new AlphaComposite(rule, alpha);
 684     }
 685 
 686     /**
 687      * Creates a context for the compositing operation.
 688      * The context contains state that is used in performing
 689      * the compositing operation.
 690      * @param srcColorModel  the {@link ColorModel} of the source


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 604     int rule;
 605 
 606     private AlphaComposite(int rule) {
 607         this(rule, 1.0f);
 608     }
 609 
 610     private AlphaComposite(int rule, float alpha) {
 611         if (rule < MIN_RULE || rule > MAX_RULE) {
 612             throw new IllegalArgumentException("unknown composite rule");
 613         }
 614         if (alpha >= 0.0f && alpha <= 1.0f) {
 615             this.rule = rule;
 616             this.extraAlpha = alpha;
 617         } else {
 618             throw new IllegalArgumentException("alpha value out of range");
 619         }
 620     }
 621 
 622     /**
 623      * Creates an <code>AlphaComposite</code> object with the specified rule.
 624      *
 625      * @param rule the compositing rule
 626      * @return the {@code AlphaComposite} object created
 627      * @throws IllegalArgumentException if <code>rule</code> is not one of
 628      *         the following:  {@link #CLEAR}, {@link #SRC}, {@link #DST},
 629      *         {@link #SRC_OVER}, {@link #DST_OVER}, {@link #SRC_IN},
 630      *         {@link #DST_IN}, {@link #SRC_OUT}, {@link #DST_OUT},
 631      *         {@link #SRC_ATOP}, {@link #DST_ATOP}, or {@link #XOR}
 632      */
 633     public static AlphaComposite getInstance(int rule) {
 634         switch (rule) {
 635         case CLEAR:
 636             return Clear;
 637         case SRC:
 638             return Src;
 639         case DST:
 640             return Dst;
 641         case SRC_OVER:
 642             return SrcOver;
 643         case DST_OVER:
 644             return DstOver;
 645         case SRC_IN:
 646             return SrcIn;


 649         case SRC_OUT:
 650             return SrcOut;
 651         case DST_OUT:
 652             return DstOut;
 653         case SRC_ATOP:
 654             return SrcAtop;
 655         case DST_ATOP:
 656             return DstAtop;
 657         case XOR:
 658             return Xor;
 659         default:
 660             throw new IllegalArgumentException("unknown composite rule");
 661         }
 662     }
 663 
 664     /**
 665      * Creates an <code>AlphaComposite</code> object with the specified rule and
 666      * the constant alpha to multiply with the alpha of the source.
 667      * The source is multiplied with the specified alpha before being composited
 668      * with the destination.
 669      *
 670      * @param rule the compositing rule
 671      * @param alpha the constant alpha to be multiplied with the alpha of
 672      * the source. <code>alpha</code> must be a floating point number in the
 673      * inclusive range [0.0,&nbsp;1.0].
 674      * @return the {@code AlphaComposite} object created
 675      * @throws IllegalArgumentException if
 676      *         <code>alpha</code> is less than 0.0 or greater than 1.0, or if
 677      *         <code>rule</code> is not one of
 678      *         the following:  {@link #CLEAR}, {@link #SRC}, {@link #DST},
 679      *         {@link #SRC_OVER}, {@link #DST_OVER}, {@link #SRC_IN},
 680      *         {@link #DST_IN}, {@link #SRC_OUT}, {@link #DST_OUT},
 681      *         {@link #SRC_ATOP}, {@link #DST_ATOP}, or {@link #XOR}
 682      */
 683     public static AlphaComposite getInstance(int rule, float alpha) {
 684         if (alpha == 1.0f) {
 685             return getInstance(rule);
 686         }
 687         return new AlphaComposite(rule, alpha);
 688     }
 689 
 690     /**
 691      * Creates a context for the compositing operation.
 692      * The context contains state that is used in performing
 693      * the compositing operation.
 694      * @param srcColorModel  the {@link ColorModel} of the source