Esempio n. 1
0
  protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    Icon icon = b.getIcon();
    Icon tmpIcon = null;

    if (icon == null) {
      return;
    }

    Icon selectedIcon = null;

    /* the fallback icon should be based on the selected state */
    if (model.isSelected()) {
      selectedIcon = (Icon) b.getSelectedIcon();
      if (selectedIcon != null) {
        icon = selectedIcon;
      }
    }

    if (!model.isEnabled()) {
      if (model.isSelected()) {
        tmpIcon = (Icon) b.getDisabledSelectedIcon();
        if (tmpIcon == null) {
          tmpIcon = selectedIcon;
        }
      }

      if (tmpIcon == null) {
        tmpIcon = (Icon) b.getDisabledIcon();
      }
    } else if (model.isPressed() && model.isArmed()) {
      tmpIcon = (Icon) b.getPressedIcon();
      if (tmpIcon != null) {
        // revert back to 0 offset
        clearTextShiftOffset();
      }
    } else if (b.isRolloverEnabled() && model.isRollover()) {
      if (model.isSelected()) {
        tmpIcon = (Icon) b.getRolloverSelectedIcon();
        if (tmpIcon == null) {
          tmpIcon = selectedIcon;
        }
      }

      if (tmpIcon == null) {
        tmpIcon = (Icon) b.getRolloverIcon();
      }
    }

    if (tmpIcon != null) {
      icon = tmpIcon;
    }

    if (model.isPressed() && model.isArmed()) {
      icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(), iconRect.y + getTextShiftOffset());
    } else {
      icon.paintIcon(c, g, iconRect.x, iconRect.y);
    }
  }
  @Override
  protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    Icon icon = b.getIcon();
    Icon tmpIcon = null;
    Icon shadowIcon = null;
    boolean borderHasPressedCue = borderHasPressedCue(b);

    if (icon == null) {
      return;
    }

    if (!model.isEnabled()) {
      if (model.isSelected()) {
        tmpIcon = (Icon) b.getDisabledSelectedIcon();
      } else {
        tmpIcon = (Icon) b.getDisabledIcon();
      }
    } else if (model.isPressed() && model.isArmed()) {
      tmpIcon = (Icon) b.getPressedIcon();
      if (tmpIcon != null) {
        // revert back to 0 offset
        clearTextShiftOffset();
      } else if (icon != null && icon instanceof ImageIcon && !borderHasPressedCue) {
        // Create an icon on the fly.
        // Note: This is only needed for borderless buttons, which
        //       have no other way to provide feedback about the pressed
        //       state.
        tmpIcon =
            new ImageIcon(HalfbrightFilter.createHalfbrightImage(((ImageIcon) icon).getImage()));
        shadowIcon = new ImageIcon(ShadowFilter.createShadowImage(((ImageIcon) icon).getImage()));
      }
    } else if (b.isRolloverEnabled() && model.isRollover()) {
      if (model.isSelected()) {
        tmpIcon = b.getRolloverSelectedIcon();
        if (tmpIcon == null) {
          tmpIcon = b.getSelectedIcon();
        }
      } else {
        tmpIcon = (Icon) b.getRolloverIcon();
      }
    } else if (model.isSelected()) {
      tmpIcon = b.getSelectedIcon();
    }

    if (tmpIcon != null) {
      icon = tmpIcon;
    }

    if (model.isPressed() && model.isArmed()) {
      if (shadowIcon != null) {
        shadowIcon.paintIcon(
            c, g, iconRect.x + getTextShiftOffset(), iconRect.y + getTextShiftOffset() + 1);
      }
      icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(), iconRect.y + getTextShiftOffset());
    } else {
      icon.paintIcon(c, g, iconRect.x, iconRect.y);
    }
  }
Esempio n. 3
0
  public void paintIcon(Graphics2D g, ButtonInfo info) {
    AbstractButton button = info.button;
    Icon icon = button.getIcon();
    ButtonModel model = button.getModel();

    if (model.isRollover() && button.getRolloverIcon() != null) icon = button.getRolloverIcon();
    if (model.isPressed() && button.getPressedIcon() != null) icon = button.getPressedIcon();
    if (model.isSelected() && button.getSelectedIcon() != null) icon = button.getSelectedIcon();
    if (model.isRollover() && model.isSelected() && button.getRolloverSelectedIcon() != null)
      icon = button.getRolloverSelectedIcon();
    if (isEnabled(button) == false && button.getDisabledIcon() != null)
      icon = button.getDisabledIcon();
    if (isEnabled(button) == false && model.isSelected() && button.getDisabledIcon() != null)
      icon = button.getDisabledSelectedIcon();

    if (icon != null) {
      g.setComposite(isEnabled(button) ? AlphaComposite.SrcOver : SRC_OVER_TRANSLUCENT);
      icon.paintIcon(button, g, info.iconRect.x, info.iconRect.y);
    }
  }
Esempio n. 4
0
 private Icon getRolloverIcon(AbstractButton b, Icon defaultIcon) {
   ButtonModel model = b.getModel();
   Icon icon = null;
   if (model.isSelected()) {
     icon =
         getIcon(
             b,
             b.getRolloverSelectedIcon(),
             null,
             SynthConstants.MOUSE_OVER | SynthConstants.SELECTED);
     if (icon == null) {
       icon = getIcon(b, b.getSelectedIcon(), null, SynthConstants.SELECTED);
     }
   }
   if (icon == null) {
     icon = getIcon(b, b.getRolloverIcon(), defaultIcon, SynthConstants.MOUSE_OVER);
   }
   return icon;
 }