當前位置: 首頁>>代碼示例>>Java>>正文


Java Action.addPropertyChangeListener方法代碼示例

本文整理匯總了Java中javax.swing.Action.addPropertyChangeListener方法的典型用法代碼示例。如果您正苦於以下問題:Java Action.addPropertyChangeListener方法的具體用法?Java Action.addPropertyChangeListener怎麽用?Java Action.addPropertyChangeListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.Action的用法示例。


在下文中一共展示了Action.addPropertyChangeListener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: PresenterUpdater

import javax.swing.Action; //導入方法依賴的package包/類
private PresenterUpdater(int type, Action action) {
    if (action == null) {
        throw new IllegalArgumentException("action must not be null"); // NOI18N
    }
    this.type = type;
    this.actionName = (String) action.getValue(Action.NAME);
    this.action = action;
    if (type == TOOLBAR) {
        presenter = new JButton();
        useActionSelectedProperty = false;
    } else { // MENU or POPUP
        useActionSelectedProperty = (action.getValue(AbstractEditorAction.PREFERENCES_KEY_KEY) != null);
        if (useActionSelectedProperty) {
            presenter = new LazyJCheckBoxMenuItem();
            presenter.setSelected(isActionSelected());
        } else {
            presenter = new LazyJMenuItem();
        }
    }

    action.addPropertyChangeListener(WeakListeners.propertyChange(this, action));
    if (type == MENU) {
        listenedContextActions = new WeakSet<Action>();
        EditorRegistryWatcher.get().registerPresenterUpdater(this); // Includes notification of active component
    } else {
        listenedContextActions = null;
    }

    presenter.addActionListener(this);
    updatePresenter(null); // Not active yet => mark updates pending
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:32,代碼來源:PresenterUpdater.java

示例2: setActiveAction

import javax.swing.Action; //導入方法依賴的package包/類
public void setActiveAction(Action a) {
    if (a == action) { // In this case there is in fact no extra context
        a = null;
    }
    synchronized (this) {
        if (a != contextAction) {
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine("setActiveAction(): from " + contextAction + " to " + a + "\n"); // NOI18N
            }
            contextAction = a;
            if (a != null && !listenedContextActions.contains(a)) {
                listenedContextActions.add(a);
                a.addPropertyChangeListener(WeakListeners.propertyChange(this, a));
                if (LOG.isLoggable(Level.FINE)) {
                    LOG.fine("setActiveAction(): started listening on " + a + "\n"); // NOI18N
                }
            }
            updatePresenter(null); // Update presenter completely
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:PresenterUpdater.java

示例3: testCopyLikeProblem

import javax.swing.Action; //導入方法依賴的package包/類
public void testCopyLikeProblem() throws Exception {
    FileObject fo = folder.getFileObject("testCopyLike.instance");

    Object obj = fo.getAttribute("instanceCreate");
    if (!(obj instanceof Action)) {
        fail("Shall create an action: " + obj);
    }

    InstanceContent ic = new InstanceContent();
    AbstractLookup l = new AbstractLookup(ic);
    ActionMap map = new ActionMap();
    map.put("copy-to-clipboard", new MyAction());
    ic.add(map);

    CntListener list = new CntListener();
    Action clone = ((ContextAwareAction)obj).createContextAwareInstance(l);
    clone.addPropertyChangeListener(list);
    assertTrue("Enabled", clone.isEnabled());

    ic.remove(map);
    assertFalse("Disabled", clone.isEnabled());
    list.assertCnt("one change", 1);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:CallbackActionTest.java

示例4: attach

import javax.swing.Action; //導入方法依賴的package包/類
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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:CallbackSystemAction.java

示例5: isEnabled

import javax.swing.Action; //導入方法依賴的package包/類
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();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:CallbackSystemAction.java

示例6: createDropdownItem

import javax.swing.Action; //導入方法依賴的package包/類
private static JMenuItem createDropdownItem(final Action action) {
    String name = (String)action.getValue("menuText"); // NOI18N
    if (name == null || name.trim().isEmpty()) name = (String)action.getValue(NAME);
    final JMenuItem item = new JMenuItem(Actions.cutAmpersand(name)) {
        public void fireActionPerformed(ActionEvent e) {
            action.actionPerformed(e);
        }
    };
    item.setEnabled(action.isEnabled());
    
    // #231371
    action.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            String propName = evt.getPropertyName();
            if ("enabled".equals(propName)) { // NOI18N
                item.setEnabled((Boolean)evt.getNewValue());
            } else if ("menuText".equals(propName)) { // NOI18N
                item.setText(Actions.cutAmpersand((String) evt.getNewValue()));
            }
        }
    });

    return item;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:ProfilerToolbarDropdownAction.java

示例7: testActionsUpdatedWhenActionMapChanges

import javax.swing.Action; //導入方法依賴的package包/類
public void testActionsUpdatedWhenActionMapChanges() throws Exception {
    ContextAwareAction a = Actions.callback("ahoj", null, true, "Ahoj!", "no/icon.png", true);
    final InstanceContent ic = new InstanceContent();
    Lookup lkp = new AbstractLookup(ic);

    ActionMap a1 = new ActionMap();
    ActionMap a2 = new ActionMap();
    a2.put("ahoj", new Enabled());

    ic.add(a1);
    Action clone = a.createContextAwareInstance(lkp);
    class L implements PropertyChangeListener {
        int cnt;
        public void propertyChange(PropertyChangeEvent evt) {
            cnt++;
        }
    }
    L listener = new L();
    clone.addPropertyChangeListener(listener);
    assertFalse("Not enabled", isEnabled(clone));

    ic.set(Collections.singleton(a2), null);

    assertTrue("Enabled now", isEnabled(clone));
    assertEquals("one change", 1, listener.cnt);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:GlobalManagerTest.java

示例8: editorActivated

import javax.swing.Action; //導入方法依賴的package包/類
public void editorActivated() {
    Action ea = getEditorAction();
    Action sa = getSystemAction();
    if (ea != null && sa != null) {
        if (updatePerformer) {
            if (ea.isEnabled() && sa instanceof CallbackSystemAction) {
                ((CallbackSystemAction)sa).setActionPerformer(this);
            }
        }

        if (syncEnabling) {
            if (enabledPropertySyncL == null) {
                enabledPropertySyncL = new EnabledPropertySyncListener(sa);
            }
            ea.addPropertyChangeListener(enabledPropertySyncL);
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:NbEditorUI.java

示例9: testContextInstancesAreIndependent

import javax.swing.Action; //導入方法依賴的package包/類
public void testContextInstancesAreIndependent() throws Exception {
    System.out.println("testContextInstancesAreIndependent");
    A a = new A();
    assertNull(Utilities.actionsGlobalContext().lookup(String.class)); //sanity check
    InstanceContent ic = new InstanceContent();
    Lookup l = new AbstractLookup(ic);
    Action a3 = a.createContextAwareInstance(l);
    assertFalse(a3.isEnabled());
    PCL pcl = new PCL();
    a3.addPropertyChangeListener(pcl);
    setContent("fuddle");
    a.assertNotPerformed();
    assertTrue(a.isEnabled());
    assertFalse(a3.isEnabled());
    synchronized (a3) {
        //should time out if test is going to pass
        a3.wait(TIMEOUT);
    }
    synchronized (pcl) {
        pcl.wait(TIMEOUT);
    }
    pcl.assertNotFired();
    ic.set(Collections.singleton("boo"), null);
    synchronized (a3) {
        a3.wait(TIMEOUT);
    }
    synchronized (pcl) {
        pcl.wait(TIMEOUT);
    }
    pcl.assertEnabledChangedTo(true);
    clearContent();
    assertTrue(a3.isEnabled());
    assertFalse(a.isEnabled());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:35,代碼來源:ContextActionTest.java

示例10: testIllegalStateException

import javax.swing.Action; //導入方法依賴的package包/類
public void testIllegalStateException() throws Exception {
    N root = new N();
    final N ch1 = new N();
    final N ch2 = new N();
    final N ch3 = new N();
    PT mockPaste = new PT();
    ch3.pasteTypes = Collections.<PasteType>singletonList(mockPaste);

    root.getChildren().add(new Node[] { ch1, ch2, ch3 });
    final ExplorerManager em = new ExplorerManager();
    em.setRootContext(root);
    em.setSelectedNodes(new Node[] { root });
    Action action = ExplorerUtils.actionPaste(em);
    Action cut = ExplorerUtils.actionCut(em);
    em.waitActionsFinished();
    assertFalse("Not enabled", action.isEnabled());
    
    action.addPropertyChangeListener(this);
    cut.addPropertyChangeListener(this);
    

    em.setSelectedNodes(new Node[] { ch3 });
    em.waitActionsFinished();
    assertFalse("Cut is not enabled", cut.isEnabled());
    assertTrue("Now enabled", action.isEnabled());
    action.actionPerformed(new ActionEvent(this, 0, ""));

    assertEquals("The paste type is going to be called", 1, mockPaste.cnt);
    
    if (err != null) {
        throw err;
    }
    if (cnt == 0) {
        fail("There should be some change in actions: " + cnt);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:37,代碼來源:ExplorerActionsImplTest.java

示例11: testPasteActionGetDelegatesBlocks

import javax.swing.Action; //導入方法依賴的package包/類
@RandomlyFails // NB-Core-Build #9619, #9847, #9998, #10014
public void testPasteActionGetDelegatesBlocks() throws Exception {
    N root = new N();
    final N ch1 = new N();
    final N ch2 = new N();
    final N ch3 = new N();
    PT mockPaste = new PT();
    ch3.pasteTypes = Collections.<PasteType>singletonList(mockPaste);

    root.getChildren().add(new Node[] { ch1, ch2, ch3 });
    final ExplorerManager em = new ExplorerManager();
    em.setRootContext(root);
    em.setSelectedNodes(new Node[] { root });
    Action action = ExplorerUtils.actionPaste(em);
    em.waitActionsFinished();
    assertFalse("Not enabled", action.isEnabled());
    
    action.addPropertyChangeListener(this);
    
    assertNull("No delegates yet", action.getValue("delegates"));

    em.setSelectedNodes(new Node[] { ch3 });
    Object ret = action.getValue("delegates");
    assertNotNull("Delegates are updated", ret);
    Object[] arr = (Object[])ret;
    assertEquals("One item in there", 1, arr.length);
    if (err != null) {
        throw err;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:31,代碼來源:ExplorerActionsImplTest.java

示例12: WrappedAWTMenuItem

import javax.swing.Action; //導入方法依賴的package包/類
public WrappedAWTMenuItem(Action a)
{
    super((String)a.getValue(Action.NAME));
    addActionListener(a);
    setEnabled(a.isEnabled());
    a.addPropertyChangeListener(this);
}
 
開發者ID:drytoastman,項目名稱:scorekeeperfrontend,代碼行數:8,代碼來源:WrappedAWTMenuItem.java

示例13: addNotify

import javax.swing.Action; //導入方法依賴的package包/類
@Override
protected synchronized void addNotify() {
    for (Action a : actions) {
        a.addPropertyChangeListener(this);
    }
    updateDelegateAction();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:8,代碼來源:MergeAction.java

示例14: BaseDelAction

import javax.swing.Action; //導入方法依賴的package包/類
/** Constructs new action that is bound to given context and
 * listens for changes of <code>ActionMap</code> in order to delegate
 * to right action.
 */
protected BaseDelAction(Map map, Object key, Lookup actionContext, Action fallback, boolean surviveFocusChange, boolean async) {
    this.map = map;
    this.key = key;
    this.fallback = fallback;
    this.global = GlobalManager.findManager(actionContext, surviveFocusChange);
    this.weakL = WeakListeners.propertyChange(this, fallback);
    this.async = async;
    if (fallback != null) {
        fallback.addPropertyChangeListener(weakL);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:GeneralAction.java

示例15: doBasicUsageWithEnabler

import javax.swing.Action; //導入方法依賴的package包/類
private ActionsInfraHid.WaitPCL doBasicUsageWithEnabler(Action operateOn) throws Exception {
    // Check enablement logic.
    ActionsInfraHid.WaitPCL l = new ActionsInfraHid.WaitPCL("enabled");
    operateOn.addPropertyChangeListener(l);
    assertFalse(getIsEnabled(operateOn));
    activate(new Lookup[] {n1});
    assertFalse("We need two nodes to become enabled", l.changed());
    l.gotit = 0;
    assertFalse("and there is just one", getIsEnabled(operateOn));
    activate(new Lookup[] {n1, n2});
    assertTrue("Ok, now we are enabled", l.changed());
    l.gotit = 0;
    assertTrue("Yes", getIsEnabled(operateOn));
    activate(new Lookup[] {n2});
    assertTrue("Disabled again", l.changed());
    l.gotit = 0;
    assertFalse("Disabled", getIsEnabled(operateOn));
    activate(new Lookup[] {n3});
    assertFalse(l.changed());
    l.gotit = 0;
    assertFalse(getIsEnabled(operateOn));
    activate(new Lookup[] {n3});
    assertFalse("Again not changed", l.changed());
    l.gotit = 0;
    assertFalse(getIsEnabled(operateOn));
    activate(new Lookup[] {n1});
    assertFalse(l.changed());
    l.gotit = 0;
    assertFalse(getIsEnabled(operateOn));
    activate(new Lookup[] {n1});
    assertFalse("No change", l.changed());
    l.gotit = 0;
    assertFalse(getIsEnabled(operateOn));
    activate(new Lookup[] {n1, n2});
    assertTrue("now there is enabledment", l.changed());
    l.gotit = 0;
    assertTrue(getIsEnabled(operateOn));
    
    return l;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:41,代碼來源:ContextActionTest.java


注:本文中的javax.swing.Action.addPropertyChangeListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。