javax.swing.Action Java Examples

The following examples show how to use javax.swing.Action. 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: Install.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Implements superclass abstract method. Creates nodes from key.
 * @return <code>PendingActionNode</code> if key is of
 * <code>Action</code> type otherwise <code>null</code> */
protected Node[] createNodes(Object key) {
    Node n = null;
    if(key instanceof Action) {
        Action action = (Action)key;
        Icon icon = (action instanceof SystemAction) ?
            ((SystemAction)action).getIcon() : null;
        
        String actionName = (String)action.getValue(Action.NAME);
        if (actionName == null) actionName = ""; // NOI18N
        actionName = org.openide.awt.Actions.cutAmpersand(actionName);
        n = new NoActionNode(icon, actionName, NbBundle.getMessage(
                Install.class, "CTL_ActionInProgress", actionName));
    } else if (key instanceof ExecutorTask) {
        n = new NoActionNode(null, key.toString(),
                NbBundle.getMessage(Install.class, "CTL_PendingExternalProcess2",
                // getExecutionEngine() had better be non-null, since getPendingTasks gave an ExecutorTask:
                ExecutionEngine.getExecutionEngine().getRunningTaskName((ExecutorTask) key))
                );
    } else if (key instanceof InternalHandle) {
        n = new NoActionNode(null, ((InternalHandle)key).getDisplayName(), null);
    }
    return n == null ? null : new Node[] { n };
}
 
