当前位置: 首页>>代码示例>>Java>>正文


Java KeyStroke.equals方法代码示例

本文整理汇总了Java中javax.swing.KeyStroke.equals方法的典型用法代码示例。如果您正苦于以下问题:Java KeyStroke.equals方法的具体用法?Java KeyStroke.equals怎么用?Java KeyStroke.equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.KeyStroke的用法示例。


在下文中一共展示了KeyStroke.equals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addKeyStroke

import javax.swing.KeyStroke; //导入方法依赖的package包/类
private void addKeyStroke(KeyStroke keyStroke, boolean add) {
    String s = Utilities.keyToString(keyStroke, true);
    KeyStroke mappedStroke = Utilities.stringToKey(s);
    if (!keyStroke.equals(mappedStroke)) {
        return;
    }
    String k = KeyStrokeUtils.getKeyStrokeAsText(keyStroke);
    // check if the text can be mapped back
    if (key.equals("")) { //NOI18N
        textField.setText(k);
        if (add)
            key = k;
    } else {
        textField.setText(key + " " + k); //NOI18N
        if (add)
            key += " " + k; //NOI18N
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ShortcutListener.java

示例2: processKeyEvent

import javax.swing.KeyStroke; //导入方法依赖的package包/类
public void processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager manager) {
    if (isReturnAction(e)) { // Handle SPACE and ENTER
        MenuElement[] p = manager.getSelectedPath();
        MenuElement m = p != null && p.length > 0 ? p[p.length - 1] : null;
        if (m instanceof StayOpen) {
            e.consume();
            if (e.getID() == KeyEvent.KEY_PRESSED)
                performAction((StayOpen)m, e.getModifiers());
            return;
        }
    } else for (Component component : getComponents()) { // Handle mnemonics and accelerators
        if (component instanceof StayOpen) {
            StayOpen item = (StayOpen)component;
            JMenuItem i = item.getItem();
            KeyStroke k = KeyStroke.getKeyStrokeForEvent(e);
            if (k.equals(mnemonic(i)) || k.equals(i.getAccelerator())) {
                e.consume();
                manager.setSelectedPath(new MenuElement[] { this, i });
                performAction(item, e.getModifiers());
                return;
            }
        }
    }
    
    super.processKeyEvent(e, path, manager);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:StayOpenPopupMenu.java

示例3: keyPressed

import javax.swing.KeyStroke; //导入方法依赖的package包/类
public void keyPressed(KeyEvent e) {
    KeyStroke keyStroke = createKeyStroke(e);
    
    boolean add = e.getKeyCode() != e.VK_SHIFT &&
            e.getKeyCode() != e.VK_CONTROL &&
            e.getKeyCode() != e.VK_ALT &&
            e.getKeyCode() != e.VK_META &&
            e.getKeyCode() != e.VK_ALT_GRAPH;
    
    if (keyStroke.equals(backspaceKS) && !key.equals("")) {
        // delete last key
        int i = key.lastIndexOf(' ');
        if (i < 0)
            key = "";
        else
            key = key.substring(0, i);
        tfShortcut.setText(key);
    } else
        // add key
        addKeyStroke(keyStroke, add);
    
    e.consume();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:ShortcutEnterPanel.java

示例4: addAccelerators

import javax.swing.KeyStroke; //导入方法依赖的package包/类
/** Adds accelerators to given JMenuItem taken from the action */
protected static void addAccelerators(Action a, JMenuItem item, JTextComponent target){
    if (target == null || a==null || item==null) return;
    
    // get accelerators from kitAction
    Action kitAction = getActionByName((String)a.getValue(Action.NAME));
    if (kitAction!=null) a = kitAction;
    // Try to get the accelerator, TopComponent action could be obsoleted
    Keymap km = target.getKeymap();

    if (km != null) {
        KeyStroke[] keys = km.getKeyStrokesForAction(a);
        KeyStroke itemAccelerator = item.getAccelerator();
        
        if (keys != null && keys.length > 0) {
            if (itemAccelerator==null || !itemAccelerator.equals(keys[0])){
                item.setAccelerator(keys[0]);
            }
        }else{
            if (itemAccelerator!=null && kitAction!=null){
                item.setAccelerator(null);
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:MainMenuAction.java

示例5: checkExpansionKeystroke

import javax.swing.KeyStroke; //导入方法依赖的package包/类
private void checkExpansionKeystroke(KeyEvent evt) {
    Position pos = null;
    Document d = null;
    synchronized (abbrevChars) {
        if (abbrevEndPosition != null && component != null && doc != null
            && component.getCaretPosition() == abbrevEndPosition.getOffset()
            && !isAbbrevDisabled()
            && doc.getProperty(EDITING_TEMPLATE_DOC_PROPERTY) == null
        ) {
            pos = abbrevEndPosition;
            d = component.getDocument();
        }
    }
    if (pos != null && d != null) {
        CodeTemplateManagerOperation operation = CodeTemplateManagerOperation.get(d, pos.getOffset());
        if (operation != null) {
            KeyStroke expandKeyStroke = operation.getExpansionKey();

            if (expandKeyStroke.equals(KeyStroke.getKeyStrokeForEvent(evt))) {
                if (expand(operation)) {
                    evt.consume();
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:AbbrevDetection.java

示例6: getLayerWithMatchingActivateCommand

import javax.swing.KeyStroke; //导入方法依赖的package包/类
/**
 * If the argument GamePiece contains a Layer whose "activate" command matches
 * the given keystroke, and whose active status matches the boolean argument,
 * return that Layer
 */
public static Embellishment getLayerWithMatchingActivateCommand(GamePiece piece, KeyStroke stroke, boolean active) {
  for (Embellishment layer = (Embellishment) Decorator.getDecorator(piece, Embellishment.class); layer != null; layer = (Embellishment) Decorator
      .getDecorator(layer.piece, Embellishment.class)) {
    for (int i = 0; i < layer.activateKey.length(); ++i) {
      if (stroke.equals(KeyStroke.getKeyStroke(layer.activateKey.charAt(i), layer.activateModifiers))) {
        if (active && layer.isActive()) {
          return layer;
        }
        else if (!active && !layer.isActive()) {
          return layer;
        }
        break;
      }
    }
  }
  return null;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:23,代码来源:Embellishment0.java

示例7: equals

import javax.swing.KeyStroke; //导入方法依赖的package包/类
public boolean equals(Object o) {
  if (o instanceof NamedKeyStroke) {
    if (getKeyStroke() == null) {
      return ((NamedKeyStroke) o).getKeyStroke() == null;
    }
    else {
      return getKeyStroke().equals(((NamedKeyStroke) o).getKeyStroke());
    }
  }
  else if (o instanceof KeyStroke) {
    final KeyStroke a = getKeyStroke();
    if (a == null) {
      return o == null;
    }
    return a.equals(o);
  }
  return false;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:19,代码来源:NamedKeyStroke.java

示例8: checkSerializedKeyStrokes

import javax.swing.KeyStroke; //导入方法依赖的package包/类
private static void checkSerializedKeyStrokes(int keyCode, int modifiers,
        boolean onKeyRelease) throws Exception {

    AWTKeyStroke awtKeyStroke = AWTKeyStroke.getAWTKeyStroke(
            keyCode, modifiers, onKeyRelease);

    KeyStroke keyStroke = KeyStroke.getKeyStroke(
            keyCode, modifiers, onKeyRelease);

    if (awtKeyStroke != getSerializedAWTKeyStroke(awtKeyStroke)) {
        throw new RuntimeException("Serialized AWTKeyStroke is not cached!");
    }

    awtKeyStroke = AWTKeyStroke.getAWTKeyStroke(
            keyCode, modifiers, !onKeyRelease);

    if (!keyStroke.equals(getSerializedAWTKeyStroke(keyStroke))) {
        throw new RuntimeException("Serialized KeyStroke is not cached!");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:TestAWTKeyStroke.java

示例9: getHelp

import javax.swing.KeyStroke; //导入方法依赖的package包/类
private String getHelp() {
	String ret = "";
	TreeMap<String,String> helpText = new TreeMap<String, String>();
	for (KeyStroke key : panel.getInputMap().allKeys()) {
		if (key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_0,0)) ||
				key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_1,0)) ||
				key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_2,0)) ||
				key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_3,0)) ||
				key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_4,0)) ||
				key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_5,0)) ||
				key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_6,0)) ||
				key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_7,0)) ||
				key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_8,0)) ||
				key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_9,0)) ||
				key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS,0)) ||
				key.equals(KeyStroke.getKeyStroke(KeyEvent.VK_COMMA,0)))
			continue;
		if (key.getModifiers() != 0) helpText.put(key.toString().replaceAll("pressed ", "").replaceAll(" ", "-"), panel.getInputMap().get(key).toString());
		else helpText.put(key.toString().replaceAll("pressed ", ""), panel.getInputMap().get(key).toString());
	}
	for (Entry<String,String> en : helpText.entrySet()) {
		ret += en.getKey() + ": " + en.getValue() + "\n";
	}
	return ret;
}
 
