本文整理匯總了Java中javax.swing.MenuSelectionManager.getSelectedPath方法的典型用法代碼示例。如果您正苦於以下問題:Java MenuSelectionManager.getSelectedPath方法的具體用法?Java MenuSelectionManager.getSelectedPath怎麽用?Java MenuSelectionManager.getSelectedPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.MenuSelectionManager
的用法示例。
在下文中一共展示了MenuSelectionManager.getSelectedPath方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
示例2: 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;
}
示例3: 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();
}
}
}
示例4: 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();
}
示例5: mousePressed
import javax.swing.MenuSelectionManager; //導入方法依賴的package包/類
/**
* Handles mouse pressed events from the event queue.
*
* @param ev the mouse pressed event
*/
private void mousePressed(MouseEvent ev)
{
// Autoclose all menus managed by the MenuSelectionManager.
MenuSelectionManager m = MenuSelectionManager.defaultManager();
Component target = ev.getComponent();
if (target instanceof Container)
target = ((Container) target).findComponentAt(ev.getPoint());
if (m.getSelectedPath().length > 0
&& ! m.isComponentPartOfCurrentMenu(target)
&& (((JComponent)target).getClientProperty(DONT_CANCEL_POPUP) == null
|| !((JComponent)target).getClientProperty(DONT_CANCEL_POPUP).equals(Boolean.TRUE)))
{
m.clearSelectedPath();
}
}
示例6: hide
import javax.swing.MenuSelectionManager; //導入方法依賴的package包/類
@Override
public void hide() {
MenuSelectionManager manager = MenuSelectionManager.defaultManager();
MenuElement[] selection = manager.getSelectedPath();
for (MenuElement element : selection) {
if (element == this) {
manager.clearSelectedPath();
break;
}
}
ComboBoxUI.this.isDown = false;
this.comboBox.repaint();
}
示例7: postProcessKeyEvent
import javax.swing.MenuSelectionManager; //導入方法依賴的package包/類
public boolean postProcessKeyEvent(KeyEvent ev) {
if(ev.isConsumed()) {
// do not manage consumed event
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;
}
示例8: actionPerformed
import javax.swing.MenuSelectionManager; //導入方法依賴的package包/類
/**
* Performs the action.
*/
public void actionPerformed(ActionEvent event)
{
JMenu menu = (JMenu) menuItem;
MenuSelectionManager defaultManager =
MenuSelectionManager.defaultManager();
MenuElement path[] = defaultManager.getSelectedPath();
if(path.length > 0 && path[path.length - 1] == menu)
{
MenuElement newPath[] = new MenuElement[path.length + 1];
System.arraycopy(path, 0, newPath, 0, path.length);
newPath[path.length] = menu.getPopupMenu();
defaultManager.setSelectedPath(newPath);
}
}
示例9: cancel
import javax.swing.MenuSelectionManager; //導入方法依賴的package包/類
/**
* Handles cancel requests (ESC key).
*/
private void cancel()
{
// Fire popup menu cancelled event. Unfortunately the
// firePopupMenuCancelled() is protected in JPopupMenu so we work
// around this limitation by fetching the listeners and notifying them
// directly.
JPopupMenu lastPopup = (JPopupMenu) getLastPopup();
EventListener[] ll = lastPopup.getListeners(PopupMenuListener.class);
for (int i = 0; i < ll.length; i++)
{
PopupMenuEvent ev = new PopupMenuEvent(lastPopup);
((PopupMenuListener) ll[i]).popupMenuCanceled(ev);
}
// Close the last popup or the whole selection if there's only one
// popup left.
MenuSelectionManager msm = MenuSelectionManager.defaultManager();
MenuElement path[] = msm.getSelectedPath();
if(path.length > 4)
{
MenuElement newPath[] = new MenuElement[path.length - 2];
System.arraycopy(path,0,newPath,0,path.length-2);
MenuSelectionManager.defaultManager().setSelectedPath(newPath);
}
else
msm.clearSelectedPath();
}
示例10: getLastPopup
import javax.swing.MenuSelectionManager; //導入方法依賴的package包/類
/**
* Returns the last popup menu in the current selection or null.
*
* @return the last popup menu in the current selection or null
*/
private JPopupMenu getLastPopup()
{
MenuSelectionManager msm = MenuSelectionManager.defaultManager();
MenuElement[] p = msm.getSelectedPath();
JPopupMenu popup = null;
for(int i = p.length - 1; popup == null && i >= 0; i--)
{
if (p[i] instanceof JPopupMenu)
popup = (JPopupMenu) p[i];
}
return popup;
}
示例11: doReturn
import javax.swing.MenuSelectionManager; //導入方法依賴的package包/類
/**
* Handles ENTER key requests. This normally opens submenus on JMenu
* items, or activates the menu item as if it's been clicked on it.
*/
private void doReturn()
{
KeyboardFocusManager fmgr =
KeyboardFocusManager.getCurrentKeyboardFocusManager();
Component focusOwner = fmgr.getFocusOwner();
if((focusOwner == null || (focusOwner instanceof JRootPane)))
{
MenuSelectionManager msm = MenuSelectionManager.defaultManager();
MenuElement path[] = msm.getSelectedPath();
MenuElement lastElement;
if(path.length > 0)
{
lastElement = path[path.length - 1];
if(lastElement instanceof JMenu)
{
MenuElement newPath[] = new MenuElement[path.length + 1];
System.arraycopy(path,0,newPath,0,path.length);
newPath[path.length] = ((JMenu) lastElement).getPopupMenu();
msm.setSelectedPath(newPath);
}
else if(lastElement instanceof JMenuItem)
{
JMenuItem mi = (JMenuItem)lastElement;
if (mi.getUI() instanceof BasicMenuItemUI)
{
((BasicMenuItemUI)mi.getUI()).doClick(msm);
}
else
{
msm.clearSelectedPath();
mi.doClick(0);
}
}
}
}
}
示例12: popupMenuWillBecomeVisible
import javax.swing.MenuSelectionManager; //導入方法依賴的package包/類
/**
* This method is invoked when JPopupMenu becomes visible
*
* @param event the PopupMenuEvent
*/
public void popupMenuWillBecomeVisible(PopupMenuEvent event)
{
// Adds topWindowListener to top-level window to listener to
// ComponentEvents fired by it. We need to cancel this popup menu
// if topWindow to which this popup belongs was resized or moved.
Component invoker = popupMenu.getInvoker();
Component rootContainer = SwingUtilities.getRoot(invoker);
if (rootContainer != null)
rootContainer.addComponentListener(topWindowListener);
// if this popup menu is a free floating popup menu,
// then by default its first element should be always selected when
// this popup menu becomes visible.
MenuSelectionManager manager = MenuSelectionManager.defaultManager();
if (manager.getSelectedPath().length == 0)
{
// Set selected path to point to the first item in the popup menu
MenuElement[] path = new MenuElement[2];
path[0] = popupMenu;
Component[] comps = popupMenu.getComponents();
if (comps.length != 0 && comps[0] instanceof MenuElement)
{
path[1] = (MenuElement) comps[0];
manager.setSelectedPath(path);
}
}
}
示例13: altReleased
import javax.swing.MenuSelectionManager; //導入方法依賴的package包/類
void altReleased(KeyEvent ev) {
if (menuCanceledOnPress) {
WindowsLookAndFeel.setMnemonicHidden(true);
WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
return;
}
MenuSelectionManager msm =
MenuSelectionManager.defaultManager();
if (msm.getSelectedPath().length == 0) {
// if no menu is active, we try activating the menubar
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;
// It might happen that the altRelease event is processed
// with a reasonable delay since it has been generated.
// Here we check the last deactivation time of the containing
// window. If this time appears to be greater than the altRelease
// event time the event is skipped to avoid unexpected menu
// activation. See 7121442.
// Also we must ensure that original source of key event belongs
// to the same window object as winAncestor. See 8001633.
boolean skip = false;
Toolkit tk = Toolkit.getDefaultToolkit();
if (tk instanceof SunToolkit) {
Component originalSource = AWTAccessor.getKeyEventAccessor()
.getOriginalSource(ev);
skip = SunToolkit.getContainingWindow(originalSource) != winAncestor ||
ev.getWhen() <= ((SunToolkit) tk).getWindowDeactivationTime(winAncestor);
}
if (menu != null && !skip) {
MenuElement[] path = new MenuElement[2];
path[0] = mbar;
path[1] = menu;
msm.setSelectedPath(path);
} else if(!WindowsLookAndFeel.isMnemonicHidden()) {
WindowsLookAndFeel.setMnemonicHidden(true);
WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
}
} else {
if((msm.getSelectedPath())[0] instanceof ComboPopup) {
WindowsLookAndFeel.setMnemonicHidden(true);
WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
}
}
}
示例14: 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 {
if (WindowsLookAndFeel.isMnemonicHidden() && ev.isAltDown()) {
WindowsLookAndFeel.setMnemonicHidden(false);
WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
}
altKeyPressed = false;
}
return false;
}
示例15: postProcessKeyEvent
import javax.swing.MenuSelectionManager; //導入方法依賴的package包/類
public boolean postProcessKeyEvent(KeyEvent ev) {
if(ev.isConsumed()) {
// do not manage consumed event
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 {
if (WindowsLookAndFeel.isMnemonicHidden() && ev.isAltDown()) {
WindowsLookAndFeel.setMnemonicHidden(false);
WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
}
altKeyPressed = false;
}
return false;
}