use of java.beans.PropertyChangeEvent in project JMRI by JMRI.
the class InstanceManager method notifyPropertyChangeListener.
protected static void notifyPropertyChangeListener(String property, Object oldValue, Object newValue) {
// make a copy of the listener vector to synchronized not needed for transmit
HashSet<PropertyChangeListener> set;
synchronized (InstanceManager.class) {
set = new HashSet<>(listeners);
}
// forward to all listeners
set.stream().forEach((listener) -> {
listener.propertyChange(new PropertyChangeEvent(InstanceManager.class, property, oldValue, newValue));
});
}
use of java.beans.PropertyChangeEvent in project JMRI by JMRI.
the class JmriSRCPTimeServer method listenToTimebase.
@Override
public void listenToTimebase(boolean listen) {
if (listen == false && timeListener == null) {
// nothing to do.
return;
}
if (timeListener == null) {
timeListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
try {
if (evt.getPropertyName().equals("minutes")) {
checkAlarmList();
}
} catch (IOException ex) {
log.warn("Unable to send message to client: {}", ex.getMessage());
timebase.removeMinuteChangeListener(timeListener);
}
}
};
if (listen == true) {
timebase.addMinuteChangeListener(timeListener);
} else {
timebase.removeMinuteChangeListener(timeListener);
}
}
}
use of java.beans.PropertyChangeEvent in project JMRI by JMRI.
the class ListedTableFrame method initComponents.
@Override
public void initComponents() {
actionList = new ActionJList(this);
detailpanel = new JPanel();
detailpanel.setLayout(new CardLayout());
tabbedTableArray = new ArrayList<TabbedTableItem>(TabbedTableItemListArrayArray.size());
ArrayList<TabbedTableItemListArray> removeItem = new ArrayList<TabbedTableItemListArray>(5);
for (int x = 0; x < TabbedTableItemListArrayArray.size(); x++) {
/* Here we add all the tables into the panel*/
TabbedTableItemListArray item = TabbedTableItemListArrayArray.get(x);
try {
TabbedTableItem itemModel = new TabbedTableItem(item.getClassAsString(), item.getItemString(), item.getStandardTableModel());
itemBeingAdded = itemModel;
detailpanel.add(itemModel.getPanel(), itemModel.getClassAsString());
tabbedTableArray.add(itemModel);
itemBeingAdded.getAAClass().addToFrame(this);
} catch (Exception ex) {
detailpanel.add(errorPanel(item.getItemString()), item.getClassAsString());
log.error("Error when adding " + item.getClassAsString() + " to display\n" + ex);
ex.printStackTrace();
removeItem.add(item);
}
}
for (TabbedTableItemListArray dead : removeItem) {
TabbedTableItemListArrayArray.remove(dead);
}
list = new JList<String>(new Vector<String>(getChoices()));
listScroller = new JScrollPane(list);
list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
list.setLayoutOrientation(JList.VERTICAL);
list.addMouseListener(actionList);
buttonpanel = new JPanel();
buttonpanel.setLayout(new BorderLayout(5, 0));
buttonpanel.setLayout(new BoxLayout(buttonpanel, BoxLayout.Y_AXIS));
buttonpanel.add(listScroller);
buildMenus(tabbedTableArray.get(0));
setTitle(tabbedTableArray.get(0).getItemString());
cardHolder = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, buttonpanel, detailpanel);
cardHolder.setDividerSize(8);
if (lastdivider != 0) {
cardHolder.setDividerLocation(lastdivider);
} else {
// if no specific size has been given we set it to the lists preferred width
cardHolder.setDividerLocation(listScroller.getPreferredSize().width);
}
cardHolder.addPropertyChangeListener(new PropertyChangeListener() {
@SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification = "We only intend to use/save the last position of the Split frame")
@Override
public void propertyChange(PropertyChangeEvent e) {
if (e.getPropertyName().equals("dividerLocation")) {
lastdivider = (Integer) e.getNewValue();
}
}
});
cardHolder.setOneTouchExpandable(true);
getContentPane().add(cardHolder);
pack();
actionList.selectListItem(0);
}
use of java.beans.PropertyChangeEvent in project JMRI by JMRI.
the class AutoActiveTrain method setupNewCurrentSignal.
protected synchronized void setupNewCurrentSignal(AllocatedSection as) {
removeCurrentSignal();
if (DispatcherFrame.instance().getSignalType() == DispatcherFrame.SIGNALHEAD) {
SignalHead sh = _lbManager.getFacingSignalHead(_currentBlock, _nextBlock);
if (sh != null) {
_controllingSignal = sh;
_conSignalProtectedBlock = _nextBlock;
sh.addPropertyChangeListener(_conSignalListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent e) {
if (e.getPropertyName().equals("Appearance")) {
// controlling signal has changed appearance
setSpeedBySignal();
if (_stoppingForStopSignal && (_targetSpeed > 0.0)) {
cancelStopInCurrentSection();
_stoppingForStopSignal = false;
}
}
}
});
if (log.isDebugEnabled()) {
log.debug("new current signal = " + sh.getSystemName());
}
setSpeedBySignal();
} else // Note: null signal head will result when exiting throat-to-throat blocks.
if (log.isDebugEnabled()) {
log.debug("new current signal is null - sometimes OK");
}
} else {
//SignalMast
SignalMast sm = null;
Block cB = _currentBlock;
Block nB = _nextBlock;
if (as == null) {
as = _currentAllocatedSection;
}
//}
while (sm == null && nB != null) {
sm = _lbManager.getFacingSignalMast(cB, nB);
if (sm == null) {
cB = nB;
nB = getNextBlock(nB, as);
}
}
if (sm != null) {
_controllingSignalMast = sm;
_conSignalProtectedBlock = nB;
sm.addPropertyChangeListener(_conSignalMastListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent e) {
if (e.getPropertyName().equals("Aspect")) {
// controlling signal has changed appearance
if (_stoppingForStopSignal && (_targetSpeed > 0.0)) {
cancelStopInCurrentSection();
_stoppingForStopSignal = false;
}
setSpeedBySignal();
} else if (e.getPropertyName().equals("Held")) {
if (!((Boolean) e.getNewValue())) {
cancelStopInCurrentSection();
_stoppingForStopSignal = false;
}
setSpeedBySignal();
}
}
});
log.debug("{}: new current signalmast {}({}) for section {}", _activeTrain.getTrainName(), sm.getDisplayName(), sm.getAspect(), as.getSectionName());
setSpeedBySignal();
} else // Note: null signal head will result when exiting throat-to-throat blocks.
{
log.debug("{}: new current signalmast is null for section {} - sometimes OK", _activeTrain.getTrainName(), as.getSectionName());
}
}
}
use of java.beans.PropertyChangeEvent in project JMRI by JMRI.
the class AllocatedSection method firePropertyChangeEvent.
protected void firePropertyChangeEvent(String name, Object oldVal, Object newVal) {
log.debug("Firing property change: " + name + " " + newVal.toString());
firePropertyChangeEvent(new PropertyChangeEvent(this, name, oldVal, newVal));
}
Aggregations