Java Code Examples for javax.swing.AbstractButton#getIcon()

The following examples show how to use javax.swing.AbstractButton#getIcon() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LuckButtonUI.java    From littleluck with Apache License 2.0 6 votes vote down vote up
public void paint(Graphics g, JComponent c)
{
    AbstractButton b = (AbstractButton) c;

    ButtonModel model = b.getModel();

    paintBg(g, (AbstractButton) c);

    // 设置组件偏移,以达到视觉上的按下和弹起效果
    // Set the component offsets to achieve visual depress and bounce
    if(model.isPressed() && model.isArmed() && b.getIcon() == null)
    {
        g.translate(2, 1);
    }

    super.paint(g, c);

    if(model.isPressed() && model.isArmed() && b.getIcon() == null)
    {
        g.translate(-2, -1);
    }
}
 
Example 2
Source File: LuckButtonUI.java    From littleluck with Apache License 2.0 6 votes vote down vote up
/**
 * check if use the default button style.
 *
 * @param b
 * @return default style return true, otherwise return false.
 */
private boolean checkIsPaintBg(AbstractButton b)
{
    if (!b.isContentAreaFilled())
    {
        return false;
    }
    
    Object isPaintBg = b.getClientProperty(LuckButtonUIBundle.IS_PAINTBG);

    if (b.getIcon() != null && isPaintBg == null)
    {
        return false;
    }

    return true;
}
 
Example 3
Source File: SeaGlassButtonUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the Icon to use in painting the button.
 *
 * @param  b the button.
 *
 * @return the icon.
 */
protected Icon getIcon(AbstractButton b) {
    Icon        icon  = b.getIcon();
    ButtonModel model = b.getModel();

    if (!model.isEnabled()) {
        icon = getSynthDisabledIcon(b, icon);
    } else if (model.isPressed() && model.isArmed()) {
        icon = getPressedIcon(b, getSelectedIcon(b, icon));
    } else if (b.isRolloverEnabled() && model.isRollover()) {
        icon = getRolloverIcon(b, getSelectedIcon(b, icon));
    } else if (model.isSelected()) {
        icon = getSelectedIcon(b, icon);
    } else {
        icon = getEnabledIcon(b, icon);
    }

    if (icon == null) {
        return getDefaultIcon(b);
    }

    return icon;
}
 
Example 4
Source File: LayoutStyle.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
private Icon getIcon(AbstractButton button) {
	Icon icon = button.getIcon();
	if (icon != null) {
		return icon;
	}
	String key = null;
	if (button instanceof JCheckBox) {
		key = "CheckBox.icon";
	} else if (button instanceof JRadioButton) {
		key = "RadioButton.icon";
	}
	if (key != null) {
		Object oIcon = UIManager.get(key);
		if (oIcon instanceof Icon) {
			return (Icon) oIcon;
		}
	}
	return null;
}
 
Example 5
Source File: ActionsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that "unknownIcon" is used if no iconBase
 */
public void testToggleButtonUnknownIcon() throws Exception {
    AbstractButton b = new AlwaysEnabledAction.DefaultIconToggleButton();
    Action action = new TestAction();
    action.putValue("iconBase", null);
    Actions.connect(b, action);
    Icon icon = b.getIcon();
    assertNotNull("null ToggleButton icon", icon);
    Icon expectedIcon = ImageUtilities.loadImageIcon("org/openide/awt/resources/unknown.gif", false); //NOI18N
    assertEquals("unkownIcon not used", expectedIcon, icon);
}
 
Example 6
Source File: CustomToolbar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void addButton(AbstractButton button) {
    Icon icon = button.getIcon();
    Dimension size = new Dimension(icon.getIconWidth() + 6, icon.getIconHeight() + 10);
    button.setMinimumSize(size);
    button.setPreferredSize(size);
    button.setMaximumSize(size);
    button.setMargin(new Insets(5, 4, 5, 4));
    toolbar.add(button);
}
 
Example 7
Source File: CustomToolbar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void addButton(AbstractButton button) {
    Icon icon = button.getIcon();
    Dimension size = new Dimension(icon.getIconWidth() + 6, icon.getIconHeight() + 10);
    button.setPreferredSize(size);
    button.setMargin(new Insets(5, 4, 5, 4));
    toolbar.add(button);
}
 
Example 8
Source File: RapidDockingToolbar.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void installButtonUI(AbstractButton button) {
	button.setUI(new ButtonUI());
	button.setBorder(null);
	button.setMargin(new Insets(0, 0, 0, 0));
	if ((button.getText() == null || "".equals(button.getText())) && button.getIcon() != null) {
		button.setPreferredSize(new Dimension((int) (button.getIcon().getIconWidth() * 1.45d), (int) (button.getIcon()
				.getIconHeight() * 1.45d)));
	}
}
 
