use of java.beans.PropertyChangeListener 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.PropertyChangeListener 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.PropertyChangeListener in project JMRI by JMRI.
the class FrameServletPreferencesPanel method initComponents.
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
private // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
void initComponents() {
bindingGroup = new BindingGroup();
framesEnabled = new ButtonGroup();
preferences = InstanceManager.getDefault(WebServerPreferences.class);
enableFramesPnl = new JPanel();
enableFrames = new JRadioButton();
clickDelay = new JSpinner();
refreshDelay = new JSpinner();
useAjax = new JCheckBox();
refreshDelayLbl = new JLabel();
clickDelayLbl = new JLabel();
disallowedFramesLbl = new JLabel();
jScrollPane1 = new JScrollPane();
disallowedFrames = new EditableList<String>();
disableFramesPnl = new JPanel();
disableFrames = new JRadioButton();
redirectToPanels = new JCheckBox();
framesEnabled.add(enableFrames);
framesEnabled.add(disableFrames);
preferences.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
preferencesPropertyChange(evt);
}
});
// NOI18N
enableFrames.setText(Bundle.getMessage("LabelEnableFrames"));
Binding binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, preferences, ELProperty.create("${!disableFrames}"), enableFrames, BeanProperty.create("selected"));
bindingGroup.addBinding(binding);
clickDelay.setModel(new SpinnerNumberModel(1, 0, 999, 1));
// NOI18N
clickDelay.setToolTipText(Bundle.getMessage("ToolTipClickDelay"));
binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, preferences, ELProperty.create("${clickDelay}"), clickDelay, BeanProperty.create("value"));
bindingGroup.addBinding(binding);
binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, enableFrames, ELProperty.create("${selected}"), clickDelay, BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
refreshDelay.setModel(new SpinnerNumberModel(5, 0, 999, 1));
// NOI18N
refreshDelay.setToolTipText(Bundle.getMessage("ToolTipRefreshDelay"));
binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, preferences, ELProperty.create("${refreshDelay}"), refreshDelay, BeanProperty.create("value"));
bindingGroup.addBinding(binding);
binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, enableFrames, ELProperty.create("${selected}"), refreshDelay, BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
// NOI18N
useAjax.setText(Bundle.getMessage("LabelUseAjax"));
// NOI18N
useAjax.setToolTipText(Bundle.getMessage("ToolTipUseAjax"));
binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, preferences, ELProperty.create("${useAjax}"), useAjax, BeanProperty.create("selected"));
bindingGroup.addBinding(binding);
binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, enableFrames, ELProperty.create("${selected}"), useAjax, BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
// NOI18N
refreshDelayLbl.setText(Bundle.getMessage("LabelRefreshDelay"));
// NOI18N
refreshDelayLbl.setToolTipText(Bundle.getMessage("ToolTipRefreshDelay"));
binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, enableFrames, ELProperty.create("${selected}"), refreshDelayLbl, BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
// NOI18N
clickDelayLbl.setText(Bundle.getMessage("LabelClickDelay"));
// NOI18N
clickDelayLbl.setToolTipText(Bundle.getMessage("ToolTipClickDelay"));
binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, enableFrames, ELProperty.create("${selected}"), clickDelayLbl, BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
// NOI18N
disallowedFramesLbl.setText(Bundle.getMessage("LabelDisallowedFrames"));
// NOI18N
disallowedFramesLbl.setToolTipText(Bundle.getMessage("ToolTipDisallowedFrames"));
binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, enableFrames, ELProperty.create("${selected}"), disallowedFramesLbl, BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
disallowedFrames.setModel(new DefaultEditableListModel<String>());
disallowedFrames.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// NOI18N
disallowedFrames.setToolTipText(Bundle.getMessage("ToolTipDisallowedFrames"));
disallowedFrames.setListCellEditor(new DefaultListCellEditor<>(new JTextField()));
binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, enableFrames, ELProperty.create("${selected}"), disallowedFrames, BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
DefaultEditableListModel<String> model = (DefaultEditableListModel<String>) this.disallowedFrames.getModel();
model.addListDataListener(this);
for (String frame : this.preferences.getDisallowedFrames()) {
model.addElement(frame);
}
model.addElement(" ");
jScrollPane1.setViewportView(disallowedFrames);
GroupLayout enableFramesPnlLayout = new GroupLayout(enableFramesPnl);
enableFramesPnl.setLayout(enableFramesPnlLayout);
enableFramesPnlLayout.setHorizontalGroup(enableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(enableFramesPnlLayout.createSequentialGroup().addContainerGap().addGroup(enableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(enableFramesPnlLayout.createSequentialGroup().addGap(29, 29, 29).addGroup(enableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(enableFramesPnlLayout.createSequentialGroup().addComponent(clickDelay, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(clickDelayLbl, GroupLayout.PREFERRED_SIZE, 104, GroupLayout.PREFERRED_SIZE)).addGroup(enableFramesPnlLayout.createSequentialGroup().addComponent(refreshDelay, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(refreshDelayLbl, GroupLayout.PREFERRED_SIZE, 104, GroupLayout.PREFERRED_SIZE)).addComponent(useAjax, GroupLayout.PREFERRED_SIZE, 160, GroupLayout.PREFERRED_SIZE)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(enableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE).addComponent(disallowedFramesLbl, GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE))).addComponent(enableFrames, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addContainerGap()));
enableFramesPnlLayout.setVerticalGroup(enableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(enableFramesPnlLayout.createSequentialGroup().addContainerGap().addComponent(enableFrames).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(enableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(clickDelay, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(clickDelayLbl).addComponent(disallowedFramesLbl)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(enableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(enableFramesPnlLayout.createSequentialGroup().addGroup(enableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(refreshDelay, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(refreshDelayLbl)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(useAjax).addContainerGap(108, Short.MAX_VALUE)).addComponent(jScrollPane1))));
// NOI18N
disableFrames.setText(Bundle.getMessage("LabelDisableFrames"));
// NOI18N
disableFrames.setToolTipText(Bundle.getMessage("ToolTipDisableFrames"));
binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, preferences, ELProperty.create("${disableFrames}"), disableFrames, BeanProperty.create("selected"));
bindingGroup.addBinding(binding);
// NOI18N
redirectToPanels.setText(Bundle.getMessage("LabelRedirectFramesToPanels"));
// NOI18N
redirectToPanels.setToolTipText(Bundle.getMessage("ToolTipRedirectFramesToPanels"));
binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, preferences, ELProperty.create("${redirectFramesToPanels}"), redirectToPanels, BeanProperty.create("selected"));
bindingGroup.addBinding(binding);
binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, disableFrames, ELProperty.create("${selected}"), redirectToPanels, BeanProperty.create("enabled"));
bindingGroup.addBinding(binding);
GroupLayout disableFramesPnlLayout = new GroupLayout(disableFramesPnl);
disableFramesPnl.setLayout(disableFramesPnlLayout);
disableFramesPnlLayout.setHorizontalGroup(disableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(disableFramesPnlLayout.createSequentialGroup().addGroup(disableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(disableFramesPnlLayout.createSequentialGroup().addContainerGap().addComponent(disableFrames, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addGroup(disableFramesPnlLayout.createSequentialGroup().addGap(35, 35, 35).addComponent(redirectToPanels, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))).addContainerGap()));
disableFramesPnlLayout.setVerticalGroup(disableFramesPnlLayout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(disableFramesPnlLayout.createSequentialGroup().addContainerGap().addComponent(disableFrames, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(redirectToPanels).addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
GroupLayout layout = new GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(enableFramesPnl, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(disableFramesPnl, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(enableFramesPnl, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(disableFramesPnl, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)));
bindingGroup.bind();
}
use of java.beans.PropertyChangeListener in project JMRI by JMRI.
the class NamedBeanTest method testDispose.
public void testDispose() {
NamedBean n = createInstance();
n.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent p) {
}
});
n.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent p) {
}
});
Assert.assertEquals("start length", 2, n.getNumPropertyChangeListeners());
n.dispose();
Assert.assertEquals("end length", 0, n.getNumPropertyChangeListeners());
}
use of java.beans.PropertyChangeListener in project JMRI by JMRI.
the class AbstractThrottleTest method testRemovePropertyChangeListener.
/**
* Test of removePropertyChangeListener method, of class AbstractThrottle.
*/
public void testRemovePropertyChangeListener() {
PropertyChangeListener l = (PropertyChangeEvent evt) -> {
};
AbstractThrottle instance = new AbstractThrottleImpl();
instance.removePropertyChangeListener(l);
}
Aggregations