⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 color.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* Color.java -- represents a color in Java   Copyright (C) 1999, 2002, 2005  Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package java.awt;import java.awt.color.ColorSpace;import java.awt.geom.AffineTransform;import java.awt.geom.Rectangle2D;import java.awt.image.ColorModel;import java.io.Serializable;/** * This class represents a color value in the AWT system. It uses the sRGB * (standard Red-Green-Blue) system, along with an alpha value ranging from * transparent (0.0f or 0) and opaque (1.0f or 255). The color is not * pre-multiplied by the alpha value an any of the accessor methods. Further * information about sRGB can be found at * <a href="http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html"> * http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html</a>. * * @author Aaron M. Renn (arenn@urbanophile.com) * @see ColorSpace * @see AlphaComposite * @since 1.0 * @status updated to 1.4 */public class Color implements Paint, Serializable{  /**   * Compatible with JDK 1.0+.   */  private static final long serialVersionUID = 118526816881161077L;  /** Constant for the color white: R=255, G=255, B=255. */  public static final Color white = new Color(0xffffff, false);  /**   * Constant for the color white: R=255, G=255, B=255.   *   * @since 1.4   */  public static final Color WHITE = white;  /** Constant for the color light gray: R=192, G=192, B=192. */  public static final Color lightGray = new Color(0xc0c0c0, false);  /**   * Constant for the color light gray: R=192, G=192, B=192.   *   * @since 1.4   */  public static final Color LIGHT_GRAY = lightGray;  /** Constant for the color gray: R=128, G=128, B=128. */  public static final Color gray = new Color(0x808080, false);  /**   * Constant for the color gray: R=128, G=128, B=128.   *   * @since 1.4   */  public static final Color GRAY = gray;  /** Constant for the color dark gray: R=64, G=64, B=64. */  public static final Color darkGray = new Color(0x404040, false);  /**   * Constant for the color dark gray: R=64, G=64, B=64.   *   * @since 1.4   */  public static final Color DARK_GRAY = darkGray;  /** Constant for the color black: R=0, G=0, B=0. */  public static final Color black = new Color(0x000000, false);  /**   * Constant for the color black: R=0, G=0, B=0.   *   * @since 1.4   */  public static final Color BLACK = black;  /** Constant for the color red: R=255, G=0, B=0. */  public static final Color red = new Color(0xff0000, false);  /**   * Constant for the color red: R=255, G=0, B=0.   *   * @since 1.4   */  public static final Color RED = red;  /** Constant for the color pink: R=255, G=175, B=175. */  public static final Color pink = new Color(0xffafaf, false);  /**   * Constant for the color pink: R=255, G=175, B=175.   *   * @since 1.4   */  public static final Color PINK = pink;  /** Constant for the color orange: R=255, G=200, B=0. */  public static final Color orange = new Color(0xffc800, false);  /**   * Constant for the color orange: R=255, G=200, B=0.   *   * @since 1.4   */  public static final Color ORANGE = orange;  /** Constant for the color yellow: R=255, G=255, B=0. */  public static final Color yellow = new Color(0xffff00, false);  /**   * Constant for the color yellow: R=255, G=255, B=0.   *   * @since 1.4   */  public static final Color YELLOW = yellow;  /** Constant for the color green: R=0, G=255, B=0. */  public static final Color green = new Color(0x00ff00, false);  /**   * Constant for the color green: R=0, G=255, B=0.   *   * @since 1.4   */  public static final Color GREEN = green;  /** Constant for the color magenta: R=255, G=0, B=255. */  public static final Color magenta = new Color(0xff00ff, false);  /**   * Constant for the color magenta: R=255, G=0, B=255.   *   * @since 1.4   */  public static final Color MAGENTA = magenta;  /** Constant for the color cyan: R=0, G=255, B=255. */  public static final Color cyan = new Color(0x00ffff, false);  /**   * Constant for the color cyan: R=0, G=255, B=255.   *   * @since 1.4   */  public static final Color CYAN = cyan;  /** Constant for the color blue: R=0, G=0, B=255. */  public static final Color blue = new Color(0x0000ff, false);  /**   * Constant for the color blue: R=0, G=0, B=255.   *   * @since 1.4   */  public static final Color BLUE = blue;  /** Internal mask for red. */  private static final int RED_MASK = 255 << 16;  /** Internal mask for green. */  private static final int GREEN_MASK = 255 << 8;  /** Internal mask for blue. */  private static final int BLUE_MASK = 255;  /** Internal mask for alpha. Package visible for use in subclass. */  static final int ALPHA_MASK = 255 << 24;  /** Amount to scale a color by when brightening or darkening. */  private static final float BRIGHT_SCALE = 0.7f;  /**   * The color value, in sRGB. Note that the actual color may be more   * precise if frgbvalue or fvalue is non-null. This class stores alpha, red,   * green, and blue, each 0-255, packed in an int. However, the subclass   * SystemColor stores an index into an array. Therefore, for serial   * compatibility (and because of poor design on Sun's part), this value   * cannot be used directly; instead you must use <code>getRGB()</code>.   *   * @see #getRGB()   * @serial the value of the color, whether an RGB literal or array index   */  final int value;  /**   * The color value, in sRGB. This may be null if the color was constructed   * with ints; and it does not include alpha. This stores red, green, and   * blue, in the range 0.0f - 1.0f.   *   * @see #getRGBColorComponents(float[])   * @see #getRGBComponents(float[])   * @serial the rgb components of the value   * @since 1.2   */  private float[] frgbvalue;  /**   * The color value, in the native ColorSpace components. This may be null   * if the color was constructed with ints or in the sRGB color space; and   * it does not include alpha.   *   * @see #getRGBColorComponents(float[])   * @see #getRGBComponents(float[])   * @serial the original color space components of the color   * @since 1.2   */  private float[] fvalue;  /**   * The alpha value. This is in the range 0.0f - 1.0f, but is invalid if   * deserialized as 0.0 when frgbvalue is null.   *   * @see #getRGBComponents(float[])   * @see #getComponents(float[])   * @serial the alpha component of this color   * @since 1.2   */  private final float falpha;  /**   * The ColorSpace. Null means the default sRGB space.   *   * @see #getColor(String)   * @see #getColorSpace()   * @see #getColorComponents(float[])   * @serial the color space for this color   * @since 1.2   */  private final ColorSpace cs;  /**   * The paint context for this solid color. Package visible for use in   * subclass.   */  transient ColorPaintContext context;  /**   * Initializes a new instance of <code>Color</code> using the specified   * red, green, and blue values, which must be given as integers in the   * range of 0-255. Alpha will default to 255 (opaque). When drawing to   * screen, the actual color may be adjusted to the best match of hardware   * capabilities.   *   * @param red the red component of the RGB value   * @param green the green component of the RGB value   * @param blue the blue component of the RGB value   * @throws IllegalArgumentException if the values are out of range 0-255   * @see #getRed()   * @see #getGreen()   * @see #getBlue()   * @see #getRGB()   * @see #Color(int, int, int, int)   */  public Color(int red, int green, int blue)  {    this(red, green, blue, 255);  }  /**   * Initializes a new instance of <code>Color</code> using the specified   * red, green, blue, and alpha values, which must be given as integers in   * the range of 0-255. When drawing to screen, the actual color may be   * adjusted to the best match of hardware capabilities.   *   * @param red the red component of the RGB value   * @param green the green component of the RGB value   * @param blue the blue component of the RGB value   * @param alpha the alpha value of the color   * @throws IllegalArgumentException if the values are out of range 0-255   * @see #getRed()   * @see #getGreen()   * @see #getBlue()   * @see #getAlpha()   * @see #getRGB()   */  public Color(int red, int green, int blue, int alpha)  {    if ((red & 255) != red || (green & 255) != green || (blue & 255) != blue        || (alpha & 255) != alpha)      throw new IllegalArgumentException("Bad RGB values"                                        +" red=0x"+Integer.toHexString(red)                                        +" green=0x"+Integer.toHexString(green)                                        +" blue=0x"+Integer.toHexString(blue)                                        +" alpha=0x"+Integer.toHexString(alpha)  );    value = (alpha << 24) | (red << 16) | (green << 8) | blue;    falpha = 1;    cs = null;  }  /**   * Initializes a new instance of <code>Color</code> using the specified   * RGB value. The blue value is in bits 0-7, green in bits 8-15, and   * red in bits 16-23. The other bits are ignored. The alpha value is set   * to 255 (opaque). When drawing to screen, the actual color may be

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -