Java Code Examples for org.openide.util.Utilities#stringToKeys()
The following examples show how to use
org.openide.util.Utilities#stringToKeys() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeybindingStorageTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testWriteKeybindings() throws IOException { // Create new keybindings Map<Collection<KeyStroke>, MultiKeyBinding> newKeybindings = new HashMap<Collection<KeyStroke>, MultiKeyBinding>(); MultiKeyBinding mkb = new MultiKeyBinding(Utilities.stringToKeys("D-D D"), "the-super-action"); newKeybindings.put(mkb.getKeyStrokeList(), mkb); EditorSettingsStorage<Collection<KeyStroke>, MultiKeyBinding> ess = EditorSettingsStorage.<Collection<KeyStroke>, MultiKeyBinding>get(KeyMapsStorage.ID); ess.save(MimePath.EMPTY, "MyProfileXyz", false, newKeybindings); FileObject settingFile = FileUtil.getConfigFile("Editors/Keybindings/MyProfileXyz/org-netbeans-modules-editor-settings-CustomKeybindings.xml"); assertNotNull("Can't find custom settingFile", settingFile); assertEquals("Wrong mime type", KeyMapsStorage.MIME_TYPE, settingFile.getMIMEType()); // Force loading from the files StorageImpl<Collection<KeyStroke>, MultiKeyBinding> storage = new StorageImpl<Collection<KeyStroke>, MultiKeyBinding>(new KeyMapsStorage(), null); Map<Collection<KeyStroke>, MultiKeyBinding> keybindings = storage.load(MimePath.EMPTY, "MyProfileXyz", false); //NOI18N assertNotNull("Keybindings map should not be null", keybindings); assertEquals("Wrong number of keybindings", 1, keybindings.size()); checkKeybinding(keybindings, "the-super-action", "D-D D"); }
Example 2
Source File: MacrosModel.java From netbeans with Apache License 2.0 | 6 votes |
public void setShortcuts(Set<String> shortcuts) { List<MultiKeyBinding> list = new ArrayList<MultiKeyBinding>(shortcuts.size()); for (String shortcut : shortcuts) { KeyStroke[] keys = Utilities.stringToKeys(shortcut); if (keys == null) { LOG.warning("Could not decode keystrokes from: " + shortcut); } else { list.add(new MultiKeyBinding(keys, MacroDialogSupport.RunMacroAction.runMacroAction)); //NOI18N } } if (Utilities.compareObjects(new HashSet<MultiKeyBinding>(getShortcuts()), new HashSet<MultiKeyBinding>(list))) { return; } cloneOnModify(); List<? extends MultiKeyBinding> oldShortcuts = this.shortcuts; this.shortcuts = list; pcs.firePropertyChange(PROP_SHORTCUTS, oldShortcuts, shortcuts); model.fireTableModelChange(this, SHORTCUTS_COLUMN_IDX); model.fireChanged(); }
Example 3
Source File: ShortcutsFinderImpl.java From netbeans with Apache License 2.0 | 5 votes |
/** * Converts Map (ShortcutAction > Set (String (shortcut AS-P))) to * Map (ShortcutAction > Set (String (shortcut Alt+Shift+P))). */ protected static Map<ShortcutAction, Set<String>> convertFromEmacs (Map<ShortcutAction, Set<String>> emacs) { Map<ShortcutAction, Set<String>> result = new HashMap<ShortcutAction, Set<String>> (); for (Map.Entry<ShortcutAction, Set<String>> entry: emacs.entrySet()) { ShortcutAction action = entry.getKey(); Set<String> shortcuts = new LinkedHashSet<String> (); for (String emacsShortcut: entry.getValue()) { KeyStroke[] keyStroke = Utilities.stringToKeys (emacsShortcut); shortcuts.add (KeyStrokeUtils.getKeyStrokesAsText (keyStroke, " ")); } result.put (action, shortcuts); } return result; }
Example 4
Source File: ActionProcessor.java From netbeans with Apache License 2.0 | 4 votes |
private void processReferences(Element e, ActionReference ref, ActionID aid) throws LayerGenerationException { if (!ref.id().category().isEmpty() && !ref.id().id().isEmpty()) { if (!aid.id().equals(ref.id().id()) || !aid.category().equals(ref.id().category())) { throw new LayerGenerationException("Can't specify id() attribute when @ActionID provided on the element", e, processingEnv, aid); } } String name = ref.name(); if (name.isEmpty()) { name = aid.id().replace('.', '-'); } if (ref.path().startsWith("Shortcuts")) { KeyStroke[] stroke = Utilities.stringToKeys(name); if (stroke == null) { throw new LayerGenerationException( "Registrations in Shortcuts folder need to represent a key. " + "Specify value for 'name' attribute.\n" + "See org.openide.util.Utilities.stringToKeys for possible values. Current " + "name=\"" + name + "\" is not valid.\n", e, processingEnv, ref, "path" ); } } File f = layer(e).file(ref.path() + "/" + name + ".shadow"); f.stringvalue("originalFile", "Actions/" + aid.category() + "/" + aid.id().replace('.', '-') + ".instance"); f.position(ref.position()); f.write(); if (ref.separatorAfter() != Integer.MAX_VALUE) { if (ref.position() == Integer.MAX_VALUE || ref.position() >= ref.separatorAfter()) { throw new LayerGenerationException("separatorAfter() must be greater than position()", e, processingEnv, ref); } File after = layer(e).file(ref.path() + "/" + name + "-separatorAfter.instance"); after.newvalue("instanceCreate", JSeparator.class.getName()); after.position(ref.separatorAfter()); after.write(); } if (ref.separatorBefore() != Integer.MAX_VALUE) { if (ref.position() == Integer.MAX_VALUE || ref.position() <= ref.separatorBefore()) { throw new LayerGenerationException("separatorBefore() must be lower than position()", e, processingEnv, ref); } File before = layer(e).file(ref.path() + "/" + name + "-separatorBefore.instance"); before.newvalue("instanceCreate", JSeparator.class.getName()); before.position(ref.separatorBefore()); before.write(); } }
Example 5
Source File: KeyMapsStorage.java From netbeans with Apache License 2.0 | 4 votes |
public @Override void startElement( String uri, String localName, String name, Attributes attributes ) throws SAXException { try { if (name.equals(ROOT)) { // We don't read anything from the root element } else if (name.equals(E_BIND)) { String key = attributes.getValue(A_KEY); if (isModuleFile() && isDefaultProfile() && key != null && key.length() > 0) { // check the key, it should never start with 'A' or 'C', because // these characters do not work on MAC, Alt should be coded as 'O' // and Ctrl as 'D' int idx = key.indexOf('-'); //NOI18N String proccessedFilePath = getProcessedFile().getPath(); if (idx != -1 && (key.charAt(0) == 'A' || key.charAt(0) == 'C') && !proccessedFilePath.endsWith("-mac.xml")) { //NOI18N LOG.warning("The keybinding '" + key + //NOI18N "' in " + proccessedFilePath + " may not work correctly on Mac. " + //NOI18N "Keybindings starting with Alt or Ctrl should " + //NOI18N "be coded with latin capital letters 'O' " + //NOI18N "or 'D' respectively. For details see org.openide.util.Utilities.stringToKey()."); //NOI18N } } KeyStroke[] shortcut = Utilities.stringToKeys(key.replaceAll("\\$", " ")); // NOI18N String remove = attributes.getValue(A_REMOVE); if (Boolean.valueOf(remove)) { removedShortcuts.add(Arrays.asList(shortcut)); } else { String actionName = attributes.getValue(A_ACTION_NAME); if (actionName != null) { MultiKeyBinding mkb = new MultiKeyBinding(shortcut, actionName); LOG.fine("Adding: Key: '" + key + "' Action: '" + mkb.getActionName() + "'"); MultiKeyBinding duplicate = keyMap.put(mkb.getKeyStrokeList(), mkb); if (duplicate != null && !duplicate.getActionName().equals(mkb.getActionName())) { LOG.warning("Duplicate shortcut '" + key + "' definition; rebound from '" + duplicate.getActionName() //NOI18N + "' to '" + mkb.getActionName() + "' in (" + getProcessedFile().getPath() + ")."); //NOI18N } } else { LOG.warning("Ignoring keybinding '" + key + "' with no action name."); //NOI18N } } } } catch (Exception ex) { LOG.log(Level.WARNING, "Can't parse keybindings file " + getProcessedFile().getPath(), ex); //NOI18N } }