Esempio n. 1
0
  public ColorTuple create(List<Value> args) throws TypeCreationException {
    int color;
    try {
      if (args.size() <= 2) {
        color = NamedColor.create(args);
        return toTuple(color);
      }

      String type = "";
      if (args.get(0).isString()) {
        type = ((StencilString) args.get(0)).getString();
      }

      if (HSB.contains(type)) {
        color = IntColor.HSVA(ensureAlpha(trimType(args)));
      } else if (RGB.contains(type)) {
        color = IntColor.RGBA(ensureAlpha(trimType(args)));
      } else {
        color = IntColor.RGBA(ensureAlpha(args));
      }

      return toTuple(color);

    } catch (Exception e) {
      throw new TypeCreationException(args, e);
    }
  }
      /**
       * get a rendered component for this data item
       *
       * @param list the list being edited
       * @param value the value of this item
       * @param index the index of this item
       * @param isSelected whether this item is selected
       * @param cellHasFocus whether this item has focus
       * @return a component to use
       */
      public Component getListCellRendererComponent(
          JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        NamedColor nm = (NamedColor) value;
        if (isCurrentValue(index)) {
          setForeground(Color.red);
        } else {
          setForeground(Color.black);
        }
        if (nm != null) {
          icon.setColor(nm.getColor());
          setIcon(icon);
          setText(nm.name);
        }

        if (isSelected) {
          setBorder(redBorder);
        } else {
          setBorder(emptyBorder);
        }

        return this;
      }