下面列出了怎么用javax.swing.plaf.ComponentInputMapUIResource的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Installs the state needed for mnemonics.
*/
protected void initMnemonics() {
mnemonicToIndexMap = new Hashtable<>();
mnemonicInputMap = new ComponentInputMapUIResource(tabPane);
mnemonicInputMap.setParent(SwingUtilities.getUIInputMap(tabPane,
JComponent.WHEN_IN_FOCUSED_WINDOW));
SwingUtilities.replaceUIInputMap(tabPane,
JComponent.WHEN_IN_FOCUSED_WINDOW,
mnemonicInputMap);
}
@Override
public void install ( @NotNull final C component )
{
super.install ( component );
// Installing listeners
component.addPropertyChangeListener ( this );
component.addMouseListener ( this );
component.addMouseWheelListener ( this );
// Installing ActionMap
final UIActionMap actionMap = new UIActionMap ();
actionMap.put ( new Actions ( component, Actions.NEXT ) );
actionMap.put ( new Actions ( component, Actions.PREVIOUS ) );
actionMap.put ( new Actions ( component, Actions.RIGHT ) );
actionMap.put ( new Actions ( component, Actions.LEFT ) );
actionMap.put ( new Actions ( component, Actions.UP ) );
actionMap.put ( new Actions ( component, Actions.DOWN ) );
actionMap.put ( new Actions ( component, Actions.PAGE_UP ) );
actionMap.put ( new Actions ( component, Actions.PAGE_DOWN ) );
actionMap.put ( new Actions ( component, Actions.REQUEST_FOCUS ) );
actionMap.put ( new Actions ( component, Actions.REQUEST_FOCUS_FOR_VISIBLE ) );
actionMap.put ( new Actions ( component, Actions.SET_SELECTED ) );
actionMap.put ( new Actions ( component, Actions.SCROLL_FORWARD ) );
actionMap.put ( new Actions ( component, Actions.SCROLL_BACKWARD ) );
SwingUtilities.replaceUIActionMap ( component, actionMap );
// Installing InputMap
final InputMap focusedMap = LafLookup.getInputMap ( component, JComponent.WHEN_FOCUSED );
SwingUtilities.replaceUIInputMap ( component, JComponent.WHEN_FOCUSED, focusedMap );
final InputMap ancestorMap = LafLookup.getInputMap ( component, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
SwingUtilities.replaceUIInputMap ( component, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, ancestorMap );
// Installing mnemonic InputMap
mnemonicInputMap = new ComponentInputMapUIResource ( component );
mnemonicInputMap.setParent ( SwingUtilities.getUIInputMap ( component, JComponent.WHEN_IN_FOCUSED_WINDOW ) );
SwingUtilities.replaceUIInputMap ( component, JComponent.WHEN_IN_FOCUSED_WINDOW, mnemonicInputMap );
}
/**
* Installs the maps on the root pane of the originating component of
* the first popup panel of the specified sequence to trace the ESC key
* and dismiss the shown popup panels.
*
* @param shownPath Popup panel sequence.
*/
private void traceRootPane(List<PopupPanelManager.PopupInfo> shownPath) {
JComponent originator = shownPath.get(0).getPopupOriginator();
this.tracedRootPane = SwingUtilities.getRootPane(originator);
if (this.tracedRootPane != null) {
newInputMap = new ComponentInputMapUIResource(tracedRootPane);
newInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
"hidePopupPanel");
newActionMap = new ActionMapUIResource();
newActionMap.put("hidePopupPanel", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
// Hide the last sequence popup for every ESC keystroke.
// There is special case - if the keytips are shown
// for the *second* panel of the app menu popup panel,
// do not dismiss the popup
List<PopupPanelManager.PopupInfo> popups = PopupPanelManager
.defaultManager().getShownPath();
if (popups.size() > 0) {
PopupPanelManager.PopupInfo lastPopup = popups
.get(popups.size() - 1);
if (lastPopup.getPopupPanel() instanceof JRibbonApplicationMenuPopupPanel) {
JRibbonApplicationMenuPopupPanel appMenuPopupPanel =
(JRibbonApplicationMenuPopupPanel) lastPopup
.getPopupPanel();
KeyTipManager.KeyTipChain currentlyShownKeyTipChain = KeyTipManager
.defaultManager().getCurrentlyShownKeyTipChain();
if ((currentlyShownKeyTipChain != null)
&& (currentlyShownKeyTipChain.chainParentComponent == appMenuPopupPanel
.getPanelLevel2()))
return;
}
}
PopupPanelManager.defaultManager().hideLastPopup();
}
});
addUIInputMap(tracedRootPane, newInputMap);
addUIActionMap(tracedRootPane, newActionMap);
}
}