本文整理汇总了Java中org.openide.util.actions.Presenter.Popup方法的典型用法代码示例。如果您正苦于以下问题:Java Presenter.Popup方法的具体用法?Java Presenter.Popup怎么用?Java Presenter.Popup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.util.actions.Presenter
的用法示例。
在下文中一共展示了Presenter.Popup方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testIsPopupVisible
import org.openide.util.actions.Presenter; //导入方法依赖的package包/类
public void testIsPopupVisible() throws Exception {
ToolsAction ta = ToolsAction.get(ToolsAction.class);
Lookup lkp = Lookups.singleton(this);
FileObject fo = FileUtil.createFolder(FileUtil.getConfigRoot(), "UI/ToolActions");
assertNotNull("ToolActions folder found", fo);
fo.createFolder("Cat1").createData("org-openide-actions-SaveAction.instance").setAttribute("position", 100);
Action a = ta.createContextAwareInstance(lkp);
assertTrue("It is menu presenter", a instanceof Presenter.Popup);
Presenter.Popup pp = (Presenter.Popup)a;
JMenuItem item = pp.getPopupPresenter();
assertTrue("Item is enabled", item.isEnabled());
DynamicMenuContent dmc = (DynamicMenuContent)item;
assertEquals("One presenter to delegte to", 1, dmc.getMenuPresenters().length);
}
示例2: createPopupMenu
import org.openide.util.actions.Presenter; //导入方法依赖的package包/类
public static JPopupMenu createPopupMenu(String path) {
JPopupMenu popUp = new JPopupMenu();
List<? extends Action> actions = Utilities.actionsForPath(path);
if(actions.isEmpty())
return null;
for(Action action : actions) {
if(action instanceof Presenter.Popup) {
popUp.add(((Presenter.Popup)action).getPopupPresenter());
} else if (action == null) {
popUp.addSeparator();
} else {
popUp.add(createActionPopUpItem(action));
}
}
return popUp;
}
示例3: getPopupMenuItem
import org.openide.util.actions.Presenter; //导入方法依赖的package包/类
private static JMenuItem getPopupMenuItem(Action action) {
JMenuItem popupItem = null;
if (action instanceof BaseAction) {
popupItem = ((BaseAction) action).getPopupMenuItem(null);
}
if (popupItem == null) {
if (action instanceof Presenter.Popup) {
popupItem = ((Presenter.Popup) action).getPopupPresenter();
}
}
return popupItem;
}
示例4: resolveInstance
import org.openide.util.actions.Presenter; //导入方法依赖的package包/类
private static void resolveInstance(Object instance, List<JComponent> result) throws IOException {
if (instance instanceof Presenter.Popup) {
JMenuItem temp = ((Presenter.Popup) instance).getPopupPresenter();
result.add(temp);
} else if (instance instanceof JSeparator) {
result.add(null);
} else if (instance instanceof JComponent) {
result.add((JComponent) instance);
} else if (instance instanceof Action) {
Actions.MenuItem mi = new Actions.MenuItem((Action) instance, true);
result.add(mi);
} else {
throw new IOException(String.format("Unsupported instance: %s, class: %s", instance, instance.getClass())); // NOI18N
}
}
示例5: item
import org.openide.util.actions.Presenter; //导入方法依赖的package包/类
private JMenuItem item(Action a, boolean menu) {
if (menu) {
if (a instanceof Presenter.Menu) {
return ((Presenter.Menu) a).getMenuPresenter();
} else {
return new JMenuItem(a);
}
} else {
if (a instanceof Presenter.Popup) {
return ((Presenter.Popup)a).getPopupPresenter();
} else {
return new JMenuItem(a);
}
}
}
示例6: createmenuItem
import org.openide.util.actions.Presenter; //导入方法依赖的package包/类
private JMenuItem createmenuItem(Action action) {
JMenuItem item;
if (action instanceof Presenter.Menu) {
item = ((Presenter.Menu) action).getMenuPresenter();
} else if (action instanceof Presenter.Popup) {
item = ((Presenter.Popup) action).getPopupPresenter();
} else {
item = new JMenuItem();
Actions.connect(item, action, true);
}
return item;
}
示例7: toMenuItem
import org.openide.util.actions.Presenter; //导入方法依赖的package包/类
/**
* Creates a menu item from an action.
*
* @param action an action
* @return JMenuItem
*/
public static JMenuItem toMenuItem(Action action) {
JMenuItem item;
if (action instanceof Presenter.Menu) {
item = ((Presenter.Menu) action).getMenuPresenter();
} else if (action instanceof Presenter.Popup) {
item = ((Presenter.Popup) action).getPopupPresenter();
} else {
item = new JMenuItem();
Actions.connect(item, action, false);
}
return item;
}
示例8: createMenu
import org.openide.util.actions.Presenter; //导入方法依赖的package包/类
private JMenuItem[] createMenu (Collection coll) {
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug (
"\n--> CollectSystemAction.createMenu: ( " + coll + " )");
ArrayList items = new ArrayList ();
Iterator it = coll.iterator();
while (it.hasNext ()) {
SystemAction a = (SystemAction) it.next();
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug (
"-*- CollectSystemAction.createMenu: next action " + a +
" -- " + ( a.isEnabled() ? "<enabled>" : "[disabled]" ) );
if ( a.isEnabled() ) {
JMenuItem item = null;
if (a instanceof Presenter.Popup) {
item = ((Presenter.Popup)a).getPopupPresenter ();
}
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug
("-*- CollectSystemAction.createMenu: menu item = " + item);
// test if we obtained the item
if (item != null) {
items.add (item);
}
}
}
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug
("<-- CollectSystemAction.createMenu: all items = " + items + "\n");
JMenuItem[] array = new JMenuItem [items.size ()];
items.toArray (array);
return array;
}
示例9: warmUpToolsPopupMenuItem
import org.openide.util.actions.Presenter; //导入方法依赖的package包/类
/** Warms up tools action popup menu item. */
private static void warmUpToolsPopupMenuItem() {
SystemAction toolsAction = SystemAction.get(ToolsAction.class);
if(toolsAction instanceof ContextAwareAction) {
// Here is important to create proper lookup
// to warm up Tools sub actions.
Lookup lookup = new org.openide.util.lookup.ProxyLookup(
new Lookup[] {
// This part of lookup causes warm up of Node (cookie) actions.
new AbstractNode(Children.LEAF).getLookup(),
// This part of lookup causes warm up of Callback actions.
new TopComponent().getLookup()
}
);
Action action = ((ContextAwareAction)toolsAction)
.createContextAwareInstance(lookup);
if(action instanceof Presenter.Popup) {
JMenuItem toolsMenuItem = ((Presenter.Popup)action)
.getPopupPresenter();
if(toolsMenuItem instanceof Runnable) {
// This actually makes the warm up.
// See ToolsAction.Popup impl.
((Runnable)toolsMenuItem).run();
}
}
}
}
示例10: doTestRefreshAfterBeingHidden
import org.openide.util.actions.Presenter; //导入方法依赖的package包/类
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
}
示例11: createMenu
import org.openide.util.actions.Presenter; //导入方法依赖的package包/类
/** Creates list of menu items that should be used for given
* data object.
* @param en enumeration of SystemAction that should be added
* into the menu if enabled and if not duplicated
*/
static JMenuItem[] createMenu (Enumeration en, boolean popUp, Lookup lookup) {
en = new RemoveDuplicatesEnumeration (en);
ArrayList items = new ArrayList ();
while (en.hasMoreElements ()) {
Action a = (Action)en.nextElement ();
// Retrieve context sensitive action instance if possible.
if(lookup != null && a instanceof ContextAwareAction) {
a = ((ContextAwareAction)a).createContextAwareInstance(lookup);
}
boolean enabled = false;
try {
enabled = a.isEnabled();
} catch (RuntimeException e) {
ErrorManager em = ErrorManager.getDefault();
em.annotate(e, ErrorManager.UNKNOWN,
"Guilty action: " + a.getClass().getName(), null, null, null); // NOI18N
em.notify(e);
}
if (enabled) {
JMenuItem item = null;
if (popUp) {
if (a instanceof Presenter.Popup) {
item = ((Presenter.Popup)a).getPopupPresenter ();
}
} else {
if (a instanceof Presenter.Menu) {
item = ((Presenter.Menu)a).getMenuPresenter ();
}
}
// test if we obtained the item
if (item != null) {
items.add (item);
}
}
}
JMenuItem[] array = new JMenuItem [items.size ()];
items.toArray (array);
return array;
}