本文整理匯總了Java中org.netbeans.api.editor.settings.KeyBindingSettings.getKeyBindings方法的典型用法代碼示例。如果您正苦於以下問題:Java KeyBindingSettings.getKeyBindings方法的具體用法?Java KeyBindingSettings.getKeyBindings怎麽用?Java KeyBindingSettings.getKeyBindings使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.netbeans.api.editor.settings.KeyBindingSettings
的用法示例。
在下文中一共展示了KeyBindingSettings.getKeyBindings方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateActions
import org.netbeans.api.editor.settings.KeyBindingSettings; //導入方法依賴的package包/類
private synchronized void updateActions(KeyBindingSettings settings) {
List<MultiKeyBinding> multiKeyBindings = settings.getKeyBindings();
actionName2Binding = new HashMap<String,List<List<KeyStroke>>>(multiKeyBindings.size() << 1);
for (MultiKeyBinding mkb : multiKeyBindings) {
String actionName = mkb.getActionName();
List<List<KeyStroke>> mkbList = actionName2Binding.get(actionName);
if (mkbList == null) {
mkbList = Collections.singletonList(mkb.getKeyStrokeList());
} else {
@SuppressWarnings("unchecked")
List<KeyStroke>[] mkbArray = new List[mkbList.size() + 1];
mkbList.toArray(mkbArray);
mkbArray[mkbList.size()] = mkb.getKeyStrokeList();
mkbList = ArrayUtilities.unmodifiableList(mkbArray);
}
actionName2Binding.put(actionName, mkbList);
}
// Update kits
}
示例2: findKeyBinding
import org.netbeans.api.editor.settings.KeyBindingSettings; //導入方法依賴的package包/類
private static String findKeyBinding(String actionName) {
KeyBindingSettings kbs = MimeLookup.getLookup(MimePath.get("text/x-java")).lookup(KeyBindingSettings.class); //NOI18N
for (MultiKeyBinding mkb : kbs.getKeyBindings()) {
if (actionName.equals(mkb.getActionName())) {
KeyStroke ks = mkb.getKeyStrokeCount() > 0 ? mkb.getKeyStroke(0) : null;
return ks != null ? KeyEvent.getKeyModifiersText(ks.getModifiers()) + '+' + KeyEvent.getKeyText(ks.getKeyCode()) : null;
}
}
return null;
}
示例3: getDefaultAccelerator
import org.netbeans.api.editor.settings.KeyBindingSettings; //導入方法依賴的package包/類
@Override
protected KeyStroke getDefaultAccelerator(){
Lookup ml = MimeLookup.getLookup(MimePath.EMPTY); //NOI18N
KeyBindingSettings kbs = (KeyBindingSettings) ml.lookup(KeyBindingSettings.class);
if (kbs != null){
List lst = kbs.getKeyBindings();
if (lst != null){
for (int i=0; i<lst.size(); i++){
MultiKeyBinding mkb = (MultiKeyBinding)lst.get(i);
String an = mkb.getActionName();
if (an != null && an.equals(getActionName())){
if (mkb.getKeyStrokeCount() == 1){// we do not support multi KB in mnemonics
return mkb.getKeyStroke(0);
}
}
}
}
}
return null;
}
示例4: getKeymap
import org.netbeans.api.editor.settings.KeyBindingSettings; //導入方法依賴的package包/類
public MultiKeymap getKeymap() {
synchronized (KEYMAPS_AND_ACTIONS_LOCK) {
MimePath mimePath = MimePath.parse(getContentType());
MultiKeymap km = (MultiKeymap)kitKeymaps.get(mimePath);
if (km == null) { // keymap not yet constructed
// construct new keymap
km = new MultiKeymap("Keymap for " + mimePath.getPath()); // NOI18N
// retrieve key bindings for this kit and super kits
KeyBindingSettings kbs = MimeLookup.getLookup(mimePath).lookup(KeyBindingSettings.class);
List<org.netbeans.api.editor.settings.MultiKeyBinding> mkbList = kbs.getKeyBindings();
List<JTextComponent.KeyBinding> editorMkbList = new ArrayList<JTextComponent.KeyBinding>();
for(org.netbeans.api.editor.settings.MultiKeyBinding mkb : mkbList) {
List<KeyStroke> keyStrokes = mkb.getKeyStrokeList();
MultiKeyBinding editorMkb = new MultiKeyBinding(keyStrokes.toArray(new KeyStroke[keyStrokes.size()]), mkb.getActionName());
editorMkbList.add(editorMkb);
}
// go through all levels and collect key bindings
km.load(editorMkbList.toArray(new JTextComponent.KeyBinding[editorMkbList.size()]), getActionMap());
km.setDefaultAction(getActionMap().get(defaultKeyTypedAction));
kitKeymaps.put(mimePath, km);
}
return km;
}
}
示例5: getAccelerator
import org.netbeans.api.editor.settings.KeyBindingSettings; //導入方法依賴的package包/類
/**
* Get single-key accelerator for a given declared action.
* <br>
* Unfortunately currently there's no easy way to display multi-keybinding in menu-item
* (there's just JMenuItem.setAccelerator() and its impl is L&F-based)
* so just display single-keystroke accelerators.
*/
public static KeyStroke getAccelerator(String mimeType, String actionName) {
KeyStroke ks = null;
if (actionName != null) {
synchronized (EditorActionUtilities.class) {
if (mimeType2actionName2KeyStroke == null) {
mimeType2actionName2KeyStroke = new HashMap<String,Map<String,KeyStroke>>();
}
Map<String,KeyStroke> actionName2KeyStrokeList = mimeType2actionName2KeyStroke.get(mimeType);
if (actionName2KeyStrokeList == null) {
actionName2KeyStrokeList = new HashMap<String,KeyStroke>();
Lookup.Result<KeyBindingSettings> result = MimeLookup.getLookup(mimeType).lookupResult(
KeyBindingSettings.class);
Collection<? extends KeyBindingSettings> instances = result.allInstances();
if (!instances.isEmpty()) {
KeyBindingSettings kbs = instances.iterator().next();
for (MultiKeyBinding kb : kbs.getKeyBindings()) {
if (!actionName2KeyStrokeList.containsKey(kb.getActionName())
&& kb.getKeyStrokeCount() == 1)
{
actionName2KeyStrokeList.put(kb.getActionName(), kb.getKeyStroke(0));
}
}
}
mimeType2actionName2KeyStroke.put(mimeType, actionName2KeyStrokeList);
// Ensure listening on changes in keybinding settings
if (!Boolean.TRUE.equals(mimeType2ListenerPresent.get(mimeType))) {
mimeType2ListenerPresent.put(mimeType, true);
result.addLookupListener(KeyBindingSettingsListener.INSTANCE);
}
}
ks = actionName2KeyStrokeList.get(actionName);
}
}
return ks;
}
示例6: testKeyBindingsImmutability
import org.netbeans.api.editor.settings.KeyBindingSettings; //導入方法依賴的package包/類
public void testKeyBindingsImmutability() {
MimePath mimePath = MimePath.parse("text/x-type-A");
Lookup lookup = MimeLookup.getLookup(mimePath);
KeyBindingSettings kbs = lookup.lookup(KeyBindingSettings.class);
assertNotNull("Can't find KeyBindingSettings", kbs);
// Check preconditions
List<MultiKeyBinding> bindings = kbs.getKeyBindings();
assertNotNull("Key bindings should not be null", bindings);
MultiKeyBinding kb = findBindingForAction("test-action-1", bindings);
checkKeyBinding(kb, "O-O");
// Change the coloring
MultiKeyBinding newKb = new MultiKeyBinding(Utilities.stringToKey("DS-D"), "test-action-1");
setOneKeyBinding("text/x-type-A", newKb);
// Check that the original KeyBindingSettings has not changed
bindings = kbs.getKeyBindings();
assertNotNull("Key bindings should not be null", bindings);
kb = findBindingForAction("test-action-1", bindings);
checkKeyBinding(kb, "O-O");
// Check that the new attributes were set
kbs = lookup.lookup(KeyBindingSettings.class);
assertNotNull("Can't find KeyBindingSettings", kbs);
bindings = kbs.getKeyBindings();
assertNotNull("Key bindings should not be null", bindings);
kb = findBindingForAction("test-action-1", bindings);
checkKeyBinding(kb, "DS-D");
}
示例7: findKeyStroke
import org.netbeans.api.editor.settings.KeyBindingSettings; //導入方法依賴的package包/類
public static KeyStroke findKeyStroke(KeyBindingSettings kbs, String actionName) {
if (kbs != null) {
for (MultiKeyBinding kb : kbs.getKeyBindings()) {
// Currently only work if a single-key shortcut is used for the action
if (actionName.equals(kb.getActionName()) && kb.getKeyStrokeCount() == 1) {
return kb.getKeyStroke(0);
}
}
}
return null;
}
示例8: getKeyBindingList
import org.netbeans.api.editor.settings.KeyBindingSettings; //導入方法依賴的package包/類
private List<? extends MultiKeyBinding> getKeyBindingList() {
Collection<? extends KeyBindingSettings> c = lookupResult.allInstances();
if (!c.isEmpty()) {
KeyBindingSettings kbs = c.iterator().next();
return kbs.getKeyBindings();
} else {
return Collections.<MultiKeyBinding>emptyList();
}
}
示例9: updateKeyStrokes
import org.netbeans.api.editor.settings.KeyBindingSettings; //導入方法依賴的package包/類
/** Updates keystrokes. Dependent code. */
private void updateKeyStrokes() {
KeyBindingSettings kbs = keybindings.allInstances().iterator().next();
// Update keyStrokes.
HashSet<KeyStroke> nextKS = new HashSet<KeyStroke>();
HashSet<KeyStroke> prevKS = new HashSet<KeyStroke>();
HashSet<KeyStroke> toggleKS = new HashSet<KeyStroke>();
// Loop thru all bindings in the kit class.
for(MultiKeyBinding mkb : kbs.getKeyBindings()) {
// Find key keystrokes for find next action.
if(mkb.getActionName().equals(BaseKit.findNextAction)) {
for (int k = 0; k < mkb.getKeyStrokeCount(); k++) {
nextKS.add(mkb.getKeyStroke(k));
}
}
// Find key keystrokes for find previous action.
if(mkb.getActionName().equals(BaseKit.findPreviousAction)) {
for (int k = 0; k < mkb.getKeyStrokeCount(); k++) {
prevKS.add(mkb.getKeyStroke(k));
}
}
// Find key keystrokes for toggle highlight action.
if(mkb.getActionName().equals(BaseKit.toggleHighlightSearchAction)) {
for (int k = 0; k < mkb.getKeyStrokeCount(); k++) {
toggleKS.add(mkb.getKeyStroke(k));
}
}
} // End of inner loop.
// Copy found values to our variables.
nextKS.toArray(keyStrokesFindNext = new KeyStroke[nextKS.size()]);
prevKS.toArray(keyStrokesFindPrevious = new KeyStroke[prevKS.size()]);
toggleKS.toArray(keyStrokesToggleHighlight = new KeyStroke[toggleKS.size()]);
// notify listeners about update
settingsUpdated();
}