Example #1
0
  @Override
  public void uninstallUI(final JComponent c) {
    radioButton.removeMouseListener(mouseAdapter);
    radioButton.removeItemListener(itemListener);

    radioButton.setIcon(null);
    radioButton = null;

    super.uninstallUI(c);
  }
Example #2
0
  private void updateIcon(final JRadioButton radioButton) {
    radioButton.setIcon(
        new Icon() {
          @Override
          public void paintIcon(final Component c, final Graphics g, final int x, final int y) {
            iconRect = new Rectangle(x, y, iconWidth, iconHeight);

            final Graphics2D g2d = (Graphics2D) g;
            final Object aa = LafUtils.setupAntialias(g2d);

            // Button size and shape
            final int round = iconWidth - shadeWidth * 2 - 2;
            final Rectangle iconRect =
                new Rectangle(
                    x + shadeWidth,
                    y + shadeWidth,
                    iconWidth - shadeWidth * 2 - 1,
                    iconHeight - shadeWidth * 2 - 1);
            final RoundRectangle2D shape =
                new RoundRectangle2D.Double(
                    iconRect.x, iconRect.y, iconRect.width, iconRect.height, round, round);

            // Shade
            if (c.isEnabled()) {
              LafUtils.drawShade(
                  g2d,
                  shape,
                  c.isEnabled() && c.isFocusOwner()
                      ? StyleConstants.fieldFocusColor
                      : StyleConstants.shadeColor,
                  shadeWidth);
            }

            // Background
            final int radius = Math.round((float) Math.sqrt(iconRect.width * iconRect.width / 2));
            g2d.setPaint(
                new RadialGradientPaint(
                    iconRect.x + iconRect.width / 2,
                    iconRect.y + iconRect.height / 2,
                    radius,
                    new float[] {0f, 1f},
                    getBgColors(radioButton)));
            g2d.fill(shape);

            // Border
            final Stroke os = LafUtils.setupStroke(g2d, borderStroke);
            g2d.setPaint(
                c.isEnabled()
                    ? (rolloverDarkBorderOnly
                        ? ColorUtils.getIntermediateColor(
                            borderColor, darkBorderColor, getProgress())
                        : darkBorderColor)
                    : disabledBorderColor);
            g2d.draw(shape);
            LafUtils.restoreStroke(g2d, os);

            // Check icon
            if (checkIcon > 0) {
              final ImageIcon icon =
                  radioButton.isEnabled() ? CHECK_STATES.get(checkIcon) : DISABLED_CHECK;
              g2d.drawImage(
                  icon.getImage(),
                  x + iconWidth / 2 - icon.getIconWidth() / 2,
                  y + iconHeight / 2 - icon.getIconHeight() / 2,
                  radioButton);
            }

            LafUtils.restoreAntialias(g2d, aa);
          }

          @Override
          public int getIconWidth() {
            return iconWidth;
          }

          @Override
          public int getIconHeight() {
            return iconHeight;
          }
        });
  }
Example #3
0
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      JComponent renderer = null;

      if (value instanceof Icon) {
        Icon icon = (Icon) value;
        // Hack to fix problem where some plaf Icons cast the component to
        // various component classes. yikes!  not very re-usable icons :(
        String className = (String) table.getValueAt(row, UIDefaultsTableModel.TYPE_COLUMN);
        if (className.contains("BasicIconFactory$RadioButtonMenuItemIcon")
            || className.contains("BasicIconFactory$CheckBoxMenuItemIcon")
            || className.contains("OceanTheme$IFIcon")
            || className.contains("MotifIconFactory$RadioButtonIcon")
            || className.contains("MotifIconFactory$CheckBoxIcon")
            || className.contains("MotifIconFactory$MenuArrowIcon")
            || className.contains("WindowsIconFactory$FrameButtonIcon")
            || className.contains("WindowsIconFactory$RadioButtonIcon")) {
          buttonIconRenderer.setIcon(icon);
          buttonIconRenderer.setSelected(true);
          renderer = buttonIconRenderer;

        } else if (className.contains("MetalIconFactory$RadioButtonIcon")) {
          radioIconRenderer.setIcon(icon);
          renderer = radioIconRenderer;

        } else if (className.contains("MetalIconFactory$RadioButtonMenuItemIcon")
            || className.contains("MetalIconFactory$CheckBoxMenuItemIcon")
            || className.contains("MetalIconFactory$MenuArrowIcon")
            || className.contains("MetalIconFactory$MenuItemArrowIcon")) {
          menuItemIconRenderer.setIcon(icon);
          menuItemIconRenderer.setSelected(true);
          renderer = menuItemIconRenderer;

        } else if (className.contains("MetalIconFactory$CheckBoxIcon")
            || className.contains("WindowsIconFactory$CheckBoxIcon")) {
          checkboxIconRenderer.setIcon(icon);
          checkboxIconRenderer.setSelected(true);
          renderer = checkboxIconRenderer;
        }
      }

      if (renderer != null) {
        // special hack renderer for icons needs to be colorized because
        // it doesn't extend RowRenderer
        setColors(table, row, isSelected);
        setBorder(renderer, hasFocus, isSelected);

      } else {
        // renderer == this
        renderer =
            (JComponent)
                super.getTableCellRendererComponent(
                    table, value, isSelected, hasFocus, row, column);
        if (value instanceof Color) {
          Color color = (Color) value;
          float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);

          setIcon(ColorIcon.getIcon(color));
          setText(
              "RGB="
                  + color.getRed()
                  + ","
                  + color.getGreen()
                  + ","
                  + color.getBlue()
                  + "  "
                  + "HSB="
                  + String.format("%.0f%n", hsb[0] * 360)
                  + ","
                  + String.format("%.3f%n", hsb[1])
                  + ","
                  + String.format("%.3f%n", hsb[2]));

        } else if (value instanceof Font) {
          Font font = (Font) value;
          setFont(font);
          setText(font.getFontName() + " size=" + font.getSize2D());
          setIcon(null);

        } else if (value instanceof Icon) {
          setIcon((Icon) value);
          setText("");
        }
      }
      return renderer;
    }
 public void decorateLargeRadioButton(JRadioButton box) {
   box.setIcon(largeRadio);
   box.setSelectedIcon(largeRadioChecked);
   box.setOpaque(false);
   box.setFocusPainted(false);
 }