public class IlvGrapherPinInteractor extends IlvManagerViewInteractor
IlvGrapherPinInteractor
is an interactor used to edit
IlvGrapherPin
objects
managed by IlvPinLinkConnector
link connectors.
This interactor must be attached to an IlvManagerView
.
It allows you to do the following:
IlvPinLinkConnector
attached to a node. To do this, click a node.
If a pin link connector is attached to it, its grapher pins
are drawn and the node is selected. If there is no pin link
connector attached to the node, or another type of link
connector is attached, a pin link connector with no pins
is attached to the node. The other editing actions
can be done only once you clicked the node.
IlvGrapherPin.allowsMove()
returns true
, for instance
IlvDefaultGrapherPin
, can be moved. Otherwise, trying to
drag the pin has no effect.
CTRL
key.
CTRL
key.
(See also createGrapherPin(ilog.views.linkconnector.IlvPinLinkConnector, ilog.views.IlvPoint, ilog.views.IlvTransformer)
).
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.
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);
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:
IlvLinkImage
,
IlvGrapher
,
IlvPinLinkConnector
,
IlvGrapherPin
,
IlvDefaultGrapherPin
,
Serialized FormConstructor and Description |
---|
IlvGrapherPinInteractor()
Creates and initializes the interactor.
|
Modifier and Type | Method and Description |
---|---|
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.
|
double |
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 |
setSelectionWhenHighlightingEnabled(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 |
setSelectionWhenHightlightingEnabled(boolean enabled)
Deprecated.
|
void |
setSnapToGridEnabled(boolean snap)
Enables or disables the snapping of the location of the
pins to the grid of the manager view.
|
void |
setSnapToNodeBoxDistance(double 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.
|
addFocusListener, addKeyListener, addMouseListener, addMouseMotionListener, allowEnsureVisible, allowEnsureVisible, disableEvents, drawGhost, enableEvents, ensureVisible, ensureVisible, getManager, getManagerView, getTransformer, handleExpose, isXORGhost, processEvent, processFocusEvent, processKeyEvent, removeFocusListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, setXORGhost
public IlvGrapherPinInteractor()
protected void attach(IlvManagerView view)
attach
in class IlvManagerViewInteractor
view
- The manager view.detach()
protected void detach()
detach
in class IlvManagerViewInteractor
IlvManagerViewInteractor.attach(ilog.views.IlvManagerView)
public final IlvGrapher getGrapher()
protected void processMouseEvent(MouseEvent event)
processMouseEvent
of the superclass is called
after processing the event.processMouseEvent
in class IlvManagerViewInteractor
event
- The event.IlvManagerViewInteractor.addMouseListener(java.awt.event.MouseListener)
protected void processMouseMotionEvent(MouseEvent event)
processMouseMotionEvent
of the superclass is called
after processing the event.processMouseMotionEvent
in class IlvManagerViewInteractor
event
- The event.IlvManagerViewInteractor.addMouseMotionListener(java.awt.event.MouseMotionListener)
public void setPinAdditionModifier(int modifier)
The default modifier is CTRL
.
public int getPinAdditionModifier()
CTRL
.public boolean isPinAdditionModifierDown(MouseEvent event)
getPinAdditionModifier()
.
This is used by the interactor to determine if a click corresponds to
the addition of a pin.
The default modifier is CTRL
.
setPinAdditionModifier(int)
public void setPinRemovalModifier(int modifier)
The default modifier is CTRL
.
public int getPinRemovalModifier()
CTRL
.public boolean isPinRemovalModifierDown(MouseEvent event)
getPinRemovalModifier()
.
This is used by the interactor to determine if a click corresponds to
the removal of a pin.
The default modifier is CTRL
.
setPinRemovalModifier(int)
public void setSnapToNodeBoxModifier(int modifier)
The default modifier is ALT
.
public int getSnapToNodeBoxModifier()
ALT
.public boolean isSnapToNodeBoxModifierDown(MouseEvent event)
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
.
setSnapToNodeBoxModifier(int)
protected IlvRect getSnapBox(IlvGraphic node, IlvTransformer t)
The default implementation returns the bounding box of the
node (node.boundingBox(t)
).
public void setSnapToGridEnabled(boolean snap)
isSnapToGridEnabled()
public boolean isSnapToGridEnabled()
true
if the location of pin
should snapped to the grid of the manager view, and
false
otherwise.setSnapToGridEnabled(boolean)
@Deprecated public void setSelectionWhenHightlightingEnabled(boolean enabled)
setSelectionWhenHightlightingEnabled(boolean)
.public void setSelectionWhenHighlightingEnabled(boolean enabled)
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.
public boolean isSelectionWhenHighlightingEnabled()
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
.
public Cursor getCursor()
public void setCursor(Cursor cursor)
protected void highlight(IlvPinLinkConnector lc, IlvGraphic obj)
isSelectionWhenHighlightingEnabled()
returns true
,
selects the graphic object obj
.lc
- The pin link connector to be edited.obj
- The graphic object associated with the link connector
(a node or a link).protected void unHighlight(IlvPinLinkConnector lc, IlvGraphic obj)
isSelectionWhenHighlightingEnabled()
returns true
,
deselects the graphic object obj
.lc
- The pin link connector that is no longer edited.obj
- The graphic object associated with the link connector
(a node or a link).public final boolean isPinAdditionAllowed()
true
if the interactor lets the user add pins.setPinAdditionAllowed(boolean)
public final void setPinAdditionAllowed(boolean v)
isPinAdditionAllowed()
public final boolean isPinRemovalAllowed()
true
if the interactor lets the user remove pins.setPinRemovalAllowed(boolean)
public final void setPinRemovalAllowed(boolean v)
isPinRemovalAllowed()
public final boolean isPinMoveAllowed()
true
if the interactor lets the user move pins.setPinMoveAllowed(boolean)
public final void setPinMoveAllowed(boolean v)
isPinMoveAllowed()
protected void drawGhost(Graphics g)
drawGhost
in class IlvManagerViewInteractor
g
- The graphics context.
Its current color is already set to the view's default ghost
color, see IlvManagerView.getDefaultGhostColor()
.
Also, in XOR ghost drawing mode, the graphics context is already
set to XOR mode, with the view's default XOR color, see
IlvManagerView.getDefaultXORColor()
.IlvManagerViewInteractor.handleExpose(java.awt.Graphics)
,
IlvManagerViewInteractor.setXORGhost(boolean)
public void setSnapToNodeBoxDistance(double dist)
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.getSnapToNodeBoxDistance()
public double getSnapToNodeBoxDistance()
setSnapToNodeBoxDistance(double)
protected IlvGrapherPin createGrapherPin(IlvPinLinkConnector lc, IlvPoint tp, IlvTransformer t)
lc
and located at the point tp
.
The default implementation creates a new pin of type
IlvDefaultGrapherPin
.
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.protected IlvPinLinkConnector createPinLinkConnector(IlvGraphic node)
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;
node
- The node.© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.