Esempio n. 1
0
  /**
   * Registers a listener which will be notified when the
   * logging properties are re-read.
   */
  public synchronized void addPropertyChangeListener(PropertyChangeListener listener)
  {
    /* do not register null. */
    listener.getClass();

    pcs.addPropertyChangeListener(listener);
  }
Esempio n. 2
0
 /**
  * Add a {@code PropertyChangeListener}, which will be invoked when the properties are reread.
  *
  * @param l the {@code PropertyChangeListener} to be added.
  */
 public void addPropertyChangeListener(PropertyChangeListener l) {
   if (l == null) {
     throw new NullPointerException();
   }
   checkAccess();
   listeners.addPropertyChangeListener(l);
 }
 /**
  * Adds an event listener to be invoked when the logging properties are re-read. Adding multiple
  * instances of the same event Listener results in multiple entries in the property event listener
  * table.
  *
  * @param l event listener
  * @exception SecurityException if a security manager exists and if the caller does not have
  *     LoggingPermission("control").
  * @exception NullPointerException if the PropertyChangeListener is null.
  */
 public void addPropertyChangeListener(PropertyChangeListener l) throws SecurityException {
   if (l == null) {
     throw new NullPointerException();
   }
   checkPermission();
   changes.addPropertyChangeListener(l);
 }
  /**
   * Add a property change listener to this application. Changes to certain elements of the state
   * will cause all registered property listeners to be notified.
   */
  public void addPropertyChangeListener(PropertyChangeListener listener) {
    if (_propertyChangeSupport == null) {
      _propertyChangeSupport = new PropertyChangeSupport(this);
    }

    _propertyChangeSupport.addPropertyChangeListener(listener);
  }
 /**
  * Adds a property change listener.
  *
  * @param p The class which will listen for property changes.
  */
 public final void addListener(PropertyChangeListener p) {
   if (pcl == null) {
     pcl = new PropertyChangeSupport(this);
   }
   LOG.debug("addPropertyChangeListener(" + p + ")");
   pcl.addPropertyChangeListener(p);
 }
  public NbListenerRef addModelUpdateListener(final ProjectModelUpdatedListener listener) {
    ExceptionHelper.checkNotNullArgument(listener, "listener");

    final PropertyChangeListener forwarder =
        new PropertyChangeListener() {
          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            listener.onUpdateProject((NbGradleModel) evt.getNewValue());
          }
        };

    updateListeners.addPropertyChangeListener(forwarder);
    return new NbListenerRef() {
      private volatile boolean registered = true;

      @Override
      public boolean isRegistered() {
        return registered;
      }

      @Override
      public void unregister() {
        updateListeners.removePropertyChangeListener(forwarder);
        registered = true;
      }
    };
  }
Esempio n. 7
0
 public void addPropertyChangeListener(PropertyChangeListener listener) {
   listeners.addPropertyChangeListener(listener);
   Property[] subProperties = getSubProperties();
   if (subProperties != null)
     for (int i = 0; i < subProperties.length; ++i)
       subProperties[i].addPropertyChangeListener(listener);
 }
Esempio n. 8
0
 public void addPropertyChangeListener(PropertyChangeListener listener) {
   List<PropertyChangeListener> listeners =
       Arrays.asList(propertyChangeSupport.getPropertyChangeListeners());
   if (!listeners.contains(listener)) {
     propertyChangeSupport.addPropertyChangeListener(listener);
   }
 }
 /**
  * Adds a property change listener.Static for simplicity of use.
  *
  * @param key The specific key to listen for.
  * @param p The class which will listen for property changes.
  */
 public final void addListener(ConfigurationKey key, PropertyChangeListener p) {
   if (pcl == null) {
     pcl = new PropertyChangeSupport(this);
   }
   LOG.debug("addPropertyChangeListener(" + key.getKey() + ")");
   pcl.addPropertyChangeListener(key.getKey(), p);
 }
Esempio n. 10
0
 /**
  * Adds a bound property listener to the dialog
  *
  * @param listener a listener for dialog events
  */
 @Override
 public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
   if (listeners == null) {
     listeners = new PropertyChangeSupport(this);
   }
   listeners.addPropertyChangeListener(listener);
 }
