1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2009-2011 - DIGITEO - Pierre Lando
4  *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13  */
14 
15 package org.scilab.forge.scirenderer.shapes.appearance;
16 
17 /**
18  * @author Pierre Lando
19  */
20 @SuppressWarnings(value = { "serial" })
21 public final class Color extends java.awt.Color {
22 
23     private static final float COMPONENT_MAX_VALUE = 255f;
24 
25     /**
26      * The default color.
27      */
28     private static final Color DEFAULT_COLOR = new Color(.2f, .3f, .4f);
29 
30     /**
31      * Default constructor.
32      * Create a copy of the default color.
33      */
Color()34     public Color() {
35         this(DEFAULT_COLOR);
36     }
37 
38     /**
39      * Copy constructor
40      * @param c the color to copy.
41      */
Color(Color c)42     public Color(Color c) {
43         super(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
44     }
45 
46     /**
47      * Creates an sRGB color with the specified red, green, blue, and
48      * alpha values in the range [0.0; 1.0].  The actual color
49      * used in rendering depends on finding the best match given the
50      * color space available for a particular output device.
51      *
52      * @param r the red component
53      * @param g the green component
54      * @param b the blue component
55      * @param a the alpha component
56      */
Color(float r, float g, float b, float a)57     public Color(float r, float g, float b, float a) {
58         super(r, g, b, a);
59     }
60 
61     /**
62      * Creates an opaque sRGB color with the specified red, green, and blue
63      * values in the range [0.0; 1.0].  Alpha is defaulted to 1.0.  The
64      * actual color used in rendering depends on finding the best
65      * match given the color space available for a particular output
66      * device.
67      *
68      * @param r the red component
69      * @param g the green component
70      * @param b the blue component
71      */
Color(float r, float g, float b)72     public Color(float r, float g, float b) {
73         super(r, g, b);
74     }
75 
76     /**
77      * Return red component value. In the range [0; 1].
78      * @return red component value. In the range [0; 1].
79      */
getRedAsFloat()80     public float getRedAsFloat() {
81         return ((float) getRed()) / COMPONENT_MAX_VALUE;
82     }
83 
84     /**
85      * Return green component value. In the range [0; 1].
86      * @return green component value. In the range [0; 1].
87      */
getGreenAsFloat()88     public float getGreenAsFloat() {
89         return ((float) getGreen()) / COMPONENT_MAX_VALUE;
90     }
91 
92     /**
93      * Return blue component value. In the range [0; 1].
94      * @return blue component value. In the range [0; 1].
95      */
getBlueAsFloat()96     public float getBlueAsFloat() {
97         return ((float) getBlue()) / COMPONENT_MAX_VALUE;
98     }
99 
100     /**
101      * Return alpha component value. In the range [0; 1].
102      * @return alpha component value. In the range [0; 1].
103      */
getAlphaAsFloat()104     public float getAlphaAsFloat() {
105         return ((float) getAlpha()) / COMPONENT_MAX_VALUE;
106     }
107 }
108