Java Code Examples for javax.swing.Action#removePropertyChangeListener()
The following examples show how to use
javax.swing.Action#removePropertyChangeListener() .
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: CallbackSystemAction.java From netbeans with Apache License 2.0 | 6 votes |
public void attach(Action action) { Reference<Action> d = delegate; if ((d == null) || (d.get() == action)) { return; } Action prev = d.get(); // reattaches to different action if (prev != null) { prev.removePropertyChangeListener(this); } this.delegate = new WeakReference<Action>(action); action.addPropertyChangeListener(this); }
Example 2
Source File: CallbackSystemAction.java From netbeans with Apache License 2.0 | 6 votes |
public boolean isEnabled() { Action a = findAction(); if (a == null) { a = delegate; } // 40915 - hold last action weakly Action last = lastRef == null ? null : lastRef.get(); if (a != last) { if (last != null) { last.removePropertyChangeListener(weakL); } lastRef = new WeakReference<Action>(a); a.addPropertyChangeListener(weakL); } return a.isEnabled(); }
Example 3
Source File: NbEditorUI.java From netbeans with Apache License 2.0 | 6 votes |
public void editorDeactivated() { Action ea = getEditorAction(); Action sa = getSystemAction(); if (ea != null && sa != null) { /* if (sa instanceof CallbackSystemAction) { CallbackSystemAction csa = (CallbackSystemAction)sa; if (csa.getActionPerformer() == this) { csa.setActionPerformer(null); } } */ if (syncEnabling && enabledPropertySyncL != null) { ea.removePropertyChangeListener(enabledPropertySyncL); } } }
Example 4
Source File: CallbackSystemAction.java From netbeans with Apache License 2.0 | 5 votes |
public void clear() { Action a; Reference<Action> d = delegate; a = d == null ? null : d.get(); if (a == null) { return; } delegate = null; a.removePropertyChangeListener(this); }
Example 5
Source File: CallbackSystemAction.java From netbeans with Apache License 2.0 | 5 votes |
protected void finalize() { Action last = lastRef == null ? null : lastRef.get(); if (last != null) { last.removePropertyChangeListener(weakL); } }
Example 6
Source File: GeneralAction.java From netbeans with Apache License 2.0 | 5 votes |
void updateState(ActionMap prev, ActionMap now, boolean fire) { if (key == null) { return; } boolean prevEnabled = false; if (prev != null) { Action prevAction = prev.get(key); if (prevAction != null) { prevEnabled = fire && prevAction.isEnabled(); prevAction.removePropertyChangeListener(weakL); } } if (now != null) { Action nowAction = now.get(key); boolean nowEnabled; if (nowAction != null) { nowAction.addPropertyChangeListener(weakL); nowEnabled = nowAction.isEnabled(); } else { nowEnabled = fallback != null && fallback.isEnabled(); } PropertyChangeSupport sup = fire ? support : null; if (sup != null && nowEnabled != prevEnabled) { sup.firePropertyChange("enabled", prevEnabled, !prevEnabled); // NOI18N } } }
Example 7
Source File: MergeAction.java From netbeans with Apache License 2.0 | 5 votes |
@Override protected synchronized void removeNotify() { for (Action a : actions) { a.removePropertyChangeListener(this); } setDelegateAction(null); }
Example 8
Source File: DynamicJMenuItemPropertyChangeListener.java From gcs with Mozilla Public License 2.0 | 5 votes |
DynamicJMenuItemPropertyChangeListener(JMenuItem menuItem, Action action, PropertyChangeListener chainedListener) { OwnedWeakReference ref; while ((ref = (OwnedWeakReference) QUEUE.poll()) != null) { DynamicJMenuItemPropertyChangeListener old = (DynamicJMenuItemPropertyChangeListener) ref.getOwner(); Action oldAction = old.mAction; if (oldAction != null) { oldAction.removePropertyChangeListener(old); } } mTarget = new OwnedWeakReference(menuItem, QUEUE, this); mAction = action; mChainedListener = chainedListener; }
Example 9
Source File: DynamicJMenuItemPropertyChangeListener.java From gcs with Mozilla Public License 2.0 | 5 votes |
@Override public void propertyChange(PropertyChangeEvent event) { JMenuItem mi = mTarget.get(); if (mi == null) { Action action = (Action) event.getSource(); action.removePropertyChangeListener(this); } else { if (event.getPropertyName().equals(Action.ACCELERATOR_KEY)) { mi.setAccelerator((KeyStroke) event.getNewValue()); mi.invalidate(); mi.repaint(); } } mChainedListener.propertyChange(event); }
Example 10
Source File: LookupSensitiveActionBase.java From netbeans with Apache License 2.0 | 4 votes |
public void testStackOverFlow() throws IOException { InstanceContent ic = new InstanceContent(); Lookup context = new AbstractLookup(ic); boolean clone = false; Action instance; if (clone) { Action a = create(Lookup.EMPTY); instance = ((ContextAwareAction)a).createContextAwareInstance(context); } else { instance = create(context); } FileObject pfo = TestSupport.createTestProject(FileUtil.createMemoryFileSystem().getRoot(), "yaya"); FileObject pf2 = TestSupport.createTestProject(FileUtil.createMemoryFileSystem().getRoot(), "blabla"); MockServices.setServices(TestSupport.TestProjectFactory.class); Project p = ProjectManager.getDefault().findProject(pfo); Project p2 = ProjectManager.getDefault().findProject(pf2); if (p instanceof TestSupport.TestProject) { enhanceProject((TestSupport.TestProject)p); } if (p2 instanceof TestSupport.TestProject) { enhanceProject((TestSupport.TestProject)p2); } assertNotNull("Project found", p); assertNotNull("Project2 found", p2); OpenProjects.getDefault().open(new Project[] { p }, false); assertFalse("Disabled1", instance.isEnabled()); instance.addPropertyChangeListener(this); ic.add(p); assertTrue("Enabled", instance.isEnabled()); assertEquals("One change", 1, change); class Q implements PropertyChangeListener { Action i; int cnt; @Override public void propertyChange(PropertyChangeEvent evt) { if ("enabled".equals(evt.getPropertyName())) { cnt++; /* What is this for? Often fails during unit tests (but tests pass). assertTrue("enabled in listener", i.isEnabled()); */ } } } Q q = new Q(); q.i = instance; ic.remove(p); instance.removePropertyChangeListener(this); ic.add(p); instance.addPropertyChangeListener(q); assertTrue("Enabled", instance.isEnabled()); assertEquals("One call", 1, q.cnt); }