Esempio n. 11
0
  OpFooter(OpControl control, List<LayerMode> layerModes) {
    super(BoxLayout.X_AXIS);

    layerControls = new LayerControls(control, layerModes, pcs);
    invertRegionSwitch = new InvertRegionCheckBox(control, pcs);
    colorControls = new ColorSelectionControls(control, pcs);

    Box blendBox = Box.createVerticalBox();
    blendBox.add(Box.createVerticalStrut(5));
    blendBox.add(layerControls);
    blendBox.add(invertRegionSwitch);
    blendBox.setBackground(LightZoneSkin.Colors.ToolPanesBackground);
    layerControls.setAlignmentX(Component.LEFT_ALIGNMENT);
    invertRegionSwitch.setAlignmentX(Component.LEFT_ALIGNMENT);

    tabPane = new JTabbedPane();
    tabPane.setFont(LightZoneSkin.fontSet.getSmallFont());
    tabPane.add(LOCALE.get("ToolSettingsTabName"), blendBox);
    tabPane.add(LOCALE.get("ColorSelectionTabName"), colorControls);

    tabPane.setIconAt(0, getThemeIcon(orangeScheme, true));
    tabPane.setIconAt(1, getThemeIcon(orangeScheme, false));

    add(tabPane, BorderLayout.NORTH);

    setBackground(LightZoneSkin.Colors.ToolPanesBackground);

    pcs.addPropertyChangeListener(this);
  }
Esempio n. 12
0
 /**
  * Adds the given <CODE>PropertyChangeListener</CODE> to the module.
  *
  * @param l The <CODE>PropertyChangeListener</CODE> to add to the module.
  */
 public synchronized void addPropertyChangeListener(PropertyChangeListener l) {
   createPropertyChangeSupport();
   propertyChangeSupport.addPropertyChangeListener(l);
   //    if (!propertyChangeListeners.contains(l))
   //    {
   //      propertyChangeListeners.add(l);
   //    }
 }
  private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
    s.defaultReadObject();

    Object listenerOrNull;
    while (null != (listenerOrNull = s.readObject())) {
      addPropertyChangeListener((PropertyChangeListener) listenerOrNull);
    }
  }
 @Override
 public void addPropertyChangeListener(PropertyChangeListener listener) {
   // Ignore duplicate method calls.
   for (PropertyChangeListener l : pcs.getPropertyChangeListeners()) {
     if (l == listener) return;
   }
   pcs.addPropertyChangeListener(listener);
 }
  public void testAddingOneListenerTwice() {
    Object bean = new Object();
    PropertyChangeSupport support = new PropertyChangeSupport(bean);
    EventLog log = new EventLog();
    support.addPropertyChangeListener("a", log);
    support.addPropertyChangeListener(log);
    support.addPropertyChangeListener(log);
    support.addPropertyChangeListener("a", log);

    PropertyChangeEvent eventA = new PropertyChangeEvent(bean, "a", false, true);
    PropertyChangeEvent eventB = new PropertyChangeEvent(bean, "b", false, true);

    support.firePropertyChange(eventA);
    support.firePropertyChange(eventB);

    assertEquals(Arrays.asList(eventA, eventA, eventA, eventA, eventB, eventB), log.log);
  }
Esempio n. 16
0
  /**
   * Adds a PropertyChangeListener. The specified PropertyChangeListener's <b>propertyChange</b>
   * method is called each time the value of any bound property is changed.
   *
   * @see #removePropertyChangeListener
   * @param listener The PropertyChangeListener.
   */
  public void addPropertyChangeListener(PropertyChangeListener listener) {
    if (listener == null) throw new NullPointerException("listener");
    if (changes_ == null) changes_ = new PropertyChangeSupport(this); // @CRS
    changes_.addPropertyChangeListener(listener);

    // must call the parents change listener since it is
    // in a different package.
    super.addPropertyChangeListener(listener);
  }
