Class ComponentResizer

java.lang.Object
java.awt.event.MouseAdapter
jaxx.runtime.swing.ComponentResizer
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, java.util.EventListener

public class ComponentResizer
extends java.awt.event.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 java.util.Map<java.awt.Component,​java.lang.String> authorizedDirectionByComponent  
    static java.lang.String DIRECTION_BOTH  
    static java.lang.String DIRECTION_HORIZONTAL  
    static java.lang.String DIRECTION_VERTICAL  
    protected static int EAST  
    protected static int NORTH  
    protected static int SOUTH  
    protected static int WEST  
  • Constructor Summary

    Constructors
    Constructor Description
    ComponentResizer()
    Convenience contructor.
    ComponentResizer​(java.awt.Component... components)
    Convenience contructor.
    ComponentResizer​(java.awt.Insets dragInsets, java.awt.Component... components)
    Convenience contructor.
    ComponentResizer​(java.awt.Insets dragInsets, java.awt.Dimension snapSize, java.awt.Component... components)
    Create a ComponentResizer.
  • Method Summary

    Modifier and Type Method Description
    protected void changeBounds​(java.awt.Component source, int direction, java.awt.Rectangle bounds, java.awt.Point pressed, java.awt.Point current)  
    void deregisterComponent​(java.awt.Component... components)
    Remove listeners from the specified component
    java.awt.Insets getDragInsets()
    Get the drag insets
    java.awt.Dimension getMaximumSize()
    Get the components maximum size.
    java.awt.Dimension getMinimumSize()
    Get the components minimum size.
    java.awt.Dimension getSnapSize()
    Get the snap size.
    void mouseDragged​(java.awt.event.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.
    void mouseEntered​(java.awt.event.MouseEvent e)  
    void mouseExited​(java.awt.event.MouseEvent e)  
    void mouseMoved​(java.awt.event.MouseEvent e)  
    void mousePressed​(java.awt.event.MouseEvent e)  
    void mouseReleased​(java.awt.event.MouseEvent e)
    Restore the original state of the Component
    void registerComponent​(java.awt.Component... components)
    Add the required listeners to the specified component
    void registerComponent​(java.lang.String authorizedDirection, java.awt.Component... components)  
    void setDragInsets​(java.awt.Insets dragInsets)
    Set the drag dragInsets.
    void setMaximumSize​(java.awt.Dimension maximumSize)
    Specify the maximum size for the component.
    void setMinimumSize​(java.awt.Dimension minimumSize)
    Specify the minimum size for the component.
    void setSnapSize​(java.awt.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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DIRECTION_VERTICAL

      public static final java.lang.String DIRECTION_VERTICAL
      See Also:
      Constant Field Values
    • DIRECTION_HORIZONTAL

      public static final java.lang.String DIRECTION_HORIZONTAL
      See Also:
      Constant Field Values
    • DIRECTION_BOTH

      public static final java.lang.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
    • authorizedDirectionByComponent

      protected java.util.Map<java.awt.Component,​java.lang.String> authorizedDirectionByComponent
  • Constructor Details

    • ComponentResizer

      public ComponentResizer()
      Convenience contructor. All borders are resizable in increments of a single pixel. Components must be registered separately.
    • ComponentResizer

      public ComponentResizer​(java.awt.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​(java.awt.Insets dragInsets, java.awt.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​(java.awt.Insets dragInsets, java.awt.Dimension snapSize, java.awt.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 Details

    • getDragInsets

      public java.awt.Insets getDragInsets()
      Get the drag insets
      Returns:
      the drag insets
    • setDragInsets

      public void setDragInsets​(java.awt.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 java.awt.Dimension getMaximumSize()
      Get the components maximum size.
      Returns:
      the maximum size
    • setMaximumSize

      public void setMaximumSize​(java.awt.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 java.awt.Dimension getMinimumSize()
      Get the components minimum size.
      Returns:
      the minimum size
    • setMinimumSize

      public void setMinimumSize​(java.awt.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​(java.awt.Component... components)
      Remove listeners from the specified component
      Parameters:
      components - the component the listeners are removed from
    • registerComponent

      public void registerComponent​(java.awt.Component... components)
      Add the required listeners to the specified component
      Parameters:
      components - the component the listeners are added to
    • registerComponent

      public void registerComponent​(java.lang.String authorizedDirection, java.awt.Component... components)
    • getSnapSize

      public java.awt.Dimension getSnapSize()
      Get the snap size.
      Returns:
      the snap size.
    • setSnapSize

      public void setSnapSize​(java.awt.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​(java.awt.event.MouseEvent e)
      Specified by:
      mouseMoved in interface java.awt.event.MouseMotionListener
      Overrides:
      mouseMoved in class java.awt.event.MouseAdapter
    • mouseEntered

      public void mouseEntered​(java.awt.event.MouseEvent e)
      Specified by:
      mouseEntered in interface java.awt.event.MouseListener
      Overrides:
      mouseEntered in class java.awt.event.MouseAdapter
    • mouseExited

      public void mouseExited​(java.awt.event.MouseEvent e)
      Specified by:
      mouseExited in interface java.awt.event.MouseListener
      Overrides:
      mouseExited in class java.awt.event.MouseAdapter
    • mousePressed

      public void mousePressed​(java.awt.event.MouseEvent e)
      Specified by:
      mousePressed in interface java.awt.event.MouseListener
      Overrides:
      mousePressed in class java.awt.event.MouseAdapter
    • mouseReleased

      public void mouseReleased​(java.awt.event.MouseEvent e)
      Restore the original state of the Component
      Specified by:
      mouseReleased in interface java.awt.event.MouseListener
      Overrides:
      mouseReleased in class java.awt.event.MouseAdapter
    • mouseDragged

      public void mouseDragged​(java.awt.event.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:
      mouseDragged in interface java.awt.event.MouseMotionListener
      Overrides:
      mouseDragged in class java.awt.event.MouseAdapter
    • changeBounds

      protected void changeBounds​(java.awt.Component source, int direction, java.awt.Rectangle bounds, java.awt.Point pressed, java.awt.Point current)