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