public abstract class IlvObjectInteractor extends Object implements Serializable
Interactors are objects that define user actions.
For example, how a graphic object will move when it is dragged
by a user, or how panning a manager view is performed.
The interactive behavior is controlled either by using view
interactors
(IlvManagerViewInteractor
and
subclasses) associated to the entire manager view or by object interactors
(IlvObjectInteractor
and subclasses)
associated to each individual graphic object.
When an event is received by a manager view that has no associated view
interactor, the event is dispatched to the manager (see
IlvManagerView.processEvent(AWTEvent)
and
IlvManager.processEvent(AWTEvent, IlvManagerView)
).
The manager attempts to send it to the object interactor of the graphic
object located at the mouse position.
To associate a specific behavior to a graphic object, you use an object
interactor, that is, an subclass of IlvObjectInteractor
.
The event dispatched by the manager is processed by the
method processEvent(IlvGraphic, AWTEvent, IlvObjectInteractorContext)
.
An object interactor can be associated to every object in a manager, and
several objects can share the same object interactor.
To attach an interactor to a graphic object, create an
IlvObjectInteractor
instance, then bind it to one or more
graphic objects using the method
IlvGraphic.setObjectInteractor(IlvObjectInteractor)
.
It is the interactor, and not the graphic object, that manages user events
and deals with them.
The following code example shows how to set a custom object interactor for a graphic object:
IlvManager mgr = new IlvManager(); // 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); // Create your custom object interactor (a subclass of IlvObjectInteractor). IlvObjectInteractor myInter = new MyObjectInteractor(); // Set this interactor on obj2 only. obj2.setObjectInteractor(myInter);
For information about how to treat events in a manager, see Handling Events. The following code examples show how to handle user events:
Modifier | Constructor and Description |
---|---|
protected |
IlvObjectInteractor()
Creates a new
IlvObjectInteractor . |
Modifier and Type | Method and Description |
---|---|
static IlvObjectInteractor |
Get(String name)
Returns an object interactor.
|
void |
handleExpose(IlvGraphic obj,
Graphics g,
IlvObjectInteractorContext context)
Called by the view when the view is drawn.
|
void |
onEnter(IlvGraphic obj,
IlvObjectInteractorContext context)
Called when the object that has this interactor is entered.
|
void |
onExit(IlvGraphic obj,
IlvObjectInteractorContext context)
Called when the object that has this interactor is exited.
|
abstract boolean |
processEvent(IlvGraphic obj,
AWTEvent event,
IlvObjectInteractorContext context)
Processes the events.
|
static void |
Put(String name,
IlvObjectInteractor inter)
Registers an object interactor.
|
protected IlvObjectInteractor()
IlvObjectInteractor
.public abstract boolean processEvent(IlvGraphic obj, AWTEvent event, IlvObjectInteractorContext context)
obj
- The graphic object.event
- The event to process.context
- The context in which the event occurred.true
if the event was handled
by this processEvent
invocation,
false
otherwise.public void handleExpose(IlvGraphic obj, Graphics g, IlvObjectInteractorContext context)
The default implementation does nothing.
obj
- The graphic object to which the object interactor is associated.g
- The Graphics
where obj
is drawn.context
- The interactor context.public void onEnter(IlvGraphic obj, IlvObjectInteractorContext context)
Subclasses can override this method to perform specific tasks when the object is entered. The default implementation does nothing.
obj
- The object.context
- The context for the object interactor.IlvSelection.onEnter(ilog.views.IlvObjectInteractorContext)
public void onExit(IlvGraphic obj, IlvObjectInteractorContext context)
Subclasses can override this method to perform specific tasks when the object is entered. The default implementation does nothing.
obj
- The object.context
- The context for the object interactor.IlvSelection.onExit(ilog.views.IlvObjectInteractorContext)
public static IlvObjectInteractor Get(String name)
name
- The fully qualified class name of the interactor
(for instance, "mypackage.MyObjectInteractor").null
if no such interactor
can be created.public static void Put(String name, IlvObjectInteractor inter)
Get(java.lang.String)
, the stored object interactor is returned.name
- The fully qualified class name of the interactor
(for instance, "mypackage.MyObjectInteractor").inter
- The interactor instance.© Copyright 2024 Rogue Wave Software, Inc., a Perforce company.. All Rights Reserved.