コード例 #1
0
  @Override
  public void mouseMoved(MouseEvent mouse) {
    // if an insertion mode is activated. Draw temp node for the user.
    if (machineMode.isSelected()) {
      if (!(cursorNode instanceof Machine))
        cursorNode =
            new Machine(
                "",
                cap(mouse.getX() - 10, 70, getWidth() - 90),
                cap(mouse.getY() - 10, 120, getHeight() - 90));

      cursorNode.x = cap(mouse.getX() - 10, 70, getWidth() - 90);
      cursorNode.y = cap(mouse.getY() - 10, 120, getHeight() - 90);
    } else if (primaryMode.isSelected()) {
      if (!(cursorNode instanceof Primary))
        cursorNode =
            new Primary(
                "",
                cap(mouse.getX() - 10, 70, getWidth() - 90),
                cap(mouse.getY() - 10, 120, getHeight() - 90));

      cursorNode.x = cap(mouse.getX() - 10, 70, getWidth() - 90);
      cursorNode.y = cap(mouse.getY() - 10, 120, getHeight() - 90);

    } else {
      cursorNode = null;
    }

    repaint();
  }
コード例 #2
0
ファイル: Layouter.java プロジェクト: vohoaiviet/metanet
  public void layoutTimeline() {
    net.clearClusters();
    Collection<Float> time = net.timeTable.values();
    if (time.size() == 0) return;
    TreeSet<Float> b = new TreeSet<Float>();
    b.addAll(time);
    Float midpoint = (b.last() - b.first()) / 2f + b.first();
    HashMap<Float, Integer> counter = new HashMap<Float, Integer>();

    for (Node n : net.nNodes) {
      Float t = n.getTime();
      if (t != null) {
        n.pos.setX((t - midpoint) * 100f);
        if (counter.containsKey(t)) {
          Integer numOccurancesAtT = counter.get(t);
          n.pos.y = numOccurancesAtT * app.getNodeSize() * 5f;
          numOccurancesAtT++;
          counter.put(t, numOccurancesAtT);
        } else {
          counter.put(t, 1);
          n.pos.y = 0f;
        }
      }
    }
  }
コード例 #3
0
ファイル: Layouter.java プロジェクト: vohoaiviet/metanet
 private float calcDist(Node a, Node b, float offset, float val) {
   float factor = 1 + .5f * (Edge.edgeName(a, b).hashCode() / Integer.MAX_VALUE);
   float vprod = Math.min(a.getiDegree(), b.getiDegree());
   // float vprod = a.getiDegree()*b.getiDegree();
   float clusterdist = calcClusterDistance(a) + calcClusterDistance(b);
   //		return 10f;
   return factor * (clusterdist + offset * (1 + vprod * val));
 }
コード例 #4
0
 @Override
 public void mouseDragged(MouseEvent mouse) {
   if (visualizeButton.isSelected()) return;
   if (selectedNode != null) {
     selectedNode.x = cap(mouse.getX() - offX, 70, getWidth() - 100);
     selectedNode.y = cap(mouse.getY() - offY, 160, getHeight() - 120);
   }
   repaint();
 }
コード例 #5
0
ファイル: Layouter.java プロジェクト: vohoaiviet/metanet
 public void layoutNodePosPlace() {
   for (Node n : net.fNodes) {
     float randPos = net.fNodes.size() * 10f + 50f;
     n.pos.setXYZ(
         Integer.MAX_VALUE / (float) n.getId(),
         Integer.MAX_VALUE / ((float) String.valueOf(n.getId() + 3).hashCode()),
         Func.rnd(-randPos, randPos));
   }
 }
コード例 #6
0
ファイル: Node.java プロジェクト: Herringway/ExamScheduler
  @Override
  public int compareTo(Node otherNode) {
    if (this.degree < otherNode.getDegree()) {
      return 1;
    } else if (this.degree > otherNode.getDegree()) {
      return -1;
    }

    return 0;
  }
コード例 #7
0
ファイル: Layouter.java プロジェクト: vohoaiviet/metanet
  /**
   * calculate node color based on gradient and level
   *
   * @param level
   * @param m
   */
  void setNodeColor(int level, Node m) {
    float[] nodeHSV = new float[3];
    nodeHSV = Func.RGBtoHSV(app.pickGradEnd);
    float[] pickHSV = new float[3];
    pickHSV = Func.RGBtoHSV(app.pickGradStart);

    if (m.hasAttribute("color")) m.setColor(Func.parseColorInt(m.getAttribute("color"), 16));
    else {
      float[] color = Func.colorGrad(level, nodeHSV, pickHSV);
      m.setColor(color);
    }
  }
