Class MegaMekController
- All Implemented Interfaces:
- KeyEventDispatcher
The idea is that the system is split into two: keys can be bound to string commands, and string commands can be bound to CommandAction objects, which are a simple class that implements an "actionPerformed" method. The class that implements the CommandAction creates the object and registers it, agnostic to what key is bound to the command. Then, somewhere else (ie; a file) can specify what keys are bound to what string commands. The possible string commands are specified in KeyCommandBind.
There are three things that need to be done to create a key binding. First, a command must exist, defined in KeyCommandBind. Then, the command must be bound to a key in the keybind XML file (mmconf/defaultKeyBinds.xml by default). Finally, a CommandAction needs to be registered somewhere.
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic interfaceThis is an interface for a parameter-less method without a return value.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected Map<String,ArrayList<CommandAction>> Maps command strings to CommandAction objects.protected booleanShould we ignore key presses?protected Set<KeyCommandBind>Maps a key code to a command string.protected TimerTimer for repeating commands for key presses.protected Map<KeyCommandBind,TimerTask> Keeps track of the tasks that are currently repeating.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionbooleandispatchKeyEvent(KeyEvent evt) voidregisterCommandAction(String cmd, CommandAction action) Registers an action to a keybind given as the cmd parameter (e.g.voidregisterCommandAction(KeyCommandBind commandBind, Supplier<Boolean> shouldPerform, MegaMekController.KeyBindAction performer, MegaMekController.KeyBindAction releaseAction) Registers an action to a keybind, e.g.voidregisterCommandAction(KeyCommandBind commandBind, KeyBindReceiver receiver, MegaMekController.KeyBindAction performer) Registers an action to a keybind, e.g.voidvoidvoidvoidsetIgnoreKeyPresses(boolean ignoreKeyPresses) Set whether key presses should be ignored or not.protected voidstartRepeating(KeyCommandBind kcb, CommandAction action) Start a new repeating timer task for the given KeyCommandBind.voidStop all repeat timers.voidStops the repeat timer task for the given KeyCommandBind.
- 
Field Details- 
boardEditor
- 
clientGUI
- 
keyCmdSetMaps a key code to a command string.
- 
cmdActionMapMaps command strings to CommandAction objects.
- 
keyRepeatTimerTimer for repeating commands for key presses. This is necessary to override the default key repeat delay.
- 
repeatingTasksKeeps track of the tasks that are currently repeating.
- 
ignoreKeyPressesprotected boolean ignoreKeyPressesShould we ignore key presses?
 
- 
- 
Constructor Details- 
MegaMekControllerpublic MegaMekController()
 
- 
- 
Method Details- 
dispatchKeyEvent- Specified by:
- dispatchKeyEventin interface- KeyEventDispatcher
 
- 
registerKeyCommandBind
- 
removeAllKeyCommandBindspublic void removeAllKeyCommandBinds()
- 
registerCommandActionRegisters an action to a keybind given as the cmd parameter (e.g. KeyCommandBind.SCROLL_NORTH.cmd). For every press of the bound key, the action will be called.- Parameters:
- cmd- The key command string, obtained through KeyCommandBind
- action- The CommandAction
 
- 
registerCommandActionpublic void registerCommandAction(KeyCommandBind commandBind, KeyBindReceiver receiver, MegaMekController.KeyBindAction performer) Registers an action to a keybind, e.g.KeyCommandBind.SCROLL_NORTH. The necessary CommandAction is constructed from the given parameters. The given performer is called when the key is pressed if the given receiver's shouldReceiveKeyCommands() method check returns true. Note that in this case, the keybind is considered consumed even if this receiver doesn't do anything with it. For a keybind to be passed on to other receivers, this receiver's shouldPerformKeyCommands() must return false.- Parameters:
- commandBind- The KeyCommandBind
- receiver- The- KeyBindReceiverthat receives this keypress
- performer- A method that takes action upon the keypress
- See Also:
 
- 
registerCommandActionpublic void registerCommandAction(KeyCommandBind commandBind, Supplier<Boolean> shouldPerform, MegaMekController.KeyBindAction performer, MegaMekController.KeyBindAction releaseAction) Registers an action to a keybind, e.g. KeyCommandBind.SCROLL_NORTH. The necessary CommandAction is constructed from the given method references. The given performer will be called when the key is pressed if the given shouldPerform check returns true. Note that in this case, the keybind is considered consumed even if this receiver doesn't do anything with it. For a keybind to be passed on to other receivers, this receiver's shouldPerform must return false. Additionally, the given releaseAction is called when the pressed key is released again (also, only when shouldPerform allows it).- Parameters:
- commandBind- The KeyCommandBind
- shouldPerform- A method that should return true when the performer is allowed to take action
- performer- A method that takes action upon the keypress
- releaseAction- A method that takes action when the key is released again
 
- 
removeAllActionspublic void removeAllActions()
- 
startRepeatingStart a new repeating timer task for the given KeyCommandBind. If the given KeyCommandBind already has a repeating task, a new one is not added. Also, if there is no mapped CommandAction for the given KeyCommandBind no task is scheduled.
- 
stopRepeatingStops the repeat timer task for the given KeyCommandBind.
- 
stopAllRepeatingpublic void stopAllRepeating()Stop all repeat timers.
- 
setIgnoreKeyPressespublic void setIgnoreKeyPresses(boolean ignoreKeyPresses) Set whether key presses should be ignored or not.
 
-