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.
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.
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));
The following UML diagram shows the custom view interactors supplied by the Rogue Wave JViews Graphics Framework:
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:
For information about how to treat events in a manager, see Handling Events. The following code examples show how to handle user events:
Constructor and Description |
---|
IlvManagerViewInteractor()
Creates a new interactor.
|
Modifier and Type | Method and Description |
---|---|
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.
|
public IlvManagerViewInteractor()
protected void attach(IlvManagerView v)
v
- The manager view.detach()
protected void detach()
attach(ilog.views.IlvManagerView)
public final IlvManagerView getManagerView()
null
if the interactor is not attached.public final IlvTransformer getTransformer()
null
if the interactor is not attached.public final IlvManager getManager()
protected void processEvent(AWTEvent evt)
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
.evt
- The event.processMouseMotionEvent(java.awt.event.MouseEvent)
,
processMouseEvent(java.awt.event.MouseEvent)
,
processKeyEvent(java.awt.event.KeyEvent)
,
processFocusEvent(java.awt.event.FocusEvent)
protected void processFocusEvent(FocusEvent e)
FocusListener
registered with this interactor (if any).e
- The event.addFocusListener(java.awt.event.FocusListener)
protected void processKeyEvent(KeyEvent e)
KeyListener
registered with this interactor (if any).e
- The event.addKeyListener(java.awt.event.KeyListener)
protected void processMouseEvent(MouseEvent e)
MouseListener
registered with this interactor (if any).e
- The event.addMouseListener(java.awt.event.MouseListener)
protected void processMouseMotionEvent(MouseEvent e)
MouseMotionListener
registered with this interactor (if any).e
- The event.addMouseMotionListener(java.awt.event.MouseMotionListener)
public void addFocusListener(FocusListener l)
l
- The listener.public void removeFocusListener(FocusListener l)
l
- The listener.public void addKeyListener(KeyListener l)
l
- The listener.public void removeKeyListener(KeyListener l)
l
- The listener.public void addMouseListener(MouseListener l)
l
- The listener.public void removeMouseListener(MouseListener l)
l
- The listener.public void addMouseMotionListener(MouseMotionListener l)
l
- The listener.public void removeMouseMotionListener(MouseMotionListener l)
l
- The listener.protected final void enableEvents(long eventsToEnable)
processEvent
regardless of whether a listener is
registered or not.eventsToEnable
- The event mask parameter.protected final void disableEvents(long eventsToDisable)
eventsToDisable
- The event mask parameter.public void setXORGhost(boolean xorGhost)
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()
.
xorGhost
- true
to set XOR mode, false
to
set Paint
mode.isXORGhost()
,
handleExpose(java.awt.Graphics)
,
drawGhost(java.awt.Graphics)
public boolean isXORGhost()
true
.
Note that this method is overridden by some subclasses for which a given XOR mode is mandatory.
true
if the drawing of the ghost will be
performed in XOR Ghost mode, or false
if it is in Paint mode.setXORGhost(boolean)
,
handleExpose(java.awt.Graphics)
,
drawGhost(java.awt.Graphics)
protected void handleExpose(Graphics g)
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)
.g
- The graphics.drawGhost(java.awt.Graphics)
,
isXORGhost()
,
IlvManagerView.getDefaultXORColor()
protected void drawGhost(Graphics g)
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()
.handleExpose(java.awt.Graphics)
,
setXORGhost(boolean)
protected final void drawGhost()
drawGhost(getManagerView().getGraphics())
.public void ensureVisible(IlvPoint p)
IlvManagerView.ensureVisible
if allowEnsureVisible
returns true
, otherwise it
does nothing.allowEnsureVisible()
public void ensureVisible(IlvRect rect)
IlvManagerView.ensureVisible
if allowEnsureVisible
returns true
, otherwise it
does nothing.allowEnsureVisible()
public final boolean allowEnsureVisible()
true
if the method ensureVisible
really calls ensureVisible
in the view, otherwise it
returns false
.ensureVisible(ilog.views.IlvPoint)
public final void allowEnsureVisible(boolean v)
ensureVisible
method.v
- Set true
to allow the ensureVisible
method, false
otherwise.ensureVisible(ilog.views.IlvPoint)
© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.