use of java.beans.PropertyChangeEvent in project sling by apache.
the class Util method setupColumnWidths.
static void setupColumnWidths(final TableColumnModel tcm, final String propertyName) {
PropertyChangeListener pcl = new PropertyChangeListener() {
private final String pclPropName = propertyName;
private final TableColumnModel pclTcm = tcm;
public void propertyChange(PropertyChangeEvent evt) {
if ("width".equals(evt.getPropertyName())) {
int[] colWidths = new int[pclTcm.getColumnCount()];
for (int i = 0; i < colWidths.length; i++) {
colWidths[i] = pclTcm.getColumn(i).getWidth();
}
setPreference(pclPropName, colWidths, true);
}
}
};
int[] colWidths = getPreference(propertyName, new int[0]);
for (int i = 0; i < colWidths.length && i < tcm.getColumnCount(); i++) {
tcm.getColumn(i).setPreferredWidth(colWidths[i]);
}
for (int i = 0; i < tcm.getColumnCount(); i++) {
tcm.getColumn(i).addPropertyChangeListener(pcl);
}
}
use of java.beans.PropertyChangeEvent in project JMRI by JMRI.
the class Section method initializeBlocks.
private void initializeBlocks() {
for (int i = 0; i < blockNameList.size(); i++) {
Block b = InstanceManager.getDefault(jmri.BlockManager.class).getBlock(blockNameList.get(i));
if (b == null) {
log.error("Missing Block - " + blockNameList.get(i) + " - when initializing Section - " + getSystemName());
} else {
if (mBlockEntries.isEmpty()) {
mFirstBlock = b;
}
mBlockEntries.add(b);
mLastBlock = b;
PropertyChangeListener listener = (PropertyChangeEvent e) -> {
handleBlockChange(e);
};
b.addPropertyChangeListener(listener);
mBlockListeners.add(listener);
}
}
initializationNeeded = false;
}
use of java.beans.PropertyChangeEvent 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.PropertyChangeEvent in project JMRI by JMRI.
the class VSDecoder method setXml.
/*
* @Deprecated public void setXml(Element e) { this.setXml(e, null); }
*
* @Deprecated public void setXml(Element e, VSDFile vf) { this.setXml(vf); }
*
* @Deprecated public void setXml(VSDFile vf) { }
*/
/**
* Build this VSDecoder from an XML representation
*
* @param vf (VSDFile) : VSD File to pull the XML from
* @param pn (String) : Parameter Name to find within the VSD File.
*/
@SuppressWarnings({ "cast" })
public void setXml(VSDFile vf, String pn) {
Iterator<Element> itr;
Element e = null;
Element el = null;
SoundEvent se;
if (vf == null) {
log.debug("Null VSD File Name");
return;
}
log.debug("VSD File Name = " + vf.getName());
// need to choose one.
this.setVSDFilePath(vf.getName());
// Find the <profile/> element that matches the name pn
// List<Element> profiles = vf.getRoot().getChildren("profile");
// java.util.Iterator i = profiles.iterator();
java.util.Iterator<Element> i = vf.getRoot().getChildren("profile").iterator();
while (i.hasNext()) {
e = i.next();
if (e.getAttributeValue("name").equals(pn)) {
break;
}
}
if (e == null) {
// No matching profile name found.
return;
}
// Set this decoder's name.
this.setProfileName(e.getAttributeValue("name"));
log.debug("Decoder Name = " + e.getAttributeValue("name"));
// Check for default element.
if (e.getChild("default") != null) {
log.debug("" + getProfileName() + "is default.");
is_default = true;
} else {
is_default = false;
}
// +++ DEBUG
// Log and print all of the child elements.
itr = (e.getChildren()).iterator();
while (itr.hasNext()) {
// Pull each element from the XML file.
el = itr.next();
log.debug("Element: " + el.toString());
if (el.getAttribute("name") != null) {
log.debug(" Name: " + el.getAttributeValue("name"));
log.debug(" type: " + el.getAttributeValue("type"));
}
}
// --- DEBUG
// First, the sounds.
String prefix = "" + this.getID() + ":";
log.debug("VSDecoder " + this.getID() + " prefix = " + prefix);
itr = (e.getChildren("sound")).iterator();
while (itr.hasNext()) {
el = (Element) itr.next();
if (el.getAttributeValue("type") == null) {
// Empty sound. Skip.
log.debug("Skipping empty Sound.");
continue;
} else if (el.getAttributeValue("type").equals("configurable")) {
// Handle configurable sounds.
ConfigurableSound cs = new ConfigurableSound(prefix + el.getAttributeValue("name"));
cs.setXml(el, vf);
sound_list.put(el.getAttributeValue("name"), cs);
} else if (el.getAttributeValue("type").equals("diesel")) {
// Handle a Diesel Engine sound
DieselSound es = new DieselSound(prefix + el.getAttributeValue("name"));
es.setXml(el, vf);
sound_list.put(el.getAttributeValue("name"), es);
} else if (el.getAttributeValue("type").equals("diesel3")) {
// Handle a Diesel Engine sound
Diesel3Sound es = new Diesel3Sound(prefix + el.getAttributeValue("name"));
es.setXml(el, vf);
sound_list.put(el.getAttributeValue("name"), es);
} else if (el.getAttributeValue("type").equals("steam")) {
// Handle a Diesel Engine sound
SteamSound es = new SteamSound(prefix + el.getAttributeValue("name"));
es.setXml(el, vf);
sound_list.put(el.getAttributeValue("name"), es);
} else if (el.getAttributeValue("type").equals("steam1")) {
// Handle a Steam Engine sound
Steam1Sound es = new Steam1Sound(prefix + el.getAttributeValue("name"));
es.setXml(el, vf);
sound_list.put(el.getAttributeValue("name"), es);
} else {
// TODO: Some type other than configurable sound. Handle appropriately
}
}
// Next, grab all of the SoundEvents
// Have to do the sounds first because the SoundEvent's setXml() will
// expect to be able to look it up.
itr = (e.getChildren("sound-event")).iterator();
while (itr.hasNext()) {
el = (Element) itr.next();
switch(SoundEvent.ButtonType.valueOf(el.getAttributeValue("buttontype").toUpperCase())) {
case MOMENTARY:
se = new MomentarySoundEvent(el.getAttributeValue("name"));
break;
case TOGGLE:
se = new ToggleSoundEvent(el.getAttributeValue("name"));
break;
case ENGINE:
se = new EngineSoundEvent(el.getAttributeValue("name"));
break;
case NONE:
default:
se = new SoundEvent(el.getAttributeValue("name"));
}
se.setParent(this);
se.setXml(el, vf);
event_list.put(se.getName(), se);
}
// Handle other types of children similarly here.
// Check for an existing throttle and update speed if it exists.
Float s = (Float) InstanceManager.throttleManagerInstance().getThrottleInfo(config.getDccAddress(), "SpeedSetting");
if (s != null) {
// Mimic a throttlePropertyChange to propagate the current (init) speed setting of the throttle.
log.debug("Existing Throttle found. Speed = " + s);
this.throttlePropertyChange(new PropertyChangeEvent(this, "SpeedSetting", null, s));
} else {
log.debug("No existing throttle found.");
}
}
use of java.beans.PropertyChangeEvent 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);
}
}
}
Aggregations