本文整理了Java中javax.swing.JMenuItem.getAccelerator()
方法的一些代码示例,展示了JMenuItem.getAccelerator()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JMenuItem.getAccelerator()
方法的具体详情如下:
包路径:javax.swing.JMenuItem
类名称:JMenuItem
方法名:getAccelerator
暂无
代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide
public void update(Observable o, Object arg) {
synchronized (menuActionLock) {
Iterator it = menuActionCache.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry)it.next();
Action act = (Action)entry.getKey();
WeakReference ref = (WeakReference)entry.getValue();
JMenuItem mn = (JMenuItem)ref.get();
if (act != null && mn != null) {
KeyStroke actKey = (KeyStroke)act.getValue(Action.ACCELERATOR_KEY);
KeyStroke mnKey = mn.getAccelerator();
if ((mnKey == null && actKey != null) ||
(mnKey != null && actKey == null) ||
(mnKey != null && actKey != null && !actKey.equals(mnKey))) {
mn.setAccelerator(actKey);
}
}
}
}
}
});
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide
public void update(Observable o, Object arg) {
synchronized (menuActionLock) {
Iterator it = menuActionCache.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry)it.next();
Action act = (Action)entry.getKey();
WeakReference ref = (WeakReference)entry.getValue();
JMenuItem mn = (JMenuItem)ref.get();
if (act != null && mn != null) {
KeyStroke actKey = (KeyStroke)act.getValue(Action.ACCELERATOR_KEY);
KeyStroke mnKey = mn.getAccelerator();
if ((mnKey == null && actKey != null) ||
(mnKey != null && actKey == null) ||
(mnKey != null && actKey != null && !actKey.equals(mnKey))) {
mn.setAccelerator(actKey);
}
}
}
}
}
});
代码示例来源:origin: jpcsp/jpcsp
/**
* Add accelerators to the global action map of MainGUI.
*
* This function will traverse a MenuElement tree to find all JMenuItems and
* to add accelerators if available for the given menu item.
*
* The element tree is traversed in a recursive manner.
*
* @param me The root menu element to start.
*/
private void globalAccelFromMenu(MenuElement me) {
for (MenuElement element : me.getSubElements()) {
// check for JMenu before JMenuItem, as JMenuItem is derived from JMenu
if ((element instanceof JPopupMenu) || (element instanceof JMenu)) {
// recursively do the same for underlying menus
globalAccelFromMenu(element);
} else if (element instanceof JMenuItem) {
JMenuItem item = (JMenuItem) element;
// only check if the accelerator exists (i.e. is not null)
// if no ActionListeners exist, an empty array is returned
if (item.getAccelerator() != null) {
actionListenerMap.put(item.getAccelerator(), item.getActionListeners());
}
}
}
}
代码示例来源:origin: net.sf.tinylaf/tinylaf
void updateAcceleratorBinding() {
KeyStroke accelerator = menuItem.getAccelerator();
if(windowInputMap != null) {
windowInputMap.clear();
}
if(accelerator != null) {
if(windowInputMap == null) {
windowInputMap = createInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
SwingUtilities.replaceUIInputMap(menuItem,
JComponent.WHEN_IN_FOCUSED_WINDOW, windowInputMap);
}
windowInputMap.put(accelerator, "doClick");
}
}
代码示例来源:origin: com.jidesoft/jide-oss
void updateAcceleratorBinding() {
KeyStroke accelerator = menuItem.getAccelerator();
if (windowInputMap != null) {
windowInputMap.clear();
}
if (accelerator != null) {
if (windowInputMap == null) {
windowInputMap = createInputMap(JComponent.
WHEN_IN_FOCUSED_WINDOW);
SwingUtilities.replaceUIInputMap(menuItem,
JComponent.WHEN_IN_FOCUSED_WINDOW, windowInputMap);
}
windowInputMap.put(accelerator, "doClick");
}
}
代码示例来源:origin: com.jidesoft/jide-oss
void updateAcceleratorBinding() {
KeyStroke accelerator = menuItem.getAccelerator();
if (windowInputMap != null) {
windowInputMap.clear();
}
if (accelerator != null) {
if (windowInputMap == null) {
windowInputMap = createInputMap(JComponent.
WHEN_IN_FOCUSED_WINDOW);
SwingUtilities.replaceUIInputMap(menuItem,
JComponent.WHEN_IN_FOCUSED_WINDOW, windowInputMap);
}
windowInputMap.put(accelerator, "doClick");
}
}
代码示例来源:origin: com.jidesoft/jide-oss
void updateAcceleratorBinding() {
KeyStroke accelerator = menuItem.getAccelerator();
if (windowInputMap != null) {
windowInputMap.clear();
}
if (accelerator != null) {
if (windowInputMap == null) {
windowInputMap = createInputMap(JComponent.
WHEN_IN_FOCUSED_WINDOW);
SwingUtilities.replaceUIInputMap(menuItem,
JComponent.WHEN_IN_FOCUSED_WINDOW, windowInputMap);
}
windowInputMap.put(accelerator, "doClick");
}
}
代码示例来源:origin: freeplane/freeplane
/** there are little reasons to use this in scripts. */
public static Node findAssignedMenuItemNodeRecursively(final DefaultMutableTreeNode menubarNode,
final KeyStroke keystroke) {
final Enumeration<?> children = menubarNode.children();
while (children.hasMoreElements()) {
final Node child = (Node) children.nextElement();
final Object childUserObject = child.getUserObject();
if (childUserObject instanceof JMenuItem) {
final JMenuItem childMenuItem = (JMenuItem) childUserObject;
if (keystroke.equals(childMenuItem.getAccelerator())) {
return child;
}
}
// recurse
final Node assignedMenuItemNode = findAssignedMenuItemNodeRecursively(child, keystroke);
if (assignedMenuItemNode != null)
return assignedMenuItemNode;
}
return null;
}
/**
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/toniclf
/** Updates the accelerator bindings for the associated menu item
* (in the case that they have changed).
*/
void updateMyAcceleratorBinding()
{
KeyStroke accelerator= menuItem.getAccelerator();
if (windowInputMap != null)
{
windowInputMap.clear();
}
if (accelerator != null)
{
if (windowInputMap == null)
{
windowInputMap= createMyInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
SwingUtilities.replaceUIInputMap(
menuItem,
JComponent.WHEN_IN_FOCUSED_WINDOW,
windowInputMap);
}
windowInputMap.put(accelerator, "doClick");
}
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/toniclf
int maxTextWidth=fm.stringWidth(getAcceleratorText(item.getAccelerator()));
maxTextWidth=Math.max(maxTextWidth, fm.stringWidth(getAcceleratorText(item.getAccelerator())));
maxTextWidth=Math.max(maxTextWidth, fm.stringWidth(getAcceleratorText(currItem.getAccelerator())));
代码示例来源:origin: mucommander/mucommander
/**
* Does things that should be done to all menu items created from
* <code>MuAction</code>s.
* <ol>
* <li>If the provided action has an icon, it would by default get displayed in the menu item.
* Since icons have nothing to do in menus, let's make sure the menu item has no icon.</li>
* <li>If the action has a keyboard shortcut that conflicts with
* the menu's internal ones (enter, space and escape), they will
* not be used.</li>
* </ol>
* @param item menu item to take care of.
*/
public static void configureActionMenuItem(JMenuItem item) {
item.setIcon(null);
KeyStroke stroke = item.getAccelerator();
if (stroke != null && stroke.getModifiers() == 0 &&
(stroke.getKeyCode() == KeyEvent.VK_ENTER || stroke.getKeyCode() == KeyEvent.VK_SPACE || stroke.getKeyCode() == KeyEvent.VK_ESCAPE))
item.setAccelerator(null);
}
代码示例来源:origin: net.sf.squirrel-sql/squirrel-sql
private JMenu cloneMenu(JMenu menu)
{
JMenu ret = new JMenu(menu.getText());
for (int i = 0; i < menu.getItemCount(); i++)
{
JMenuItem toClone = menu.getItem(i);
if (toClone instanceof JMenu)
{
ret.add(cloneMenu((JMenu) toClone));
}
else if(toClone instanceof JMenuItem)
{
JMenuItem clone = new JMenuItem(toClone.getText(), toClone.getIcon());
clone.setMnemonic(toClone.getMnemonic());
clone.setAction(toClone.getAction());
clone.setAccelerator(toClone.getAccelerator());
clone.setToolTipText(toClone.getToolTipText());
ret.add(clone);
}
else
{
ret.addSeparator();
}
}
return ret;
}
代码示例来源:origin: realXuJiang/bigtable-sql
private JMenu cloneMenu(JMenu menu)
{
JMenu ret = new JMenu(menu.getText());
for (int i = 0; i < menu.getItemCount(); i++)
{
JMenuItem toClone = menu.getItem(i);
if (toClone instanceof JMenu)
{
ret.add(cloneMenu((JMenu) toClone));
}
else if(toClone instanceof JMenuItem)
{
JMenuItem clone = new JMenuItem(toClone.getText(), toClone.getIcon());
clone.setMnemonic(toClone.getMnemonic());
clone.setAction(toClone.getAction());
clone.setAccelerator(toClone.getAccelerator());
clone.setToolTipText(toClone.getToolTipText());
ret.add(clone);
}
else
{
ret.addSeparator();
}
}
return ret;
}
代码示例来源:origin: omegat-org/omegat
/**
* Test of bindKeyStrokes method, of class PropertiesShortcuts.
*/
@Test
public void testBindKeyStrokesJMenuBar() {
JMenuBar menu = new JMenuBar();
JMenu parent = new JMenu();
JMenuItem child1 = new JMenu();
JMenuItem child2 = new JMenuItem();
child2.setActionCommand(TEST_DELETE);
child2.setAccelerator(CTRL_D);
JMenuItem grandchild1 = new JMenuItem();
grandchild1.setActionCommand(TEST_USER_1);
JMenuItem grandchild2 = new JMenuItem();
grandchild2.setActionCommand(OUT_OF_LIST);
grandchild2.setAccelerator(CTRL_X);
menu.add(parent);
parent.add(child1);
parent.add(child2);
child1.add(grandchild1);
child1.add(grandchild2);
// bind
shortcuts.bindKeyStrokes(menu);
assertNull(parent.getAccelerator());
assertNull(child1.getAccelerator());
assertNull(child2.getAccelerator());
assertEquals(CTRL_P, grandchild1.getAccelerator());
assertEquals(CTRL_X, grandchild2.getAccelerator());
}
代码示例来源:origin: omegat-org/omegat
/**
* Test of bindKeyStrokes method, of class PropertiesShortcuts.
*/
@Test
public void testBindKeyStrokesJMenuItem() {
// case JMenuItem with no children
JMenuItem item = new JMenuItem();
item.setActionCommand(TEST_SAVE);
assertNull(item.getAccelerator()); // before binding
shortcuts.bindKeyStrokes(item); // bind
assertEquals(CTRL_S, item.getAccelerator()); // after binding(1)
item.setActionCommand(TEST_DELETE);
shortcuts.bindKeyStrokes(item); // bind
assertNull(item.getAccelerator()); // after binding(2)
item.setActionCommand(OUT_OF_LIST);
item.setAccelerator(CTRL_D);
shortcuts.bindKeyStrokes(item); // bind
assertEquals(CTRL_D, item.getAccelerator()); // after binding(3) - nothing has changed
}
代码示例来源:origin: omegat-org/omegat
/**
* Test of bindKeyStrokes method, of class PropertiesShortcuts.
*/
@Test
public void testBindKeyStrokesJMenuItemRecursive() {
// case JMenu with children
JMenu parent = new JMenu();
JMenuItem child1 = new JMenu();
JMenuItem child2 = new JMenuItem();
child2.setActionCommand(TEST_DELETE);
child2.setAccelerator(CTRL_D);
JMenuItem grandchild1 = new JMenuItem();
grandchild1.setActionCommand(TEST_USER_1);
JMenuItem grandchild2 = new JMenuItem();
grandchild2.setActionCommand(OUT_OF_LIST);
grandchild2.setAccelerator(CTRL_X);
parent.add(child1);
parent.add(child2);
child1.add(grandchild1);
child1.add(grandchild2);
// bind
shortcuts.bindKeyStrokes(parent);
assertNull(parent.getAccelerator());
assertNull(child1.getAccelerator());
assertNull(child2.getAccelerator());
assertEquals(CTRL_P, grandchild1.getAccelerator());
assertEquals(CTRL_X, grandchild2.getAccelerator());
}
代码示例来源:origin: freeplane/freeplane
@Test
public void createsMenuButtonWithAcceleratedAction() {
final EntryAccessor entryAccessor = new EntryAccessor();
entryAccessor.setComponent(menuEntry, menu);
menuEntry.addChild(actionEntry);
final KeyStroke keyStroke = KeyStroke.getKeyStroke('A');
when(accelerators.getAccelerator(action)).thenReturn(keyStroke);
menuActionGroupBuilder.visit(actionEntry);
JMenuItem item = (JMenuItem) new EntryAccessor().getComponent(actionEntry);
Assert.assertThat(item.getAccelerator(), equalTo(keyStroke));
}
代码示例来源:origin: freeplane/freeplane
@Test
public void setsKeystroke() throws Exception {
final EntriesForAction entriesForAction = new EntriesForAction();
final MenuAcceleratorChangeListener menuAcceleratorChangeListener = new MenuAcceleratorChangeListener(entriesForAction);
final AFreeplaneAction action = mock(AFreeplaneAction.class);
Entry actionEntry = new Entry();
final JMenuItem menu = new JMenuItem();
new EntryAccessor().setComponent(actionEntry, menu);
entriesForAction.registerEntry(action, actionEntry);
final KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 0);
menuAcceleratorChangeListener.acceleratorChanged(action, null, keyStroke);
Assert.assertThat(menu.getAccelerator(), equalTo(keyStroke));
}
}
代码示例来源:origin: org.fudaa.framework.fudaa/fudaa-common
/**
* Remplace un item menu en provenance de Bu par une action, plus gnraliste.
* @param _command La commande.
* @return L'action de remplacement, ou null si la commande n'existait pas.
*/
protected EbliActionAbstract replaceItemByAction(String _command) {
JMenuItem it=((JMenuItem)getMainMenuBar().getMenuItem(_command));
if (it==null) return null;
BuMenu mn=(BuMenu)getMainMenuBar().getMenuForAction(_command);
if (mn==null) return null;
int idx=mn.indexOf(_command);
if (idx==-1) return null;
EbliActionAbstract act=new EbliActionSimple(it.getText(),it.getIcon(),it.getActionCommand()) {
public void actionPerformed(ActionEvent _evt) {
FudaaCommonImplementation.this.actionPerformed(_evt);
}
};
act.setDefaultToolTip(it.getToolTipText());
act.setKey(it.getAccelerator());
mn.remove(idx);
mn.insert(act,idx)
// Pour rester compatible avec Bu.
.setName("mi"+_command);
return act;
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/toniclf
KeyStroke accelerator= b.getAccelerator();
String acceleratorText= "";
内容来源于网络,如有侵权,请联系作者删除!