Search in sources :

Example 46 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project JMRI by JMRI.

the class VSDControl method configButtonPressed.

/**
     * Handle "Config" button presses
     */
protected void configButtonPressed(ActionEvent e) {
    log.debug("(" + address + ") Config Button Pressed");
    VSDConfigDialog d = new VSDConfigDialog(this, Bundle.getMessage("ConfigDialogTitlePrefix") + " " + this.address, config);
    d.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            log.debug("property change name " + event.getPropertyName() + " old " + event.getOldValue() + " new " + event.getNewValue());
            configDialogPropertyChange(event);
        }
    });
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener)

Example 47 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project JMRI by JMRI.

the class VSDControl method optionButtonPressed.

/**
     * Handle "Option" button presses
     */
protected void optionButtonPressed(ActionEvent e) {
    log.debug("(" + address + ") Option Button Pressed");
    VSDOptionsDialog d = new VSDOptionsDialog(this, Bundle.getMessage("OptionsDialogTitlePrefix") + " " + this.address);
    d.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            log.debug("property change name " + event.getPropertyName() + " old " + event.getOldValue() + " new " + event.getNewValue());
            optionsDialogPropertyChange(event);
        }
    });
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener)

Example 48 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project JMRI by JMRI.

the class AbstractThrottleManager method notifyThrottleKnown.

/**
     * Handle throttle information when it's finally available, e.g. when a new
     * Throttle object has been created.
     * <P>
     * This method creates a throttle for all ThrottleListeners of that address
     * and notifies them via the ThrottleListener.notifyThrottleFound method.
     */
public void notifyThrottleKnown(DccThrottle throttle, LocoAddress addr, boolean suppressUseIncrements) {
    log.debug("notifyThrottleKnown for " + addr);
    DccLocoAddress dla = (DccLocoAddress) addr;
    Addresses ads = null;
    if (!addressThrottles.containsKey(dla)) {
        log.debug("Address " + addr + "doesn't already exists so will add");
        ads = new Addresses(throttle);
        addressThrottles.put(dla, ads);
    } else {
        addressThrottles.get(dla).setThrottle(throttle);
    }
    ArrayList<WaitingThrottle> a = throttleListeners.get(dla);
    if (a == null) {
        log.debug("notifyThrottleKnown with zero-length listeners: " + addr);
    } else {
        for (int i = 0; i < a.size(); i++) {
            ThrottleListener l = a.get(i).getListener();
            log.debug("Notify listener " + (i + 1) + " of " + a.size());
            l.notifyThrottleFound(throttle);
            if (suppressUseIncrements == false) {
                // this is a new throttle
                addressThrottles.get(dla).incrementUse();
            } else {
                // requestThrottle() found an existing throttle, we're re-using that one
                log.debug("incrementUse suppressed");
            }
            addressThrottles.get(dla).addListener(l);
            if (ads != null && a.get(i).getRosterEntry() != null && throttle.getRosterEntry() == null) {
                throttle.setRosterEntry(a.get(i).getRosterEntry());
            }
        }
        throttleListeners.remove(dla);
    }
    ArrayList<WaitingThrottle> p = listenerOnly.get(dla);
    if (p == null) {
        log.debug("notifyThrottleKnown with zero-length propertyChangeListeners: " + addr);
    } else {
        for (int i = 0; i < p.size(); i++) {
            PropertyChangeListener l = p.get(i).getPropertyChangeListener();
            log.debug("Notify propertyChangeListener");
            l.propertyChange(new PropertyChangeEvent(this, "throttleAssigned", null, dla));
            if (ads != null && p.get(i).getRosterEntry() != null && throttle.getRosterEntry() == null) {
                throttle.setRosterEntry(p.get(i).getRosterEntry());
            }
            throttle.addPropertyChangeListener(l);
        }
        listenerOnly.remove(dla);
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ThrottleListener(jmri.ThrottleListener) DccLocoAddress(jmri.DccLocoAddress)

Example 49 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project JMRI by JMRI.

the class AbstractThrottleManager method attachListener.

public void attachListener(DccLocoAddress la, BasicRosterEntry re, java.beans.PropertyChangeListener p) {
    if (addressThrottles.containsKey(la)) {
        addressThrottles.get(la).getThrottle().addPropertyChangeListener(p);
        p.propertyChange(new PropertyChangeEvent(this, "throttleAssigned", null, la));
        return;
    } else {
        if (!listenerOnly.containsKey(la)) {
            listenerOnly.put(la, new ArrayList<WaitingThrottle>());
        }
        // get the corresponding list to check length
        ArrayList<WaitingThrottle> a = listenerOnly.get(la);
        a.add(new WaitingThrottle(p, re));
        //requested.
        if ((!throttleListeners.containsKey(la)) && (a.size() == 1)) {
            requestThrottleSetup(la, false);
        }
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent)

Example 50 with PropertyChangeEvent

use of java.beans.PropertyChangeEvent in project JMRI by JMRI.

the class AbstractThrottleManager method failedThrottleRequest.

/**
     * If the system-specific ThrottleManager has been unable to create the DCC
     * throttle then it needs to be removed from the throttleListeners,
     * otherwise any subsequent request for that address results in the address
     * being reported as already in use, if singleUse is set. This also sends a
     * notification message back to the requestor with a string reason as to why
     * the request has failed.
     *
     * @param address The DCC Loco Address that the request failed on.
     * @param reason  A text string passed by the ThrottleManae as to why
     */
public void failedThrottleRequest(DccLocoAddress address, String reason) {
    ArrayList<WaitingThrottle> a = throttleListeners.get(address);
    if (a == null) {
        log.warn("failedThrottleRequest with zero-length listeners: " + address);
    } else {
        for (int i = 0; i < a.size(); i++) {
            ThrottleListener l = a.get(i).getListener();
            l.notifyFailedThrottleRequest(address, reason);
        }
    }
    throttleListeners.remove(address);
    ArrayList<WaitingThrottle> p = listenerOnly.get(address);
    if (p == null) {
        log.debug("failedThrottleRequest with zero-length PropertyChange listeners: " + address);
    } else {
        for (int i = 0; i < p.size(); i++) {
            PropertyChangeListener l = p.get(i).getPropertyChangeListener();
            l.propertyChange(new PropertyChangeEvent(this, "attachFailed", address, null));
        }
    }
    listenerOnly.remove(address);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ThrottleListener(jmri.ThrottleListener)

Aggregations

PropertyChangeEvent (java.beans.PropertyChangeEvent)589 PropertyChangeListener (java.beans.PropertyChangeListener)375 ActionEvent (java.awt.event.ActionEvent)42 ActionListener (java.awt.event.ActionListener)35 JPanel (javax.swing.JPanel)35 Test (org.junit.Test)33 ArrayList (java.util.ArrayList)30 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)27 IFigure (org.eclipse.draw2d.IFigure)25 File (java.io.File)24 JLabel (javax.swing.JLabel)24 BorderLayout (java.awt.BorderLayout)22 List (java.util.List)21 IOException (java.io.IOException)19 Dimension (java.awt.Dimension)16 ChangeEvent (javax.swing.event.ChangeEvent)15 PropertyVetoException (java.beans.PropertyVetoException)14 PropertyChangeSupport (java.beans.PropertyChangeSupport)13 ChangeListener (javax.swing.event.ChangeListener)13 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)13