Example #2
Source File: SqlTemplatesAndActions.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public Action getOpenInSldEditorAction( TableLevel table, DatabaseViewer spatialiteViewer ) {
    if (spatialiteViewer.currentConnectedDatabase.getType() == EDb.GEOPACKAGE) {
        return new AbstractAction("Open in SLD editor"){
            @Override
            public void actionPerformed( ActionEvent e ) {
                try {

                    DefaultGuiBridgeImpl gBridge = new DefaultGuiBridgeImpl();
                    String databasePath = spatialiteViewer.currentConnectedDatabase.getDatabasePath();

                    final MainController controller = new MainController(new File(databasePath), table.tableName);
                    final JFrame frame = gBridge.showWindow(controller.asJComponent(), "HortonMachine SLD Editor");
                    Class<DatabaseViewer> class1 = DatabaseViewer.class;
                    ImageIcon icon = new ImageIcon(class1.getResource("/org/hortonmachine/images/hm150.png"));
                    frame.setIconImage(icon.getImage());
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        };
    } else {
        return null;
    }
}
 
Example #3
Source File: AbstractEditorActionTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Test
public void testWrapperAction() {
    Map attrs = new HashMap(SIMPLE_ATTRS);
    attrs.put(AbstractEditorAction.WRAPPER_ACTION_KEY, true);
    final MyAction a = new MyAction(); // No attrs passed
    attrs.put("delegate", a);
    WrapperEditorAction wrapperAction = WrapperEditorAction.create(attrs);
    JTextComponent c = new JEditorPane();
    assertEquals("my-name", wrapperAction.getValue(Action.NAME));
    assertNull(a.getValue(Action.NAME));
    
    ActionEvent evt = new ActionEvent(c, 0, "");
    wrapperAction.actionPerformed(evt);
    assertEquals(Thread.currentThread(), a.actionPerformedThread);

    // Properties transferred
    assertEquals("my-name", a.getValue(Action.NAME));
}
 
Example #4
Source File: UI.java    From Girinoscope with Apache License 2.0 6 votes vote down vote up
private JMenu createDataStrokeWidthMenu() {
    JMenu menu = new JMenu("Data stroke width");
    ButtonGroup group = new ButtonGroup();
    for (final int width : new int[]{1, 2, 3}) {
        Action setStrokeWidth = new AbstractAction(width + " px") {

            @Override
            public void actionPerformed(ActionEvent event) {
                graphPane.setDataStrokeWidth(width);
            }
        };
        AbstractButton button = new JCheckBoxMenuItem(setStrokeWidth);
        if (width == 1) {
            button.doClick();
        }
        group.add(button);
        menu.add(button);
    }
    return menu;
}
 
Example #5
Source File: PlugableFrame.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void addTreeItem(String menu, Action action, ViewPlugin plugin) {
    String[] strings = menu.split("/");
    for (int i = 0; i < strings.length; i++) {
        strings[i] = plugin.getString("Menu." + strings[i]);
    }

    TreeList map = mainMenu;
    for (int i = 0; i < strings.length - 1; i++) {
        TreeList m = (TreeList) map.get(strings[i]);
        if (m == null) {
            m = new TreeList();
            map.put(strings[i], m);
        }
        map = m;
    }
    ArrayList<Action> actions = (ArrayList<Action>) map
            .get(strings[strings.length - 1]);
    if (actions == null) {
        actions = new ArrayList<Action>();
        map.put(strings[strings.length - 1], actions);
    }
    actions.add(action);
}
 
Example #6
Source File: BattleDisplay.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
private Action getPlayerAction(
    final String title,
    final Supplier<RetreatResult> showDialog,
    final CompletableFuture<Territory> future) {
  return SwingAction.of(
      title,
      e -> {
        actionButton.setEnabled(false);
        final RetreatResult retreatResult = showDialog.get();
        if (retreatResult.isConfirmed()) {
          future.complete(retreatResult.getTarget());
          actionButton.setAction(nullAction);
        }
        actionButton.setEnabled(true);
      });
}
 
Example #7
Source File: BrowserUnavailableDialogFactory.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates a Copy Button
 *
 * @param text
 *            Text to copy into clipboard
 * @return
 */
private static JButton makeCopyButton(String text) {
	Action copyAction = new ResourceAction(true, "browser_unavailable.copy") {

		private static final long serialVersionUID = 1L;

		@Override
		public void loggedActionPerformed(ActionEvent e) {
			StringSelection stringSelection = new StringSelection(text);
			Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
			clpbrd.setContents(stringSelection, null);
		}

	};
	JButton copyButton = new JButton(copyAction);
	return copyButton;
}
 
Example #8
Source File: ShelveChangesAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static ShelveChangesActionProvider getProvider () {
    if (ACTION_PROVIDER == null) {
        ACTION_PROVIDER = new ShelveChangesActionProvider() {
            @Override
            public Action getAction () {
                Action a = SystemAction.get(SaveStashAction.class);
                Utils.setAcceleratorBindings("Actions/Git", a); //NOI18N
                return a;
            }

            @Override
            public JComponent[] getUnshelveActions (VCSContext ctx, boolean popup) {
                JComponent[] cont = UnshelveMenu.getInstance().getMenu(ctx, popup);
                if (cont == null) {
                    cont = super.getUnshelveActions(ctx, popup);
                }
                return cont;
            }
            
        };
    }
    return ACTION_PROVIDER;
}
 
Example #9
Source File: LocalHistoryVCSAnnotator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Action[] getActions(VCSContext ctx, VCSAnnotator.ActionDestination destination) {
    Lookup context = ctx.getElements();
    List<Action> actions = new ArrayList<Action>();
    if (destination == VCSAnnotator.ActionDestination.MainMenu) {
        actions.add(SystemAction.get(ShowHistoryAction.class));
        actions.add(SystemAction.get(RevertDeletedAction.class));
    } else {
        actions.add(SystemActionBridge.createAction(
                                        SystemAction.get(ShowHistoryAction.class), 
                                        NbBundle.getMessage(ShowHistoryAction.class, "CTL_ShowHistory"), 
                                        context));
        actions.add(SystemActionBridge.createAction(
                                        SystemAction.get(RevertDeletedAction.class), 
                                        NbBundle.getMessage(RevertDeletedAction.class, "CTL_ShowRevertDeleted"),  
                                        context));           
        
    }
    return actions.toArray(new Action[actions.size()]);
}
 
Example #10
Source File: SelectableTableView.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
public JToolBar createToolBar() {
    JToolBar bar = new JToolBar();

    for (Action action : getActions()) {
        if (action != null) {
            String command = (String) action
                    .getValue(Action.ACTION_COMMAND_KEY);
            JButton button = bar.add(action);
            button.setFocusable(false);
            if (action.getValue(Action.SHORT_DESCRIPTION) == null) {
                String text = null;
                StringGetter getter = (StringGetter) action
                        .getValue(StringGetter.ACTION_STRING_GETTER);
                if (getter != null)
                    text = getter.getString(command);
                else
                    text = GlobalResourcesManager.getString(command);
                if (text != null)
                    button.setToolTipText(text);
            }
        } else
            bar.addSeparator();
    }

    return bar;
}
 
Example #11
Source File: SnapUtilsTest.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testAddRemoveAction() throws Exception {
    AbstractAction realAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
        }
    };
    FileObject actionFile = SnapUtils.addAction(realAction, "Test/Action");
    assertNotNull(actionFile);
    assertNotNull(actionFile.getParent());
    assertEquals("application/x-nbsettings", actionFile.getMIMEType());
    assertEquals("Test/Action", actionFile.getParent().getPath());
    assertEquals("instance", actionFile.getExt());

    Action action = FileUtil.getConfigObject(actionFile.getPath(), Action.class);
    assertNotNull(action);
    assertEquals(TransientAction.class, action.getClass());
    assertSame(realAction, ((TransientAction) action).getDelegate());

    boolean ok = SnapUtils.removeAction(actionFile);
    assertEquals(true, ok);
    action = FileUtil.getConfigObject(actionFile.getPath(), Action.class);
    assertNull(action);
}
 
