ilog.views.interactor
Class IlvGrapherPinInteractor

java.lang.Object
  extended by ilog.views.IlvManagerViewInteractor
      extended by ilog.views.interactor.IlvGrapherPinInteractor
All Implemented Interfaces:
Serializable

public class IlvGrapherPinInteractor
extends IlvManagerViewInteractor

IlvGrapherPinInteractor is an interactor used to edit IlvGrapherPin objects managed by IlvPinLinkConnector link connectors.

Overview

This interactor must be attached to an IlvManagerView. It allows you to do the following:

During the pin addition or move operations, the ALT keyboard modifier allows you to snap the location of the pin to the closest point of the bounding box of the node or its center. See getSnapToNodeBoxModifier() and getSnapBox(ilog.views.IlvGraphic, ilog.views.IlvTransformer) for more information.

Example

The following code example shows how to use IlvGrapherPinInteractor in a simple Java application:

        IlvGraphic node1, node2;
        IlvGrapher grapher = new IlvGrapher();
        IlvLinkImage link;
          
        //Create new ellipse node and add it to the grapher.
        node1 = new IlvEllipse(new IlvRect(30,10,50,50), true, false);
        grapher.addNode(node1,false);
          
        //Add a new rectangular node to the grapher.
        node2 = new IlvRectangle(new IlvRect(220,80,50,50), false, true);
        grapher.addNode(node2, 2, true);
          
        //Link the two nodes and add them to a grapher.
        link = new IlvLinkImage(node1, node2, true);
        grapher.addLink(link,false);
          
        //Add the manager to different views.
        mgrview = new IlvManagerView(grapher);
        mgrview.setBackground(Color.WHITE);
        
        IlvGrapherPinInteractor pinInteractor =
                new IlvGrapherPinInteractor() {
                {
                  enableEvents(AWTEvent.KEY_EVENT_MASK);
                }};             
        
        mgrview.setInteractor(pinInteractor);
 

About Interactors and Accelerators

IlvGrapherPinInteractor 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:

Since:
JViews 5.5
See Also:
IlvLinkImage, IlvGrapher, IlvPinLinkConnector, IlvGrapherPin, IlvDefaultGrapherPin, Serialized Form

Constructor Summary
IlvGrapherPinInteractor()
          Creates and initializes the interactor.
 
Method Summary
protected  void attach(IlvManagerView view)
          Called when the interactor is attached to the manager view.
protected  IlvGrapherPin createGrapherPin(IlvPinLinkConnector lc, IlvPoint tp, IlvTransformer t)
          Creates a new grapher pin added to the pin link connector lc and located at the point tp.
protected  IlvPinLinkConnector createPinLinkConnector(IlvGraphic node)
          Creates a new pin link connector and attaches node to it.
protected  void detach()
          This method is called when the interactor is detached from the view.
protected  void drawGhost(Graphics g)
          Draws the ghost of the edited link connector, if any.
 Cursor getCursor()
          Returns the cursor used for editing.
 IlvGrapher getGrapher()
          Returns the grapher where the interactor is attached.
 int getPinAdditionModifier()
          Returns the addition modifier.
 int getPinRemovalModifier()
          Returns the removal modifier.
protected  IlvRect getSnapBox(IlvGraphic node, IlvTransformer t)
          Returns the box of a node to be used for snapping.
 float getSnapToNodeBoxDistance()
          Returns the snap to node box distance.
 int getSnapToNodeBoxModifier()
          Returns the snap to node bounding box modifier.
protected  void highlight(IlvPinLinkConnector lc, IlvGraphic obj)
          Highlights a link connector.
 boolean isPinAdditionAllowed()
          Returns true if the interactor lets the user add pins.
 boolean isPinAdditionModifierDown(MouseEvent event)
          Tests if the addition modifier is currently down.
 boolean isPinMoveAllowed()
          Returns true if the interactor lets the user move pins.
 boolean isPinRemovalAllowed()
          Returns true if the interactor lets the user remove pins.
 boolean isPinRemovalModifierDown(MouseEvent event)
          Tests if the removal modifier is currently down.
 boolean isSelectionWhenHighlightingEnabled()
          Returns true if the graphic objects must be selected (in the sense of IlvManager.setSelected(IlvGraphic, boolean, boolean)) to indicate that the pin link connector attached to it is currently edited, and returns false otherwise.
 boolean isSnapToGridEnabled()
          Returns true if the location of pin should snapped to the grid of the manager view, and false otherwise.
 boolean isSnapToNodeBoxModifierDown(MouseEvent event)
          Tests if the snap to node bounding box modifier is currently down.
protected  void processMouseEvent(MouseEvent event)
          Processes the mouse events.
