ilog.views.interactor
Class IlvDragRectangleInteractor

java.lang.Object
  extended by ilog.views.IlvManagerViewInteractor
      extended by ilog.views.interactor.IlvDragRectangleInteractor
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
IlvMakePrototypeInstanceInteractor, IlvMakeRectangleInteractor, IlvMapZoomInteractor, IlvPrintAreaInteractor, IlvSelectInteractorMultipleSelection, IlvUnZoomViewInteractor, IlvZoomViewInteractor

public class IlvDragRectangleInteractor
extends IlvManagerViewInteractor

IlvDragRectangleInteractor is a global interactor class that lets the user indicate a rectangular area in a manager view by dragging the mouse.

Overview

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 ILOG JViews, for example IlvMakeRectangleInteractor.

Example

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);
 

About Interactors and Accelerators

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:

See Also:
Serialized Form

Constructor Summary
IlvDragRectangleInteractor()
          Constructs and initializes a new instance of a drag rectangle interactor.
 
Method Summary
 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  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.
 float 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(float ratio)
          Changes the aspect ratio of the dragged rectangle.
 void setRotationAllowed(boolean allowed)
          Tells 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.
 
Methods inherited from class ilog.views.IlvManagerViewInteractor
addFocusListener, addKeyListener, addMouseListener, addMouseMotionListener, allowEnsureVisible, allowEnsureVisible, disableEvents, drawGhost, enableEvents, ensureVisible, ensureVisible, getManager, getManagerView, getTransformer, handleExpose, processEvent, processFocusEvent, processKeyEvent, removeFocusListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, setXORGhost
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IlvDragRectangleInteractor

public IlvDragRectangleInteractor()
Constructs and initializes a new instance of a drag rectangle interactor.

Method Detail

isGridMode

public final boolean isGridMode()
Returns true if the interactor snaps the dragged rectangle to the grid of the view, or false otherwise.

See Also:
setGridMode(boolean), IlvGrid

setGridMode

public final void setGridMode(boolean value)
Changes the way the interactor works with the grid.

Parameters:
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 #isGridMode
See Also:
IlvGrid

setOpaqueMode

public void setOpaqueMode(boolean set)
Sets the interactor in Opaque mode. The interactor has two modes to drag a rectangle: The Opaque mode and the Ghost mode.

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.

Since:
JViews 5.0
See Also:
isOpaqueMode()

isOpaqueMode

public boolean isOpaqueMode()
Returns whether the interactor is in Opaque mode or not.

Since:
JViews 5.0
See Also:
setOpaqueMode(boolean)

isXORGhost

public boolean isXORGhost()
Returns the ghost drawing mode. Overrides the method of the superclass to force the XOR mode when the method isOpaqueMode() returns false.

Overrides:
isXORGhost in class IlvManagerViewInteractor
Returns:
true if the drawing will be performed in XOR mode, false otherwise.
Since:
JViews 5.0
See Also:
IlvManagerViewInteractor.setXORGhost(boolean), IlvManagerViewInteractor.handleExpose(java.awt.Graphics), IlvManagerViewInteractor.drawGhost(java.awt.Graphics)

attach

protected void attach(IlvManagerView v)
Called when the interactor is attached to the specified manager view.

Overrides:
attach in class IlvManagerViewInteractor
Parameters:
v - The manager view.
See Also:
IlvManagerViewInteractor.detach()

detach

protected void detach()
Called when the interactor is detached from the current manager view.

Overrides:
detach in class IlvManagerViewInteractor
See Also:
IlvManagerViewInteractor.attach(ilog.views.IlvManagerView)

getCursor

public Cursor getCursor()
Returns the cursor used for editing.


setCursor

public void setCursor(Cursor cursor)
Changes the cursor used for editing.

Parameters:
cursor - The new cursor.

getRectangleAspectRatio

public float getRectangleAspectRatio()
Returns the aspect ratio of the dragged rectangle. The ratio is the width of the rectangle divided by the height. For example, a ratio of 2 allows dragging a rectangle whose width is twice the height. A value of zero allows dragging any rectangle regardless of the aspect ratio. This is the default.


setRectangleAspectRatio

public void setRectangleAspectRatio(float ratio)
Changes the aspect ratio of the dragged rectangle. This method allows you to set an aspect ratio for the rectangle. The ratio is the width of the rectangle divided by the height. For example, a ratio of 2 allows dragging a rectangle whose width is twice the height. A value of zero allows dragging any rectangle regardless of the aspect ratio. This is the default.

Parameters:
ratio - The new aspect ratio.

getStartPoint

protected IlvPoint getStartPoint()
Returns the anchor point of the rectangle that is dragged. While the user drags the rectangle, this method returns a point whose coordinates correspond to the point where the user has clicked for the first time. The point is in the coordinate space of the IlvManager displayed by the IlvManagerView to which this interactor is attached.