Example #12
Source File: ViewActions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an action that opens Watches TopComponent.
 */
public static Action createWatchesViewAction() {
    ViewActions action = new ViewActions("watchesView");
    // When changed, update also mf-layer.xml, where are the properties duplicated because of Actions.alwaysEnabled()
    action.putValue (Action.NAME, "CTL_WatchesAction");
    action.putValue ("iconbase",
            "org/netbeans/modules/debugger/resources/watchesView/watch_16.png" // NOI18N
    );
    return action;
}
 
Example #13
Source File: JavaStackTraceAction.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public JavaStackTraceAction() {
    super(VALUE_NAME, ActionManager.getIcon(VALUE_SMALL_ICON));

    putValue(Action.ACTION_COMMAND_KEY, VALUE_COMMAND);
    putValue(Action.SHORT_DESCRIPTION, VALUE_SHORT_DESCRIPTION);
    putValue(Action.LONG_DESCRIPTION, VALUE_LONG_DESCRIPTION);
    putValue(Action.MNEMONIC_KEY, VALUE_MNEMONIC);
}
 
Example #14
Source File: DropdownButton.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void addAction(JPopupMenu popup, Action action) {
    if (action == null) {
        popup.addSeparator();
    } else {
        Class cls = (Class)action.getValue(KEY_CLASS);
        if (Boolean.class.equals(cls)) {
            Boolean boolvalue = (Boolean)action.getValue(KEY_BOOLVALUE);
            JCheckBoxMenuItem item = new JCheckBoxMenuItem(action);
            item.setSelected(boolvalue);
            popup.add(item);
        } else {
            popup.add(action);
        }
    }
}
 
Example #15
Source File: DataLoaderGetActionsTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * This test should test behaviour of the getActions method when
 * there is some alien object specified in the configuration folder.
 * The testing object is of type Integer (instead of javax.swing.Action).
 */
public void testWrongActionObjectInConfig() throws Exception {
    assertEquals("No actions at the start", 0, node.getActions(false).length);
    FileObject test = root;
    FileObject a1 = test.createData("java-lang-String.instance");
    Action [] res = node.getActions(false);
    assertEquals("There should be zero actions.", 0, res.length);        
}
 
Example #16
Source File: SplitAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ClearSplitAction(TopComponent tc) {
           // Replaced by weak ref since strong ref led to leaking of editor panes
    this.tcRef = new WeakReference<TopComponent>(tc);
    putValue(Action.NAME, Bundle.LBL_ClearSplitAction());
    //hack to insert extra actions into JDev's popup menu
    putValue("_nb_action_id_", Bundle.LBL_ValueClearSplit()); //NOI18N
    if (tc instanceof Splitable) {
	setEnabled(((Splitable) tc).getSplitOrientation() != -1);
    } else {
	setEnabled(false);
    }
}
 
Example #17
Source File: ShowAction.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public ShowAction() {
    super(VALUE_NAME, ActionManager.getIcon(VALUE_SMALL_ICON));

    putValue(Action.ACTION_COMMAND_KEY, VALUE_COMMAND);
    putValue(Action.SHORT_DESCRIPTION, VALUE_SHORT_DESCRIPTION);
    putValue(Action.LONG_DESCRIPTION, VALUE_LONG_DESCRIPTION);
    putValue(Action.MNEMONIC_KEY, VALUE_MNEMONIC);
}
 
