- java.lang.Object
-
- net.miginfocom.swing.SwingComponentWrapper
-
- All Implemented Interfaces:
ComponentWrapper
- Direct Known Subclasses:
SwingContainerWrapper
public class SwingComponentWrapper extends java.lang.Object implements ComponentWrapper
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Booleanblprivate java.awt.Componentcprivate intcompTypeprivate static java.awt.ColorDB_COMP_OUTLINEDebug color for component bounds outline.private static java.util.IdentityHashMap<java.awt.FontMetrics,java.awt.geom.Point2D.Float>FM_MAPCache.private static booleanisJava9orLaterprivate static booleanmaxSetprivate booleanprefCalledprivate static java.awt.FontSUBST_FONTprivate static java.lang.StringVISUAL_PADDING_PROPERTYProperty to use in LAF settings and as JComponent client property to specify the visual padding.private static booleanvp-
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 SwingComponentWrapper(java.awt.Component c)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private intcheckType(boolean disregardScrollPane)booleanequals(java.lang.Object o)intgetBaseline(int width, int height)Returns the baseline for the component given the suggested height.java.lang.ObjectgetComponent()Returns the actual object that this wrapper is aggregating.intgetComponentType(boolean disregardScrollPane)Returns the type of component that this wrapper is wrapping.intgetContentBias()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).intgetHeight()Returns the current height for this component.intgetHorizontalScreenDPI()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.intgetLayoutHashCode()Returns a hash code that should be reasonably different for anything that might change the layout.java.lang.StringgetLinkId()Returns a String id that can be used to reference the component in link constraints.intgetMaximumHeight(int sz)Returns the maximum height of the component.intgetMaximumWidth(int sz)Returns the maximum width of the component.intgetMinimumHeight(int sz)Returns the minimum height of the component.intgetMinimumWidth(int sz)Returns the minimum width of the component.ContainerWrappergetParent()Returns the container for this component.floatgetPixelUnitFactor(boolean isHor)Returns the pixel unit factor for the horizontal or vertical dimension.intgetPreferredHeight(int sz)Returns the preferred height of the component.intgetPreferredWidth(int sz)Returns the preferred width of the component.intgetScreenHeight()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.intgetScreenLocationX()Returns the screen x-coordinate for the upper left coordinate of the component layout-able bounds.intgetScreenLocationY()Returns the screen y-coordinate for the upper left coordinate of the component layout-able bounds.intgetScreenWidth()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.intgetVerticalScreenDPI()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.intgetWidth()Returns the current width for this component.intgetX()Returns the current x coordinate for this component.intgetY()Returns the current y coordinate for this component.booleanhasBaseline()Returns if the component has a baseline and if it can be retrieved.inthashCode()private booleanisMaxSet(java.awt.Component c)static booleanisMaxSizeSetOn1_4()Deprecated.Java 1.4 is not supported anymorebooleanisVisible()Returns if the component's visibility is set totrue.static booleanisVisualPaddingEnabled()voidpaintDebugOutline(boolean showVisualPadding)Paints component outline to indicate where it is.voidsetBounds(int x, int y, int width, int height)Sets the component's bounds.static voidsetMaxSizeSetOn1_4(boolean b)Deprecated.Java 1.4 is not supported anymorestatic voidsetVisualPaddingEnabled(boolean b)
-
-
-
Field Detail
-
maxSet
private static boolean maxSet
-
vp
private static boolean vp
-
DB_COMP_OUTLINE
private static final java.awt.Color DB_COMP_OUTLINE
Debug color for component bounds outline.
-
VISUAL_PADDING_PROPERTY
private static final java.lang.String VISUAL_PADDING_PROPERTY
Property to use in LAF settings and as JComponent client property to specify the visual padding.
-
c
private final java.awt.Component c
-
compType
private int compType
-
bl
private java.lang.Boolean bl
-
prefCalled
private boolean prefCalled
-
FM_MAP
private static final java.util.IdentityHashMap<java.awt.FontMetrics,java.awt.geom.Point2D.Float> FM_MAP
Cache.
-
SUBST_FONT
private static final java.awt.Font SUBST_FONT
-
isJava9orLater
private static boolean isJava9orLater
-
-
Method Detail
-
getBaseline
public final int getBaseline(int width, int height)Description copied from interface:ComponentWrapperReturns the baseline for the component given the suggested height.- Specified by:
getBaselinein interfaceComponentWrapper- Parameters:
width- The width to calculate for if other than the current. If-1the current size should be used.height- The height to calculate for if other than the current. If-1the current size should be used.- Returns:
- The baseline from the top or -1 if not applicable.
-
getComponent
public final java.lang.Object getComponent()
Description copied from interface:ComponentWrapperReturns 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:
getComponentin interfaceComponentWrapper- Returns:
- The actual object that this wrapper is aggregating. Not
null.
-
getPixelUnitFactor
public final float getPixelUnitFactor(boolean isHor)
Description copied from interface:ComponentWrapperReturns 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:
getPixelUnitFactorin interfaceComponentWrapper- Parameters:
isHor- If it is the horizontal factor that should be returned.- Returns:
- The factor.
-
getX
public final int getX()
Description copied from interface:ComponentWrapperReturns the current x coordinate for this component.- Specified by:
getXin interfaceComponentWrapper- Returns:
- The current x coordinate for this component.
-
getY
public final int getY()
Description copied from interface:ComponentWrapperReturns the current y coordinate for this component.- Specified by:
getYin interfaceComponentWrapper- Returns:
- The current y coordinate for this component.
-
getHeight
public final int getHeight()
Description copied from interface:ComponentWrapperReturns the current height for this component.- Specified by:
getHeightin interfaceComponentWrapper- Returns:
- The current height for this component.
-
getWidth
public final int getWidth()
Description copied from interface:ComponentWrapperReturns the current width for this component.- Specified by:
getWidthin interfaceComponentWrapper- Returns:
- The current width for this component.
-
getScreenLocationX
public final int getScreenLocationX()
Description copied from interface:ComponentWrapperReturns the screen x-coordinate for the upper left coordinate of the component layout-able bounds.- Specified by:
getScreenLocationXin interfaceComponentWrapper- Returns:
- The screen x-coordinate for the upper left coordinate of the component layout-able bounds.
-
getScreenLocationY
public final int getScreenLocationY()
Description copied from interface:ComponentWrapperReturns the screen y-coordinate for the upper left coordinate of the component layout-able bounds.- Specified by:
getScreenLocationYin interfaceComponentWrapper- Returns:
- The screen y-coordinate for the upper left coordinate of the component layout-able bounds.
-
getMinimumHeight
public final int getMinimumHeight(int sz)
Description copied from interface:ComponentWrapperReturns the minimum height of the component.- Specified by:
getMinimumHeightin interfaceComponentWrapper- Parameters:
sz- 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.
-
getMinimumWidth
public final int getMinimumWidth(int sz)
Description copied from interface:ComponentWrapperReturns the minimum width of the component.- Specified by:
getMinimumWidthin interfaceComponentWrapper- Parameters:
sz- 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.
-
getPreferredHeight
public final int getPreferredHeight(int sz)
Description copied from interface:ComponentWrapperReturns the preferred height of the component.- Specified by:
getPreferredHeightin interfaceComponentWrapper- Parameters:
sz- 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.
-
getPreferredWidth
public final int getPreferredWidth(int sz)
Description copied from interface:ComponentWrapperReturns the preferred width of the component.- Specified by:
getPreferredWidthin interfaceComponentWrapper- Parameters:
sz- 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.
-
getMaximumHeight
public final int getMaximumHeight(int sz)
Description copied from interface:ComponentWrapperReturns the maximum height of the component.- Specified by:
getMaximumHeightin interfaceComponentWrapper- Parameters:
sz- 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.
-
getMaximumWidth
public final int getMaximumWidth(int sz)
Description copied from interface:ComponentWrapperReturns the maximum width of the component.- Specified by:
getMaximumWidthin interfaceComponentWrapper- Parameters:
sz- 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.
-
isMaxSet
private boolean isMaxSet(java.awt.Component c)
-
getParent
public final ContainerWrapper getParent()
Description copied from interface:ComponentWrapperReturns the container for this component.- Specified by:
getParentin interfaceComponentWrapper- Returns:
- The container for this component. Will return
nullif the component has no parent.
-
getHorizontalScreenDPI
public final int getHorizontalScreenDPI()
Description copied from interface:ComponentWrapperReturns 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:
getHorizontalScreenDPIin interfaceComponentWrapper- Returns:
- The DPI.
-
getVerticalScreenDPI
public final int getVerticalScreenDPI()
Description copied from interface:ComponentWrapperReturns 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:
getVerticalScreenDPIin interfaceComponentWrapper- Returns:
- The DPI.
-
getScreenWidth
public final int getScreenWidth()
Description copied from interface:ComponentWrapperReturns 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
1024is returned.- Specified by:
getScreenWidthin interfaceComponentWrapper- Returns:
- The screen size. E.g.
1280.
-
getScreenHeight
public final int getScreenHeight()
Description copied from interface:ComponentWrapperReturns 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
768is returned.- Specified by:
getScreenHeightin interfaceComponentWrapper- Returns:
- The screen size. E.g.
1024.
-
hasBaseline
public final boolean hasBaseline()
Description copied from interface:ComponentWrapperReturns if the component has a baseline and if it can be retrieved. Should for instance returnfalsefor Swing before mustang.- Specified by:
hasBaselinein interfaceComponentWrapper- Returns:
- If the component has a baseline and if it can be retrieved.
-
getLinkId
public final java.lang.String getLinkId()
Description copied from interface:ComponentWrapperReturns 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 componentnullshould be returned.For instance the Swing implementation returns the string returned from
Component.getName().- Specified by:
getLinkIdin interfaceComponentWrapper- Returns:
- The string link id or
null.
-
setBounds
public final void setBounds(int x, int y, int width, int height)Description copied from interface:ComponentWrapperSets the component's bounds.- Specified by:
setBoundsin interfaceComponentWrapper- Parameters:
x- The x coordinate.y- The y coordinate.width- The width.height- The height.
-
isVisible
public boolean isVisible()
Description copied from interface:ComponentWrapperReturns 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:
isVisiblein interfaceComponentWrapper- Returns:
truemeans visible.
-
getVisualPadding
public final int[] getVisualPadding()
Description copied from interface:ComponentWrapperReturns 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
nullfor 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:
getVisualPaddingin interfaceComponentWrapper- Returns:
nullif 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]
-
isMaxSizeSetOn1_4
public static boolean isMaxSizeSetOn1_4()
Deprecated.Java 1.4 is not supported anymore
-
setMaxSizeSetOn1_4
public static void setMaxSizeSetOn1_4(boolean b)
Deprecated.Java 1.4 is not supported anymore
-
isVisualPaddingEnabled
public static boolean isVisualPaddingEnabled()
-
setVisualPaddingEnabled
public static void setVisualPaddingEnabled(boolean b)
-
paintDebugOutline
public final void paintDebugOutline(boolean showVisualPadding)
Description copied from interface:ComponentWrapperPaints component outline to indicate where it is.- Specified by:
paintDebugOutlinein interfaceComponentWrapper- Parameters:
showVisualPadding- If the visual padding should be shown in the debug drawing.
-
getComponentType
public int getComponentType(boolean disregardScrollPane)
Description copied from interface:ComponentWrapperReturns the type of component that this wrapper is wrapping.This method can be invoked often so the result should be cached.
- Specified by:
getComponentTypein interfaceComponentWrapper- Parameters:
disregardScrollPane- Istrueany 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.
-
getLayoutHashCode
public int getLayoutHashCode()
Description copied from interface:ComponentWrapperReturns 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:
getLayoutHashCodein interfaceComponentWrapper- Returns:
- A hash code that should be reasonably different for anything that might change the layout. Returns -1 if the widget is disposed.
-
checkType
private int checkType(boolean disregardScrollPane)
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
getContentBias
public int getContentBias()
Description copied from interface:ComponentWrapperReturns 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.HORIZONTALIf the min/pref/max width depends on it's height (not common) returnLayoutUtil.VERTICALIf there is no connection between the preferred min/pref/max and the size of the component return -1.- Specified by:
getContentBiasin interfaceComponentWrapper
-
-