Since:
JViews 5.0

setLineStyle

public void setLineStyle(float[] lineStyle)
Changes the dash array used when dragging the rectangle. The default value is null, meaning that the dragged rectangle is drawn as a solid line.

Parameters:
lineStyle - The new line style, or null to remove the line style.
See Also:
getLineStyle()

getLineStyle

public float[] getLineStyle()
Returns the dash array used when dragging the rectangle. This method returns null if no line style was specified.

See Also:
setLineStyle(float[])

setStartDragModifier

public final void setStartDragModifier(int modifier)
Sets the modifier used to start a drag. This is used by the interactor to determine if a mouse pressed corresponds to the start of the drag. The default modifier is InputEvent.BUTTON1_MASK.

Since:
JViews 6.0
See Also:
getStartDragModifier(), isStartDragModifierDown(java.awt.event.MouseEvent)

getStartDragModifier

public final int getStartDragModifier()
Returns the modifier used to start a drag. The default modifier is InputEvent.BUTTON1_MASK.

Since:
JViews 6.0
See Also:
setStartDragModifier(int), isStartDragModifierDown(java.awt.event.MouseEvent)

isStartDragModifierDown

protected boolean isStartDragModifierDown(MouseEvent event)
Tests if the start drag modifier is currently down. The method compares the current modifiers of the event with the modifier returned by the method 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.

Since:
JViews 6.0
See Also:
setStartDragModifier(int)

processMouseEvent

protected void processMouseEvent(MouseEvent event)
Processes the mouse events. If the type of the event is 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.

Overrides:
processMouseEvent in class IlvManagerViewInteractor
Parameters:
event - The event.
See Also:
IlvManagerViewInteractor.addMouseListener(java.awt.event.MouseListener)

processMouseMotionEvent

protected void processMouseMotionEvent(MouseEvent event)
Processes the mouse motion events.

Overrides:
processMouseMotionEvent in class IlvManagerViewInteractor
Parameters:
event - The event.
See Also:
IlvManagerViewInteractor.addMouseMotionListener(java.awt.event.MouseMotionListener)

handleButtonDown

protected boolean handleButtonDown(MouseEvent event)
Processes the button down events.

Parameters:
event - The event.
Returns:
true if the event has been processed, false otherwise.
Since:
JViews 5.0

handleButtonDragged

protected boolean handleButtonDragged(MouseEvent event)
Processes the button dragged events.

Parameters:
event - The event.
Returns:
true if the event has been processed, false otherwise.
Since:
JViews 5.0

handleButtonUp

protected boolean handleButtonUp(MouseEvent event)
Processes the button up events.

Parameters:
event - The event.
Returns:
true if the event has been processed, false otherwise.
Since:
JViews 5.0

drawGhost

protected void drawGhost(Graphics g)
Draws the rectangle while it is dragged.

Overrides:
drawGhost in class IlvManagerViewInteractor
Parameters:
g - The Graphics.
See Also:
IlvManagerViewInteractor.handleExpose(java.awt.Graphics), IlvManagerViewInteractor.setXORGhost(boolean)

addRectangleDraggedListener

public void addRectangleDraggedListener(RectangleDraggedListener listener)
Adds the specified listener to receive rectangle dragged events from this interactor when the user has finished dragging a rectangle.

Parameters:
listener - The listener.
See Also:
removeRectangleDraggedListener(ilog.views.interactor.RectangleDraggedListener)

removeRectangleDraggedListener

public void removeRectangleDraggedListener(RectangleDraggedListener listener)
Removes the specified listener so that it no longer receives dragged rectangle events from this interactor.

Parameters:
listener - The listener.
See Also:
addRectangleDraggedListener(ilog.views.interactor.RectangleDraggedListener)

fireRectangleDraggedEvent

protected void fireRectangleDraggedEvent(IlvRect rectangle,
                                         MouseEvent event)
Fires a 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.

Parameters:
rectangle - The rectangle that was dragged in the manager coordinate system.
event - The mouse released event.

getDraggedRectangle

public IlvRect getDraggedRectangle()
Returns the rectangle that is dragged by this interactor. This rectangle is in manager coordinates if isRotationAllowed() returns true, otherwise it is in view coordinates.

Returns:
The rectangle that is dragged by this interactor.
Since:
JViews 7.5

setRotationAllowed

public void setRotationAllowed(boolean allowed)
Tells whether the dragged rectangle must stay parallel with the axis or is allowed to turn following the transformer. The default value is false.

Since:
JViews 7.5
See Also:
isRotationAllowed()

isRotationAllowed

public 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.

Since:
JViews 7.5
See Also:
setRotationAllowed(boolean)


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.   . All Rights Reserved.