001/** 002 * Swing action to create and register a IEEE802154 PacketGenFrame object 003 * 004 * @author Bob Jacobsen Copyright (C) 2001, 2002 005 */ 006package jmri.jmrix.ieee802154.xbee.swing.packetgen; 007 008import java.awt.event.ActionEvent; 009import javax.swing.Action; 010import jmri.InstanceManager; 011import jmri.jmrix.ieee802154.xbee.XBeeConnectionMemo; 012import jmri.jmrix.ieee802154.xbee.XBeeTrafficController; 013import jmri.jmrix.ieee802154.xbee.swing.XBeeSystemConnectionAction; 014import org.slf4j.Logger; 015import org.slf4j.LoggerFactory; 016 017public class PacketGenAction extends XBeeSystemConnectionAction { 018 019 public PacketGenAction(String s, XBeeConnectionMemo memo) { 020 super(s, memo); 021 } 022 023 public PacketGenAction(XBeeConnectionMemo memo) { 024 this(Bundle.getMessage("SendCommandTitle"), memo); 025 } 026 027 public PacketGenAction(String s) { 028 this(s,InstanceManager.getNullableDefault(XBeeConnectionMemo.class)); 029 } 030 031 public PacketGenAction() { 032 this(Bundle.getMessage("SendXbeeCommandTitle")); 033 } 034 035 @Override 036 public void actionPerformed(ActionEvent e) { 037 XBeeConnectionMemo memo = getSystemConnectionMemo(); 038 if (memo != null) { 039 // create a PacketGenFrame 040 PacketGenFrame f = new PacketGenFrame(); 041 try { 042 f.initComponents(); 043 } catch (Exception ex) { 044 log.error("Exception: {}", ex.toString()); 045 } 046 f.setVisible(true); 047 048 // connect to the TrafficController 049 f.connect((XBeeTrafficController) memo.getTrafficController()); 050 } else { 051 log.error("No connection, so not performing action {}", getValue(Action.NAME)); 052 } 053 } 054 055 private final static Logger log = LoggerFactory.getLogger(PacketGenAction.class); 056 057}