ilog.views
Class IlvManagerViewInteractor

java.lang.Object
  extended by ilog.views.IlvManagerViewInteractor
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
IlvConnectInteractor, IlvContinuousZoomInteractor, IlvDragRectangleInteractor, IlvEditLabelInteractor, IlvGrapherPinInteractor, IlvMagnifyInteractor, IlvMakePolyPointsInteractor, IlvMakeSDMNodeInteractor, IlvManagerMagViewInteractor, IlvManagerViewRotateInteractor, IlvMoveRectangleInteractor, IlvPanInteractor, IlvRotateInteractor, IlvSeeThroughInteractor, IlvSelectInteractor

public class IlvManagerViewInteractor
extends Object
implements Serializable

IlvManagerViewInteractor is the base class for all interactors that can be attached to a manager view. Extend this class to make a custom global interactor.

Overview

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 globally or locally. Global, or view interactors are instances of IlvManagerViewInteractor and its subclasses. They are associated to the entire manager view. Local, or object interactors are instances of IlvObjectInteractor and its subclasses. They are associated to each individual graphic object.

For your application to respond to global user actions, you associate an IlvManagerViewInteractor instance with each view by calling IlvManagerView.setInteractor(IlvManagerViewInteractor). The interactor object handles events that are received by that particular view. If the manager does not have an interactor object associated with a view, events are handled by the IlvObjectInteractor instance associated with the graphic object that received the event.

Setting a View Interactor

In a manager view, only one interactor at a time is active. The following code example shows how to combine an IlvSelectInteractor instance with a delete accelerator so a user can delete graphic objects in the manager by selecting the object using the mouse and pressing the delete key.

   IlvManagerViewInteractor inter = new IlvSelectInteractor();
   inter.setOpaqueMove(false);
   mgrview.setInteractor(inter);
   manager.addAccelerator(new 
     IlvDeleteSelectionAccelerator(KeyEvent.KEY_PRESSED, KeyEvent.VK_DELETE, 0));
 

Custom View Interactors

The following UML diagram shows the custom view interactors supplied by the ILOG JViews Graphics Framework:

Example

The following code example shows you how to activate different interactors when the user clicks on different JButton objects. It also shows how to use a listener to update the user interface so the user is aware of the currently active interactor. (Notice that the IlvManagerViewControlBar provides this functionality out-of-the-box.)

   IlvManager manager;
   IlvManagerView mgrview;
   IlvManagerViewInteractor magInter, selectInteractor;
   JButton selectButton, magButton;
     
   void createButtons()
   {
     JPanel buttons = new JPanel();
     // A button to install a select interactor.
     selectButton = new JButton("Select");
     selectButton.setBackground(Color.gray);
     selectButton.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent evt) {
         if (selectInteractor == null)
           selectInteractor = new IlvSelectInteractor();
         if (mgrview.getInteractor() != selectInteractor)
           mgrview.setInteractor(selectInteractor);
       }
     });
     buttons.add(selectButton);
   
     // A button to install the magnify interactor.
     magButton = new JButton("Magnify");
     magButton.setBackground(Color.gray);
     magButton.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent evt) {
         if (magInter == null)
           magInter = new IlvMagnifyInteractor();
         if (mgrview.getInteractor() != magInter)
           mgrview.setInteractor(magInter);
      }
     });
     buttons.add(magButton);
     getContentPane().add(buttons, BorderLayout.SOUTH);
  }
    
  public void interactorChanged(InteractorChangedEvent event)
  {
    IlvManagerViewInteractor oldI = event.getOldValue();
    IlvManagerViewInteractor newI = event.getNewValue();
    
    if (oldI == selectInteractor)
      selectButton.setBackground(Color.gray);
    else if (oldI == magInter)
      magButton.setBackground(Color.gray);
    // there is no new interactor
    if (newI == null)
      return;
    if (newI == selectInteractor)
      selectButton.setBackground(Color.red);
    else if (newI == magInter)
      magButton.setBackground(Color.red);
  }
    
  public interactorExample()
  {
    // create the manager
    manager = new IlvManager();
    // creates a view associated to the manager
    mgrview = new IlvManagerView(manager);
    mgrview.setBackground(Color.white);
    
    IlvGraphic obj;
    obj = new IlvRectangle(new IlvRect(60,30,50,50), false, true);
    manager.addObject(obj, false);
    obj = new IlvRectangle(new IlvRect(140,50,10,10), false, true);
    manager.addObject(obj, false);
    
    getContentPane().setLayout(new BorderLayout(0,0));
    getContentPane().add(new IlvJScrollManagerView(mgrview), 
                       BorderLayout.CENTER);
    
    createButtons();
    // listens to interactor modification
    mgrview.addInteractorListener(this);
  }
 

The following image shows the magnifier interactor used in the code example:

About Interactors and Accelerators

For information about how to treat events in a manager, see Handling Events. The following code examples show how to handle user events:

