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

The following examples show how to use javax.swing.AbstractButton#getMargin() . 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: ButtonUI.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
public Dimension getPreferredSize(JComponent c) {
	AbstractButton b = (AbstractButton) c;
	Dimension d = BasicGraphicsUtils.getPreferredButtonSize(b, b.getIconTextGap());
	Insets margin = b.getMargin();
	d.setSize(d.getWidth() + margin.left + margin.right, d.getHeight() + margin.top + margin.bottom);
	return d;
}
 
Example 3
Source File: NavlinkUI.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
public Dimension getPreferredSize(JComponent c) {
	AbstractButton b = (AbstractButton) c;
	Dimension d = BasicGraphicsUtils.getPreferredButtonSize(b, b.getIconTextGap());
	Insets margin = b.getMargin();
	d.setSize(d.getWidth() + margin.left + margin.right, d.getHeight() + margin.top + margin.bottom);
	return d;
}
 
Example 4
Source File: QButtonUI.java    From pumpernickel with MIT License 4 votes vote down vote up
@Override
public Insets getBorderInsets(Component c) {
	JComponent jc = (JComponent) c;
	AbstractButton button = (jc instanceof AbstractButton) ? (AbstractButton) jc
			: null;
	Insets i = new Insets(0, 0, 0, 0);

	boolean isFocusPainted = button == null || button.isFocusPainted();
	if (paintFocus == PaintFocus.OUTSIDE && isFocusPainted) {
		i.top += focusRingSize;
		i.left += focusRingSize;
		i.bottom += focusRingSize;
		i.right += focusRingSize;
	}

	if (buttonFill.getShadowHighlight(new ButtonState.Float(0, 0, 0, 0,
			0)) != null) {
		i.bottom = Math.max(1, i.bottom);
	}

	// 1 pixel for the stroke itself
	i.top++;
	i.left++;
	i.bottom++;
	i.right++;

	int interior = cornerRadius;
	if (paintFocus == PaintFocus.INSIDE && isFocusPainted)
		interior = Math.max(interior, focusRingSize);
	interior = Math.max(interior, 3);

	int interiorSegment = Math.max(interior - 4, 2);

	HorizontalPosition horizontalPosition = getHorizontalPosition(jc);
	switch (horizontalPosition) {
	case ONLY:
		i.left += interior;
		i.right += interior;
		break;
	case LEFT:
		i.left += interior;
		i.right += interiorSegment;
		break;
	case MIDDLE:
		i.left += interiorSegment;
		i.right += interiorSegment;
		break;
	case RIGHT:
		i.left += interiorSegment;
		i.right += interior;
	}

	VerticalPosition verticalPosition = getVerticalPosition(jc);
	switch (verticalPosition) {
	case ONLY:
		i.top += interior;
		i.bottom += interior;
		break;
	case TOP:
		i.top += interior;
		i.bottom += interiorSegment;
		break;
	case MIDDLE:
		i.top += interiorSegment;
		i.bottom += interiorSegment;
		break;
	case BOTTOM:
		i.top += interiorSegment;
		i.bottom += interior;
	}

	// TODO: maybe rethink how we suport margins? Instead of setting it once
	// in installUI, we could update it with the "interior" calculations above
	Insets margin = button == null ? null : button.getMargin();
	if (margin != null) {
		i.top += margin.top;
		i.left += margin.left;
		i.bottom += margin.bottom;
		i.right += margin.right;
	}

	return i;
}
 
Example 5
Source File: SeaGlassButtonUI.java    From seaglass with Apache License 2.0 4 votes vote down vote up
/**
 * Update the style of the button.
 *
 * @param b the button.
 */
public void updateStyle(AbstractButton b) {
    SeaGlassContext context  = getContext(b, SynthConstants.ENABLED);
    SynthStyle      oldStyle = style;

    style = SeaGlassLookAndFeel.updateStyle(context, this);
    if (style != oldStyle) {
        if (b.getMargin() == null || (b.getMargin() instanceof UIResource)) {
            Insets margin = (Insets) style.get(context, getPropertyPrefix() + "margin");

            if (margin == null) {
                // Some places assume margins are non-null.
                margin = SeaGlassLookAndFeel.EMPTY_UIRESOURCE_INSETS;
            }

            b.setMargin(margin);
        }

        Object value = style.get(context, getPropertyPrefix() + "iconTextGap");

        if (value != null) {
            LookAndFeel.installProperty(b, "iconTextGap", value);
        }

        value = style.get(context, getPropertyPrefix() + "contentAreaFilled");
        LookAndFeel.installProperty(b, "contentAreaFilled", value != null ? value : Boolean.TRUE);

        value = b.getClientProperty(APPLE_PREFIX + "buttonType");
        if (value != null) {
            if ("segmented".equals(value)) {
                b.setMargin(SeaGlassLookAndFeel.EMPTY_UIRESOURCE_INSETS);
            }
        }

        if (oldStyle != null) {
            uninstallKeyboardActions(b);
            installKeyboardActions(b);
        }
    }

    context.dispose();
}