1 50 51 package org.openlaszlo.iv.flash.api; 52 53 import java.io.*; 54 import java.util.*; 55 import java.lang.Math ; 56 import org.openlaszlo.iv.flash.parser.*; 57 import org.openlaszlo.iv.flash.util.*; 58 59 65 public final class AlphaColor extends Color { 66 67 public static final AlphaColor white = new AlphaColor( 255, 255, 255 ); 69 public static final AlphaColor black = new AlphaColor( 0, 0, 0 ); 70 public static final AlphaColor red = new AlphaColor( 255, 0, 0 ); 71 public static final AlphaColor blue = new AlphaColor( 0, 0, 255 ); 72 public static final AlphaColor green = new AlphaColor( 0, 255, 0 ); 73 public static final AlphaColor lightgray = new AlphaColor( 180, 180, 180 ); 74 public static final AlphaColor gray = new AlphaColor( 150, 150, 150 ); 75 public static final AlphaColor darkgray = new AlphaColor( 90, 90, 90 ); 76 77 private int a; 78 79 public AlphaColor() {} 80 81 86 public AlphaColor( int rgba ) { 87 setRGBA( rgba ); 88 } 89 90 97 public AlphaColor( int r, int g, int b ) { 98 this( r, g, b, 255 ); 99 } 100 101 108 public AlphaColor( float r, float g, float b ) { 109 this( r, g, b, 1.0f ); 110 } 111 112 120 public AlphaColor( int r, int g, int b, int a ) { 121 super( r, g, b ); 122 this.a = a; 123 } 124 125 133 public AlphaColor( float r, float g, float b, float a ) { 134 super( r, g, b ); 135 this.a = Math.round( a * 255 ); 136 } 137 138 public int getAlpha() { 139 return a; 140 } 141 142 147 public int getRGBA() { 148 return a<<24 | getRGB(); 149 } 150 151 public void setAlpha( int a ) { 152 this.a = a; 153 } 154 155 160 public void setRGBA( int rgba ) { 161 setRGB( rgba ); 162 this.a = (rgba&0xff000000)>>>24; 163 } 164 165 170 public void write( FlashOutput fob ) { 171 writeRGBA( fob ); 172 } 173 174 public void writeRGBA( FlashOutput fob ) { 175 super.writeRGB( fob ); 176 fob.writeByte( a ); 177 } 178 179 public void printContent( PrintStream out, String indent ) { 180 out.println( indent+"AlphaColor: (0x"+Util.b2h(r)+",0x"+Util.b2h(g)+",0x"+Util.b2h(b)+",0x"+Util.b2h(a)+")" ); 181 } 182 183 public static AlphaColor parse( Parser p ) { 184 return parseRGBA(p); 185 } 186 187 192 public static void skip( Parser p ) { 193 p.skip(4); 194 } 195 196 protected FlashItem copyInto( FlashItem item, ScriptCopier copier ) { 197 super.copyInto( item, copier ); 198 ((AlphaColor)item).a = a; 199 return item; 200 } 201 202 public FlashItem getCopy( ScriptCopier copier ) { 203 return copyInto( new AlphaColor(), copier ); 204 } 205 206 public boolean equals( Object o ) { 207 if( o instanceof AlphaColor ) { 208 AlphaColor c = (AlphaColor) o; 209 return r == c.r && g == c.g && b == c.b && a == c.a; 210 } else 211 return a == 255 && super.equals( o ); 212 } 213 214 220 public boolean hasAlpha() { return true; } 221 222 227 public AlphaColor getReducedColor() { 228 double k = 0.5; 229 return new AlphaColor( r, g, b, (int)(a*k) ); 231 } 232 233 240 public static AlphaColor getColor( String name ) { 241 return (AlphaColor) colors.get(name.toLowerCase()); 242 } 243 244 public static Enumeration getAllColors() { 245 return colors.elements(); 246 } 247 248 private static final Hashtable colors = new Hashtable(); 250 251 private static void add( String name, int rgb ) { 252 AlphaColor c = new AlphaColor(); 253 c.setRGB(rgb); 254 c.setAlpha(255); 255 colors.put(name.toLowerCase(), c); 256 } 257 258 static { 259 add("black",0x000000); 260 add("navy",0x000080); 261 add("blue",0x0000FF); 262 add("green",0x008000); 263 add("dark cyan",0x008B8B); 264 add("dark turquoise",0x00CED1); 265 add("lime",0x00FF00); 266 add("aqua",0x00FFFF); 267 add("midnight blue",0x191970); 268 add("light seagreen",0x20B2AA); 269 add("forest green",0x228B22); 270 add("lime green",0x32CD32); 271 add("turquoise",0x40E0D0); 272 add("dark slateblue",0x4682B4); 273 add("medium turquoise",0x48D1CC); 274 add("cadet blue",0x5F9EA0); 275 add("medium aquamarine",0x66CDAA); 276 add("slate blue",0x6A5ACD); 277 add("slate gray",0x708090); 278 add("medium slateblue",0x7B68EE); 279 add("chartreuse",0x7FFF00); 280 add("maroon",0x800000); 281 add("olive",0x80800); 282 add("sky blue",0x87CEEB); 283 add("dark red",0x8B0000); 284 add("saddle brown",0x8B4513); 285 add("light green",0x90EE90); 286 add("dark violet",0x9400D3); 287 add("dark orchid",0x9932CC); 288 add("sienna",0xA0522D); 289 add("dark gray",0xA9A9A9); 290 add("green yellow",0xADFF2F); 291 add("pale turquoise",0xAFEEEE); 292 add("firebrick",0xB22222); 293 add("dark goldenrod",0xB8860B); 294 add("medium orchid",0xBA55D); 295 add("medium violetred",0xC71585); 296 add("indian red",0xCD5C5C); 297 add("peru",0xCD853F); 298 add("thistle",0xD8BFD8); 299 add("orchid",0xDA70D6); 300 add("goldenrod",0xDAA520); 301 add("pale violetred",0xDB7093); 302 add("crimson",0xDC143C); 303 add("dark salmon",0xE9967A); 304 add("violet",0xEE82EE); 305 add("pale goldenrod",0xEEE8AA); 306 add("light coral",0xF08080); 307 add("sandy brown",0xF4A460); 308 add("wheat",0xF5DEB3); 309 add("ghost white",0xF8F8FF); 310 add("salmon",0xFA8072); 311 add("antique white",0xFAEBD7); 312 add("red",0xFF0000); 313 add("fuchsia",0xFF00FF); 314 add("magenta",0xFF00FF); 315 add("hot pink",0xFF69B4); 316 add("coral",0xFF7F50); 317 add("dark orange",0xFF8C00); 318 add("light salmon",0xFFA07A); 319 add("orange",0xFFA500); 320 add("light pink",0xFFB6C1); 321 add("pink",0xFFC0CB); 322 add("papaya whip",0xFFEFD5); 323 add("lavender blush",0xFFF0F5); 324 add("seashel",0xFFF5EE); 325 add("snow",0xFFFAFA); 326 add("yellow",0xFFFF00); 327 add("white",0xFFFFFF); 328 add("dark blue",0x00008B); 329 add("medium blue",0x0000CD); 330 add("dark green",0x006400); 331 add("teal",0x008080); 332 add("deep skyblue",0x00BFFF); 333 add("medium springgreen",0x00FA9A); 334 add("spring green",0x00FF7F); 335 add("cyan",0x00FFFF); 336 add("dodger blue",0x1E90FF); 337 add("sea green",0x2E8B57); 338 add("dark slategray",0x2F4F4F); 339 add("medium seagreen",0x3CB371); 340 add("royal blue",0x4169E1); 341 add("steel blue",0x4682B4); 342 add("indigo",0x4B0082); 343 add("cornflower blue",0x6495ED); 344 add("dim gray",0x696969); 345 add("olive drab",0x6B8E23); 346 add("light slategray",0x778899); 347 add("lawn green",0x7CFC00); 348 add("aquamarine",0x7FFFD4); 349 add("purple",0x800080); 350 add("gray",0x808080); 351 add("blue violet",0x87CEFA); 352 add("dark magenta",0x8B008B); 353 add("dark seagreen",0x8FBC8F); 354 add("medium purple",0x9370DB); 355 add("pale green",0x98FB98); 356 add("yellow green",0x9ACD32); 357 add("brown",0xA52A2A); 358 add("light blue",0xADD8E6); 359 add("light steelblue",0xB0C4DE); 360 add("powder blue",0xB0E0E6); 361 add("rosy brown",0xBC8F8F); 362 add("dark khaki",0xBC8F8F); 363 add("silver",0xC0C0C0); 364 add("chocolate",0xD2691E); 365 add("tan",0xD2B48C); 366 add("light grey",0xD3D3D3); 367 add("gainsboro",0xDCDCDC); 368 add("plum",0xDDA0DD); 369 add("burlywood",0xDEB887); 370 add("light cyan",0xE0FFFF); 371 add("lavender",0xE6E6FA); 372 add("khaki",0xF0E68C); 373 add("alice blue",0xF0F8FF); 374 add("honeydew",0xF0FFF0); 375 add("azure",0xF0FFFF); 376 add("white smoke",0xF5F5F5); 377 add("mint cream",0xF5FFFA); 378 add("linen",0xFAF0E6); 379 add("light goldenrodyellow",0xFAFAD2); 380 add("old lace",0xFDF5E6); 381 add("deep pink",0xFF1493); 382 add("orange red",0xFF4500); 383 add("tomato",0xFF6347); 384 add("gold",0xFFD700); 385 add("peach puff",0xFFDAB9); 386 add("navajo white",0xFFDEAD); 387 add("moccasin",0xFFE4B5); 388 add("bisque",0xFFE4C4); 389 add("misty rose",0xFFE4E1); 390 add("blanched almond",0xFFEBCD); 391 add("cornsilk",0xFFF8DC); 392 add("lemon chiffon",0xFFFACD); 393 add("floral white",0xFFFAF0); 394 add("light yellow",0xFFFFE0); 395 add("ivory",0xFFFFF0); 396 } 397 398 } 399 | Popular Tags |