net.miginfocom.layout

Class PlatformDefaults

public final class PlatformDefaults extends Object

Currently handles Windows, Mac OS X, and GNOME spacing.
Field Summary
static intBASE_FONT_SIZE
I value indicating that the size of the font for the container of the component will be used as a base for calculating the logical pixel size.
static intBASE_REAL_PIXEL
I value indicating that the size of a logical pixel should always be a real pixel and thus no compensation will be made.
static intBASE_SCALE_FACTOR
I value indicating that the screen DPI will be used as a base for calculating the logical pixel size.
static intGNOME
static intMAC_OSX
static intWINDOWS_XP
Method Summary
static StringgetButtonOrder()
Returns the order for the typical buttons in a standard button bar.
static intgetCurrentPlatform()
Returns the platform that the JRE is running on currently.
static intgetDefaultDPI()
static intgetDefaultHorizontalUnit()
Returns the current default unit.
static booleangetDefaultRowAlignmentBaseline()
The default alignment for rows.
static intgetDefaultVerticalUnit()
Returns the current default unit.
static UnitValuegetDialogInsets(int side)
Returns the default dialog inset depending of the current platform.
static InCellGapProvidergetGapProvider()
Returns the current gap provider or null if none is set and "related" should always be used.
static BoundSizegetGridGapX()
Returns the platform recommended inter-cell gap in the horizontal (x) dimension..
static BoundSizegetGridGapY()
Returns the platform recommended inter-cell gap in the vertical (x) dimension..
static FloatgetHorizontalScaleFactor()
The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied with.
static floatgetLabelAlignPercentage()
Returns the percentage used for alignment for labels (0 is left, 50 is center and 100 is right).
static intgetLogicalPixelBase()
What base value should be used to calculate logical pixel sizes.
static UnitValuegetMinimumButtonWidth()
Returns the recommended minimum button width depending on the current set platform.
static intgetModCount()
Returns how many times the defaults has been changed.
static UnitValuegetPanelInsets(int side)
Returns the default panel inset depending of the current platform.
static intgetPlatform()
Returns the current platform
static UnitValuegetUnitValueX(String unit)
Returns the unit value associated with the unit.
static UnitValuegetUnitValueY(String unit)
Returns the unit value associated with the unit.
static FloatgetVerticalScaleFactor()
The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied with.
voidinvalidate()
Tells all layout manager instances to revalidate and recalculated everything.
static voidsetButtonOrder(String order)
Sets the order for the typical buttons in a standard button bar.
static voidsetDefaultDPI(Integer dpi)
Sets the default platform DPI.
static voidsetDefaultHorizontalUnit(int unit)
Sets the default unit.
static voidsetDefaultRowAlignmentBaseline(boolean b)
The default alignment for rows.
static voidsetDefaultVerticalUnit(int unit)
Sets the default unit.
static voidsetDialogInsets(UnitValue top, UnitValue left, UnitValue bottom, UnitValue right)
Sets the default insets for a dialog.
static voidsetGapProvider(InCellGapProvider provider)
Sets the current gap provider or null if none is set and "related" should always be used.
static voidsetGridCellGap(UnitValue x, UnitValue y)
Sets gap between two cells in the grid.
static voidsetHorizontalScaleFactor(Float f)
The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied with.
static voidsetIndentGap(UnitValue x, UnitValue y)
Sets gap value for components that are "intended".
static voidsetLogicalPixelBase(int base)
What base value should be used to calculate logical pixel sizes.
static voidsetMinimumButtonWidth(UnitValue width)
Sets the recommended minimum button width.
static voidsetPanelInsets(UnitValue top, UnitValue left, UnitValue bottom, UnitValue right)
Sets the default insets for a dialog.
static voidsetParagraphGap(UnitValue x, UnitValue y)
Sets paragraph gap value for components.
static voidsetPlatform(int plaf)
Set the defaults to the default for the platform
static voidsetRelatedGap(UnitValue x, UnitValue y)
Sets gap value for components that are "related".
static voidsetUnitValue(String[] unitStrings, UnitValue x, UnitValue y)
Sets the unit value associated with a unit string.
static voidsetUnrelatedGap(UnitValue x, UnitValue y)
Sets gap value for components that are "unrelated".
static voidsetVerticalScaleFactor(Float f)
The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied with.

