1 16 17 package org.apache.cocoon.components.elementprocessor.impl.poi.hssf.elements; 18 19 import java.io.IOException ; 20 21 import java.util.StringTokenizer ; 22 23 30 public class ColorCode { 31 private static final int _red = 0; 32 private static final int _green = 1; 33 private static final int _blue = 2; 34 private static final int _component_count = 3; 35 private int[] _components = new int[ _component_count ]; 36 private String rgbstring = null; 37 38 45 46 public ColorCode(final String value) throws IOException { 47 rgbstring = value; 48 if (value == null) { 49 throw new IOException ("cannot process a null color code"); 50 } 51 StringTokenizer tokenizer = new StringTokenizer (value.trim(), ":"); 52 53 if (tokenizer.countTokens() != _component_count) { 54 throw new IOException ("color code must have exactly " 55 + _component_count + " components, no more, no less"); 56 } 57 for (int j = 0; j < _component_count; j++) { 58 try { 59 _components[j] = Integer.parseInt(tokenizer.nextToken(), 16); 60 } catch (Exception e) { 61 throw new IOException ("cannot parse component #" + j + " (" 62 + e.getMessage() + ")"); 63 } 64 if (_components[j] < 0 || _components[j] > 65535) { 65 throw new IOException ("Component #" + j + " is out of range"); 66 } 67 } 68 } 69 70 73 74 public int getRed() { 75 return _components[_red]; 76 } 77 78 81 82 public int getGreen() { 83 return _components[_green]; 84 } 85 86 89 90 public int getBlue() { 91 return _components[_blue]; 92 } 93 94 public String toString() { 95 return rgbstring; 96 } 97 } | Popular Tags |