开发者ID:FedericoPecora,项目名称:coordination_oru,代码行数:26,代码来源:PathEditor.java

示例10: keyPressed

import javax.swing.KeyStroke; //导入方法依赖的package包/类
public void keyPressed(KeyEvent e) {
    assert (e.getSource() instanceof JTextField);

    if(((e.getModifiers() & (KeyEvent.ALT_MASK | KeyEvent.SHIFT_MASK | KeyEvent.CTRL_MASK | KeyEvent.META_MASK)) == 0) &&
            (e.getKeyCode() == KeyEvent.VK_DOWN || 
            e.getKeyCode() == KeyEvent.VK_UP ||
            e.getKeyCode() == KeyEvent.VK_ESCAPE)) {
        return ;
    }
    
    textField = (JTextField) e.getSource();
    KeyStroke keyStroke = createKeyStroke(e);

    boolean add = e.getKeyCode() != KeyEvent.VK_SHIFT &&
            e.getKeyCode() != KeyEvent.VK_CONTROL &&
            e.getKeyCode() != KeyEvent.VK_ALT &&
            e.getKeyCode() != KeyEvent.VK_META &&
            e.getKeyCode() != KeyEvent.VK_ALT_GRAPH;

    if (!(enterConfirms && keyStroke.equals(enterKS))) {
        if (keyStroke.equals(backspaceKS) && !key.equals("")) {
            // delete last key
            int i = key.lastIndexOf(' '); //NOI18N
            if (i < 0) {
                key = ""; //NOI18N
            } else {
                key = key.substring(0, i);
            }
            textField.setText(key);
        } else {
            // add key
            addKeyStroke(keyStroke, add);
        }

        e.consume();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:ShortcutListener.java

示例11: keyPressed

import javax.swing.KeyStroke; //导入方法依赖的package包/类
public void keyPressed (KeyEvent e) {
    KeyStroke keyStroke = ShortcutListener.createKeyStroke(e);
    
    boolean add = e.getKeyCode () != KeyEvent.VK_SHIFT &&
                  e.getKeyCode () != KeyEvent.VK_CONTROL &&
                  e.getKeyCode () != KeyEvent.VK_ALT &&
                  e.getKeyCode () != KeyEvent.VK_META &&
                  e.getKeyCode () != KeyEvent.VK_ALT_GRAPH;
    
    if (keyStroke.equals (backspaceKS) && !key.equals ("")) {
        // delete last key
        int i = key.lastIndexOf (' '); //NOI18N
        if (i < 0) {
            key = ""; //NOI18N
        } else {
            key = key.substring (0, i);
        }
        getTfShortcut().setText (key);
    } else {
        // add key
        addKeyStroke (keyStroke, add);
    }
    if (add) {
        updateWarning();
    } else {
        setShortcutValid(false);
    }
    e.consume ();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:ShortcutsDialog.java

示例12: getExpandKeyStrokeText

import javax.swing.KeyStroke; //导入方法依赖的package包/类
private static String getExpandKeyStrokeText(KeyStroke keyStroke) {
    String expandKeyStrokeText;
    if (keyStroke.equals(KeyStroke.getKeyStroke(' '))) { //NOI18N
        expandKeyStrokeText = "SPACE"; // NOI18N
    } else if (keyStroke.equals(KeyStroke.getKeyStroke(new Character(' '), InputEvent.SHIFT_MASK))) { //NOI18N
        expandKeyStrokeText = "Shift-SPACE"; // NOI18N
    } else if (keyStroke.equals(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0))) {
        expandKeyStrokeText = "TAB"; // NOI18N
    } else if (keyStroke.equals(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0))) {
        expandKeyStrokeText = "ENTER"; // NOI18N
    } else {
        expandKeyStrokeText = keyStroke.toString();
    }
    return expandKeyStrokeText;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:CodeTemplateManagerOperation.java

示例13: patchExpansionKey

import javax.swing.KeyStroke; //导入方法依赖的package包/类
private static KeyStroke patchExpansionKey(KeyStroke eks) {
// Patch the keyPressed => keyTyped to prevent insertion of expand chars into editor
       if (eks.equals(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0))) {
           eks = KeyStroke.getKeyStroke(' ');
       } else if (eks.equals(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.SHIFT_MASK))) {
           eks = KeyStroke.getKeyStroke(new Character(' '), InputEvent.SHIFT_MASK);
       } else if (eks.equals(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0))) {
       } else if (eks.equals(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0))) {
       }
return eks;
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:CodeTemplateManagerOperation.java

示例14: isEnabled

import javax.swing.KeyStroke; //导入方法依赖的package包/类
private boolean isEnabled(KeyStroke stroke) {
  if (stroke == null) {
    return false;
  }
  for (int i = 0; i < commands.length; ++i) {
    if (stroke.equals(commands[i].getKeyStroke())) {
      return commands[i].isEnabled();
    }
  }
  return true;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:12,代码来源:BasicPiece.java

示例15: getMatchingActivationChar

import javax.swing.KeyStroke; //导入方法依赖的package包/类
private char getMatchingActivationChar(KeyStroke stroke) {
  for (int i = 0; i < activateKey.length(); ++i) {
    if (stroke != null && stroke.equals(KeyStroke.getKeyStroke(activateKey.charAt(i), activateModifiers))) {
      return activateKey.charAt(i);
    }
  }
  return (char) 0;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:9,代码来源:Embellishment0.java


注:本文中的javax.swing.KeyStroke.equals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。