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

    radioButton.setIcon(null);
    radioButton = null;

    super.uninstallUI(c);
  }
コード例 #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;
          }
        });
  }