public Action createContextAwareInstance(Lookup actionContext) { return new AlwaysEnabledAction(map, this, actionContext, equals); }
static Action alwaysEnabled(Map map) { return AlwaysEnabledAction.create(map); }
static final Object extractCommonAttribute(Map fo, Action action, String name) { return AlwaysEnabledAction.extractCommonAttribute(fo, name); }
public void actionPerformed(final ActionEvent e) { assert EventQueue.isDispatchThread(); if (getDelegate() instanceof Action) { if (!((Action)getDelegate()).isEnabled()) { Toolkit.getDefaultToolkit().beep(); // Do not fire newValue == null (see #165838) firePropertyChange("enabled", null, isEnabled()); // NOI18N return; } } boolean async = Boolean.TRUE.equals(map.get("asynchronous")); // NOI18N Runnable ar = new Runnable() { public void run() { getDelegate().actionPerformed(e); } }; ActionInvoker.invokeAction(this, e, async, ar); }
protected ActionListener getDelegate() { if (delegate == null) { ActionListener al; if (parent == null) { Object listener = map.get("delegate"); // NOI18N if (!(listener instanceof ActionListener)) { throw new NullPointerException("No 'delegate' in " + map); } al = (ActionListener) listener; } else { al = parent.getDelegate(); } delegate = bindToContext(al, context); if (delegate instanceof Action) { Action actionDelegate = (Action) delegate; if (weakL == null) { weakL = WeakListeners.propertyChange(this, actionDelegate); } actionDelegate.addPropertyChangeListener(weakL); // Ensure display names and other properties are in sync or propagate them syncActionDelegateProperty(Action.NAME, actionDelegate); } } return delegate; }
@Override public String toString() { return "AlwaysEnabledAction[" + getValue(Action.NAME) + "]"; // NOI18N }
public void run() { getDelegate().actionPerformed(e); } };
public void propertyChange(PropertyChangeEvent evt) { if (evt.getSource() == delegate) { firePropertyChange(evt.getPropertyName(), evt.getOldValue(), evt.getNewValue()); } }
@Override public void actionPerformed(ActionEvent e) { // Toggle state in preferences togglePreferencesSelected(); super.actionPerformed(e); }
public static Action alwaysEnabled(Map map) { return new AlwaysEnabledAction(map); }
private void syncActionDelegateProperty(String propertyName, Action actionDelegate) { Object value = extractCommonAttribute(map, propertyName); Object delegateValue = actionDelegate.getValue(propertyName); if (value != null) { if (delegateValue == null) { actionDelegate.putValue(propertyName, value); } else { if (!delegateValue.equals(value)) { // Values differ LOG.log(Level.FINE, "Value of property \"{0}\" of AlwaysEnabledAction " + "is \"{1}\" but delegate {2} has \"{3}\"", new Object[] {propertyName, value, delegate, delegateValue}); } } } // else either both values are null or // this has null and delegate has non-null which is probably fine (declarer does not care) }
static Action checkbox(Map map) { return AlwaysEnabledAction.create(map); }
static AlwaysEnabledAction create(Map m) { return (m.containsKey(PREFERENCES_KEY)) ? new CheckBox(m) : new AlwaysEnabledAction(m); }
@Override public Object getValue(String name) { if (delegate instanceof Action) { Object ret = ((Action)delegate).getValue(name); if (ret != null) { return ret; } if ( "iconBase".equals(name) && // NOI18N ((Action)delegate).getValue(Action.SMALL_ICON) != null ) { return null; } } Object o = extractCommonAttribute(map, name); // cf. #137709 JG18: return o != null ? o : super.getValue(name); }