Exemple #1
0
  @Override
  public void addInterfaces(MainScreen parent, Node node) {

    String[] choices = {
      "5 Ethernet-TX ports simple switch.",
      "8 Ethernet-TX ports switch.",
      "12 Ethernet-TX ports switch.",
      "24 Ethernet-TX ports switch.",
      "12 Ethernet-TX ports with 2 Ethernet-FX switch.",
      "24 Ethernet-TX ports with 2 Ethernet-FX switch.",
      "12 Ethernet-FX ports with 2 Ethernet-TX switch.",
      "24 Ethernet-FX ports with 2 Ethernet-TX switch."
    };

    String choice =
        parent.getDeviceTypeDialog("Create new switch", "Please choose switch type", choices);

    int tx = 0, fx = 0;

    if (choice.contains(choices[0])) {
      tx = 5;
      fx = 0;
    } else if (choice.contains(choices[1])) {
      tx = 8;
      fx = 0;
    } else if (choice.contains(choices[2])) {
      tx = 12;
      fx = 0;
    } else if (choice.contains(choices[3])) {
      tx = 24;
      fx = 0;
    } else if (choice.contains(choices[4])) {
      tx = 12;
      fx = 2;
    } else if (choice.contains(choices[5])) {
      tx = 24;
      fx = 2;
    } else if (choice.contains(choices[6])) {
      tx = 2;
      fx = 12;
    } else if (choice.contains(choices[7])) {
      tx = 2;
      fx = 24;
    }

    for (int i = 0; i < tx; i++) {
      node.addNetworkInterface(
          core.NetworkInterface.getIntName(core.NetworkInterface.Ethernet10T) + String.valueOf(i),
          core.NetworkInterface.Ethernet10T,
          false);
    }

    for (int i = 0; i < fx; i++) {
      node.addNetworkInterface(
          core.NetworkInterface.getIntName(core.NetworkInterface.Ethernet100FX) + String.valueOf(i),
          core.NetworkInterface.Ethernet100FX,
          false);
    }
  }
  /**
   * Visualize node's location, radio ranges and connections
   *
   * @param g2 The graphic context to draw to
   */
  private void drawHost(Graphics2D g2) {
    Coord loc = node.getLocation();

    if (drawCoverage && node.isRadioActive()) {
      ArrayList<NetworkInterface> interfaces = new ArrayList<NetworkInterface>();
      interfaces.addAll(node.getInterfaces());
      for (NetworkInterface ni : interfaces) {
        double range = ni.getTransmitRange();
        Ellipse2D.Double coverage;

        coverage =
            new Ellipse2D.Double(
                scale(loc.getX() - range),
                scale(loc.getY() - range),
                scale(range * 2),
                scale(range * 2));

        // draw the "range" circle
        g2.setColor(rangeColor);
        g2.draw(coverage);
      }
    }

    if (drawConnections) {
      g2.setColor(conColor);
      Coord c1 = node.getLocation();
      ArrayList<Connection> conList = new ArrayList<Connection>();
      // create a copy to prevent concurrent modification exceptions
      conList.addAll(node.getConnections());
      for (Connection c : conList) {
        DTNHost otherNode = c.getOtherNode(node);
        Coord c2;

        if (otherNode == null) {
          continue; /* disconnected before drawn */
        }
        c2 = otherNode.getLocation();
        g2.drawLine(scale(c1.getX()), scale(c1.getY()), scale(c2.getX()), scale(c2.getY()));
      }
    }

    /* draw node rectangle */
    g2.setColor(hostColor);
    g2.drawRect(scale(loc.getX() - 1), scale(loc.getY() - 1), scale(2), scale(2));

    if (isHighlighted()) {
      g2.setColor(highlightedNodeColor);
      g2.fillRect(scale(loc.getX()) - 3, scale(loc.getY()) - 3, 6, 6);
    }

    if (drawNodeName) {
      g2.setColor(hostNameColor);
      // Draw node's address next to it
      g2.drawString(node.toString(), scale(loc.getX()), scale(loc.getY()));
    }
  }