當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。