Example 9
Source File: SeaGlassButtonUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the Icon used in calculating the pref/min/max size.
 *
 * @param  b DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
protected Icon getSizingIcon(AbstractButton b) {
    // NOTE: this is slightly different than BasicButtonUI, where it
    // would just use getIcon, but this should be ok.
    Icon icon = (b.isEnabled() || b.getDisabledIcon() == null) ? b.getIcon() : b.getDisabledIcon();

    if (icon == null) {
        icon = getDefaultIcon(b);
    }

    return icon;
}
 
Example 10
Source File: NavlinkUI.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
public void paint(Graphics g, JComponent c) {
	AbstractButton b = (AbstractButton) c;
	ButtonModel model = b.getModel();

	String text = layout(b, g.getFontMetrics(), b.getWidth(), b.getHeight());

	clearTextShiftOffset();

	if (model.isArmed() && model.isPressed()) {
		paintButtonPressed(g, b);
	} else if (b.isRolloverEnabled() && model.isRollover()) {
		paintButtonPressed(g, b);
	}

	if (b.getIcon() != null) {
		paintIcon(g, c, iconRect);
	}

	if (b.isFocusPainted() && b.isFocusOwner()) {
		paintFocus(g, b, viewRect, textRect, iconRect);
		if (iconRect != null && iconRect.width > 0 && iconRect.height > 0) {
			if (b.getIcon() != null) {
				paintIcon(g, c, iconRect);
			}
		}
	}

	if (text != null && !text.equals("")) {
		Graphics2D g2 = (Graphics2D) g.create();
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);

		View v = (View) c.getClientProperty(BasicHTML.propertyKey);
		if (v != null) {
			v.paint(g2, textRect);
		} else {
			paintText(g2, b, textRect, text);
		}
	}
}
 
Example 11
Source File: ToolButtonFactory.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static void configure(AbstractButton button) {

        RolloverButtonEventListener l = new RolloverButtonEventListener();
        button.addMouseListener(l);
        button.addItemListener(l);

        if (button.getAction() != null) {
            if (button.getIcon() != null) {
                button.putClientProperty("hideActionText", Boolean.TRUE);
            }
            Object largeIcon = button.getAction().getValue("_largeIcon");
            if (largeIcon instanceof Icon) {
                button.setIcon((Icon) largeIcon);
            }
        }

        Icon icon = button.getIcon();
        int minWidth = BUTTON_MIN_SIZE;
        int minHeight = BUTTON_MIN_SIZE;
        if (icon != null) {
            button.setText(null);
            minWidth = Math.max(icon.getIconWidth(), BUTTON_MIN_SIZE);
            minHeight = Math.max(icon.getIconHeight(), BUTTON_MIN_SIZE);
            if (icon instanceof ImageIcon) {
                button.setRolloverIcon(createRolloverIcon((ImageIcon) icon));
            }
        } else {
            button.setText("[?]");
        }
        final int space = 3;
        Dimension prefSize = new Dimension(minWidth + space, minHeight + space);
        Dimension minSize = new Dimension(minWidth, minHeight);
        Dimension maxSize = new Dimension(minWidth + space, minHeight + space);
        button.setPreferredSize(prefSize);
        button.setMaximumSize(maxSize);
        button.setMinimumSize(minSize);

    }
 
Example 12
Source File: FlatRadioButtonUI.java    From FlatLaf with Apache License 2.0 4 votes vote down vote up
private int getIconFocusWidth( JComponent c ) {
	AbstractButton b = (AbstractButton) c;
	return (b.getIcon() == null && getDefaultIcon() instanceof FlatCheckBoxIcon)
		? UIScale.scale( ((FlatCheckBoxIcon)getDefaultIcon()).focusWidth )
		: 0;
}
 
