## modules/graphics/src/main/java/javafx/scene/paint/Color.java

Print this page

    rev 4839 : RT-2529: Locale specific runtime errors (Turkish)

      10  *
      11  * This code is distributed in the hope that it will be useful, but WITHOUT
      12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14  * version 2 for more details (a copy is included in the LICENSE file that
      15  * accompanied this code).
      16  *
      17  * You should have received a copy of the GNU General Public License version
      18  * 2 along with this work; if not, write to the Free Software Foundation,
      19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
      20  *
      21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
      22  * or visit www.oracle.com if you need additional information or have any
      23  * questions.
      24  */
      25
      26 package javafx.scene.paint;
      27
      28 import javafx.animation.Interpolatable;
      29 import java.util.HashMap;

      30 import java.util.Map;
      31 import com.sun.javafx.Utils;
      32 import com.sun.javafx.beans.annotations.Default;
      33 import com.sun.javafx.tk.Toolkit;
      34
      35 // NOTE: this definition, while correct, contains a lot of information which
      36 // is irrelevant to most developers. We should get to the basic definition and
      37 // usage patterns sooner.
      38
      39 /**
      40  * The Color class is used to encapsulate colors in the default sRGB color space.
      41  * Every color has an implicit alpha value of 1.0 or an explicit one provided
      42  * in the constructor. The alpha value defines the transparency of a color
      43  * and can be  represented by a double value in the range 0.0-1.0 or 0-255.
      44  * An alpha value of 1.0 or 255 means that the color is completely opaque
      45  * and an alpha value of 0 or 0.0 means that the color is completely transparent.
      46  * When constructing a {@code Color} with an explicit alpha or getting
      47  * the color/alpha components of a Color,
      48  * the color components are never premultiplied by the alpha component.
      49  * </p>
     371      * </table>
     372      * </div>
     373      *
     374      * @param colorString the name or numeric representation of the color
     375      *                    in one of the supported formats
     376      * @param opacity the opacity component in range from 0.0 (transparent)
     377      *                to 1.0 (opaque)
     378      * @throws NullPointerException if {@code colorString} is {@code null}
     379      * @throws IllegalArgumentException if {@code colorString} specifies
     380      *      an unsupported color name or contains an illegal numeric value
     381      */
     382     public static Color web(String colorString, double opacity) {
     383         if (colorString == null) {
     384             throw new NullPointerException(
     385                     "The color components or name must be specified");
     386         }
     387         if (colorString.isEmpty()) {
     388             throw new IllegalArgumentException("Invalid color specification");
     389         }
     390
     391         String color = colorString.toLowerCase();
     392
     393         if (color.startsWith("#")) {
     394             color = color.substring(1);
     395         } else if (color.startsWith("0x")) {
     396             color = color.substring(2);
     397         } else if (color.startsWith("rgb")) {
     398             if (color.startsWith("(", 3)) {
     399                 return parseRGBColor(color, 4, false, opacity);
     400             } else if (color.startsWith("a(", 3)) {
     401                 return parseRGBColor(color, 5, true, opacity);
     402             }
     403         } else if (color.startsWith("hsl")) {
     404             if (color.startsWith("(", 3)) {
     405                 return parseHSLColor(color, 4, false, opacity);
     406             } else if (color.startsWith("a(", 3)) {
     407                 return parseHSLColor(color, 5, true, opacity);
     408             }
     409         } else {
     410             Color col = NamedColors.get(color);
     411             if (col != null) {
      10  *
      11  * This code is distributed in the hope that it will be useful, but WITHOUT
      12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14  * version 2 for more details (a copy is included in the LICENSE file that
      15  * accompanied this code).
      16  *
      17  * You should have received a copy of the GNU General Public License version
      18  * 2 along with this work; if not, write to the Free Software Foundation,
      19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
      20  *
      21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
      22  * or visit www.oracle.com if you need additional information or have any
      23  * questions.
      24  */
      25
      26 package javafx.scene.paint;
      27
      28 import javafx.animation.Interpolatable;
      29 import java.util.HashMap;
      30 import java.util.Locale;
      31 import java.util.Map;
      32 import com.sun.javafx.Utils;
      33 import com.sun.javafx.beans.annotations.Default;
      34 import com.sun.javafx.tk.Toolkit;
      35
      36 // NOTE: this definition, while correct, contains a lot of information which
      37 // is irrelevant to most developers. We should get to the basic definition and
      38 // usage patterns sooner.
      39
      40 /**
      41  * The Color class is used to encapsulate colors in the default sRGB color space.
      42  * Every color has an implicit alpha value of 1.0 or an explicit one provided
      43  * in the constructor. The alpha value defines the transparency of a color
      44  * and can be  represented by a double value in the range 0.0-1.0 or 0-255.
      45  * An alpha value of 1.0 or 255 means that the color is completely opaque
      46  * and an alpha value of 0 or 0.0 means that the color is completely transparent.
      47  * When constructing a {@code Color} with an explicit alpha or getting
      48  * the color/alpha components of a Color,
      49  * the color components are never premultiplied by the alpha component.
      50  * </p>
     372      * </table>
     373      * </div>
     374      *
     375      * @param colorString the name or numeric representation of the color
     376      *                    in one of the supported formats
     377      * @param opacity the opacity component in range from 0.0 (transparent)
     378      *                to 1.0 (opaque)
     379      * @throws NullPointerException if {@code colorString} is {@code null}
     380      * @throws IllegalArgumentException if {@code colorString} specifies
     381      *      an unsupported color name or contains an illegal numeric value
     382      */
     383     public static Color web(String colorString, double opacity) {
     384         if (colorString == null) {
     385             throw new NullPointerException(
     386                     "The color components or name must be specified");
     387         }
     388         if (colorString.isEmpty()) {
     389             throw new IllegalArgumentException("Invalid color specification");
     390         }
     391
     392         String color = colorString.toLowerCase(Locale.ROOT);
     393
     394         if (color.startsWith("#")) {
     395             color = color.substring(1);
     396         } else if (color.startsWith("0x")) {
     397             color = color.substring(2);
     398         } else if (color.startsWith("rgb")) {
     399             if (color.startsWith("(", 3)) {
     400                 return parseRGBColor(color, 4, false, opacity);
     401             } else if (color.startsWith("a(", 3)) {
     402                 return parseRGBColor(color, 5, true, opacity);
     403             }
     404         } else if (color.startsWith("hsl")) {
     405             if (color.startsWith("(", 3)) {
     406                 return parseHSLColor(color, 4, false, opacity);
     407             } else if (color.startsWith("a(", 3)) {
     408                 return parseHSLColor(color, 5, true, opacity);
     409             }
     410         } else {
     411             Color col = NamedColors.get(color);
     412             if (col != null) {