001package jmri.jmrix.ieee802154.xbee.swing.nodeconfig;
002
003import java.awt.event.ActionEvent;
004import org.slf4j.Logger;
005import org.slf4j.LoggerFactory;
006
007/**
008 * Swing action to create and register a XBeeNodeConfigFrame object
009 *
010 * @author Bob Jacobsen Copyright (C) 2001
011 */
012public class XBeeNodeConfigAction extends jmri.jmrix.ieee802154.swing.nodeconfig.NodeConfigAction {
013
014    private jmri.jmrix.ieee802154.xbee.XBeeConnectionMemo xcm = null;
015
016    public XBeeNodeConfigAction(String s, jmri.jmrix.ieee802154.xbee.XBeeConnectionMemo cm) {
017        super(s, cm);
018        if (cm == null) {
019            // find the first registered memo.
020            try {
021                xcm = jmri.InstanceManager.
022                        getList(jmri.jmrix.ieee802154.xbee.XBeeConnectionMemo.class).get(0);
023            } catch (java.lang.NullPointerException|java.lang.IndexOutOfBoundsException e) {
024                // no memo is registered, is this the first time the
025                // connection has been configured?
026                log.debug("No XBee System Connection Memo available");
027            }
028        } else {
029            xcm = cm;
030        }
031    }
032
033    public XBeeNodeConfigAction() {
034        this(Bundle.getMessage("ConfigureXbeeTitle"), null);
035    }
036
037    public XBeeNodeConfigAction(String s) {
038        this(s, null);
039    }
040
041    public XBeeNodeConfigAction(jmri.jmrix.ieee802154.xbee.XBeeConnectionMemo cm) {
042        this(Bundle.getMessage("ConfigureXbeeTitle"), cm);
043    }
044
045    @Override
046    public void actionPerformed(ActionEvent e) {
047        XBeeNodeConfigFrame f = new XBeeNodeConfigFrame((jmri.jmrix.ieee802154.xbee.XBeeTrafficController) xcm.getTrafficController());
048        try {
049            f.initComponents();
050        } catch (Exception ex) {
051            log.error("Exception: {}", ex.toString());
052        }
053        f.setLocation(100, 30);
054        f.setVisible(true);
055    }
056
057    private final static Logger log = LoggerFactory.getLogger(XBeeNodeConfigAction.class);
058
059}