org.zaval.awt.gdp
Class ShapeController


java.lang.Object

  |

  +--org.zaval.awt.gdp.Controller

        |

        +--org.zaval.awt.gdp.ShapeController

All Implemented Interfaces:
java.util.EventListener, MouseDragListener

public class ShapeController
extends Controller
implements MouseDragListener

This shape controller class that can be used to control size and location for the specified target component.

The controller registers itself as MouseDragListener listener of the target component and registers a cursor controller for the target component.


Constructor Summary
ShapeController(java.awt.Component target)
           Constructs a new shape controller with the specified target component.
 
Method Summary
 void dragMoved(MouseDragEvent e)
           Invoked every time when mouse drag event is performed with the source component.
 void dragStarted(MouseDragEvent e)
           Invoked when first mouse drag events has been performed with the source component.
 void dragStopped(MouseDragEvent e)
           Invoked when mouse drag is stopped.
protected  java.awt.Insets getBoundsMask()
           Gets the insets mask.
 CursorController getCursorController()
           Gets the cursor controller that is used for the target component with the controller.
protected  void moveComponent(int ax, int ay)
           Moves the target component to the new location.
protected  void resizeComponent(java.awt.Rectangle r)
           Shapes the target component with the specified bounds.
protected  void setCursorController(CursorController c)
           Sets the specified cursor controller.
protected  void targetWasChanged(java.awt.Component n, java.awt.Component o)
           The method is called whenever the target component has been changed.
 
Methods inherited from class org.zaval.awt.gdp.Controller
getTarget, setTarget
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShapeController


public ShapeController(java.awt.Component target)
Constructs a new shape controller with the specified target component.
Parameters:
target - the specified target component.
Method Detail

dragStarted


public void dragStarted(MouseDragEvent e)
Invoked when first mouse drag events has been performed with the source component.
Specified by:
dragStarted in interface MouseDragListener
Parameters:
e - the specified mouse drag event.

dragMoved


public void dragMoved(MouseDragEvent e)
Invoked every time when mouse drag event is performed with the source component.
Specified by:
dragMoved in interface MouseDragListener
Parameters:
e - the specified mouse drag event.

dragStopped


public void dragStopped(MouseDragEvent e)
Invoked when mouse drag is stopped.
Specified by:
dragStopped in interface MouseDragListener
Parameters:
e - the specified mouse drag event.

getCursorController


public CursorController getCursorController()
Gets the cursor controller that is used for the target component with the controller.
Returns:
a cursor controller .

setCursorController


protected void setCursorController(CursorController c)
Sets the specified cursor controller.
Parameters:
c - the specified cursor controller.

moveComponent


protected void moveComponent(int ax,
                             int ay)
Moves the target component to the new location.
Parameters:
ax - the specified x coordinate relatively the top-level parent component of the target component.
ay - the specified y coordinate relatively the top-level parent component of the target component.

resizeComponent


protected void resizeComponent(java.awt.Rectangle r)
Shapes the target component with the specified bounds.
Parameters:
r - the new bounds for the target component. The x and y fields of the bounds define a new location of the target relatively the top-level parent component.

getBoundsMask


protected java.awt.Insets getBoundsMask()
Gets the insets mask. The insets indicates what bounds should be changed. It is necessary to use 0 or 1 value as the insets fields values. The insets fileds meaning is described bellow:
  • left field indicates that x top-left corner coordinate of the target component should be changed according to the current mouse pointer location (a location of the bottom-right corner is not changed).
  • top field indicates that y top-left corner coordinate of the target component should be changed according to the current mouse pointer location (a location of the bottom-right corner is not changed).
  • right field indicates that x bottom-right corner coordinate of the target component should be changed according to the current mouse pointer location (a location of the top-left corner is not changed).
  • bottom field indicates that y bottom-right corner coordinate of the target component should be changed according to the current mouse pointer location (a location of the top-left corner is not changed).
  • If all fields are set to 1 than the component will be moved. In this case the target can get a new parent container.
  • The insets is null if nothing should be changed for the target component.

The implementation defines the insets fields according to the current mouse cursor type (the mouse cursor type is set with the cursor controller). The table bellow shows the correspondence the cursor type and the insets that will be returnd.
Cursor type Returned insets
Cursor.W_RESIZE_CURSOR left=1, top=0, right=0, bottom=0
Cursor.E_RESIZE_CURSOR left=0, top=0, right=1, bottom=0
Cursor.N_RESIZE_CURSOR left=0, top=1, right=0, bottom=0
Cursor.S_RESIZE_CURSOR left=0, top=0, right=0, bottom=1
Cursor.NW_RESIZE_CURSOR left=1, top=1, right=0, bottom=0
Cursor.NE_RESIZE_CURSOR left=0, top=1, right=1, bottom=0
Cursor.SW_RESIZE_CURSOR left=1, top=0, right=0, bottom=1
Cursor.SE_RESIZE_CURSOR left=0, top=0, right=1, bottom=1
Cursor.MOVE_CURSOR left=1, top=1, right=1, bottom=1

Returns:
an insets.

targetWasChanged


protected void targetWasChanged(java.awt.Component n,
                                java.awt.Component o)
The method is called whenever the target component has been changed. The controller uses cursor controller and drag controller, so the method implementation synchronizes the new target with the two controllers.
Overrides:
targetWasChanged in class Controller
Parameters:
n - the specified new target component.
o - the specified old target component.


Copyright © Zaval Creative Engineering Group, 2000-2005
http://www.zaval.org