Java Color from String string2Color(String stringColor)

Here you can find the source of string2Color(String stringColor)

Description

Obtiene el color de un string generado con color2String

License

Open Source License

Parameter

Parameter Description
stringColor string

Return

Color

Declaration

public static Color string2Color(String stringColor) 

Method Source Code


//package com.java2s;
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
 *
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
 *
 * This program 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 2
 * of the License, or (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
 *
 * For more information, contact://from  w  w  w.  java 2 s  . co  m
 *
 *  Generalitat Valenciana
 *   Conselleria d'Infraestructures i Transport
 *   Av. Blasco Ib??ez, 50
 *   46010 VALENCIA
 *   SPAIN
 *
 *      +34 963862235
 *   gvsig@gva.es
 *      www.gvsig.gva.es
 *
 *    or
 *
 *   IVER T.I. S.A
 *   Salamanca 50
 *   46005 Valencia
 *   Spain
 *
 *   +34 963163400
 *   dac@iver.es
 */

import java.awt.Color;

public class Main {
    /**
     * Obtiene el color de un string generado con color2String 
     *
     * @param stringColor string 
     *
     * @return Color
     */
    public static Color string2Color(String stringColor) {
        if (stringColor == null || stringColor.equals("null"))
            return null;
        String[] ints = new String[4];
        ints = stringColor.split(",");

        int[] ret = new int[4];

        for (int i = 0; i < ret.length; i++) {
            ret[i] = new Integer(ints[i]).intValue();
        }

        return new Color(ret[0], ret[1], ret[2], ret[3]);

        /*
           long color = new Long(stringColor).longValue();
           long alpha = color / 16777216;
           color = color % 16777216;
            
           long red = color / 65536;
           color = color % 65536;
           long green = color / 256;
           color = color % 256;
           long blue = color;
           return new Color(red, green, blue, alpha);*/
    }
}

Related

  1. str2Color(String s, Color defaultValue)
  2. string2color(String str)
  3. stringToColor(final String s)
  4. stringToColor(final String value)
  5. stringToColor(String color)
  6. stringToColor(String color)