Package org.opencms.gwt.client.util
Class CmsPositionBean
- java.lang.Object
-
- org.opencms.gwt.client.util.CmsPositionBean
-
public class CmsPositionBean extends java.lang.Object
Bean holding the position data of a HTML DOM element.- Since:
- 8.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CmsPositionBean.Area
Position area.
-
Constructor Summary
Constructors Constructor Description CmsPositionBean()
Constructor.CmsPositionBean(CmsPositionBean model)
Copy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
avoidCollision(CmsPositionBean posA, CmsPositionBean posB, int margin)
Manipulates the position infos to ensure a minimum margin between the rectangles.static boolean
checkCollision(CmsPositionBean posA, CmsPositionBean posB, int margin)
Checks whether the two position rectangles collide.boolean
containsPoint(int x, int y)
Checks if the rectangle defined by this bean contains the given point.void
ensureSurrounds(CmsPositionBean child, int padding)
Increases the dimensions to completely surround the child.static CmsPositionBean
generatePositionInfo(com.google.gwt.dom.client.Element element)
Collects the position information of the given UI object and returns a position info bean.static CmsPositionBean
generatePositionInfo(com.google.gwt.user.client.ui.UIObject uiObject)
Collects the position information of the given UI object and returns a position info bean.CmsPositionBean.Area
getArea(int absLeft, int absTop, int offset)
Returns over which area of this the given position is.static CmsPositionBean
getBoundingClientRect(com.google.gwt.dom.client.Element panel)
Returns the bounding rectangle dimensions of the element including all floated elements.static CmsPositionBean
getBoundingClientRect(com.google.gwt.dom.client.Element panel, boolean addScroll)
Returns the bounding rectangle dimensions of the element including all floated elements.int
getHeight()
Returns the height.static CmsPositionBean
getInnerDimensions(com.google.gwt.dom.client.Element panel)
Returns a position info representing the dimensions of all visible child elements of the given panel (excluding elements with position:absolute).int
getLeft()
Returns the left.int
getTop()
Returns the top.int
getWidth()
Returns the width.static boolean
isInRangeInclusive(int min, int max, int value)
Checks whether a value is in a given interval (including the end points).boolean
isInside(CmsPositionBean child, int padding)
Checks whether the given position is completely surrounded by this position.boolean
isOverElement(int absLeft, int absTop)
Returns if given position is inside the position beans coordinates.boolean
isOverTopHalf(int absTop)
Returns if given absolute top is above the vertical middle of the position beans coordinates.void
setHeight(int height)
Sets the height.void
setLeft(int left)
Sets the left.void
setTop(int top)
Sets the top.void
setWidth(int width)
Sets the width.java.lang.String
toString()
-
-
-
Constructor Detail
-
CmsPositionBean
public CmsPositionBean()
Constructor.
-
CmsPositionBean
public CmsPositionBean(CmsPositionBean model)
Copy constructor. Generating a copy of the given model.- Parameters:
model
- the model to copy
-
-
Method Detail
-
avoidCollision
public static void avoidCollision(CmsPositionBean posA, CmsPositionBean posB, int margin)
Manipulates the position infos to ensure a minimum margin between the rectangles.- Parameters:
posA
- the first position to checkposB
- the second position to checkmargin
- the required margin
-
checkCollision
public static boolean checkCollision(CmsPositionBean posA, CmsPositionBean posB, int margin)
Checks whether the two position rectangles collide.- Parameters:
posA
- the first position to checkposB
- the second position to checkmargin
- the required margin- Returns:
true
if the two position rectangles collide
-
generatePositionInfo
public static CmsPositionBean generatePositionInfo(com.google.gwt.dom.client.Element element)
Collects the position information of the given UI object and returns a position info bean.- Parameters:
element
- the object to read the position data from- Returns:
- the position data
-
generatePositionInfo
public static CmsPositionBean generatePositionInfo(com.google.gwt.user.client.ui.UIObject uiObject)
Collects the position information of the given UI object and returns a position info bean.- Parameters:
uiObject
- the object to read the position data from- Returns:
- the position data
-
getBoundingClientRect
public static CmsPositionBean getBoundingClientRect(com.google.gwt.dom.client.Element panel)
Returns the bounding rectangle dimensions of the element including all floated elements.- Parameters:
panel
- the panel- Returns:
- the position info
-
getBoundingClientRect
public static CmsPositionBean getBoundingClientRect(com.google.gwt.dom.client.Element panel, boolean addScroll)
Returns the bounding rectangle dimensions of the element including all floated elements.- Parameters:
panel
- the paneladdScroll
- if true, the result will contain the coordinates in the document's coordinate system, not the viewport coordinate system- Returns:
- the position info
-
getInnerDimensions
public static CmsPositionBean getInnerDimensions(com.google.gwt.dom.client.Element panel)
Returns a position info representing the dimensions of all visible child elements of the given panel (excluding elements with position:absolute). If the panel has no visible child elements, it's outer dimensions are returned.- Parameters:
panel
- the panel- Returns:
- the position info
-
isInRangeInclusive
public static boolean isInRangeInclusive(int min, int max, int value)
Checks whether a value is in a given interval (including the end points).- Parameters:
min
- the minimum of the intervalmax
- the maximum of the intervalvalue
- the value to check- Returns:
- true if the value is in the given interval
-
containsPoint
public boolean containsPoint(int x, int y)
Checks if the rectangle defined by this bean contains the given point.- Parameters:
x
- the horizontal coordinatey
- the vertical coordinate- Returns:
- true if this object contains the given point
-
ensureSurrounds
public void ensureSurrounds(CmsPositionBean child, int padding)
Increases the dimensions to completely surround the child.- Parameters:
child
- the child position infopadding
- the padding to apply
-
getArea
public CmsPositionBean.Area getArea(int absLeft, int absTop, int offset)
Returns over which area of this the given position is. Will returnnull
if the provided position is not within this position.- Parameters:
absLeft
- the left positionabsTop
- the right positionoffset
- the border offset- Returns:
- the area
-
getHeight
public int getHeight()
Returns the height.- Returns:
- the height
-
getLeft
public int getLeft()
Returns the left.- Returns:
- the left
-
getTop
public int getTop()
Returns the top.- Returns:
- the top
-
getWidth
public int getWidth()
Returns the width.- Returns:
- the width
-
isInside
public boolean isInside(CmsPositionBean child, int padding)
Checks whether the given position is completely surrounded by this position.- Parameters:
child
- the child positionpadding
- the padding to use- Returns:
true
if the child position is completely surrounded
-
isOverElement
public boolean isOverElement(int absLeft, int absTop)
Returns if given position is inside the position beans coordinates.- Parameters:
absLeft
- the absolute left positionabsTop
- the absolute top position- Returns:
- true if the given position if within the beans coordinates
-
isOverTopHalf
public boolean isOverTopHalf(int absTop)
Returns if given absolute top is above the vertical middle of the position beans coordinates.- Parameters:
absTop
- the absolute top position- Returns:
- true if given absolute top is above the vertical middle
-
setHeight
public void setHeight(int height)
Sets the height.- Parameters:
height
- the height to set
-
setLeft
public void setLeft(int left)
Sets the left.- Parameters:
left
- the left to set
-
setTop
public void setTop(int top)
Sets the top.- Parameters:
top
- the top to set
-
setWidth
public void setWidth(int width)
Sets the width.- Parameters:
width
- the width to set
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
- See Also:
Object.toString()
-
-