예제 #1
0
    boolean tick(long time) {
      boolean r = false;
      if (tick > 0) {
        tick--;
        r = true;
      }

      for (int i = 0, n = node.getLinkCount(); i < n; i++) {
        Link link = node.getLink(i);
        long age = (time - link.getLastActive()) / 100;
        if (age < 200) {
          r = true;
          break;
        }
      }
      return r;
    }
예제 #2
0
  public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    int lx = 10;
    super.paint(g);
    long time = System.currentTimeMillis();
    if (mapImage != null) {
      mapImage.paintIcon(this, g, 0, 0);
    }
    MapNode[] nodes = nodeList;
    if (nodes != null) {
      Line2D line = new Line2D.Double();
      for (int i = 0, m = nodes.length; i < m; i++) {
        MapNode n = nodes[i];
        int x, y;
        if (n.node.hasLocation()) {
          x = n.node.getX();
          y = n.node.getY();
        } else {
          x = lx;
          y = 10;
          lx += 30;
        }

        if (!hideNetwork) {
          FontMetrics fm = g.getFontMetrics();
          int fnHeight = fm.getHeight();
          int fnDescent = fm.getDescent();
          for (int j = 0, mu = n.node.getLinkCount(); j < mu; j++) {
            Link link = n.node.getLink(j);
            if (link.node.hasLocation()) {
              long age = (time - link.getLastActive()) / 100;
              int x2 = link.node.getX();
              int y2 = link.node.getY();
              if (n.isSelected) {
                if (age > LINK_COLOR.length) {
                  age = 100;
                } else {
                  age -= 50;
                }
              }
              line.setLine(x, y, x2, y2);
              if (age < LINK_COLOR.length) {
                g.setColor(age < 0 ? LINK_COLOR[0] : LINK_COLOR[(int) age]);
              } else {
                g.setColor(LINK_COLOR[LINK_COLOR.length - 1]);
              }
              g2d.draw(line);
              //              g.setColor(Color.lightGray);
              int xn1, xn2, yn1, yn2;
              if (x <= x2) {
                xn1 = x;
                xn2 = x2;
                yn1 = y;
                yn2 = y2;
              } else {
                xn1 = x2;
                xn2 = x;
                yn1 = y2;
                yn2 = y;
              }
              int dx = xn1 + (xn2 - xn1) / 2 + 4;
              int dy = yn1 + (yn2 - yn1) / 2 - fnDescent;
              if (yn2 < yn1) {
                dy += fnHeight - fnDescent;
              }
              g.drawString("ETX:" + (((int) (link.getETX() * 100 + 0.5)) / 100.0), dx, dy);
            }
          }
        }

        n.paint(g, x, y);

        g.setColor(Color.black);
        if (n.isSelected) {
          BasicGraphicsUtils.drawDashedRect(g, x - delta, y - delta, 2 * delta, 2 * delta);
        }
        if (selectedNode != null && selectedNode.message != null) {
          g.drawString(selectedNode.message, 10, 10);
        }
      }
    }
  }