コード例 #8
0
ファイル: Layouter.java プロジェクト: vohoaiviet/metanet
  private float calcClusterDistance(Node n) {
    if (n.cluster.size() == 0) return n.size() / 2f;

    float x;
    if (n.spiralcluster) x = spiral_rad(n, n.cluster.size());
    else x = circle_rad(n, n.cluster.size());

    return x;
  }
コード例 #9
0
  @Override
  public void mouseReleased(MouseEvent mouse) {
    //		if(visualizeButton.isSelected())return;

    if (selectionMode.isSelected()) {
      if (selectedNode != null) {
        if (selectedNode instanceof Machine) {
          ui.attributesPanel.machineAP.setInfo((Machine) selectedNode);
          ui.attributesPanel.informationPanelCardLayout.show(
              ui.attributesPanel.informationPanel, Constants.machineAPCode);
        } else if (selectedNode instanceof Primary) {
          ui.attributesPanel.primaryAP.setInfo((Primary) selectedNode);
          ui.attributesPanel.informationPanelCardLayout.show(
              ui.attributesPanel.informationPanel, Constants.primaryAPCode);
        } else {
          System.out.println("Unidentified node type.");
        }
      } else if (selectedEdge != null) {
        ui.attributesPanel.edgeAP.setInfo(selectedEdge);
        ui.attributesPanel.informationPanelCardLayout.show(
            ui.attributesPanel.informationPanel, Constants.edgeAPCode);
      } else {
        ui.attributesPanel.informationPanelCardLayout.show(
            ui.attributesPanel.informationPanel, Constants.nullAPCode);
      }
    } else if (edgeMode.isSelected()) {
      toNode = getSelectedNode(mouse);

      if (fromNode != null && toNode != null && fromNode != toNode) {
        if (!fromNode.adjacent.contains(new Edge(fromNode, toNode))) {
          //					System.out.println("Adding a new edge between " + fromNode + " -> " + toNode);

          Edge edge1 = new Edge(fromNode, toNode);
          Edge edge2 = new Edge(toNode, fromNode);

          fromNode.addAdjacentEdge(edge1);
          toNode.addAdjacentEdge(edge2);
        }
      }
    }

    repaint();
  }
コード例 #10
0
ファイル: Layouter.java プロジェクト: vohoaiviet/metanet
 public void layoutInflate(float st_, Net net) {
   if (net == null) return;
   float strength = st_;
   BBox3D bounds = BBox3D.calcBounds(net.nNodes);
   layoutCenterOnPivot();
   if (net.fNodes.size() == 1) return;
   for (Node nodeRef : net.fNodes) {
     if (!nodeRef.isLocked()) {
       Vector3D trans = new Vector3D();
       Vector3D corr = new Vector3D();
       trans.setXYZ(nodeRef.pos);
       trans.normalize();
       trans.mult(strength);
       corr.setXYZ(bounds.size);
       corr.normalize();
       trans.setXYZ(trans.x * (1 - corr.x), trans.y * (1 - corr.y), trans.z * (1 - corr.z));
       nodeRef.pos.add(trans);
     }
   }
 }
コード例 #11
0
ファイル: Layouter.java プロジェクト: vohoaiviet/metanet
  public void applyPickColors() {
    float[] nodeHSV = new float[3];
    nodeHSV = Func.RGBtoHSV(app.pickGradEnd);
    float[] pickHSV = new float[3];
    pickHSV = Func.RGBtoHSV(app.pickGradStart);

    for (Node n : net.nNodes) {
      //	calculate hue based on network distance from selected node
      float max = app.getPickdepth();
      float grad = n.pickDistance / max;
      float hue = pickHSV[0] + grad * (nodeHSV[0] - pickHSV[0]);
      float[] result = new float[3];
      result = Func.HSVtoRGB(hue, nodeHSV[1], nodeHSV[2], 0.8f);
      //	set the color of the selection frame
      float alpha = Math.max(0f, Math.min(1, max - n.pickDistance + 1));
      result[3] = alpha;
      n.setPickColor(result);

      //			set the alpha of the node color	based on selection
      if (app.fadeNodes && !n.rollover && !n.isFrame()) n.setAlpha(Math.max(0.05f, alpha));
      else n.setAlpha(app.nodeColor[3]);

      n.genColorFromAtt();
    }
  }
コード例 #12
0
ファイル: Layouter.java プロジェクト: vohoaiviet/metanet
  // here only the strongly visible nodes repell the others ...
  private void layoutRepVisible(float abstand, float strength) {
    Vector3D dist = new Vector3D();
    net.repNodes.clear();
    for (Node tmp : net.fNodes) {
      if (tmp.getColor()[3] > 0.2) net.repNodes.add(tmp);
    }

    for (Node a : net.fNodes) {
      for (Node b : net.fNodes) {
        if ((a != b) && (a.getColor()[3] > 0.2 && b.getColor()[3] > 0.2)) {
          repFrucht(abstand, strength, dist, a, b, app.getRepellMax());
        }
      }
    }
  }