Field Detail

BASE_FONT_SIZE

public static final int BASE_FONT_SIZE
I value indicating that the size of the font for the container of the component will be used as a base for calculating the logical pixel size. This is much as how Windows calculated DLU (dialog units).

See Also: LPX LPY PlatformDefaults

BASE_REAL_PIXEL

public static final int BASE_REAL_PIXEL
I value indicating that the size of a logical pixel should always be a real pixel and thus no compensation will be made.

See Also: LPX LPY PlatformDefaults

BASE_SCALE_FACTOR

public static final int BASE_SCALE_FACTOR
I value indicating that the screen DPI will be used as a base for calculating the logical pixel size.

This is the default value.

See Also: LPX LPY PlatformDefaults setVerticalScaleFactor setHorizontalScaleFactor

GNOME

public static final int GNOME

MAC_OSX

public static final int MAC_OSX

WINDOWS_XP

public static final int WINDOWS_XP

Method Detail

getButtonOrder

public static final String getButtonOrder()
Returns the order for the typical buttons in a standard button bar. It is one letter per button type.

Returns: The button order.

See Also: setButtonOrder

getCurrentPlatform

public static int getCurrentPlatform()
Returns the platform that the JRE is running on currently.

Returns: The platform that the JRE is running on currently. E.g. MAC_OSX, WINDOWS_XP, or GNOME.

getDefaultDPI

public static int getDefaultDPI()

getDefaultHorizontalUnit

public static final int getDefaultHorizontalUnit()
Returns the current default unit. The default unit is the unit used if no unit is set. E.g. "width 10".

Returns: The current default unit.

See Also: PIXEL LPX

getDefaultRowAlignmentBaseline

public static boolean getDefaultRowAlignmentBaseline()
The default alignment for rows. Pre v3.5 this was false but now it is true.

Returns: The current value. Default is true.

Since: 3.5

getDefaultVerticalUnit

public static final int getDefaultVerticalUnit()
Returns the current default unit. The default unit is the unit used if no unit is set. E.g. "width 10".

Returns: The current default unit.

See Also: PIXEL LPY

getDialogInsets

public static UnitValue getDialogInsets(int side)
Returns the default dialog inset depending of the current platform.

Parameters: side top == 0, left == 1, bottom = 2, right = 3.

Returns: The inset. Never null.

getGapProvider

public static InCellGapProvider getGapProvider()
Returns the current gap provider or null if none is set and "related" should always be used.

Returns: The current gap provider or null if none is set and "related" should always be used.

getGridGapX

public static BoundSize getGridGapX()
Returns the platform recommended inter-cell gap in the horizontal (x) dimension..

Returns: The platform recommended inter-cell gap in the horizontal (x) dimension..

getGridGapY

public static BoundSize getGridGapY()
Returns the platform recommended inter-cell gap in the vertical (x) dimension..

Returns: The platform recommended inter-cell gap in the vertical (x) dimension..

getHorizontalScaleFactor

public static Float getHorizontalScaleFactor()
The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied with. If null this will default to a scale that will scale the current screen to the default screen resolution (72 DPI for Mac and 92 DPI for Windows).

Returns: The forced scale or null for default scaling.

See Also: getHorizontalScaleFactor getHorizontalScreenDPI

getLabelAlignPercentage

public static float getLabelAlignPercentage()
Returns the percentage used for alignment for labels (0 is left, 50 is center and 100 is right).

Returns: The percentage used for alignment for labels

getLogicalPixelBase

public static int getLogicalPixelBase()
What base value should be used to calculate logical pixel sizes.

Returns: The current base. Default is BASE_SCALE_FACTOR

See Also: BASE_FONT_SIZE # BASE_SCREEN_DPI_FACTOR BASE_REAL_PIXEL