Esempio n. 17
0
  /**
   * Add a property change listener.
   *
   * @param l the listener to add
   */
  public synchronized void addPropertyChangeListener(PropertyChangeListener l) {
    if (support == null)
      synchronized (this) {
        // new test under synchronized block
        if (support == null) support = new PropertyChangeSupport(element);
      }

    support.addPropertyChangeListener(l);
  }
  public void testSerialize() {
    String s =
        "aced0005737200206a6176612e6265616e732e50726f70657274794368616e67"
            + "65537570706f727458d5d264574860bb03000349002a70726f706572747943686"
            + "16e6765537570706f727453657269616c697a65644461746156657273696f6e4c"
            + "00086368696c6472656e7400154c6a6176612f7574696c2f486173687461626c6"
            + "53b4c0006736f757263657400124c6a6176612f6c616e672f4f626a6563743b78"
            + "7000000002737200136a6176612e7574696c2e486173687461626c6513bb0f252"
            + "14ae4b803000246000a6c6f6164466163746f724900097468726573686f6c6478"
            + "703f4000000000000877080000000b00000001740001617371007e00000000000"
            + "2707400046265616e7372003a6c6962636f72652e6a6176612e7574696c2e6265"
            + "616e732e50726f70657274794368616e6765537570706f7274546573742445766"
            + "56e744c6f67b92667637d0b6f450200024c00036c6f677400104c6a6176612f75"
            + "74696c2f4c6973743b4c00046e616d657400124c6a6176612f6c616e672f53747"
            + "2696e673b7870737200136a6176612e7574696c2e41727261794c6973747881d2"
            + "1d99c7619d03000149000473697a6578700000000077040000000a7874000b6c6"
            + "97374656e6572546f4171007e000c70787871007e00087371007e00097371007e"
            + "000d0000000077040000000a7874000d6c697374656e6572546f416c6c7078";

    Object bean = "bean";
    PropertyChangeSupport support = new PropertyChangeSupport(bean);
    EventLog listenerToAll = new EventLog();
    listenerToAll.name = "listenerToAll";
    EventLog listenerToA = new EventLog();
    listenerToA.name = "listenerToA";
    support.addPropertyChangeListener(listenerToAll);
    support.addPropertyChangeListener("a", listenerToA);
    support.addPropertyChangeListener("a", listenerToA);

    new SerializationTester<PropertyChangeSupport>(support, s) {
      @Override
      protected boolean equals(PropertyChangeSupport a, PropertyChangeSupport b) {
        return describe(a.getPropertyChangeListeners())
            .equals(describe(b.getPropertyChangeListeners()));
      }

      @Override
      protected void verify(PropertyChangeSupport deserialized) {
        assertEquals(
            "[a to listenerToA, a to listenerToA, listenerToAll]",
            describe(deserialized.getPropertyChangeListeners()));
      }
    }.test();
  }
 /**
  * Adds a PropertyChangeListener to the listener list for a specific property. The specified
  * property may be one of the following:
  *
  * <ul>
  *   <li>if this AppContext is disposed ("disposed")
  * </ul>
  *
  * <ul>
  *   <li>if this AppContext's unowned Windows have been disposed ("guidisposed"). Code to cleanup
  *       after the GUI is disposed (such as LookAndFeel.uninitialize()) should execute in response
  *       to this property being fired. Notifications for the "guidisposed" property are sent on
  *       the event dispatch thread.
  * </ul>
  *
  * <p>If listener is null, no exception is thrown and no action is performed.
  *
  * @param propertyName one of the property names listed above
  * @param listener the PropertyChangeListener to be added
  * @see #removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
  * @see #getPropertyChangeListeners(java.lang.String)
  * @see #addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
  */
 public synchronized void addPropertyChangeListener(
     String propertyName, PropertyChangeListener listener) {
   if (listener == null) {
     return;
   }
   if (changeSupport == null) {
     changeSupport = new PropertyChangeSupport(this);
   }
   changeSupport.addPropertyChangeListener(propertyName, listener);
 }
  public void testOldAndNewAreBothNull() {
    Object bean = new Object();
    PropertyChangeSupport support = new PropertyChangeSupport(bean);
    EventLog listener = new EventLog();
    support.addPropertyChangeListener(listener);

    PropertyChangeEvent nullToNull = new PropertyChangeEvent(bean, "a", null, null);
    support.firePropertyChange(nullToNull);
    assertEquals(Arrays.<PropertyChangeEvent>asList(nullToNull), listener.log);
  }
  public void testOldAndNewAreTheSame() {
    Object bean = new Object();
    PropertyChangeSupport support = new PropertyChangeSupport(bean);
    EventLog listener = new EventLog();
    support.addPropertyChangeListener(listener);

    PropertyChangeEvent xToX = new PropertyChangeEvent(bean, "a", "x", new String("x"));
    support.firePropertyChange(xToX);
    assertEquals(Arrays.<PropertyChangeEvent>asList(), listener.log);
  }
 public VertexCreationFormLayout(
     final Set metaInstance,
     final Set containerInstance,
     final MultitabPanel parent,
     final Action action) {
   this.metaInstance = metaInstance;
   this.containerInstance = containerInstance;
   this.parent = parent;
   this.action = action;
   createInputForm();
   changeSupport = new PropertyChangeSupport(this);
   changeSupport.addPropertyChangeListener(EditorController.getInstance());
 }
  /**
   * Test that we need to do our own equals() work to manually unwrap an arbitrary number of
   * proxies.
   */
  public void testRemoveWithProxies() {
    Object bean = new Object();
    PropertyChangeSupport support = new PropertyChangeSupport(bean);

    EventLog all = new EventLog();
    support.addPropertyChangeListener(all);
    assertEquals(1, support.getPropertyChangeListeners().length);

    EventLog proxiedA = new EventLog();
    support.addPropertyChangeListener(new PropertyChangeListenerProxy("a", proxiedA));
    assertEquals(2, support.getPropertyChangeListeners().length);

    EventLog addA = new EventLog();
    support.addPropertyChangeListener("a", addA);
    assertEquals(3, support.getPropertyChangeListeners().length);

    EventLog addAProxiedB = new EventLog();
    support.addPropertyChangeListener("a", new PropertyChangeListenerProxy("b", addAProxiedB));
    assertEquals(4, support.getPropertyChangeListeners().length);

    EventLog proxiedAB = new EventLog();
    PropertyChangeListenerProxy proxyAB =
        new PropertyChangeListenerProxy("a", new PropertyChangeListenerProxy("b", proxiedAB));
    support.addPropertyChangeListener(proxyAB);
    assertEquals(5, support.getPropertyChangeListeners().length);

    EventLog proxiedAAC = new EventLog();
    support.addPropertyChangeListener(
        new PropertyChangeListenerProxy(
            "a",
            new PropertyChangeListenerProxy(
                "a", new PropertyChangeListenerProxy("c", proxiedAAC))));
    assertEquals(6, support.getPropertyChangeListeners().length);

    support.removePropertyChangeListener(all);
    assertEquals(5, support.getPropertyChangeListeners().length);
    support.removePropertyChangeListener("a", proxiedA);
    assertEquals(4, support.getPropertyChangeListeners().length);
    support.removePropertyChangeListener(new PropertyChangeListenerProxy("a", addA));
    assertEquals(3, support.getPropertyChangeListeners().length);
    support.removePropertyChangeListener("a", new PropertyChangeListenerProxy("b", addAProxiedB));
    assertEquals(2, support.getPropertyChangeListeners().length);
    support.removePropertyChangeListener(proxyAB);
    assertEquals(1, support.getPropertyChangeListeners().length);

    support.removePropertyChangeListener(proxiedAAC);
    support.removePropertyChangeListener(new PropertyChangeListenerProxy("a", proxiedAAC));
    support.removePropertyChangeListener("a", new PropertyChangeListenerProxy("c", proxiedAAC));
    support.removePropertyChangeListener(
        "a",
        new PropertyChangeListenerProxy("c", new PropertyChangeListenerProxy("a", proxiedAAC)));
    assertEquals(1, support.getPropertyChangeListeners().length);

    support.removePropertyChangeListener(
        "a",
        new PropertyChangeListenerProxy("a", new PropertyChangeListenerProxy("c", proxiedAAC)));
    assertEquals(0, support.getPropertyChangeListeners().length);
  }