コード例 #13
0
ファイル: Layouter.java プロジェクト: vohoaiviet/metanet
 private void clusterCircle(final GL gl, float xRot, float yRot, Node aref) {
   aref.spiralcluster = false;
   int jcount = 0;
   float matrix[] = new float[16];
   float rad = aref.cluster.size();
   float clusterDist = calcClusterDistance(aref);
   for (Node bref : aref.cluster) {
     if (bref != null) {
       gl.glPushMatrix();
       gl.glLoadIdentity();
       gl.glTranslatef(aref.pos.x, aref.pos.y, aref.pos.z);
       //				gl.glRotatef(xRot, 0, 1, 0);
       //				gl.glRotatef(yRot, 1, 0, 0);
       gl.glRotatef(90 + 360 * jcount / rad, 0, 0, 1);
       gl.glTranslatef(-clusterDist, 0, 0);
       gl.glGetFloatv(GL.GL_MODELVIEW_MATRIX, matrix, 0);
       bref.pos.setXYZ(matrix[12], matrix[13], matrix[14]);
       gl.glPopMatrix();
       jcount++;
     }
   }
 }
コード例 #14
0
ファイル: Layouter.java プロジェクト: vohoaiviet/metanet
 private float spiral_rad(Node n, int i) {
   return app.getStandardNodeDistance() / 2f
       + (float) Math.sqrt(app.getClusterRad() * i + n.getSize()) * 10f;
 }
コード例 #15
0
ファイル: Layouter.java プロジェクト: vohoaiviet/metanet
 private float spiral_angle(Node n, int i) {
   return (float) Math.sqrt(app.getClusterRad() * i + n.getSize()) * 75f;
 }
コード例 #16
0
ファイル: Layouter.java プロジェクト: vohoaiviet/metanet
 public void layoutLocksRemove() {
   for (Node n : net.nNodes) n.setLocked(false);
 }
コード例 #17
0
ファイル: Layouter.java プロジェクト: vohoaiviet/metanet
 private void clusterSpiral(final GL gl, float xRot, float yRot, Node aref) {
   aref.spiralcluster = true;
   glSpiral(gl, aref, aref.cluster);
 }
コード例 #18
0
ファイル: Layouter.java プロジェクト: vohoaiviet/metanet
 public void layoutLockRemove(Node picked, Net net2) {
   picked.setLocked(false);
 }
コード例 #19
0
ファイル: Layouter.java プロジェクト: vohoaiviet/metanet
 public void layoutLockPlace(Net net2) {
   for (Node n : net.fNodes) {
     if (n.isLocked()) n.pos = n.lockedPos.copy();
   }
 }
コード例 #20
0
ファイル: Layouter.java プロジェクト: vohoaiviet/metanet
 public void applyAttributeColors() {
   for (Node n : app.getView().nNodes) n.genColorFromAtt();
   for (Edge e : app.getView().nEdges) e.genColorFromAtt();
 }
コード例 #21
0
ファイル: Layouter.java プロジェクト: vohoaiviet/metanet
 public void layoutLocksAll() {
   for (Node n : net.fNodes) {
     n.lockedPos = n.pos.copy();
     n.setLocked(true);
   }
 }
