Package com.jackmeng.core.gui
Class gui_HalcyonFrame.TitledFrame.ComponentResizer
java.lang.Object
java.awt.event.MouseAdapter
com.jackmeng.core.gui.gui_HalcyonFrame.TitledFrame.ComponentResizer
- All Implemented Interfaces:
MouseListener
,MouseMotionListener
,MouseWheelListener
,EventListener
- Enclosing class:
- gui_HalcyonFrame.TitledFrame
-
Field Summary
Modifier and TypeFieldDescriptionprivate boolean
private Rectangle
private int
private Insets
protected static final int
private static final Dimension
private Dimension
private static final Dimension
private Dimension
protected static final int
private Point
private boolean
private Dimension
private Cursor
protected static final int
protected static final int
-
Constructor Summary
ConstructorDescriptionConvenience 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
Modifier and TypeMethodDescriptionprotected void
changeBounds
(Component source, int direction, Rectangle bounds, Point pressed, Point current) void
deregisterComponent
(Component... components) Remove listeners from the specified componentprivate Dimension
getBoundingSize
(Component source) private int
getDragBounded
(int drag, int snapSize, int dimension, int minimum, int maximum) private int
getDragDistance
(int larger, int smaller, int snapSize) Get the drag insetsGet the components maximum size.Get the components minimum size.Get the snap size.void
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.void
void
void
void
void
Restore the original state of the Componentvoid
registerComponent
(Component... components) Add the required listeners to the specified componentvoid
setDragInsets
(Insets dragInsets) Set the drag dragInsets.void
setMaximumSize
(Dimension maximumSize) Specify the maximum size for the component.void
setMinimumSize
(Dimension minimumSize) Specify the minimum size for the component.void
setSnapSize
(Dimension snapSize) Control how many pixels a border must be dragged before the size of the component is changed.private void
validateMinimumAndInsets
(Dimension minimum, Insets drag) When the components minimum size is less than the drag insets then we can't determine which border should be resized so we need to prevent this from happening.Methods inherited from class java.awt.event.MouseAdapter
mouseClicked, mouseWheelMoved
-
Field Details
-
MINIMUM_SIZE
-
MAXIMUM_SIZE
-
cursors
-
dragInsets
-
snapSize
-
direction
private int direction -
NORTH
protected static final int NORTH- See Also:
-
WEST
protected static final int WEST- See Also:
-
SOUTH
protected static final int SOUTH- See Also:
-
EAST
protected static final int EAST- See Also:
-
sourceCursor
-
resizing
private boolean resizing -
bounds
-
pressed
-
autoscrolls
private boolean autoscrolls -
minimumSize
-
maximumSize
-
-
Constructor Details
-
ComponentResizer
public ComponentResizer()Convenience contructor. All borders are resizable in increments of a single pixel. Components must be registered separately. -
ComponentResizer
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
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
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 Details
-
getDragInsets
Get the drag insets- Returns:
- the drag insets
-
setDragInsets
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
Get the components maximum size.- Returns:
- the maximum size
-
setMaximumSize
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
Get the components minimum size.- Returns:
- the minimum size
-
setMinimumSize
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
Remove listeners from the specified component- Parameters:
components
- the component the listeners are removed from
-
registerComponent
Add the required listeners to the specified component- Parameters:
components
- the component the listeners are added to
-
getSnapSize
Get the snap size.- Returns:
- the snap size.
-
setSnapSize
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.
-
validateMinimumAndInsets
When the components minimum size is less than the drag insets then we can't determine which border should be resized so we need to prevent this from happening. -
mouseMoved
- Specified by:
mouseMoved
in interfaceMouseMotionListener
- Overrides:
mouseMoved
in classMouseAdapter
-
mouseEntered
- Specified by:
mouseEntered
in interfaceMouseListener
- Overrides:
mouseEntered
in classMouseAdapter
-
mouseExited
- Specified by:
mouseExited
in interfaceMouseListener
- Overrides:
mouseExited
in classMouseAdapter
-
mousePressed
- Specified by:
mousePressed
in interfaceMouseListener
- Overrides:
mousePressed
in classMouseAdapter
-
mouseReleased
Restore the original state of the Component- Specified by:
mouseReleased
in interfaceMouseListener
- Overrides:
mouseReleased
in classMouseAdapter
-
mouseDragged
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:
mouseDragged
in interfaceMouseMotionListener
- Overrides:
mouseDragged
in classMouseAdapter
-
changeBounds
-
getDragDistance
private int getDragDistance(int larger, int smaller, int snapSize) -
getDragBounded
private int getDragBounded(int drag, int snapSize, int dimension, int minimum, int maximum) -
getBoundingSize
-