public abstract class AbstractContextMenuInputMode<TContextMenu> extends Object implements IInputMode
IInputMode
interface that will display a ContextMenu
when the user right clicks
on the CanvasControl
.
The methods showMenu
, hideMenu(Object)
hideMenu} as well as the
MenuClosedCallback
are used to communicate to this instance whenever the context menu should be opened or closed.
The methods isMenuEmpty
and clearMenu(Object)
are used when the menu is
initialized and one can register a callback to the PopulateMenu
event
to customize the contents of the menu strip depending on the coordinate in the world
coordinate system where the menu strip has been opened.
This mode is Exclusive
by default.
Constructor and Description |
---|
AbstractContextMenuInputMode()
Creates a new instance with no initial context menu.
|
AbstractContextMenuInputMode(TContextMenu menu)
Creates a new instance using the provided menu.
|
Modifier and Type | Method and Description |
---|---|
void |
addPopulateMenuListener(IEventHandler<PopulateMenuEventArgs> populateMenuEvent)
Adds the given listener for the
PopulateMenu event that occurs when the context menu is about to be shown. |
void |
cancel()
Makes the menu invisible.
|
protected abstract void |
clearMenu(TContextMenu menu)
Clears all items of the given popup menu.
|
protected abstract TContextMenu |
createMenu()
Creates a new instance of the popup menu.
|
protected IInputModeContext |
createPopulateMenuContext()
Creates an
IInputModeContext for use with the PopulateMenu call
in the upcoming query. |
protected ConcurrencyController |
getController()
Gets the installed
ConcurrencyController . |
IInputModeContext |
getInputModeContext()
Returns the context instance this mode is currently installed in or
null if this instance is not installed. |
TContextMenu |
getMenu()
Gets the menu to show.
|
int |
getPriority()
The priority of this input mode.
|
IHitTestable |
getValidMenuLocationHitTestable()
Gets an
IHitTestable that determines whether it is valid to open a context menu at the queried position. |
protected abstract void |
hideMenu(TContextMenu menu)
Hides the given popup menu.
|
void |
install(IInputModeContext context,
ConcurrencyController controller)
Installs this mode in the canvas.
|
boolean |
isEnabled()
Gets the enabled state of this input mode.
|
boolean |
isExclusive()
Gets a value indicating whether this mode will be the only one running when it has the mutex.
|
boolean |
isMenuClearingEnabled()
Gets a value indicating whether to clear
Menu 's items
before the PopulateMenu event is triggered. |
protected abstract boolean |
isMenuEmpty(TContextMenu menu)
Indicates whether the given popup menu does not have any items.
|
protected void |
onCanceled()
Called after
cancel() has been called. |
protected void |
onConcurrencyControllerActivated()
|
protected void |
onConcurrencyControllerDeactivated()
|
protected void |
onPopulateMenu(PopulateMenuEventArgs args)
Raises the
PopulateMenu event. |
protected boolean |
onPopulateMenu(TContextMenu menu,
PointD location,
EventSource eventSource)
This will populate the context menu for the given world coordinate.
|
protected void |
onStopped()
Called after
stop() has been called. |
void |
removePopulateMenuListener(IEventHandler<PopulateMenuEventArgs> populateMenuEvent)
Removes the given listener for the
PopulateMenu event that occurs when the context menu is about to be shown. |
void |
setEnabled(boolean value)
Sets the enabled state of this input mode.
|
void |
setExclusive(boolean value)
Sets a value indicating whether this mode will be the only one running when it has the mutex.
|
void |
setMenu(TContextMenu value)
Sets the menu to show.
|
void |
setMenuClearingEnabled(boolean value)
|
protected abstract void |
setMenuClosedCallback(TContextMenu menu,
Runnable menuClosedCallback)
Defines or removes a function to be called when the given popup menu has been closed.
|
void |
setPriority(int value)
The priority of this input mode.
|
void |
setValidMenuLocationHitTestable(IHitTestable value)
Sets an
IHitTestable that determines whether it is valid to open a context menu at the queried position. |
protected abstract void |
showMenu(TContextMenu menu,
PointD viewLocation)
Shows the given popup menu at the given location in view coordinates.
|
boolean |
stop()
Makes the menu invisible.
|
void |
uninstall(IInputModeContext context)
Removes the menu from the context and replaces it with the old instance.
|
public AbstractContextMenuInputMode()
createMenu()
,
getMenu()
public AbstractContextMenuInputMode(TContextMenu menu)
menu
- The menu to show.public final void addPopulateMenuListener(IEventHandler<PopulateMenuEventArgs> populateMenuEvent)
PopulateMenu
event that occurs when the context menu is about to be shown.
Handlers of the event can populate the Menu
, set the ShowingMenuRequested
and set or respect the Handled
property. Note that all handlers will be
called, even if one of them sets the Handled
property to
true
. Every handler should query this property and decide carefully what to do.
populateMenuEvent
- The listener to add.removePopulateMenuListener(IEventHandler)
public void cancel()
cancel
in interface IInputMode
protected abstract void clearMenu(TContextMenu menu)
Subclasses have to implement this method for the given framework specific popup menu instance that has been
created by createMenu()
. Whenever yFiles framework needs to clear a popup menu and
isMenuClearingEnabled()
returns true
this method for GUI framework specific removal of menu
items is called.
menu
- the framework specific popup menu to remove the items fromprotected abstract TContextMenu createMenu()
Subclasses have to create the framework specific popup menu instance here. The other abstract methods of this class need to be able to handle popup menu instances created by this method.
showMenu(Object, com.yworks.yfiles.geometry.PointD)
,
hideMenu(Object)
,
clearMenu(Object)
,
isMenuEmpty(Object)
protected IInputModeContext createPopulateMenuContext()
IInputModeContext
for use with the PopulateMenu
call
in the upcoming query.IInputModeContext
.protected final ConcurrencyController getController()
ConcurrencyController
.public final IInputModeContext getInputModeContext()
IInputMode
null
if this instance is not installed.
Note that this instance should not be passed down to subordinate modes or instances. Instead a corresponding context
that has this instance set as the ParentInputMode
should be used.
getInputModeContext
in interface IInputMode
public final TContextMenu getMenu()
If no menu has been configured with this instance this will create the menu using the createMenu()
callback.
#setMenu(ContextMenu)
public final int getPriority()
IInputMode
The priority will influence the order in which the modes will be installed
into the canvas control. The lower the priority value, the earlier it will be installed. If two modes are installed
using the same priority value, the first one will be installed earlier.
getPriority
in interface IInputMode
public final IHitTestable getValidMenuLocationHitTestable()
IHitTestable
that determines whether it is valid to open a context menu at the queried position.
If the instance yields false
#onMenuOpening(ContextMenu, PointD, EventSource)
will not be queried and
the context menu will not be shown. By default there is a hit testable instance that always yields true
.
setValidMenuLocationHitTestable(IHitTestable)
protected abstract void hideMenu(TContextMenu menu)
Subclasses have to implement this method for the given framework specific popup menu instance that has been
created by createMenu()
. Whenever yFiles framework needs to hide a popup menu this method for GUI
framework specific hiding of popup menus is called.
menu
- the framework specific popup menu to hidepublic void install(IInputModeContext context, ConcurrencyController controller)
install
in interface IInputMode
context
- The context to install this mode into.controller
- The Controller
for this mode.IInputMode.uninstall(IInputModeContext)
public boolean isEnabled()
Clients can use this property to disable or reenable this instance. This will set the Enabled
property of the installed Controller
so a disabled instance should never try to acquire the
input mutex.
setEnabled(boolean)
public final boolean isExclusive()
The value of this property will be delegated to the Exclusive
property of
the Controller
.
If this mode is marked as exclusive and has the mutex, all other modes added
to the same MultiplexingInputMode
will be deactivated. Otherwise it will always run
concurrently with all other modes.
setExclusive(boolean)
public final boolean isMenuClearingEnabled()
Menu
's items
before the PopulateMenu
event is triggered.true
(the default value) if the context menu should be cleared before the query; false
otherwise.setMenuClearingEnabled(boolean)
protected abstract boolean isMenuEmpty(TContextMenu menu)
Subclasses have to implement this method for the given framework specific popup menu instance that has been
created by createMenu()
. Whenever yFiles input framework needs to know if a popup menu does not have
any items this method for GUI framework specific query is called.
menu
- the framework specific popup menu to to check for itemstrue
if the given popup menu does not have any items; false
otherwiseprotected void onCanceled()
cancel()
has been called.
Can be overridden in subclasses to perform additional actions after the mode has been canceled.
This implementation does nothing.
protected void onConcurrencyControllerActivated()
Active
property of the installed ConcurrencyController
has been set to true
.
Can be overridden in subclasses to perform additional actions after the mode has been activated.
Overriding implementations should call the base implementation.
protected void onConcurrencyControllerDeactivated()
Active
property of the installed ConcurrencyController
has been set to false
.
Can be overridden in subclasses to perform additional actions after the mode has been deactivated.
Overriding implementations should call the base implementation.
protected void onPopulateMenu(PopulateMenuEventArgs args)
PopulateMenu
event.args
- The PopulateMenuEventArgs
instance containing the event data.protected boolean onPopulateMenu(TContextMenu menu, PointD location, EventSource eventSource)
This implementation will trigger the PopulateMenu
event and will use the
ShowingMenuRequested
value as the return value. If the event
will not be handled, this method will return true
if the menu already contains elements.
menu
- The menu to optionally populate with items.location
- The location in the world coordinate system for which the context menu has been invoked.eventSource
- The source of the context menu event.protected void onStopped()
stop()
has been called.
Can be overridden in subclasses to perform additional actions after the mode has been stopped.
This implementation does nothing.
public final void removePopulateMenuListener(IEventHandler<PopulateMenuEventArgs> populateMenuEvent)
PopulateMenu
event that occurs when the context menu is about to be shown.
Handlers of the event can populate the Menu
, set the ShowingMenuRequested
and set or respect the Handled
property. Note that all handlers will be
called, even if one of them sets the Handled
property to
true
. Every handler should query this property and decide carefully what to do.
populateMenuEvent
- The listener to remove.addPopulateMenuListener(IEventHandler)
public void setEnabled(boolean value)
Clients can use this property to disable or reenable this instance. This will set the Enabled
property of the installed Controller
so a disabled instance should never try to acquire the
input mutex.
value
- The Enabled to set.isEnabled()
public final void setExclusive(boolean value)
The value of this property will be delegated to the Exclusive
property of
the Controller
.
If this mode is marked as exclusive and has the mutex, all other modes added
to the same MultiplexingInputMode
will be deactivated. Otherwise it will always run
concurrently with all other modes.
value
- The Exclusive to set.isExclusive()
public final void setMenu(TContextMenu value)
If no menu has been configured with this instance this will create the menu using the createMenu()
callback.
value
- The Menu to set.getMenu()
public final void setMenuClearingEnabled(boolean value)
value
- true
(the default value) if the context menu should be cleared before the query; false
otherwise.isMenuClearingEnabled()
protected abstract void setMenuClosedCallback(TContextMenu menu, Runnable menuClosedCallback)
Subclasses have to implement this method for the given framework specific popup menu instance that has been
created by createMenu()
. The yFiles framework calls this method to define a function that should be
called when the given popup menu has been closed. If the menuClosedCallback
is null
,
then a former defined function should no longer be called.
menu
- the framework specific popup menu to set the callback formenuClosedCallback
- the function to be called when the popup menu has been closed or null
if a
former defined function should no longer be called.public final void setPriority(int value)
The priority will influence the order in which the modes will be installed
into the canvas control. The lower the priority value, the earlier it will be installed. If two modes are installed
using the same priority value, the first one will be installed earlier.
value
- The Priority to set.getPriority()
public final void setValidMenuLocationHitTestable(IHitTestable value)
IHitTestable
that determines whether it is valid to open a context menu at the queried position.
If the instance yields false
#onMenuOpening(ContextMenu, PointD, EventSource)
will not be queried and
the context menu will not be shown. By default there is a hit testable instance that always yields true
.
value
- The ValidMenuLocationHitTestable to set.getValidMenuLocationHitTestable()
protected abstract void showMenu(TContextMenu menu, PointD viewLocation)
Subclasses have to implement this method for the given framework specific popup menu instance that has been
created by createMenu()
. Whenever yFiles framework requires a popup menu this method for GUI framework
specific display of popup menus is called.
menu
- the framework specific popup menu to showviewLocation
- the location in view coordinates where to show the popup menupublic boolean stop()
stop
in interface IInputMode
base.Stop()
IInputMode.cancel()
public void uninstall(IInputModeContext context)
uninstall
in interface IInputMode
context
- The context to uninstall this mode from.