protected  void processMouseMotionEvent(MouseEvent event)
          Processes the mouse motion events.
 void setCursor(Cursor cursor)
          Changes the cursor used for editing.
 void setPinAdditionAllowed(boolean v)
          Allows or prohibits pin addition.
 void setPinAdditionModifier(int modifier)
          Sets the addition modifier.
 void setPinMoveAllowed(boolean v)
          Allows or prohibits pin move.
 void setPinRemovalAllowed(boolean v)
          Allows or prohibits pin removal.
 void setPinRemovalModifier(int modifier)
          Sets the removal modifier.
 void setSelectionWhenHightlightingEnabled(boolean enabled)
          Enables or disables the selection of graphic objects (in the sense of IlvManager.setSelected(IlvGraphic, boolean, boolean)) to indicate that the pin link connector attached to it is currently edited.
 void setSnapToGridEnabled(boolean snap)
          Enables or disables the snapping of the location of the pins to the grid of the manager view.
 void setSnapToNodeBoxDistance(float dist)
          Sets the 'snap to node box' distance.
 void setSnapToNodeBoxModifier(int modifier)
          Sets the snap to node bounding box modifier.
protected  void unHighlight(IlvPinLinkConnector lc, IlvGraphic obj)
          Unhighlights a link connector.
 
Methods inherited from class ilog.views.IlvManagerViewInteractor
addFocusListener, addKeyListener, addMouseListener, addMouseMotionListener, allowEnsureVisible, allowEnsureVisible, disableEvents, drawGhost, enableEvents, ensureVisible, ensureVisible, getManager, getManagerView, getTransformer, handleExpose, isXORGhost, 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

IlvGrapherPinInteractor

public IlvGrapherPinInteractor()
Creates and initializes the interactor.

Method Detail

attach

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

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

detach

protected void detach()
This method is called when the interactor is detached from the view.

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

getGrapher

public final IlvGrapher getGrapher()
Returns the grapher where the interactor is attached.


processMouseEvent

protected void processMouseEvent(MouseEvent event)
Processes the mouse events. The method processMouseEvent of the superclass is called after processing the event.

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. The method processMouseMotionEvent of the superclass is called after processing the event.

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

setPinAdditionModifier

public void setPinAdditionModifier(int modifier)
Sets the addition modifier. This is used by the interactor to determine if a click corresponds to the addition of a pin.

The default modifier is CTRL.

See Also:
getPinAdditionModifier(), isPinAdditionModifierDown(java.awt.event.MouseEvent)

getPinAdditionModifier

public int getPinAdditionModifier()
Returns the addition modifier. The default modifier is CTRL.

See Also:
setPinAdditionModifier(int), isPinAdditionModifierDown(java.awt.event.MouseEvent)

isPinAdditionModifierDown

public boolean isPinAdditionModifierDown(MouseEvent event)
Tests if the addition modifier is currently down. The method compares the current modifiers of the event with the modifier returned by the method getPinAdditionModifier(). This is used by the interactor to determine if a click corresponds to the addition of a pin.

The default modifier is CTRL.

See Also:
setPinAdditionModifier(int)

setPinRemovalModifier

public void setPinRemovalModifier(int modifier)
Sets the removal modifier. This is used by the interactor to determine if a click corresponds to the removal of a pin.

The default modifier is CTRL.

See Also:
getPinRemovalModifier(), isPinRemovalModifierDown(java.awt.event.MouseEvent)

getPinRemovalModifier

public int getPinRemovalModifier()
Returns the removal modifier. The default modifier is CTRL.

See Also:
setPinRemovalModifier(int), isPinRemovalModifierDown(java.awt.event.MouseEvent)

isPinRemovalModifierDown

public boolean isPinRemovalModifierDown(MouseEvent event)
Tests if the removal modifier is currently down. The method compares the current modifiers of the event with the modifier returned by the method getPinRemovalModifier(). This is used by the interactor to determine if a click corresponds to the removal of a pin.

The default modifier is CTRL.

See Also:
setPinRemovalModifier(int)

setSnapToNodeBoxModifier

public void setSnapToNodeBoxModifier(int modifier)
Sets the snap to node bounding box modifier. This is used by the interactor to determine if it should snap the location of added or moved pins to the border or center of the bounding box of the corresponding node.

The default modifier is ALT.

See Also:
getSnapToNodeBoxModifier(), isSnapToNodeBoxModifierDown(java.awt.event.MouseEvent), getSnapBox(ilog.views.IlvGraphic, ilog.views.IlvTransformer)

getSnapToNodeBoxModifier

public int getSnapToNodeBoxModifier()
Returns the snap to node bounding box modifier. The default modifier is ALT.

See Also:
setSnapToNodeBoxModifier(int), isSnapToNodeBoxModifierDown(java.awt.event.MouseEvent), getSnapBox(ilog.views.IlvGraphic, ilog.views.IlvTransformer)

isSnapToNodeBoxModifierDown

public boolean isSnapToNodeBoxModifierDown(MouseEvent event)
Tests if the snap to node bounding box modifier is currently down. The method compares the current modifiers of the event with the modifier returned by the method getSnapToNodeBoxModifier(). This is used by the interactor to determine if it should snap the location of added or moved pins to the bounding box of the corresponding node.

The default modifier is ALT.

See Also:
setSnapToNodeBoxModifier(int)

getSnapBox

protected IlvRect getSnapBox(IlvGraphic node,
                             IlvTransformer t)
Returns the box of a node to be used for snapping.

