001package jmri.jmrix.ieee802154.swing.mon;
002
003import jmri.jmrix.ieee802154.IEEE802154Listener;
004import jmri.jmrix.ieee802154.IEEE802154Message;
005import jmri.jmrix.ieee802154.IEEE802154Reply;
006import jmri.jmrix.ieee802154.IEEE802154SystemConnectionMemo;
007
008/**
009 * Pane displaying (and logging) IEEE 802.15.4 messages
010 *
011 * @author Paul Bender Copyright (C) 2013,2018
012 */
013public class IEEE802154MonPane extends jmri.jmrix.AbstractMonPane implements IEEE802154Listener {
014
015    private IEEE802154SystemConnectionMemo _memo = null;
016
017    public IEEE802154MonPane() {
018        super();
019    }
020
021    @Override
022    public String getTitle() {
023        return Bundle.getMessage("MonFrameTitle");
024    }
025
026    // ieee802.15.4 Listener methods
027    @Override
028    public void message(IEEE802154Message m) {
029        logMessage(m);
030    }
031
032    @Override
033    public void reply(IEEE802154Reply m) {
034        logMessage(m);
035    }
036
037    @Override
038    public void dispose() {
039        _memo.getTrafficController().removeIEEE802154Listener(this);
040        // unwind swing
041        super.dispose();
042    }
043
044    @Override
045    protected void init() {
046    }
047
048    @Override
049    public void initContext(Object context) {
050       if (context instanceof IEEE802154SystemConnectionMemo) {
051            _memo = (IEEE802154SystemConnectionMemo) context;
052            // connect to the TrafficController
053            _memo.getTrafficController().addIEEE802154Listener(this);
054       }
055    }
056
057    /**
058     * Nested class to create one of these using old-style defaults
059     */
060    static public class Default extends jmri.util.swing.JmriNamedPaneAction {
061
062        public Default() {
063            super(Bundle.getMessage("MonFrameTitle"), IEEE802154MonPane.class.getName());
064            setContext(jmri.InstanceManager.
065                    getDefault(IEEE802154SystemConnectionMemo.class));
066        }
067    }
068
069}