001package jmri.jmrix.roco.z21.swing.mon;
002
003import jmri.jmrix.roco.z21.Z21Listener;
004import jmri.jmrix.roco.z21.Z21Message;
005import jmri.jmrix.roco.z21.Z21Reply;
006import jmri.jmrix.roco.z21.Z21SystemConnectionMemo;
007
008/**
009 * Panel displaying (and logging) Z21 messages derived from Z21MonFrame.
010 *
011 * @author Bob Jacobsen Copyright (C) 2002
012 * @author Paul Bender Copyright (C) 2004-2014
013 * @author Giorgio Terdina Copyright (C) 2007
014 */
015public class Z21MonPane extends jmri.jmrix.AbstractMonPane implements Z21Listener {
016
017    protected Z21SystemConnectionMemo memo = null;
018
019    @Override
020    public String getTitle() {
021        return (Bundle.getMessage("Z21TrafficTitle"));
022    }
023
024    @Override
025    public void initContext(Object context) {
026        if (context instanceof Z21SystemConnectionMemo) {
027            memo = (Z21SystemConnectionMemo) context;
028            // connect to the TrafficController
029            memo.getTrafficController().addz21Listener(this);
030        }
031    }
032
033    /**
034     * Initialize the data source.
035     */
036    @Override
037    protected void init() {
038    }
039
040    @Override
041    public void dispose() {
042        // disconnect from the TrafficController
043        memo.getTrafficController().removez21Listener(this);
044        // and unwind swing
045        super.dispose();
046    }
047
048    @Override
049    public synchronized void reply(Z21Reply l) { // receive an XpressNet message and log it
050        logMessage(l);
051    }
052
053    /**
054     * Listen for the messages to the LI100/LI101
055     */
056    @Override
057    public synchronized void message(Z21Message l) {
058        logMessage(l);
059    }
060
061    /**
062     * Nested class to create one of these using old-style defaults
063     */
064    static public class Default extends jmri.util.swing.JmriNamedPaneAction {
065
066        public Default() {
067            super(Bundle.getMessage("Z21TrafficTitle"),
068                    Z21MonPane.class.getName());
069            setContext(jmri.InstanceManager.
070                    getDefault(Z21SystemConnectionMemo.class));
071        }
072    }
073
074}