001package jmri.jmrix.xpa.swing.xpamon; 002 003import jmri.jmrix.xpa.XpaListener; 004import jmri.jmrix.xpa.XpaMessage; 005import jmri.jmrix.xpa.XpaSystemConnectionMemo; 006import jmri.jmrix.xpa.XpaTrafficController; 007 008/** 009 * Panel displaying (and logging) Xpa+Modem command messages. 010 * Derived from XpaMonFrame. 011 * 012 * @author Paul Bender Copyright (C) 2004,2016 013 */ 014public class XpaMonPane extends jmri.jmrix.AbstractMonPane implements XpaListener { 015 016 protected XpaTrafficController tc = null; 017 protected XpaSystemConnectionMemo memo = null; 018 019 @Override 020 public String getTitle() { 021 return (Bundle.getMessage("XpaMonFrameTitle")); 022 } 023 024 @Override 025 public void initContext(Object context) { 026 if (context instanceof XpaSystemConnectionMemo) { 027 memo = (XpaSystemConnectionMemo) context; 028 tc = memo.getXpaTrafficController(); 029 // connect to the TrafficController 030 tc.addXpaListener(this); 031 } 032 } 033 034 @Override 035 protected void init() { 036 } 037 038 @Override 039 public void dispose() { 040 if (tc != null) tc.removeXpaListener(this); 041 super.dispose(); 042 } 043 044 @Override 045 public synchronized void message(XpaMessage l) { // receive a message and log it 046 logMessage("Sent: ",l); 047 } 048 049 @Override 050 public synchronized void reply(XpaMessage l) { // receive a reply message and log it 051 logMessage("Received: ",l); 052 } 053 054 /** 055 * Nested class to create one of these using old-style defaults 056 */ 057 static public class Default extends jmri.util.swing.JmriNamedPaneAction { 058 059 public Default() { 060 super(java.util.ResourceBundle. 061 getBundle("jmri.jmrix.xpa.swing.XpaSwingBundle"). 062 getString("XpaMonFrameTitle"), XpaMonPane.class.getName()); 063 setContext(jmri.InstanceManager. 064 getDefault(XpaSystemConnectionMemo.class)); 065 } 066 } 067 068}