001: package tools.tracesviewer;
002:
003: import javax.swing.*;
004: import javax.swing.border.*;
005: import java.awt.*;
006: import java.awt.event.*;
007:
008: public class TracesSessionsDisplayer extends javax.swing.JFrame {
009:
010: public TracesSessions tracesSessions;
011: public TextArea allmessagesTextArea;
012: public List sessionsList;
013:
014: public JPanel mainPanel;
015: public JButton okButton;
016:
017: public TracesSessionsDisplayer() {
018: super ("Sessions Displayer");
019: this .tracesSessions = null;
020: initComponents();
021: }
022:
023: public void initComponents() {
024: /********************** The main container ****************************/
025:
026: Container container = this .getContentPane();
027: container.setLayout(new BorderLayout());
028: container.setBackground(Color.black);
029: this .setSize(650, 600);
030: this .addWindowListener(new WindowAdapter() {
031: public void windowClosing(WindowEvent e) {
032:
033: }
034: });
035:
036: /*************************** MAIN PANEL ********************************/
037:
038: mainPanel = new JPanel();
039: // If put to False: we see the container's background
040: mainPanel.setOpaque(false);
041: mainPanel.setLayout(new BorderLayout());
042: container.add(mainPanel, BorderLayout.CENTER);
043:
044: allmessagesTextArea = new TextArea();
045: allmessagesTextArea.setEditable(false);
046: allmessagesTextArea.setFont(new Font("Dialog", 1, 12));
047: allmessagesTextArea.setForeground(Color.black);
048: allmessagesTextArea
049: .append("Select a session in the list to view its messages");
050: mainPanel.add(allmessagesTextArea, BorderLayout.CENTER);
051:
052: sessionsList = new List();
053: sessionsList.addItemListener(new ItemListener() {
054: public void itemStateChanged(ItemEvent e) {
055: showMessages(e);
056: }
057: });
058: sessionsList.setForeground(Color.black);
059: sessionsList.setFont(new Font("Dialog", 1, 14));
060: mainPanel.add(sessionsList, BorderLayout.WEST);
061:
062: okButton = new JButton(" OK ");
063: okButton.setToolTipText("Returns to the main frame");
064: okButton.setFont(new Font("Dialog", 1, 16));
065: okButton.setFocusPainted(false);
066: okButton.setBackground(Color.lightGray);
067: okButton.setBorder(new BevelBorder(BevelBorder.RAISED));
068: okButton.setVerticalAlignment(AbstractButton.CENTER);
069: okButton.setHorizontalAlignment(AbstractButton.CENTER);
070: container.add(okButton, BorderLayout.SOUTH);
071: okButton.addActionListener(new ActionListener() {
072: public void actionPerformed(ActionEvent evt) {
073: hide();
074: }
075: });
076: }
077:
078: public static String getTrueName(String name) {
079: try {
080: int firstIndex = name.indexOf("//");
081: int secondIndex = name.indexOf("/", 2);
082: String fakeName = name.substring(2, secondIndex);
083: if (fakeName.equals(TracesViewer.stackId))
084: return "the proxy";
085: else
086: return "a user agent (" + fakeName + ")";
087: } catch (Exception e) {
088: return "unknown";
089: }
090: }
091:
092: public void setTracesSessions(TracesSessions tracesSessions) {
093: sessionsList.removeAll();
094: this .tracesSessions = tracesSessions;
095: for (int i = 0; i < tracesSessions.size(); i++) {
096: TracesSession tracesSession = (TracesSession) tracesSessions
097: .elementAt(i);
098: String name = tracesSession.getName();
099: //System.out.println("name:"+name);
100: if (name
101: .equals("No available session yet, click on refresh"))
102: sessionsList.add(name);
103: else {
104: String trueName = getTrueName(name);
105: sessionsList.add("Trace " + (i + 1) + " from "
106: + trueName);
107: }
108: }
109: if (tracesSessions.size() != 0)
110: sessionsList.select(0);
111: }
112:
113: // Item Listener stuff
114: public void showMessages(ItemEvent e) {
115: int index = 0;
116: if (e != null)
117: index = ((Integer) e.getItem()).intValue();
118: allmessagesTextArea.setText("");
119: TracesSession tS = (TracesSession) tracesSessions
120: .elementAt(index);
121: for (int i = 0; i < tS.size(); i++) {
122: TracesMessage tM = (TracesMessage) tS.elementAt(i);
123: //allmessagesTextArea.setForeground(Color.red);
124: //allmessagesTextArea.setFont(new Font ("Dialog", 1, 18));
125: allmessagesTextArea.append("Message " + (i + 1) + " from "
126: + tM.getFrom() + " to " + tM.getTo());
127: allmessagesTextArea.append("\n\n");
128: //allmessagesTextArea.setForeground(Color.black);
129: //allmessagesTextArea.setFont(new Font ("Dialog", 1, 14));
130: allmessagesTextArea.append(tM.getMessageString());
131: allmessagesTextArea.append("\n");
132: }
133: allmessagesTextArea.select(0, 0);
134: }
135:
136: public void show(TracesSessions tracesSessions) {
137: //System.out.println("tracesSessions:"+tracesSessions);
138: this .tracesSessions = tracesSessions;
139: setTracesSessions(tracesSessions);
140: showMessages(null);
141: this .setVisible(true);
142: }
143:
144: }
|