本文整理匯總了Java中org.openide.util.Utilities.stringToKey方法的典型用法代碼示例。如果您正苦於以下問題:Java Utilities.stringToKey方法的具體用法?Java Utilities.stringToKey怎麽用?Java Utilities.stringToKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.openide.util.Utilities
的用法示例。
在下文中一共展示了Utilities.stringToKey方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addKeyStroke
import org.openide.util.Utilities; //導入方法依賴的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
}
}
示例2: checkKeyBinding
import org.openide.util.Utilities; //導入方法依賴的package包/類
private void checkKeyBinding(MultiKeyBinding kb, String... keyStrokes) {
assertNotNull("Key binding should not be null", kb);
ArrayList<KeyStroke> list = new ArrayList<KeyStroke>();
for(String s : keyStrokes) {
KeyStroke stroke = Utilities.stringToKey(s);
if (stroke != null) {
list.add(stroke);
}
}
assertEquals("Wrong number of key strokes", list.size(), kb.getKeyStrokeCount());
for(int i = 0; i < list.size(); i++) {
assertEquals("KeyStroke[" + i + "] is different",
list.get(i), kb.getKeyStroke(i));
}
}
示例3: stringToKeyStroke
import org.openide.util.Utilities; //導入方法依賴的package包/類
public static KeyStroke stringToKeyStroke(String keyStroke) {
int modifiers = 0;
if (keyStroke.startsWith("Ctrl+")) { // NOI18N
modifiers |= InputEvent.CTRL_DOWN_MASK;
keyStroke = keyStroke.substring(5);
}
if (keyStroke.startsWith("Alt+")) { // NOI18N
modifiers |= InputEvent.ALT_DOWN_MASK;
keyStroke = keyStroke.substring(4);
}
if (keyStroke.startsWith("Shift+")) { // NOI18N
modifiers |= InputEvent.SHIFT_DOWN_MASK;
keyStroke = keyStroke.substring(6);
}
if (keyStroke.startsWith("Meta+")) { // NOI18N
modifiers |= InputEvent.META_DOWN_MASK;
keyStroke = keyStroke.substring(5);
}
KeyStroke ks = Utilities.stringToKey(keyStroke);
if (ks == null) {
return null;
}
KeyStroke result = KeyStroke.getKeyStroke(ks.getKeyCode(), modifiers);
return result;
}
示例4: stringToKeyStrokes2
import org.openide.util.Utilities; //導入方法依賴的package包/類
private static KeyStroke[] stringToKeyStrokes2(String key) {
List<KeyStroke> result = new ArrayList<KeyStroke>();
for (StringTokenizer st = new StringTokenizer(key, " "); st.hasMoreTokens();) { //NOI18N
String ks = st.nextToken().trim();
KeyStroke keyStroke = Utilities.stringToKey(ks);
if (keyStroke == null) {
LOG.warning("'" + ks + "' is not a valid keystroke"); //NOI18N
return null;
}
result.add(keyStroke);
}
return result.toArray(new KeyStroke[result.size()]);
}
示例5: getKeyStroke
import org.openide.util.Utilities; //導入方法依賴的package包/類
/**
* Convert human-readable keystroke name to {@link KeyStroke} object.
*/
public static @CheckForNull KeyStroke getKeyStroke(
@NonNull String keyStroke) {
int modifiers = 0;
while (true) {
if (keyStroke.startsWith(EMACS_CTRL)) {
modifiers |= InputEvent.CTRL_DOWN_MASK;
keyStroke = keyStroke.substring(EMACS_CTRL.length());
} else if (keyStroke.startsWith(EMACS_ALT)) {
modifiers |= InputEvent.ALT_DOWN_MASK;
keyStroke = keyStroke.substring(EMACS_ALT.length());
} else if (keyStroke.startsWith(EMACS_SHIFT)) {
modifiers |= InputEvent.SHIFT_DOWN_MASK;
keyStroke = keyStroke.substring(EMACS_SHIFT.length());
} else if (keyStroke.startsWith(EMACS_META)) {
modifiers |= InputEvent.META_DOWN_MASK;
keyStroke = keyStroke.substring(EMACS_META.length());
} else if (keyStroke.startsWith(STRING_ALT)) {
modifiers |= InputEvent.ALT_DOWN_MASK;
keyStroke = keyStroke.substring(STRING_ALT.length());
} else if (keyStroke.startsWith(STRING_META)) {
modifiers |= InputEvent.META_DOWN_MASK;
keyStroke = keyStroke.substring(STRING_META.length());
} else {
break;
}
}
KeyStroke ks = Utilities.stringToKey (keyStroke);
if (ks == null) { // Return null to indicate an invalid keystroke
return null;
} else {
KeyStroke result = KeyStroke.getKeyStroke (ks.getKeyCode (), modifiers);
return result;
}
}
示例6: testKeyBindingsImmutability
import org.openide.util.Utilities; //導入方法依賴的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: getExpandKey
import org.openide.util.Utilities; //導入方法依賴的package包/類
public KeyStroke getExpandKey() {
Preferences prefs = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class);
String ks = prefs.get(CODE_TEMPLATE_EXPAND_KEY, null);
if (ks != null) {
KeyStroke keyStroke = Utilities.stringToKey(ks);
if (keyStroke != null) {
return keyStroke;
}
}
return DEFAULT_EXPANSION_KEY;
}
示例8: actionPerformed
import org.openide.util.Utilities; //導入方法依賴的package包/類
/**
* Invoked when an action occurs.
*/
public void actionPerformed(final ActionEvent e) {
acceleratorKeyStroke = Utilities.stringToKey(e.getActionCommand());
if (acceleratorKeyStroke == null || acceleratorKeyStroke.getModifiers() == 0) {
ProfilerDialogs.displayError(
Bundle.ToggleProfilingPointAction_InvalidShortcutMsg(
Bundle.ToggleProfilingPointAction_ActionName()));
return;
}
if (warningDialogOpened) {
return;
}
if (ProfilingPointsManager.getDefault().isProfilingSessionInProgress()) {
warningDialogOpened = true;
ProfilerDialogs.displayWarning(
Bundle.ToggleProfilingPointAction_ProfilingProgressMsg());
warningDialogOpened = false;
return;
}
if (Utils.getCurrentLocation(0).equals(CodeProfilingPoint.Location.EMPTY)) {
warningDialogOpened = true;
ProfilerDialogs.displayWarning(
Bundle.ToggleProfilingPointAction_BadSourceMsg());
warningDialogOpened = false;
return;
}
ProfilingPointsSwitcher chooserFrame = getChooserFrame();
boolean toggleOff = false;
CodeProfilingPoint.Location location = Utils.getCurrentLocation(CodeProfilingPoint.Location.OFFSET_START);
for(CodeProfilingPoint pp : ProfilingPointsManager.getDefault().getProfilingPoints(CodeProfilingPoint.class, Utils.getCurrentProject(), false, false)) {
if (location.equals(pp.getLocation())) {
ProfilingPointsManager.getDefault().removeProfilingPoint(pp);
toggleOff = true;
}
}
if (!toggleOff) {
if (chooserFrame.isVisible()) {
nextFactory();
chooserFrame.setProfilingPointFactory((currentFactory == ppFactories.length) ? null : ppFactories[currentFactory],
currentFactory);
} else {
if (EditorSupport.currentlyInJavaEditor()) {
resetFactories();
chooserFrame.setProfilingPointFactory((currentFactory == ppFactories.length) ? null : ppFactories[currentFactory],
currentFactory);
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
chooserFrame.setVisible(true);
}
}
}
}
示例9: actionPerformed
import org.openide.util.Utilities; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent evt) {
boolean editors = true;
boolean views = !documentsOnly;
if( "immediately".equals( evt.getActionCommand() ) ) {
TopComponent activeTc = TopComponent.getRegistry().getActivated();
if( null != activeTc ) {
if( TopComponentTracker.getDefault().isEditorTopComponent( activeTc ) ) {
//switching in a document, go to some other document
views = false;
} else {
//switching in a view, go to some other view
editors = false;
views = true;
}
}
}
TopComponent[] documents = getRecentWindows(editors, views);
if (documents.length < 2) {
return;
}
if(!"immediately".equals(evt.getActionCommand()) && // NOI18N
!(evt.getSource() instanceof javax.swing.JMenuItem)) {
// #46800: fetch key directly from action command
KeyStroke keyStroke = Utilities.stringToKey(evt.getActionCommand());
if(keyStroke != null) {
int triggerKey = keyStroke.getKeyCode();
int reverseKey = KeyEvent.VK_SHIFT;
int releaseKey = 0;
int modifiers = keyStroke.getModifiers();
if((InputEvent.CTRL_MASK & modifiers) != 0) {
releaseKey = KeyEvent.VK_CONTROL;
} else if((InputEvent.ALT_MASK & modifiers) != 0) {
releaseKey = KeyEvent.VK_ALT;
} else if((InputEvent.META_MASK & modifiers) != 0) {
releaseKey = KeyEvent.VK_META;
}
if(releaseKey != 0) {
if (!KeyboardPopupSwitcher.isShown()) {
KeyboardPopupSwitcher.showPopup(documentsOnly, releaseKey, triggerKey, (evt.getModifiers() & KeyEvent.SHIFT_MASK) == 0);
}
return;
}
}
}
int documentIndex = (evt.getModifiers() & KeyEvent.SHIFT_MASK) == 0 ? 1 : documents.length-1;
TopComponent tc = documents[documentIndex];
// #37226 Unmaximized the other mode if needed.
WindowManagerImpl wm = WindowManagerImpl.getInstance();
ModeImpl mode = (ModeImpl) wm.findMode(tc);
if(mode != null && mode != wm.getCurrentMaximizedMode()) {
wm.switchMaximizedMode(null);
}
tc.requestActive();
}
示例10: afterLoad
import org.openide.util.Utilities; //導入方法依賴的package包/類
@Override
public void afterLoad(Map<Collection<KeyStroke>, MultiKeyBinding> map, MimePath mimePath, String profile, boolean defaults) throws IOException {
KeyStroke key = Utilities.stringToKey("CAS-Q");
map.put(Arrays.asList(key), new MultiKeyBinding(key, "filterB-injected-action-1"));
}
示例11: beforeSave
import org.openide.util.Utilities; //導入方法依賴的package包/類
@Override
public void beforeSave(Map<Collection<KeyStroke>, MultiKeyBinding> map, MimePath mimePath, String profile, boolean defaults) throws IOException {
KeyStroke key = Utilities.stringToKey("CAS-Q");
map.remove(Arrays.asList(key));
}
示例12: actionPerformed
import org.openide.util.Utilities; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent evt) {
List<DVThread> threads = getThreads();
int threadsCount = threads.size();
if (threadsCount < 1) {
Toolkit.getDefaultToolkit().beep();
return;
}
if(!"immediately".equals(evt.getActionCommand()) && // NOI18N
!(evt.getSource() instanceof javax.swing.JMenuItem)) {
// #46800: fetch key directly from action command
KeyStroke keyStroke = Utilities.stringToKey(evt.getActionCommand());
if(keyStroke != null) {
int triggerKey = keyStroke.getKeyCode();
int releaseKey = 0;
int modifiers = keyStroke.getModifiers();
if((InputEvent.CTRL_MASK & modifiers) != 0) {
releaseKey = KeyEvent.VK_CONTROL;
} else if((InputEvent.ALT_MASK & modifiers) != 0) {
releaseKey = KeyEvent.VK_ALT;
} else if((InputEvent.META_MASK & modifiers) != 0) {
releaseKey = InputEvent.META_MASK;
}
if(releaseKey != 0) {
if (!KeyboardPopupSwitcher.isShown()) {
KeyboardPopupSwitcher.selectItem(
createSwitcherItems(threads),
releaseKey, triggerKey, true, true); // (evt.getModifiers() & KeyEvent.SHIFT_MASK) == 0
}
return;
}
}
}
if (threadsCount == 1) {
threads.get(0).makeCurrent();
} else {
int index = (evt.getModifiers() & KeyEvent.SHIFT_MASK) == 0 ? 1 : threadsCount - 1;
threads.get(index).makeCurrent();
}
}