Here you can find the source of str2Color(String s, Color defaultValue)
Parameter | Description |
---|---|
s | A given String to examine. |
defaultValue | A default Color to return in case we fail. |
public static Color str2Color(String s, Color defaultValue)
//package com.java2s; /*/*from w w w . j a v a 2 s . co m*/ This file is part of JFLICKS. JFLICKS is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. JFLICKS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with JFLICKS. If not, see <http://www.gnu.org/licenses/>. */ import java.awt.Color; public class Main { /** * We have this method to convert the "standard" Color constants as a * String to their Color value. * * @param s A given String to examine. * @param defaultValue A default Color to return in case we fail. * @return A Color instance. */ public static Color str2Color(String s, Color defaultValue) { Color result = defaultValue; if (s != null) { if (s.equalsIgnoreCase("BLACK")) { result = Color.BLACK; } else if (s.equalsIgnoreCase("BLUE")) { result = Color.BLUE; } else if (s.equalsIgnoreCase("CYAN")) { result = Color.CYAN; } else if (s.equalsIgnoreCase("DARK_GRAY")) { result = Color.DARK_GRAY; } else if (s.equalsIgnoreCase("GRAY")) { result = Color.GRAY; } else if (s.equalsIgnoreCase("GREEN")) { result = Color.GREEN; } else if (s.equalsIgnoreCase("LIGHT_GRAY")) { result = Color.LIGHT_GRAY; } else if (s.equalsIgnoreCase("MAGENTA")) { result = Color.MAGENTA; } else if (s.equalsIgnoreCase("ORANGE")) { result = Color.ORANGE; } else if (s.equalsIgnoreCase("PINK")) { result = Color.PINK; } else if (s.equalsIgnoreCase("RED")) { result = Color.RED; } else if (s.equalsIgnoreCase("WHITE")) { result = Color.WHITE; } else if (s.equalsIgnoreCase("YELLOW")) { result = Color.YELLOW; } } return (result); } }