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);
}
}
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();
}
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);
}
});
}
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);
}
});
}
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);
}
}
Aggregations