Java Code Examples for javax.swing.Action#putValue()

The following examples show how to use javax.swing.Action#putValue() . 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: AbstractEditorAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public final void putValue(String key, Object value) {
    Action dAction = delegateAction;
    // Delegate whole putValue() if delegateAction already exists
    if (dAction != null && dAction != UNITIALIZED_ACTION) {
        dAction.putValue(key, value);
        return;
    }

    if (value == null && properties == null) { // Prevent NPE from super(null) in constructor
        return;
    }
    Object oldValue;
    if ("enabled" == key) { // Same == in AbstractAction
        oldValue = enabled;
        enabled = Boolean.TRUE.equals(value);
    } else {
        synchronized (properties) {
            oldValue = properties.put(key, (value != null) ? value : MASK_NULL_VALUE);
        }
    }
    firePropertyChange(key, oldValue, value); // Checks whether oldValue.equals(value)
}
 
Example 2
Source File: Assistant.java    From Dayon with GNU General Public License v3.0 6 votes vote down vote up
private Action createResetAction() {
    final Action configure = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent ev) {
            // Currently making a RESET within the assisted ...
            sendCaptureConfiguration(captureEngineConfiguration);
        }
    };

    configure.putValue(Action.NAME, "resetCapture");
    configure.putValue(Action.SHORT_DESCRIPTION, Babylon.translate("capture.reset"));
    configure.putValue(Action.SMALL_ICON, ImageUtilities.getOrCreateIcon(ImageNames.RESET_CAPTURE));

    return configure;
}
 
Example 3
Source File: LogFileViewer.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Inits the.
 *
 * @param file the file
 * @param d the d
 */
public void init(File file, Dimension d) {
	createMenus();
	this.logFile = file;
	this.textArea = new JTextArea();
	// Copy
	Action copyAction = this.textArea.getActionMap().get(DefaultEditorKit.copyAction);
	copyAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C,
			InputEvent.CTRL_MASK));
	copyAction.setEnabled(true);
	this.scrollPane = new JScrollPane(this.textArea);
	this.setContentPane(this.scrollPane);
	this.scrollPane.setPreferredSize(d);
	boolean doneLoadingFile = loadFile();
	if (!doneLoadingFile) {
		this.dispose();
		return;
	}
	this.pack();
	this.setVisible(true);
}
 
Example 4
Source File: AntActions.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Messages({
        "# {0} - # of selected projects (0 if disabled), or -1 if main project", 
        "# {1} - project name, if exactly one project", 
//        "LBL_ProfileMainProjectAction=&Profile {0,choice,-1#Main Project|0#Project|1#Project ({1})|1<{0} Projects}" // #231371
        "LBL_AttachMainProjectAction=&Attach to {0,choice,-1#Main Project|0#Project|1#Project ({1})|1<Project}"
    })
    @ActionID(category="Profile", id="org.netbeans.modules.profiler.actions.AttachMainProject")
    @ActionRegistration(displayName="#LBL_AttachMainProjectAction", lazy=false)
    @ActionReferences({
        @ActionReference(path="Menu/Profile", position=125)
    })
    public static Action attachMainProjectAction() {
        Action delegate = ProjectSensitiveActions.projectSensitiveAction(
                ProjectSensitivePerformer.attachProject(), 
                NbBundle.getMessage(AntActions.class, "LBL_AttachMainProjectAction"), // NOI18N
                Icons.getIcon(ProfilerIcons.ATTACH)
        );
        delegate.putValue(Action.SHORT_DESCRIPTION, NbBundle.getMessage(AntActions.class, "LBL_AttachMainProjectAction")); // NOI18N
        delegate.putValue("iconBase", Icons.getResource(ProfilerIcons.ATTACH)); // NOI18N
        
        return delegate;
    }
 
Example 5
Source File: FigureWidget.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example 6
Source File: CommonMenuText.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @param a the action to change the text, short description and mnemonic
 * @param substitutes substitutes to use in a message format
 * @param prop key bundle to use
 */
public static void name(Action a, String prop, Object... substitutes)
{
	a.putValue(Action.NAME, getName(prop, substitutes));
	String shortDesc = getShortDesc(prop, substitutes);
	if (shortDesc != null && !shortDesc.isEmpty())
	{
		a.putValue(Action.SHORT_DESCRIPTION, shortDesc);
	}
	a.putValue(Action.MNEMONIC_KEY, getMnemonic(prop));
}
 
Example 7
Source File: DiagramScene.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public Action createGotoAction(final Figure f) {
    final DiagramScene diagramScene = this;
    Action a = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            diagramScene.gotoFigure(f);
        }
    };

    a.setEnabled(true);
    a.putValue(Action.SMALL_ICON, new ColorIcon(f.getColor()));
    String name = f.getLines()[0];

    name += " (";

    if (f.getCluster() != null) {
        name += "B" + f.getCluster().toString();
    }
    if (!this.getFigureWidget(f).isVisible()) {
        if (f.getCluster() != null) {
            name += ", ";
        }
        name += "hidden";
    }
    name += ")";
    a.putValue(Action.NAME, name);
    return a;
}
 
