001package jmri.jmrix.srcp.swing.packetgen;
002
003import java.awt.event.ActionEvent;
004import jmri.InstanceManager;
005import jmri.jmrix.srcp.SRCPSystemConnectionMemo;
006import jmri.jmrix.srcp.swing.SRCPSystemConnectionAction;
007import org.slf4j.Logger;
008import org.slf4j.LoggerFactory;
009
010/**
011 * Swing action to create and register a PacketGenFrame object
012 *
013 * @author Bob Jacobsen Copyright (C) 2008
014 */
015public class PacketGenAction extends SRCPSystemConnectionAction {
016
017    public PacketGenAction(String s, SRCPSystemConnectionMemo memo) {
018        super(s, memo);
019    }
020
021    public PacketGenAction(SRCPSystemConnectionMemo memo) {
022        this(Bundle.getMessage("MenuItemSendSRCPCommand"), memo);
023    }
024
025    public PacketGenAction() {
026        this(InstanceManager.getDefault(SRCPSystemConnectionMemo.class));
027    }
028
029    @Override
030    public void actionPerformed(ActionEvent e) {
031        SRCPSystemConnectionMemo memo = getSystemConnectionMemo();
032        if (memo == null) {
033            log.error("No SRCP connection.");
034        } else {
035            PacketGenFrame f = new PacketGenFrame(memo);
036            try {
037                f.initComponents();
038            } catch (Exception ex) {
039                log.error("Unexpected exception", ex);
040            }
041            f.setVisible(true);
042        }
043    }
044    private final static Logger log = LoggerFactory.getLogger(PacketGenAction.class);
045}