Package com.mxgraph.canvas

Examples of com.mxgraph.canvas.mxGraphicsCanvas2D$CanvasState


  /**
   * Creates the canvas for rendering the stencil.
   */
  protected mxGraphicsCanvas2D createCanvas(mxGraphics2DCanvas gc)
  {
    return new mxGraphicsCanvas2D(gc.getGraphics());
  }
View Full Code Here


   * Paints the stencil for the given state.
   */
  public void paintShape(mxGraphics2DCanvas gc, mxCellState state)
  {
    Map<String, Object> style = state.getStyle();
    mxGraphicsCanvas2D canvas = createCanvas(gc);

    double rotation = mxUtils.getDouble(style, mxConstants.STYLE_ROTATION,
        0);
    String direction = mxUtils.getString(style,
        mxConstants.STYLE_DIRECTION, null);

    // Default direction is east (ignored if rotation exists)
    if (direction != null)
    {
      if (direction.equals("north"))
      {
        rotation += 270;
      }
      else if (direction.equals("west"))
      {
        rotation += 180;
      }
      else if (direction.equals("south"))
      {
        rotation += 90;
      }
    }

    // New styles for shape flipping the stencil
    boolean flipH = mxUtils.isTrue(style, mxConstants.STYLE_STENCIL_FLIPH,
        false);
    boolean flipV = mxUtils.isTrue(style, mxConstants.STYLE_STENCIL_FLIPV,
        false);

    if (flipH && flipV)
    {
      rotation += 180;
      flipH = false;
      flipV = false;
    }

    // Saves the global state for each cell
    canvas.save();

    // Adds rotation and horizontal/vertical flipping
    rotation = rotation % 360;

    if (rotation != 0 || flipH || flipV)
    {
      canvas.rotate(rotation, flipH, flipV, state.getCenterX(),
          state.getCenterY());
    }

    // Note: Overwritten in mxStencil.paintShape (can depend on aspect)
    double scale = state.getView().getScale();
    double sw = mxUtils.getDouble(style, mxConstants.STYLE_STROKEWIDTH, 1)
        * scale;
    canvas.setStrokeWidth(sw);

    double alpha = mxUtils.getDouble(style, mxConstants.STYLE_OPACITY, 100) / 100;
    String gradientColor = mxUtils.getString(style,
        mxConstants.STYLE_GRADIENTCOLOR, null);

    // Converts colors with special keyword none to null
    if (gradientColor != null && gradientColor.equals(mxConstants.NONE))
    {
      gradientColor = null;
    }

    String fillColor = mxUtils.getString(style,
        mxConstants.STYLE_FILLCOLOR, null);

    if (fillColor != null && fillColor.equals(mxConstants.NONE))
    {
      fillColor = null;
    }

    String strokeColor = mxUtils.getString(style,
        mxConstants.STYLE_STROKECOLOR, null);

    if (strokeColor != null && strokeColor.equals(mxConstants.NONE))
    {
      strokeColor = null;
    }

    // Draws the shadow if the fillColor is not transparent
    if (mxUtils.isTrue(style, mxConstants.STYLE_SHADOW, false))
    {
      drawShadow(canvas, state, rotation, flipH, flipV, state, alpha, fillColor != null);
    }

    canvas.setAlpha(alpha);

    // Sets the dashed state
    if (mxUtils.isTrue(style, mxConstants.STYLE_DASHED, false))
    {
      canvas.setDashed(true);
    }

    // Draws background and foreground
    if (strokeColor != null || fillColor != null)
    {
      if (strokeColor != null)
      {
        canvas.setStrokeColor(strokeColor);
      }

      if (fillColor != null)
      {
        if (gradientColor != null
            && !gradientColor.equals("transparent"))
        {
          canvas.setGradient(fillColor, gradientColor, state.getX(),
              state.getY(), state.getWidth(), state.getHeight(),
              direction, 1, 1);
        }
        else
        {
          canvas.setFillColor(fillColor);
        }
      }

      // Draws background and foreground of shape
      drawShape(canvas, state, state, true);
View Full Code Here

            {
              protected mxGraphicsCanvas2D createCanvas(
                  final mxGraphics2DCanvas gc)
              {
                // Redirects image loading to graphics canvas
                return new mxGraphicsCanvas2D(gc.getGraphics())
                {
                  protected Image loadImage(String src)
                  {
                    // Adds image base path to relative image URLs
                    if (!src.startsWith("/")
View Full Code Here

TOP

Related Classes of com.mxgraph.canvas.mxGraphicsCanvas2D$CanvasState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.