javax.swing.JMenuItem.getAction()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(165)

本文整理了Java中javax.swing.JMenuItem.getAction()方法的一些代码示例,展示了JMenuItem.getAction()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JMenuItem.getAction()方法的具体详情如下:
包路径:javax.swing.JMenuItem
类名称:JMenuItem
方法名:getAction

JMenuItem.getAction介绍

暂无

代码示例

代码示例来源:origin: chewiebug/GCViewer

@Override
public void internalFrameActivated(InternalFrameEvent e) {
  for (int i=2; i < getMenuBar(e).getWindowMenu().getItemCount(); i++) {
    final JMenuItem item = getMenuBar(e).getWindowMenu().getItem(i);
    if (((WindowMenuItemAction)item.getAction()).getInternalFrame() == e.getInternalFrame()) {
      item.setSelected(true);
      break;
    }
  }
  
  getActionMap(e).get(ActionCommands.EXPORT.toString()).setEnabled(true);
  getActionMap(e).get(ActionCommands.REFRESH.toString()).setEnabled(true);
  getActionMap(e).get(ActionCommands.WATCH.toString()).setEnabled(true);
  getActionMap(e).get(ActionCommands.ZOOM.toString()).setEnabled(true);
  getActionMap(e).get(ActionCommands.ARRANGE.toString()).setEnabled(true);
  // setSelected() does not fire ActionEvent -> both buttons have to be changed
  getMenuBar(e).getWatchMenuItem().setSelected(getSelectedGCDocument(e).isWatched());
  getToolBar(e).getWatchToggleButton().setSelected(getSelectedGCDocument(e).isWatched());
  
  updateMenuItemState(e);
}

代码示例来源:origin: chewiebug/GCViewer

@Override
public void internalFrameClosing(InternalFrameEvent e) {
  JInternalFrame internalFrame = e.getInternalFrame();
  internalFrame.removeInternalFrameListener(this);
  internalFrame.getRootPane().remove(internalFrame);
  if (internalFrame.getRootPane().getComponentCount() == 0) {
    getActionMap(e).get(ActionCommands.ARRANGE.toString()).setEnabled(false);
  }
  
  // remove menuitem from menu and from button group
  JMenu windowMenu = getMenuBar(e).getWindowMenu();
  for (int i = 2; i < windowMenu.getItemCount(); i++) {
    JMenuItem item = windowMenu.getItem(i);
    if (((WindowMenuItemAction) item.getAction()).getInternalFrame() == internalFrame) {
      getMenuBar(e).removeFromWindowMenuGroup(item);
      break;
    }
  }
  // if this internalFrame is the last to be open, update the menu state
  // -> otherwise any settings done by the user are lost
  if (getGCViewerGui(e).getDesktopPane().getComponentCount() == 1) {
    updateMenuItemState(e);
    // set same menustate, when the last is closed as is set for deactivated
    internalFrameDeactivated(e);
  }
  // if some thread is still loading, it should stop now
  getSelectedGCDocument(e).getGCResources().stream().forEach(gcResource -> gcResource.setIsReadCancelled(true));
}

代码示例来源:origin: Audiveris/audiveris

@Override
  public void mouseEntered (MouseEvent e)
  {
    JMenuItem item = (JMenuItem) e.getSource();
    InterAction action = (InterAction) item.getAction();
    action.publish();
  }
}

代码示例来源:origin: Audiveris/audiveris

@Override
public void mouseEntered (MouseEvent e)
{
  JMenuItem item = (JMenuItem) e.getSource();
  RelationAction relationAction = (RelationAction) item.getAction();
  relationAction.publish();
}

代码示例来源:origin: org.gosu-lang.gosu/gosu-lab

@Override
public void menuSelected( MenuEvent e )
{
 for( int i = 0; i < getItemCount(); i++ )
 {
  JMenuItem item = getItem( i );
  if( item != null && item.getAction() != null )
  {
   item.setEnabled( item.getAction().isEnabled() );
  }
 }
}

代码示例来源:origin: org.gosu-lang.gosu/gosu-editor

