1 7 8 package java.awt; 9 10 import java.awt.image.ColorModel ; 11 import sun.java2d.SunCompositeContext; 12 13 334 335 public final class AlphaComposite implements Composite { 336 347 public static final int CLEAR = 1; 348 349 360 public static final int SRC = 2; 361 362 373 public static final int DST = 9; 374 376 386 public static final int SRC_OVER = 3; 387 388 399 public static final int DST_OVER = 4; 400 401 412 public static final int SRC_IN = 5; 413 414 425 public static final int DST_IN = 6; 426 427 438 public static final int SRC_OUT = 7; 439 440 451 public static final int DST_OUT = 8; 452 453 458 470 public static final int SRC_ATOP = 10; 471 472 484 public static final int DST_ATOP = 11; 485 486 499 public static final int XOR = 12; 500 501 506 public static final AlphaComposite Clear = new AlphaComposite (CLEAR); 507 508 513 public static final AlphaComposite Src = new AlphaComposite (SRC); 514 515 521 public static final AlphaComposite Dst = new AlphaComposite (DST); 522 523 528 public static final AlphaComposite SrcOver = new AlphaComposite (SRC_OVER); 529 530 535 public static final AlphaComposite DstOver = new AlphaComposite (DST_OVER); 536 537 542 public static final AlphaComposite SrcIn = new AlphaComposite (SRC_IN); 543 544 549 public static final AlphaComposite DstIn = new AlphaComposite (DST_IN); 550 551 556 public static final AlphaComposite SrcOut = new AlphaComposite (SRC_OUT); 557 558 563 public static final AlphaComposite DstOut = new AlphaComposite (DST_OUT); 564 565 571 public static final AlphaComposite SrcAtop = new AlphaComposite (SRC_ATOP); 572 573 579 public static final AlphaComposite DstAtop = new AlphaComposite (DST_ATOP); 580 581 587 public static final AlphaComposite Xor = new AlphaComposite (XOR); 588 589 private static final int MIN_RULE = CLEAR; 590 private static final int MAX_RULE = XOR; 591 592 float extraAlpha; 593 int rule; 594 595 private AlphaComposite(int rule) { 596 this(rule, 1.0f); 597 } 598 599 private AlphaComposite(int rule, float alpha) { 600 if (alpha < 0.0f || alpha > 1.0f) { 601 throw new IllegalArgumentException ("alpha value out of range"); 602 } 603 if (rule < MIN_RULE || rule > MAX_RULE) { 604 throw new IllegalArgumentException ("unknown composite rule"); 605 } 606 this.rule = rule; 607 this.extraAlpha = alpha; 608 } 609 610 619 public static AlphaComposite getInstance(int rule) { 620 switch (rule) { 621 case CLEAR: 622 return Clear; 623 case SRC: 624 return Src; 625 case DST: 626 return Dst; 627 case SRC_OVER: 628 return SrcOver; 629 case DST_OVER: 630 return DstOver; 631 case SRC_IN: 632 return SrcIn; 633 case DST_IN: 634 return DstIn; 635 case SRC_OUT: 636 return SrcOut; 637 case DST_OUT: 638 return DstOut; 639 case SRC_ATOP: 640 return SrcAtop; 641 case DST_ATOP: 642 return DstAtop; 643 case XOR: 644 return Xor; 645 default: 646 throw new IllegalArgumentException ("unknown composite rule"); 647 } 648 } 649 650 667 public static AlphaComposite getInstance(int rule, float alpha) { 668 if (alpha == 1.0f) { 669 return getInstance(rule); 670 } 671 return new AlphaComposite (rule, alpha); 672 } 673 674 683 public CompositeContext createContext(ColorModel srcColorModel, 684 ColorModel dstColorModel, 685 RenderingHints hints) { 686 return new SunCompositeContext(this, srcColorModel, dstColorModel); 687 } 688 689 694 public float getAlpha() { 695 return extraAlpha; 696 } 697 698 702 public int getRule() { 703 return rule; 704 } 705 706 710 public int hashCode() { 711 return (Float.floatToIntBits(extraAlpha) * 31 + rule); 712 } 713 714 727 public boolean equals(Object obj) { 728 if (!(obj instanceof AlphaComposite )) { 729 return false; 730 } 731 732 AlphaComposite ac = (AlphaComposite ) obj; 733 734 if (rule != ac.rule) { 735 return false; 736 } 737 738 if (extraAlpha != ac.extraAlpha) { 739 return false; 740 } 741 742 return true; 743 } 744 745 } 746 | Popular Tags |