Here you can find the source of getCheckBoxBorder(int fontSize, boolean ltr)
Parameter | Description |
---|---|
fontSize | Font size. |
public static Border getCheckBoxBorder(int fontSize, boolean ltr)
//package com.java2s; import javax.swing.border.Border; import javax.swing.plaf.BorderUIResource; public class Main { /**//from w ww .j a v a 2 s .c om * 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; } }