@Override
  protected void updateItem(JList list, Object value) {
    if (value instanceof IcyColorMap) {
      final IcyColorMap colormap = (IcyColorMap) value;
      final JComboBox comboBox = getComboBox();
      final Dimension dim = comboBox.getSize();
      int btnWidth;

      try {
        // a bit ugly but we really want to access it
        final JButton popBtn =
            (JButton) ReflectionUtil.getFieldObject(comboBox.getUI(), "arrowButton", true);

        btnWidth = popBtn.getWidth();
        if (btnWidth <= 0) btnWidth = popBtn.getPreferredSize().width;
        if (btnWidth <= 0) btnWidth = 20;
      } catch (Exception e) {
        btnWidth = 20;
      }

      final Insets insets = getInsets();

      dim.width -= btnWidth + insets.left + insets.right;
      dim.height -= insets.top + insets.bottom + 2;

      setIcon(new ColormapIcon(colormap, dim.width, dim.height));
      setText("");
      setToolTipText("Set " + colormap.getName() + " colormap");
      setEnabled(list.isEnabled());
      setFont(list.getFont());
    } else super.updateItem(list, value);
  }
Ejemplo n.º 2
0
  /**
   * Return true if the colormap has the same type and same color intensities than specified one.
   */
  @Override
  public boolean equals(Object obj) {
    if (obj instanceof IcyColorMap) {
      final IcyColorMap colormap = (IcyColorMap) obj;

      if (colormap.getType() != type) return false;

      if (!Arrays.equals(red.map, colormap.red.map)) return false;
      if (!Arrays.equals(green.map, colormap.green.map)) return false;
      if (!Arrays.equals(blue.map, colormap.blue.map)) return false;
      if (!Arrays.equals(gray.map, colormap.gray.map)) return false;
      if (!Arrays.equals(alpha.map, colormap.alpha.map)) return false;

      return true;
    }

    return super.equals(obj);
  }