001package jmri.jmrix.rfid.swing.serialmon; 002 003import jmri.InstanceManager; 004import jmri.jmrix.rfid.RfidListener; 005import jmri.jmrix.rfid.RfidMessage; 006import jmri.jmrix.rfid.RfidReply; 007import jmri.jmrix.rfid.RfidSystemConnectionMemo; 008import jmri.jmrix.rfid.swing.RfidNamedPaneAction; 009import jmri.jmrix.rfid.swing.RfidPanelInterface; 010import jmri.util.swing.sdi.JmriJFrameInterface; 011 012/** 013 * Swing action to create and register a MonFrame object. 014 * 015 * @author Bob Jacobsen Copyright (C) 2001, 2008 016 * @author Matthew Harris Copyright (C) 2011 017 * @since 2.11.4 018 */ 019public class SerialMonPane extends jmri.jmrix.AbstractMonPane implements RfidListener, RfidPanelInterface { 020 021 public SerialMonPane() { 022 super(); 023 } 024 025 @Override 026 public String getHelpTarget() { 027 return null; 028 } 029 030 @Override 031 public String getTitle() { 032 return Bundle.getMessage("MonitorXTitle", "RFID Device"); 033 } 034 035 @Override 036 public void dispose() { 037 // disconnect from the RfidTrafficController 038 memo.getTrafficController().removeRfidListener(this); 039 // and unwind swing 040 super.dispose(); 041 } 042 043 @Override 044 public void init() { 045 } 046 047 RfidSystemConnectionMemo memo; 048 049 @Override 050 public void initContext(Object context) { 051 if (context instanceof RfidSystemConnectionMemo) { 052 initComponents((RfidSystemConnectionMemo) context); 053 } 054 } 055 056 @Override 057 public void initComponents(RfidSystemConnectionMemo memo) { 058 this.memo = memo; 059 // connect to the RfidTrafficController 060 memo.getTrafficController().addRfidListener(this); 061 } 062 063 @Override 064 public synchronized void message(RfidMessage l) { // receive a message and log it 065 if (l.isBinary()) { 066 logMessage("binary cmd: ",l); 067 } else { 068 logMessage("cmd: ",l); 069 } 070 } 071 072 @Override 073 public synchronized void reply(RfidReply l) { // receive a reply message and log it 074 if (l.isUnsolicited()) { 075 logMessage("msg: ",l); 076 } else { 077 logMessage("rep: ", l); 078 } 079 } 080 081 /** 082 * Nested class to create one of these using old-style defaults. 083 */ 084 static public class Default extends RfidNamedPaneAction { 085 086 public Default() { 087 super(Bundle.getMessage("MonitorXTitle", "RFID Device"), 088 new JmriJFrameInterface(), 089 SerialMonPane.class.getName(), 090 InstanceManager.getDefault(RfidSystemConnectionMemo.class)); 091 } 092 } 093 094}