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

The following examples show how to use javax.swing.AbstractButton#getSize() . 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: SlidingButtonUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void paintBackground(Graphics2D g, AbstractButton b) {
    Dimension size = b.getSize();
    
    Insets insets = b.getInsets();
    Insets margin = b.getMargin();
    if( null == insets || null == margin )
        return;
    g.fillRect(insets.left - margin.left,
        insets.top - margin.top,
    size.width - (insets.left-margin.left) - (insets.right - margin.right),
    size.height - (insets.top-margin.top) - (insets.bottom - margin.bottom));
}
 
Example 2
Source File: FreeColButtonUI.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void paintButtonPressed(Graphics g, AbstractButton c) {
    if (c.isContentAreaFilled()) {
        Graphics2D g2d = (Graphics2D) g;
        Dimension size = c.getSize();
        Composite oldComposite = g2d.getComposite();
        Color oldColor = g2d.getColor();
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
        g2d.setColor(Color.BLACK);
        g2d.fillRect(0, 0, size.width, size.height);
        g2d.setComposite(oldComposite);
        g2d.setColor(oldColor);

    }
}
 
Example 3
Source File: ButtonUI.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect,
		Rectangle iconRect) {
	super.paintFocus(g, b, viewRect, textRect, iconRect);
	if (b instanceof RPButton) {
		RPButton link = (RPButton) b;
		if (link.getBtnGroup() != null && link.isLeftNode()) {
			float width = link.getWidth();
			float height = link.getHeight();
			int arc = link.getBtnGroup().getArc();
			Graphics2D g2 = (Graphics2D) g.create();
			g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
			g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
			RoundRectangle2D rect = new RoundRectangle2D.Float(iconRect.x + getTextShiftOffset(),
					iconRect.y + getTextShiftOffset(), width, height, link.getBtnGroup().getArc(), arc);
			g2.setColor(getFocusColor());
			g2.fill(rect);
			Rectangle2D rectFix = new Rectangle((int) width - arc, 0, (int) arc, (int) height);
			g2.fill(rectFix);
			g2.dispose();
		} else {
			Dimension size = b.getSize();
			g.setColor(getFocusColor());
			g.fillRect(0, 0, size.width, size.height);

		}
	}
}
 
Example 4
Source File: ButtonUI.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
protected void paintButtonBackground(Graphics g, AbstractButton b) {
	if (b.isContentAreaFilled()) {
		if (b instanceof RPButton) {
			RPButton link = (RPButton) b;
			if (link.getBtnGroup() != null && link.isLeftNode()) {
				float width = link.getWidth();
				float height = link.getHeight();
				int arc = link.getBtnGroup().getArc();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);

				RoundRectangle2D rect = new RoundRectangle2D.Float(0, 0, width, height, link.getBtnGroup().getArc(),
						arc);
				g2.setColor(b.getBackground());
				g2.fill(rect);

				Rectangle2D rectFix = new Rectangle((int) width - arc, 0, (int) arc, (int) height);
				g2.fill(rectFix);

				g2.dispose();
			} else {
				Dimension size = b.getSize();
				g.setColor(b.getBackground());
				g.fillRect(0, 0, size.width, size.height);
			}
		}
	}
}
 
Example 5
Source File: ButtonUI.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
protected void paintButtonPressed(Graphics g, AbstractButton b) {
	if (b.isContentAreaFilled()) {
		if (b instanceof RPButton) {
			RPButton link = (RPButton) b;
			if (link.getBtnGroup() != null && link.isLeftNode()) {
				float width = link.getWidth();
				float height = link.getHeight();
				int arc = link.getBtnGroup().getArc();

				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);

				RoundRectangle2D rect = new RoundRectangle2D.Float(0, 0, width, height, link.getBtnGroup().getArc(),
						arc);
				g2.setColor(getSelectColor());
				g2.fill(rect);

				Rectangle2D rectFix = new Rectangle((int) width - arc, 0, (int) arc, (int) height);
				g2.fill(rectFix);

				g2.dispose();
			} else {
				Dimension size = b.getSize();
				g.setColor(getSelectColor());
				g.fillRect(0, 0, size.width, size.height);
			}
		}
	}
}
 
Example 6
Source File: NavlinkUI.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
protected void paintButtonPressed(Graphics g, AbstractButton b) {
	if (b.isContentAreaFilled()) {
		if (b instanceof RPNavlink) {
			RPNavlink link = (RPNavlink) b;
			if (link.isLeftNode()) {
				float width = link.getWidth();
				float height = link.getHeight();
				int arc = link.getNavbar().getArc();

				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);

				RoundRectangle2D rect = new RoundRectangle2D.Float(0, 0, width, height, link.getNavbar().getArc(),
						arc);
				g2.setColor(getSelectColor());
				g2.fill(rect);

				Rectangle2D rectFix = new Rectangle((int) width - arc, 0, (int) arc, (int) height);
				g2.fill(rectFix);

				g2.dispose();
			} else {
				Dimension size = b.getSize();
				g.setColor(getSelectColor());
				g.fillRect(0, 0, size.width, size.height);
			}
		}
	}
}
 
Example 7
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));
		}
	}
}