Esempio n. 24
0
  protected void init() {
    log.fine("No service implementation instance available, initializing...");
    try {
      // The actual instance we ware going to use and hold a reference to (1:1 instance for manager)
      serviceImpl = createServiceInstance();

      // How the implementation instance will tell us about property changes
      propertyChangeSupport = createPropertyChangeSupport(serviceImpl);
      propertyChangeSupport.addPropertyChangeListener(createPropertyChangeListener(serviceImpl));

    } catch (Exception ex) {
      throw new RuntimeException("Could not initialize implementation: " + ex, ex);
    }
  }
 /**
  * Add a PropertyChangeListener for a specific property. The listener will be invoked only when a
  * call on firePropertyChange names that specific property. The same listener object may be added
  * more than once. For each property, the listener will be invoked the number of times it was
  * added for that property. If <code>propertyName</code> or <code>listener</code> is null, no
  * exception is thrown and no action is taken.
  *
  * @param propertyName The name of the property to listen on.
  * @param listener The PropertyChangeListener to be added
  */
 public synchronized void addPropertyChangeListener(
     String propertyName, PropertyChangeListener listener) {
   if (listener == null || propertyName == null) {
     return;
   }
   if (children == null) {
     children = new java.util.Hashtable();
   }
   PropertyChangeSupport child = (PropertyChangeSupport) children.get(propertyName);
   if (child == null) {
     child = new PropertyChangeSupport(source);
     children.put(propertyName, child);
   }
   child.addPropertyChangeListener(listener);
 }