コード例 #22
0
  @Override
  public void paint(Graphics g) {
    super.paint(g);

    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    float dash[] = {10.0f};
    g2d.setStroke(
        new BasicStroke(0.1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f));

    int width = getWidth();
    int height = getHeight();

    if (showGridFlag) {
      int stX = 20;
      // Vertical.
      for (int d = 0; stX + d * 20 < width - 20; d++)
        g2d.drawLine(stX + d * 20, 115, stX + d * 20, height - 55);

      // Horizontal.
      for (int d = 2; 70 + d * 20 < height - 60; d++)
        g2d.drawLine(stX - 5, 80 + d * 20, width - 25, 80 + d * 20);
    }

    // Legend box.

    if (!visualizeButton.isSelected()) {
      g2d.drawString("Source", 45, height - Constants.MARGIN);
      g2d.drawString("Destination", 175, height - Constants.MARGIN);
      g2d.drawString("Primary", 315, height - Constants.MARGIN);
      g2d.drawString("Selected", 440, height - Constants.MARGIN);
      g2d.setColor(Constants.SOURCE_COLOR);
      g2d.fillRect(15, height - 35, 25, 20);
      g2d.setColor(Constants.DEST_COLOR);
      g2d.fillRect(145, height - 35, 25, 20);
      g2d.setColor(Constants.PRIMARY_COLOR);
      g2d.fillRect(285, height - 35, 25, 20);
      g2d.setColor(Constants.SELECTED_COLOR);
      g2d.fillRect(410, height - 35, 25, 20);

      //	        repaint();
    } else {
      Font normalFont = g2d.getFont();
      g2d.setFont(new Font("" + Font.SERIF, 0, 16));
      g2d.drawString("Min.", 110, height - Constants.MARGIN);
      g2d.drawString("Max.", 655, height - Constants.MARGIN);

      g2d.setFont(normalFont);

      ArrayList<JRadioButton> vap = ui.attributesPanel.visualizationPanel.buttons;
      int x = 145, y = height - 35, w = 500, h = 20;
      GradientPaint gradientPaint = null;
      if (vap.get(0).isSelected()) { // loss ratio
        gradientPaint =
            new GradientPaint(
                x, y + h / 2, new Color(0, 255, 0), x + w, y + h / 2, new Color(255, 0, 0));
      } else if (vap.get(1).isSelected()) { // Nodal delay
        gradientPaint =
            new GradientPaint(
                x, y + h / 2, new Color(0, 255, 0), x + w, y + h / 2, new Color(255, 0, 0));
      } else if (vap.get(2).isSelected()) { // link delay
        gradientPaint =
            new GradientPaint(
                x, y + h / 2, new Color(0, 255, 0), x + w, y + h / 2, new Color(255, 0, 0));
      } else if (vap.get(3).isSelected()) { // No. of switches
        gradientPaint =
            new GradientPaint(
                x, y + h / 2, new Color(0, 0, 0), x + w, y + h / 2, new Color(0, 0, 255));
      }
      g2d.setPaint(gradientPaint);
      g2d.fillRect(x, y, w, h);

      //			repaint();
    }
    g2d.setStroke(new BasicStroke(1));

    String drawingOption =
        visualizeButton.isSelected()
            ? ui.attributesPanel
                .visualizationPanel
                .visualiztionOptions
                .getSelection()
                .getActionCommand()
            : "Init";

    for (Node node : listOfNodes) {
      // Draw the Node itself.
      node.draw(
          g2d,
          this,
          drawingOption,
          selectionMode.isSelected()
              || (node instanceof Machine ? machineMode.isSelected() : primaryMode.isSelected()));
    }

    for (Node node : listOfNodes) {
      if (node.topologyOption.equalsIgnoreCase("Location-based")) continue;

      // Draw all the edges.
      for (Edge edge : node.adjacent) {
        edge.draw(g2d, this, drawingOption, selectionMode.isSelected() || edgeMode.isSelected());
      }
    }

    // if an insertion mode is activated. Draw temp node for the user.
    if (cursorNode != null) cursorNode.draw(g2d, drawingPanel, drawingOption, true);

    // Draw simulation of the packets.
    if (!drawingOption.equals("Init")) {
      long currentTime = ui.attributesPanel.visualizationPanel.currentSimulationTime;
      for (Interval interval : sc.timeline) {
        String intervalMessage = interval.packetID == -1 ? interval.message : "WirelessPacket";

        if (interval.fromTime <= currentTime + sc.minTimestamp
            && currentTime + sc.minTimestamp <= interval.toTime
            && canShow(intervalMessage)) {
          int fromX = interval.fromNode.x;
          int fromY = interval.fromNode.y;

          int toX = interval.toNode.x;
          int toY = interval.toNode.y;

          int dX = toX - fromX;
          int dY = toY - fromY;

          long currentDisp = currentTime + sc.minTimestamp - interval.fromTime;
          long totalTime = interval.toTime - interval.fromTime;

          int packetX = (int) (fromX + (currentDisp * 1.0 / totalTime) * dX);
          int packetY = (int) (fromY + (currentDisp * 1.0 / totalTime) * dY);

          if (interval.packetID == -1) {
            // protocol related packet
            if (colorMap == null || !colorMap.containsKey(interval.message)) continue;
            g2d.setColor(colorMap.get(interval.message));
            g2d.fillOval(packetX + 5, packetY + 5, 10, 10);
          } else {
            g2d.setColor(colorMap.get("WirelessPacket"));
            g2d.fillOval(packetX + 5, packetY + 5, 10, 10);
          }

          //					g2d.setColor(Color.WHITE);
          g2d.drawOval(packetX + 5, packetY + 5, 10, 10);
        }
      }

      //			for(FallingPacketPosition p: sc.fallingPackets){
      //				if(p.fromTime <= sc.maxTimestamp && p.toTime <= sc.maxTimestamp && p.fromTime <=
      // currentTime + sc.minTimestamp && currentTime + sc.minTimestamp <= p.toTime &&
      // canShow("WirelessPacket")){
      //					g2d.setColor(colorMap.get("WirelessPacket"));
      //					g2d.fillOval(p.x + 5, p.y + 5, 10, 10);
      //					g2d.setColor(Color.BLACK);
      //					g2d.drawOval(p.x + 5, p.y + 5, 10, 10);
      //				}
      //			}

    }
  }