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

The following examples show how to use javax.swing.AbstractAction#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: ButtonFactory.java    From openAGV with Apache License 2.0 6 votes vote down vote up
private static JButton createFontStyleItalicButton(DrawingEditor editor) {
  JButton button = new JButton();
  button.setIcon(ImageDirectory.getImageIcon("/toolbar/attributeFontItalic.png"));
  button.setText(null);
  button.setToolTipText(BUNDLE.getString("buttonFactory.button_fontStyleItalic.tooltipText"));
  button.setFocusable(false);

  AbstractAction action
      = new AttributeToggler<>(editor,
                               AttributeKeys.FONT_ITALIC,
                               Boolean.TRUE,
                               Boolean.FALSE,
                               new StyledEditorKit.BoldAction());
  action.putValue(ActionUtil.UNDO_PRESENTATION_NAME_KEY,
                  BUNDLE.getString("buttonFactory.action_fontStyleItalic.undo.presentationName"));
  button.addActionListener(action);

  return button;
}
 
Example 2
Source File: ButtonFactory.java    From openAGV with Apache License 2.0 6 votes vote down vote up
private static JButton createFontStyleUnderlineButton(DrawingEditor editor) {
  JButton button = new JButton();
  button.setIcon(ImageDirectory.getImageIcon("/toolbar/attributeFontUnderline.png"));
  button.setText(null);
  button.setToolTipText(BUNDLE.getString("buttonFactory.button_fontStyleUnderline.tooltipText"));
  button.setFocusable(false);

  AbstractAction action
      = new AttributeToggler<>(editor,
                               AttributeKeys.FONT_UNDERLINE,
                               Boolean.TRUE,
                               Boolean.FALSE,
                               new StyledEditorKit.BoldAction());
  action.putValue(ActionUtil.UNDO_PRESENTATION_NAME_KEY,
                  BUNDLE.getString("buttonFactory.action_fontStyleUnderline.undo.presentationName"));
  button.addActionListener(action);

  return button;
}
 
Example 3
Source File: BasicGraphEditor.java    From blog-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param name
 * @param action
 * @return a new Action bound to the specified string name and icon
 */
@SuppressWarnings("serial")
public Action bind(String name, final Action action, String iconUrl)
{
	AbstractAction newAction = new AbstractAction(name, (iconUrl != null) ? new ImageIcon(
			BasicGraphEditor.class.getResource(iconUrl)) : null)
	{
		public void actionPerformed(ActionEvent e)
		{
			action.actionPerformed(new ActionEvent(getGraphComponent(), e
					.getID(), e.getActionCommand()));
		}
	};
	
	newAction.putValue(Action.SHORT_DESCRIPTION, action.getValue(Action.SHORT_DESCRIPTION));
	
	return newAction;
}
 
Example 4
Source File: Tools.java    From Zettelkasten with GNU General Public License v3.0 6 votes vote down vote up
/**
     * This method sets the locale descriptions for the standard-actions cut,
     * copy and paste - which are in English by default.
     *
     * @param actionMap the class's actionmap
     */
    public static void initLocaleForDefaultActions(javax.swing.ActionMap actionMap) {
        String[] actions = new String[]{"cut", "copy", "paste"};
        for (String ac : actions) {
            // get the action's name
            AbstractAction aac = (AbstractAction) actionMap.get(ac);
            // and put them together :-)
            aac.putValue(AbstractAction.NAME, toolbarResourceMap.getString(ac + ".Action.text"));
            aac.putValue(AbstractAction.SHORT_DESCRIPTION, toolbarResourceMap.getString(ac + ".Action.shortDescription"));
//            // get the new icon-path from the resource-map
//            URL imgURL = org.jdesktop.application.Application.getInstance(de.danielluedecke.zettelkasten.ZettelkastenApp.class).getClass().getResource(resourceMap.getString(ac+".Action.largeIcon"));
//            // create icon
//            ImageIcon img = new ImageIcon(imgURL);
//            aac.putValue(AbstractAction.LARGE_ICON_KEY, img);
            aac.putValue(AbstractAction.SMALL_ICON, null);
        }
    }
 