Esempio n. 26
0
  @Test
  public void setFireGet() throws Exception {

    LastChange lc = new LastChange(new RenderingControlLastChangeParser());

    lc.setEventedValue(0, new RenderingControlVariable.PresetNameList("foo"));
    lc.setEventedValue(0, new RenderingControlVariable.PresetNameList("foobar")); // Double set!

    lc.setEventedValue(
        0, new RenderingControlVariable.Volume(new ChannelVolume(Channel.Master, 123)));

    lc.setEventedValue(
        1, new RenderingControlVariable.Brightness(new UnsignedIntegerTwoBytes(456)));

    final String[] lcValue = new String[1];
    PropertyChangeSupport pcs = new PropertyChangeSupport(this);
    pcs.addPropertyChangeListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            if (ev.getPropertyName().equals("LastChange")) lcValue[0] = (String) ev.getNewValue();
          }
        });
    lc.fire(pcs);

    // Check it's clear
    assertEquals(lc.getEventedValue(0, RenderingControlVariable.PresetNameList.class), null);
    assertEquals(lc.toString(), "");

    // Set something again, it's not fired, so it has no consequence on further assertions
    lc.setEventedValue(0, new RenderingControlVariable.PresetNameList("foo"));

    // Read the XML string instead
    lc = new LastChange(new RenderingControlLastChangeParser(), lcValue[0]);

    assertEquals(
        lc.getEventedValue(0, RenderingControlVariable.PresetNameList.class).getValue(), "foobar");

    assertEquals(
        lc.getEventedValue(0, RenderingControlVariable.Volume.class).getValue().getChannel(),
        Channel.Master);
    assertEquals(
        lc.getEventedValue(0, RenderingControlVariable.Volume.class).getValue().getVolume(),
        new Integer(123));

    assertEquals(
        lc.getEventedValue(1, RenderingControlVariable.Brightness.class).getValue(),
        new UnsignedIntegerTwoBytes(456));
  }
  public void testAddingAListenerActuallyAddsAProxy() {
    Object bean = new Object();
    PropertyChangeSupport support = new PropertyChangeSupport(bean);
    PropertyChangeListener listener =
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent event) {}
        };
    support.addPropertyChangeListener("a", listener);

    PropertyChangeListenerProxy p1 =
        (PropertyChangeListenerProxy) support.getPropertyChangeListeners()[0];
    assertEquals(PropertyChangeListenerProxy.class, p1.getClass());
    assertTrue(p1 != listener); // weird but consistent with the RI
    assertEquals("a", p1.getPropertyName());
    assertEquals(listener, p1.getListener());
  }
  /**
   * Add a PropertyChangeListener to the listener list. The listener is registered for all
   * properties. The same listener object may be added more than once, and will be called as many
   * times as it is added. If <code>listener</code> is null, no exception is thrown and no action is
   * taken.
   *
   * @param listener The PropertyChangeListener to be added
   */
  public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
    if (listener == null) {
      return;
    }

    if (listener instanceof PropertyChangeListenerProxy) {
      PropertyChangeListenerProxy proxy = (PropertyChangeListenerProxy) listener;
      // Call two argument add method.
      addPropertyChangeListener(
          proxy.getPropertyName(), (PropertyChangeListener) proxy.getListener());
    } else {
      if (listeners == null) {
        listeners = new EventListenerAggregate(PropertyChangeListener.class);
      }
      listeners.add(listener);
    }
  }
  public void testEventsFilteredByProxies() {
    Object bean = new Object();
    PropertyChangeEvent eventA = new PropertyChangeEvent(bean, "a", false, true);
    PropertyChangeEvent eventB = new PropertyChangeEvent(bean, "b", false, true);
    PropertyChangeEvent eventC = new PropertyChangeEvent(bean, "c", false, true);

    PropertyChangeSupport support = new PropertyChangeSupport(bean);

    EventLog all = new EventLog();
    support.addPropertyChangeListener(all);

    EventLog proxiedA = new EventLog();
    support.addPropertyChangeListener(new PropertyChangeListenerProxy("a", proxiedA));

    EventLog addA = new EventLog();
    support.addPropertyChangeListener("a", addA);

    EventLog addAProxiedB = new EventLog();
    support.addPropertyChangeListener("a", new PropertyChangeListenerProxy("b", addAProxiedB));

    EventLog proxiedAB = new EventLog();
    support.addPropertyChangeListener(
        new PropertyChangeListenerProxy("a", new PropertyChangeListenerProxy("b", proxiedAB)));

    EventLog proxiedAA = new EventLog();
    support.addPropertyChangeListener(
        new PropertyChangeListenerProxy("a", new PropertyChangeListenerProxy("a", proxiedAA)));

    EventLog proxiedAAC = new EventLog();
    support.addPropertyChangeListener(
        new PropertyChangeListenerProxy(
            "a",
            new PropertyChangeListenerProxy(
                "a", new PropertyChangeListenerProxy("c", proxiedAAC))));

    support.firePropertyChange(eventA);
    support.firePropertyChange(eventB);
    support.firePropertyChange(eventC);

    assertEquals(Arrays.asList(eventA, eventB, eventC), all.log);
    assertEquals(Arrays.asList(eventA), proxiedA.log);
    assertEquals(Arrays.asList(eventA), addA.log);
    assertEquals(Arrays.<PropertyChangeEvent>asList(), addAProxiedB.log);
    assertEquals(Arrays.<PropertyChangeEvent>asList(), proxiedAB.log);
    assertEquals(Arrays.<PropertyChangeEvent>asList(eventA), proxiedAA.log);
    assertEquals(Arrays.<PropertyChangeEvent>asList(), proxiedAAC.log);
  }
  public void testAddingAProxy() {
    Object bean = new Object();
    PropertyChangeSupport support = new PropertyChangeSupport(bean);
    PropertyChangeListener listener =
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent event) {}
        };
    PropertyChangeListenerProxy proxy = new PropertyChangeListenerProxy("a", listener);
    support.addPropertyChangeListener("b", proxy);

    // this proxy sets us up to receive 'b' events
    PropertyChangeListenerProxy p1 =
        (PropertyChangeListenerProxy) support.getPropertyChangeListeners()[0];
    assertEquals(PropertyChangeListenerProxy.class, p1.getClass());
    assertEquals("b", p1.getPropertyName());

    // this proxy sets us up to receive 'a' events
    PropertyChangeListenerProxy p2 = (PropertyChangeListenerProxy) p1.getListener();
    assertEquals(PropertyChangeListenerProxy.class, p2.getClass());
    assertEquals("a", p2.getPropertyName());
    assertEquals(listener, p2.getListener());
  }