本文整理匯總了Java中javax.swing.MenuElement類的典型用法代碼示例。如果您正苦於以下問題:Java MenuElement類的具體用法?Java MenuElement怎麽用?Java MenuElement使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MenuElement類屬於javax.swing包,在下文中一共展示了MenuElement類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: enableHints
import javax.swing.MenuElement; //導入依賴的package包/類
public void enableHints(Component comp, boolean enabled) {
if (enabled)
comp.addMouseListener(this);
else
comp.removeMouseListener(this);
if (comp instanceof Container) {
Component[] components = ((Container) comp).getComponents();
for (int i = 0; i < components.length; i++)
enableHints(components[i], enabled);
}
if (comp instanceof MenuElement) {
MenuElement[] elements = ((MenuElement) comp).getSubElements();
for (int i = 0; i < elements.length; i++)
enableHints(elements[i].getComponent(), enabled);
}
}
示例2: visitMenuBar
import javax.swing.MenuElement; //導入依賴的package包/類
/** Open all menus in menubar
* @param menu to be visited */
public static void visitMenuBar(JMenuBar menu) {
MenuElement[] elements = menu.getSubElements();
JMenuBarOperator op = new JMenuBarOperator(menu);
for (int k = 0; k < elements.length; k++) {
if (elements[k] instanceof JMenuItem) {
op.pushMenu(((JMenuItem) elements[k]).getText(), "/", true, true);
try {
op.wait(200);
} catch (Exception e) {
}
}
}
}
示例3: main
import javax.swing.MenuElement; //導入依賴的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!");
}
});
}
示例4: getMenuType
import javax.swing.MenuElement; //導入依賴的package包/類
static MenuType getMenuType(Class cl) {
if (MenuElement.class.isAssignableFrom(cl)) {
if (JMenu.class.isAssignableFrom(cl)) {
return MenuType.JMenu;
}
if (JMenuBar.class.isAssignableFrom(cl)) {
return MenuType.JMenuBar;
}
if (JCheckBoxMenuItem.class.isAssignableFrom(cl)) {
return MenuType.JCheckBoxMenuItem;
}
if (JRadioButtonMenuItem.class.isAssignableFrom(cl)) {
return MenuType.JRadioButtonMenuItem;
}
if (JMenuItem.class.isAssignableFrom(cl)) {
return MenuType.JMenuItem;
}
if (JPopupMenu.class.isAssignableFrom(cl)) {
return MenuType.JPopupMenu;
}
} else if (JSeparator.class.isAssignableFrom(cl)) {
return MenuType.JSeparator;
}
return null;
}
示例5: getMenuBarArrayList
import javax.swing.MenuElement; //導入依賴的package包/類
/** Get MenuBar and tranfer it to ArrayList.
* @param menu menu to be tranfered
* @return tranfered menubar */
private static List<NbMenu> getMenuBarArrayList(JMenuBar menu) {
visitMenuBar(menu);
MenuElement [] elements = menu.getSubElements();
List<NbMenu> list = new ArrayList<NbMenu>();
for(int k=0; k < elements.length; k++) {
// if(elements[k] instanceof JMenuItem) {
// list.add(new NbMenu((JMenuItem)elements[k], null));
JMenuBarOperator menuOp = new JMenuBarOperator(menu);
JMenu item = menuOp.getMenu(k);
list.add(new NbMenu(item, getMenuArrayList(item)));
// }
/*if(elements[k] instanceof JMenuBar) {
JMenuBarOperator menuOp = new JMenuBarOperator(menu);
list.add(getMenuArrayList(menuOp.getMenu(0)));
}
*/
}
return list;
}
示例6: processKeyEvent
import javax.swing.MenuElement; //導入依賴的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);
}
示例7: getMenuBarArrayList
import javax.swing.MenuElement; //導入依賴的package包/類
/** Get MenuBar and tranfer it to ArrayList.
* @param menu menu to be tranfered
* @return tranfered menubar - !separator is ignored
*/
public static ArrayList<NbMenuItem> getMenuBarArrayList(JMenuBar menu) {
// System.out.println("getMenuBarArrayList " + menu.getName());
visitMenuBar(menu);
MenuElement[] elements = menu.getSubElements();
ArrayList<NbMenuItem> list = new ArrayList<NbMenuItem>();
for (int k = 0; k < elements.length; k++) {
if (elements[k] instanceof JPopupMenu.Separator) {
NbMenuItem separator = new NbMenuItem();
separator.setSeparator(true);
list.add(separator);
} else {
if (elements[k] instanceof JMenuItem) {
NbMenuItem item = new NbMenuItem((JMenuItem) elements[k]);
JMenuBarOperator menuOp = new JMenuBarOperator(menu);
item.setSubmenu(getMenuArrayList(menuOp.getMenu(k)));
list.add(item);
}
}
}
return list;
}
示例8: getPopupMenuArrayList
import javax.swing.MenuElement; //導入依賴的package包/類
/** Get PopupMenu and transfer it to ArrayList.
* @param popup menu to be tranfered
* @return transfered menu - !separator is ignored
*/
public static ArrayList<NbMenuItem> getPopupMenuArrayList(JPopupMenu popup) {
//System.out.print("getPopupMenuArrayList: "); popup.list(); //DEBUG
MenuElement[] elements = popup.getSubElements();
ArrayList<NbMenuItem> list = new ArrayList<NbMenuItem>();
for (MenuElement menuElement : elements) {
//System.out.print("getPopupMenuArrayList: ");
// ((JComponent) menuElement).list();
if (menuElement instanceof JSeparator) {
//System.out.println("adding separator");//DEBUG
NbMenuItem separator = new NbMenuItem();
separator.setSeparator(true);
list.add(separator);
} else {
if (menuElement instanceof JMenu) {
NbMenuItem mitem = new NbMenuItem((JMenuItem) menuElement);
mitem.setName(mitem.getName());
mitem.setSubmenu (getMenuArrayList((JMenu) menuElement));
list.add(mitem);
} else if (menuElement instanceof JMenuItem) //if()
{
if (!((JMenuItem) menuElement).isVisible()) {
continue;
}
NbMenuItem item = new NbMenuItem((JMenuItem) menuElement);
item.setName(item.getName());
list.add(item);
} else {
System.out.println("getPopup unknown:" + menuElement.toString());
}
}
}
return list;
}
示例9: postProcessKeyEvent
import javax.swing.MenuElement; //導入依賴的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;
}
示例10: altPressed
import javax.swing.MenuElement; //導入依賴的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();
}
}
}
示例11: launch
import javax.swing.MenuElement; //導入依賴的package包/類
@Override
public MenuElement launch() {
MenuElement element = getMenuElement();
if (element != null) {
MenuElement[] subElements = element.getSubElements();
for (MenuElement subElement : subElements) {
if (((Component) subElement).isShowing()
&& ((Component) subElement).isEnabled()
&& chooser.checkPathComponent(depth, subElement)) {
process(subElement);
return subElement;
}
if (stopped) {
return null;
}
}
}
return null;
}
示例12: actionPerformed
import javax.swing.MenuElement; //導入依賴的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);
}
}
示例13: getPath
import javax.swing.MenuElement; //導入依賴的package包/類
/**
* Returns path to this menu item.
*
* @return $MenuElement[]$ Returns array of menu elements that constitute a
* path to this menu item.
*/
public MenuElement[] getPath()
{
ArrayList path = new ArrayList();
Component c = menuItem;
while (c instanceof MenuElement)
{
path.add(0, c);
if (c instanceof JPopupMenu)
c = ((JPopupMenu) c).getInvoker();
else
c = c.getParent();
}
MenuElement[] pathArray = new MenuElement[path.size()];
path.toArray(pathArray);
return pathArray;
}
示例14: findEnabledChild
import javax.swing.MenuElement; //導入依賴的package包/類
/**
* Searches the next or previous enabled child menu element.
*
* @param children the children to search through
* @param start the index at which to start
* @param dir the direction (true == forward, false == backward)
*
* @return the found element or null
*/
private MenuElement findEnabledChild(MenuElement[] children,
int start, boolean dir)
{
MenuElement result = null;
if (dir)
{
result = findNextEnabledChild(children, start + 1, children.length-1);
if (result == null)
result = findNextEnabledChild(children, 0, start - 1);
}
else
{
result = findPreviousEnabledChild(children, start - 1, 0);
if (result == null)
result = findPreviousEnabledChild(children, children.length-1,
start + 1);
}
return result;
}
示例15: findNextEnabledChild
import javax.swing.MenuElement; //導入依賴的package包/類
/**
* Finds the next child element that is enabled and visible.
*
* @param children the children to search through
* @param start the start index
* @param end the end index
*
* @return the found child, or null
*/
private MenuElement findNextEnabledChild(MenuElement[] children, int start,
int end)
{
MenuElement found = null;
for (int i = start; i <= end && found == null; i++)
{
if (children[i] != null)
{
Component comp = children[i].getComponent();
if (comp != null && comp.isEnabled() && comp.isVisible())
{
found = children[i];
}
}
}
return found;
}