CanvasContextMenuProvider
Package: velox.api.layer1.layers.strategies.interfaces
Type: Interface
Description​
Use ScreenSpaceCanvas.addContextMenuProvider(CanvasContextMenuProvider) to add menu items into the context menu generated by Bookmap.
Internally the right-click handling looks like this:
- A right-click event occurs
getRightClickEventScore(CanvasMouseEvent)is called for every module- Bookmap finds a module with the highest score
- If this module is different from the previously focused one,
onFocusLost()is called on the previous one - Bookmap calls
onFocusGained()on the newly focused module - Bookmap calls
getMenuItems(CanvasMouseEvent)on every module, and combines obtained menu items into one context menu - Context menu is shown
Methods​
getRightClickEventScore​
default int getRightClickEventScore(CanvasMouseEvent e)
Every CanvasContextMenuProvider on every right-click is asked to "vote" for this event. The module which provided the highest score - wins, and its onFocusGained() is called.
Use MouseModuleScore as a reference for your values, e.g. if you want your module to capture focus on trade circles/indicator lines, return the score higher than MouseModuleScore.GRAPH_LAYERS_MODULES_MAX.
You can track focus state with onFocusGained()/onFocusLost(), and insert different menu items based on it.
Parameters:
e- Right click mouse event
Returns: Score in range [MouseModuleScore.MIN, MouseModuleScore.MAX] if you want to obtain focus for this event, MouseModuleScore.NONE otherwise.
Throws:
IllegalArgumentException- If score is out of range [MouseModuleScore.MIN,MouseModuleScore.MAX] and not equal toMouseModuleScore.NONE
See Also:
MouseModuleScore
onFocusGained​
default void onFocusGained()
Called if this module wins the voting for a right-click event
onFocusLost​
default void onFocusLost()
Called after onFocusGained(), when some other module wins the voting for another mouse event
getMenuItems​
List<JMenuItem> getMenuItems(CanvasMouseEvent e)
On right-click Bookmap asks every CanvasContextMenuProvider to provide a list of menu items.
Parameters:
e- A right-click event that you can use to decide what to include in the resulting menu.
Returns: JMenuItems that should be included into Bookmap-generated context menu