Пример #1
0
  void draw(Graphics2D g) {

    int endX, endY;
    Block from = null;
    if (fromId > -1) from = diag.blocks.get(new Integer(fromId));
    Block to = null;
    if (!endsAtLine && toId > -1) to = diag.blocks.get(new Integer(toId));

    if (toX == -1) endX = diag.xa;
    else endX = toX;

    if (toY == -1) endY = diag.ya;
    else endY = toY;

    g.setColor(Color.GRAY);

    Stroke stroke = g.getStroke();
    ZigzagStroke zzstroke = new ZigzagStroke(stroke, 2, 4);

    if (toX == -1) {
      g.drawRect(fromX - 3, fromY - 3, 6, 6);
      return;
    }

    if (from != null) {
      if (fromSide == Side.TOP) fromY = from.cy - from.height / 2;
      else if (fromSide == Side.BOTTOM) fromY = from.cy + from.height / 2;
      else if (fromSide == Side.LEFT) fromX = from.cx - from.width / 2;
      else if (fromSide == Side.RIGHT) fromX = from.cx + from.width / 2;
    }

    if (to != null) {
      if (toSide == Side.TOP) toY = to.cy - to.height / 2;
      else if (toSide == Side.BOTTOM) toY = to.cy + to.height / 2;
      else if (toSide == Side.LEFT) toX = to.cx - to.width / 2;
      else if (toSide == Side.RIGHT) toX = to.cx + to.width / 2;
    }

    if (driver.selArrowP == this) g.setColor(Color.BLUE);
    else if ((from instanceof ComponentBlock
            || from instanceof ExtPortBlock
            || from instanceof Enclosure)
        && (to instanceof ComponentBlock
            || to instanceof ExtPortBlock
            || to instanceof Enclosure
            || endsAtLine))
      if (checkStatus == Status.UNCHECKED) g.setColor(Color.BLACK);
      else if (checkStatus == Status.COMPATIBLE) g.setColor(FOREST_GREEN);
      else g.setColor(ORANGE_RED);
    else if (from instanceof LegendBlock || to instanceof LegendBlock) g.setColor(Color.GRAY);

    int fx, fy, tx, ty;
    fx = fromX;
    fy = fromY;
    // tx = toX;
    // ty = toY;
    // int autoX = -1, autoY = -1;  // only used for automatic ports
    if (bends != null) {
      for (Bend bend : bends) {
        tx = bend.x;
        ty = bend.y;
        if (!dropOldest) g.drawLine(fx, fy, tx, ty);
        else {
          Shape shape = new Line2D.Double(fx, fy, tx, ty);
          shape = zzstroke.createStrokedShape(shape);
          g.draw(shape);
          // g.setStroke(stroke);
        }

        if (bend.marked) {
          Color col = g.getColor();
          g.setColor(Color.RED);
          g.drawOval(tx - 5, ty - 5, 10, 10);
          g.setColor(col);
        }
        calcLimits(fx, tx, fy, ty);
        fx = tx;
        fy = ty;
      }
    }
    tx = endX;
    ty = endY;

    int x = endX;
    if (to != null && endsAtBlock && to.multiplex) {
      String s = to.mpxfactor;
      if (s == null) s = " ";
      int i = s.length() * driver.fontWidth + 10;
      x -= i;
    }

    if (headMarked) {
      Color col = g.getColor();
      g.setColor(Color.RED);
      g.drawOval(x - 5, toY - 5, 10, 10);
      g.setColor(col);
    }

    if (!dropOldest) g.drawLine(fx, fy, tx, ty);
    else {
      Shape shape = new Line2D.Double(fx, fy, tx, ty);
      shape = zzstroke.createStrokedShape(shape);
      g.draw(shape);
      // g.setStroke(stroke);
    }

    if (tailMarked) {
      Color col = g.getColor();
      g.setColor(Color.RED);
      g.drawOval(fromX - 5, fromY - 5, 10, 10);
      g.setColor(col);
    }

    calcLimits(fx, x, fy, toY);

    if (!endsAtBlock && !endsAtLine) {
      g.drawRect(fromX - 3, fromY - 3, 6, 6);
      g.drawRect(x - 3, toY - 3, 6, 6);
    } else if (endsAtBlock) {
      if ((from instanceof ComponentBlock
              || from instanceof ExtPortBlock
              || from instanceof Enclosure)
          && (to instanceof ComponentBlock
              || to instanceof ExtPortBlock
              || to instanceof Enclosure)) {
        Arrowhead ah = new Arrowhead(fx, fy, toX, toY);
        ah.draw(g);
      }

    } else if (endsAtLine) {
      drawCircleTo(g, fx, fy, x, toY, Color.BLACK, 4);
      // g.drawOval(toX - 2, toY - 2, 4, 4);
      // g.fillOval(toX - 2, toY - 2, 4, 4);
    }

    if (toX != -1 && (endsAtBlock || endsAtLine)) {
      if (upStreamPort != null && (from instanceof ComponentBlock || from instanceof Enclosure)) {
        if (upStreamPort.equals("*")) {
          drawCircleFrom(g, fromX, fromY, endX, endY, Color.BLUE, 8);
          // g.setColor(Color.BLUE);
          // g.drawOval(fromX, fromY - 4, 8, 8);
          // g.fillOval(fromX, fromY - 4, 8, 8);
        } else if (from.visible) {
          g.setColor(Color.BLUE);
          int y = fromY + driver.fontHeight;
          int x2 = fromX + driver.fontWidth;
          g.drawString(upStreamPort, x2, y);
        }
        g.setColor(Color.BLACK);
      }
      if (downStreamPort != null
          && !endsAtLine
          && to != null
          && (to instanceof ComponentBlock || to instanceof Enclosure)) {
        if (downStreamPort.equals("*")) {
          drawCircleTo(g, fx, fy, toX, toY, Color.BLUE, 8);
          // g.setColor(Color.BLUE);
          // g.drawOval(x - 8, toY - 4, 8, 8);
          // g.fillOval(x - 8, toY - 4, 8, 8);
        } else if (to.visible) {
          g.setColor(Color.BLUE);
          int y = toY - driver.fontHeight / 2;
          x = toX - driver.fontWidth * (downStreamPort.length() + 1);
          if (!endsAtLine && to != null && to.multiplex) x -= 20;
          g.drawString(downStreamPort, x, y);
        }
        g.setColor(Color.BLACK);
      }
    }
    if (extraArrowhead != null) extraArrowhead.draw(g);
  }