See Also:
IlvManagerView.pushInteractor(ilog.views.IlvManagerViewInteractor, java.awt.AWTEvent), IlvManagerView.popInteractor(), Serialized Form

Constructor Summary
IlvManagerViewInteractor()
          Creates a new interactor.
 
Method Summary
 void addFocusListener(FocusListener l)
          Adds a listener on focus events.
 void addKeyListener(KeyListener l)
          Adds a listener on key events.
 void addMouseListener(MouseListener l)
          Adds a listener on mouse events.
 void addMouseMotionListener(MouseMotionListener l)
          Adds a listener on mouse motion events.
 boolean allowEnsureVisible()
          Returns true if the method ensureVisible really calls ensureVisible in the view, otherwise it returns false.
 void allowEnsureVisible(boolean v)
          Allows or inhibits the ensureVisible method.
protected  void attach(IlvManagerView v)
          Called when the interactor is attached to the manager view.
protected  void detach()
          Called when the interactor is detached from the view.
protected  void disableEvents(long eventsToDisable)
          Disables the events defined by the specified event mask parameter from being delivered to this interactor.
protected  void drawGhost()
          Calls drawGhost(getManagerView().getGraphics()).
protected  void drawGhost(Graphics g)
          Draws the ghost.
protected  void enableEvents(long eventsToEnable)
          Enables the events defined by the specified event mask parameter to be delivered to this interactor.
 void ensureVisible(IlvPoint p)
          Calls IlvManagerView.ensureVisible if allowEnsureVisible returns true, otherwise it does nothing.
 void ensureVisible(IlvRect rect)
          Calls IlvManagerView.ensureVisible if allowEnsureVisible returns true, otherwise it does nothing.
 IlvManager getManager()
          Returns the manager corresponding to the view to which the interactor is attached.
 IlvManagerView getManagerView()
          Returns the manager view when the interactor is attached, or null if the interactor is not attached.
 IlvTransformer getTransformer()
          Returns the transformer of the view when the interactor is attached, or null if the interactor is not attached.
protected  void handleExpose(Graphics g)
          Called by the view when the view is drawn.
 boolean isXORGhost()
          Returns the ghost drawing mode.
protected  void processEvent(AWTEvent evt)
          Processes the events.
protected  void processFocusEvent(FocusEvent e)
          Processes the focus events.
protected  void processKeyEvent(KeyEvent e)
          Processes the key events.
protected  void processMouseEvent(MouseEvent e)
          Processes the mouse events.
protected  void processMouseMotionEvent(MouseEvent e)
          Processes the mouse moved and mouse dragged events.
 void removeFocusListener(FocusListener l)
          Removes a listener on focus events.
 void removeKeyListener(KeyListener l)
          Removes a listener on key events.
 void removeMouseListener(MouseListener l)
          Removes a listener on mouse events.
 void removeMouseMotionListener(MouseMotionListener l)
          Removes a listener on mouse motion events.
 void setXORGhost(boolean xorGhost)
          Sets the ghost drawing mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IlvManagerViewInteractor

public IlvManagerViewInteractor()
Creates a new interactor.

See Also:
IlvManagerView.pushInteractor(ilog.views.IlvManagerViewInteractor, java.awt.AWTEvent), IlvManagerView.popInteractor()
Method Detail

attach

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

Parameters:
v - The manager view.
See Also:
detach()

detach

protected void detach()
Called when the interactor is detached from the view.

See Also:
attach(ilog.views.IlvManagerView)

getManagerView

public final IlvManagerView getManagerView()
Returns the manager view when the interactor is attached, or null if the interactor is not attached.


getTransformer

public final IlvTransformer getTransformer()
Returns the transformer of the view when the interactor is attached, or null if the interactor is not attached.


getManager

public final IlvManager getManager()
Returns the manager corresponding to the view to which the interactor is attached.


processEvent

protected void processEvent(AWTEvent evt)
Processes the events. This method calls the following methods depending on the event type: processMouseMotionEvent, processMouseEvent, processKeyEvent, processFocusEvent. Note that the methods will be called only if a listener has been added for the type of event or if the handling of the event has been enabled with enableEvents.

Parameters:
evt - The event.
See Also:
processMouseMotionEvent(java.awt.event.MouseEvent), processMouseEvent(java.awt.event.MouseEvent), processKeyEvent(java.awt.event.KeyEvent), processFocusEvent(java.awt.event.FocusEvent)

processFocusEvent

protected void processFocusEvent(FocusEvent e)
Processes the focus events. The method dispatches the event to the FocusListener registered with this interactor (if any).

Parameters:
e - The event.
See Also:
addFocusListener(java.awt.event.FocusListener)

processKeyEvent

protected void processKeyEvent(KeyEvent e)
Processes the key events. The method dispatches the event to the KeyListener registered with this interactor (if any).

Parameters:
e - The event.
See Also:
addKeyListener(java.awt.event.KeyListener)

