1 43 44 package org.jfree.ui; 45 46 import java.awt.GradientPaint ; 47 import java.awt.Shape ; 48 import java.awt.geom.Rectangle2D ; 49 import java.io.Serializable ; 50 51 import org.jfree.util.PublicCloneable; 52 53 58 public class StandardGradientPaintTransformer 59 implements GradientPaintTransformer, Cloneable , PublicCloneable, 60 Serializable { 61 62 63 private static final long serialVersionUID = -8155025776964678320L; 64 65 66 private GradientPaintTransformType type; 67 68 71 public StandardGradientPaintTransformer() { 72 this(GradientPaintTransformType.VERTICAL); 73 } 74 75 80 public StandardGradientPaintTransformer( 81 final GradientPaintTransformType type) { 82 this.type = type; 83 } 84 85 93 public GradientPaint transform(final GradientPaint paint, 94 final Shape target) { 95 96 GradientPaint result = paint; 97 final Rectangle2D bounds = target.getBounds2D(); 98 99 if (this.type.equals(GradientPaintTransformType.VERTICAL)) { 100 result = new GradientPaint ( 101 (float) bounds.getCenterX(), (float) bounds.getMinY(), 102 paint.getColor1(), (float) bounds.getCenterX(), 103 (float) bounds.getMaxY(), paint.getColor2() 104 ); 105 } 106 else if (this.type.equals(GradientPaintTransformType.HORIZONTAL)) { 107 result = new GradientPaint ( 108 (float) bounds.getMinX(), (float) bounds.getCenterY(), 109 paint.getColor1(), (float) bounds.getMaxX(), 110 (float) bounds.getCenterY(), paint.getColor2() 111 ); 112 } 113 else if (this.type.equals(GradientPaintTransformType.CENTER_HORIZONTAL)) 114 { 115 result = new GradientPaint ( 116 (float) bounds.getCenterX(), (float) bounds.getCenterY(), 117 paint.getColor1(), (float) bounds.getMaxX(), 118 (float) bounds.getCenterY(), paint.getColor2(), true 119 ); 120 } 121 else if (this.type.equals(GradientPaintTransformType.CENTER_VERTICAL)) { 122 result = new GradientPaint ( 123 (float) bounds.getCenterX(), (float) bounds.getMinY(), 124 paint.getColor1(), (float) bounds.getCenterX(), 125 (float) bounds.getCenterY(), paint.getColor2(), true 126 ); 127 } 128 129 return result; 130 } 131 132 139 public boolean equals(final Object obj) { 140 if (obj == this) { 141 return true; 142 } 143 if (!(obj instanceof StandardGradientPaintTransformer)) { 144 return false; 145 } 146 final StandardGradientPaintTransformer that 147 = (StandardGradientPaintTransformer) obj; 148 if (this.type != that.type) { 149 return false; 150 } 151 return true; 152 } 153 154 162 public Object clone() throws CloneNotSupportedException { 163 return super.clone(); 164 } 165 166 171 public int hashCode() { 172 return (this.type != null ? this.type.hashCode() : 0); 173 } 174 175 } 176 | Popular Tags |