Java Code Examples for javax.swing.JMenu#addNotify()

The following examples show how to use javax.swing.JMenu#addNotify() . 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: ActionsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testPopupTextIsTaken() throws Exception {
    Action action = new ActionsTest.TestAction();
    JMenuItem item = new JMenuItem();
    JMenu jmenu = new JMenu();
    jmenu.addNotify();
    assertTrue("Peer created", jmenu.isDisplayable());
    jmenu.getPopupMenu().addNotify();
    assertTrue("Peer for popup", jmenu.getPopupMenu().isDisplayable());

    action.putValue("popupText", "&Ahoj");
    action.putValue("menuText", "&Ble");
    action.putValue(action.NAME, "&Mle");
    
    Actions.connect(item, action, true);
    
    assertEquals(Utilities.isMac() ? 0 : 'A', item.getMnemonic());
    assertEquals("Ahoj", item.getText());
}
 
Example 2
Source File: ActionsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testMenuTextIsTaken() throws Exception {
    Action action = new ActionsTest.TestAction();
    JMenuItem item = new JMenuItem();
    JMenu jmenu = new JMenu();
    jmenu.addNotify();
    assertTrue("Peer created", jmenu.isDisplayable());
    jmenu.getPopupMenu().addNotify();
    assertTrue("Peer for popup", jmenu.getPopupMenu().isDisplayable());

    //action.putValue("popupText", "&Ahoj");
    action.putValue("menuText", "&Ble");
    action.putValue(action.NAME, "&Mle");
    
    Actions.connect(item, action, false);
    
    assertEquals(Utilities.isMac() ? 0 : 'B', item.getMnemonic());
    assertEquals("Ble", item.getText());
}
 
Example 3
Source File: ActionsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testActionNameIsTaken() throws Exception {
    Action action = new ActionsTest.TestAction();
    JMenuItem item = new JMenuItem();
    JMenu jmenu = new JMenu();
    jmenu.addNotify();
    assertTrue("Peer created", jmenu.isDisplayable());
    jmenu.getPopupMenu().addNotify();
    assertTrue("Peer for popup", jmenu.getPopupMenu().isDisplayable());

    //action.putValue("popupText", "&Ahoj");
    //action.putValue("menuText", "&Ble");
    action.putValue(action.NAME, "&Mle");
    
    Actions.connect(item, action, false);
    
    assertEquals(Utilities.isMac() ? 0 : 'M', item.getMnemonic());
    assertEquals("Mle", item.getText());
}
 
Example 4
Source File: LookupSensitiveActionBase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void doTestRefreshAfterBeingHidden(boolean clone, boolean menu) throws IOException {
    InstanceContent ic = new InstanceContent();
    Lookup context = new AbstractLookup(ic);
    
    
    Action instance;
    if (clone) {
        Action a = create(Lookup.EMPTY);
        instance = ((ContextAwareAction)a).createContextAwareInstance(context);
    } else {
        instance = create(context);
    }
    
    if (!(instance instanceof Presenter.Popup)) {
        // cannot test, skipping
        return;
    }
    
    
    CharSequence log1 = Log.enable("org.netbeans.modules.project.ui.actions", Level.FINER);
    assertFalse("Disabled", instance.isEnabled());
    if (!log1.toString().contains("Refreshing")) {
        fail("Should be refreshing: " + log1);
    }
    
    JMenuItem item = item(instance, menu);
    JMenu jmenu = new JMenu();
    jmenu.addNotify();
    assertTrue("Peer created", jmenu.isDisplayable());
    jmenu.getPopupMenu().addNotify();
    assertTrue("Peer for popup", jmenu.getPopupMenu().isDisplayable());
    
    item.addPropertyChangeListener(this);
    jmenu.add(item);
    assertEquals("anncessor properly changes, this means the actions framework is activated", 1, ancEvent);
    
    
    assertFalse("Not enabled", item.isEnabled());
    FileObject pfo = TestSupport.createTestProject(FileUtil.createMemoryFileSystem().getRoot(), "yaya");
    FileObject pf2 = TestSupport.createTestProject(FileUtil.createMemoryFileSystem().getRoot(), "blabla");
    MockServices.setServices(TestSupport.TestProjectFactory.class);
    Project p = ProjectManager.getDefault().findProject(pfo);
    Project p2 = ProjectManager.getDefault().findProject(pf2);
    if (p instanceof TestSupport.TestProject) {
        enhanceProject((TestSupport.TestProject)p);
    }
    if (p2 instanceof TestSupport.TestProject) {
        enhanceProject((TestSupport.TestProject)p2);
    }
    
    assertNotNull("Project found", p);
    assertNotNull("Project2 found", p2);
    OpenProjects.getDefault().open(new Project[] { p }, false);
    ic.add(p);
    assertTrue("enabled", item.isEnabled());
    assertEquals("One change", 1, change);

    if (menu) {
        item.removeNotify();
        CharSequence log2 = Log.enable("org.netbeans.modules.project.ui.actions", Level.FINER);
        ic.remove(p);
        ic.add(p2);
        if (log2.length() > 0) {
            fail("Nothing shall happen:\n" + log2);
        }
    } // irrelevant for popups
}