jwo.utils.gui
Class JWRubberband

java.lang.Object
  extended byjwo.utils.gui.JWRubberband

public class JWRubberband
extends Object

Draws a rubberband box for interactive selection of rectangular regions with the mouse.

Version:
2.2, 14th September, 2002.
Author:
Jack Harich, modified by Jo Wood.

Field Summary
static int BOX
          Identifies rubberband box.
static int LINE
          Identifies linear rubberband.
 
Constructor Summary
JWRubberband(Component component)
          Initialises rubberband box with the component to draw on and a default rubberband colour.
JWRubberband(Component component, boolean line)
          Initialises rubberband feature with the component to draw on and a default rubberband colour.
JWRubberband(Component component, Color boxColour)
          Initialises rubberband box with the component to draw on and the given colour.
JWRubberband(Component component, Color boxColour, boolean line)
          Initialises rubberband feature with the component to draw on and the given colour.
 
Method Summary
 Rectangle getLine()
          Returns the current bounding box of the rubberband line, which is the final one if this is called after mouseUp.
 Rectangle getRectangle()
          Returns the current bounding box of the rubberband, which is the final one if this is called after mouseUp.
 void mouseDown(int x, int y)
          Identifies corner of rectangle.
 void mouseDrag(int x, int y)
          Identifies current active corner/end of rubberband.
 void mouseUp(int x, int y)
          Identifies closing corner/end of rubberband and erases it from component.
 void mouseUp(int x, int y, boolean visible)
          Identifies closing corner/end of rubberband.
 void setLeave(boolean leave)
          Determines if rubberband is left on component when mouse is released.
 void setRubberbandColour(Color boxColour)
          Changes the colour of the rubberband box.
 void setType(int type)
          Sets the rubberband to either a box or a line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINE

public static final int LINE
Identifies linear rubberband.

See Also:
Constant Field Values

BOX

public static final int BOX
Identifies rubberband box.

See Also:
Constant Field Values
Constructor Detail

JWRubberband

public JWRubberband(Component component)
Initialises rubberband box with the component to draw on and a default rubberband colour.

Parameters:
component - Component on which to draw the rubberband.

JWRubberband

public JWRubberband(Component component,
                    boolean line)
Initialises rubberband feature with the component to draw on and a default rubberband colour. Can be line or a box.

Parameters:
component - Component on which to draw the rubberband.
line - Rubberband line drawn if true, box if false.

JWRubberband

public JWRubberband(Component component,
                    Color boxColour)
Initialises rubberband box with the component to draw on and the given colour.

Parameters:
component - Component on which to draw the rubberband.
boxColour - Colour of rubberband box.

JWRubberband

public JWRubberband(Component component,
                    Color boxColour,
                    boolean line)
Initialises rubberband feature with the component to draw on and the given colour. Can be either a box or a line.

Parameters:
component - Component on which to draw the rubberband.
boxColour - Colour of rubberband box.
line - Rubberband line drawn if true, box if false.
Method Detail

setRubberbandColour

public void setRubberbandColour(Color boxColour)
Changes the colour of the rubberband box.

Parameters:
boxColour - New colour for the rubberband box.

setType

public void setType(int type)
Sets the rubberband to either a box or a line.

Parameters:
type - Type of rubberband feature (BOX or LINE).

setLeave

public void setLeave(boolean leave)
Determines if rubberband is left on component when mouse is released.

Parameters:
leave - Rubberband is left if set to true, erased if false.

getRectangle

public Rectangle getRectangle()
Returns the current bounding box of the rubberband, which is the final one if this is called after mouseUp.

Returns:
Bounding box of rubberband currently selected by the mouse.

getLine

public Rectangle getLine()
Returns the current bounding box of the rubberband line, which is the final one if this is called after mouseUp. The x and y coordinates of the rectangle represent the beginning of the line, the width and height the relative offset of the end. Offset may be negative if to the left or below the start point.

Returns:
Bounding box of rubberband line currently selected by the mouse.

mouseDown

public void mouseDown(int x,
                      int y)
Identifies corner of rectangle.

Parameters:
x - x-coordinate of rubberband box corner.
y - y-coordinate of rubberband box corner.

mouseDrag

public void mouseDrag(int x,
                      int y)
Identifies current active corner/end of rubberband.

Parameters:
x - x-coordinate of rubberband active corner.
y - y-coordinate of rubberband active corner.

mouseUp

public void mouseUp(int x,
                    int y)
Identifies closing corner/end of rubberband and erases it from component.

Parameters:
x - x-coordinate of rubberband box corner.
y - y-coordinate of rubberband box corner.

mouseUp

public void mouseUp(int x,
                    int y,
                    boolean visible)
Identifies closing corner/end of rubberband. Will leave rubberband in place if visible is set to true.

Parameters:
x - x-coordinate of rubberband box corner.
y - y-coordinate of rubberband box corner.
visible - Rubberband is left on component if true, erased if false.


Copyright Jo Wood, 1996-2005, last modified, 11th March, 2005