001package jmri.jmrix.rps.rpsmon;
002
003import jmri.jmrix.rps.Distributor;
004import jmri.jmrix.rps.Measurement;
005import jmri.jmrix.rps.MeasurementListener;
006import jmri.jmrix.rps.Reading;
007import jmri.jmrix.rps.ReadingListener;
008import jmri.jmrix.rps.RpsSystemConnectionMemo;
009
010/**
011 * Frame displaying (and logging) RPS messages.
012 *
013 * @author Bob Jacobsen Copyright (C) 2006
014 */
015public class RpsMonFrame extends jmri.jmrix.AbstractMonFrame
016        implements ReadingListener, MeasurementListener {
017
018    RpsSystemConnectionMemo memo = null;
019
020    public RpsMonFrame(RpsSystemConnectionMemo _memo) {
021        super();
022        memo = _memo;
023        Distributor.instance().addReadingListener(this);
024        Distributor.instance().addMeasurementListener(this);
025    }
026
027    @Override
028    protected String title() {
029        return "RPS Monitor";
030    }
031
032    @Override
033    public void dispose() {
034        // remove from notification
035        Distributor.instance().removeReadingListener(this);
036        Distributor.instance().removeMeasurementListener(this);
037        // and unwind swing
038        super.dispose();
039    }
040
041    @Override
042    protected void init() {
043    }
044
045    @Override
046    public void notify(Reading r) {
047        String raw = "";
048        if (r.getRawData() != null) {
049            raw = r.getRawData().toString();
050        }
051        nextLine(r.toString() + "\n", raw);
052    }
053
054    @Override
055    public void notify(Measurement m) {
056        String raw = "";
057        if (m.getReading() != null) {
058            raw = m.getReading().toString();
059        }
060        nextLine(m.toString() + "\n", raw);
061    }
062
063}