本文整理汇总了Java中org.openide.util.actions.Presenter.Menu方法的典型用法代码示例。如果您正苦于以下问题:Java Presenter.Menu方法的具体用法?Java Presenter.Menu怎么用?Java Presenter.Menu使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.util.actions.Presenter
的用法示例。
在下文中一共展示了Presenter.Menu方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testManualRefreshPreference
import org.openide.util.actions.Presenter; //导入方法依赖的package包/类
public void testManualRefreshPreference() throws IOException {
Preferences pref = NbPreferences.root().node("org/openide/actions/FileSystemRefreshAction");
assertFalse("Not set", pref.getBoolean("manual", false));
FileObject fo = FileUtil.toFileObject(getWorkDir());
Lookup lkp = Lookups.singleton(DataFolder.findFolder(fo).getNodeDelegate());
FileSystemAction fsa = FileSystemAction.get(FileSystemAction.class);
Action a = fsa.createContextAwareInstance(lkp);
assertEquals("Menu presenter ", true, a instanceof Presenter.Menu);
Presenter.Menu pm = (Presenter.Menu)a;
DynamicMenuContent submenu = (DynamicMenuContent)pm.getMenuPresenter();
assertEquals("No submenu", 0, submenu.getMenuPresenters().length);
pref.putBoolean("manual", true);
DynamicMenuContent submenu2 = (DynamicMenuContent)pm.getMenuPresenter();
assertEquals("One action", 1, submenu2.getMenuPresenters().length);
}
示例2: setShowEditorToolbar
import org.openide.util.actions.Presenter; //导入方法依赖的package包/类
private static boolean setShowEditorToolbar( boolean show ) {
boolean res = true;
Action toggleEditorToolbar = FileUtil.getConfigObject( "Editors/Actions/toggle-toolbar.instance", Action.class ); //NOI18N
if( null != toggleEditorToolbar ) {
if( toggleEditorToolbar instanceof Presenter.Menu ) {
JMenuItem menuItem = ((Presenter.Menu)toggleEditorToolbar).getMenuPresenter();
if( menuItem instanceof JCheckBoxMenuItem ) {
JCheckBoxMenuItem checkBoxMenu = ( JCheckBoxMenuItem ) menuItem;
res = checkBoxMenu.isSelected();
if( checkBoxMenu.isSelected() != show ) {
try {
toggleEditorToolbar.actionPerformed( new ActionEvent( menuItem, 0, "")); //NOII18N
} catch( Exception ex ) {
//don't worry too much if it isn't working, we're just trying to be helpful here
Logger.getLogger( EditorOnlyDisplayer.class.getName()).log( Level.FINE, null, ex );
}
}
}
}
}
return res;
}
示例3: testInlineIsNotBlocked
import org.openide.util.actions.Presenter; //导入方法依赖的package包/类
public void testInlineIsNotBlocked() 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("Cat3").createData(BlockingAction.class.getName().replace('.', '-') + ".instance").setAttribute("position", 100);
Action a = ta.createContextAwareInstance(lkp);
assertTrue("It is menu presenter", a instanceof Presenter.Menu);
Presenter.Menu mp = (Presenter.Menu)a;
JMenuItem item = mp.getMenuPresenter();
assertTrue("Item is enabled", item.isEnabled());
DynamicMenuContent dmc = (DynamicMenuContent)item;
final JComponent[] arr = dmc.getMenuPresenters();
assertEquals("One presenter to delegte to", 1, arr.length);
assertFalse("Disabled", arr[0].isEnabled());
}
示例4: 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);
}
}
}
示例5: 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 {
item = new JMenuItem();
Actions.connect(item, action, false);
}
return item;
}
示例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: DelegateAction
import org.openide.util.actions.Presenter; //导入方法依赖的package包/类
public DelegateAction (Action a, Lookup actionContext) {
if (! (a instanceof Presenter.Menu)) {
throw new IllegalStateException ("Should be menu presenter: " + a); // NOI18N
}
if (! (a instanceof Presenter.Toolbar)) {
throw new IllegalStateException ("Should be toolbar presenter: " + a); // NOI18N
}
this.delegate = a;
this.lookup = actionContext;
}
示例9: testCreateContextAwareInstance
import org.openide.util.actions.Presenter; //导入方法依赖的package包/类
/**
* Test of createContextAwareInstance method, of class ActiveConfigAction.
*/
@RandomlyFails
public void testCreateContextAwareInstance() throws Exception {
P p = PF.toCreate;
OpenProjects.getDefault().open(new Project[] { p }, false);
OpenProjects.getDefault().setMainProject(p);
ActiveConfigAction instance = new ActiveConfigAction();
Action result = instance;//.createContextAwareInstance(actionContext);
assertTrue("menu: " + result, result instanceof Presenter.Menu);
Presenter.Menu menu = (Presenter.Menu)result;
JMenuItem item = menu.getMenuPresenter();
assertNotNull(item);
assertTrue("Enabled", item.isEnabled());
final DynamicMenuContent m = (DynamicMenuContent)item;
assertEquals("One", 1, m.getMenuPresenters().length);
holder = item;
OpenProjects.getDefault().close(new Project[] { p });
assertNull("NO project selected", OpenProjects.getDefault().getMainProject());
WeakReference<Object> ref = new WeakReference<Object>(p);
p = null;
PF.toCreate = null;
//Await refresh
final Logger log = Logger.getLogger(ActiveConfigAction.class.getName());
final Level origLogLevel = log.getLevel();
final FH handler = new FH();
log.setLevel(Level.FINEST);
log.addHandler(handler);
try {
handler.get(30, TimeUnit.SECONDS);
} finally {
log.setLevel(origLogLevel);
log.removeHandler(handler);
}
//Rebuild the current pop up menu
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
m.getMenuPresenters();
}
});
assertGC("Reference can go away", ref);
}
示例10: 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;
}