예제 #1
0
  public void draw(Canvas _canvas, Rect _top_left) {
    Rect myrect;
    Rect subrect;
    // START KGU 2015-10-13: All highlighting rules now encapsulated by this new method
    // Color drawColor = getColor();
    Color drawColor = getFillColor();
    // END KGU 2015-10-13
    FontMetrics fm = _canvas.getFontMetrics(Element.font);
    Canvas canvas = _canvas;
    // START KGU 2015-10-13: Became obsolete by new method getFillColor() applied above now
    //		if (selected==true)
    //		{
    //			drawColor=Element.E_DRAWCOLOR;
    //		}
    // END KGU 2015-10-13

    rect = _top_left.copy();

    myrect = _top_left.copy();
    myrect.bottom = myrect.top;

    if (children.size() > 0) {
      // draw children
      for (int i = 0; i < children.size(); i++) {
        subrect = ((Element) children.get(i)).prepareDraw(_canvas);
        myrect.bottom += subrect.bottom;
        if (i == children.size() - 1) {
          myrect.bottom = _top_left.bottom;
        }
        ((Element) children.get(i)).draw(_canvas, myrect);

        // myrect.bottom-=1;
        myrect.top += subrect.bottom;
      }
    } else {
      // draw nothing
      rect = _top_left.copy();

      canvas.setBackground(drawColor);
      canvas.setColor(drawColor);

      myrect = _top_left.copy();

      canvas.fillRect(myrect);

      canvas.setColor(Color.BLACK);
      canvas.writeOut(
          _top_left.left
              + ((_top_left.right - _top_left.left) / 2)
              - (_canvas.stringWidth("\u2205") / 2),
          _top_left.top + ((_top_left.bottom - _top_left.top) / 2) + (fm.getHeight() / 2),
          "\u2205");

      canvas.drawRect(_top_left);
    }
  }
예제 #2
0
  public void draw(Canvas _canvas, Rect _top_left) {
    if (isCollapsed()) {
      Instruction.draw(_canvas, _top_left, getCollapsedText(), this);
      return;
    }

    Rect myrect = new Rect();
    // START KGU 2015-10-13: All highlighting rules now encapsulated by this new method
    // Color drawColor = getColor();
    Color drawColor = getFillColor();
    // END KGU 2015-10-13
    FontMetrics fm = _canvas.getFontMetrics(font);
    //		int p;
    //		int w;

    // START KGU 2015-10-13: Became obsolete by new method getFillColor() applied above now
    //		if (selected==true)
    //		{
    //			drawColor=Element.E_DRAWCOLOR;
    //		}
    // END KGU 2015-10-13

    Canvas canvas = _canvas;
    canvas.setBackground(drawColor);
    canvas.setColor(drawColor);

    // draw background
    myrect = _top_left.copy();
    canvas.fillRect(myrect);

    // draw shape
    rect = _top_left.copy();
    canvas.setColor(Color.BLACK);
    canvas.drawRect(_top_left);

    myrect = _top_left.copy();
    myrect.bottom =
        _top_left.top + fm.getHeight() * getText().count() + 2 * Math.round(Element.E_PADDING / 2);
    canvas.drawRect(myrect);

    myrect.bottom = _top_left.bottom;
    myrect.top = myrect.bottom - E_PADDING;
    canvas.drawRect(myrect);

    myrect = _top_left.copy();
    myrect.right = myrect.left + E_PADDING;
    canvas.drawRect(myrect);

    // fill shape
    canvas.setColor(drawColor);
    myrect.left = myrect.left + 1;
    myrect.top = myrect.top + 1;
    myrect.bottom = myrect.bottom;
    myrect.right = myrect.right - 1;
    canvas.fillRect(myrect);

    myrect = _top_left.copy();
    myrect.bottom =
        _top_left.top + fm.getHeight() * getText().count() + 2 * Math.round(E_PADDING / 2);
    myrect.left = myrect.left + 1;
    myrect.top = myrect.top + 1;
    myrect.bottom = myrect.bottom;
    myrect.right = myrect.right - 1;
    canvas.fillRect(myrect);

    myrect.bottom = _top_left.bottom;
    myrect.top = myrect.bottom - Element.E_PADDING;
    myrect.left = myrect.left + 1;
    myrect.top = myrect.top + 1;
    myrect.bottom = myrect.bottom;
    myrect.right = myrect.right;
    canvas.fillRect(myrect);

    // draw comment
    if (Element.E_SHOWCOMMENTS == true && !comment.getText().trim().equals("")) {
      // START KGU 2015-10-11: Use an inherited helper method now
      //			canvas.setBackground(E_COMMENTCOLOR);
      //			canvas.setColor(E_COMMENTCOLOR);
      //
      //			Rect someRect = _top_left.copy();
      //
      //			someRect.left+=2;
      //			someRect.top+=2;
      //			someRect.right=someRect.left+4;
      //			someRect.bottom-=1;
      //
      //			canvas.fillRect(someRect);
      this.drawCommentMark(canvas, _top_left);
      // END KGU 2015-10-11
    }
    // START KGU 2015-10-11
    // draw breakpoint bar if necessary
    this.drawBreakpointMark(canvas, _top_left);
    // END KGU 2015-10-11

    // draw text
    for (int i = 0; i < getText().count(); i++) {
      String text = this.getText().get(i);
      text = BString.replace(text, "<--", "<-");

      canvas.setColor(Color.BLACK);
      writeOutVariables(
          canvas,
          _top_left.left + Math.round(E_PADDING / 2),
          _top_left.top + Math.round(E_PADDING / 2) + (i + 1) * fm.getHeight(),
          text,
          this);
    }

    // draw children
    myrect = _top_left.copy();
    myrect.left = myrect.left + Element.E_PADDING - 1;
    myrect.top =
        _top_left.top + fm.getHeight() * getText().count() + 2 * Math.round(E_PADDING / 2) - 1;
    myrect.bottom = myrect.bottom - E_PADDING + 1;
    q.draw(_canvas, myrect);
  }