001package jmri.jmrix.cmri.serial.serialmon;
002
003import java.awt.event.ActionEvent;
004import javax.swing.Action;
005import jmri.InstanceManager;
006import jmri.jmrix.cmri.CMRISystemConnectionMemo;
007import jmri.jmrix.cmri.swing.CMRISystemConnectionAction;
008import org.slf4j.Logger;
009import org.slf4j.LoggerFactory;
010
011/**
012 * Swing action to create and register a SerialMonFrame object
013 *
014 * @author Bob Jacobsen Copyright (C) 2001
015 */
016public class SerialMonAction extends CMRISystemConnectionAction {
017
018    public SerialMonAction(String s, CMRISystemConnectionMemo memo) {
019        super(s, memo);
020    }
021
022    public SerialMonAction(CMRISystemConnectionMemo memo) {
023        this(Bundle.getMessage("SerialCommandMonTitle"), memo);
024    }
025
026    public SerialMonAction() {
027        this(InstanceManager.getNullableDefault(CMRISystemConnectionMemo.class));
028    }
029
030    @Override
031    public void actionPerformed(ActionEvent e) {
032        CMRISystemConnectionMemo memo = getSystemConnectionMemo();
033        if (memo != null) {
034            SerialMonFrame f = new SerialMonFrame(memo);
035            try {
036                f.initComponents();
037            } catch (Exception ex) {
038                log.warn("Exception starting SerialMonFrame", ex);
039            }
040            f.setVisible(true);
041        } else {
042            log.error("Not performing action {} because there is no connection", getValue(Action.NAME));
043        }
044    }
045
046    private final static Logger log = LoggerFactory.getLogger(SerialMonAction.class);
047
048}