Example usage for javax.swing JMenu getAccelerator

List of usage examples for javax.swing JMenu getAccelerator

Introduction

In this page you can find the example usage for javax.swing JMenu getAccelerator.

Prototype

public KeyStroke getAccelerator() 

Source Link

Document

Returns the KeyStroke which serves as an accelerator for the menu item.

Usage

From source file:org.omegat.gui.shortcuts.PropertiesShortcutsTest.java

/**
 * Test of bindKeyStrokes method, of class PropertiesShortcuts.
 *//*from w w w .jav a  2 s . c om*/
@Test
public void testBindKeyStrokes_JMenuBar() {
    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
    shotcuts.bindKeyStrokes(menu);

    KeyStroke result = parent.getAccelerator();
    assertNull(result);

    result = child1.getAccelerator();
    assertNull(result);

    result = child2.getAccelerator();
    assertNull(result);

    KeyStroke expected = CTRL_P;
    result = grandchild1.getAccelerator();
    assertEquals(expected, result);

    expected = CTRL_X;
    result = grandchild2.getAccelerator();
    assertEquals(expected, result);
}

From source file:org.omegat.gui.shortcuts.PropertiesShortcutsTest.java

/**
 * Test of bindKeyStrokes method, of class PropertiesShortcuts.
 *///from  w w  w.ja  v a 2  s.com
@Test
public void testBindKeyStrokes_JMenuItem_Recursive() {
    // 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
    shotcuts.bindKeyStrokes(parent);

    KeyStroke result = parent.getAccelerator();
    assertNull(result);

    result = child1.getAccelerator();
    assertNull(result);

    result = child2.getAccelerator();
    assertNull(result);

    KeyStroke expected = CTRL_P;
    result = grandchild1.getAccelerator();
    assertEquals(expected, result);

    expected = CTRL_X;
    result = grandchild2.getAccelerator();
    assertEquals(expected, result);
}