Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package tools.tracesviewer;
  
  import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  
  public class TracesSessionsDisplayer extends javax.swing.JFrame {
  
     public TracesSessions tracesSessions;
     public TextArea allmessagesTextArea;
     public List sessionsList;
 
     public JPanel mainPanel;
     public JButton okButton;
 
     public TracesSessionsDisplayer() {
         super("Sessions Displayer");
         this. = null;
         initComponents();
     }
 
     public void initComponents() {
        
The main container **************************
 
 
         Container container = this.getContentPane();
         container.setLayout(new BorderLayout());
         container.setBackground(.);
         this.setSize(650, 600);
         this.addWindowListener(new WindowAdapter() {
             public void windowClosing(WindowEvent e) {
 
             }
         });

        
MAIN PANEL ******************************
 
 
          = new JPanel();
         // If put to False: we see the container's background
         .setOpaque(false);
         .setLayout(new BorderLayout());
         container.add(.);
 
          = new TextArea();
         .setEditable(false);
         .setFont(new Font("Dialog", 1, 12));
         .append(
             "Select a session in the list to view its messages");
 
          = new List();
         .addItemListener(new ItemListener() {
             public void itemStateChanged(ItemEvent e) {
                 showMessages(e);
             }
         });
         .setFont(new Font("Dialog", 1, 14));
 
          = new JButton("  OK  ");
         .setToolTipText("Returns to the main frame");
         .setFont(new Font("Dialog", 1, 16));
         .setFocusPainted(false);
         container.add(.);
         .addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent evt) {
                 hide();
             }
         });
     }
 
     public static String getTrueName(String name) {
         try {
             int firstIndex = name.indexOf("//");
             int secondIndex = name.indexOf("/", 2);
             String fakeName = name.substring(2, secondIndex);
             if (fakeName.equals(.))
                 return "the proxy";
             else
                 return "a user agent (" + fakeName + ")";
         } catch (Exception e) {
             return "unknown";
         }
     }
 
     public void setTracesSessions(TracesSessions tracesSessions) {
         .removeAll();
         this. = tracesSessions;
         for (int i = 0; i < tracesSessions.size(); i++) {
             TracesSession tracesSession =
                 (TracesSessiontracesSessions.elementAt(i);
             String name = tracesSession.getName();
             //System.out.println("name:"+name);
            if (name.equals("No available session yet, click on refresh"))
                .add(name);
            else {
                String trueName = getTrueName(name);
                .add("Trace " + (i + 1) + " from " + trueName);
            }
        }
        if (tracesSessions.size() != 0)
            .select(0);
    }
    // Item Listener stuff
    public void showMessages(ItemEvent e) {
        int index = 0;
        if (e != null)
            index = ((Integere.getItem()).intValue();
        .setText("");
        TracesSession tS = (TracesSession.elementAt(index);
        for (int i = 0; i < tS.size(); i++) {
            TracesMessage tM = (TracesMessagetS.elementAt(i);
            //allmessagesTextArea.setForeground(Color.red);
            //allmessagesTextArea.setFont(new Font ("Dialog", 1, 18));
            .append(
                "Message "
                    + (i + 1)
                    + " from "
                    + tM.getFrom()
                    + " to "
                    + tM.getTo());
            .append("\n\n");
            //allmessagesTextArea.setForeground(Color.black);
            //allmessagesTextArea.setFont(new Font ("Dialog", 1, 14));
            .append(tM.getMessageString());
            .append("\n");
        }
        .select(0, 0);
    }
    public void show(TracesSessions tracesSessions) {
        //System.out.println("tracesSessions:"+tracesSessions);
        this. = tracesSessions;
        setTracesSessions(tracesSessions);
        showMessages(null);
        this.setVisible(true);
    }
New to GrepCode? Check out our FAQ X