Example #1
0
  public void draw(MiRenderer renderer) {
    if (!isVisible()) return;

    if (graphics != null) {
      graphics.draw(renderer);
    } else if (strValue != null) {
      renderer.setAttributes(attributes);
      renderer.drawText(strValue, innerBounds, attributes.getFont());
    }
  }
Example #2
0
  /**
   * ------------------------------------------------------ Render this container (i.e. the
   * background shape then all of it's parts).
   *
   * @param renderer the renderer to use for drawing
   * @overrides MiContainer#render ------------------------------------------------------
   */
  protected void render(MiRenderer renderer) {
    // -------------------------------------------------------
    // Get the outer bounds of this container, subtract margins
    // from it, then assign these bounds to the background shape.
    // -------------------------------------------------------
    MiBounds tmpBounds1 = MiBounds.newBounds();
    MiBounds tmpBounds2 = MiBounds.newBounds();
    getBounds(tmpBounds1);
    tmpBounds1.subtractMargins(getMargins(tmpMargins));
    if (hasFixedWidthOrHeight) {
      shape.setFixedHeight(false);
      shape.setFixedWidth(false);
    }
    if (shape instanceof MiMultiPointShape) shape.setBounds(tmpBounds1);
    else shape.replaceBounds(tmpBounds1);

    // -------------------------------------------------------
    // Assign this container's attributes to the background shape
    // and then draw the background shape.
    // -------------------------------------------------------
    shape.replaceAttributes(getAttributes());
    if (shape instanceof MiMultiPointShape) shape.refreshBounds();
    else shape.replaceDrawBounds(getDrawBounds(tmpBounds1));

    shape.draw(renderer);

    // -------------------------------------------------------
    // Get the clip bounds from the renderer and then intersect
    // these clip bounds with the inner bounds of this container.
    // If there is such an intersection...
    // But use the _drawBounds_ because shadows (and ?) extend
    // outside the innerBounds.
    // -------------------------------------------------------
    if (!okToDrawOutsideInnerBounds) {
      MiBounds clip = renderer.getClipBounds(tmpBounds1);
      if (getInnerBounds(tmpBounds2).intersectionWith(clip)) {
        // -------------------------------------------------------
        // ... set the clip bounds of the renderer to this
        // intersection bounds, draw this containers contents
        // (in super.render()), then restore the clip bounds of
        // the renderer.
        // -------------------------------------------------------
        renderer.setClipBounds(tmpBounds2);
        super.render(renderer);
        renderer.setClipBounds(clip);
      }
    } else {
      super.render(renderer);
    }
    MiBounds.freeBounds(tmpBounds1);
    MiBounds.freeBounds(tmpBounds2);
  }
Example #3
0
  public boolean render(MiPart obj, MiRenderer renderer) {
    if (!enabled) return (true);

    if (!(obj instanceof MiMultiPointShape)) return (true);

    MiDistance size;
    MiAttributes attributes = obj.getAttributes();
    Graphics g = renderer.getWindowSystemRenderer();
    MiPoint basePoint = new MiPoint();
    MiPoint endPoint = new MiPoint();

    // FIX: if line length < lineEndSize then exit

    int style = attributes.getLineStartStyle();
    int lwidth = renderer.getLineWidth();
    Color color;
    Color fillColor;
    if (useTargetObjectAttributes) color = attributes.getColor();
    else color = getAttributes().getColor();

    if (useTargetObjectAttributes) fillColor = attributes.getBackgroundColor();
    else fillColor = getAttributes().getBackgroundColor();

    if (style != Mi_NONE) {
      size = attributes.getLineStartSize();
      if (attributes.getLineEndsSizeFnOfLineWidth()) size += attributes.getLineWidth();

      double exitAngle = obj.getPointExitAngle(0) + Math.PI;
      obj.getPoint(0, basePoint);
      calcNewLineEndPoint(renderer, exitAngle, style, size, basePoint);
      obj.getPoint(0, endPoint);
      renderLineEnd(
          renderer, exitAngle, style, size, basePoint, endPoint, lwidth, color, fillColor);
    }
    style = attributes.getLineEndStyle();
    if (style != Mi_NONE) {
      size = attributes.getLineEndSize();
      if (attributes.getLineEndsSizeFnOfLineWidth()) size += attributes.getLineWidth();

      double entryAngle = obj.getPointEntryAngle(-1);
      obj.getPoint(-1, basePoint);
      calcNewLineEndPoint(renderer, entryAngle, style, size, basePoint);
      g.setColor(attributes.getColor());
      obj.getPoint(-1, endPoint);
      renderLineEnd(
          renderer, entryAngle, style, size, basePoint, endPoint, lwidth, color, fillColor);
    }
    return (true);
  }
