private static int hex2rgb(String spec) {
      try {
         if (spec.startsWith("#")) {
            int val = Integer.parseInt(spec.substring(1), 16);
            if (val >= 0 && val < 16)
               return -16 + val;
         } else if (spec.startsWith("%")) {
            int val = Integer.parseInt(spec.substring(1), 8);
            if (val >= 0 && val < 16)
               return -16 + colconv[val];
         } else {
            int rgb = Integer.parseInt(spec, 16);
            switch (spec.length()) {
            case 3:
               return (((rgb & 0xF00) << 8) |
                       ((rgb & 0x0F0) << 4) |
                       ((rgb & 0x00F))) * 0x11;
            case 6:
               return rgb;
            }
         }
      } catch (NumberFormatException e) {}   // Drop through
      return 0x7FFFFFFF;
   }