Package org.nuiton.jaxx.runtime.swing
Class ComponentResizer
- java.lang.Object
-
- java.awt.event.MouseAdapter
-
- org.nuiton.jaxx.runtime.swing.ComponentResizer
-
- All Implemented Interfaces:
MouseListener,MouseMotionListener,MouseWheelListener,EventListener
public class ComponentResizer extends MouseAdapter
The ComponentResizer allows you to resize a component by dragging a border of the component.- Since:
- 2.5.10
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<Component,String>authorizedDirectionByComponentstatic StringDIRECTION_BOTHstatic StringDIRECTION_HORIZONTALstatic StringDIRECTION_VERTICALprotected static intEASTprotected static intNORTHprotected static intSOUTHprotected static intWEST
-
Constructor Summary
Constructors Constructor Description ComponentResizer()Convenience contructor.ComponentResizer(Component... components)Convenience contructor.ComponentResizer(Insets dragInsets, Component... components)Convenience contructor.ComponentResizer(Insets dragInsets, Dimension snapSize, Component... components)Create a ComponentResizer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidchangeBounds(Component source, int direction, Rectangle bounds, Point pressed, Point current)voidderegisterComponent(Component... components)Remove listeners from the specified componentInsetsgetDragInsets()Get the drag insetsDimensiongetMaximumSize()Get the components maximum size.DimensiongetMinimumSize()Get the components minimum size.DimensiongetSnapSize()Get the snap size.voidmouseDragged(MouseEvent e)Resize the component ensuring location and size is within the bounds of the parent container and that the size is within the minimum and maximum constraints.voidmouseEntered(MouseEvent e)voidmouseExited(MouseEvent e)voidmouseMoved(MouseEvent e)voidmousePressed(MouseEvent e)voidmouseReleased(MouseEvent e)Restore the original state of the ComponentvoidregisterComponent(Component... components)Add the required listeners to the specified componentvoidregisterComponent(String authorizedDirection, Component... components)voidsetDragInsets(Insets dragInsets)Set the drag dragInsets.voidsetMaximumSize(Dimension maximumSize)Specify the maximum size for the component.voidsetMinimumSize(Dimension minimumSize)Specify the minimum size for the component.voidsetSnapSize(Dimension snapSize)Control how many pixels a border must be dragged before the size of the component is changed.-
Methods inherited from class java.awt.event.MouseAdapter
mouseClicked, mouseWheelMoved
-
-
-
-
Field Detail
-
DIRECTION_VERTICAL
public static final String DIRECTION_VERTICAL
- See Also:
- Constant Field Values
-
DIRECTION_HORIZONTAL
public static final String DIRECTION_HORIZONTAL
- See Also:
- Constant Field Values
-
DIRECTION_BOTH
public static final String DIRECTION_BOTH
- See Also:
- Constant Field Values
-
NORTH
protected static final int NORTH
- See Also:
- Constant Field Values
-
WEST
protected static final int WEST
- See Also:
- Constant Field Values
-
SOUTH
protected static final int SOUTH
- See Also:
- Constant Field Values
-
EAST
protected static final int EAST
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ComponentResizer
public ComponentResizer()
Convenience contructor. All borders are resizable in increments of a single pixel. Components must be registered separately.
-
ComponentResizer
public ComponentResizer(Component... components)
Convenience contructor. All borders are resizable in increments of a single pixel. Components can be registered when the class is created or they can be registered separately afterwards.- Parameters:
components- components to be automatically registered
-
ComponentResizer
public ComponentResizer(Insets dragInsets, Component... components)
Convenience contructor. Eligible borders are resisable in increments of a single pixel. Components can be registered when the class is created or they can be registered separately afterwards.- Parameters:
dragInsets- Insets specifying which borders are eligible to be resized.components- components to be automatically registered
-
ComponentResizer
public ComponentResizer(Insets dragInsets, Dimension snapSize, Component... components)
Create a ComponentResizer.- Parameters:
dragInsets- Insets specifying which borders are eligible to be resized.snapSize- Specify the dimension to which the border will snap to when being dragged. Snapping occurs at the halfway mark.components- components to be automatically registered
-
-
Method Detail
-
getDragInsets
public Insets getDragInsets()
Get the drag insets- Returns:
- the drag insets
-
setDragInsets
public void setDragInsets(Insets dragInsets)
Set the drag dragInsets. The insets specify an area where mouseDragged events are recognized from the edge of the border inwards. A value of 0 for any size will imply that the border is not resizable. Otherwise the appropriate drag cursor will appear when the mouse is inside the resizable border area.- Parameters:
dragInsets- Insets to control which borders are resizeable.
-
getMaximumSize
public Dimension getMaximumSize()
Get the components maximum size.- Returns:
- the maximum size
-
setMaximumSize
public void setMaximumSize(Dimension maximumSize)
Specify the maximum size for the component. The component will still be constrained by the size of its parent.- Parameters:
maximumSize- the maximum size for a component.
-
getMinimumSize
public Dimension getMinimumSize()
Get the components minimum size.- Returns:
- the minimum size
-
setMinimumSize
public void setMinimumSize(Dimension minimumSize)
Specify the minimum size for the component. The minimum size is constrained by the drag insets.- Parameters:
minimumSize- the minimum size for a component.
-
deregisterComponent
public void deregisterComponent(Component... components)
Remove listeners from the specified component- Parameters:
components- the component the listeners are removed from
-
registerComponent
public void registerComponent(Component... components)
Add the required listeners to the specified component- Parameters:
components- the component the listeners are added to
-
registerComponent
public void registerComponent(String authorizedDirection, Component... components)
-
getSnapSize
public Dimension getSnapSize()
Get the snap size.- Returns:
- the snap size.
-
setSnapSize
public void setSnapSize(Dimension snapSize)
Control how many pixels a border must be dragged before the size of the component is changed. The border will snap to the size once dragging has passed the halfway mark.- Parameters:
snapSize- Dimension object allows you to separately spcify a horizontal and vertical snap size.
-
mouseMoved
public void mouseMoved(MouseEvent e)
- Specified by:
mouseMovedin interfaceMouseMotionListener- Overrides:
mouseMovedin classMouseAdapter
-
mouseEntered
public void mouseEntered(MouseEvent e)
- Specified by:
mouseEnteredin interfaceMouseListener- Overrides:
mouseEnteredin classMouseAdapter
-
mouseExited
public void mouseExited(MouseEvent e)
- Specified by:
mouseExitedin interfaceMouseListener- Overrides:
mouseExitedin classMouseAdapter
-
mousePressed
public void mousePressed(MouseEvent e)
- Specified by:
mousePressedin interfaceMouseListener- Overrides:
mousePressedin classMouseAdapter
-
mouseReleased
public void mouseReleased(MouseEvent e)
Restore the original state of the Component- Specified by:
mouseReleasedin interfaceMouseListener- Overrides:
mouseReleasedin classMouseAdapter
-
mouseDragged
public void mouseDragged(MouseEvent e)
Resize the component ensuring location and size is within the bounds of the parent container and that the size is within the minimum and maximum constraints. All calculations are done using the bounds of the component when the resizing started.- Specified by:
mouseDraggedin interfaceMouseMotionListener- Overrides:
mouseDraggedin classMouseAdapter
-
-