001package jmri.jmrix.powerline.swing.serialmon; 002 003import jmri.jmrix.powerline.SerialListener; 004import jmri.jmrix.powerline.SerialMessage; 005import jmri.jmrix.powerline.SerialReply; 006import jmri.jmrix.powerline.SerialSystemConnectionMemo; 007import jmri.jmrix.powerline.swing.PowerlinePanelInterface; 008 009/** 010 * Swing action to create and register a MonFrame object. 011 * 012 * @author Bob Jacobsen Copyright (C) 2001, 2008 copied from Ecos and converted 013 * to Powerline 014 * @author Ken Cameron Copyright (C) 2011 015 */ 016public class SerialMonPane extends jmri.jmrix.AbstractMonPane implements SerialListener, PowerlinePanelInterface { 017 018 public SerialMonPane() { 019 super(); 020 } 021 022 @Override 023 public String getHelpTarget() { 024 return "package.jmri.jmrix.powerline.serialmon.SerialMonFrame"; 025 } 026 027 @Override 028 public String getTitle() { 029 StringBuilder x = new StringBuilder(); 030 if (memo != null) { 031 x.append(memo.getUserName()); 032 } else { 033 x.append(Bundle.getMessage("DefaultTag")); 034 } 035 x.append(": "); 036 x.append(Bundle.getMessage("Title")); 037 return x.toString(); 038 } 039 040 @Override 041 public void dispose() { 042 // disconnect from the SerialTrafficController 043 if (memo != null) { 044 memo.getTrafficController().removeSerialListener(this); 045 } 046 // and unwind swing 047 super.dispose(); 048 } 049 050 @Override 051 public void init() { 052 } 053 054 SerialSystemConnectionMemo memo; 055 056 @Override 057 public void initContext(Object context) { 058 if (context instanceof SerialSystemConnectionMemo) { 059 initComponents((SerialSystemConnectionMemo) context); 060 } 061 } 062 063 @Override 064 public void initComponents(SerialSystemConnectionMemo memo) { 065 this.memo = memo; 066 // connect to the SerialTrafficController 067 memo.getTrafficController().addSerialListener(this); 068 } 069 070 @Override 071 public synchronized void message(SerialMessage l) { // receive a message and log it 072 logMessage(l); 073 } 074 075 @Override 076 public synchronized void reply(SerialReply l) { // receive a reply message and log it 077 logMessage(l); 078 } 079 080}