Beispiel #1
1
  /** ************************************************************************** */
  public TracesSessions refreshTracesSessions() {
    TracesSessions retval = null;
    TracesSessions tss = new TracesSessions();
    String trace = null;
    try {
      if (this.logFile != null) {
        File file = new File(this.logFile);
        char[] cbuf = new char[(int) file.length()];
        FileReader fr = new FileReader(file);
        fr.read(cbuf);
        fr.close();
        trace = new String(cbuf);
      }
      // System.out.println("**** TRACE ******:\n"+trace+"\n");
      if (trace != null && !trace.equals("")) {
        LogFileParser parser = new LogFileParser();
        HashMap<String, MessageLogList> traces = parser.parseLogsFromString(trace);
        Enumeration<MessageLogList> elements = traces.elements();
        while (elements.hasMoreElements()) {
          MessageLogList mll = elements.nextElement();
          TracesSession ts = new TracesSession(mll);
          ts.setName(parser.logName);
          ts.setLogDescription(parser.logDescription);
          ts.setInfo(parser.auxInfo);
          tss.add(ts);
        }
        tss.setName(parser.logName);

        retval = tss;
      } else {
        TracesSession ts = new TracesSession();
        ts.setName("No available session, refresh");
        tss.add(ts);
        retval = tss;
      }
    } catch (Exception e) {
      System.out.println("*** Exception retrieving trace ***");
      e.printStackTrace();
      TracesSession ts = new TracesSession();
      ts.setName("No available session, refresh");
      tss.add(ts);
      retval = tss;
    }

    tracesSessions = retval;
    return tracesSessions;
  }
Beispiel #2
1
  /**
   * Call this constructor when you want to construct a visualizer from traces that you have already
   * read.
   *
   * @param titles is an array containing the titles for the traces.
   * @param traces is an array containing an array of XML Formatted traces.
   */
  public TracesViewer(
      HashMap<String, MessageLogList> traces,
      String logName,
      String logDescription,
      String auxInfo) {
    // System.out.println("**** TRACE ******:\n"+trace+"\n");
    TracesSessions tss = new TracesSessions();
    Enumeration<MessageLogList> elements = traces.elements();
    tss.setName(logName);
    logFile = logName;
    while (elements.hasMoreElements()) {
      MessageLogList mll = elements.nextElement();
      TracesSession ts = new TracesSession(mll);
      ts.setName(logName);
      ts.setInfo(auxInfo);
      ts.setLogDescription(logDescription);
      tss.add(ts);
    }

    listenerTracesViewer = new ListenerTracesViewer(this);

    // The order is important!!!!!
    // Look at the rmi registry for new traces
    // tracesSessions=refreshTracesSessions();
    this.tracesSessions = tss;
    this.standaloneViewer = true;
    initComponents();
    // Initialisation of the tracesSessionsList:
    tracesSessionsList.setTracesSessions(this.tracesSessions);
    // Initialisation of the Thread for the animations:
    animationThread = new TracesAnimationThread(tracesCanvas);

    // width, height
    this.setSize(670, 620);
    this.setLocation(0, 0);
  }
