當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。