001 package toolbus; 002 003 import java.awt.BorderLayout; 004 import java.awt.Container; 005 import java.awt.GridLayout; 006 import java.awt.event.ActionEvent; 007 import java.awt.event.ActionListener; 008 009 import javax.swing.JButton; 010 import javax.swing.JFrame; 011 import javax.swing.JPanel; 012 import javax.swing.WindowConstants; 013 014 public class DebugConsole{ 015 private final ToolBus toolbus; 016 017 private final ButtonListener buttonListener; 018 019 private JFrame frame; 020 021 private final JButton unhandledMessages; 022 private final JButton performanceStats; 023 private final JButton toolsStatus; 024 private final JButton queuedMessages; 025 private final JButton toolbusState; 026 private final JButton partnerlessStuff; 027 private final JButton shutdown; 028 029 public DebugConsole(ToolBus toolbus){ 030 super(); 031 032 this.toolbus = toolbus; 033 034 buttonListener = new ButtonListener(); 035 036 frame = new JFrame(); 037 038 unhandledMessages = new JButton("Unhandled Messages"); 039 performanceStats = new JButton("Performance Stats"); 040 toolsStatus = new JButton("Tools Status"); 041 queuedMessages = new JButton("Queued Messages"); 042 toolbusState = new JButton("Toolbus State"); 043 partnerlessStuff = new JButton("Partnerless Stuff"); 044 shutdown = new JButton("Shut Down & Die"); 045 046 layout(); 047 } 048 049 private void layout(){ 050 JPanel buttonPanel = new JPanel(); 051 buttonPanel.setLayout(new GridLayout(2, 3)); 052 unhandledMessages.addActionListener(buttonListener); 053 buttonPanel.add(unhandledMessages); 054 performanceStats.addActionListener(buttonListener); 055 buttonPanel.add(performanceStats); 056 toolsStatus.addActionListener(buttonListener); 057 buttonPanel.add(toolsStatus); 058 queuedMessages.addActionListener(buttonListener); 059 buttonPanel.add(queuedMessages); 060 toolbusState.addActionListener(buttonListener); 061 buttonPanel.add(toolbusState); 062 partnerlessStuff.addActionListener(buttonListener); 063 buttonPanel.add(partnerlessStuff); 064 065 Container frameContent = frame.getContentPane(); 066 frameContent.setLayout(new BorderLayout()); 067 068 frameContent.add(buttonPanel, BorderLayout.CENTER); 069 shutdown.addActionListener(buttonListener); 070 frameContent.add(shutdown, BorderLayout.SOUTH); 071 072 frame.setSize(600, 400); 073 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 074 } 075 076 public void show(){ 077 frame.setVisible(true); 078 } 079 080 private class ButtonListener implements ActionListener{ 081 082 public ButtonListener(){ 083 super(); 084 } 085 086 public void actionPerformed(ActionEvent e){ 087 Object source = e.getSource(); 088 if(source == unhandledMessages){ 089 toolbus.dumpUnhandledMessages(); 090 }else if(source == performanceStats){ 091 toolbus.dumpPerformanceStats(); 092 }else if(source == toolsStatus){ 093 toolbus.getToolInstanceManager().showStatus(); 094 }else if(source == queuedMessages){ 095 toolbus.getToolInstanceManager().printQueueTerms(); 096 }else if(source == toolbusState){ 097 toolbus.showStatus(); 098 }else if(source == partnerlessStuff){ 099 toolbus.getMatchStore().printPartnerlessCommunicationAtoms(); 100 }else if(source == shutdown){ 101 toolbus.shutdown(toolbus.getTBTermFactory().makeList()); 102 System.exit(0); 103 } 104 } 105 } 106 }