Exemplo n.º 1
0
  @Override
  public CanvasPainter showAction(
      SVGHandle handle,
      int level,
      Set<Element> elementSet,
      SelectionItem item,
      Point2D firstPoint,
      Point2D currentPoint) {

    // getting the element that will undergo the action
    Element element = elementSet.iterator().next();

    // the canvas painter that should be returned
    CanvasPainter painter = null;

    // whether the shape should be painted
    boolean canPaintShape = true;

    // the shape that will be painted
    Shape shape = null;

    // getting the action transform
    AffineTransform actionTransform = null;

    switch (level) {
      case 0:

        // getting the resize transform
        actionTransform = getResizeTransform(handle, element, item, firstPoint, currentPoint);
        break;

      case 1:
        if (item.getType() == SelectionItem.CENTER) {

          // storing the center point for the rotate action
          rotationSkewSelectionItemCenterPoint = currentPoint;
          item.setPoint(currentPoint);
          canPaintShape = false;

        } else if (item.getType() == SelectionItem.NORTH_WEST
            || item.getType() == SelectionItem.NORTH_EAST
            || item.getType() == SelectionItem.SOUTH_EAST
            || item.getType() == SelectionItem.SOUTH_WEST) {

          // getting the rotation transform
          actionTransform = getRotationTransform(handle, element, firstPoint, currentPoint);

        } else {

          // getting the skew transform
          actionTransform = getSkewTransform(handle, element, firstPoint, currentPoint, item);
        }

        break;
    }

    if (actionTransform != null) {

      // getting the initial shape
      shape = getShape(handle, element, true);

      // getting the element's transform
      AffineTransform transform = handle.getSvgElementsManager().getTransform(element);

      // concatenating the action transform to the element's transform
      transform.preConcatenate(actionTransform);

      // computing the screen scaled shape
      shape = handle.getTransformsManager().getScaledShape(shape, false, transform);
    }

    if (canPaintShape && shape != null) {

      final Shape fshape = shape;

      // creating the set of the clips
      final HashSet<Rectangle2D> fclips = new HashSet<Rectangle2D>();
      fclips.add(fshape.getBounds2D());

      painter =
          new CanvasPainter() {

            @Override
            public void paintToBeDone(Graphics2D g) {

              g = (Graphics2D) g.create();
              g.setRenderingHint(
                  RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
              g.setColor(strokeColor);
              g.draw(fshape);
              g.dispose();
            }

            @Override
            public Set<Rectangle2D> getClip() {

              return fclips;
            }
          };
    }

    return painter;
  }