001package jmri.jmrix.pricom.pockettester;
002
003import javax.swing.BoxLayout;
004import javax.swing.JButton;
005import javax.swing.JPanel;
006import javax.swing.JScrollPane;
007import javax.swing.JTable;
008import javax.swing.table.TableRowSorter;
009
010/**
011 * Frame providing survey of DCC contents
012 *
013 * @author Bob Jacobsen Copyright (C) 2005
014 */
015public class PacketTableFrame extends jmri.util.JmriJFrame implements DataListener {
016
017    PacketDataModel model = new PacketDataModel();
018    JTable table;
019    JScrollPane scroll;
020
021    @Override
022    public void initComponents() {
023
024        table = new JTable(model);
025        table.setRowSorter(new TableRowSorter<>(model));
026        scroll = new JScrollPane(table);
027
028        model.configureTable(table);
029
030        // general GUI config
031        setTitle("Packet Monitor");
032        getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
033
034        getContentPane().add(scroll);
035
036        JPanel p1 = new JPanel();
037        JButton b = new JButton(Bundle.getMessage("ButtonClear"));
038        b.addActionListener(new java.awt.event.ActionListener() {
039            @Override
040            public void actionPerformed(java.awt.event.ActionEvent evt) {
041                model.reset();
042            }
043        });
044        p1.add(b);
045        getContentPane().add(p1);
046
047        pack();
048
049    }
050
051    @Override
052    public void dispose() {
053        if (source != null) {
054            source.removeListener(this);
055        }
056        model.dispose();
057        model = null;
058        table = null;
059        scroll = null;
060        super.dispose();
061    }
062
063    DataSource source;
064
065    public void setSource(DataSource d) {
066        source = d;
067        model.setSource(d);
068    }
069
070    @Override
071    public void asciiFormattedMessage(String m) {
072        model.asciiFormattedMessage(m);
073    }
074
075}