001package jmri.jmrix.roco.z21.swing.configtool;
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 Z21ConfigFrame object
010 *
011 * @author Paul Bender Copyright (C) 2016
012 */
013public class Z21ConfigAction extends AbstractAction {
014
015    private jmri.jmrix.roco.z21.Z21SystemConnectionMemo _memo;
016
017    public Z21ConfigAction(String s, jmri.jmrix.roco.z21.Z21SystemConnectionMemo memo) {
018        super(s);
019        _memo = memo;
020    }
021
022    public Z21ConfigAction(jmri.jmrix.roco.z21.Z21SystemConnectionMemo memo) {
023        this(Bundle.getMessage("Z21ConfigToolMenuItem"), memo);
024    }
025
026    public Z21ConfigAction(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 Z21ConfigAction() {
035        this("Z21 Configuration Tool");
036    }
037
038    @Override
039    public void actionPerformed(ActionEvent e) {
040        // create a Z21ConfigFrame
041        Z21ConfigFrame f = new Z21ConfigFrame(_memo);
042        try {
043            f.initComponents();
044        } catch (Exception ex) {
045            log.warn("Z21ConfigAction starting Z21ConfigFrame: ",ex);
046        }
047        f.setVisible(true);
048
049    }
050
051    private static final Logger log = LoggerFactory.getLogger(Z21ConfigAction.class);
052
053}