Re: How to add a shortcut key to my plugin menu item?
Code: Select all
public PluginAction [] getActions() {
final PluginAction pluginAction = new [i]PluginActionClass[/i](...);
// Create shortcut once Sweet Home 3D window is created
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// KeyStroke for shortcut Ctrl+Alt+Shift+C (cmd+alt+shift+C under Mac OS X)
KeyStroke cmdOrCtrlAltShiftC = KeyStroke.getKeyStroke(KeyEvent.VK_C,
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
| KeyEvent.ALT_DOWN_MASK
| KeyEvent.SHIFT_DOWN_MASK);
// Bind shortcut with the key "MY_KEY"
JComponent homePane = (JComponent)getHomeController().getView();
String actionKey = "MY_KEY";
homePane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).
put(cmdOrCtrlAltShiftC, actionKey);
// Bind the key "MY_KEY" with an action that will execute the plug-in
homePane.getActionMap().put(actionKey, new AbstractAction() {
public void actionPerformed(ActionEvent e) {
pluginAction.execute();
}
});
}
});
return new PluginAction [] {pluginAction};
}
Code: Select all
((JFrame)SwingUtilities.getWindowAncestor((JComponent)getHomeController().getView())).
getJMenuBar();