001package jmri.jmrix.tams.swing.monitor; 002 003import javax.swing.JCheckBox; 004import javax.swing.JPanel; 005import jmri.jmrix.tams.TamsListener; 006import jmri.jmrix.tams.TamsMessage; 007import jmri.jmrix.tams.TamsReply; 008import jmri.jmrix.tams.TamsSystemConnectionMemo; 009import jmri.jmrix.tams.swing.TamsPanelInterface; 010 011/** 012 * Swing action to create and register a MonFrame object. 013 * 014 * Based on work by Bob Jacobsen 015 * 016 * @author Kevin Dickerson Copyright (C) 2012 017 */ 018public class TamsMonPane extends jmri.jmrix.AbstractMonPane implements TamsListener, TamsPanelInterface { 019 020 public TamsMonPane() { 021 super(); 022 } 023 024 @Override 025 public String getHelpTarget() { 026 return null; 027 } 028 029 @Override 030 public String getTitle() { 031 return Bundle.getMessage("CommandMonitor"); 032 } 033 034 @Override 035 public void dispose() { 036 // disconnect from the TamsTrafficController 037 memo.getTrafficController().removeTamsListener(this); 038 // and unwind swing 039 super.dispose(); 040 } 041 042 @Override 043 public void init() { 044 } 045 046 TamsSystemConnectionMemo memo; 047 048 JCheckBox disablePollingCheckBox = new JCheckBox(); 049 050 @Override 051 public void initContext(Object context) { 052 if (context instanceof TamsSystemConnectionMemo) { 053 initComponents((TamsSystemConnectionMemo) context); 054 } 055 } 056 057 @Override 058 public void initComponents(TamsSystemConnectionMemo memo) { 059 this.memo = memo; 060 // connect to the TamsTrafficController 061 memo.getTrafficController().addTamsListener(this); 062 disablePollingCheckBox.setSelected(memo.getTrafficController().getPollQueueDisabled()); 063 } 064 065 @Override 066 public void initComponents() { 067 super.initComponents(); 068 JPanel check = new JPanel(); 069 disablePollingCheckBox.setText(Bundle.getMessage("DisablePollingBoxLabel")); 070 disablePollingCheckBox.setVisible(true); 071 disablePollingCheckBox.setToolTipText(Bundle.getMessage("DisablePollingToolTip")); 072 disablePollingCheckBox.addActionListener(new java.awt.event.ActionListener() { 073 @Override 074 public void actionPerformed(java.awt.event.ActionEvent e) { 075 if (memo != null) { 076 memo.getTrafficController().setPollQueueDisabled(disablePollingCheckBox.isSelected()); 077 } 078 } 079 }); 080 check.add(disablePollingCheckBox); 081 add(check); 082 } 083 084 @Override 085 public synchronized void message(TamsMessage tm) { // receive a message and log it 086 if (tm.isBinary()) { 087 logMessage("Binary cmd: ", tm); 088 } else { 089 logMessage("ASCII cmd: ", tm); 090 } 091 } 092 093 @Override 094 public synchronized void reply(TamsReply l) { // receive a reply message and log it 095 String raw = ""; 096 for (int i = 0; i < l.getNumDataElements(); i++) { 097 if (i > 0) { 098 raw += " "; 099 } 100 raw = jmri.util.StringUtil.appendTwoHexFromInt(l.getElement(i) & 0xFF, raw); 101 } 102 if (l.isUnsolicited()) { 103 logMessage("msg: ", l); 104 } else { 105 if (l.isBinary()){ 106 logMessage("Binary rep: ", l); 107 } else { 108 logMessage("ASCII rep: " , l); 109 } 110 } 111 } 112 113}