use of java.beans.PropertyChangeListener in project JMRI by JMRI.
the class AddressPanel method initGUI.
/**
* Create, initialize and place the GUI objects.
*/
private void initGUI() {
mainPanel = new JPanel();
this.setContentPane(mainPanel);
this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
mainPanel.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.anchor = GridBagConstraints.CENTER;
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.insets = new Insets(2, 2, 2, 2);
constraints.weightx = 1;
constraints.weighty = 0;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.ipadx = -16;
if (jmri.util.SystemType.isLinux()) {
constraints.ipady = 0;
} else {
constraints.ipady = -16;
}
addrSelector.setVariableSize(true);
mainPanel.add(addrSelector.getCombinedJPanel(), constraints);
setButton = new JButton(Bundle.getMessage("ButtonSet"));
constraints.gridx = GridBagConstraints.RELATIVE;
constraints.fill = GridBagConstraints.NONE;
constraints.weightx = 0;
constraints.ipadx = constraints.ipady = 0;
mainPanel.add(setButton, constraints);
setButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
consistAddress = null;
changeOfAddress();
}
});
rosterBox = new RosterEntrySelectorPanel();
getRosterEntrySelector().setNonSelectedItem(Bundle.getMessage("NoLocoSelected"));
getRosterEntrySelector().setToolTipText(Bundle.getMessage("SelectLocoFromRosterTT"));
getRosterEntrySelector().addPropertyChangeListener("selectedRosterEntries", new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent pce) {
rosterItemSelected();
}
});
constraints.gridx = 0;
constraints.gridy = GridBagConstraints.RELATIVE;
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weightx = 1;
constraints.weighty = 0;
constraints.gridwidth = GridBagConstraints.REMAINDER;
mainPanel.add(getRosterEntrySelector(), constraints);
conRosterBox = NceConsistRoster.instance().fullRosterComboBox();
if (NceConsistRoster.instance().numEntries() > 0) {
// empty entry
conRosterBox.insertItemAt(Bundle.getMessage("NoConsistSelected"), 0);
conRosterBox.setSelectedIndex(0);
conRosterBox.setToolTipText(Bundle.getMessage("SelectConsistFromRosterTT"));
conRosterBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
consistRosterSelected();
}
});
constraints.gridx = 0;
constraints.gridy = GridBagConstraints.RELATIVE;
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weightx = 1;
constraints.weighty = 0;
mainPanel.add(conRosterBox, constraints);
}
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout());
dispatchButton = new JButton(Bundle.getMessage("ButtonDispatch"));
buttonPanel.add(dispatchButton);
dispatchButton.setEnabled(false);
dispatchButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispatchAddress();
}
});
releaseButton = new JButton(Bundle.getMessage("ButtonRelease"));
buttonPanel.add(releaseButton);
releaseButton.setEnabled(false);
releaseButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
releaseAddress();
}
});
progButton = new JButton(Bundle.getMessage("ButtonProgram"));
buttonPanel.add(progButton);
progButton.setEnabled(false);
progButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
openProgrammer();
}
});
constraints.gridx = 0;
constraints.gridy = GridBagConstraints.RELATIVE;
constraints.gridwidth = 2;
constraints.weighty = 0;
constraints.insets = new Insets(0, 0, 0, 0);
mainPanel.add(buttonPanel, constraints);
pack();
}
use of java.beans.PropertyChangeListener in project JMRI by JMRI.
the class VSDecoderPreferences method set.
public void set(VSDecoderPreferences tp) {
setAutoStartEngine(tp.isAutoStartingEngine());
setAutoLoadDefaultVSDFile(tp.isAutoLoadingDefaultVSDFile());
setDefaultVSDFilePath(tp.getDefaultVSDFilePath());
setDefaultVSDFileName(tp.getDefaultVSDFileName());
setListenerPosition(tp.getListenerPosition());
setAudioMode(tp.getAudioMode());
if (listeners != null) {
for (int i = 0; i < listeners.size(); i++) {
PropertyChangeListener l = listeners.get(i);
PropertyChangeEvent e = new PropertyChangeEvent(this, "VSDecoderPreferences", null, this);
l.propertyChange(e);
}
}
}
use of java.beans.PropertyChangeListener in project JMRI by JMRI.
the class AbstractNamedBean method dispose.
@Override
@OverridingMethodsMustInvokeSuper
public void dispose() {
PropertyChangeListener[] listeners = pcs.getPropertyChangeListeners();
for (PropertyChangeListener l : listeners) {
pcs.removePropertyChangeListener(l);
register.remove(l);
listenerRefs.remove(l);
}
}
use of java.beans.PropertyChangeListener in project JMRI by JMRI.
the class AbstractNamedBean method getListenerRefs.
/**
* Get a meaningful list of places where the bean is in use.
*
* @return ArrayList of the listeners
*/
@Override
public synchronized ArrayList<String> getListenerRefs() {
ArrayList<String> list = new ArrayList<String>();
Enumeration<PropertyChangeListener> en = listenerRefs.keys();
while (en.hasMoreElements()) {
PropertyChangeListener l = en.nextElement();
list.add(listenerRefs.get(l));
}
return list;
}
use of java.beans.PropertyChangeListener 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);
}
}
Aggregations