Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/flexstor/common/util/ColorUtil.java


1   /*
2    * ColorUtil.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:31 $ FLEXSTOR.net Inc.
5    *
6    * This work is licensed for use and distribution under license terms found at
7    * http://www.flexstor.org/license.html
8    *
9    */
10  
11  package com.flexstor.common.util;
12  
13  import java.awt.Color;
14  import java.util.StringTokenizer;
15  
16  public class ColorUtil
17  {
18     public static String colorToString ( Color c )
19     {
20        if ( c == null )
21           throw new IllegalArgumentException();
22        
23        return c.getRed() + "-" + c.getGreen() + "-" + c.getBlue();
24     }
25     
26     public static Color stringToColor ( String s )
27        throws IllegalArgumentException
28     {
29        int nColorValue = 0;
30        
31        if ( s == null )
32           throw new IllegalArgumentException();
33           
34        StringTokenizer st = new StringTokenizer(s, ",-|/");
35        while (st.hasMoreTokens())
36        {
37           nColorValue <<= 8;
38           nColorValue += Integer.parseInt(st.nextToken());
39        }
40        return new Color( nColorValue );
41     }
42  }