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