Java JButton Settings getRadioButtonBorder(int fontSize, boolean ltr)

Here you can find the source of getRadioButtonBorder(int fontSize, boolean ltr)

Description

Returns the border for radio buttons under the specified font size.

License

Open Source License

Parameter

Parameter Description
fontSize Font size.

Return

Border for radio buttons under the specified font size.

Declaration

public static Border getRadioButtonBorder(int fontSize, boolean ltr) 

Method Source Code

//package com.java2s;
import java.awt.*;
import javax.swing.border.Border;
import javax.swing.plaf.BorderUIResource;

public class Main {
    /**//from   w  w  w .ja  v  a  2  s. com
     * Returns the border for radio buttons under the specified font size.
     * 
     * @param fontSize
     *            Font size.
     * @return Border for radio buttons under the specified font size.
     */
    public static Border getRadioButtonBorder(int fontSize, boolean ltr) {
        Border checkBoxBorder = getCheckBoxBorder(fontSize, ltr);
        Insets checkBoxInsets = checkBoxBorder.getBorderInsets(null);
        return new BorderUIResource.EmptyBorderUIResource(
                checkBoxInsets.top, checkBoxInsets.left - (ltr ? 0 : 2),
                checkBoxInsets.bottom, checkBoxInsets.right - (ltr ? 2 : 0));
    }

    /**
     * Returns the border for check boxes under the specified font size.
     * 
     * @param fontSize
     *            Font size.
     * @return Border for check boxes under the specified font size.
     */
    public static Border getCheckBoxBorder(int fontSize, boolean ltr) {
        // The base insets are 2,3,3,5. We add one pixel for
        // each 3 extra points in base control size.
        int tInset = getAdjustedSize(fontSize, 2, 3, 1, false);
        int bInset = getAdjustedSize(fontSize, 3, 3, 1, false);
        if (fontSize == 11) {
            tInset = 2;
            bInset = 2;
        }
        int leadingInset = getAdjustedSize(fontSize, 3, 3, 1, false);
        int trailingInset = getAdjustedSize(fontSize, 5, 3, 1, false);

        return new BorderUIResource.EmptyBorderUIResource(tInset,
                ltr ? leadingInset : trailingInset, bInset,
                ltr ? trailingInset : leadingInset);
    }

    /**
     * Gets the adjusted size. The basic functionality of this method is as
     * follows:
     * 
     * <ul>
     * <li>The <code>baseSize</code> parameter specifies the base value</li>
     * <li>The <code>forEachBase</code> and <code>toAdjustBy</code> specify how
     * to adjust the resulting value based on the passed <code>fontSize</code>.</li>
     * </ul>
     * 
     * For example, if you want base value to be 1.2 pixels, and have it grow by
     * 0.1 pixel for every additional pixel in the font size, call this method
     * with the following values:
     * 
     * <ul>
     * <li><code>baseSize</code> = 1.2</li>
     * <li><code>forEachBase</code> = 1</li>
     * <li><code>toAdjustBy</code> = 0.1</li>
     * </ul>
     * 
     * @param fontSize
     *            Font size.
     * @param baseSize
     *            The base value.
     * @param forEachBase
     *            Base units for computing the adjustment.
     * @param toAdjustBy
     *            Adjustment amount for computing the adjustment.
     * @return Adjusted size.
     */
    public static float getAdjustedSize(int fontSize, float baseSize,
            int forEachBase, float toAdjustBy) {
        int delta = fontSize - 11;
        if (delta <= 0)
            return baseSize;
        float result = baseSize + delta * toAdjustBy / forEachBase;
        return result;
    }

    /**
     * Gets the adjusted size. The basic functionality of this method is as
     * follows:
     * 
     * <ul>
     * <li>The <code>baseSize</code> parameter specifies the base value</li>
     * <li>The <code>forEachBase</code> and <code>toAdjustBy</code> specify how
     * to adjust the resulting value based on the passed <code>fontSize</code>.</li>
     * </ul>
     * 
     * For example, if you want base value to be 4 pixels, and have it grow by 1
     * pixel for every 3 additional pixels in the font size, call this method
     * with the following values:
     * 
     * <ul>
     * <li><code>baseSize</code> = 4</li>
     * <li><code>forEachBase</code> = 3</li>
     * <li><code>toAdjustBy</code> = 1</li>
     * </ul>
     * 
     * @param fontSize
     *            Font size.
     * @param baseSize
     *            The base value.
     * @param forEachBase
     *            Base units for computing the adjustment.
     * @param toAdjustBy
     *            Adjustment amount for computing the adjustment.
     * @param toRoundAsEven
     *            If <code>true</code>, the final value will be rounded down to
     *            the closest even value.
     * @return Adjusted size.
     */
    public static int getAdjustedSize(int fontSize, int baseSize,
            int forEachBase, int toAdjustBy, boolean toRoundAsEven) {
        int delta = fontSize - 11;
        if (delta <= 0)
            return baseSize;
        int result = baseSize + delta * toAdjustBy / forEachBase;
        if (toRoundAsEven && (result % 2 != 0))
            result--;
        return result;
    }
}

Related

  1. getListenedButtonsFor(Container c)
  2. getMonospaceButton(final String text, final int size)
  3. getPreferredButtonSize(AbstractButton b, int textIconGap)
  4. getPreferredButtonSize(AbstractButton b, int textIconGap)
  5. getPressedButtonIcon(int x, int y)
  6. getSelectedButton(ButtonGroup group)
  7. getSelectedButtonText(ButtonGroup buttonGroup)
  8. getSelectedButtonText(ButtonGroup buttonGroup)
  9. getSoftToggleButton(String string)