public abstract class IlvChartInteractor extends Object implements IlvChart3DSupport, Serializable
Chart interactors should be seen as atomic interactions that can be combined together to build more complex interactions. For example, if you want to be able to zoom the chart using the left mouse button and at the same time be able to pan the chart using the right mouse button :
IlvChartInteractor inter = IlvChartInteractor.create("Zoom"); chart.addInteractor(inter); inter = IlvChartInteractor.create("Pan"); chart.addInteractor(inter); ...A chart handles interactors as a list and process the events to interactors according to decreasing priority order. When an input event is received by the chart (actually the chart area), it is forwarded to all the interactors, until one of them consumes the event. That is, you have to take into account the types of events expected by the interactors and their action keys - in case they overlap - when assigning the priorities. In the sample above, there will be no conflicts between both the interactors due to their default configuration (zoom on the left mouse button, pan on the right mouse button). Since a chart forwards every input events to all of its interactors until one of them handles it (if any), the interactor that handled the event must set it as consumed so that it is no longer forwarded (see
java.awt.AWTEvent.consumed()
).
An interactor is associated with a chart and with a specific y-axis so that interactions performed on the chart using an interactor are only possible on the renderer attached to the same y-axis. It cannot be shared among several charts.
An interaction is defined according to three steps: when the interaction
begins, when the interactions ends, and when the interaction is aborted.
Each of these steps has a corresponding method that can be
overridden to handle the state changes (startOperation(java.awt.event.MouseEvent)
,
endOperation(java.awt.event.MouseEvent)
, abort()
). While writing an interactor class,
the programmer is responsible for defining these different states
calling these callbacks when appropriate.
Interactor classes can be associated with a name (its shortname)
and stored in an internal repository allowing the instantiation of
any known interactor classes by shortcut name (see
create(java.lang.String)
).
For example :
to register your own IlvChartInteractor
subclass into
the repository:
class MyInteractor extends IlvChartInteractor { static { IlvChartInteractor.register("MyInter", MyInteractor.class); } ...
to get a new IlvChartEditPointInteractor
instance by its shortname:
IlvChartInteractor inter = IlvChartInteractor.create("EditPoint");
Interactors can have a localized name. In order to carry a localized name, an interactor class should carry a public static function
public static String getLocalizedName(Locale locale) { ... }
IlvChart.addInteractor(ilog.views.chart.IlvChartInteractor)
,
Serialized FormModifier and Type | Field and Description |
---|---|
static int |
INTERNAL_HIGH
The priority value for high-priority internal interactors.
|
static int |
INTERNAL_LOW
The priority value for low-priority internal interactors.
|
static int |
NORMAL
The default priority value for public interactors.
|
Constructor and Description |
---|
IlvChartInteractor()
Creates a new
IlvChartInteractor object
associated to the y-axis of index 0 , with no action
key. |
IlvChartInteractor(int yAxisIndex,
int buttonOrKeyEventMask)
Creates a new
IlvChartInteractor object associated
to the given y-axis with the specified action key. |
Modifier and Type | Method and Description |
---|---|
protected void |
abort()
Called when the interaction has been aborted.
|
void |
addChartInteractionListener(ChartInteractionListener l)
Adds a new interactor listener.
|
protected void |
chartConnected(IlvChart oldChart,
IlvChart newChart)
Called when an interactor has been added to a chart.
|
static IlvChartInteractor |
create(String interName)
Creates a new interactor object according to a name.
|
static IlvChartInteractor |
create(String interName,
boolean exception)
Creates a new interactor object according to a name.
|
protected void |
disableEvents(long mask)
Removes the given events from the handled events list.
|
protected void |
drawGhost()
Calls drawGhost(java.awt.Graphics).
|
protected void |
drawGhost(Graphics g)
This method may be overridden to do some temporary
drawing during the interaction.
|
protected void |
enableEvents(long mask)
Adds the given events to the handled events list.
|
protected void |
endOperation(MouseEvent event)
Called when the interaction ends.
|
protected void |
fireChartInteractionEvent(ChartInteractionEvent event)
Fires a
ChartInteractionEvent |
long |
getAWTEventMask()
Returns the event mask.
|
IlvChart |
getChart()
Returns the chart on which the interactor has been attached to.
|
IlvCoordinateSystem |
getCoordinateSystem()
Returns the
IlvCoordinateSystem owning the
associated y-axis. |
IlvDoublePoint |
getData(int x,
int y)
Returns the data values corresponding to the specified display
coordinates.
|
IlvDoublePoint |
getData(MouseEvent event)
Returns the data values corresponding to the coordinates of the
specified mouse event.
|
int |
getEventMask()
Returns the action event mask.
|
int |
getEventMaskEx()
Returns the action event mask, according to the conventions of
java.awt.event.InputEvent.getModifiersEx() . |
protected Rectangle |
getGhostBounds()
Returns the ghost bounds.
|
Color |
getGhostColor()
Returns the color used during the ghost drawing operation.
|
static Class<?> |
getInteractorClassByName(String shortName)
Returns the interactor class associated with a given short name.
|
static String |
getLocalizedName(Class<?> interactorClass,
Locale locale)
Returns the localized name of an interactor class in a given locale.
|
int |
getPriority()
Returns the priority of this interactor.
|
static String[] |
getRegisteredInteractorsByName()
Returns all the registered interactor classes using their short name.
|
static String |
getShortName(Class<?> interactorClass)
Returns the short name associated to the given interactor class.
|
IlvAxis |
getXAxis()
Returns the x-axis of the attached chart.
|
Color |
getXORColor()
Returns the XOR color.
|
IlvAxis |
getYAxis()
Returns the associated y-axis.
|
int |
getYAxisIndex()
Returns the associated y-axis index.
|
void |
handleExpose(Graphics g)
Called by the chart when the chart area is drawn.
|
boolean |
has3DSupport()
Indicates whether the interactor can be used with a 3D chart.
|
protected void |
initGhostGraphics(Graphics g)
Initializes the
g according
to the ghost properties. |
void |
interactionStarted(IlvChartInteractor inter,
MouseEvent event)
Called when the given interactor is about to start an interaction
on the given event.
|
boolean |
isAborted()
Returns whether the interactor is in aborted state.
|
protected boolean |
isAllowDrawGhost()
Returns whether a ghost can be drawn.
|
boolean |
isConsumeEvents()
Returns
true if this interactor consumes the events that it has
recognized. |
boolean |
isHandling(int x,
int y)
Returns whether the mouse event that occurred at the specified
location should be handled by the interactor.
|
boolean |
isInOperation()
Returns whether the interactor is in operation state.
|
boolean |
isXORGhost()
Returns whether the interactor draws its ghost in XOR mode.
|
void |
processKeyEvent(KeyEvent event)
Handles a
KeyEvent event. |
void |
processMouseEvent(MouseEvent event)
Handles a mouse event.
|
void |
processMouseMotionEvent(MouseEvent event)
Handles a mouse motion event.
|
protected static void |
register(String shortName,
Class<?> interClass)
Registers the given class with the specified short name
A registered interactor can then be instantiated using its short name.
|
void |
removeChartInteractionListener(ChartInteractionListener l)
Removes
l from the interactor listeners. |
protected void |
setAborted(boolean aborted)
Sets whether the interactor is in aborted state.
|
protected void |
setAllowDrawGhost(boolean allow)
Sets whether a ghost can be drawn.
|
void |
setChart(IlvChart chart)
Called when this interactor is attached to a chart or detached from its
current chart.
|
void |
setConsumeEvents(boolean consume)
Determines whether this interactor should consume the events that it has
recognized.
|
protected Cursor |
setCursor(Cursor cursor)
Sets the current mouse cursor.
|
void |
setEventMask(int actionEventMask)
Sets the action event mask.
|
void |
setGhostColor(Color color)
Sets the color used during the ghost drawing operation.
|
protected void |
setInOperation(boolean ended)
Sets whether the interactor is in operation state.
|
void |
setPriority(int priority)
Sets the priority of this interactor.
|
void |
setXORColor(Color xorColor)
Sets the XOR color.
|
void |
setXORGhost(boolean useXOR)
Sets whether the interactor draws its ghost in XOR mode.
|
void |
setYAxisIndex(int index)
Sets the associated y-axis index.
|
protected void |
startOperation(MouseEvent event)
Called when the interaction starts.
|
IlvDoublePoint |
toDisplay(IlvDoublePoint pt)
Returns the display coordinates corresponding to the specified data
value.
|
public static final int INTERNAL_HIGH
getPriority()
,
Constant Field Valuespublic static final int NORMAL
getPriority()
,
Constant Field Valuespublic static final int INTERNAL_LOW
getPriority()
,
Constant Field Valuespublic IlvChartInteractor()
IlvChartInteractor
object
associated to the y-axis of index 0
, with no action
key.public IlvChartInteractor(int yAxisIndex, int buttonOrKeyEventMask)
IlvChartInteractor
object associated
to the given y-axis with the specified action key.yAxisIndex
- The y-axis index.buttonOrKeyEventMask
- A valid KeyEvent/MouseEvent key/button mask.protected static void register(String shortName, Class<?> interClass)
create(java.lang.String)
public static Class<?> getInteractorClassByName(String shortName)
null
if no class with the given short name is
registered so far.register(java.lang.String, java.lang.Class<?>)
public static String getShortName(Class<?> interactorClass)
null
if no class is found.public static IlvChartInteractor create(String interName)
interName
.
If no class is found, then interName
is supposed to be a class name and the interactor is
created using the Java Reflection mechanism.
Note: The short name of an interactor is put in the registry
when the class of this interactor is loaded. You must thus explicitly
load the class (for example using Class.forName()
)
before using the short name as a parameter to this method.
interName
- The name associated to the interactor
or a full qualified class name.null
if
no corresponding class is found.register(java.lang.String, java.lang.Class<?>)
,
getInteractorClassByName(java.lang.String)
,
create(String,boolean)
public static IlvChartInteractor create(String interName, boolean exception) throws ClassNotFoundException, InstantiationException, IllegalAccessException
interName
- The name of the interactor.exception
- Whether exception should be thrown, or only reported on
the standard error output stream.ClassNotFoundException
InstantiationException
IllegalAccessException
create(String)
public static String[] getRegisteredInteractorsByName()
public static String getLocalizedName(Class<?> interactorClass, Locale locale)
String getLocalizedName(Locale)
, the corresponding short
name is used, if it exists. Otherwise the class name, without package
prefix, is used as a fallback.public final int getPriority()
The framework distinguishes two kinds of interactors:
NORMAL
priority.IlvChart.getInteractors()
) and can have
either an INTERNAL_HIGH
priority (they are processed first
before the user interactors) or INTERNAL_LOW
priority
(they are process last after the user interactors).public void setPriority(int priority)
priority
- The new priority of this interactor. It should be a value
between -1000 and 1000 (exclusive).public final IlvAxis getXAxis()
public final IlvAxis getYAxis()
public final IlvCoordinateSystem getCoordinateSystem()
IlvCoordinateSystem
owning the
associated y-axis.public final IlvChart getChart()
public final void setChart(IlvChart chart)
This method invokes chartConnected(ilog.views.chart.IlvChart, ilog.views.chart.IlvChart)
.
chart
- The chart to which this interactor is being attached to, or
null
when it is being detached.protected void chartConnected(IlvChart oldChart, IlvChart newChart)
oldChart
- The previous attached chart.newChart
- The new attached chart.IlvChart.addInteractor(ilog.views.chart.IlvChartInteractor)
public final long getAWTEventMask()
InputEvent
mask
values.protected final void enableEvents(long mask)
protected final void disableEvents(long mask)
public final boolean isAborted()
protected void setAborted(boolean aborted)
public final boolean isInOperation()
protected void setInOperation(boolean ended)
public final int getYAxisIndex()
public void setYAxisIndex(int index)
public final int getEventMask()
setEventMask(int)
,
getEventMaskEx()
public final int getEventMaskEx()
java.awt.event.InputEvent.getModifiersEx()
. This mask
is computed from getEventMask()
.getEventMask()
,
setEventMask(int)
public void setEventMask(int actionEventMask)
Note: In the mask, InputEvent.BUTTON2_DOWN_MASK
should be used instead of InputEvent.BUTTON2_MASK
, and
InputEvent.BUTTON3_DOWN_MASK
should be used instead of InputEvent.BUTTON3_MASK
,
because the values of ALT_MASK/BUTTON2_MASK
and
META_MASK/BUTTON3_MASK
overlap.
actionEventMask
- A valid KeyEvent/MouseEvent key/button value.public boolean isConsumeEvents()
true
if this interactor consumes the events that it has
recognized.public void setConsumeEvents(boolean consume)
By default, interactors do consume events. Set this to false
if you have several interactors watching out for the same events.
public Color getGhostColor()
public void setGhostColor(Color color)
drawGhost()
public final Color getXORColor()
setXORColor(java.awt.Color)
public void setXORColor(Color xorColor)
Color.black
.protected final boolean isAllowDrawGhost()
false
(nothing to redraw). This property
is used to know if a repaint event should be forwarded
to the active interactor to draw the ghost.protected void setAllowDrawGhost(boolean allow)
public final boolean isXORGhost()
public void setXORGhost(boolean useXOR)
isXORGhost()
protected Rectangle getGhostBounds()
null
, meaning that no ghost is drawn.
Since this method is used to compute the clipping rectangle,
you should override this method if your interactor performs
drawing operations during the interaction.public boolean isHandling(int x, int y)
true
if
the event occurred inside the projection area.
You can override this method to modify the sensitive
area of an interactor.public final IlvDoublePoint getData(MouseEvent event)
public final IlvDoublePoint getData(int x, int y)
public final IlvDoublePoint toDisplay(IlvDoublePoint pt)
public void processMouseEvent(MouseEvent event)
public void processMouseMotionEvent(MouseEvent event)
public void processKeyEvent(KeyEvent event)
KeyEvent
event. When an event is
received by the chart, it is dispatched to all
of its interactors until one of them consumes the
event.public void handleExpose(Graphics g)
g
- The graphic context.drawGhost(java.awt.Graphics)
protected final void drawGhost()
protected void drawGhost(Graphics g)
protected void initGhostGraphics(Graphics g)
g
according
to the ghost properties.public void interactionStarted(IlvChartInteractor inter, MouseEvent event)
protected void startOperation(MouseEvent event)
event
- The event that starts the interaction.interactionStarted(ilog.views.chart.IlvChartInteractor, java.awt.event.MouseEvent)
protected void endOperation(MouseEvent event)
event
- The event that ends the interaction.protected void abort()
protected Cursor setCursor(Cursor cursor)
null
removes the
current cursor and installs the previous one.null
).public final void addChartInteractionListener(ChartInteractionListener l)
public final void removeChartInteractionListener(ChartInteractionListener l)
l
from the interactor listeners.protected final void fireChartInteractionEvent(ChartInteractionEvent event)
ChartInteractionEvent
event
- The event to fire.public boolean has3DSupport()
true
.has3DSupport
in interface IlvChart3DSupport
© Copyright 2024 Rogue Wave Software, Inc., a Perforce company.. All Rights Reserved.