1 33 34 package edu.rice.cs.drjava.config; 35 import java.awt.*; 36 37 41 public class ColorOption extends Option<Color>{ 42 43 public ColorOption(String key, Color def) { super(key,def); } 44 45 public Color parse(String s) { 46 try { return Color.decode(s); } 47 catch (NumberFormatException nfe) { 48 throw new OptionParseException(name, s, 49 "Must be a string that represents an " + 50 "opaque color as a 24-bit integer."); 51 } 52 } 53 54 public String format(Color c) { 55 int len = 6; String str = Integer.toHexString(c.getRGB() & 0xFFFFFF); 57 final StringBuilder buff = new StringBuilder (str); 58 for (int i = 0; i < (len - str.length()); i++) buff.insert(0, '0'); 59 buff.insert(0, '#'); 60 return buff.toString(); 61 } 62 } 63 | Popular Tags |