001package jmri.jmrix.roco.z21.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 z21 PacketGenFrame object.
010 *
011 * @author Bob Jacobsen Copyright (C) 2001, 2002
012 */
013public class PacketGenAction extends AbstractAction {
014
015    jmri.jmrix.roco.z21.Z21SystemConnectionMemo _memo;
016
017    public PacketGenAction(String s, jmri.jmrix.roco.z21.Z21SystemConnectionMemo memo) {
018        super(s);
019        _memo = memo;
020    }
021
022    public PacketGenAction(jmri.jmrix.roco.z21.Z21SystemConnectionMemo memo) {
023        this(Bundle.getMessage("SendZ21MessageTitle"), memo);
024    }
025
026    public PacketGenAction(String s) {
027        super(s);
028        // If there is no system memo given, assume the system memo
029        // is the first one in the instance list.
030        _memo = jmri.InstanceManager.
031                getList(jmri.jmrix.roco.z21.Z21SystemConnectionMemo.class).get(0);
032    }
033
034    public PacketGenAction() {
035        this(Bundle.getMessage("SendZ21MessageTitle"));
036    }
037
038    @Override
039    public void actionPerformed(ActionEvent e) {
040        // create a PacketGenFrame
041        PacketGenFrame f = new PacketGenFrame();
042        try {
043            f.initComponents();
044        } catch (Exception ex) {
045            log.error("Exception: {}",ex,ex);
046        }
047        f.setVisible(true);
048
049        // connect to the TrafficController
050        f.connect(_memo.getTrafficController());
051    }
052
053    private static final Logger log = LoggerFactory.getLogger(PacketGenAction.class);
054
055}