Example 13
Source File: BasicLinkButtonUI.java    From orbit-image-analysis with GNU General Public License v3.0 4 votes vote down vote up
public void paint(Graphics g, JComponent c) {
  AbstractButton b = (AbstractButton)c;
  ButtonModel model = b.getModel();

  FontMetrics fm = g.getFontMetrics();

  Insets i = c.getInsets();

  viewRect.x = i.left;
  viewRect.y = i.top;
  viewRect.width = b.getWidth() - (i.right + viewRect.x);
  viewRect.height = b.getHeight() - (i.bottom + viewRect.y);

  textRect.x = textRect.y = textRect.width = textRect.height = 0;
  iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;

  Font f = c.getFont();
  g.setFont(f);

  // layout the text and icon
  String text =
    SwingUtilities.layoutCompoundLabel(
      c,
      fm,
      b.getText(),
      b.getIcon(),
      b.getVerticalAlignment(),
      b.getHorizontalAlignment(),
      b.getVerticalTextPosition(),
      b.getHorizontalTextPosition(),
      viewRect,
      iconRect,
      textRect,
      b.getText() == null ? 0 : b.getIconTextGap());

  clearTextShiftOffset();

  // perform UI specific press action, e.g. Windows L&F shifts text
  if (model.isArmed() && model.isPressed()) {
    paintButtonPressed(g, b);
  }

  // Paint the Icon
  if (b.getIcon() != null) {
    paintIcon(g, c, iconRect);
  }

  Composite oldComposite = ((Graphics2D)g).getComposite();

  if (model.isRollover()) {
    ((Graphics2D)g).setComposite(
      AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
  }

  if (text != null && !text.equals("")) {
    View v = (View)c.getClientProperty(BasicHTML.propertyKey);
    if (v != null) {
      textRect.x += getTextShiftOffset();
      textRect.y += getTextShiftOffset();
      v.paint(g, textRect);
      textRect.x -= getTextShiftOffset();
      textRect.y -= getTextShiftOffset();
    } else {
      paintText(g, b, textRect, text);
    }
  }

  if (b.isFocusPainted() && b.hasFocus()) {
    // paint UI specific focus
    paintFocus(g, b, viewRect, textRect, iconRect);
  }

  ((Graphics2D)g).setComposite(oldComposite);
}
 
Example 14
Source File: ToggleButtonUI.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void paint(Graphics g, JComponent c) {
	AbstractButton b = (AbstractButton) c;

	Dimension size = b.getSize();
	FontMetrics fm = g.getFontMetrics();

	Insets i = c.getInsets();

	Rectangle viewRect = new Rectangle(size);

	viewRect.x += i.left;
	viewRect.y += i.top;
	viewRect.width -= i.right + viewRect.x;
	viewRect.height -= i.bottom + viewRect.y;

	Rectangle iconRect = new Rectangle();
	Rectangle textRect = new Rectangle();

	Font f = c.getFont();
	g.setFont(f);

	String text = SwingUtilities.layoutCompoundLabel(c, fm, b.getText(), b.getIcon(), b.getVerticalAlignment(),
			b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect,
			textRect, b.getText() == null ? 0 : b.getIconTextGap());

	g.setColor(b.getBackground());

	if (b.isContentAreaFilled()) {
		if (RapidLookTools.isToolbarButton(b)) {
			RapidLookTools.drawToolbarButton(g, b);
		} else {
			RapidLookTools.drawButton(b, g, RapidLookTools.createShapeForButton(b));
		}
	}

	if (b.getIcon() != null) {
		paintIcon(g, b, iconRect);
	}

	if (text != null && !text.equals("")) {
		View v = (View) c.getClientProperty(BasicHTML.propertyKey);
		if (v != null) {
			v.paint(g, textRect);
		} else {
			paintText(g, b, textRect, text);
		}
	}

	if (b.isFocusPainted() && b.hasFocus()) {
		paintFocus(g, b, viewRect, textRect, iconRect);
	}

	if (!RapidLookTools.isToolbarButton(b)) {
		if (b.isBorderPainted()) {
			RapidLookTools.drawButtonBorder(b, g, RapidLookTools.createBorderShapeForButton(b));
		}
	}
}
 
Example 15
Source File: ButtonUI.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
public void paint(Graphics g, JComponent c) {
	AbstractButton b = (AbstractButton) c;
	ButtonModel model = b.getModel();

	String text = layout(b, g.getFontMetrics(), b.getWidth(), b.getHeight());

	clearTextShiftOffset();

	if (!model.isArmed() && !model.isPressed()) {
		paintButtonBackground(g, b);
	}

	if (model.isArmed() && model.isPressed()) {
		paintButtonPressed(g, b);
	} else if (b.isRolloverEnabled() && model.isRollover()) {
		paintButtonPressed(g, b);
	}

	if (b.getIcon() != null) {
		paintIcon(g, c, iconRect);
	}

	if (b.isFocusPainted() && b.isFocusOwner()) {
		paintFocus(g, b, viewRect, textRect, iconRect);
		if (iconRect != null && iconRect.width > 0 && iconRect.height > 0) {
			if (b.getIcon() != null) {
				paintIcon(g, c, iconRect);
			}
		}
	}

	if (text != null && !text.equals("")) {
		Graphics2D g2 = (Graphics2D) g.create();
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);

		View v = (View) c.getClientProperty(BasicHTML.propertyKey);
		if (v != null) {
			v.paint(g2, textRect);
		} else {
			paintText(g2, b, textRect, text);
		}
	}

}