1 /*--------------------------------------------------------------------------
2 * Copyright 2010 utgenome.org
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *--------------------------------------------------------------------------*/
16 //--------------------------------------
17 // utgb-core Project
18 //
19 // ColorUtil.java
20 // Since: 2010/10/08
21 //
22 //--------------------------------------
23 package org.utgenome.gwt.utgb.client.canvas;
24
25 import com.google.gwt.widgetideas.graphics.client.Color;
26
27 /**
28 * Color code generator
29 *
30 * @author leo
31 *
32 */
33 public class ColorUtil {
34
35 public static Color toColor(String hex) {
36 if (hex.startsWith("#"))
37 hex = hex.substring(1);
38
39 int r = Integer.parseInt(hex.substring(0, 2), 16);
40 int g = Integer.parseInt(hex.substring(2, 4), 16);
41 int b = Integer.parseInt(hex.substring(4, 6), 16);
42 Color c = new Color(r, g, b);
43 return c;
44 }
45
46 public static Color toColor(String hex, float alpha) {
47 if (hex.startsWith("#"))
48 hex = hex.substring(1);
49
50 int r = Integer.parseInt(hex.substring(0, 2), 16);
51 int g = Integer.parseInt(hex.substring(2, 4), 16);
52 int b = Integer.parseInt(hex.substring(4, 6), 16);
53 return new Color(r, g, b, alpha);
54 }
55
56 }