@Override
public void menuSelected( MenuEvent e )
{
 for( int i = 0; i < getItemCount(); i++ )
 {
  JMenuItem item = getItem( i );
  if( item != null && item.getAction() != null )
  {
   item.setEnabled( item.getAction().isEnabled() );
  }
 }
}

代码示例来源:origin: com.nelkinda.japi/nelkinda-japi-swing

public static Optional<JMenu> findJMenu(final JMenu jMenu, final String actionCommand) {
  for (int i = 0; i < jMenu.getItemCount(); i++) {
    final JMenuItem jMenuItem = jMenu.getItem(i);
    if (jMenuItem instanceof JMenu) {
      if (actionCommand.equals(jMenuItem.getAction().getValue(ACTION_COMMAND_KEY))) {
        return Optional.of((JMenu) jMenuItem);
      }
      final Optional<JMenu> candidate = findJMenu((JMenu) jMenuItem, actionCommand);
      if (candidate.isPresent()) {
        return candidate;
      }
    }
  }
  return Optional.empty();
}

代码示例来源:origin: ujmp/universal-java-matrix-package

private void registerKeyboardActions() {
  for (JComponent c : new MatrixActions(this, matrixGUIObject, null)) {
    if (c instanceof JMenuItem) {
      registerKeyboardAction(((JMenuItem) c).getAction());
    }
  }
}

代码示例来源:origin: org.appdapter/org.appdapter.lib.gui

public Action[] getActions() {
  ArrayList actions = new ArrayList<Action>();
  for (Component c : initEditMenu(true).getMenuComponents()) {
    Action act = null;
    if (c instanceof JMenuItem) {
      JMenuItem mi = (JMenuItem) c;
      act = mi.getAction();
    } else if (c instanceof AbstractButton) {
      AbstractButton mi = (AbstractButton) c;
      act = mi.getAction();
    }
    if (act != null)
      actions.add(act);
  }
  return (Action[]) actions.toArray(new Action[actions.size()]);
}

代码示例来源:origin: net.anwiba.commons/anwiba-commons-swing-core

void remove(final Action action) {
  for (int i = 0; i < getItemCount(); i++) {
   final JMenuItem item = getItem(i);
   if (item.getAction().equals(action)) {
    remove(item);
    return;
   }
  }
 }
}

代码示例来源:origin: org.bidib.org.oxbow/swingbits

@Override
    public JMenuItem add(JMenuItem menuItem) {
      Action action = menuItem.getAction();
//            Action action = menuItem instanceof JMenu? new ActionDropDownMenu((ActionGroup) menuAction): menuAction;
      
      AbstractButton b = add( action, menuItem );
      b.setHorizontalTextPosition(SwingConstants.LEADING);
      b.putClientProperty("hideActionText", action.getValue(Action.SMALL_ICON) != null);
      return menuItem;
    }

代码示例来源:origin: eugener/oxbow

@Override
    public JMenuItem add(JMenuItem menuItem) {
      Action action = menuItem.getAction();
//            Action action = menuItem instanceof JMenu? new ActionDropDownMenu((ActionGroup) menuAction): menuAction;
      
      AbstractButton b = add( action, menuItem );
      b.setHorizontalTextPosition(SwingConstants.LEADING);
      b.putClientProperty("hideActionText", action.getValue(Action.SMALL_ICON) != null);
      return menuItem;
    }

代码示例来源:origin: org.cytoscape/vizmap-gui-impl

public void onTaskFactoryUnregistered(final TaskFactory taskFactory, final Map<?, ?> properties) {
  final JMenuItem menuItem = taskFactories.remove(taskFactory);
  
  if (menuItem != null) {
    vizMapperMainPanel.getMainMenu().remove(menuItem);
    vizMapperMainPanel.getEditSubMenu().remove(menuItem);
    
    if (menuItem.getAction() instanceof PopupMenuListener) {
      vizMapperMainPanel.getMainMenu().removePopupMenuListener((PopupMenuListener)menuItem.getAction());
      vizMapperMainPanel.getContextMenu().removePopupMenuListener((PopupMenuListener)menuItem.getAction());
    }
  }
}

