001package jmri.jmrix.tams.swing.statusframe; 002 003import javax.swing.BoxLayout; 004import javax.swing.JButton; 005import javax.swing.JLabel; 006import jmri.jmrix.tams.TamsListener; 007import jmri.jmrix.tams.TamsMessage; 008import jmri.jmrix.tams.TamsReply; 009import jmri.jmrix.tams.TamsSystemConnectionMemo; 010import jmri.jmrix.tams.TamsTrafficController; 011 012/** 013 * Panel to show TAMS status. 014 * 015 * Based on work by Bob Jacobsen 016 * 017 * @author Kevin Dickerson Copyright (C) 2012 018 */ 019public class StatusPanel extends jmri.jmrix.tams.swing.TamsPanel implements TamsListener { 020 021 String appString = Bundle.getMessage("ApplicationVersionLabel"); 022 String serString = Bundle.getMessage("SerialNumberLabel"); 023 JLabel appVersion = new JLabel(appString + Bundle.getMessage("StateUnknown")); // "<unknown>" 024 JLabel serVersion = new JLabel(serString + Bundle.getMessage("StateUnknown")); 025 026 JButton sendButton; 027 028 public StatusPanel() { 029 super(); 030 } 031 032 @Override 033 public void initComponents(TamsSystemConnectionMemo memo) { 034 super.initComponents(memo); 035 //memo.getTrafficController().addTamsListener(this); 036 tc = memo.getTrafficController(); 037 // Create GUI 038 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 039 add(appVersion); 040 add(serVersion); 041 042 // ask to be notified 043 TamsMessage m = new TamsMessage("xV"); 044 tc.sendTamsMessage(m, this); 045 046 sendButton = new JButton(Bundle.getMessage("ButtonUpdate")); 047 sendButton.setVisible(true); 048 sendButton.setToolTipText(Bundle.getMessage("ButtonUpdateToolTip")); 049 050 add(sendButton); 051 sendButton.addActionListener(new java.awt.event.ActionListener() { 052 @Override 053 public void actionPerformed(java.awt.event.ActionEvent e) { 054 sendButtonActionPerformed(e); 055 } 056 }); 057 } 058 059 void reset() { 060 appVersion.setText(appString + Bundle.getMessage("StateUnknown")); 061 } 062 063 // to free resources when no longer used 064 @Override 065 public void dispose() { 066 tc.removeTamsListener(this); 067 tc = null; 068 } 069 070 public void sendButtonActionPerformed(java.awt.event.ActionEvent e) { 071 reset(); 072 TamsMessage m = new TamsMessage("xV"); 073 tc.sendTamsMessage(m, this); 074 } 075 076 TamsTrafficController tc; 077 078 // to listen for status changes from Tams system 079 @Override 080 public void reply(TamsReply m) { 081 // power message? 082 String msg = m.toString(); 083 String[] version = msg.split("\\r"); 084 appVersion.setText(appString + version[0]); 085 serVersion.setText(serString + version[1]); 086 } 087 088 @Override 089 public void message(TamsMessage m) { 090 // messages are ignored 091 } 092 093 /** 094 * {@inheritDoc} 095 */ 096 @Override 097 public String getTitle() { 098 return Bundle.getMessage("MenuItemInfo"); 099 } 100 101}