本文整理汇总了Java中javax.swing.MenuSelectionManager类的典型用法代码示例。如果您正苦于以下问题:Java MenuSelectionManager类的具体用法?Java MenuSelectionManager怎么用?Java MenuSelectionManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MenuSelectionManager类属于javax.swing包,在下文中一共展示了MenuSelectionManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.swing.MenuSelectionManager; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
SwingUtilities.invokeAndWait(() -> {
JPopupMenu popup = new JPopupMenu("Popup Menu");
JMenu menu = new JMenu("Menu");
menu.add(new JMenuItem("Menu Item"));
popup.add(menu);
menu.doClick();
MenuElement[] elems = MenuSelectionManager
.defaultManager().getSelectedPath();
if (elems == null || elems.length == 0) {
throw new RuntimeException("Empty Selection");
}
if (elems[0] != popup || elems[1] != menu) {
throw new RuntimeException("Necessary menus are not selected!");
}
});
}
示例2: processKeyEvent
import javax.swing.MenuSelectionManager; //导入依赖的package包/类
public void processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager manager) {
if (isReturnAction(e)) { // Handle SPACE and ENTER
MenuElement[] p = manager.getSelectedPath();
MenuElement m = p != null && p.length > 0 ? p[p.length - 1] : null;
if (m instanceof StayOpen) {
e.consume();
if (e.getID() == KeyEvent.KEY_PRESSED)
performAction((StayOpen)m, e.getModifiers());
return;
}
} else for (Component component : getComponents()) { // Handle mnemonics and accelerators
if (component instanceof StayOpen) {
StayOpen item = (StayOpen)component;
JMenuItem i = item.getItem();
KeyStroke k = KeyStroke.getKeyStrokeForEvent(e);
if (k.equals(mnemonic(i)) || k.equals(i.getAccelerator())) {
e.consume();
manager.setSelectedPath(new MenuElement[] { this, i });
performAction(item, e.getModifiers());
return;
}
}
}
super.processKeyEvent(e, path, manager);
}
示例3: showDialog
import javax.swing.MenuSelectionManager; //导入依赖的package包/类
@BeforeMethod public void showDialog() throws Throwable {
JavaElementFactory.add(JMenuItem.class, JMenuItemJavaElement.class);
SwingUtilities.invokeAndWait(new Runnable() {
@Override public void run() {
frame = new JFrame(JMenuItemJavaElementTest.class.getSimpleName());
frame.setName("frame-" + JMenuItemJavaElementTest.class.getSimpleName());
MenuDemo demo = new MenuDemo();
frame.setJMenuBar(demo.createMenuBar());
frame.setContentPane(demo.createContentPane());
frame.pack();
frame.setAlwaysOnTop(true);
frame.setVisible(true);
}
});
MenuSelectionManager.defaultManager().clearSelectedPath();
driver = new JavaAgent();
menus = driver.findElementsByTagName("menu");
AMenu = menus.get(0);
}
示例4: showDialog
import javax.swing.MenuSelectionManager; //导入依赖的package包/类
@BeforeMethod public void showDialog() throws Throwable {
SwingUtilities.invokeAndWait(new Runnable() {
@Override public void run() {
frame = new JFrame(JMenuItemJavaElement2Test.class.getSimpleName());
frame.setName("frame-" + JMenuItemJavaElement2Test.class.getSimpleName());
PopupMenuDemoX demo = new PopupMenuDemoX();
frame.setJMenuBar(demo.createMenuBar());
frame.setContentPane(demo.createContentPane());
// Create and set up the popup menu.
demo.createPopupMenu();
frame.pack();
frame.setAlwaysOnTop(true);
frame.setVisible(true);
}
});
MenuSelectionManager.defaultManager().clearSelectedPath();
JavaElementFactory.add(JMenuItem.class, JMenuItemJavaElement.class);
}
示例5: showDialog
import javax.swing.MenuSelectionManager; //导入依赖的package包/类
@BeforeMethod public void showDialog() throws Throwable {
SwingUtilities.invokeAndWait(new Runnable() {
@Override public void run() {
frame = new JFrame(JPopupMenuTest.class.getSimpleName());
frame.setName("frame-" + JPopupMenuTest.class.getSimpleName());
PopupMenuDemo demo = new PopupMenuDemo();
frame.setJMenuBar(demo.createMenuBar());
frame.setContentPane(demo.createContentPane());
// Create and set up the popup menu.
demo.createPopupMenu();
frame.pack();
frame.setAlwaysOnTop(true);
frame.setVisible(true);
}
});
MenuSelectionManager.defaultManager().clearSelectedPath();
}
示例6: postProcessKeyEvent
import javax.swing.MenuSelectionManager; //导入依赖的package包/类
public boolean postProcessKeyEvent(KeyEvent ev) {
if(ev.isConsumed() && ev.getKeyCode() != KeyEvent.VK_ALT) {
// mnemonic combination, it's consumed, but we need
// set altKeyPressed to false, otherwise after selection
// component by mnemonic combination a menu will be open
altKeyPressed = false;
return false;
}
if (ev.getKeyCode() == KeyEvent.VK_ALT) {
root = SwingUtilities.getRootPane(ev.getComponent());
winAncestor = (root == null ? null :
SwingUtilities.getWindowAncestor(root));
if (ev.getID() == KeyEvent.KEY_PRESSED) {
if (!altKeyPressed) {
altPressed(ev);
}
altKeyPressed = true;
return true;
} else if (ev.getID() == KeyEvent.KEY_RELEASED) {
if (altKeyPressed) {
altReleased(ev);
} else {
MenuSelectionManager msm =
MenuSelectionManager.defaultManager();
MenuElement[] path = msm.getSelectedPath();
if (path.length <= 0) {
WindowsLookAndFeel.setMnemonicHidden(true);
WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
}
}
altKeyPressed = false;
}
root = null;
winAncestor = null;
} else {
altKeyPressed = false;
}
return false;
}
示例7: altPressed
import javax.swing.MenuSelectionManager; //导入依赖的package包/类
void altPressed(KeyEvent ev) {
MenuSelectionManager msm =
MenuSelectionManager.defaultManager();
MenuElement[] path = msm.getSelectedPath();
if (path.length > 0 && ! (path[0] instanceof ComboPopup)) {
msm.clearSelectedPath();
menuCanceledOnPress = true;
ev.consume();
} else if(path.length > 0) { // We are in ComboBox
menuCanceledOnPress = false;
WindowsLookAndFeel.setMnemonicHidden(false);
WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
ev.consume();
} else {
menuCanceledOnPress = false;
WindowsLookAndFeel.setMnemonicHidden(false);
WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
JMenuBar mbar = root != null ? root.getJMenuBar() : null;
if(mbar == null && winAncestor instanceof JFrame) {
mbar = ((JFrame)winAncestor).getJMenuBar();
}
JMenu menu = mbar != null ? mbar.getMenu(0) : null;
if(menu != null) {
ev.consume();
}
}
}
示例8: hide
import javax.swing.MenuSelectionManager; //导入依赖的package包/类
/**
* This method hides drop down list of items
*/
public void hide()
{
MenuSelectionManager menuSelectionManager =
MenuSelectionManager.defaultManager();
javax.swing.MenuElement[] menuElements =
menuSelectionManager.getSelectedPath();
for (int i = 0; i < menuElements.length; i++)
{
if (menuElements[i] == this)
{
menuSelectionManager.clearSelectedPath();
break;
}
}
comboBox.repaint();
}
示例9: actionPerformed
import javax.swing.MenuSelectionManager; //导入依赖的package包/类
/**
* Performs the action.
*/
public void actionPerformed(ActionEvent event)
{
// In the JDK this action seems to pop up the first menu of the
// menu bar.
JMenuBar menuBar = (JMenuBar) event.getSource();
MenuSelectionManager defaultManager =
MenuSelectionManager.defaultManager();
MenuElement me[];
MenuElement subElements[];
JMenu menu = menuBar.getMenu(0);
if (menu != null)
{
me = new MenuElement[3];
me[0] = (MenuElement) menuBar;
me[1] = (MenuElement) menu;
me[2] = (MenuElement) menu.getPopupMenu();
defaultManager.setSelectedPath(me);
}
}
示例10: installUI
import javax.swing.MenuSelectionManager; //导入依赖的package包/类
/**
* Installs and initializes all fields for this UI delegate. Any properties
* of the UI that need to be initialized and/or set to defaults will be
* done now. It will also install any listeners necessary.
*
* @param c The {@link JComponent} that is having this UI installed.
*/
public void installUI(JComponent c)
{
super.installUI(c);
// Install KeyboardHelper when the first popup is initialized.
if (numPopups == 0)
{
keyboardHelper = new KeyboardHelper();
MenuSelectionManager msm = MenuSelectionManager.defaultManager();
msm.addChangeListener(keyboardHelper);
}
numPopups++;
popupMenu = (JPopupMenu) c;
popupMenu.setLayout(new DefaultMenuLayout(popupMenu, BoxLayout.Y_AXIS));
popupMenu.setBorderPainted(true);
JPopupMenu.setDefaultLightWeightPopupEnabled(true);
installDefaults();
installListeners();
installKeyboardActions();
}
示例11: uninstallUI
import javax.swing.MenuSelectionManager; //导入依赖的package包/类
/**
* Performs the opposite of installUI. Any properties or resources that need
* to be cleaned up will be done now. It will also uninstall any listeners
* it has. In addition, any properties of this UI will be nulled.
*
* @param c The {@link JComponent} that is having this UI uninstalled.
*/
public void uninstallUI(JComponent c)
{
uninstallListeners();
uninstallDefaults();
uninstallKeyboardActions();
popupMenu = null;
// Install KeyboardHelper when the first popup is initialized.
numPopups--;
if (numPopups == 0)
{
MenuSelectionManager msm = MenuSelectionManager.defaultManager();
msm.removeChangeListener(keyboardHelper);
}
}
示例12: actionPerformed
import javax.swing.MenuSelectionManager; //导入依赖的package包/类
@Override public void actionPerformed(ActionEvent ev) {
Help h = (Help)Lookup.getDefault().lookup(Help.class);
if (h == null) {
Toolkit.getDefaultToolkit().beep();
return;
}
HelpCtx help;
final MenuElement[] path =
MenuSelectionManager.defaultManager().getSelectedPath();
if (path != null
&& path.length > 0
&& !(path[0].getComponent() instanceof javax.swing.plaf.basic.ComboPopup)
) {
help = HelpCtx.findHelp(path[path.length - 1].getComponent());
SwingUtilities.invokeLater(new Runnable() {
public void run() {
MenuElement[] newPath =
MenuSelectionManager.defaultManager().getSelectedPath();
if (newPath.length != path.length)
return;
for (int i = 0; i < newPath.length; i++) {
if (newPath[i] != path[i])
return;
}
MenuSelectionManager.defaultManager().clearSelectedPath();
}
});
}
else {
help = findHelpCtx();
}
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(HelpAction.class, "CTL_OpeningHelp"));
h.showHelp (help);
}
示例13: doShow
import javax.swing.MenuSelectionManager; //导入依赖的package包/类
private void doShow () {
//#206802 - dialog windows are hidden behind full screen window
Window fullScreenWindow = null;
if( Utilities.isUnix() ) {
GraphicsDevice gd = getGraphicsConfiguration().getDevice();
if( gd.isFullScreenSupported() ) {
fullScreenWindow = gd.getFullScreenWindow();
if( null != fullScreenWindow )
gd.setFullScreenWindow( null );
}
}
NbPresenter prev = null;
try {
MenuSelectionManager.defaultManager().clearSelectedPath();
} catch( NullPointerException npE ) {
//#216184
LOG.log( Level.FINE, null, npE );
}
if (isModal()) {
prev = currentModalDialog;
currentModalDialog = this;
fireChangeEvent();
}
superShow();
if( null != fullScreenWindow )
getGraphicsConfiguration().getDevice().setFullScreenWindow( fullScreenWindow );
if (currentModalDialog != prev) {
currentModalDialog = prev;
fireChangeEvent();
}
}
示例14: showMenuPath
import javax.swing.MenuSelectionManager; //导入依赖的package包/类
/**
* Show and select menu at a given path. Used to restore a menu after click.
*/
private void showMenuPath(MenuElement[] selectedPath) {
if (selectedPath != null && selectedPath.length > 1) {
if (selectedPath[0] instanceof JPopupMenu) {
((JPopupMenu) selectedPath[0]).setVisible(true);
MenuSelectionManager.defaultManager().setSelectedPath(
selectedPath);
}
}
}
示例15: AllMenuItem
import javax.swing.MenuSelectionManager; //导入依赖的package包/类
public AllMenuItem(Set<Category> evalCats) {
this.evalCats = evalCats;
this.totalCount = ProviderModel.getInstance()
.getCategories().size();
getModel().addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (isShowing() && model.isArmed()) {
selectedPath = MenuSelectionManager.defaultManager()
.getSelectedPath();
}
}
});
addActionListener(this);
}