代码示例来源:origin: org.cytoscape/vizmap-gui-impl

/**
 * Custom listener for removing unregistered VizMapper CyActions from the main menu.
 */
public synchronized void onCyActionUnregistered(final CyAction action, final Map<?, ?> properties) {
  final Component[] arr = vizMapperMainPanel.getEditSubMenu().getComponents();
  final List<Component> cList = arr != null ? Arrays.asList(arr) : new ArrayList<Component>();
  for (final Component c : cList) {
    if (c instanceof JMenuItem && ((JMenuItem)c).getAction().equals(action)) {
      vizMapperMainPanel.getEditSubMenu().remove(c);
      vizMapperMainPanel.getContextMenu().removePopupMenuListener(action);
    }
  }
}

代码示例来源:origin: org.apache.cayenne.modeler/cayenne-modeler

public void popupMenuFilter() {
  Action cutAction = mediator.getApplication().getActionManager().getAction(CutAction.class);
  for (MenuElement element : popup.getSubElements()) {
    JMenuItem item = (JMenuItem) element;
    if (!item.getAction().equals(cutAction)) {
      item.setVisible(item.isEnabled());
    } else {
      break;
    }
  }
}

代码示例来源:origin: freeplane/freeplane

private void assertThatMenuItemHasCorrectAction(final JMenuItem menuItem) {
  final AccelerateableAction itemAction = (AccelerateableAction) menuItem.getAction();
  assertThat(itemAction.getOriginalAction(), CoreMatchers.<Action> equalTo(action));
}

代码示例来源:origin: Audiveris/audiveris

@Override
  public void mouseReleased (MouseEvent e)
  {
    JMenuItem item = (JMenuItem) e.getSource();
    RelationAction ra = (RelationAction) item.getAction();
    SIGraph sig = ra.getInter().getSig();
    Relation relation = ra.getRelation();
    String relStr = relation.getName();
    if (OMR.gui.displayConfirmation("Remove " + relStr + " relation?")) {
      interController.unlink(sig, relation);
    }
  }
}

代码示例来源:origin: UNIVALI-LITE/Portugol-Studio

public void adicionaMenu(JMenu submenu, boolean usaToggleButtons)
  {
    Action acoes[] = new Action[submenu.getItemCount()];

    for (int i = 0; i < submenu.getItemCount(); i++)
    {
      acoes[i] = submenu.getItem(i).getAction();
    }

    adicionaGrupoDeItems(submenu.getText(), submenu.getIcon(), acoes, usaToggleButtons);
  }
}

代码示例来源:origin: cpesch/RouteConverter

public void intervalRemoved(ListDataEvent e) {
  for (int i = e.getIndex1(); i >= e.getIndex0(); i--) {
    JMenuItem menuItem = i < menu.getMenuComponentCount() ? (JMenuItem) menu.getMenuComponent(i) : null;
    if (menuItem != null) {
      MergePositionListAction action = (MergePositionListAction) menuItem.getAction();
      action.dispose();
      menuItem.setAction(null);
    }
    if (menu.getItemCount() > i)
      menu.remove(i);
  }
  menu.setEnabled(formatAndRoutesModel.getSize() > 1);
}

代码示例来源:origin: com.mgmtp.gcviewer/gcviewer

public void internalFrameClosed(final InternalFrameEvent e) {
  if (desktopPane.getAllFrames().length == 0) arrangeAction.setEnabled(false);
  ((GCDocument)e.getInternalFrame()).getRefreshWatchDog().stop();
  // remove menuitem from menu and from button group
  for (int i=2; i<windowMenu.getItemCount(); i++) {
    final JMenuItem item = windowMenu.getItem(i);
    if (((WindowMenuItemAction)item.getAction()).getInternalFrame() == e.getInternalFrame()) {
      windowMenu.remove(item);
      windowCheckBoxGroup.remove(item);
      break;
    }
  }
}

相关文章

JMenuItem类方法