Writing an object interactor
Describes the steps involved in writing an object interactor.
Shows how to write a subclass of an interactor.
Describes how to enable the custom interactor.
Shows how to connect the custom interactor to the diagram.
Writing a subclass of IlvObjectInteractor
The following code example shows an outline of the code in SwitchInteractor to illustrate a typical interactor.
A typical interactor in Java code
public class SwitchInteractor extends ilog.views.IlvObjectInteractor {
/**
* Callback when user clicks a graphic object
* */
public boolean processEvent(IlvGraphic obj,
java.awt.AWTEvent event,
IlvObjectInteractorContext context) {
if (obj.getGraphicBag() instanceof IlvGrapher) {
// find sdm engine
IlvSDMEngine engine = IlvSDMEngine.getSDMEngine(
(IlvGrapher)obj.getGraphicBag());
// find object model
if (engine != null) {
Object modelObject = engine.getObject(obj);
// cast and do whatever is needed here
...
// event has been processed
return true;
}
}
// event has not been processed
return false;
}
}
Enabling a custom interactor
Before you can enable a custom interactor in the style sheet, you must enable the Interactor renderer. You then specify the Interactor graphic property to override the default interactor for the objects in the selector. The following code example shows how to specify an interactor for switchable nodes.
Attaching a custom interactor to an object type in the style sheet
SDM {
Interactor : true;
}
...
node.switchable {
Interactor : ’SwitchInteractor’;
}
NOTE A custom interactor such as SwitchInteractor will not be available in the Designer.
Connecting interactors to diagrams using listeners
In the Designer you can pass the status of a push_state interactor in a node to a Designer property. For information on how to do this, see Linking predefined interactors to parameters in Using the Designer. To customize the application behavior, use a Java™ listener to provoke custom behavior in your application when the node is clicked. The following code sample shows how to do so:
A listener to follow changes in diagram property values
/**
* Listener for user interaction. Assume that in the style sheet
* there is a
* mapping:
* push_state : "@state";
*/
public class ModelListener implements SDMPropertyChangeListener {
/*
* @see ilog.views.sdm.event.SDMPropertyChangeListener#propertyChanged(
* ilog.views.sdm.event.SDMPropertyChangeEvent)
*/
public void propertyChanged(SDMPropertyChangeEvent event) {
String propertyName = event.getPropertyName();
Object target = event.getObject();
String value = event.getNewValue().toString();
if ("state".equals(propertyName)) {
// push interactor has modified the model
// invoke callback
performSomeAction(target, value);
}
}
}
...
//Usage:
IlvDiagrammer diag;
diag = new IlvDiagrammer();
diag.getEngine().getModel().addSDMPropertyChangeListener(new
ModelListener());
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.