001package jmri.jmrix.lenz.swing.packetgen;
002
003import jmri.jmrix.lenz.XNetMessage;
004import jmri.jmrix.lenz.XNetTrafficController;
005
006/**
007 * Frame for user input of XpressNet messages
008 *
009 * @author Bob Jacobsen Copyright (C) 2001,2002
010 */
011public class PacketGenFrame extends jmri.jmrix.swing.AbstractPacketGenFrame {
012
013    /**
014     * {@inheritDoc}
015     */
016    @Override
017    public void initComponents() {
018        super.initComponents();
019
020        // all we need to do is set the title 
021        setTitle(Bundle.getMessage("PacketGenFrameTitle"));
022
023        // pack to cause display
024        pack();
025    }
026
027    /**
028     * {@inheritDoc}
029     */
030    @Override
031    public void sendButtonActionPerformed(java.awt.event.ActionEvent e) {
032        if (packetTextField.getSelectedItem() != null) {
033            tc.sendXNetMessage(createPacket(packetTextField.getSelectedItem().toString()), null);
034        }
035    }
036
037    XNetMessage createPacket(String s) {
038        if (s.equals("")) {
039            return null; // message cannot be empty
040        }
041        return new XNetMessage(s);
042    }
043
044    // connect to the TrafficController
045    public void connect(XNetTrafficController t) {
046        tc = t;
047    }
048
049    // private data
050    private XNetTrafficController tc = null;
051}