Search in sources :

Example 41 with PropertyChangeEvent

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

the class SpeedProfilePanel method notifyThrottleFound.

@Override
public void notifyThrottleFound(DccThrottle _throttle) {
    t = _throttle;
    if (t == null) {
        JOptionPane.showMessageDialog(null, Bundle.getMessage("ErrorThrottleNotFound"));
        log.warn("null throttle returned for train  " + re.getId() + " during automatic initialization.");
        setButtonStates(true);
        return;
    }
    if (log.isDebugEnabled()) {
        log.debug("throttle address= " + t.getLocoAddress().toString());
    }
    int speedStepMode = t.getSpeedStepMode();
    profileIncrement = t.getSpeedIncrement();
    //        int speedStep;
    if (speedStepMode == DccThrottle.SpeedStepMode14) {
        profileSpeedStepMode = 14;
    } else if (speedStepMode == DccThrottle.SpeedStepMode27) {
        profileSpeedStepMode = 27;
    } else if (speedStepMode == DccThrottle.SpeedStepMode28) {
        profileSpeedStepMode = 28;
    } else {
        // default to 128 speed step mode
        profileSpeedStepMode = 126;
    }
    if (finishSpeedStep <= 0) {
        finishSpeedStep = profileSpeedStepMode;
    }
    log.debug("Speed step mode " + profileSpeedStepMode);
    profileSpeed = profileIncrement * profileStep;
    if (profile) {
        startSensor = middleBlockSensor.getSensor();
        finishSensor = sensorB.getSensor();
        startListener = new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent e) {
                if (e.getPropertyName().equals("KnownState")) {
                    if (((Integer) e.getNewValue()) == Sensor.ACTIVE) {
                        startTiming();
                    }
                    if (((Integer) e.getNewValue()) == Sensor.INACTIVE) {
                        stopLoco();
                    }
                }
            }
        };
        finishListener = new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent e) {
                if (e.getPropertyName().equals("KnownState")) {
                    if (((Integer) e.getNewValue()) == Sensor.ACTIVE) {
                        stopCurrentSpeedStep();
                    }
                }
            }
        };
        isForward = true;
        startProfile();
    } else {
        if (re.getSpeedProfile() == null) {
            log.error("Loco has no speed profile");
            JOptionPane.showMessageDialog(null, Bundle.getMessage("ErrorNoSpeedProfile"));
            setButtonStates(true);
            return;
        }
        startSensor = middleBlockSensor.getSensor();
        startListener = new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent e) {
                if (e.getPropertyName().equals("KnownState")) {
                    if (((Integer) e.getNewValue()) == Sensor.ACTIVE) {
                        stopTrainTest();
                    }
                }
            }
        };
        startSensor.addPropertyChangeListener(startListener);
        int startstep = Integer.parseInt(speedStepTest.getText());
        isForward = true;
        t.setIsForward(isForward);
        try {
            Thread.sleep(250);
        } catch (InterruptedException e) {
        // Nthing I can do.      
        }
        profileSpeed = profileIncrement * startstep;
        t.setSpeedSetting(profileSpeed);
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener)

Example 42 with PropertyChangeEvent

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

the class DieselPane method startButtonChange.

public void startButtonChange(ActionEvent e) {
    firePropertyChangeEvent(new PropertyChangeEvent(this, "start", engine_started, start_button.isSelected()));
    engine_started = start_button.isSelected();
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent)

Example 43 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 44 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 45 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)

Aggregations

PropertyChangeEvent (java.beans.PropertyChangeEvent)574 PropertyChangeListener (java.beans.PropertyChangeListener)349 ActionEvent (java.awt.event.ActionEvent)42 JPanel (javax.swing.JPanel)36 ActionListener (java.awt.event.ActionListener)35 Test (org.junit.Test)33 ArrayList (java.util.ArrayList)31 PropertyVetoException (java.beans.PropertyVetoException)24 JLabel (javax.swing.JLabel)24 File (java.io.File)23 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 PropertyChangeSupport (java.beans.PropertyChangeSupport)13 ChangeListener (javax.swing.event.ChangeListener)13 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)13 JScrollPane (javax.swing.JScrollPane)12 UnprocessedChangeEvent (org.jvnet.hk2.config.UnprocessedChangeEvent)12