Example #18
Source File: SwingSet2.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
/**
 * Create the theme's audio submenu.
 *
 * @param menu the menu
 * @param label the label
 * @param mnemonic the mnemonic
 * @param accessibleDescription the accessible description
 * @param action the action
 * @return the j menu item
 */
public JMenuItem createAudioMenuItem(JMenu menu, String label,
		String mnemonic,
		String accessibleDescription,
		Action action) {
	JRadioButtonMenuItem mi = (JRadioButtonMenuItem) menu.add(new JRadioButtonMenuItem(getString(label)));
	audioMenuGroup.add(mi);
	mi.setMnemonic(getMnemonic(mnemonic));
	mi.getAccessibleContext().setAccessibleDescription(getString(accessibleDescription));
	mi.addActionListener(action);

	return mi;
}
 
Example #19
Source File: DebuggerAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static DebuggerAction createStepOutAction () {
    DebuggerAction action = new DebuggerAction(ActionsManager.ACTION_STEP_OUT);
    action.putValue (Action.NAME, "CTL_Step_out_action_name");
    action.putValue (
        "iconBase", // NOI18N
        "org/netbeans/modules/debugger/resources/actions/StepOut.gif" // NOI18N
    );
    return action;
}
 
Example #20
Source File: DialogHelper.java    From Girinoscope with Apache License 2.0 5 votes vote down vote up
public static void installEscapeCloseOperation(final JDialog dialog) {
    @SuppressWarnings("serial")
    Action dispatchClosing = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent event) {
            dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
        }
    };
    JRootPane root = dialog.getRootPane();
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ESCAPE_STROKE, DISPATCH_WINDOW_CLOSING_ACTION_MAP_KEY);
    root.getActionMap().put(DISPATCH_WINDOW_CLOSING_ACTION_MAP_KEY, dispatchClosing);
}
 
Example #21
Source File: ResultsSwitchViewAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Action[] getActions(NodeActionsProvider original, Object node) throws UnknownTypeException {
    Action[] actions = original.getActions(node);
    int n = actions.length;
    Action[] newActions = new Action[n+1];
    System.arraycopy(actions, 0, newActions, 0, n);
    if (switchViewAction == null) {
        switchViewAction = getSwitchViewAction();
    }
    newActions[n] = switchViewAction;
    return newActions;
}
 
Example #22
Source File: ExecuteDiskAction.java    From DiskBrowser with GNU General Public License v3.0 5 votes vote down vote up
public ExecuteDiskAction (MenuHandler owner)
// ---------------------------------------------------------------------------------//
{
  super ("Run current disk");
  putValue (Action.SHORT_DESCRIPTION, "Same as double-clicking on the disk");
  putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt X"));
  this.owner = owner;
}
 
Example #23
Source File: CDisableAllViewAction.java    From binnavi with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new action object.
 *
 * @param debuggerProvider Provides the debuggers where breakpoints can be set.
 * @param view The view to consider when disabling the breakpoints.
 */
public CDisableAllViewAction(
    final BackEndDebuggerProvider debuggerProvider, final INaviView view) {
  m_debuggerProvider =
      Preconditions.checkNotNull(debuggerProvider, "IE01347: Manager argument can not be null");
  m_view = Preconditions.checkNotNull(view, "IE01348: View argument can not be null");

  putValue(Action.SHORT_DESCRIPTION, "Disable all view breakpoints");
}
 
Example #24
Source File: OutlierErrorTableNode.java    From BART with MIT License 5 votes vote down vote up
@Override
public Action[] getActions(boolean context) {
   Action[] result = new Action[]{
        Actions.forID("RandomErrorsNode", "it.unibas.bartgui.controlegt.actions.node.randomError.EditToDO"),
    };
    return result;
}
 
Example #25
Source File: DebugSeleniumAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private DebugSeleniumAction(Lookup actionContext) {
    activatedFOs = lookupSeleniumTestOnly(actionContext);
    if(activatedFOs != null) {
        putValue(Action.NAME, Bundle.SeleniumDebugTestFileAction_name());
    }
    putValue(DynamicMenuContent.HIDE_WHEN_DISABLED, true);
    setEnabled(activatedFOs != null);
}
 