getMinimumButtonWidth

public static UnitValue getMinimumButtonWidth()
Returns the recommended minimum button width depending on the current set platform.

Returns: The recommended minimum button width depending on the current set platform.

getModCount

public static int getModCount()
Returns how many times the defaults has been changed. This can be used as a light weight check to see if layout caches needs to be refreshed.

Returns: How many times the defaults has been changed.

getPanelInsets

public static UnitValue getPanelInsets(int side)
Returns the default panel inset depending of the current platform.

Parameters: side top == 0, left == 1, bottom = 2, right = 3.

Returns: The inset. Never null.

getPlatform

public static int getPlatform()
Returns the current platform

Returns: PlatformDefaults.WINDOWS or PlatformDefaults.MAC_OSX

getUnitValueX

public static UnitValue getUnitValueX(String unit)
Returns the unit value associated with the unit. (E.i. "related" or "indent"). Must be lower case.

Parameters: unit The unit string.

Returns: The unit value associated with the unit. null for unrecognized units.

getUnitValueY

public static UnitValue getUnitValueY(String unit)
Returns the unit value associated with the unit. (E.i. "related" or "indent"). Must be lower case.

Parameters: unit The unit string.

Returns: The unit value associated with the unit. null for unrecognized units.

getVerticalScaleFactor

public static Float getVerticalScaleFactor()
The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied with. If null this will default to a scale that will scale the current screen to the default screen resolution (72 DPI for Mac and 92 DPI for Windows).

Returns: The forced scale or null for default scaling.

See Also: getHorizontalScaleFactor getVerticalScreenDPI

invalidate

public void invalidate()
Tells all layout manager instances to revalidate and recalculated everything.

setButtonOrder

public static final void setButtonOrder(String order)
Sets the order for the typical buttons in a standard button bar. It is one letter per button type.

Letter in upper case will get the minimum button width that the getMinimumButtonWidth specifies and letters in lower case will get the width the current look&feel specifies.

Gaps will never be added to before the first component or after the last component. However, '+' (push) will be applied before and after as well, but with a minimum size of 0 if first/last so there will not be a gap before or after.

If gaps are explicitly set on buttons they will never be reduced, but they may be increased.

These are the characters that can be used:

Even though the style tags are normally applied to buttons this works with all components.

The normal style for MAC OS X is "L_HE+U+FBI_NYCOA_R", for Windows is "L_E+U+FBI_YNOCAH_R", and for GNOME is "L_HE+UNYACBXIO_R".

Parameters: order The new button order for the current platform.

setDefaultDPI

public static void setDefaultDPI(Integer dpi)
Sets the default platform DPI. Normally this is set in the PlatformDefaults for the different platforms but it can be tweaked here. For instance SWT on Mac does this.

Note that this is not the actual current DPI, but the base DPI for the toolkit.

Parameters: dpi The base DPI. If null the default DPI is reset to the platform base DPI.

setDefaultHorizontalUnit

public static final void setDefaultHorizontalUnit(int unit)
Sets the default unit. The default unit is the unit used if no unit is set. E.g. "width 10".

Parameters: unit The new default unit.

See Also: PIXEL LPX

setDefaultRowAlignmentBaseline

public static void setDefaultRowAlignmentBaseline(boolean b)
The default alignment for rows. Pre v3.5 this was false but now it is true.

Parameters: b The new value. Default is true from v3.5.

Since: 3.5

setDefaultVerticalUnit

public static final void setDefaultVerticalUnit(int unit)
Sets the default unit. The default unit is the unit used if no unit is set. E.g. "width 10".

Parameters: unit The new default unit.

See Also: PIXEL LPY

setDialogInsets

public static void setDialogInsets(UnitValue top, UnitValue left, UnitValue bottom, UnitValue right)
Sets the default insets for a dialog. Values that are null will not be changed.

Parameters: top The top inset. May be null. left The left inset. May be null. bottom The bottom inset. May be null. right The right inset. May be null.

setGapProvider

