/[classpath]/classpath/java/awt/Color.java
ViewVC logotype

Diff of /classpath/java/awt/Color.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by mark, Sun Jan 13 15:45:15 2002 UTC revision 1.4 by tromey, Tue Jan 22 22:00:14 2002 UTC
# Line 1  Line 1 
1  /* Color.java -- Class representing a color in Java  /* Color.java -- Class representing a color in Java
2     Copyright (C) 1999 Free Software Foundation, Inc.     Copyright (C) 1999, 2002 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 42  public class Color implements java.io.Se Line 42  public class Color implements java.io.Se
42  /**  /**
43    * Constant for the color white    * Constant for the color white
44    */    */
45  public static final Color white = new Color(255,255,255);  public static final Color white = new Color(255,255,255,255);
46    
47  /**  /**
48    * Constant for the color light gray    * Constant for the color light gray
49    */    */
50  public static final Color lightGray = new Color(192,192,192);  public static final Color lightGray = new Color(192,192,192,255);
51    
52  /**  /**
53    * Constant for the color gray    * Constant for the color gray
54    */    */
55  public static final Color gray = new Color(128,128,128);  public static final Color gray = new Color(128,128,128,255);
56    
57  /**  /**
58    * Constant for the color dark gray    * Constant for the color dark gray
59    */    */
60  public static final Color darkGray = new Color(64,64,64);  public static final Color darkGray = new Color(64,64,64,255);
61    
62  /**  /**
63    * Constant for the color black    * Constant for the color black
64    */    */
65  public static final Color black = new Color(0,0,0);  public static final Color black = new Color(0,0,0,255);
66    
67  /**  /**
68    * Constant for the color red    * Constant for the color red
69    */    */
70  public static final Color red = new Color(255,0,0);  public static final Color red = new Color(255,0,0,255);
71    
72  /**  /**
73    * Constant for the color pink    * Constant for the color pink
74    */    */
75  public static final Color pink = new Color(255, 175, 175);  public static final Color pink = new Color(255, 175, 175,255);
76    
77  /**  /**
78    * Constant for the color orange    * Constant for the color orange
79    */    */
80  public static final Color orange = new Color(255, 200, 0);  public static final Color orange = new Color(255, 200, 0,255);
81    
82  /**  /**
83    * Constant for the color yellow    * Constant for the color yellow
84    */    */
85  public static final Color yellow = new Color(255,255,0);  public static final Color yellow = new Color(255,255,0,255);
86    
87  /**  /**
88    * Constant for the color green    * Constant for the color green
89    */    */
90  public static final Color green = new Color(0,255,0);  public static final Color green = new Color(0,255,0,255);
91    
92  /**  /**
93    * Constant for the color magenta    * Constant for the color magenta
94    */    */
95  public static final Color magenta = new Color(255,0,255);  public static final Color magenta = new Color(255,0,255,255);
96    
97  /**  /**
98    * Constant for the color cyan    * Constant for the color cyan
99    */    */
100  public static final Color cyan = new Color(0,255,255);  public static final Color cyan = new Color(0,255,255,255);
101    
102  /**  /**
103    * Constant for the color blue    * Constant for the color blue
104    */    */
105  public static final Color blue = new Color(0,0,255);  public static final Color blue = new Color(0,0,255,255);
106    
107  // Serialization Constant  // Serialization Constant
108  private static final long serialVersionUID = 118526816881161077L;  private static final long serialVersionUID = 118526816881161077L;
# Line 111  private static final long serialVersionU Line 111  private static final long serialVersionU
111  private static final int redmask = 255 << 16;  private static final int redmask = 255 << 16;
112  private static final int greenmask = 255 << 8;  private static final int greenmask = 255 << 8;
113  private static final int bluemask = 255;  private static final int bluemask = 255;
114    private static final int alphamask = 255 << 24;
115    
116    private static final int BRIGHT_STEP = 0x30;
117    
118  /*************************************************************************/  /*************************************************************************/
119    
# Line 121  private static final int bluemask = 255; Line 124  private static final int bluemask = 255;
124  /**  /**
125    * @serial The RGB value of the color.    * @serial The RGB value of the color.
126    */    */
127  private int value;  private int value = 0xFFFFFFFF;
128    
129  /*************************************************************************/  /*************************************************************************/
130    
# Line 292  Color(int red, int green, int blue) Line 295  Color(int red, int green, int blue)
295    value = blue + (green << 8) + (red << 16);    value = blue + (green << 8) + (red << 16);
296  }  }
297    
298    public
299    Color(int red, int green, int blue, int alpha)
300    {
301      if ((red < 0) || (red > 255) || (green < 0) || (green > 255) ||
302          (blue < 0) || (blue > 255))
303        throw new IllegalArgumentException("Bad RGB values");
304    
305      value = blue + (green << 8) + (red << 16) + (alpha << 24);
306    }
307    
308  /*************************************************************************/  /*************************************************************************/
309    
310  /**  /**
# Line 307  Color(int value) Line 320  Color(int value)
320    this.value = value;    this.value = value;
321  }  }
322    
323    public
324    Color(int value, boolean hasalpha)
325    {
326      this.value = value;
327      if (! hasalpha)
328        this.value |= 0xFF000000;
329    }
330    
331  /*************************************************************************/  /*************************************************************************/
332    
333  /**  /**
# Line 382  getBlue() Line 403  getBlue()
403    return(blueval);    return(blueval);
404  }  }
405    
406    public int
407    getAlpha()
408    {
409      int alphaval = (value & alphamask);
410    
411      return(alphaval);
412    }
413    
414    public int
415    getTransparency()
416    {
417      if (getAlpha() == 0xFF)
418        return Transparency.OPAQUE;
419      else
420        return Transparency.TRANSLUCENT;
421    }
422    
423  /*************************************************************************/  /*************************************************************************/
424    
425  /**  /**
# Line 408  getRGB() Line 446  getRGB()
446  public Color  public Color
447  brighter()  brighter()
448  {  {
449    int red = getRed();    return new Color(Math.min(255, getRed()   + BRIGHT_STEP),
450    int green = getGreen();                     Math.min(255, getGreen() + BRIGHT_STEP),
451    int blue = getBlue();                     Math.min(255, getBlue()  + BRIGHT_STEP),
452                       getAlpha());
   red += 10;  
   green += 10;  
   blue += 10;  
   
   if (red > 255)  
     red = 255;  
   if (green > 255)  
     green = 255;  
   if (blue > 255)  
     blue = 255;  
   
   return(new Color(red, green, blue));  
453  }  }
454    
455  /*************************************************************************/  /*************************************************************************/
# Line 438  brighter() Line 464  brighter()
464  public Color  public Color
465  darker()  darker()
466  {  {
467    int red = getRed();    return new Color(Math.max(0, getRed()   - BRIGHT_STEP),
468    int green = getGreen();                     Math.max(0, getGreen() - BRIGHT_STEP),
469    int blue = getBlue();                     Math.max(0, getBlue()  - BRIGHT_STEP),
470                       getAlpha());
   red -= 10;  
   green -= 10;  
   blue -= 10;  
   
   if (red < 0)  
     red = 0;  
   if (green < 0)  
     green = 0;  
   if (blue < 0)  
     blue = 0;  
   
   return(new Color(red, green, blue));  
471  }  }
472    
473  /*************************************************************************/  /*************************************************************************/
# Line 483  hashCode() Line 497  hashCode()
497  public boolean  public boolean
498  equals(Object obj)  equals(Object obj)
499  {  {
   if (obj == null)  
     return(false);  
   
500    if (!(obj instanceof Color))    if (!(obj instanceof Color))
501      return(false);      return(false);
502    
503    Color c = (Color)obj;    Color c = (Color)obj;
504      return value == c.value;
   if (c.getRed() != getRed())  
     return(false);  
   if (c.getGreen() != getGreen())  
     return(false);  
   if (c.getBlue() != getBlue())  
     return(false);  
   
   return(true);  
505  }  }
506    
507  /*************************************************************************/  /*************************************************************************/

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26