protected void handleCSSPropertyChanged(int property) {
   switch (property) {
     case SVGCSSEngine.MARKER_START_INDEX:
     case SVGCSSEngine.MARKER_MID_INDEX:
     case SVGCSSEngine.MARKER_END_INDEX:
       if (!hasNewShapePainter) {
         hasNewShapePainter = true;
         ShapeNode shapeNode = (ShapeNode) node;
         shapeNode.setShapePainter(createShapePainter(ctx, e, shapeNode));
       }
       break;
     default:
       super.handleCSSPropertyChanged(property);
   }
 }
Exemplo n.º 2
0
  public static ShapePainter convertStrokePainter(Element e, ShapeNode node, BridgeContext ctx) {
    Shape shape = node.getShape();
    if (shape == null) return null;

    Stroke stroke = convertStroke(e);
    if (stroke == null) return null;

    Paint strokePaint = convertStrokePaint(e, node, ctx);
    StrokeShapePainter sp = new StrokeShapePainter(shape);
    sp.setStroke(stroke);
    sp.setPaint(strokePaint);
    return sp;
  }
Exemplo n.º 3
0
  /**
   * Returns a <code>ShapePainter</code> defined on the specified element and for the specified
   * shape node.
   *
   * @param e the element with the marker CSS properties
   * @param node the shape node
   * @param ctx the bridge context
   */
  public static ShapePainter convertMarkers(Element e, ShapeNode node, BridgeContext ctx) {
    Value v;
    v = CSSUtilities.getComputedStyle(e, SVGCSSEngine.MARKER_START_INDEX);
    Marker startMarker = convertMarker(e, v, ctx);
    v = CSSUtilities.getComputedStyle(e, SVGCSSEngine.MARKER_MID_INDEX);
    Marker midMarker = convertMarker(e, v, ctx);
    v = CSSUtilities.getComputedStyle(e, SVGCSSEngine.MARKER_END_INDEX);
    Marker endMarker = convertMarker(e, v, ctx);

    if (startMarker != null || midMarker != null || endMarker != null) {
      MarkerShapePainter p = new MarkerShapePainter(node.getShape());
      p.setStartMarker(startMarker);
      p.setMiddleMarker(midMarker);
      p.setEndMarker(endMarker);
      return p;
    } else {
      return null;
    }
  }
Exemplo n.º 4
0
  /**
   * Returns a <code>ShapePainter</code> defined on the specified element and for the specified
   * shape node, and using the specified bridge context.
   *
   * @param e the element interested in a shape painter
   * @param node the shape node
   * @param ctx the bridge context
   */
  public static ShapePainter convertFillAndStroke(Element e, ShapeNode node, BridgeContext ctx) {
    Shape shape = node.getShape();
    if (shape == null) return null;

    Paint fillPaint = convertFillPaint(e, node, ctx);
    FillShapePainter fp = new FillShapePainter(shape);
    fp.setPaint(fillPaint);

    Stroke stroke = convertStroke(e);
    if (stroke == null) return fp;

    Paint strokePaint = convertStrokePaint(e, node, ctx);
    StrokeShapePainter sp = new StrokeShapePainter(shape);
    sp.setStroke(stroke);
    sp.setPaint(strokePaint);

    CompositeShapePainter cp = new CompositeShapePainter(shape);
    cp.addShapePainter(fp);
    cp.addShapePainter(sp);
    return cp;
  }
  /**
   * Creates the shape painter associated to the specified element. This implementation creates a
   * shape painter considering the various fill and stroke properties in addition to the marker
   * properties.
   *
   * @param ctx the bridge context to use
   * @param e the element that describes the shape painter to use
   * @param shapeNode the shape node that is interested in its shape painter
   */
  protected ShapePainter createShapePainter(BridgeContext ctx, Element e, ShapeNode shapeNode) {
    ShapePainter fillAndStroke;
    fillAndStroke = createFillStrokePainter(ctx, e, shapeNode);

    ShapePainter markerPainter = createMarkerPainter(ctx, e, shapeNode);

    Shape shape = shapeNode.getShape();
    ShapePainter painter;

    if (markerPainter != null) {
      if (fillAndStroke != null) {
        CompositeShapePainter cp = new CompositeShapePainter(shape);
        cp.addShapePainter(fillAndStroke);
        cp.addShapePainter(markerPainter);
        painter = cp;
      } else {
        painter = markerPainter;
      }
    } else {
      painter = fillAndStroke;
    }
    return painter;
  }
  /**
   * Constructs a circle according to the specified parameters.
   *
   * @param ctx the bridge context to use
   * @param e the element that describes a rect element
   * @param shapeNode the shape node to initialize
   */
  protected void buildShape(BridgeContext ctx, Element e, ShapeNode shapeNode) {
    try {
      SVGOMCircleElement ce = (SVGOMCircleElement) e;

      // 'cx' attribute - default is 0
      AbstractSVGAnimatedLength _cx = (AbstractSVGAnimatedLength) ce.getCx();
      float cx = _cx.getCheckedValue();

      // 'cy' attribute - default is 0
      AbstractSVGAnimatedLength _cy = (AbstractSVGAnimatedLength) ce.getCy();
      float cy = _cy.getCheckedValue();

      // 'r' attribute - required
      AbstractSVGAnimatedLength _r = (AbstractSVGAnimatedLength) ce.getR();
      float r = _r.getCheckedValue();

      float x = cx - r;
      float y = cy - r;
      float w = r * 2;
      shapeNode.setShape(new Ellipse2D.Float(x, y, w, w));
    } catch (LiveAttributeException ex) {
      throw new BridgeException(ctx, ex);
    }
  }
 protected ShapePainter createShapePainter(BridgeContext ctx, Element e, ShapeNode shapeNode) {
   Rectangle2D r2d = shapeNode.getShape().getBounds2D();
   if ((r2d.getWidth() == 0) || (r2d.getHeight() == 0)) return null;
   return super.createShapePainter(ctx, e, shapeNode);
 }