1 18 package org.apache.batik.ext.awt; 19 20 import java.awt.Color ; 21 import java.awt.Paint ; 22 import java.awt.geom.AffineTransform ; 23 24 34 35 public abstract class MultipleGradientPaint implements Paint { 36 37 38 protected int transparency; 39 40 41 protected float[] fractions; 42 43 44 protected Color [] colors; 45 46 47 protected AffineTransform gradientTransform; 48 49 50 protected CycleMethodEnum cycleMethod; 51 52 53 protected ColorSpaceEnum colorSpace; 54 55 56 public static class ColorSpaceEnum { 57 } 58 59 60 public static class CycleMethodEnum { 61 } 62 63 66 public static final CycleMethodEnum NO_CYCLE = new CycleMethodEnum(); 67 68 72 public static final CycleMethodEnum REFLECT = new CycleMethodEnum(); 73 74 78 public static final CycleMethodEnum REPEAT = new CycleMethodEnum(); 79 80 83 public static final ColorSpaceEnum SRGB = new ColorSpaceEnum(); 84 85 88 public static final ColorSpaceEnum LINEAR_RGB = new ColorSpaceEnum(); 89 90 91 112 public MultipleGradientPaint(float[] fractions, 113 Color [] colors, 114 CycleMethodEnum cycleMethod, 115 ColorSpaceEnum colorSpace, 116 AffineTransform gradientTransform) { 117 118 if (fractions == null) { 119 throw new IllegalArgumentException ("Fractions array cannot be " + 120 "null"); 121 } 122 123 if (colors == null) { 124 throw new IllegalArgumentException ("Colors array cannot be null"); 125 } 126 127 if (fractions.length != colors.length) { 128 throw new IllegalArgumentException ("Colors and fractions must " + 129 "have equal size"); 130 } 131 132 if (colors.length < 2) { 133 throw new IllegalArgumentException ("User must specify at least " + 134 "2 colors"); 135 } 136 137 if ((colorSpace != LINEAR_RGB) && 138 (colorSpace != SRGB)) { 139 throw new IllegalArgumentException ("Invalid colorspace for " + 140 "interpolation."); 141 } 142 143 if ((cycleMethod != NO_CYCLE) && 144 (cycleMethod != REFLECT) && 145 (cycleMethod != REPEAT)) { 146 throw new IllegalArgumentException ("Invalid cycle method."); 147 } 148 149 if (gradientTransform == null) { 150 throw new IllegalArgumentException ("Gradient transform cannot be "+ 151 "null."); 152 } 153 154 this.fractions = new float[fractions.length]; 156 System.arraycopy(fractions, 0, this.fractions, 0, fractions.length); 157 158 this.colors = new Color [colors.length]; 160 System.arraycopy(colors, 0, this.colors, 0, colors.length); 161 162 this.colorSpace = colorSpace; 164 this.cycleMethod = cycleMethod; 165 166 this.gradientTransform = (AffineTransform )gradientTransform.clone(); 168 169 boolean opaque = true; 171 for(int i=0; i<colors.length; i++){ 172 opaque = opaque && (colors[i].getAlpha()==0xff); 173 } 174 175 if(opaque) { 176 transparency = OPAQUE; 177 } 178 179 else { 180 transparency = TRANSLUCENT; 181 } 182 } 183 184 189 public Color [] getColors() { 190 Color colors[] = new Color [this.colors.length]; 191 System.arraycopy(this.colors, 0, colors, 0, this.colors.length); 192 return colors; 193 } 194 195 202 public float[] getFractions() { 203 float fractions[] = new float[this.fractions.length]; 204 System.arraycopy(this.fractions, 0, fractions, 0, this.fractions.length); 205 return fractions; 206 } 207 208 213 public int getTransparency() { 214 return transparency; 215 } 216 217 221 public CycleMethodEnum getCycleMethod() { 222 return cycleMethod; 223 } 224 225 231 public ColorSpaceEnum getColorSpace() { 232 return colorSpace; 233 } 234 235 239 public AffineTransform getTransform() { 240 return (AffineTransform )gradientTransform.clone(); 241 } 242 } 243 | Popular Tags |