Search in sources :

Example 51 with PropertyChangeEvent

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));
    });
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener)

Example 52 with PropertyChangeEvent

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);
        }
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) IOException(java.io.IOException)

Example 53 with PropertyChangeEvent

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);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) CardLayout(java.awt.CardLayout) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) BoxLayout(javax.swing.BoxLayout) ArrayList(java.util.ArrayList) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) BorderLayout(java.awt.BorderLayout) JSplitPane(javax.swing.JSplitPane) Vector(java.util.Vector)

Example 54 with PropertyChangeEvent

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());
        }
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) SignalHead(jmri.SignalHead) SignalMast(jmri.SignalMast) Block(jmri.Block)

Example 55 with PropertyChangeEvent

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));
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent)

Aggregations

PropertyChangeEvent (java.beans.PropertyChangeEvent)589 PropertyChangeListener (java.beans.PropertyChangeListener)375 ActionEvent (java.awt.event.ActionEvent)42 ActionListener (java.awt.event.ActionListener)35 JPanel (javax.swing.JPanel)35 Test (org.junit.Test)33 ArrayList (java.util.ArrayList)30 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)27 IFigure (org.eclipse.draw2d.IFigure)25 File (java.io.File)24 JLabel (javax.swing.JLabel)24 BorderLayout (java.awt.BorderLayout)22 List (java.util.List)21 IOException (java.io.IOException)19 Dimension (java.awt.Dimension)16 ChangeEvent (javax.swing.event.ChangeEvent)15 PropertyVetoException (java.beans.PropertyVetoException)14 PropertyChangeSupport (java.beans.PropertyChangeSupport)13 ChangeListener (javax.swing.event.ChangeListener)13 UnprocessedChangeEvents (org.jvnet.hk2.config.UnprocessedChangeEvents)13