Example 5
Source File: RunTargetsAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Action createContextAwareInstance(final Lookup actionContext) {
    if (actionContext.lookup(TargetLister.Target.class) != null) { //#220590
        final Target target = actionContext.lookup(TargetLister.Target.class);
        AbstractAction a = new AbstractAction(getName()) {
                          @Override
                          public void actionPerformed(ActionEvent e) {
                              try {
                                  new TargetExecutor(target.getOriginatingScript(), new String[]{target.getName()}).execute();
                              } catch (IOException ioe) {
                                  AntModule.err.notify(ioe);
                              }
                          }
                      };
        
        a.putValue(ACCELERATOR_KEY, this.getValue(ACCELERATOR_KEY));            
        return a;
    } else {
        return new ContextAction(actionContext);
    }
}
 
Example 6
Source File: ActionsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testCheckPrioritiesOfIcons() {
    AbstractAction aa = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    };
    Icon icon = ImageUtilities.loadImageIcon("org/openide/awt/TestIcon_big.png", true);
    aa.putValue(Action.SMALL_ICON, icon);
    aa.putValue("iconBase", "org/openide/awt/data/testIcon.gif");
    
    JButton b = new JButton();
    Actions.connect(b, aa);
    
    JMenuItem m = new JMenuItem();
    Actions.connect(m, aa, false);
    
    
    assertSame("Using the same icon (small" + icon, b.getIcon(), m.getIcon());
}
 
Example 7
Source File: ActionsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testCheckPrioritiesOfIconsWithStringSmallIcon() {
    AbstractAction aa = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    };
    Object icon = "org/openide/awt/TestIcon_big.png";
    aa.putValue(Action.SMALL_ICON, icon);
    aa.putValue("iconBase", "org/openide/awt/data/testIcon.gif");
    
    JButton b = new JButton();
    Actions.connect(b, aa);
    
    JMenuItem m = new JMenuItem();
    Actions.connect(m, aa, false);
    
    
    assertSame("Using the same icon (small" + icon, b.getIcon(), m.getIcon());
}
 
Example 8
Source File: SourceMultiViewElement.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public CloseOperationState canCloseElement() {
    // if this is not the last cloned editor component, closing is OK
    if(!getEditorSupport().isModified() ||
            MultiViewSupport.getNumberOfClones(multiViewCallback.getTopComponent()) > 1) {
        return CloseOperationState.STATE_OK;
    }
    // return a state which will save/discard changes and is called by close handler
    AbstractAction save = new AbstractAction(){
                public void actionPerformed(ActionEvent arg0) {
                    //save changes
                    try {
                        getEditorSupport().saveDocument();
                    } catch (IOException ex) {
                    }
                }

            };
    save.putValue(Action.LONG_DESCRIPTION, NbBundle.getMessage(DataObject.class,
                        "MSG_SaveFile", // NOI18N
                        getEditorSupport().getDataObject().getPrimaryFile().getNameExt()));     
    return MultiViewFactory.createUnsafeCloseState(
            "ID_JAXWS_CLOSING", // NOI18N
            save,
            MultiViewFactory.NOOP_CLOSE_ACTION);
}
 
Example 9
Source File: ButtonFactory.java    From openAGV with Apache License 2.0 6 votes vote down vote up
private static JButton createFontStyleBoldButton(DrawingEditor editor) {
  JButton button = new JButton();
  button.setIcon(ImageDirectory.getImageIcon("/toolbar/attributeFontBold.png"));
  button.setText(null);
  button.setToolTipText(BUNDLE.getString("buttonFactory.button_fontStyleBold.tooltipText"));
  button.setFocusable(false);

  AbstractAction action
      = new AttributeToggler<>(editor,
                               AttributeKeys.FONT_BOLD,
                               Boolean.TRUE,
                               Boolean.FALSE,
                               new StyledEditorKit.BoldAction());
  action.putValue(ActionUtil.UNDO_PRESENTATION_NAME_KEY,
                  BUNDLE.getString("buttonFactory.action_fontStyleBold.undo.presentationName"));
  button.addActionListener(action);

  return button;
}
 
Example 10
Source File: MainFrame.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
public Action createAction(final String name, final String label,
                           final String describe, final Icon icon, final KeyStroke stroke) {
    final AbstractAction action = new AbstractAction(label, icon) {

        public void actionPerformed(ActionEvent e) {
            MainFrame.this.actionPerformed(e);
        }

    };
    actions.put(name, action);
    action.putValue(Action.ACTION_COMMAND_KEY, name);
    if (describe != null)
        action.putValue(Action.SHORT_DESCRIPTION, describe);
    if (stroke != null)
        action.putValue(Action.ACCELERATOR_KEY, stroke);

    return action;
}
 