Beispiel #3
1
  // Constructor for the daemon only!!!!!
  public TracesViewer(
      String port,
      String logFile,
      HashMap<String, MessageLogList> traces,
      String logName,
      String logDescription,
      String auxInfo,
      String title,
      String back,
      String faces,
      String actors,
      String aLogoNist) {
    super(title);
    this.logFile = logFile;

    try {
      Toolkit toolkit = Toolkit.getDefaultToolkit();
      URL url = TracesViewer.class.getResource(back);
      backgroundImage = toolkit.getImage(url);
      url = TracesViewer.class.getResource(actors);
      actorsImage = toolkit.getImage(url);
      url = TracesViewer.class.getResource(faces);
      facesImage = toolkit.getImage(url);
      url = TracesViewer.class.getResource(aLogoNist);
      logoNist = toolkit.getImage(url);
    } catch (Exception e) {
      backgroundImage = null;
      actorsImage = null;
      facesImage = null;
      logoNist = null;
      System.out.println("Images are not loaded.");

      e.printStackTrace();
    }

    TracesSessions tss = new TracesSessions();
    tss.setName(logName);
    if (traces != null) {
      Enumeration elements = traces.elements();
      while (elements.hasMoreElements()) {
        MessageLogList mll = (MessageLogList) elements.nextElement();
        TracesSession ts = new TracesSession(mll);
        ts.setName(logName);
        ts.setInfo(auxInfo);
        ts.setLogDescription(logDescription);
        tss.add(ts);
      }
    }
    if (tss.isEmpty()) {
      TracesSession ts = new TracesSession();
      ts.setName("No available session, refresh");
      tss.add(ts);
    }

    listenerTracesViewer = new ListenerTracesViewer(this);

    this.tracesSessions = tss;
    initComponents();
    // Initialisation of the tracesSessionsList:
    tracesSessionsList.setTracesSessions(this.tracesSessions);
    // Initialisation of the Thread for the animations:
    animationThread = new TracesAnimationThread(tracesCanvas);

    // width, height
    this.setSize(670, 620);
    this.setLocation(0, 0);

    try {
      // Try to open a connection:
      TracesSocket ts = new TracesSocket(logFile, port);
      ts.start();
    } catch (Exception e) {
      e.printStackTrace();
    }
    this.setVisible(true);
  }
 public void setTracesSessions(TracesSessions tracesSessions) {
   sessionsList.removeAll();
   this.tracesSessions = tracesSessions;
   for (int i = 0; i < tracesSessions.size(); i++) {
     TracesSession tracesSession = tracesSessions.elementAt(i);
     String name = tracesSession.getName();
     // System.out.println("name:"+name);
     if (name.equals("No available session yet, click on refresh")) sessionsList.add(name);
     else {
       String trueName = getTrueName(name);
       sessionsList.add("Trace " + (i + 1) + " from " + trueName);
     }
   }
   if (tracesSessions.size() != 0) sessionsList.select(0);
 }
 // Item Listener stuff
 public void showMessages(ItemEvent e) {
   int index = 0;
   if (e != null) index = ((Integer) e.getItem()).intValue();
   allmessagesTextArea.setText("");
   TracesSession tS = tracesSessions.elementAt(index);
   for (int i = 0; i < tS.size(); i++) {
     TracesMessage tM = tS.elementAt(i);
     // allmessagesTextArea.setForeground(Color.red);
     // allmessagesTextArea.setFont(new Font ("Dialog", 1, 18));
     allmessagesTextArea.append(
         "Message " + (i + 1) + " from " + tM.getFrom() + " to " + tM.getTo());
     allmessagesTextArea.append("\n\n");
     // allmessagesTextArea.setForeground(Color.black);
     // allmessagesTextArea.setFont(new Font ("Dialog", 1, 14));
     allmessagesTextArea.append(tM.getMessageString());
     allmessagesTextArea.append("\n");
   }
   allmessagesTextArea.select(0, 0);
 }
