Class BBComponentWrapper
- java.lang.Object
-
- com.basiscomponents.ui.layout.BBComponentWrapper
-
- All Implemented Interfaces:
ComponentWrapper
- Direct Known Subclasses:
BBContainerWrapper
public class BBComponentWrapper extends Object implements ComponentWrapper
- Author:
- rlance
-
-
Field Summary
-
Fields inherited from interface net.miginfocom.layout.ComponentWrapper
TYPE_BUTTON, TYPE_CHECK_BOX, TYPE_COMBO_BOX, TYPE_CONTAINER, TYPE_IMAGE, TYPE_LABEL, TYPE_LIST, TYPE_PANEL, TYPE_PROGRESS_BAR, TYPE_SCROLL_BAR, TYPE_SCROLL_PANE, TYPE_SEPARATOR, TYPE_SLIDER, TYPE_SPINNER, TYPE_TABBED_PANE, TYPE_TABLE, TYPE_TEXT_AREA, TYPE_TEXT_FIELD, TYPE_TREE, TYPE_UNKNOWN, TYPE_UNSET
-
-
Constructor Summary
Constructors Constructor Description BBComponentWrapper(BBComponent component)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
This needs to be overridden so that different wrappers that hold the same component compare as equal.int
getBaseline(int width, int height)
Returns the baseline for the component given the suggested height.Object
getComponent()
Returns the actual object that this wrapper is aggregating.int
getComponentType(boolean disregardScrollPane)
Returns the type of component that this wrapper is wrapping.BBContainerWrapper
getContainerWrapper()
int
getContentBias()
Returns in what way the min/pref/max sizes relates to it's height or width for the current settings of the component (like wrapText).int
getHeight()
Returns the current height for this component.int
getHorizontalScreenDPI()
Returns the DPI (Dots Per Inch) of the screen the component is currently in or for the default screen if the component is not visible.int
getLayoutHashCode()
Returns a hash code that should be reasonably different for anything that might change the layout.String
getLinkId()
Returns a String id that can be used to reference the component in link constraints.int
getMaximumHeight(int wHint)
Returns the maximum height of the component.int
getMaximumWidth(int hHint)
Returns the maximum width of the component.int
getMinimumHeight(int wHint)
Returns the minimum height of the component.int
getMinimumWidth(int hHint)
Returns the minimum width of the component.ContainerWrapper
getParent()
Returns the container for this component.float
getPixelUnitFactor(boolean isHor)
Returns the pixel unit factor for the horizontal or vertical dimension.int
getPreferredHeight(int wHint)
Returns the preferred height of the component.int
getPreferredWidth(int hHint)
Returns the preferred width of the component.int
getScreenHeight()
Returns the pixel size of the screen that the component is currently in or for the default screen if the component is not visible ornull
.int
getScreenLocationX()
Returns the screen x-coordinate for the upper left coordinate of the component layout-able bounds.int
getScreenLocationY()
Returns the screen y-coordinate for the upper left coordinate of the component layout-able bounds.int
getScreenWidth()
Returns the pixel size of the screen that the component is currently in or for the default screen if the component is not visible ornull
.int
getVerticalScreenDPI()
Returns the DPI (Dots Per Inch) of the screen the component is currently in or for the default screen if the component is not visible.int[]
getVisualPadding()
Returns the padding on a component by component basis.int
getWidth()
Returns the current width for this component.int
getX()
Returns the current x coordinate for this component.int
getY()
Returns the current y coordinate for this component.boolean
hasBaseline()
Returns if the component has a baseline and if it can be retrieved.int
hashCode()
boolean
isVisible()
Returns if the component's visibility is set totrue
.void
paintDebugOutline(boolean showVisualPadding)
Paints component outline to indicate where it is.void
setBounds(int x, int y, int width, int height)
Sets the component's bounds.void
setContainerWrapper(BBContainerWrapper containerWrapper)
-
-
-
Constructor Detail
-
BBComponentWrapper
public BBComponentWrapper(BBComponent component)
-
-
Method Detail
-
getComponent
public Object getComponent()
Description copied from interface:ComponentWrapper
Returns the actual object that this wrapper is aggregating. This might be needed for getting information about the object that the wrapper interface does not provide.If this is a container the container should be returned instead.
- Specified by:
getComponent
in interfaceComponentWrapper
- Returns:
- The actual object that this wrapper is aggregating. Not
null
.
-
getX
public int getX()
Description copied from interface:ComponentWrapper
Returns the current x coordinate for this component.- Specified by:
getX
in interfaceComponentWrapper
- Returns:
- The current x coordinate for this component.
-
getY
public int getY()
Description copied from interface:ComponentWrapper
Returns the current y coordinate for this component.- Specified by:
getY
in interfaceComponentWrapper
- Returns:
- The current y coordinate for this component.
-
getWidth
public int getWidth()
Description copied from interface:ComponentWrapper
Returns the current width for this component.- Specified by:
getWidth
in interfaceComponentWrapper
- Returns:
- The current width for this component.
-
getHeight
public int getHeight()
Description copied from interface:ComponentWrapper
Returns the current height for this component.- Specified by:
getHeight
in interfaceComponentWrapper
- Returns:
- The current height for this component.
-
getScreenLocationX
public int getScreenLocationX()
Description copied from interface:ComponentWrapper
Returns the screen x-coordinate for the upper left coordinate of the component layout-able bounds.- Specified by:
getScreenLocationX
in interfaceComponentWrapper
- Returns:
- The screen x-coordinate for the upper left coordinate of the component layout-able bounds.
-
getScreenLocationY
public int getScreenLocationY()
Description copied from interface:ComponentWrapper
Returns the screen y-coordinate for the upper left coordinate of the component layout-able bounds.- Specified by:
getScreenLocationY
in interfaceComponentWrapper
- Returns:
- The screen y-coordinate for the upper left coordinate of the component layout-able bounds.
-
getMinimumWidth
public int getMinimumWidth(int hHint)
Description copied from interface:ComponentWrapper
Returns the minimum width of the component.- Specified by:
getMinimumWidth
in interfaceComponentWrapper
- Parameters:
hHint
- The Size hint for the other dimension. An implementation can use this value or the current size for the widget in this dimension, or a combination of both, to calculate the correct size.
Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.- Returns:
- The minimum width of the component.
-
getMinimumHeight
public int getMinimumHeight(int wHint)
Description copied from interface:ComponentWrapper
Returns the minimum height of the component.- Specified by:
getMinimumHeight
in interfaceComponentWrapper
- Parameters:
wHint
- The Size hint for the other dimension. An implementation can use this value or the current size for the widget in this dimension, or a combination of both, to calculate the correct size.
Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.- Returns:
- The minimum height of the component.
-
getPreferredWidth
public int getPreferredWidth(int hHint)
Description copied from interface:ComponentWrapper
Returns the preferred width of the component.- Specified by:
getPreferredWidth
in interfaceComponentWrapper
- Parameters:
hHint
- The Size hint for the other dimension. An implementation can use this value or the current size for the widget in this dimension, or a combination of both, to calculate the correct size.
Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.- Returns:
- The preferred width of the component.
-
getPreferredHeight
public int getPreferredHeight(int wHint)
Description copied from interface:ComponentWrapper
Returns the preferred height of the component.- Specified by:
getPreferredHeight
in interfaceComponentWrapper
- Parameters:
wHint
- The Size hint for the other dimension. An implementation can use this value or the current size for the widget in this dimension, or a combination of both, to calculate the correct size.
Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.- Returns:
- The preferred height of the component.
-
getMaximumWidth
public int getMaximumWidth(int hHint)
Description copied from interface:ComponentWrapper
Returns the maximum width of the component.- Specified by:
getMaximumWidth
in interfaceComponentWrapper
- Parameters:
hHint
- The Size hint for the other dimension. An implementation can use this value or the current size for the widget in this dimension, or a combination of both, to calculate the correct size.
Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.- Returns:
- The maximum width of the component.
-
getMaximumHeight
public int getMaximumHeight(int wHint)
Description copied from interface:ComponentWrapper
Returns the maximum height of the component.- Specified by:
getMaximumHeight
in interfaceComponentWrapper
- Parameters:
wHint
- The Size hint for the other dimension. An implementation can use this value or the current size for the widget in this dimension, or a combination of both, to calculate the correct size.
Use -1 to denote that there is no hint. This corresponds with SWT.DEFAULT.- Returns:
- The maximum height of the component.
-
setBounds
public void setBounds(int x, int y, int width, int height)
Description copied from interface:ComponentWrapper
Sets the component's bounds.- Specified by:
setBounds
in interfaceComponentWrapper
- Parameters:
x
- The x coordinate.y
- The y coordinate.width
- The width.height
- The height.
-
isVisible
public boolean isVisible()
Description copied from interface:ComponentWrapper
Returns if the component's visibility is set totrue
. This should not return if the component is actually visible, but if the visibility is set to true or not.- Specified by:
isVisible
in interfaceComponentWrapper
- Returns:
true
means visible.
-
getBaseline
public int getBaseline(int width, int height)
Description copied from interface:ComponentWrapper
Returns the baseline for the component given the suggested height.- Specified by:
getBaseline
in interfaceComponentWrapper
- Parameters:
width
- The width to calculate for if other than the current. If-1
the current size should be used.height
- The height to calculate for if other than the current. If-1
the current size should be used.- Returns:
- The baseline from the top or -1 if not applicable.
-
hasBaseline
public boolean hasBaseline()
Description copied from interface:ComponentWrapper
Returns if the component has a baseline and if it can be retrieved. Should for instance returnfalse
for Swing before mustang.- Specified by:
hasBaseline
in interfaceComponentWrapper
- Returns:
- If the component has a baseline and if it can be retrieved.
-
getParent
public ContainerWrapper getParent()
Description copied from interface:ComponentWrapper
Returns the container for this component.- Specified by:
getParent
in interfaceComponentWrapper
- Returns:
- The container for this component. Will return
null
if the component has no parent.
-
getPixelUnitFactor
public float getPixelUnitFactor(boolean isHor)
Description copied from interface:ComponentWrapper
Returns the pixel unit factor for the horizontal or vertical dimension.The factor is 1 for both dimensions on the normal font in a JPanel on Windows. The factor should increase with a bigger "X".
This is the Swing version:
Rectangle2D r = fm.getStringBounds("X", parent.getGraphics()); wFactor = r.getWidth() / 6; hFactor = r.getHeight() / 13.27734375f;
- Specified by:
getPixelUnitFactor
in interfaceComponentWrapper
- Parameters:
isHor
- If it is the horizontal factor that should be returned.- Returns:
- The factor.
-
getHorizontalScreenDPI
public int getHorizontalScreenDPI()
Description copied from interface:ComponentWrapper
Returns the DPI (Dots Per Inch) of the screen the component is currently in or for the default screen if the component is not visible.If headless mode
PlatformDefaults.getDefaultDPI()
will be returned.- Specified by:
getHorizontalScreenDPI
in interfaceComponentWrapper
- Returns:
- The DPI.
-
getVerticalScreenDPI
public int getVerticalScreenDPI()
Description copied from interface:ComponentWrapper
Returns the DPI (Dots Per Inch) of the screen the component is currently in or for the default screen if the component is not visible.If headless mode
PlatformDefaults.getDefaultDPI()
will be returned.- Specified by:
getVerticalScreenDPI
in interfaceComponentWrapper
- Returns:
- The DPI.
-
getScreenWidth
public int getScreenWidth()
Description copied from interface:ComponentWrapper
Returns the pixel size of the screen that the component is currently in or for the default screen if the component is not visible ornull
.If in headless mode
1024
is returned.- Specified by:
getScreenWidth
in interfaceComponentWrapper
- Returns:
- The screen size. E.g.
1280
.
-
getScreenHeight
public int getScreenHeight()
Description copied from interface:ComponentWrapper
Returns the pixel size of the screen that the component is currently in or for the default screen if the component is not visible ornull
.If in headless mode
768
is returned.- Specified by:
getScreenHeight
in interfaceComponentWrapper
- Returns:
- The screen size. E.g.
1024
.
-
getLinkId
public String getLinkId()
Description copied from interface:ComponentWrapper
Returns a String id that can be used to reference the component in link constraints. This value should return the default id for the component. The id can be set for a component in the constraints and if so the value returned by this method will never be used. If there are no sensible id for the componentnull
should be returned.For instance the Swing implementation returns the string returned from
Component.getName()
.- Specified by:
getLinkId
in interfaceComponentWrapper
- Returns:
- The string link id or
null
.
-
getLayoutHashCode
public int getLayoutHashCode()
Description copied from interface:ComponentWrapper
Returns a hash code that should be reasonably different for anything that might change the layout. This value is used to know if the component layout needs to clear any caches.- Specified by:
getLayoutHashCode
in interfaceComponentWrapper
- Returns:
- A hash code that should be reasonably different for anything that might change the layout. Returns -1 if the widget is disposed.
-
getVisualPadding
public int[] getVisualPadding()
Description copied from interface:ComponentWrapper
Returns the padding on a component by component basis. This method can be overridden to return padding to compensate for example for borders that have shadows or where the outer most pixel is not the visual "edge" to align to.Default implementation returns
null
for all components except for Windows XP's JTabbedPane which will return new Insets(0, 0, 2, 2).NOTE! To reduce generated garbage the returned padding should never be changed so that the same insets can be returned many times.
- Specified by:
getVisualPadding
in interfaceComponentWrapper
- Returns:
null
if no padding. NOTE! To reduce generated garbage the returned padding should never be changed so that the same insets can be returned many times. [top, left, bottom, right]
-
getComponentType
public int getComponentType(boolean disregardScrollPane)
Description copied from interface:ComponentWrapper
Returns the type of component that this wrapper is wrapping.This method can be invoked often so the result should be cached.
- Specified by:
getComponentType
in interfaceComponentWrapper
- Parameters:
disregardScrollPane
- Istrue
any wrapping scroll pane should be disregarded and the type of the scrolled component should be returned.- Returns:
- The type of component that this wrapper is wrapping. E.g.
ComponentWrapper.TYPE_LABEL
.
-
getContainerWrapper
public BBContainerWrapper getContainerWrapper()
- Returns:
- the containerWrapper
-
setContainerWrapper
public void setContainerWrapper(BBContainerWrapper containerWrapper)
- Parameters:
containerWrapper
- the containerWrapper to set
-
equals
public boolean equals(Object o)
This needs to be overridden so that different wrappers that hold the same component compare as equal. Otherwise, Grid won't be able to layout the components correctly.
-
paintDebugOutline
public void paintDebugOutline(boolean showVisualPadding)
Description copied from interface:ComponentWrapper
Paints component outline to indicate where it is.- Specified by:
paintDebugOutline
in interfaceComponentWrapper
- Parameters:
showVisualPadding
- If the visual padding should be shown in the debug drawing.
-
getContentBias
public int getContentBias()
Description copied from interface:ComponentWrapper
Returns in what way the min/pref/max sizes relates to it's height or width for the current settings of the component (like wrapText). If the min/pref/max height depends on it's width returnLayoutUtil.HORIZONTAL
If the min/pref/max width depends on it's height (not common) returnLayoutUtil.VERTICAL
If there is no connection between the preferred min/pref/max and the size of the component return -1.- Specified by:
getContentBias
in interfaceComponentWrapper
-
-