processMouseEvent

protected void processMouseEvent(MouseEvent e)
Processes the mouse events. The method dispatches the event to the MouseListener registered with this interactor (if any).

Parameters:
e - The event.
See Also:
addMouseListener(java.awt.event.MouseListener)

processMouseMotionEvent

protected void processMouseMotionEvent(MouseEvent e)
Processes the mouse moved and mouse dragged events. The method dispatches the event to the MouseMotionListener registered with this interactor (if any).

Parameters:
e - The event.
See Also:
addMouseMotionListener(java.awt.event.MouseMotionListener)

addFocusListener

public void addFocusListener(FocusListener l)
Adds a listener on focus events.

Parameters:
l - The listener.

removeFocusListener

public void removeFocusListener(FocusListener l)
Removes a listener on focus events.

Parameters:
l - The listener.

addKeyListener

public void addKeyListener(KeyListener l)
Adds a listener on key events.

Parameters:
l - The listener.

removeKeyListener

public void removeKeyListener(KeyListener l)
Removes a listener on key events.

Parameters:
l - The listener.

addMouseListener

public void addMouseListener(MouseListener l)
Adds a listener on mouse events.

Parameters:
l - The listener.

removeMouseListener

public void removeMouseListener(MouseListener l)
Removes a listener on mouse events.

Parameters:
l - The listener.

addMouseMotionListener

public void addMouseMotionListener(MouseMotionListener l)
Adds a listener on mouse motion events.

Parameters:
l - The listener.

removeMouseMotionListener

public void removeMouseMotionListener(MouseMotionListener l)
Removes a listener on mouse motion events.

Parameters:
l - The listener.

enableEvents

protected final void enableEvents(long eventsToEnable)
Enables the events defined by the specified event mask parameter to be delivered to this interactor. Event types are automatically enabled when a listener for that type is added to the interactor. So, this method just needs to be invoked by the subclasses of an interactor that requires specified event types to be delivered to processEvent regardless of whether a listener is registered or not.

Parameters:
eventsToEnable - The event mask parameter.

disableEvents

protected final void disableEvents(long eventsToDisable)
Disables the events defined by the specified event mask parameter from being delivered to this interactor.

Parameters:
eventsToDisable - The event mask parameter.

setXORGhost

public void setXORGhost(boolean xorGhost)
Sets the ghost drawing mode. If xorGhost is true, the ghost should be drawn in XOR Ghost mode, otherwise in Paint mode. The default value is true.

Note that for some subclasses a given XOR mode may be mandatory. Such subclasses may override the method isXORGhost().

Parameters:
xorGhost - true to set XOR mode, false to set Paint mode.
Since:
JViews 5.0
See Also:
isXORGhost(), handleExpose(java.awt.Graphics), drawGhost(java.awt.Graphics)

isXORGhost

public boolean isXORGhost()
Returns the ghost drawing mode. The default value is true.

Note that this method is overridden by some subclasses for which a given XOR mode is mandatory.

Returns:
true if the drawing of the ghost will be performed in XOR Ghost mode, or false if it is in Paint mode.
Since:
JViews 5.0
See Also:
setXORGhost(boolean), handleExpose(java.awt.Graphics), drawGhost(java.awt.Graphics)

handleExpose

protected void handleExpose(Graphics g)
Called by the view when the view is drawn. This method calls the method drawGhost(java.awt.Graphics). If the interactor is in XOR Ghost drawing mode, the default XOR color of the view is set on the Graphics before calling drawGhost(Graphics).

Parameters:
g - The graphics.
See Also:
drawGhost(java.awt.Graphics), isXORGhost(), IlvManagerView.getDefaultXORColor()

drawGhost

protected void drawGhost(Graphics g)
Draws the ghost. The default implementation does nothing. The method can be overridden to do temporary drawing when the interactor is working.

Parameters:
g - The graphics.
See Also:
handleExpose(java.awt.Graphics), setXORGhost(boolean)

drawGhost

protected final void drawGhost()
Calls drawGhost(getManagerView().getGraphics()).


ensureVisible

public void ensureVisible(IlvPoint p)
Calls IlvManagerView.ensureVisible if allowEnsureVisible returns true, otherwise it does nothing.

See Also:
allowEnsureVisible()

ensureVisible

public void ensureVisible(IlvRect rect)
Calls IlvManagerView.ensureVisible if allowEnsureVisible returns true, otherwise it does nothing.

See Also:
allowEnsureVisible()

allowEnsureVisible

public final boolean allowEnsureVisible()
Returns true if the method ensureVisible really calls ensureVisible in the view, otherwise it returns false.

See Also:
ensureVisible(ilog.views.IlvPoint)

allowEnsureVisible

public final void allowEnsureVisible(boolean v)
Allows or inhibits the ensureVisible method.

Parameters:
v - Set true to allow the ensureVisible method, false otherwise.
See Also:
ensureVisible(ilog.views.IlvPoint)


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