public static void setGapProvider(InCellGapProvider provider)
Sets the current gap provider or null if none is set and "related" should always be used.

Parameters: provider The current gap provider or null if none is set and "related" should always be used.

setGridCellGap

public static void setGridCellGap(UnitValue x, UnitValue y)
Sets gap between two cells in the grid. Note that this is not a gap between component IN a cell, that has to be set on the component constraints. The value will be the min and preferred size of the gap.

Parameters: x The value that will be transformed to pixels. If null the current value will not change. y The value that will be transformed to pixels. If null the current value will not change.

setHorizontalScaleFactor

public static void setHorizontalScaleFactor(Float f)
The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied with. If null this will default to a scale that will scale the current screen to the default screen resolution (72 DPI for Mac and 92 DPI for Windows).

Parameters: f The forced scale or null for default scaling.

See Also: getHorizontalScaleFactor getHorizontalScreenDPI

setIndentGap

public static void setIndentGap(UnitValue x, UnitValue y)
Sets gap value for components that are "intended".

Parameters: x The value that will be transformed to pixels. If null the current value will not change. y The value that will be transformed to pixels. If null the current value will not change.

setLogicalPixelBase

public static void setLogicalPixelBase(int base)
What base value should be used to calculate logical pixel sizes.

Parameters: base The new base. Default is BASE_SCALE_FACTOR

See Also: BASE_FONT_SIZE # BASE_SCREEN_DPI_FACTOR BASE_REAL_PIXEL

setMinimumButtonWidth

public static void setMinimumButtonWidth(UnitValue width)
Sets the recommended minimum button width.

Parameters: width The recommended minimum button width.

setPanelInsets

public static void setPanelInsets(UnitValue top, UnitValue left, UnitValue bottom, UnitValue right)
Sets the default insets for a dialog. Values that are null will not be changed.

Parameters: top The top inset. May be null. left The left inset. May be null. bottom The bottom inset. May be null. right The right inset. May be null.

setParagraphGap

public static void setParagraphGap(UnitValue x, UnitValue y)
Sets paragraph gap value for components.

Parameters: x The value that will be transformed to pixels. If null the current value will not change. y The value that will be transformed to pixels. If null the current value will not change.

setPlatform

public static void setPlatform(int plaf)
Set the defaults to the default for the platform

Parameters: plaf The platform. PlatformDefaults.WINDOWS_XP, PlatformDefaults.MAC_OSX, or PlatformDefaults.GNOME.

setRelatedGap

public static void setRelatedGap(UnitValue x, UnitValue y)
Sets gap value for components that are "related".

Parameters: x The value that will be transformed to pixels. If null the current value will not change. y The value that will be transformed to pixels. If null the current value will not change.

setUnitValue

public static final void setUnitValue(String[] unitStrings, UnitValue x, UnitValue y)
Sets the unit value associated with a unit string. This may be used to store values for new unit strings or modify old. Note that if a built in unit (such as "related") is modified all versions of it must be set (I.e. "r", "rel" and "related"). The build in values will be reset to the default ones if the platform is re-set.

Parameters: unitStrings The unit strings. E.g. "mu", "myunit". Will be converted to lower case and trimmed. Not null. x The value for the horizontal dimension. If null the value is not changed. y The value for the vertical dimension. Might be same object as for x. If null the value is not changed.

setUnrelatedGap

public static void setUnrelatedGap(UnitValue x, UnitValue y)
Sets gap value for components that are "unrelated".

Parameters: x The value that will be transformed to pixels. If null the current value will not change. y The value that will be transformed to pixels. If null the current value will not change.

setVerticalScaleFactor

public static void setVerticalScaleFactor(Float f)
The forced scale factor that all screen relative units (e.g. millimeters, inches and logical pixels) will be multiplied with. If null this will default to a scale that will scale the current screen to the default screen resolution (72 DPI for Mac and 92 DPI for Windows).

Parameters: f The forced scale or null for default scaling.

See Also: getHorizontalScaleFactor getVerticalScreenDPI