001package jmri.jmrit.sendpacket;
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 SendPacketFrame object.
010 *
011 * @author Bob Jacobsen Copyright (C) 2003
012 */
013public class SendPacketAction extends AbstractAction {
014
015    public SendPacketAction(String s) {
016        super(s);
017
018        // disable ourself if there is no command Station object available
019        if (jmri.InstanceManager.getNullableDefault(jmri.CommandStation.class) == null) {
020            setEnabled(false);
021        }
022    }
023
024    public SendPacketAction() {
025        this(Bundle.getMessage("SendPacketTitle"));
026    }
027
028    @Override
029    public void actionPerformed(ActionEvent e) {
030        // create a SendPacketFrame
031        SendPacketFrame f = new SendPacketFrame();
032        try {
033            f.initComponents();
034        } catch (Exception ex) {
035            log.error("Exception: {}", ex.toString());
036        }
037        f.setVisible(true);
038    }
039
040    private final static Logger log = LoggerFactory.getLogger(SendPacketAction.class);
041
042}