当前位置: 首页>>代码示例>>Java>>正文


Java Action.setEnabled方法代码示例

本文整理汇总了Java中javax.swing.Action.setEnabled方法的典型用法代码示例。如果您正苦于以下问题:Java Action.setEnabled方法的具体用法?Java Action.setEnabled怎么用?Java Action.setEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.Action的用法示例。


在下文中一共展示了Action.setEnabled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testHideWhenDisabled

import javax.swing.Action; //导入方法依赖的package包/类
public void testHideWhenDisabled() throws Exception {
    class NoOpAction extends AbstractAction {
        NoOpAction(String n) {
            super(n);
        }
        public @Override void actionPerformed(ActionEvent e) {}
    }
    Action a = new NoOpAction("a1");
    assertEquals(Collections.singletonList("a1"), popupMenu(a));
    a = new NoOpAction("a2");
    a.setEnabled(false);
    assertEquals(Collections.singletonList("a2[disabled]"), popupMenu(a));
    a = new NoOpAction("a3");
    a.putValue(DynamicMenuContent.HIDE_WHEN_DISABLED, true);
    assertEquals(Collections.singletonList("a3"), popupMenu(a));
    a = new NoOpAction("a4");
    a.putValue(DynamicMenuContent.HIDE_WHEN_DISABLED, true);
    a.setEnabled(false);
    assertEquals(Collections.emptyList(), popupMenu(a));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:DefaultAWTBridgeTest.java

示例2: setEnableActionsX

import javax.swing.Action; //导入方法依赖的package包/类
private void setEnableActionsX(final String[] actions) {
    final Collection<Action> c = this.actions.values();
    final Iterator<Action> it = c.iterator();
    while (it.hasNext()) {
        final Action action = it.next();
        if (!isAllwayEnable(action)) {
            boolean b = false;
            for (final String s : actions) {
                if (s.equals(action.getValue(Action.ACTION_COMMAND_KEY)))
                    b = true;
            }
            if (b) {
                if (!action.isEnabled())
                    action.setEnabled(true);
            } else {
                if (action.isEnabled())
                    action.setEnabled(false);
            }
        }
    }
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:22,代码来源:MainFrame.java

示例3: buildPopup

import javax.swing.Action; //导入方法依赖的package包/类
@Override
public JPopupMenu buildPopup(int row) {
  final JPopupMenu m = new JPopupMenu();
  final Action playAction = new Player.LaunchAction(ModuleManagerWindow.this, file);
  playAction.setEnabled(!Info.isModuleTooNew(metadata.getVassalVersion()));
  m.add(playAction);
  final Action editAction = new Editor.ListLaunchAction(ModuleManagerWindow.this, file);
  editAction.setEnabled(!Info.isModuleTooNew(metadata.getVassalVersion()));
  m.add(editAction);
  m.add(new AbstractAction(Resources.getString("General.remove")) {
    private static final long serialVersionUID = 1L;

    public void actionPerformed(ActionEvent e) {
      removeModule(file);
      cleanupTileCache();
    }
  });

  m.addSeparator();
  m.add(addFolderAction);
  m.addSeparator();
  m.add(newExtensionAction);
  m.add(addExtensionAction);
  return m;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:26,代码来源:ModuleManagerWindow.java

示例4: getPopupMenu

import javax.swing.Action; //导入方法依赖的package包/类
@Override
public JPopupMenu getPopupMenu(Widget widget, Point point) {
    JPopupMenu menu = diagramScene.createPopupMenu();
    menu.addSeparator();

    build(menu, getFigure(), this, false, diagramScene);
    menu.addSeparator();
    build(menu, getFigure(), this, true, diagramScene);

    if (getFigure().getSubgraphs() != null) {
        menu.addSeparator();
        JMenu subgraphs = new JMenu("Subgraphs");
        menu.add(subgraphs);

        final GraphViewer viewer = Lookup.getDefault().lookup(GraphViewer.class);
        for (final InputGraph subgraph : getFigure().getSubgraphs()) {
            Action a = new AbstractAction() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    viewer.view(subgraph, true);
                }
            };

            a.setEnabled(true);
            a.putValue(Action.NAME, subgraph.getName());
            subgraphs.add(a);
        }
    }

    return menu;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:FigureWidget.java

示例5: testContextAwareActionsShareDelegate

import javax.swing.Action; //导入方法依赖的package包/类
public void testContextAwareActionsShareDelegate() throws Exception {
    myListenerCounter = 0;
    myIconResourceCounter = 0;
    Action a = readAction("testDelegate.instance");

    assertContextAware(a);
    assertNull("No real action created yet", MyAction.last);
    
    Action cca1 = ((ContextAwareAction)a).createContextAwareInstance(new AbstractLookup(new InstanceContent()));
    Action cca2 = ((ContextAwareAction)a).createContextAwareInstance(new AbstractLookup(new InstanceContent()));

    cca1.actionPerformed(new ActionEvent(this, 0, "kuk"));
    assertEquals("Action not invoked as it is disabled", 0, myListenerCalled);
    assertNotNull("real action created", MyAction.last);
    Action lastCca1 = MyAction.last;
    
    lastCca1.setEnabled(true);
    cca1.actionPerformed(new ActionEvent(this, 0, "kuk"));
    assertEquals("Action invoked as no longer disabled", 1, myListenerCalled);

    cca2.actionPerformed(new ActionEvent(this, 0, "kuk"));

    Action lastCca2 = MyAction.last;
    assertEquals("MyAction created just once", lastCca1, lastCca2);
    
    assertEquals("Action invoked as it remains enabled", 2, myListenerCalled);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:AlwaysEnabledActionTest.java

示例6: setInputVisible

import javax.swing.Action; //导入方法依赖的package包/类
@Override
public void setInputVisible(boolean val) {
    super.setInputVisible(val);
    Action pasteAction = action(PASTE);
    if (pasteAction != null) {
        pasteAction.setEnabled(val);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:OutputTab.java

示例7: getPopupActions

import javax.swing.Action; //导入方法依赖的package包/类
@Override
public Action[] getPopupActions() {
    List<TreeListNode> selectedNodes = DashboardViewer.getInstance().getSelectedNodes();
    TaskNode[] taskNodes = new TaskNode[selectedNodes.size()];
    boolean justTasks = true;
    boolean containsNewTask = false;
    for (int i = 0; i < selectedNodes.size(); i++) {
        TreeListNode treeListNode = selectedNodes.get(i);
        if (treeListNode instanceof TaskNode) {
            taskNodes[i] = (TaskNode) treeListNode;
            if (!containsNewTask &&((TaskNode) treeListNode).getTask().isNew()) {
                containsNewTask = true;
            }
        } else {
            justTasks = false;
            break;
        }
    }
    List<Action> actions = new ArrayList<Action>();
    if (justTasks) {
        actions.addAll(Actions.getTaskPopupActions(taskNodes));
        actions.add(null);
    }
    List<Action> submitablePopupActions = Actions.getSubmitablePopupActions(selectedNodes.toArray(new TreeListNode[selectedNodes.size()]));
    if (!submitablePopupActions.isEmpty()) {
        actions.addAll(submitablePopupActions);
        actions.add(null);
    }
    List<Action> defaultActions = Actions.getDefaultActions(selectedNodes.toArray(new TreeListNode[selectedNodes.size()]));
    if (containsNewTask) {
        for (Action action : defaultActions) {
            action.setEnabled(false);
        }
    }
    actions.addAll(defaultActions);
    return actions.toArray(new Action[actions.size()]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:TaskNode.java

示例8: getScheduleAction

import javax.swing.Action; //导入方法依赖的package包/类
/**
 * Create action for changing scheduling info for supplied nodes.
 *
 * <p>
 * If one of the nodes does not support schedule handling, the action is disabled!</p>
 *
 * @param nodes
 * @return
 */
private static Action getScheduleAction(final TaskNode... taskNodes) {
    // Check the selected nodes - if one of the selected nodes does not
    // support scheduling - don't offer it in the menu
    boolean hasSchedule = true;
    for (TaskNode tn : taskNodes) {
        if (!tn.getTask().hasSchedule()) {
            hasSchedule = false;
            break;
        }
    }

    IssueScheduleInfo schedule = null;
    if (taskNodes.length == 1) {
        schedule = taskNodes[0].getTask().getSchedule();
    }
    final DashboardUtils.SchedulingMenu scheduleMenu = DashboardUtils.createScheduleMenu(schedule);

    //TODO weak listener??
    final ChangeListener listener = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            for (TaskNode taskNode : taskNodes) {
                if (taskNode.getTask().hasSchedule()) {
                    taskNode.getTask().setSchedule(scheduleMenu.getScheduleInfo());
                }
            }
            scheduleMenu.removeChangeListener(this);
        }
    };
    scheduleMenu.addChangeListener(listener);
    Action menuAction = scheduleMenu.getMenuAction();
    menuAction.setEnabled(hasSchedule);
    return menuAction;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:44,代码来源:Actions.java

示例9: buildPasteAction

import javax.swing.Action; //导入方法依赖的package包/类
protected Action buildPasteAction(final Configurable target) {
  final Action a = new AbstractAction(pasteCmd) {
    private static final long serialVersionUID = 1L;

    public void actionPerformed(ActionEvent e) {
      if (cutData != null) {
        final DefaultMutableTreeNode targetNode = getTreeNode(target);
        final Configurable cutObj = (Configurable) cutData.getUserObject();
        final Configurable convertedCutObj = convertChild(target, cutObj);
        if (remove(getParent(cutData), cutObj)) {
          insert(target, convertedCutObj, targetNode.getChildCount());
        }
        copyData = getTreeNode(convertedCutObj);
      }
      else if (copyData != null) {
        final Configurable copyBase = (Configurable) copyData.getUserObject();
        Configurable clone = null;
        try {
          clone = convertChild(target, copyBase.getClass().getConstructor().newInstance());
        }
        catch (Throwable t) {
          ReflectionUtils.handleNewInstanceFailure(t, copyBase.getClass());
        }

        if (clone != null) {
          clone.build(copyBase.getBuildElement(Builder.createNewDocument()));
          insert(target, clone, getTreeNode(target).getChildCount());
          updateGpIds(clone);
        }
      }
      cutData = null;
      updateEditMenu();
    }
  };
  a.setEnabled(isValidPasteTarget(target));
  return a;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:38,代码来源:ConfigureTree.java

示例10: updateActions

import javax.swing.Action; //导入方法依赖的package包/类
/**
 * Ensures that undo/redo actions are enabled appropriately and have
 * descriptive text at all times.
 */
public void updateActions() {

	String text;

	Action a = RTextArea.getAction(RTextArea.UNDO_ACTION);
	if (canUndo()) {
		a.setEnabled(true);
		text = getUndoPresentationName();
		a.putValue(Action.NAME, text);
		a.putValue(Action.SHORT_DESCRIPTION, text);
	}
	else {
		if (a.isEnabled()) {
			a.setEnabled(false);
			text = cantUndoText;
			a.putValue(Action.NAME, text);
			a.putValue(Action.SHORT_DESCRIPTION, text);
		}
	}

	a = RTextArea.getAction(RTextArea.REDO_ACTION);
	if (canRedo()) {
		a.setEnabled(true);
		text = getRedoPresentationName();
		a.putValue(Action.NAME, text);
		a.putValue(Action.SHORT_DESCRIPTION, text);
	}
	else {
		if (a.isEnabled()) {
			a.setEnabled(false);
			text = cantRedoText;
			a.putValue(Action.NAME, text);
			a.putValue(Action.SHORT_DESCRIPTION, text);
		}
	}

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:42,代码来源:RUndoManager.java

示例11: setActionEnabled

import javax.swing.Action; //导入方法依赖的package包/类
public void setActionEnabled(String name, boolean enabled)
{
    Action action = getAction(name);
    if(action != null)
        action.setEnabled(enabled);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:ActionManager.java

示例12: testDelegatesToPreviousInstanceWhenCreated

import javax.swing.Action; //导入方法依赖的package包/类
public void testDelegatesToPreviousInstanceWhenCreated() throws Exception {
    myListenerCounter = 0;
    myIconResourceCounter = 0;
    Action a = readAction("testDelegate.instance");

    assertNotNull("Action created", a);
    assertEquals("No myListener called", 0, myListenerCounter);
    assertEquals("No myIconURL called", 0, myIconResourceCounter);

    Object name = a.getValue(a.NAME);
    Object mnem = a.getValue(a.MNEMONIC_KEY);
    Object smallIcon = a.getValue(a.SMALL_ICON);
    //Object icon = a.getValue(a.ICON)

    assertEquals("Right localized name", "Icon &Name Action", name);
    assertEquals("Mnemonic is N", (int) 'N', mnem);
    assertNotNull("small icon present", smallIcon);

    assertEquals("once icon called", 1, myIconResourceCounter);


    Object base = a.getValue("iconBase");
    assertEquals("iconBase attribute is delegated", 2, myIconResourceCounter);

    assertTrue("Always enabled", a.isEnabled());
    a.setEnabled(false);
    assertTrue("Still Always enabled", a.isEnabled());

    assertNull("No real action created yet", MyAction.last);
    a.actionPerformed(new ActionEvent(this, 0, "kuk"));
    assertEquals("Action not invoked as it is disabled", 0, myListenerCalled);
    assertNotNull("real action created", MyAction.last);
    a.addPropertyChangeListener(this);
    assertFalse("Disabled", a.isEnabled());
    MyAction.last.setEnabled(true);
    assertEquals("Change in a property delivered", 1, changeCounter);
    assertTrue("enabled now", a.isEnabled());
    a.actionPerformed(new ActionEvent(this, 0, "kuk"));
    assertEquals("Action invoked as no longer disabled", 1, myListenerCalled);

    assertEquals("No icon in menu", Boolean.TRUE, a.getValue("noIconInMenu"));

    assertEquals("Right localized name", "Icon &Name Action", a.getValue(Action.NAME));
    MyAction.last.putValue(MyAction.NAME, "Ahoj");
    assertEquals("Next Change in a property delivered", 2, changeCounter);
    assertEquals("Value taken from delegate", "Ahoj", a.getValue(Action.NAME));


    assertContextAware(a);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:51,代码来源:AlwaysEnabledActionTest.java

示例13: testContextAwareDelegate

import javax.swing.Action; //导入方法依赖的package包/类
public void testContextAwareDelegate() throws Exception {
    myListenerCounter = 0;
    myIconResourceCounter = 0;
    Action a = readAction("testContextDelegate.instance");

    assertNotNull("Action created", a);
    assertEquals("No myListener called", 0, myListenerCounter);
    assertEquals("No myIconURL called", 0, myIconResourceCounter);

    Object name = a.getValue(a.NAME);
    Object mnem = a.getValue(a.MNEMONIC_KEY);
    Object smallIcon = a.getValue(a.SMALL_ICON);
    //Object icon = a.getValue(a.ICON)

    assertEquals("Right localized name", "Icon &Name Action", name);
    assertEquals("Mnemonic is N", (int) 'N', mnem);
    assertNotNull("small icon present", smallIcon);

    assertEquals("once icon called", 1, myIconResourceCounter);


    Object base = a.getValue("iconBase");
    assertEquals("iconBase attribute is delegated", 2, myIconResourceCounter);

    assertTrue("Always enabled", a.isEnabled());
    a.setEnabled(false);
    assertTrue("Still Always enabled", a.isEnabled());

    assertNull("No real action created yet", MyAction.last);

    InstanceContent ic = new InstanceContent();
    Lookup lkp = new AbstractLookup(ic);
    if (a instanceof ContextAwareAction) {
        a = ((ContextAwareAction)a).createContextAwareInstance(lkp);
    } else {
        fail("Should be context sensitive: " + a);
    }
    assertEquals("No clone created yet", 0, MyContextAction.clones);

    a.actionPerformed(new ActionEvent(this, 0, "kuk"));

    assertEquals("Clone created", 1, MyContextAction.clones);
    assertSame("Lookup used", lkp, MyContextAction.lkp);

    assertEquals("Action not invoked as it is disabled", 0, myListenerCalled);
    assertNotNull("real action created", MyAction.last);
    a.addPropertyChangeListener(this);
    assertFalse("Disabled", a.isEnabled());
    MyAction.last.setEnabled(true);
    assertEquals("Change in a property delivered", 1, changeCounter);
    assertTrue("enabled now", a.isEnabled());
    a.actionPerformed(new ActionEvent(this, 0, "kuk"));
    assertEquals("Action invoked as no longer disabled", 1, myListenerCalled);

    assertEquals("No icon in menu", Boolean.TRUE, a.getValue("noIconInMenu"));

    assertEquals("Right localized name", "Icon &Name Action", a.getValue(Action.NAME));
    MyAction.last.putValue(MyAction.NAME, "Ahoj");
    assertEquals("Next Change in a property delivered", 2, changeCounter);
    assertEquals("Value taken from delegate", "Ahoj", a.getValue(Action.NAME));

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:63,代码来源:AlwaysEnabledActionTest.java

示例14: getActions

import javax.swing.Action; //导入方法依赖的package包/类
@NbBundle.Messages({
    "LBL_RerunTest=Run Again",
    "LBL_DebugTest=Debug"
})
@Override
public Action[] getActions(boolean context) {
    List<Action> actions = new ArrayList<Action>();
    Action preferred = getPreferredAction();
    if (preferred != null) {
        actions.add(preferred);
    }
    // Method node might belong to an inner class
    FileObject testFO = ((JUnitTestcase) testcase).getClassFileObject(true);
    if (testFO == null) {
        Logger.getLogger(AntJUnitTestMethodNode.class.getName()).log(Level.INFO, "Test running process was probably abnormally interrupted. Could not locate FileObject for {0}", testcase.toString());
        for (Action prefAction : actions) {
            prefAction.setEnabled(false);
        }
    } else {
        boolean parameterized = false;
        try {
            String text = testFO.asText();
            if (text != null) {
                text = text.replaceAll("\n", "").replaceAll(" ", "");
                if ((text.contains("@RunWith") || text.contains("@org.junit.runner.RunWith")) //NOI18N
                        && text.contains("Parameterized.class)")) {  //NOI18N
                    parameterized = true;
                }
            }
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }

        if (!parameterized) {
            ActionProvider actionProvider = OutputUtils.getActionProvider(testFO);
            if (actionProvider != null) {
                List supportedActions = Arrays.asList(actionProvider.getSupportedActions());

                SingleMethod methodSpec = new SingleMethod(testFO, testcase.getName());
                Lookup nodeContext = Lookups.singleton(methodSpec);
                if (supportedActions.contains(COMMAND_RUN_SINGLE_METHOD)
                        && actionProvider.isActionEnabled(COMMAND_RUN_SINGLE_METHOD, nodeContext)) {
                    actions.add(new TestMethodNodeAction(actionProvider, nodeContext, COMMAND_RUN_SINGLE_METHOD, Bundle.LBL_RerunTest()));
                }
                if (supportedActions.contains(COMMAND_DEBUG_SINGLE_METHOD)
                        && actionProvider.isActionEnabled(COMMAND_DEBUG_SINGLE_METHOD, nodeContext)) {
                    actions.add(new TestMethodNodeAction(actionProvider, nodeContext, COMMAND_DEBUG_SINGLE_METHOD, Bundle.LBL_DebugTest()));
                }
            }
        }
    }
    actions.addAll(Arrays.asList(super.getActions(context)));

    return actions.toArray(new Action[actions.size()]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:56,代码来源:AntJUnitTestMethodNode.java

示例15: buildTranslateAction

import javax.swing.Action; //导入方法依赖的package包/类
protected Action buildTranslateAction(final Configurable target) {
  Action a = new TranslateAction(target, helpWindow, this);
  a.setEnabled(target.getI18nData().isTranslatable());
  return a;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:6,代码来源:ConfigureTree.java


注:本文中的javax.swing.Action.setEnabled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。