示例#1
0
  /** Creates the control widgets. */
  void createControlWidgets() {
    /* Controls the type of Throughput */
    // GridData gridData=new GridData(GridData.FILL_HORIZONTAL);

    Label filterByLabel = new Label(controlGroup, SWT.None);
    filterByLabel.setText(Analyze.getResourceString("Filter by"));
    filterByLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));

    filterByCombo = new Combo(controlGroup, SWT.READ_ONLY);
    filterByCombo.setItems(new String[] {"Node ID", "Label ID"});
    filterByCombo.select(0);
    /* Add listener */
    filterByCombo.addSelectionListener(
        new SelectionListener() {
          public void widgetSelected(SelectionEvent e) {
            // System.out.println(filterByCombo.getSelectionIndex());
            setItemFromComboToCombo();
          }

          public void widgetDefaultSelected(SelectionEvent e) {
            // System.out.println("nghia");
          }
        });

    Label fromLabel = new Label(controlGroup, SWT.None);
    fromLabel.setText(Analyze.getResourceString("From"));
    fromLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));

    fromCombo = new Combo(controlGroup, SWT.READ_ONLY);

    Label toLabel = new Label(controlGroup, SWT.None);
    toLabel.setText(Analyze.getResourceString("To"));
    toLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));

    toCombo = new Combo(controlGroup, SWT.READ_ONLY);
    setItemFromComboToCombo();

    analyze = new Button(controlGroup, SWT.PUSH);
    analyze.setText(Analyze.getResourceString("Analyze"));
    analyze.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));

    Button analyzeGroup = new Button(controlGroup, SWT.PUSH);
    analyzeGroup.setText(Analyze.getResourceString("Analyze Group"));
    analyzeGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));

    /* Add listener to button analyze group */
    analyzeGroup.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            if (listNodeAreaDest.size() > 0 && listNodeAreaSource.size() > 0) {
              setUpInfoGroupHopCount();
            }
          }
        });

    /* Add listener to add an element to the table */
    analyze.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            if (fromCombo.getSelectionIndex() == -1 || toCombo.getSelectionIndex() == -1) {
              MessageBox dialog = new MessageBox(new Shell(), SWT.ICON_QUESTION | SWT.OK);
              dialog.setText("Error");
              dialog.setMessage("Let choose source node and destination node!");
              dialog.open();
            } else {
              table.removeAll();
              int No = 1;
              int maxHopCount = 0;
              int minHopCount = 1000000000;
              double totalHopCount = 0;
              double totalTime = 0;
              LinkedHashMap<Packet, Integer> listHopCountPacket =
                  new LinkedHashMap<Packet, Integer>();
              ArrayList<Packet> listPacket = new ArrayList<Packet>();
              for (int i = 0; i < Analyze.mParser.getListPacket().size(); i++) {
                Packet packet = Analyze.mParser.getListPacket().get(i);

                if (!fromCombo.getItem(fromCombo.getSelectionIndex()).equals("All nodes")
                    && !toCombo.getItem(toCombo.getSelectionIndex()).equals("All nodes")) {
                  if (fromCombo.getItem(fromCombo.getSelectionIndex()).equals((packet.sourceID))
                      && toCombo.getItem(toCombo.getSelectionIndex()).equals((packet.destID))
                      && packet.isSuccess) {
                    listPacket.add(packet);
                  }
                }
                if (!fromCombo.getItem(fromCombo.getSelectionIndex()).equals("All nodes")
                    && toCombo.getItem(toCombo.getSelectionIndex()).equals("All nodes")) {
                  if (fromCombo.getItem(fromCombo.getSelectionIndex()).equals((packet.sourceID))
                      && packet.isSuccess) {
                    listPacket.add(packet);
                  }
                }
                if (fromCombo.getItem(fromCombo.getSelectionIndex()).equals("All nodes")
                    && !toCombo.getItem(toCombo.getSelectionIndex()).equals("All nodes")) {
                  if (toCombo.getItem(toCombo.getSelectionIndex()).equals((packet.destID))
                      && packet.isSuccess) {
                    listPacket.add(packet);
                  }
                }
                if (fromCombo.getItem(fromCombo.getSelectionIndex()).equals("All nodes")
                    && toCombo.getItem(toCombo.getSelectionIndex()).equals("All nodes")) {
                  if (packet.isSuccess) {
                    listPacket.add(packet);
                  }
                }
              }
              for (int i = 0; i < listPacket.size(); i++) {
                Packet packet = listPacket.get(i);
                TableItem tableItem = new TableItem(table, SWT.NONE);
                tableItem.setText(0, Integer.toString(No++));
                tableItem.setText(1, packet.id);
                tableItem.setText(2, Integer.toString(packet.listNode.size() - 1));
                tableItem.setText(3, packet.sourceID + "---" + packet.destID);
                totalHopCount += packet.listNode.size() - 1;
                totalTime +=
                    (Double.parseDouble(packet.endTime) - Double.parseDouble(packet.startTime));
                listHopCountPacket.put(packet, packet.listNode.size() - 1);

                if (maxHopCount < packet.listNode.size() - 1)
                  maxHopCount = packet.listNode.size() - 1;
                if (minHopCount > packet.listNode.size() - 1)
                  minHopCount = packet.listNode.size() - 1;
              }
              if (No == 1) {
                MessageBox dialog = new MessageBox(new Shell(), SWT.ICON_QUESTION | SWT.OK);
                dialog.setText("Error");
                dialog.setMessage(
                    "No packet from node "
                        + fromCombo.getItem(fromCombo.getSelectionIndex())
                        + " to node "
                        + toCombo.getItem(toCombo.getSelectionIndex())
                        + "!");
                dialog.open();
                avgText.setText("0");
                variantText.setText("0");
                maxText.setText("0");
                minText.setText("0");
                xSeries = new double[0];
                ySeries = new double[0];
              } else {
                DecimalFormat df = new DecimalFormat("0.00");
                // System.out.println(No-1);
                String str = df.format(totalHopCount / (No - 1));
                // set mean
                avgText.setText(str);
                // set text variant
                variantText.setText(df.format(variancesHopCount(listHopCountPacket, totalTime)));
                maxText.setText(Integer.toString(maxHopCount));
                minText.setText(Integer.toString(minHopCount));
                // init line chart
                initXYseries(listHopCountPacket);
              }
              if (filterByCombo.getSelectionIndex() == 0) resetEditors();
            }
          }
        });

    /* Add common controls */
    super.createControlWidgets();
  }