001package jmri.jmrix.ieee802154.swing.packetgen;
002
003import java.awt.event.ActionEvent;
004import javax.swing.AbstractAction;
005import org.slf4j.Logger;
006import org.slf4j.LoggerFactory;
007
008/**
009 * Swing action to create and register a IEEE802154 PacketGenFrame
010 * object
011 *
012 * @author Bob Jacobsen Copyright (C) 2001, 2002
013 */
014public class PacketGenAction extends AbstractAction {
015
016    jmri.jmrix.ieee802154.IEEE802154SystemConnectionMemo _memo = null;
017
018    public PacketGenAction(String s, jmri.jmrix.ieee802154.IEEE802154SystemConnectionMemo memo) {
019        super(s);
020        _memo = memo;
021    }
022
023    public PacketGenAction(jmri.jmrix.ieee802154.IEEE802154SystemConnectionMemo memo) {
024        this("Send IEEE 802.15.4 Message", memo);
025    }
026
027    public PacketGenAction(String s) {
028        super(s);
029        // If there is no system memo given, assume the system memo
030        // is the first one in the instance list.
031        _memo = jmri.InstanceManager.
032                getList(jmri.jmrix.ieee802154.IEEE802154SystemConnectionMemo.class).get(0);
033    }
034
035    public PacketGenAction() {
036        this("Send IEEE 802.15.4 Message");
037    }
038
039    @Override
040    public void actionPerformed(ActionEvent e) {
041        // create a PacketGenFrame
042        PacketGenFrame f = new PacketGenFrame();
043        try {
044            f.initComponents();
045        } catch (Exception ex) {
046            log.error("Exception: {}", ex.toString());
047        }
048        f.setVisible(true);
049
050        // connect to the TrafficController
051        f.connect(_memo.getTrafficController());
052    }
053
054    private final static Logger log = LoggerFactory.getLogger(PacketGenAction.class);
055
056}