當前位置: 首頁>>代碼示例>>Java>>正文


Java MenuSelectionManager.setSelectedPath方法代碼示例

本文整理匯總了Java中javax.swing.MenuSelectionManager.setSelectedPath方法的典型用法代碼示例。如果您正苦於以下問題:Java MenuSelectionManager.setSelectedPath方法的具體用法?Java MenuSelectionManager.setSelectedPath怎麽用?Java MenuSelectionManager.setSelectedPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.MenuSelectionManager的用法示例。


在下文中一共展示了MenuSelectionManager.setSelectedPath方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:StayOpenPopupMenu.java

示例2: 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);
    }
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:23,代碼來源:BasicMenuBarUI.java

示例3: mouseEntered

import javax.swing.MenuSelectionManager; //導入方法依賴的package包/類
/**
 * This method is called when mouse enters menu item. When this happens menu
 * item is considered to be selected and selection path in
 * MenuSelectionManager is set. This event is also forwarded to
 * MenuSelection Manager for further processing.
 *
 * @param e
 *          A {@link MouseEvent}.
 */
public void mouseEntered(MouseEvent e)
{
  Component source = (Component) e.getSource();
  if (source.getParent() instanceof MenuElement)
    {
      MenuSelectionManager manager = MenuSelectionManager.defaultManager();
      manager.setSelectedPath(getPath());
      manager.processMouseEvent(e);
    }
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:20,代碼來源:BasicMenuItemUI.java

示例4: 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);
  }
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:18,代碼來源:BasicMenuUI.java

示例5: 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);
                }
            }
        }
    }
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:41,代碼來源:BasicPopupMenuUI.java

示例6: 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);
        }
    }
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:34,代碼來源:BasicPopupMenuUI.java

示例7: 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);
        }
    }

}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:53,代碼來源:WindowsRootPaneUI.java

示例8: mousePressed

import javax.swing.MenuSelectionManager; //導入方法依賴的package包/類
public void mousePressed(MouseEvent e)
{
  MenuSelectionManager manager = MenuSelectionManager.defaultManager();
  JMenu menu = (JMenu) menuItem;
  if (menu.isEnabled())
    {
      // Open up the menu immediately if it's a toplevel menu.
      // But not yet the popup, which might be opened delayed, see below.
      if (menu.isTopLevelMenu())
        {
          if (menu.isSelected())
            manager.clearSelectedPath();
          else
            {
              Container cnt = menu.getParent();
              if (cnt != null && cnt instanceof JMenuBar)
                {
                  MenuElement[] me = new MenuElement[2];
                  me[0] = (MenuElement) cnt;
                  me[1] = menu;
                  manager.setSelectedPath(me);
               }
            }
        }

      // Open the menu's popup. Either do that immediately if delay == 0,
      // or delayed when delay > 0.
      MenuElement[] selectedPath = manager.getSelectedPath();
      if (selectedPath.length > 0
          && selectedPath[selectedPath.length - 1] != menu.getPopupMenu())
        {
          if(menu.isTopLevelMenu() || menu.getDelay() == 0)
            {
              MenuElement[] newPath =
                new MenuElement[selectedPath.length + 1];
              System.arraycopy(selectedPath, 0, newPath, 0,
                               selectedPath.length);
              newPath[selectedPath.length] = menu.getPopupMenu();
              manager.setSelectedPath(newPath);
            }
          else
            {
              setupPostTimer(menu);
            }
        }

    }
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:49,代碼來源:BasicMenuUI.java

示例9: menuDragMouseDragged

import javax.swing.MenuSelectionManager; //導入方法依賴的package包/類
/**
 * This method is invoked when mouse is dragged over the menu item.
 *
 * @param e The MenuDragMouseEvent
 */
public void menuDragMouseDragged(MenuDragMouseEvent e)
{
  if (menuItem.isEnabled())
    {
      MenuSelectionManager manager = e.getMenuSelectionManager();
      MenuElement path[] = e.getPath();

      Point p = e.getPoint();
      if(p.x >= 0 && p.x < menuItem.getWidth()
          && p.y >= 0 && p.y < menuItem.getHeight())
        {
          JMenu menu = (JMenu) menuItem;
          MenuElement[] selectedPath = manager.getSelectedPath();
          if(! (selectedPath.length > 0
              && selectedPath[selectedPath.length-1]
                              == menu.getPopupMenu()))
            {
              if(menu.isTopLevelMenu() || menu.getDelay() == 0
                 || e.getID() == MouseEvent.MOUSE_DRAGGED)
                {
                  MenuElement[] newPath = new MenuElement[path.length + 1];
                  System.arraycopy(path, 0, newPath, 0, path.length);
                  newPath[path.length] = menu.getPopupMenu();
                  manager.setSelectedPath(newPath);
                }
              else
                {
                  manager.setSelectedPath(path);
                  setupPostTimer(menu);
                }
            }
        }
      else if (e.getID() == MouseEvent.MOUSE_RELEASED)
        {
          Component comp = manager.componentForPoint(e.getComponent(),
                                                     e.getPoint());
          if (comp == null)
            manager.clearSelectedPath();
        }
    }
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:47,代碼來源:BasicMenuUI.java

示例10: menuDragMouseDragged

import javax.swing.MenuSelectionManager; //導入方法依賴的package包/類
/**
 * Tbis method is invoked when mouse is dragged over the menu item.
 *
 * @param e
 *          The MenuDragMouseEvent
 */
public void menuDragMouseDragged(MenuDragMouseEvent e)
{
  MenuSelectionManager manager = e.getMenuSelectionManager();
  manager.setSelectedPath(e.getPath());
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:12,代碼來源:BasicMenuItemUI.java

示例11: menuDragMouseEntered

import javax.swing.MenuSelectionManager; //導入方法依賴的package包/類
/**
 * Tbis method is invoked when mouse enters the menu item while it is being
 * dragged.
 *
 * @param e
 *          The MenuDragMouseEvent
 */
public void menuDragMouseEntered(MenuDragMouseEvent e)
{
  MenuSelectionManager manager = e.getMenuSelectionManager();
  manager.setSelectedPath(e.getPath());
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:13,代碼來源:BasicMenuItemUI.java


注:本文中的javax.swing.MenuSelectionManager.setSelectedPath方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。