Esempio n. 1
0
  public static Color getColor(String name, Color def) {
    if (name == null) {
      // System.out.println("illegal color: " + name);
      // Thread.dumpStack();
      return (def);
    }
    name = name.toLowerCase();
    Color nc = (Color) colors.get(name);
    if (nc == null) {
      StringTokenizer st = new StringTokenizer(name, ", ");
      // System.out.println(st.countTokens();

      if ((st.countTokens() < 3) || (st.countTokens() > 4)) {
        // System.out.println("illegal color");
        nc = def;
      } else {
        try {
          int r = Integer.parseInt(st.nextToken());
          int g = Integer.parseInt(st.nextToken());
          int b = Integer.parseInt(st.nextToken());
          if (st.countTokens() == 0) {
            nc = new GuessColor(r, g, b);
          } else {
            int a = Integer.parseInt(st.nextToken());
            nc = new GuessColor(r, g, b, a);
          }
          colors.put(name, nc);
        } catch (Exception e) {
          ExceptionWindow.getExceptionWindow(e);
          StatusBar.setErrorStatus("Invalid color, using default");
          nc = def;
        }
      }
    }
    return (nc);
  }