下面列出了javax.swing.SwingUtilities#replaceUIInputMap ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void installKeyboardActions() {
super.installKeyboardActions();
JTextComponent comp = getComponent();
UIDefaults uidefaults = XToolkit.getUIDefaults();
String prefix = getPropertyPrefix();
InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");
if (map != null) {
SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
map);
}
}
@Override
protected void installKeyboardActions() {
super.installKeyboardActions();
JTextComponent comp = getComponent();
UIDefaults uidefaults = XToolkit.getUIDefaults();
String prefix = getPropertyPrefix();
InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");
if (map != null) {
SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
map);
}
}
@Override
protected void installKeyboardActions() {
super.installKeyboardActions();
JTextComponent comp = getComponent();
UIDefaults uidefaults = XToolkit.getUIDefaults();
String prefix = getPropertyPrefix();
InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");
if (map != null) {
SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
map);
}
}
@Override
protected void installKeyboardActions() {
super.installKeyboardActions();
JTextComponent comp = getComponent();
UIDefaults uidefaults = XToolkit.getUIDefaults();
String prefix = getPropertyPrefix();
InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");
if (map != null) {
SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
map);
}
}
@Override
protected void installKeyboardActions() {
super.installKeyboardActions();
JTextComponent comp = getComponent();
UIDefaults uidefaults = XToolkit.getUIDefaults();
String prefix = getPropertyPrefix();
InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");
if (map != null) {
SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
map);
}
}
/**
* Creates new form CompareResultImages
*/
public CompareResultImages() {
initComponents();
toReviewList.setModel(new DefaultListModel());
fillList();
setSize(800, 600);
setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
actualImage.setStretch(false);
referenceImage.setStretch(false);
acceptAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control D"));
InputMap keyMap = new ComponentInputMap(acceptButton);
keyMap.put(KeyStroke.getKeyStroke("control D"), "accept");
ActionMap actionMap = new ActionMapUIResource();
actionMap.put("accept", acceptAction);
SwingUtilities.replaceUIActionMap(acceptButton, actionMap);
SwingUtilities.replaceUIInputMap(acceptButton, JComponent.WHEN_IN_FOCUSED_WINDOW, keyMap);
}
@Override
protected void installKeyboardActions() {
super.installKeyboardActions();
JTextComponent comp = getComponent();
UIDefaults uidefaults = XToolkit.getUIDefaults();
String prefix = getPropertyPrefix();
InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");
if (map != null) {
SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
map);
}
}
@Override
protected void installKeyboardActions() {
super.installKeyboardActions();
JTextComponent comp = getComponent();
UIDefaults uidefaults = XToolkit.getUIDefaults();
String prefix = getPropertyPrefix();
InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");
if (map != null) {
SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
map);
}
}
@Override
protected void installKeyboardActions() {
super.installKeyboardActions();
JTextComponent comp = getComponent();
UIDefaults uidefaults = XToolkit.getUIDefaults();
String prefix = getPropertyPrefix();
InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");
if (map != null) {
SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
map);
}
}
@Override
protected void installKeyboardActions() {
super.installKeyboardActions();
JTextComponent comp = getComponent();
UIDefaults uidefaults = XToolkit.getUIDefaults();
String prefix = getPropertyPrefix();
InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");
if (map != null) {
SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
map);
}
}
@Override
protected void installKeyboardActions() {
super.installKeyboardActions();
JTextComponent comp = getComponent();
UIDefaults uidefaults = XToolkit.getUIDefaults();
String prefix = getPropertyPrefix();
InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");
if (map != null) {
SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
map);
}
}
/**
* Invoked as part from the boilerplate install block.
*/
protected void installKeyboardActions(mxGraphComponent graphComponent)
{
InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
SwingUtilities.replaceUIInputMap(graphComponent,
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);
inputMap = getInputMap(JComponent.WHEN_FOCUSED);
SwingUtilities.replaceUIInputMap(graphComponent,
JComponent.WHEN_FOCUSED, inputMap);
SwingUtilities.replaceUIActionMap(graphComponent, createActionMap());
}
@Override
protected PropertyChangeListener createPropertyChangeListener() {
return new BasicScrollBarUI.PropertyChangeHandler() {
@Override
public void propertyChange( PropertyChangeEvent e ) {
super.propertyChange( e );
switch( e.getPropertyName() ) {
case FlatClientProperties.SCROLL_BAR_SHOW_BUTTONS:
scrollbar.revalidate();
scrollbar.repaint();
break;
case "componentOrientation":
// this is missing in BasicScrollBarUI.Handler.propertyChange()
InputMap inputMap = (InputMap) UIManager.get( "ScrollBar.ancestorInputMap" );
if( !scrollbar.getComponentOrientation().isLeftToRight() ) {
InputMap rtlInputMap = (InputMap) UIManager.get( "ScrollBar.ancestorInputMap.RightToLeft" );
if( rtlInputMap != null ) {
rtlInputMap.setParent( inputMap );
inputMap = rtlInputMap;
}
}
SwingUtilities.replaceUIInputMap( scrollbar, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap );
break;
}
}
};
}
/**
* Installs the state needed for mnemonics.
*/
private void initMnemonics() {
mnemonicToIndexMap = new Hashtable<Integer, Integer>();
mnemonicInputMap = new InputMapUIResource();
mnemonicInputMap.setParent(SwingUtilities.getUIInputMap(tabPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT));
SwingUtilities.replaceUIInputMap(tabPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, mnemonicInputMap);
}
private void uninstallMaps() {
InputMap currMap = SwingUtilities.getUIInputMap(this.jcomp,
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
InputMap newMap = new InputMap();
if (currMap != null) {
KeyStroke[] kss = currMap.allKeys();
for (int i = 0; i < kss.length; i++) {
KeyStroke stroke = kss[i];
Object val = currMap.get(stroke);
if (stroke
.equals(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.CTRL_DOWN_MASK))) {
if ("tabSwitcherForward".equals(val))
continue;
}
if (stroke.equals(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, InputEvent.CTRL_DOWN_MASK))) {
if ("tabSwitcherBackward".equals(val))
continue;
}
if (stroke.equals(KeyStroke.getKeyStroke(KeyEvent.VK_CONTROL, 0, true))) {
if ("tabSwitcherClose".equals(val))
continue;
}
if (stroke.equals(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0))) {
if ("tabSwitcherHide".equals(val))
continue;
}
newMap.put(stroke, val);
}
}
this.jcomp.getActionMap().remove("tabSwitcherForward");
this.jcomp.getActionMap().remove("tabSwitcherBackward");
this.jcomp.getActionMap().remove("tabSwitcherClose");
this.jcomp.getActionMap().remove("tabSwitcherHide");
SwingUtilities.replaceUIInputMap(this.jcomp, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
newMap);
}
public EuropeButton(String text, int keyEvent, String command,
ActionListener listener) {
setOpaque(true);
setText(text);
setActionCommand(command);
addActionListener(listener);
InputMap closeInputMap = new ComponentInputMap(this);
closeInputMap.put(KeyStroke.getKeyStroke(keyEvent, 0, false),
"pressed");
closeInputMap.put(KeyStroke.getKeyStroke(keyEvent, 0, true),
"released");
SwingUtilities.replaceUIInputMap(this,
JComponent.WHEN_IN_FOCUSED_WINDOW,
closeInputMap);
}
protected void uninstallKeyboardActions() {
SwingUtilities.replaceUIActionMap(lizziePane, null);
SwingUtilities.replaceUIInputMap(
lizziePane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
}
@Override
protected void uninstallKeyboardActions() {
SwingUtilities.replaceUIActionMap(tabPane, null);
SwingUtilities.replaceUIInputMap(tabPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
SwingUtilities.replaceUIInputMap(tabPane, JComponent.WHEN_FOCUSED, null);
}
protected void uninstallKeyboardActions()
{
SwingUtilities.replaceUIInputMap(terminal, JComponent.WHEN_FOCUSED, null);
SwingUtilities.replaceUIActionMap(terminal, null);
}
/** Installs the UI for a component. */
public @Override void installUI(JComponent c) {
super.installUI(c);
if (!(c instanceof JTextComponent)) {
return;
}
JTextComponent component = getComponent();
prefs = MimeLookup.getLookup(org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(component)).lookup(Preferences.class);
// set margin
String value = prefs.get(SimpleValueNames.MARGIN, null);
Insets margin = value != null ? SettingsConversions.parseInsets(value) : null;
component.setMargin(margin != null ? margin : EditorUI.NULL_INSETS);
getEditorUI().installUI(component);
// attach to the model and component
//component.addPropertyChangeListener(this); already done in super class
if (component.getClientProperty(UIWatcher.class) == null) {
UIWatcher uiWatcher = new UIWatcher(this.getClass());
component.addPropertyChangeListener(uiWatcher);
component.putClientProperty(UIWatcher.class, uiWatcher);
}
BaseKit kit = (BaseKit)getEditorKit(component);
ViewFactory vf = kit.getViewFactory();
// Create and attach caret
Caret defaultCaret = component.getCaret();
Caret caret = kit.createCaret();
component.setCaretColor(Color.black); // will be changed by settings later
component.setCaret(caret);
component.putClientProperty(PROP_DEFAULT_CARET_BLINK_RATE, defaultCaret.getBlinkRate());
component.setKeymap(kit.getKeymap());
// assign blink rate
int br = prefs.getInt(SimpleValueNames.CARET_BLINK_RATE, -1);
if (br == -1) {
br = defaultCaret.getBlinkRate();
}
caret.setBlinkRate(br);
SwingUtilities.replaceUIInputMap(c, JComponent.WHEN_FOCUSED, null);
EditorApiPackageAccessor.get().register(component);
component.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
}