Example 8
Source File: MRUScriptsAction.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
private Action createAction(String actionCommand) {
    Action action = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            menuItemActionPerformed(e);
        }
    };
 
    action.putValue(Action.ACTION_COMMAND_KEY, actionCommand);
    return action;
}
 
Example 9
Source File: ShelveChangesAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JComponent[] getMenu (VCSContext context, boolean popup) {
    Set<File> actionRoots = GitUtils.getRepositoryRoots(context);
    if (actionRoots.size() == 1) {
        final File root = actionRoots.iterator().next();
        RepositoryInfo info = RepositoryInfo.getInstance(root);
        final List<GitRevisionInfo> stashes = info.getStashes();
        if (!stashes.isEmpty()) {
            JMenu menu = new JMenu(popup ? Bundle.CTL_UnstashMenu_name_popup(): Bundle.CTL_UnstashMenu_name());
            Mnemonics.setLocalizedText(menu, menu.getText());
            int i = 0;
            for (ListIterator<Stash> it = Stash.create(root, stashes).listIterator(); it.hasNext() && i < 10; ++i) {
                Stash stash = it.next();
                Action a = stash.getApplyAction();
                String name = Bundle.CTL_UnstashAction_name(stash.getIndex(), stash.getInfo().getShortMessage());
                if (name.length() > 40) {
                    name = name.substring(0, 40);
                }
                a.putValue(Action.NAME, name);
                a.putValue(Action.SHORT_DESCRIPTION, stash.getInfo().getShortMessage());
                JMenuItem item = new JMenuItem(name);
                if (popup) {
                    Actions.connect(item, a, true);
                } else {
                    Actions.connect(item, a);
                }
                menu.add(item);
            }
            return new JComponent[] { menu };
        }
    }
    return null;
}
 
Example 10
Source File: Actions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static Action rebuildProject() {
    Action a = new ProjectAction(
        ActionProvider.COMMAND_REBUILD,
        NbBundle.getMessage(Actions.class, "LBL_RebuildProjectAction_Name"),
        NbBundle.getMessage(Actions.class, "LBL_RebuildProjectAction_Name_popup"),
        null,
        null ); 
    a.putValue("iconBase","org/netbeans/modules/project/ui/resources/rebuildCurrentProject.gif"); //NOI18N
    return a;
}
 
Example 11
Source File: StreamsEditDialog.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
private Action createAction(final String action, final ImageIcon icon) {
    final Action res = new AbstractAction(null, icon) {

        public void actionPerformed(ActionEvent e) {
            performed(e.getActionCommand());
        }

    };

    res.putValue(Action.ACTION_COMMAND_KEY, action);
    res
            .putValue(Action.SHORT_DESCRIPTION, ResourceLoader
                    .getString(action));
    return res;
}
 
Example 12
Source File: KeyBindingsUpdater.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void updateKits(Map<String,List<List<KeyStroke>>> actionName2binding, List<KitReference> kitRefs) {
    // Update kits without locks (a.putValue() is done)
    for (KitReference kitRef : kitRefs) {
        EditorKit kit = kitRef.get();
        if (kit == null) { // Might be null since this is a copy of orig. list
            continue;
        }
        Action[] actions = kit.getActions();
        for (int i = 0; i < actions.length; i++) {
            Action a = actions[i];
            String actionName = (String) a.getValue(Action.NAME);
            @SuppressWarnings("unchecked")
            List<List<KeyStroke>> origAccels = (List<List<KeyStroke>>) 
                    a.getValue(AbstractEditorAction.MULTI_ACCELERATOR_LIST_KEY);
            List<List<KeyStroke>> accels = actionName2binding.get(actionName);
            if (accels == null) {
                accels = Collections.emptyList();
            }
            if (origAccels == null || !origAccels.equals(accels)) {
                a.putValue(AbstractEditorAction.MULTI_ACCELERATOR_LIST_KEY, accels);
                if (accels.size() > 0) {
                    // First keystroke of first multi-key accelerator in the list
                    a.putValue(Action.ACCELERATOR_KEY, accels.get(0).get(0));
                }
            }
        }
    }
}
 
Example 13
Source File: QualifierPreferencesPanel.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
private JPopupMenu createPopupMenu() {
    JPopupMenu menu = new JPopupMenu();
    for (Action action : getActions()) {
        if (action == null)
            menu.addSeparator();
        else {
            action.putValue(Action.NAME, GlobalResourcesManager
                    .getString((String) action
                            .getValue(Action.ACTION_COMMAND_KEY)));
            menu.add(action);
        }
    }
    return menu;
}
 
Example 14
Source File: OpenRunningShellAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NbBundle.Messages({
        "# {0} - type of message",
        "# {1} - 1st projct name",
        "LBL_OpenShellForMainProject=&Open Java Shell for {0,choice,-1#Main Project|0#Project|1#Project ({1})|1<{0} Projects}"
})
public static Action action() {
    Action a = MainProjectSensitiveActions.mainProjectSensitiveAction(new OpenRunningShellAction(), 
            NbBundle.getMessage(OpenRunningShellAction.class, "LBL_OpenShellForMainProject"), null);
    a.putValue("iconBase", "org/netbeans/modules/jshell/resources/jshell-terminal.png");
    return a; 
}
 
