001package jmri.jmrit.logixng.implementation.swing;
002
003import javax.annotation.CheckForNull;
004import javax.annotation.Nonnull;
005import javax.swing.*;
006
007import jmri.jmrit.logixng.*;
008import jmri.jmrit.logixng.implementation.DefaultMaleDigitalExpressionSocket;
009
010/**
011 * Configures an DefaultMaleDigitalActionSocket object with a Swing JPanel.
012 */
013public class DefaultMaleDigitalExpressionSocketSwing extends AbstractMaleSocketSwing {
014
015    private JPanel _panel;
016    private final JLabel _listenLabel = new JLabel(Bundle.getMessage("DefaultMaleDigitalExpressionSocketSwing_Listen"));
017    private JCheckBox _listenCheckBox;
018
019    @Override
020    protected JPanel getSubPanel(@CheckForNull Base object) {
021        if ((object != null) && (! (object instanceof DefaultMaleDigitalExpressionSocket))) {
022            throw new IllegalArgumentException("object is not an DefaultMaleDigitalExpressionSocket: " + object.getClass().getName());
023        }
024
025        _panel = new JPanel();
026        _listenCheckBox = new JCheckBox();
027        _listenCheckBox.setSelected(true);  // Listen should be true if not changed by the user
028
029        DefaultMaleDigitalExpressionSocket maleSocket = (DefaultMaleDigitalExpressionSocket)object;
030        if (maleSocket != null) {
031            _listenCheckBox.setSelected(maleSocket.getListen());
032        }
033
034        _listenLabel.setLabelFor(_listenCheckBox);
035        _panel.add(_listenLabel);
036        _panel.add(_listenCheckBox);
037
038        return _panel;
039    }
040
041    /** {@inheritDoc} */
042    @Override
043    public void updateObjectForSubPanel(@Nonnull Base object) {
044        Base obj = object;
045        while (((obj instanceof MaleSocket)) && (! (obj instanceof DefaultMaleDigitalExpressionSocket))) {
046            obj = ((MaleSocket)obj).getObject();
047        }
048        if (! (obj instanceof DefaultMaleDigitalExpressionSocket)) {
049            throw new IllegalArgumentException("object is not an DefaultMaleDigitalExpressionSocket: " + object.getClass().getName());
050        }
051
052        DefaultMaleDigitalExpressionSocket maleSocket = (DefaultMaleDigitalExpressionSocket)obj;
053        maleSocket.setListen(_listenCheckBox.isSelected());
054    }
055
056//    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(DefaultMaleDigitalExpressionSocketSwing.class);
057
058}