Example 11
Source File: PageFlowElement.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public CloseOperationState canCloseElement() {
    if (!getEditorSupport().isModified()) {
        return CloseOperationState.STATE_OK;
    }

    AbstractAction save = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            //save changes
            try {
                getEditorSupport().saveDocument();
            } catch (IOException ex) {
                LOG.log(Level.WARNING, "File {0} couldn''t be saved.", context.getFacesConfigFile().getName());
            }
        }
    };
    save.putValue(Action.LONG_DESCRIPTION, NbBundle.getMessage(DataObject.class,
            "MSG_SaveFile", // NOI18N
            getEditorSupport().getDataObject().getPrimaryFile().getNameExt()));

    return MultiViewFactory.createUnsafeCloseState(
            "ID_FACES_CONFIG_CLOSING", //NOI18N
            save,
            MultiViewFactory.NOOP_CLOSE_ACTION);
}
 
Example 12
Source File: View.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
public static void addEditorAction(JEditorPane editor, AbstractAction a, String key, String name, String keyStroke) {
    KeyStroke ks = KeyStroke.getKeyStroke(keyStroke);
    a.putValue(Action.ACCELERATOR_KEY, ks);
    a.putValue(Action.NAME, name);

    String actionName = key;
    ActionMap amap = editor.getActionMap();
    InputMap imap = editor.getInputMap(JTextComponent.WHEN_FOCUSED);
    imap.put(ks, actionName);
    amap.put(actionName, a);

    JPopupMenu pmenu = editor.getComponentPopupMenu();
    JMenuItem findUsagesMenu = new JMenuItem(a);
    pmenu.add(findUsagesMenu);
}
 
Example 13
Source File: DisplayableCard.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
private AbstractAction generateActionFromKey(MTGKeyWord k) throws NoSuchMethodException,InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException {
		Class a = PluginRegistry.inst().loadClass("org.magic.game.actions.cards." + k.toString() + "Actions");
		Constructor ctor = a.getDeclaredConstructor(DisplayableCard.class);
		AbstractAction aaction = (AbstractAction) ctor.newInstance(this);
		aaction.putValue(Action.LONG_DESCRIPTION, k.getKeyword());
	return aaction;
}
 
Example 14
Source File: WebPanel.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
private AbstractAction createAction(final String name, final String text, final Icon icon) {
    final AbstractAction action = new AbstractAction(name, icon) {

        public void actionPerformed(ActionEvent e) {
            WebPanel.this.actionPerformed(e);
        }

    };
    action.putValue(Action.LONG_DESCRIPTION, text);
    action.putValue(Action.SHORT_DESCRIPTION, text);
    action.putValue(Action.DEFAULT, text);
    actions.add(action);
    return action;
}
 
Example 15
Source File: PropertiesEditorSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Messages({
    "MSG_SaveModified=File {0} is modified. Save?"
})
@Override
public CloseOperationState canCloseElement() {
    final CloneableEditorSupport sup = getLookup().lookup(CloneableEditorSupport.class);
    Enumeration en = getReference().getComponents();
    if (en.hasMoreElements()) {
        en.nextElement();
        if (en.hasMoreElements()) {
            // at least two is OK
            return CloseOperationState.STATE_OK;
        }
    }
    
    PropertiesDataObject dataObject = getDataObject();
    if (dataObject.isModified()) {
        AbstractAction save = new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    sup.saveDocument();
                } catch (IOException ex) {
                    Exceptions.printStackTrace(ex);
                }
            }
        };
        save.putValue(Action.LONG_DESCRIPTION, Bundle.MSG_SaveModified(FileUtil.getFileDisplayName(dataObject.getPrimaryFile())));
        return MultiViewFactory.createUnsafeCloseState("editor", save, null);
    } 
    return CloseOperationState.STATE_OK;
}
 
Example 16
Source File: FormEditorSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Messages({
    "MSG_MODIFIED=File {0} is modified. Save?"
})
final CloseOperationState canCloseElement(TopComponent tc) {
    // if this is not the last cloned java editor component, closing is OK
    if (!FormEditorSupport.isLastView(tc)) {
        return CloseOperationState.STATE_OK;
    }

    if (!isModified()) {
        return CloseOperationState.STATE_OK;
    }
    
    AbstractAction save = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                saveDocument();
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    };
    save.putValue(Action.LONG_DESCRIPTION, Bundle.MSG_MODIFIED(
        getDataObject().getPrimaryFile().getNameExt()
    ));

    // return a placeholder state - to be sure our CloseHandler is called
    return MultiViewFactory.createUnsafeCloseState(
            "ID_FORM_CLOSING", // NOI18N
            save,
            MultiViewFactory.NOOP_CLOSE_ACTION);
}
 
