Here you can find the source of getDefaultBorderInsets(int fontSize)
Parameter | Description |
---|---|
fontSize | Font size. |
public static Insets getDefaultBorderInsets(int fontSize)
//package com.java2s; import java.awt.*; public class Main { /**//from www .j a v a2s. c om * Returns the default border insets under the specified font size. * * @param fontSize * Font size. * @return Default border insets under the specified font size. */ public static Insets getDefaultBorderInsets(int fontSize) { // The base insets are 2,2,2,2. We add one pixel for // each 3 extra points in base control size. int inset = getAdjustedSize(fontSize, 2, 3, 1, false); return new Insets(inset, inset, inset, inset); } /** * 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; } }