public class IlvDragRectangleInteractor extends IlvAbstractScrollInteractor
IlvDragRectangleInteractor
is a global interactor class that
lets the user indicate a rectangular area in a manager view by dragging
the mouse.
When the mouse is dragged, a rectangle corresponding to the dragged
area is temporarily drawn in the view, and the listeners registered using
addRectangleDraggedListener(RectangleDraggedListener)
are notified
of the event.
Typically, subclasses of this interactor are used for implementing
interactions such as creating rectangular graphic objects, zooming in
a specific area of the view and so on. Predefined subclasses are
provided by Rogue Wave JViews, for example IlvMakeRectangleInteractor
.
The following code example shows how to use
IlvDragRectangleInteractor
in a simple Java application:
IlvManager mgr = new IlvManager(); IlvManagerView view = new IlvManagerView(mgr); // Create and add 2 graphic objects. IlvGraphic obj1 = new IlvRectangle(new IlvRect(60, 30, 50, 50)); mgr.addObject(obj1, false); IlvGraphic obj2 = new IlvRectangle(new IlvRect(140, 50, 10, 10)); mgr.addObject(obj2, false); IlvDragRectangleInteractor inter = new IlvDragRectangleInteractor(); view.setInteractor(inter);
IlvDragRectangleInteractor
is a custom global interactor, that
is, a subclass of IlvManagerViewInteractor
. A global interactor
is a class that listens to a specific event in the manager view. All input events
are handled by means of interactors or accelerators. For information about
how to treat events in a manager, see
Handling Events. The following code
examples show how to handle user events:
Constructor and Description |
---|
IlvDragRectangleInteractor()
Constructs and initializes a new instance of a drag rectangle interactor.
|
Modifier and Type | Method and Description |
---|---|
void |
addRectangleDraggedListener(RectangleDraggedListener listener)
Adds the specified listener to receive rectangle dragged events from this
interactor when the user has finished dragging a rectangle.
|
protected void |
attach(IlvManagerView v)
Called when the interactor
is attached to the specified manager view.
|
protected void |
detach()
Called when the interactor
is detached from the current manager view.
|
protected boolean |
dragscroll(MouseEvent event)
Called by the dragging scroll timer to scroll the view.
|
protected void |
drawGhost(Graphics g)
Draws the rectangle while it is dragged.
|
protected void |
fireRectangleDraggedEvent(IlvRect rectangle,
MouseEvent event)
Fires a
RectangleDraggedEvent . |
Cursor |
getCursor()
Returns the cursor used for editing.
|
IlvRect |
getDraggedRectangle()
Returns the rectangle that is dragged by this interactor.
|
float[] |
getLineStyle()
Returns the dash array used when dragging
the rectangle.
|
double |
getRectangleAspectRatio()
Returns the aspect ratio of the dragged rectangle.
|
int |
getStartDragModifier()
Returns the modifier used to start a drag.
|
protected IlvPoint |
getStartPoint()
Returns the anchor point of the rectangle that is dragged.
|
protected boolean |
handleButtonDown(MouseEvent event)
Processes the button down events.
|
protected boolean |
handleButtonDragged(MouseEvent event)
Processes the button dragged events.
|
protected boolean |
handleButtonUp(MouseEvent event)
Processes the button up events.
|
boolean |
isGridMode()
Returns
true if the interactor snaps the dragged rectangle
to the grid of the view, or false otherwise. |
boolean |
isOpaqueMode()
Returns whether the interactor is in Opaque
mode or not.
|
boolean |
isRotationAllowed()
Returns
true if the dragged rectangle is allowed
to rotate following the transformer, and returns false
if it must stay parallel to the axis. |
protected boolean |
isStartDragModifierDown(MouseEvent event)
Tests if the start drag modifier is currently down.
|
boolean |
isXORGhost()
Returns the ghost drawing mode.
|
protected void |
processMouseEvent(MouseEvent event)
Processes the mouse events.
|
protected void |
processMouseMotionEvent(MouseEvent event)
Processes the mouse motion events.
|
void |
removeRectangleDraggedListener(RectangleDraggedListener listener)
Removes the specified listener so that it no longer receives dragged
rectangle events from this interactor.
|
void |
setCursor(Cursor cursor)
Changes the cursor used for editing.
|
void |
setGridMode(boolean value)
Changes the way the interactor works with the grid.
|
void |
setLineStyle(float[] lineStyle)
Changes the dash array used when dragging
the rectangle.
|
void |
setOpaqueMode(boolean set)
Sets the interactor in Opaque mode.
|
void |
setRectangleAspectRatio(double ratio)
Changes the aspect ratio of the dragged rectangle.
|
void |
setRotationAllowed(boolean allowed)
Specifies whether the dragged rectangle must stay parallel with the
axis or is allowed to turn following the transformer.
|
void |
setStartDragModifier(int modifier)
Sets the modifier used to start a drag.
|
adjustPointIfOutsideView, doAutoScroll, getMaximumScrollDistance, getScrollTiming, isProgressiveScroll, setMaximumScrollDistance, setProgressiveScroll, setScrollTiming, startDraggingScrollTimer, stopDraggingScrollTimer
addFocusListener, addKeyListener, addMouseListener, addMouseMotionListener, allowEnsureVisible, allowEnsureVisible, disableEvents, drawGhost, enableEvents, ensureVisible, ensureVisible, getManager, getManagerView, getTransformer, handleExpose, processEvent, processFocusEvent, processKeyEvent, removeFocusListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, setXORGhost
public IlvDragRectangleInteractor()
public final boolean isGridMode()
true
if the interactor snaps the dragged rectangle
to the grid of the view, or false
otherwise.setGridMode(boolean)
,
IlvGrid
public final void setGridMode(boolean value)
value
- Must be set to true
if you want the interactor to snap the dragged rectangle
to the grid of the view; false
otherwise.
#see #isGridModeIlvGrid
public void setOpaqueMode(boolean set)
In Opaque mode, while the user drags the rectangle,
the previous rectangle is erased by invalidating
the corresponding regions of the view using
IlvManagerView.invalidateRect(ilog.views.IlvRect)
and requesting a redraw using IlvManagerView.reDrawViews()
.
This mode may be slower because it requires partial redraws of the
manager, but it is safer because it behaves well if animated
gif
images are used (inside IlvIcon
graphic objects).
In Ghost mode, the previous rectangle is erased by drawing it again (in XOR mode). This mode is quicker because there is no redraw of the manager contents.
The default mode is the Ghost mode.
isOpaqueMode()
public boolean isOpaqueMode()
setOpaqueMode(boolean)
public boolean isXORGhost()
isOpaqueMode()
returns false
.isXORGhost
in class IlvManagerViewInteractor
true
if the drawing will be performed in
XOR
mode, false
otherwise.IlvManagerViewInteractor.setXORGhost(boolean)
,
IlvManagerViewInteractor.handleExpose(java.awt.Graphics)
,
IlvManagerViewInteractor.drawGhost(java.awt.Graphics)
protected void attach(IlvManagerView v)
attach
in class IlvManagerViewInteractor
v
- The manager view.IlvManagerViewInteractor.detach()
protected void detach()
detach
in class IlvAbstractScrollInteractor
IlvManagerViewInteractor.attach(ilog.views.IlvManagerView)
public Cursor getCursor()
public void setCursor(Cursor cursor)
cursor
- The new cursor.public double getRectangleAspectRatio()
public void setRectangleAspectRatio(double ratio)
ratio
- The new aspect ratio.protected IlvPoint getStartPoint()
IlvManager
displayed by the
IlvManagerView
to which this interactor is attached.public void setLineStyle(float[] lineStyle)
null
, meaning
that the dragged rectangle is drawn as a solid line.lineStyle
- The new line style, or null
to remove the
line style.getLineStyle()
public float[] getLineStyle()
null
if no line style was specified.setLineStyle(float[])
public final void setStartDragModifier(int modifier)
InputEvent.BUTTON1_MASK
.getStartDragModifier()
,
isStartDragModifierDown(java.awt.event.MouseEvent)
public final int getStartDragModifier()
InputEvent.BUTTON1_MASK
.setStartDragModifier(int)
,
isStartDragModifierDown(java.awt.event.MouseEvent)
protected boolean isStartDragModifierDown(MouseEvent event)
getStartDragModifier()
.
This is used by the interactor to determine if a mouse pressed corresponds to
the start of the drag.
The default modifier is InputEvent.BUTTON2_MASK
.setStartDragModifier(int)
protected void processMouseEvent(MouseEvent event)
MOUSE_PRESSED
, the method handleButtonDown(java.awt.event.MouseEvent)
is
called. Otherwise, if the type of the event is MOUSE_RELEASED
,
the method handleButtonUp(java.awt.event.MouseEvent)
is called. In all cases, the
method processMouseEvent
of the superclass is called.processMouseEvent
in class IlvManagerViewInteractor
event
- The event.IlvManagerViewInteractor.addMouseListener(java.awt.event.MouseListener)
protected void processMouseMotionEvent(MouseEvent event)
processMouseMotionEvent
in class IlvManagerViewInteractor
event
- The event.IlvManagerViewInteractor.addMouseMotionListener(java.awt.event.MouseMotionListener)
protected boolean handleButtonDown(MouseEvent event)
event
- The event.true
if the event has been processed,
false
otherwise.protected boolean handleButtonDragged(MouseEvent event)
event
- The event.true
if the event has been processed,
false
otherwise.protected boolean dragscroll(MouseEvent event)
handleButtonDragged(java.awt.event.MouseEvent)
.dragscroll
in class IlvAbstractScrollInteractor
protected boolean handleButtonUp(MouseEvent event)
event
- The event.true
if the event has been processed,
false
otherwise.protected void drawGhost(Graphics g)
drawGhost
in class IlvManagerViewInteractor
g
- The Graphics.IlvManagerViewInteractor.handleExpose(java.awt.Graphics)
,
IlvManagerViewInteractor.setXORGhost(boolean)
public void addRectangleDraggedListener(RectangleDraggedListener listener)
listener
- The listener.removeRectangleDraggedListener(ilog.views.interactor.RectangleDraggedListener)
public void removeRectangleDraggedListener(RectangleDraggedListener listener)
listener
- The listener.addRectangleDraggedListener(ilog.views.interactor.RectangleDraggedListener)
protected void fireRectangleDraggedEvent(IlvRect rectangle, MouseEvent event)
RectangleDraggedEvent
.
This method notifies all the listeners that a rectangle
has been dragged. The method is called when the user
releases the mouse button after the drag.rectangle
- The rectangle that was dragged in the
manager coordinate system.event
- The mouse released event.public IlvRect getDraggedRectangle()
isRotationAllowed()
returns true
, otherwise it is in view coordinates.public void setRotationAllowed(boolean allowed)
false
.isRotationAllowed()
public boolean isRotationAllowed()
true
if the dragged rectangle is allowed
to rotate following the transformer, and returns false
if it must stay parallel to the axis.setRotationAllowed(boolean)
© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.