Example #26
Source File: MainFrame.java    From FCMFrame with Apache License 2.0 5 votes vote down vote up
public JMenuItem createMenuItem(JMenu menu, String label, String mnemonic, String accessibleDescription, Action action) {
	JMenuItem mi = (JMenuItem) menu.add(new JMenuItem(label));
	mi.addActionListener(action);
	if(action == null) {
		mi.setEnabled(false);
	}
	return mi;
}
 
Example #27
Source File: OpenLayoutPerspectiveAction.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
public OpenLayoutPerspectiveAction() {		
	putValue(Action.NAME, I18NSupport.getString("layout.perspective"));
	putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("report_perspective"));
	putValue(Action.ACCELERATOR_KEY,
			KeyStroke.getKeyStroke(ShortcutsUtil.getShortcut("perspective.report.open.accelerator", "control 2")));
	putValue(Action.SHORT_DESCRIPTION,
			I18NSupport.getString("layout.perspective.desc") + " (" + ShortcutsUtil.getShortcut("perspective.report.open.accelerator.display", "Ctrl 2") + ")");
	putValue(Action.LONG_DESCRIPTION, I18NSupport.getString("layout.perspective.desc"));
}
 
Example #28
Source File: ActionPool.java    From LoboBrowser with MIT License 5 votes vote down vote up
public Action createNavigateAction(final String fullURL) {
  try {
    return new NavigateAction(new URL(fullURL));
  } catch (final java.net.MalformedURLException mfu) {
    logger.log(Level.WARNING, "createNavigateAction()", mfu);
    throw new IllegalStateException(mfu);
  }
}
 
Example #29
Source File: ReloadAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NbBundle.Messages({"# {0} - count", "ACT_Reload_Projects=Reload {0} Projects"})
@SuppressWarnings("OverridableMethodCallInConstructor")
private ReloadAction(Lookup lkp) {
    context = lkp;
    Collection<? extends NbGradleProjectImpl> col = context.lookupAll(NbGradleProjectImpl.class);
    if (col.size() > 1) {
        putValue(Action.NAME, ACT_Reload_Projects(col.size()));
    } else {
        putValue(Action.NAME, ACT_Reload_Project());
    }
}
 
Example #30
Source File: DefaultSyntaxKit.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Add all pop-up menu items to a Toolbar.  <b>You need to call the validate method
 * on the toolbar after this is done to layout the buttons.</b>
 * Only Actions which have a SMALL_ICON property will be added to the toolbar
 * There are three Configuration Keys that affect the appearance of the added buttons:
 * CONFIG_TOOLBAR_ROLLOVER, CONFIG_TOOLBAR_BORDER, CONFIG_TOOLBAR_OPAQUE
 * 
 * @param editorPane
 * @param toolbar
 */
public void addToolBarActions(JEditorPane editorPane, JToolBar toolbar) {
	String[] toolBarItems = getConfig().getPropertyList(CONFIG_TOOLBAR);
	if (toolBarItems == null || toolBarItems.length == 0) {
		toolBarItems = getConfig().getPropertyList(CONFIG_MENU);
		if (toolBarItems == null || toolBarItems.length == 0) {
			return;
		}
	}
	boolean btnRolloverEnabled = getConfig().getBoolean(CONFIG_TOOLBAR_ROLLOVER, true);
	boolean btnBorderPainted = getConfig().getBoolean(CONFIG_TOOLBAR_BORDER, false);
	boolean btnOpaque = getConfig().getBoolean(CONFIG_TOOLBAR_OPAQUE, false);
	int btnBorderSize = getConfig().getInteger(CONFIG_TOOLBAR_BORDER_SIZE, 2);
	for (String menuString : toolBarItems) {
		if (menuString.equals("-") ||
			menuString.startsWith("<") ||
			menuString.startsWith(">")) {
			toolbar.addSeparator();
		} else {
			Action action = editorPane.getActionMap().get(menuString);
			if (action != null && action.getValue(Action.SMALL_ICON) != null) {
				JButton b = toolbar.add(action);
				b.setRolloverEnabled(btnRolloverEnabled);
				b.setBorderPainted(btnBorderPainted);
				b.setOpaque(btnOpaque);
				b.setFocusable(false);
				b.setBorder(BorderFactory.createEmptyBorder(btnBorderSize,
					btnBorderSize, btnBorderSize, btnBorderSize));
			}
		}
	}
}