当前位置: 首页>>代码示例>>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;未经允许,请勿转载。