Beispiel #6
0
  /** *********************************************************************** */
  private void initComponents() {

    /** ******************** The main container *************************** */
    Container container = this.getContentPane();
    container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
    // container.setLayout( new PercentLayout() );
    container.setBackground(Color.black);

    addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            System.out.println("Trace viewer closed!");
            // System.exit(0);
          }
        });

    /** ******************** Menu bar ************************************* */
    menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    // Build a second menu in the menu bar.
    optionsMenu = new JMenu("      Options      ");
    optionsMenu.setBorder(new BevelBorder(BevelBorder.RAISED));
    optionsMenu.setToolTipText("Some options related to the GUI");
    animationMenuItem = new JMenuItem("    Animation    ");
    animationMenuItem.setToolTipText("Animation of the entire selected session");
    animationMenuItem.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            listenerTracesViewer.animationActionPerformed(evt);
          }
        });
    optionsMenu.add(animationMenuItem);
    menuBar.add(optionsMenu);

    // create a menu and add it to the menubar
    displayAllSessionsMenu = new JMenu("    Display Sessions    ");
    displayAllSessionsMenu.setBorder(new BevelBorder(BevelBorder.RAISED));
    displayAllSessionsMenu.setToolTipText(
        "Display all the retrieved sessions in a separate windows");
    displayAllSessionsMenu.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent evt) {
            listenerTracesViewer.displayAllSessionsMouseEvent(evt);
          }
        });
    // add the Controls menu to the menu bar
    menuBar.add(displayAllSessionsMenu);

    // create a menu and add it to the menubar
    refreshMenu = new JMenu("   Refresh   ");
    refreshMenu.setBorder(new BevelBorder(BevelBorder.RAISED));
    refreshMenu.setBackground(new Color(51, 153, 255));
    refreshMenu.setToolTipText("Get the new traces");
    refreshMenu.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent evt) {
            listenerTracesViewer.refreshActionPerformed(evt);
          }
        });
    // add the Controls menu to the menu bar
    menuBar.add(refreshMenu);

    // ...create and add some menus...
    menuBar.add(Box.createHorizontalGlue());

    helpMenu = new JMenu("    Help    ");
    helpMenu.setBorder(new BevelBorder(BevelBorder.RAISED));
    helpMenu.setToolTipText("Some useful notes about this tool");
    helpMenu.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent evt) {
            listenerTracesViewer.helpMenuMouseEvent(evt);
          }
        });
    menuBar.add(helpMenu);

    aboutMenu = new JMenu("    About    ");
    aboutMenu.setBorder(new BevelBorder(BevelBorder.RAISED));
    aboutMenu.setToolTipText("Some advertises about the creators!");
    aboutMenu.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent evt) {
            listenerTracesViewer.aboutMenuMouseEvent(evt);
          }
        });
    menuBar.add(aboutMenu);

    quitMenu = new JMenu("    Quit    ");
    quitMenu.setBorder(new BevelBorder(BevelBorder.RAISED));
    quitMenu.setToolTipText("Quit the traces viewer");
    quitMenu.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent evt) {
            close();
          }
        });
    menuBar.add(quitMenu);

    /** ****************** FIRST PANEL ******************************* */
    firstPanel = new JPanel();
    // If put to False: we see the container's background
    firstPanel.setOpaque(false);
    firstPanel.setLayout(new PercentLayout());
    // firstPanel.setLayout(  new BorderLayout() );
    container.add(firstPanel);

    // Sub right panel:
    // topx %, topy %, width %, height % 73, 100-> 65, 95
    PercentLayoutConstraint firstPanelConstraint = new PercentLayoutConstraint(30, 0, 70, 100);
    tracesSessionsList = new TracesSessionsList();
    tracesSessionsList.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent e) {
            listenerTracesViewer.tracesSessionsListStateChanged(e);
          }
        });
    tracesSessionsList.setForeground(Color.black);
    tracesSessionsList.setFont(new Font("Dialog", 1, 14));

    ScrollPane scroll = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
    TracesSession tracesSession = tracesSessions.firstElement();
    String name = tracesSession.getName();
    String logDescription = tracesSession.getLogDescription();
    String callId = tracesSessionsList.getCallId(name);
    String origin = tracesSessionsList.getOrigin(name);

    // Warning: to put before for the canvas!!!!
    TextArea messageContentTextArea = new TextArea();
    messageContentButton = new JButton("SIP Message:");
    if (name.equals("No available session, refresh")) {
      tracesCanvas = new TracesCanvas(tracesSession, messageContentTextArea, "unknown", this);
    } else if (logDescription == null || logDescription.trim().equals("")) {
      tracesCanvas = new TracesCanvas(tracesSession, messageContentTextArea, origin, this);
    } else {
      //  System.out.println("logDesc44:"+logDescription);
      tracesCanvas = new TracesCanvas(tracesSession, messageContentTextArea, logDescription, this);
    }

    tracesSessionsList.setTracesCanvas(tracesCanvas);
    // The ScrollPane for the Canvas
    scroll.add(tracesCanvas);
    firstPanel.add(scroll, firstPanelConstraint);

    /** ************************* SECOND PANEL ******************************* */

    //  left panel:
    secondPanel = new JPanel();
    secondPanel.setBackground(Color.black);
    // rows, columns
    //  secondPanel.setLayout(new GridLayout(3,1,0,0) );
    secondPanel.setLayout(new BorderLayout());
    // topx %, topy %, width %, height %
    PercentLayoutConstraint secondPanelConstraint = new PercentLayoutConstraint(0, 0, 30, 100);
    firstPanel.add(secondPanel, secondPanelConstraint);

    /** **************************** FIRST SUB PANEL ********************************* */

    // Sub left panel:
    firstSubPanel = new JPanel();
    firstSubPanel.setBackground(Color.black);
    // Top, left, bottom, right
    firstSubPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 7, 5));

    if (!standaloneViewer) {
      // rows, columns, gap, gap
      firstSubPanel.setLayout(new GridLayout(2, 1, 3, 6));
      secondPanel.add(firstSubPanel, BorderLayout.NORTH);

      JPanel panelGrid = new JPanel();
      panelGrid.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
      panelGrid.setLayout(new GridLayout(2, 1, 0, 0));

      JPanel panelBox = new JPanel();
      panelBox.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
      panelBox.setLayout(new BorderLayout());

      JLabel scriptLabel = new JLabel("Display the event script:");
      scriptLabel.setToolTipText("Display the content of the selected script");

      scriptLabel.setHorizontalAlignment(SwingConstants.CENTER);
      scriptLabel.setForeground(Color.black);
      scriptLabel.setFont(new Font("Dialog", 1, 14));
      // If put to true: we see the label's background
      scriptLabel.setOpaque(true);
      panelGrid.add(scriptLabel);

      choice = new Choice();
      panelBox.add(choice, BorderLayout.CENTER);

      scriptButton = new JButton("Open");
      scriptButton.setToolTipText("Get the script controlling the current session");
      scriptButton.setFont(new Font("Dialog", 1, 14));
      scriptButton.setFocusPainted(false);
      scriptButton.setBackground(new Color(186, 175, 175));
      scriptButton.setBorder(new BevelBorder(BevelBorder.RAISED));
      scriptButton.setVerticalAlignment(SwingConstants.CENTER);
      scriptButton.setHorizontalAlignment(SwingConstants.CENTER);
      panelBox.add(scriptButton, BorderLayout.EAST);
      scriptButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
              listenerTracesViewer.scriptActionPerformed(evt);
            }
          });
      panelGrid.add(panelBox);
      firstSubPanel.add(panelGrid);
      // initComboBox();

      /*
      refreshButton=new JButton("Refresh");
      refreshButton.setToolTipText("Refresh all the sessions");
      refreshButton.setFont(new Font ("Dialog", 1, 14));
      refreshButton.setFocusPainted(false);
      //refreshButton.setBackground(new Color(186,175,175));
      refreshButton.setBackground( new Color(51,153,255));
      refreshButton.setBorder(new BevelBorder(BevelBorder.RAISED));
      refreshButton.setVerticalAlignment(AbstractButton.CENTER);
      refreshButton.setHorizontalAlignment(AbstractButton.CENTER);
      firstSubPanel.add(refreshButton);
      refreshButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
               listenerTracesViewer.refreshActionPerformed(evt);
         }
      }
      );
       */
      ImageIcon icon;
      if (logoNist != null) {
        icon = new ImageIcon(logoNist);

        JLabel label = new JLabel(icon);
        label.setVisible(true);
        label.setToolTipText("The NIST logo!!!");
        // label.setHorizontalAlignment(AbstractButton.CENTER);
        label.setForeground(Color.black);
        // label.setFont(new Font ("Dialog", 1, 14));
        label.setOpaque(false);
        firstSubPanel.add(label);
      }
    } else {
      // rows, columns, gap, gap
      firstSubPanel.setLayout(new GridLayout(1, 1, 3, 6));
      secondPanel.add(firstSubPanel, BorderLayout.NORTH);

      ImageIcon icon;
      if (logoNist != null) {
        icon = new ImageIcon(logoNist);
        JLabel label = new JLabel(icon);
        label.setVisible(true);
        label.setToolTipText("The NIST logo!!!");
        label.setHorizontalAlignment(SwingConstants.CENTER);
        label.setForeground(Color.black);
        label.setFont(new Font("Dialog", 1, 14));
        label.setOpaque(false);
        firstSubPanel.add(label);
      }
    }

    /** **************** SECOND SUB PANEL *************************************** */
    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(2, 1, 0, 0));
    secondPanel.add(panel, BorderLayout.CENTER);
    secondSubPanel = new JPanel();
    secondSubPanel.setBackground(Color.black);
    secondSubPanel.setLayout(new BorderLayout());
    // secondPanel.add(secondSubPanel);
    panel.add(secondSubPanel);

    sessionsLabel = new JLabel("Sessions available:");
    sessionsLabel.setToolTipText("All the sessions currently available");
    // Alignment of the text
    sessionsLabel.setHorizontalAlignment(SwingConstants.CENTER);
    // Color of the text
    sessionsLabel.setForeground(Color.black);
    // Size of the text
    sessionsLabel.setFont(new Font("Dialog", 1, 14));
    // If put to true: we see the label's background
    sessionsLabel.setOpaque(true);
    sessionsLabel.setBackground(Color.lightGray);
    sessionsLabel.setBorder(BorderFactory.createLineBorder(Color.darkGray));
    secondSubPanel.add(sessionsLabel, BorderLayout.NORTH);

    ScrollPane scrollList = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
    scrollList.add(tracesSessionsList);
    // secondSubPanel.add(scrollList,BorderLayout.CENTER);
    secondSubPanel.add(tracesSessionsList, BorderLayout.CENTER);

    /** ****************** THIRD SUB PANEL *************************************** */
    thirdSubPanel = new JPanel();
    thirdSubPanel.setBackground(Color.black);
    thirdSubPanel.setLayout(new BorderLayout());
    // secondPanel.add(thirdSubPanel);
    panel.add(thirdSubPanel);

    messageContentButton.setToolTipText("Display all the content of the current SIP message");
    // Alignment of the text
    messageContentButton.setHorizontalAlignment(SwingConstants.CENTER);
    // Color of the text
    messageContentButton.setForeground(Color.black);
    // Size of the text
    messageContentButton.setFont(new Font("Dialog", 1, 14));
    // If put to true: we see the label's background
    messageContentButton.setOpaque(true);
    messageContentButton.setBackground(Color.lightGray);
    messageContentButton.setBorder(BorderFactory.createLineBorder(Color.darkGray));
    messageContentButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            listenerTracesViewer.debugActionPerformed(evt);
          }
        });
    messageContentTextArea.setBackground(Color.white);
    messageContentTextArea.setEditable(false);
    messageContentTextArea.setFont(new Font("Dialog", 1, 12));
    messageContentTextArea.setForeground(Color.black);
    thirdSubPanel.add(messageContentButton, BorderLayout.NORTH);
    thirdSubPanel.add(messageContentTextArea, BorderLayout.CENTER);

    validateTree();
  }