Java 8 Action - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Action class.

This code example shows how to use the following methods:addPropertyChangeListener, isEnabled, removePropertyChangeListener
        support.removePropertyChangeListener(listener);
    } 
     
    private void changeDelegate(JComponent comp, Action action){
        if(delegate!=null)
            delegate.removePropertyChangeListener(delegateListener);
        source = comp;
        delegate = action;
        delegate.addPropertyChangeListener(delegateListener);
        boolean enabled = delegate.isEnabled();
        support.firePropertyChange("enabled", !enabled, enabled);
    } 
     
    public boolean isEnabled(){ 
        return delegate!=null && delegate.isEnabled();
    } 
     
    public void setEnabled(boolean enabled){
        if(delegate!=null)
            delegate.setEnabled(enabled);
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addPropertyChangeListener, getValue, isEnabled
   * 
   * The button is enabled and visible. 
   */ 
  public SmartIconJButton(Action action) {
    this.action = action;
    defaultIcon = (Icon) action.getValue(AbstractAction.SMALL_ICON);
    tooltipText = (String) action.getValue(AbstractAction.SHORT_DESCRIPTION);
    isVisible = true;
    isEnabled = action.isEnabled();
    action.addPropertyChangeListener(this);    
  } 
 
  /** Update the default icon property */ 
  public void setIcon(Icon icon){
    this.defaultIcon = icon;
  } 
   
  /** Returns the default icon */ 
  public Icon getIcon(){
    return defaultIcon;
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getValue, putValue
     * action's name, concatenated with a description of a keyboard 
     * accelerator, if one has been set previously on the action.   
     * The item will be enabled by default. 
     */ 
    public static JMenuItem addMenuItem (JMenu menu, Action action) {
	String label = (String)action.getValue(action.NAME);
	int mnemonic = 0;
	Integer i = (Integer)action.getValue(MNEMONIC_KEY);
	if (i != null)
	    mnemonic = i.intValue();
   	return addMenuItem(menu, label, action, mnemonic, null, true);
    } 
	 
 
    /** Add an action to a menu and return the menu item created.  If 
     * the tool tip is null, use the "tooltip" property already in the 
     * action, otherwise add the property to the action. (The mnemonic 
     * isn't added.)  The new menu item is added to the action as the 
     * "menuItem" property.  The menu item's text is set using the 
     * action's name, concatenated with a description of a keyboard 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getValue
        super(action);
    } 
     
    @Override 
    protected void actionPropertyChanged(Action action, String propertyName) {
        super.actionPropertyChanged(action, propertyName);
         
        if (propertyName == Action.SELECTED_KEY && hasSelectedKey(action)) {
            setSelectedFromAction(action);
        } 
    } 
     
    /** Sets the selected state of the button from the action. */ 
    private void setSelectedFromAction(Action a) {
        boolean selected = false;
        if (a != null) {
            selected =  Boolean.TRUE.equals(a.getValue(Action.SELECTED_KEY));
        } 
         
        if (selected != isSelected()) {

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:putValue
        button.setMnemonic(-1);
        button.setDisplayedMnemonicIndex(-1);
 
        Mnemonics.setLocalizedText(button, text);
 
        action.putValue(Action.NAME, button.getText());
        action.putValue(Action.MNEMONIC_KEY, button.getMnemonic());
        action.putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY, button.getDisplayedMnemonicIndex());
    } 
     
    /** Set a name and mnemonics to a pane in JTabbedPane. 
     *  
     * @param tabbedPane tabbed pane containing the pane 
     * @param tabIndex index of the pane tab 
     * @param text localized string containg & before character  
     *             which should be used as a mnemonics 
     * @see org.openide.awt.Mnemonics#setLocalizedText(javax.swing.AbstractButton, java.lang.String)  
     */ 
    public static void setLocalizedText(JTabbedPane tabbedPane, int tabIndex, String text) {
        button.setText(null);
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getValue, putValue
    /** 
     * Adds an action to the view header. 
     * @param action The action to be added. 
     */ 
    public void addAction(Action action) {
        String name = (String) action.getValue(AbstractAction.NAME);
        action.putValue(AbstractAction.NAME, "");
        action.putValue(AbstractAction.SHORT_DESCRIPTION, name);
        JButton button = new JButton(action) {
            /** 
             *  
             */ 
            private static final long serialVersionUID = -5577350824168578334L;
 
            public void updateUI() { 
//                super.updateUI(); 
            } 
        }; 
        button.setFocusable(false);
        toolBar.add(button);

5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:putValue
	 * @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));
	} 
 
	private static int getMnemonic(String prop)
	{ 
		return LanguageBundle.getMnemonic(MNEMONIC_SUFFIX + prop);
	} 
 
	private static String getShortDesc(String prop, Object... substitutes)
	{ 
		return LanguageBundle.getFormattedString(LanguageBundle.KEY_PREFIX 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getValue, putValue
    /** Add an action to the table of actions. Every action known by 
     * the application should be added here so it can be retrieved and 
     * invoked later. 
     */ 
    public void addAction (Action action) {
        _actions.put(action.getValue(Action.NAME), action);
    } 
 
    /** Add an action to a menu and return the menu item created.  If 
     * the tool tip is null, use the "tooltip" property already in the 
     * action, otherwise add the property to the action. (The mnemonic 
     * isn't added.)  The new menu item is added to the action as the 
     * "menuItem" property.  The menu item's text is set using the 
     * action's name and is enabled by default. 
     * @deprecated Use method in GUIUtilities instead. 
     */ 
    public JMenuItem addMenuItem (JMenu menu, Action action,
            int mnemonic, String tooltip) {
	return GUIUtilities.addMenuItem(menu, action, mnemonic, tooltip);
    } 

5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:addPropertyChangeListener, getValue, isEnabled
 
   public static JButton createToolbarButton(JaWEAction ja, JaWEComponent comp) {
      Action a = ja.getAction(); 
      String aname = null; 
      if (a != null) { 
         aname = (String) a.getValue(Action.NAME); 
      } 
      String depName = ja.getLangDepName(); 
      String label = comp.getSettings().getLanguageDependentString(depName 
                                                                   + LABEL_POSTFIX); 
      if (aname == null) { 
         aname = depName; 
      } 
      if (label == null) { 
         label = aname; 
      } 
      JButton b = null; 
 
      ImageIcon ai = ja.getIcon(); 
      if (ai != null) { 

5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:actionPerformed, isEnabled
        maskTable.addMouseListener(new MouseAdapter() {
            @Override 
            public void mouseClicked(final MouseEvent e) {
                if (e.getClickCount() == 2) {
                    Action action = getDoubleClickAction();
                    if (action.isEnabled()) {
                        action.actionPerformed(new ActionEvent(e.getSource(), e.getID(), null));
                    } 
                } 
            } 
        }); 
 
    } 
 
    public JTable getMaskTable() {
        return maskTable;
    } 
 
    public Action getDoubleClickAction() {
        return null; 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Java 8 Action Methods: