IlpTree
is associated with an IlpDefaultViewInteractor, which should
satisfy most needs. You can retrieve this interactor by calling the
method
getViewInteractor()
.
Tree { interactor: true; } Interactor { viewInteractor: @+viewInt; } Subobject#viewInt { class: 'ilog.cpl.interactor.IlpDefaultViewInteractor'; action[0]: @+viewAction0; } Subobject#viewAction0 { class: 'ilog.cpl.interactor.IlpGestureAction'; gesture: BUTTON3_CLICKED; action: @+myAction; } Subobject#myAction { class: MyAction; }
IlpTree tree = // ... // Retrieve the view interactor IlpViewInteractor viewInteractor = tree.getViewInteractor(); // Create an action Action myAction = new MyAction(); // Clicking the 3rd mouse button will trigger myAction viewInteractor.setGestureAction(IlpGesture.BUTTON3_CLICKED,myAction);
IlpObject
by means of the following code (which should be in the
MyAction
class).
// Implementation of the ActionListener interface public void actionPerformed(ActionEvent e) { // JTGO interactors use IlpViewActionEvent IlpViewActionEvent viewEvent = (IlpViewActionEvent)e; // Get the IlpObject (if any) where the interaction occurred IlpObject ilpObj = viewEvent.getIlpObject(); // Perform operation on the given object }
Tree { interactor: true; } Interactor { viewInteractor: @+viewInt; } Subobject#viewInt { class: 'ilog.cpl.interactor.IlpDefaultViewInteractor'; action[0]: @+viewAction0; } Subobject#viewAction0 { class: 'ilog.cpl.interactor.IlpKeyStrokeAction'; keyStroke: 'typed D'; action: @+myAction; } Subobject#myAction { class: MyAction; }
// Create an action Action myAction = new MyAction(); // Typing CTRL+D will trigger myAction viewInteractor.setKeyStrokeAction( KeyStroke.getKeyStroke('D',java.awt.Event.CTRL_MASK),myAction);
Tree { interactor: true; } Interactor { viewInteractor: @+viewInt; } Subobject#viewInt { class: 'ilog.cpl.interactor.IlpDefaultViewInteractor'; popupMenuFactory: @+viewPopupMenuFactory; } Subobject#viewPopupMenuFactory { class: MyPopupMenuFactory; }
// Subclass IlpAbstractPopupMenuFactory, which has useful shortcuts IlpPopupMenuFactory popupMenuFactory = new IlpAbstractPopupMenuFactory(){ // Add the identifier of each of the selected objects to the menu public JPopupMenu createPopupMenu (IlpObjectSelectionModel ilpSelectionModel) { // Create an empty popup menu JPopupMenu menu = new JPopupMenu(); // Access the selected objects from the selection model Collection selectedObjects = ilpSelectionModel.getSelectedObjects(); // fill the menu according to the current selection return menu; } };
// Set the popup menu factory to the view interactor viewInteractor.setPopupMenuFactory(popupMenuFactory);