Example 15
Source File: GoalsPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Action[] getActions(boolean context) {
    NetbeansActionMapping mapp = new NetbeansActionMapping();
    for (Param p : mojo.getNotSetParams()) {
        if (p.property != null) {
            mapp.addProperty(p.property, "");
        }
    }
    
    //
    // Execute with modifiers 
    //
    mapp.setGoals(Collections.singletonList(mojo.a.getGroupId() + ":" + mojo.a.getArtifactId() + ":" + mojo.a.getVersion() + ":" + mojo.goal));
    Action runGoalWithModsAction = ActionProviderImpl.createCustomMavenAction(mojo.prefix + ":" + mojo.goal, mapp, true, Lookup.EMPTY, project);
    runGoalWithModsAction.putValue(Action.NAME, ACT_Execute_mod());
    
    //
    // Show Documentation
    //
    // f.e.: help:describe -Dcmd=org.codehaus.mojo:gwt-maven-plugin:1.2:debug -Ddetail
    NetbeansActionMapping mappForHelpDesc = new NetbeansActionMapping();

    mappForHelpDesc.setGoals(Collections.singletonList("help:describe"));
    
    HashMap<String, String> m = new HashMap<>();
    m.put("cmd", String.format("%s:%s:%s:%s", mojo.a.getGroupId(), mojo.a.getArtifactId(), mojo.a.getVersion(), mojo.goal));
    m.put("detail", "true");
    mappForHelpDesc.setProperties(m);
    Action runHelpDescAction = ActionProviderImpl.createCustomMavenAction(String.format("help:describe for %s:%s", mojo.prefix, mojo.goal), mappForHelpDesc, false, Lookup.EMPTY, project);
    runHelpDescAction.putValue(Action.NAME, ACT_Execute_help());
    
    return new Action[] {
        new RunGoalAction(mojo, project),
        runGoalWithModsAction,
        null,
        runHelpDescAction
    };
}
 
Example 16
Source File: Actions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static Action cleanProject() {
    Action a = new ProjectAction(
            ActionProvider.COMMAND_CLEAN,
            NbBundle.getMessage(Actions.class, "LBL_CleanProjectAction_Name"),
            NbBundle.getMessage(Actions.class, "LBL_CleanProjectAction_Name_popup"),
            null,
            null );
    a.putValue("iconBase","org/netbeans/modules/project/ui/resources/cleanCurrentProject.gif"); //NOI18N
    return a;
}
 
Example 17
Source File: TaskPaneMain.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
Action makeAction(String title, String tooltiptext, String iconPath) {
  Action action = new AbstractAction(title) {
    public void actionPerformed(ActionEvent e) {}
  };
  action.putValue(Action.SMALL_ICON, new ImageIcon(TaskPaneMain.class
    .getResource(iconPath)));
  action.putValue(Action.SHORT_DESCRIPTION, tooltiptext);
  return action;
}
 
Example 18
Source File: ActionsTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Tests if changes in accelerator key or name of the action does not change the tooltip
 * of the button if the action has a custom tooltip. See first part of #57974.
 */
public void testTooltipsArePersistent() throws Exception {
    Action action = new ActionsTest.TestActionWithTooltip();
    JButton button = new JButton();
    
    Actions.connect(button, action);
    
    JFrame f = new JFrame();
    
    f.getContentPane().add(button);
    f.setVisible(true);
    
    assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP));
    
    action.putValue(Action.NAME, "new-name");
    
    assertTrue(button.getToolTipText().equals(TestActionWithTooltip.TOOLTIP));
    
    action.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('a'));
    
    assertTrue(button.getToolTipText().indexOf(TestActionWithTooltip.TOOLTIP) != (-1));
    
    f.setVisible(false);
}
 
Example 19
Source File: SampleProjectAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override public void actionPerformed(ActionEvent e) {
    Action sampleProject = CommonProjectActions.newProjectAction();
    sampleProject.putValue(ProjectTemplates.PRESELECT_CATEGORY, "Samples" ); // NOI18N
    sampleProject.actionPerformed( e );
}
 
Example 20
Source File: CommonProjectActions.java    From netbeans with Apache License 2.0 3 votes vote down vote up
/**
 * Creates action that invokes the <b>New Project</b> wizard, preselects the 
 * given category path and propagates a set of custom properties the wizard's 
 * {@link org.openide.WizardDescriptor}.
 * 
 * @param categoryPath the category path to be selected
 * @param initialProperties a map of custom properties which are propagated 
 * to the new project wizard's {@link org.openide.WizardDescriptor}
 *
 * @since 1.81
 * @return an action
 */
public static Action newProjectAction(String categoryPath, Map<String, Object> initialProperties) {
    Action a = newProjectAction();
    a.putValue(PRESELECT_CATEGORY, categoryPath );
    String[] keys = initialProperties.keySet().toArray(new String[initialProperties.size()]);
    a.putValue(INITIAL_VALUE_PROPERTIES, keys);
    for (String key : keys) {
        a.putValue(key, initialProperties.get(key));
    }
    return a;
}