Example #4
0
  protected void renderLineEnd(
      MiRenderer renderer,
      double angle,
      int style,
      MiDistance size,
      MiPoint basePoint,
      MiPoint endPoint,
      int lwidth,
      Color color,
      Color fillColor) {
    int dSize = 0;
    int dx = 0;
    int dy = 0;
    int dx1 = 0;
    int dy1 = 0;
    int dx2 = 0;
    int dy2 = 0;

    renderer.getTransform().wtod(basePoint, dBasePoint);
    renderer.getTransform().wtod(endPoint, dEndPoint);

    int baseX = dBasePoint.x;
    int baseY = renderer.getYmax() - dBasePoint.y;
    int x = dEndPoint.x;
    int y = renderer.getYmax() - dEndPoint.y;

    Graphics g = renderer.getWindowSystemRenderer();

    boolean attributesOverridden = renderer.hasOverrideAttributes();

    if ((color != Mi_TRANSPARENT_COLOR) && (!attributesOverridden)) g.setColor(color);
    if ((fillColor == Mi_TRANSPARENT_COLOR) && (!attributesOverridden)) fillColor = color;

    switch (style) {
      case Mi_TRIANGLE_LINE_END_STYLE:
      case Mi_FILLED_TRIANGLE_LINE_END_STYLE:
      case Mi_TRIANGLE_VIA_LINE_END_STYLE:
      case Mi_FILLED_TRIANGLE_VIA_LINE_END_STYLE:
      case Mi_CIRCLE_LINE_END_STYLE:
      case Mi_CIRCLE_VIA_LINE_END_STYLE:
      case Mi_FILLED_CIRCLE_LINE_END_STYLE:
      case Mi_FILLED_CIRCLE_VIA_LINE_END_STYLE:
      case Mi_SQUARE_LINE_END_STYLE:
      case Mi_FILLED_SQUARE_LINE_END_STYLE:
        {
          tmpVector.x = size / 2 * Math.sin(angle);
          tmpVector.y = -size / 2 * Math.cos(angle);
          renderer.getTransform().wtod(basePoint, tmpVector, tmpDVector);
          dx = tmpDVector.x;
          dy = tmpDVector.y;

          tmpVector.x = size;
          tmpVector.y = size;
          renderer.getTransform().wtod(basePoint, tmpVector, tmpDVector);
          dSize = tmpDVector.x;

          break;
        }
      default:
        {
          double arrowPointyness = ((double) 60) / 180 * Math.PI; // 60 degrees
          double arrowLength = size;
          double arrowShapeFactor = arrowLength / Math.cos(arrowPointyness / 2);

          tmpVector.x = arrowShapeFactor * Math.cos(angle - arrowPointyness / 2);
          tmpVector.y = arrowShapeFactor * Math.sin(angle - arrowPointyness / 2);
          renderer.getTransform().wtod(basePoint, tmpVector, tmpDVector);

          dx1 = tmpDVector.x;
          dy1 = -tmpDVector.y;

          tmpVector.x = arrowShapeFactor * Math.cos(angle + arrowPointyness / 2);
          tmpVector.y = arrowShapeFactor * Math.sin(angle + arrowPointyness / 2);
          renderer.getTransform().wtod(basePoint, tmpVector, tmpDVector);

          dx2 = tmpDVector.x;
          dy2 = -tmpDVector.y;
        }
    }

    /*
    System.out.println("angle = " + angle * 180 / Math.PI);
    System.out.println("size = " + size);
    System.out.println("dsize = " + dSize);
    System.out.println("dx = " + dx);
    System.out.println("dy = " + dy);
    System.out.println("dx1 = " + dx1);
    System.out.println("dy1 = " + dy1);
    System.out.println("dx2 = " + dx2);
    System.out.println("dy2 = " + dy2);
    */

    switch (style) {
      case Mi_NONE:
      default:
        break;

      case Mi_STROKED_ARROW_LINE_END_STYLE:
        if (color == Mi_TRANSPARENT_COLOR) break;

        if (lwidth < 2) {
          g.drawLine(x, y, x - dx1, y - dy1);
          g.drawLine(x, y, x - dx2, y - dy2);
        } else {
          renderer.setColor(color);
          renderer.setBackgroundColor(color);
          renderer.drawWideLine(x, y, x - dx1, y - dy1, lwidth);
          renderer.drawWideLine(x, y, x - dx2, y - dy2, lwidth);
        }
        break;

      case Mi_3FEATHER_LINE_END_STYLE:
      case Mi_2FEATHER_LINE_END_STYLE:
        if (color == Mi_TRANSPARENT_COLOR) break;

        if (lwidth < 2) {
          g.drawLine(baseX, baseY, baseX + dx1, baseY + dy1);
          g.drawLine(baseX, baseY, baseX + dx2, baseY + dy2);
        } else {
          renderer.setColor(color);
          renderer.setBackgroundColor(color);
          renderer.drawWideLine(baseX, baseY, baseX + dx1, baseY + dy1, lwidth);
          renderer.drawWideLine(baseX, baseY, baseX + dx2, baseY + dy2, lwidth);
        }
        break;

      case Mi_DIAMOND_LINE_END_STYLE:
      case Mi_FILLED_DIAMOND_LINE_END_STYLE:
        xPoints[0] = baseX;
        xPoints[1] = baseX + dx1;
        xPoints[2] = x;
        xPoints[3] = baseX + dx2;
        xPoints[4] = baseX;

        yPoints[0] = baseY;
        yPoints[1] = baseY + dy1;
        yPoints[2] = y;
        yPoints[3] = baseY + dy2;
        yPoints[4] = baseY;

        if ((style == Mi_FILLED_DIAMOND_LINE_END_STYLE) && (fillColor != Mi_TRANSPARENT_COLOR)) {
          if (!attributesOverridden) g.setColor(fillColor);
          g.fillPolygon(xPoints, yPoints, 5);
        }

        if ((color != Mi_TRANSPARENT_COLOR)
            && ((style != Mi_FILLED_DIAMOND_LINE_END_STYLE) || (!color.equals(fillColor)))) {
          if (lwidth < 2) {
            if (!attributesOverridden) g.setColor(color);
            g.drawPolygon(xPoints, yPoints, 5);
          } else {
            renderer.setColor(color);
            renderer.setBackgroundColor(color);
            for (int i = 1; i < 5; ++i) {
              renderer.drawWideLine(xPoints[i - 1], yPoints[i - 1], xPoints[i], yPoints[i], lwidth);
            }
          }
        }
        break;

      case Mi_FILLED_ARROW_LINE_END_STYLE:
        if (fillColor == Mi_TRANSPARENT_COLOR) break;

        xPoints[0] = x;
        xPoints[1] = x - dx1;
        xPoints[2] = x - dx2;
        xPoints[3] = xPoints[0];

        yPoints[0] = y;
        yPoints[1] = y - dy1;
        yPoints[2] = y - dy2;
        yPoints[3] = yPoints[0];

        if (!attributesOverridden) g.setColor(fillColor);
        g.fillPolygon(xPoints, yPoints, 4);
        break;

      case Mi_TRIANGLE_LINE_END_STYLE:
      case Mi_FILLED_TRIANGLE_LINE_END_STYLE:
      case Mi_TRIANGLE_VIA_LINE_END_STYLE:
      case Mi_FILLED_TRIANGLE_VIA_LINE_END_STYLE:
        xPoints[0] = baseX + dx;
        xPoints[1] = x;
        xPoints[2] = baseX - dx;
        xPoints[3] = xPoints[0];

        yPoints[0] = baseY - dy;
        yPoints[1] = y;
        yPoints[2] = baseY + dy;
        yPoints[3] = yPoints[0];

        if (((style == Mi_FILLED_TRIANGLE_LINE_END_STYLE)
                || (style == Mi_FILLED_TRIANGLE_VIA_LINE_END_STYLE))
            && (fillColor != Mi_TRANSPARENT_COLOR)) {
          if (!attributesOverridden) g.setColor(fillColor);
          g.fillPolygon(xPoints, yPoints, 4);
        }

        if (color != Mi_TRANSPARENT_COLOR) {
          if (lwidth < 2) {
            if (!attributesOverridden) g.setColor(color);
            g.drawPolygon(xPoints, yPoints, 4);
          } else {
            renderer.setColor(color);
            renderer.setBackgroundColor(color);
            for (int i = 1; i < 4; ++i) {
              renderer.drawWideLine(xPoints[i - 1], yPoints[i - 1], xPoints[i], yPoints[i], lwidth);
            }
          }
        }
        break;

      case Mi_CIRCLE_LINE_END_STYLE:
      case Mi_CIRCLE_VIA_LINE_END_STYLE:
        if (color != Mi_TRANSPARENT_COLOR) {
          g.drawOval(
              x - (x - baseX) / 2 - dSize / 2, y - (y - baseY) / 2 - dSize / 2, dSize, dSize);
        }
        break;

      case Mi_FILLED_CIRCLE_LINE_END_STYLE:
      case Mi_FILLED_CIRCLE_VIA_LINE_END_STYLE:
        if (fillColor != Mi_TRANSPARENT_COLOR) {
          if (!attributesOverridden) g.setColor(fillColor);
          g.fillOval(
              x - (x - baseX) / 2 - dSize / 2, y - (y - baseY) / 2 - dSize / 2, dSize, dSize);
        }
        break;

      case Mi_SQUARE_LINE_END_STYLE:
      case Mi_FILLED_SQUARE_LINE_END_STYLE:
        xPoints[0] = x + dx;
        xPoints[1] = x - dx;
        xPoints[2] = baseX - dx;
        xPoints[3] = baseX + dx;
        xPoints[4] = xPoints[0];

        yPoints[0] = y - dy;
        yPoints[1] = y + dy;
        yPoints[2] = baseY + dy;
        yPoints[3] = baseY - dy;
        yPoints[4] = yPoints[0];

        if ((style == Mi_FILLED_SQUARE_LINE_END_STYLE) && (fillColor != Mi_TRANSPARENT_COLOR)) {
          if (!attributesOverridden) g.setColor(fillColor);
          g.fillPolygon(xPoints, yPoints, 5);
        }
        if (color != Mi_TRANSPARENT_COLOR) {
          if (lwidth < 2) {
            if (!attributesOverridden) g.setColor(color);
            g.drawPolygon(xPoints, yPoints, 5);
          } else {
            renderer.setColor(color);
            renderer.setBackgroundColor(color);
            for (int i = 1; i < 5; ++i) {
              renderer.drawWideLine(xPoints[i - 1], yPoints[i - 1], xPoints[i], yPoints[i], lwidth);
            }
          }
        }
        break;

      case Mi_SQUARE_VIA_LINE_END_STYLE:
      case Mi_FILLED_SQUARE_VIA_LINE_END_STYLE:
        int tipX = x + (x - baseX);
        int tipY = y + (y - baseY);

        xPoints[0] = tipX + dx;
        xPoints[1] = tipX - dx;
        xPoints[2] = baseX - dx;
        xPoints[3] = baseX + dx;
        xPoints[4] = xPoints[0];

        yPoints[0] = tipY - dy;
        yPoints[1] = tipY + dy;
        yPoints[2] = baseY + dy;
        yPoints[3] = baseY - dy;
        yPoints[4] = yPoints[0];

        if ((style == Mi_FILLED_SQUARE_VIA_LINE_END_STYLE) && (fillColor != Mi_TRANSPARENT_COLOR)) {
          if (!attributesOverridden) g.setColor(fillColor);
          g.fillPolygon(xPoints, yPoints, 5);
        }

        if (color != Mi_TRANSPARENT_COLOR) {
          if (lwidth < 2) {
            if (!attributesOverridden) g.setColor(color);
            g.drawPolygon(xPoints, yPoints, 5);
          } else {
            renderer.setColor(color);
            renderer.setBackgroundColor(color);
            for (int i = 1; i < 5; ++i) {
              renderer.drawWideLine(xPoints[i - 1], yPoints[i - 1], xPoints[i], yPoints[i], lwidth);
            }
          }
        }
        break;
    }
  }