Java Code Examples for javax.swing.AbstractAction#setEnabled()

The following examples show how to use javax.swing.AbstractAction#setEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProgressBarDemo.java    From beautyeye with Apache License 2.0 6 votes vote down vote up
/**
    * Creates the load button.
    *
    * @return the j button
    */
   public JButton createLoadButton() {
loadAction = new AbstractAction(getString("ProgressBarDemo.start_button")) {
    public void actionPerformed(ActionEvent e) {
	loadAction.setEnabled(false);
	stopAction.setEnabled(true);
               if (progressBar.getValue() == progressBar.getMaximum()) {
                   progressBar.setValue(0);
                   textLocation = 0;
                   progressTextArea.setText("");
               }
	timer.start();
    }
};
return createButton(loadAction);
   }
 
Example 2
Source File: TypeEditorMouseHandler.java    From binnavi with Apache License 2.0 5 votes vote down vote up
private JPopupMenu createNodeClickedMenu(final TreeNode clickedNode) {
  final JPopupMenu popupMenu = new JPopupMenu();
  if (clickedNode instanceof TypeMemberTreeNode) {
    final TypeMember selectedMember = ((TypeMemberTreeNode) clickedNode).getTypeMember();
    final AbstractAction editMemberAction = new EditMemberAction(
        owner, typeManager, selectedMember);
    final AbstractAction insertAction =
        new InsertMemberAction(owner, typeManager, selectedMember);
    if (tree.getSelectionCount() > 1) {
      editMemberAction.setEnabled(false);
      insertAction.setEnabled(false);
    }
    if (selectedMember.getParentType() != null
        && selectedMember.getParentType().getCategory() == BaseTypeCategory.STRUCT) {
      popupMenu.add(new AppendMemberAction(owner, typeManager, selectedMember.getParentType()));
      popupMenu.add(insertAction);
    }
    popupMenu.add(editMemberAction);
    popupMenu.add(new DeleteMemberAction(owner, typeManager, typeEditor));
  } else if (clickedNode instanceof BaseTypeTreeNode) {
    final BaseType selectedType = ((BaseTypeTreeNode) clickedNode).getBaseType();
    final AbstractAction editAction = new EditTypeAction(owner, typeManager, selectedType);
    final AbstractAction appendAction = new AppendMemberAction(owner, typeManager, selectedType);
    if (tree.getSelectionCount() > 1) {
      editAction.setEnabled(false);
      appendAction.setEnabled(false);
    } else if (selectedType.getCategory() != BaseTypeCategory.STRUCT) {
      appendAction.setEnabled(false);
    }
    popupMenu.add(editAction);
    popupMenu.add(appendAction);
    popupMenu.add(new DeleteTypeAction(owner, typeManager, typeEditor));
  }
  return popupMenu;
}
 
Example 3
Source File: ProgressBarDemo.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
/**
    * Creates the stop button.
    *
    * @return the j button
    */
   public JButton createStopButton() {
stopAction = new AbstractAction(getString("ProgressBarDemo.stop_button")) {
    public void actionPerformed(ActionEvent e) {
	timer.stop();
	loadAction.setEnabled(true);
	stopAction.setEnabled(false);
    }
};
return createButton(stopAction);
   }
 
Example 4
Source File: EditMenuControls.java    From pumpernickel with MIT License 4 votes vote down vote up
private void registerAction(EditCommand<AbstractAction> command,
		final Selection selection, final boolean requiresEdits) {
	final AbstractAction action = new EditMenuAction(
			(String) command.getValue(AbstractAction.ACTION_COMMAND_KEY));
	PropertyChangeListener pcl = new PropertyChangeListener() {

		JTextComponent textComponent;
		CaretListener caretListener = new CaretListener() {

			@Override
			public void caretUpdate(CaretEvent e) {
				refresh();
			}

		};

		@Override
		public void propertyChange(PropertyChangeEvent evt) {
			Component c = KeyboardFocusManager
					.getCurrentKeyboardFocusManager().getFocusOwner();

			if (c == textComponent)
				return;

			JTextComponent jtc = c instanceof JTextComponent ? ((JTextComponent) c)
					: null;

			if (textComponent != null)
				textComponent.removeCaretListener(caretListener);

			textComponent = jtc;

			if (textComponent != null)
				textComponent.addCaretListener(caretListener);

			refresh();
		}

		private void refresh() {
			if (textComponent == null) {
				action.setEnabled(false);
			} else if (!textComponent.isEditable() && requiresEdits) {
				action.setEnabled(false);
			} else if (selection == null) {
				action.setEnabled(true);
			} else {
				action.setEnabled(selection.accepts(textComponent));
			}
		}

	};
	KeyboardFocusManager.getCurrentKeyboardFocusManager()
			.addPropertyChangeListener("focusOwner", pcl);
	command.install(action);
	registerAction(action);
}
 
Example 5
Source File: TransientActionTest.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testProxyDelegatesAllCalls() throws Exception {
    String[] actionCommand = new String[1];
    AbstractAction delegate = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            actionCommand[0] = e.getActionCommand();
        }
    };
    delegate.setEnabled(false);

    TransientAction transientAction = new TransientAction(delegate, "Test/MyAction.instance");

    // Enables state
    assertEquals(false, delegate.isEnabled());
    assertEquals(false, transientAction.isEnabled());
    transientAction.setEnabled(true);
    assertEquals(true, delegate.isEnabled());
    assertEquals(true, transientAction.isEnabled());

    // Property values
    assertEquals(null, delegate.getValue("XXX"));
    assertEquals(null, transientAction.getValue("XXX"));
    transientAction.putValue("XXX", 3456);
    assertEquals(3456, delegate.getValue("XXX"));
    assertEquals(3456, transientAction.getValue("XXX"));

    // Property changes
    String[] name = new String[1];
    transientAction.addPropertyChangeListener(evt -> {
        name[0] = evt.getPropertyName();
    });
    assertEquals(null, name[0]);
    transientAction.putValue("XXX", 9954);
    assertEquals("XXX", name[0]);
    delegate.putValue("YYY", 9954);
    assertEquals("YYY", name[0]);

    // Action
    assertEquals(null, actionCommand[0]);
    delegate.actionPerformed(new ActionEvent(this, 0, "cmd1"));
    assertEquals("cmd1", actionCommand[0]);
    transientAction.actionPerformed(new ActionEvent(this, 1, "cmd2"));
    assertEquals("cmd2", actionCommand[0]);
}