本文整理匯總了Java中javax.swing.MenuElement.getComponent方法的典型用法代碼示例。如果您正苦於以下問題:Java MenuElement.getComponent方法的具體用法?Java MenuElement.getComponent怎麽用?Java MenuElement.getComponent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.MenuElement
的用法示例。
在下文中一共展示了MenuElement.getComponent方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: invokerEquals
import javax.swing.MenuElement; //導入方法依賴的package包/類
private boolean invokerEquals(MenuElement el1, MenuElement el2)
{
Component invoker1 = el1.getComponent();
Component invoker2 = el2.getComponent();
if (invoker1 instanceof JPopupMenu)
invoker1 = ((JPopupMenu) invoker1).getInvoker();
if (invoker2 instanceof JPopupMenu)
invoker2 = ((JPopupMenu) invoker2).getInvoker();
return invoker1 == invoker2;
}
示例2: addMenuElements
import javax.swing.MenuElement; //導入方法依賴的package包/類
private static final void addMenuElements(final MenuElement parent, final MenuElement... children)
{
if (children == null || children.length <= 0)
{
return;
}
//
// Get the parent menu component, where we will add the children
final Container parentComp = (Container)parent.getComponent();
//
// Add separator if we got more then one child
final boolean moreThanOneChildren = children.length > 1;
if (moreThanOneChildren)
{
addSeparator(parentComp);
}
//
// Add children to parent
for (MenuElement child : children)
{
if (child == null)
{
addSeparator(parentComp);
}
else
{
parentComp.add(child.getComponent());
}
}
}
示例3: getAction
import javax.swing.MenuElement; //導入方法依賴的package包/類
private final IContextMenuAction getAction(MenuElement me)
{
final Component c = me.getComponent();
if (c instanceof JComponent)
{
final JComponent jc = (JComponent)c;
final IContextMenuAction action = (IContextMenuAction)jc.getClientProperty(ATTR_Action);
return action;
}
return null;
}
示例4: checkAvailable
import javax.swing.MenuElement; //導入方法依賴的package包/類
/**
* Check and update menu item if available
*
* @param item
* @return true if item is available
*/
private boolean checkAvailable(MenuElement item)
{
final Component itemComp = item.getComponent();
final boolean isRoot = item == this;
if (!isRoot)
{
final IContextMenuAction action = getAction(item);
if (action == null)
{
// not controlled by this editor, take it's status and return
final boolean available = itemComp.isVisible();
return available;
}
if (!action.isAvailable())
{
itemComp.setVisible(false);
return false;
}
if (!action.isRunnable())
{
final boolean hideWhenNotRunnable = action.isHideWhenNotRunnable();
itemComp.setVisible(!hideWhenNotRunnable);
itemComp.setEnabled(false);
return false;
}
}
final MenuElement[] children = getSubElements(item);
if (children != null && children.length > 0)
{
boolean submenuAvailable = false;
for (MenuElement subitem : children)
{
final boolean subitemAvailable = checkAvailable(subitem);
if (subitemAvailable)
{
submenuAvailable = true;
}
}
itemComp.setVisible(submenuAvailable);
return submenuAvailable;
}
else
{
itemComp.setVisible(true);
itemComp.setEnabled(true);
}
return true;
}
示例5: actionPerformed
import javax.swing.MenuElement; //導入方法依賴的package包/類
public void actionPerformed(ActionEvent e) {
MenuElement path[] = MenuSelectionManager.defaultManager().getSelectedPath();
if (path.length > 0) {
Component compo = path[path.length - 1].getComponent();
boolean visiblePopup = false;
if (compo instanceof JPopupMenu) {
if (path.length == 1) {
return;
}
compo = path[path.length - 2].getComponent();
visiblePopup = true;
}
if (compo.isEnabled() &&
(compo instanceof JMenu) &&
// XXX 11048. See first XXX 11048 comment.
(!(compo instanceof Actions.SubMenu)
|| ((Actions.SubMenu)compo).getMenuComponentCount() > 1) &&
!((JMenu) compo).isTopLevelMenu()) {
JPopupMenu popup = ((JMenu) compo).getPopupMenu();
changeTargetUI(popup);
MenuElement subElements[] = popup.getSubElements();
if (subElements.length > 0) {
int adder = (visiblePopup ? 1 : 2);
int relativePopupIdx = (visiblePopup ? 1 : 0);
MenuElement enabledChild = nextEnabledChild(subElements, 0);
if (enabledChild != null) {
//boolean setPopup = (enabledChild.getComponent() instanceof JMenu);
java.awt.Component c = enabledChild.getComponent();
boolean setPopup = (c instanceof JMenu
// XXX 11048. See first XXX 11048 comment.
&& (!(c instanceof Actions.SubMenu)
|| ((Actions.SubMenu)c).getMenuComponentCount() > 1));
if (setPopup) {
adder++;
}
MenuElement newPath[] = new MenuElement[path.length + adder];
System.arraycopy(path, 0, newPath, 0, path.length);
newPath[path.length - relativePopupIdx] = popup;
newPath[path.length + 1 - relativePopupIdx] = enabledChild;
if (setPopup) {
JMenu jmenu = (JMenu) enabledChild.getComponent();
newPath[newPath.length - 1] = jmenu.getPopupMenu();
}
MenuSelectionManager.defaultManager().setSelectedPath(newPath);
}
}
}
}
}