The default implementation returns the bounding box of the node (node.boundingBox(t)).

See Also:
isSnapToNodeBoxModifierDown(java.awt.event.MouseEvent)

setSnapToGridEnabled

public void setSnapToGridEnabled(boolean snap)
Enables or disables the snapping of the location of the pins to the grid of the manager view.

See Also:
isSnapToGridEnabled()

isSnapToGridEnabled

public boolean isSnapToGridEnabled()
Returns true if the location of pin should snapped to the grid of the manager view, and false otherwise.

See Also:
setSnapToGridEnabled(boolean)

setSelectionWhenHightlightingEnabled

public void setSelectionWhenHightlightingEnabled(boolean enabled)
Enables or disables the selection of graphic objects (in the sense of IlvManager.setSelected(IlvGraphic, boolean, boolean)) to indicate that the pin link connector attached to it is currently edited.

The default value is true.

However, objects that are non-selectable {IlvManager.isSelectable(IlvGraphic))) are not selected even if the selection when highlighting is enabled.


isSelectionWhenHighlightingEnabled

public boolean isSelectionWhenHighlightingEnabled()
Returns true if the graphic objects must be selected (in the sense of IlvManager.setSelected(IlvGraphic, boolean, boolean)) to indicate that the pin link connector attached to it is currently edited, and returns false otherwise.

The default value is true.

However, objects that are non-selectable {IlvManager.isSelectable(IlvGraphic))) are not selected even if this method returns true.


getCursor

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


setCursor

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


highlight

protected void highlight(IlvPinLinkConnector lc,
                         IlvGraphic obj)
Highlights a link connector. The default implementation draws the ghost of the link connector and, if isSelectionWhenHighlightingEnabled() returns true, selects the graphic object obj.

Parameters:
lc - The pin link connector to be edited.
obj - The graphic object associated with the link connector (a node or a link).

unHighlight

protected void unHighlight(IlvPinLinkConnector lc,
                           IlvGraphic obj)
Unhighlights a link connector. The default implementation erases the ghost of the link connector and, if isSelectionWhenHighlightingEnabled() returns true, deselects the graphic object obj.

Parameters:
lc - The pin link connector that is no longer edited.
obj - The graphic object associated with the link connector (a node or a link).

isPinAdditionAllowed

public final boolean isPinAdditionAllowed()
Returns true if the interactor lets the user add pins.

See Also:
setPinAdditionAllowed(boolean)

setPinAdditionAllowed

public final void setPinAdditionAllowed(boolean v)
Allows or prohibits pin addition.

See Also:
isPinAdditionAllowed()

isPinRemovalAllowed

public final boolean isPinRemovalAllowed()
Returns true if the interactor lets the user remove pins.

See Also:
setPinRemovalAllowed(boolean)

setPinRemovalAllowed

public final void setPinRemovalAllowed(boolean v)
Allows or prohibits pin removal.

See Also:
isPinRemovalAllowed()

isPinMoveAllowed

public final boolean isPinMoveAllowed()
Returns true if the interactor lets the user move pins.

See Also:
setPinMoveAllowed(boolean)

setPinMoveAllowed

public final void setPinMoveAllowed(boolean v)
Allows or prohibits pin move.

See Also:
isPinMoveAllowed()

drawGhost

protected void drawGhost(Graphics g)
Draws the ghost of the edited link connector, if any.

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

setSnapToNodeBoxDistance

public void setSnapToNodeBoxDistance(float dist)
Sets the 'snap to node box' distance. In snap to node box mode, if the distance between the location of the moved or added pin and the bounds or the center of the node (such as returned by the method getSnapBox(ilog.views.IlvGraphic, ilog.views.IlvTransformer)) is smaller than this distance, the location is snapped to the closest point on the bounds or to the center. The default distance is 8.

See Also:
getSnapToNodeBoxDistance()

getSnapToNodeBoxDistance

public float getSnapToNodeBoxDistance()
Returns the snap to node box distance.

See Also:
setSnapToNodeBoxDistance(float)

createGrapherPin

protected IlvGrapherPin createGrapherPin(IlvPinLinkConnector lc,
                                         IlvPoint tp,
                                         IlvTransformer t)
Creates a new grapher pin added to the pin link connector lc and located at the point tp.

The default implementation creates a new pin of type IlvDefaultGrapherPin.

Parameters:
lc - The pin link connector to which the pin must be added.
tp - The transformed location of the pin.
t - The transformer used to draw the pin.

createPinLinkConnector

protected IlvPinLinkConnector createPinLinkConnector(IlvGraphic node)
Creates a new pin link connector and attaches node to it. The method is called when the user clicks over a node that is not attached to a IlvPinLinkConnector or a subclass.

The default implementation creates a new IlvPinLinkConnector with no pins.

You can override this method to return a subclass of IlvPinLinkConnector, or to return null if you don't want a pin link connector to be created for node. For instance:

 if (node.getProperty("pinsAllowed") != null) {
   IlvPinLinkConnector lc = new MyPinLinkConnector();
   lc.attach(node, true);
   return lc;
 } else
   return null;
 

Parameters:
node - The node.


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