Example 17
Source File: BIEditorSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
final CloseOperationState canCloseElement(TopComponent tc) {
    // if this is not the last cloned java editor component, closing is OK
    if (!isLastView(tc)) {
        return CloseOperationState.STATE_OK;
    }

    if (!isModified()) {
        return CloseOperationState.STATE_OK;
    }

    AbstractAction save = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                saveDocument();
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    };
    save.putValue(Action.LONG_DESCRIPTION, NbBundle.getMessage(BIEditorSupport.class, "MSG_MODIFIED", getDataObject().getPrimaryFile().getNameExt()));

    // return a placeholder state - to be sure our CloseHandler is called
    return MultiViewFactory.createUnsafeCloseState(
            "ID_BEANINFO_CLOSING", // NOI18N
            save,
            MultiViewFactory.NOOP_CLOSE_ACTION);
}
 
Example 18
Source File: LookAndFeelPlugin.java    From ramus with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ActionDescriptor[] getActionDescriptors() {
    LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
    ActionDescriptor[] res = new ActionDescriptor[infos.length];
    final LookAndFeel laf = UIManager.getLookAndFeel();
    for (int i = 0; i < infos.length; i++) {
        final LookAndFeelInfo info = infos[i];
        ActionDescriptor ad = new ActionDescriptor();

        ad.setActionLevel(ActionLevel.GLOBAL);
        ad.setButtonGroup("LookAndFeel");
        ad.setMenu("Windows/LookAndFeel");
        ad.setSelective(true);

        AbstractAction action = new AbstractAction() {
            /**
             *
             */
            private static final long serialVersionUID = 1L;

            @Override
            public void actionPerformed(ActionEvent e) {
                Options.setString("LookAndFeel", info.getClassName());
                System.setProperty("AnywayExit", Boolean.TRUE.toString());
                JOptionPane
                        .showMessageDialog(
                                framework.getMainFrame(),
                                GlobalResourcesManager
                                        .getString("LookAndFeelWillApplyAfterProgramReboot"));
            }
        };

        action.putValue(Action.SELECTED_KEY, (info.getClassName()
                .equals(laf.getClass().getName())));
        action.putValue(Action.ACTION_COMMAND_KEY, info.getName());
        ad.setAction(action);

        res[i] = ad;
    }
    return res;
}
 
Example 19
Source File: CodeEvaluatorUI.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private JButton createDropDownButton() {
    Icon icon = ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/evaluator/drop_down_arrow.png", false);
    final JButton button = new DropDownButton();
    button.setIcon(icon);
    String tooltipText = NbBundle.getMessage(CodeEvaluatorUI.class, "CTL_Expressions_Dropdown_tooltip");
    button.setToolTipText(tooltipText);
    button.setEnabled(false);
    Dimension size = new Dimension(icon.getIconWidth() + 3, icon.getIconHeight() + 2);
    button.setPreferredSize(size);
    button.setMargin(new Insets(0, 0, 0, 0));
    button.setFocusable(false);
    AbstractAction action = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if ("pressed".equals(e.getActionCommand())) {
                JComponent jc = (JComponent) e.getSource();
                Point p = new Point(0, 0);
                SwingUtilities.convertPointToScreen(p, jc);
                if (!ButtonPopupSwitcher.isShown()) {
                    SwitcherTableItem[] items = createSwitcherItems();
                    ButtonPopupSwitcher.selectItem(jc, items, p.x, p.y);
                }
                //Other portion of issue 37487, looks funny if the
                //button becomes pressed
                if (jc instanceof AbstractButton) {
                    AbstractButton jb = (AbstractButton) jc;
                    jb.getModel().setPressed(false);
                    jb.getModel().setRollover(false);
                    jb.getModel().setArmed(false);
                    jb.repaint();
                }
            }
        } // actionPerformed

        @Override
        public boolean isEnabled() {
            return !getEditItemsList().isEmpty();
        }

    };
    action.putValue(Action.SMALL_ICON, icon);
    action.putValue(Action.SHORT_DESCRIPTION, tooltipText);
    button.setAction(action);
    return button;
}
 
Example 20
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]);
}