本文整理匯總了Java中org.netbeans.api.editor.settings.KeyBindingSettings類的典型用法代碼示例。如果您正苦於以下問題:Java KeyBindingSettings類的具體用法?Java KeyBindingSettings怎麽用?Java KeyBindingSettings使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
KeyBindingSettings類屬於org.netbeans.api.editor.settings包,在下文中一共展示了KeyBindingSettings類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: prepareSettings
import org.netbeans.api.editor.settings.KeyBindingSettings; //導入依賴的package包/類
/** Prepares settings. */
private void prepareSettings() {
if (prepared) return;
prepared = true;
// Set listening on changes of settings.
fontsColors = MimeLookup.getLookup(PropertiesKit.PROPERTIES_MIME_TYPE).lookupResult(FontColorSettings.class);
fontsColors.addLookupListener(WeakListeners.create(LookupListener.class, fontsColorsTracker, fontsColors));
keybindings = MimeLookup.getLookup(PropertiesKit.PROPERTIES_MIME_TYPE).lookupResult(KeyBindingSettings.class);
keybindings.addLookupListener(WeakListeners.create(LookupListener.class, keybindingsTracker, keybindings));
// Init settings.
updateColors();
updateKeyStrokes();
}
示例3: testLookupsGCedAfterKbs
import org.netbeans.api.editor.settings.KeyBindingSettings; //導入依賴的package包/類
public void testLookupsGCedAfterKbs() {
MimePath mimePath = MimePath.parse("text/x-type-A");
KeyBindingSettingsImpl kbsi = KeyBindingSettingsImpl.get(mimePath);
Lookup lookup = MimeLookup.getLookup(mimePath);
KeyBindingSettings kbs = lookup.lookup(KeyBindingSettings.class);
WeakReference<KeyBindingSettingsImpl> kbsiRef = new WeakReference<KeyBindingSettingsImpl>(kbsi);
WeakReference<MimePath> mimePathRef = new WeakReference<MimePath>(mimePath);
WeakReference<Lookup> lookupRef = new WeakReference<Lookup>(lookup);
WeakReference<KeyBindingSettings> kbsRef = new WeakReference<KeyBindingSettings>(kbs);
kbsi = null;
mimePath = null;
lookup = null;
kbs = null;
// release text/x-type-A from MimePath's LRU
for(int i = 0; i < 10; i++) {
MimePath.parse("text/x-type-" + ('Z' + i));
}
assertGC("KBSI hasn't been GCed", kbsiRef);
assertGC("MimePath hasn't been GCed", mimePathRef);
assertGC("Lookup hasn't been GCed", lookupRef);
assertGC("KBS hasn't been GCed", kbsRef);
}
示例4: 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;
}
示例5: NbEditorToolBar
import org.netbeans.api.editor.settings.KeyBindingSettings; //導入依賴的package包/類
public NbEditorToolBar(JTextComponent component) {
this.componentRef = new WeakReference(component);
setFloatable(false);
//mkleint - instead of here, assign the border in CloneableEditor and MultiView module.
// // special border installed by core or no border if not available
// Border b = (Border)UIManager.get("Nb.Editor.Toolbar.border"); //NOI18N
// setBorder(b);
addMouseListener(sharedMouseListener);
installModulesInstallationListener();
installNoOpActionMappings();
lookupResult = MimeLookup.getLookup(DocumentUtilities.getMimeType(component)).lookupResult(KeyBindingSettings.class);
lookupResult.addLookupListener(WeakListeners.create(LookupListener.class, keybindingsTracker, lookupResult));
String mimeType = DocumentUtilities.getMimeType(component);
preferences = MimeLookup.getLookup(mimeType == null ? MimePath.EMPTY : MimePath.parse(mimeType)).lookup(Preferences.class);
preferences.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, prefsTracker, preferences));
refreshToolbarButtons();
setBorderPainted(true);
}
示例6: 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;
}
示例7: 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;
}
}
示例8: KeybindingsAndPreferencesTracker
import org.netbeans.api.editor.settings.KeyBindingSettings; //導入依賴的package包/類
public KeybindingsAndPreferencesTracker(String mimeType) {
this.mimeType = mimeType;
Lookup lookup = MimeLookup.getLookup(mimeType);
this.lookupResult = lookup.lookupResult(KeyBindingSettings.class);
this.lookupResult.addLookupListener(WeakListeners.create(LookupListener.class, this, this.lookupResult));
this.lookupResult.allInstances();
this.prefs = lookup.lookup(Preferences.class);
this.prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, this, this.prefs));
}
示例9: 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;
}
示例10: KeyBindingsUpdater
import org.netbeans.api.editor.settings.KeyBindingSettings; //導入依賴的package包/類
private KeyBindingsUpdater(String mimeType) {
this.mimeType = mimeType;
lookupResult = MimeLookup.getLookup(mimeType).lookup(
new Lookup.Template<KeyBindingSettings>(KeyBindingSettings.class));
lookupResult.addLookupListener(this);
updateActionsAndKits();
}
示例11: updateActionsAndKits
import org.netbeans.api.editor.settings.KeyBindingSettings; //導入依賴的package包/類
private void updateActionsAndKits() {
Collection<? extends KeyBindingSettings> instances = lookupResult.allInstances();
if (!instances.isEmpty()) {
updateActions(instances.iterator().next());
Map<String,List<List<KeyStroke>>> actionName2BindingLocal;
List<KitReference> kitRefsCopy;
synchronized (this) {
actionName2BindingLocal = actionName2Binding; // actionName2binding not mutated
@SuppressWarnings("unchecked")
List<KitReference> krc = (List<KitReference>) kitRefs.clone();
kitRefsCopy = krc;
}
updateKits(actionName2BindingLocal, kitRefsCopy);
}
}
示例12: 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");
}
示例13: 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;
}
示例14: testKeybindingsForSpecialTestMimeType
import org.netbeans.api.editor.settings.KeyBindingSettings; //導入依賴的package包/類
public void testKeybindingsForSpecialTestMimeType() throws Exception {
final String origMimeType = "text/x-orig";
final String specialTestMimeType = "test123456_" + origMimeType;
Lookup lookup = MimeLookup.getLookup(MimePath.parse(specialTestMimeType));
// Check the API class
Collection<? extends KeyBindingSettings> c = lookup.lookupAll(KeyBindingSettings.class);
assertEquals("Wrong number of kbs", 1, c.size());
KeyBindingSettings kbs = c.iterator().next();
assertNotNull("KBS should not be null", kbs);
assertTrue("Wrong kbs impl", kbs instanceof KeyBindingSettingsImpl.Immutable);
}
示例15: 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();
}
}