Ejemplo n.º 1
0
  /**
   * Draws the background to the specified graphics device. If the dial frame specifies a window,
   * the clipping region will already have been set to this window before this method is called.
   *
   * @param g2 the graphics device (<code>null</code> not permitted).
   * @param plot the plot (ignored here).
   * @param frame the dial frame (ignored here).
   * @param view the view rectangle (<code>null</code> not permitted).
   */
  @Override
  public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    // work out the anchor point
    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius);
    Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN);
    Point2D pt = arc.getStartPoint();

    // the indicator bounds is calculated from the templateValue (which
    // determines the minimum size), the maxTemplateValue (which, if
    // specified, provides a maximum size) and the actual value
    FontMetrics fm = g2.getFontMetrics(this.font);
    double value = plot.getValue(this.datasetIndex);
    String valueStr = this.formatter.format(value);
    Rectangle2D valueBounds = TextUtilities.getTextBounds(valueStr, g2, fm);

    // calculate the bounds of the template value
    String s = this.formatter.format(this.templateValue);
    Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm);
    double minW = tb.getWidth();
    double minH = tb.getHeight();

    double maxW = Double.MAX_VALUE;
    double maxH = Double.MAX_VALUE;
    if (this.maxTemplateValue != null) {
      s = this.formatter.format(this.maxTemplateValue);
      tb = TextUtilities.getTextBounds(s, g2, fm);
      maxW = Math.max(tb.getWidth(), minW);
      maxH = Math.max(tb.getHeight(), minH);
    }
    double w = fixToRange(valueBounds.getWidth(), minW, maxW);
    double h = fixToRange(valueBounds.getHeight(), minH, maxH);

    // align this rectangle to the frameAnchor
    Rectangle2D bounds =
        RectangleAnchor.createRectangle(new Size2D(w, h), pt.getX(), pt.getY(), this.frameAnchor);

    // add the insets
    Rectangle2D fb = this.insets.createOutsetRectangle(bounds);

    // draw the background
    g2.setPaint(this.backgroundPaint);
    g2.fill(fb);

    // draw the border
    g2.setStroke(this.outlineStroke);
    g2.setPaint(this.outlinePaint);
    g2.draw(fb);

    // now find the text anchor point
    Shape savedClip = g2.getClip();
    g2.clip(fb);

    Point2D pt2 = RectangleAnchor.coordinates(bounds, this.valueAnchor);
    g2.setPaint(this.paint);
    g2.setFont(this.font);
    TextUtilities.drawAlignedString(
        valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.textAnchor);
    g2.setClip(savedClip);
  }
Ejemplo n.º 2
0
  /**
   * WhiteboardShapeRect constructor.
   *
   * @param id String that uniquely identifies this WhiteboardShapeRect
   * @param thickness number of pixels that this object (or its border) should be thick
   * @param color WhiteboardShapeRect's color (or rather it's border)
   * @param point coordinates of this object.
   * @param width width value of this object (in pixel)
   * @param height height value of this object (in pixel)
   * @param fill True is filled, false is unfilled
   * @param transform 2D affine transformation
   */
  public WhiteboardShapeRect(
      String id,
      int thickness,
      Color color,
      WhiteboardPoint point,
      double width,
      double height,
      boolean fill,
      AffineTransform transform) {
    super(id);

    Point2D v0 = new Point2D.Double(point.getX(), point.getY());
    Point2D w0 = transform.transform(v0, null);

    double x = w0.getX();
    double y = w0.getY();

    point.setX(x);
    point.setY(y);

    Point2D v1 = new Point2D.Double(x + width, y + height);
    Point2D w1 = transform.transform(v1, null);

    double transformedWidth = w1.getX() - x;
    double transformedHeight = w1.getY() - y;

    this.initShape(thickness, color, point, transformedWidth, transformedHeight, fill);
  }
Ejemplo n.º 3
0
  @Override
  public void Zoom(BigDecimal Percent, Point2D Center) {
    CurrentZoom = Percent;

    // distance between first point and center
    BigDecimal X1Distance = new BigDecimal(Double.toString(Center.getX())).subtract(X1);
    BigDecimal Y1Distance = new BigDecimal(Double.toString(Center.getY())).subtract(Y1);
    // distance between second point and center
    BigDecimal X2Distance = new BigDecimal(Double.toString(Center.getX())).subtract(X2);
    BigDecimal Y2Distance = new BigDecimal(Double.toString(Center.getY())).subtract(Y2);

    X1Distance = X1Distance.multiply(Percent);
    Y1Distance = Y1Distance.multiply(Percent);
    X2Distance = X2Distance.multiply(Percent);
    Y2Distance = Y2Distance.multiply(Percent);

    X1New = new BigDecimal(Double.toString(Center.getX())).subtract(X1Distance);
    Y1New = new BigDecimal(Double.toString(Center.getY())).subtract(Y1Distance);
    X2New = new BigDecimal(Double.toString(Center.getX())).subtract(X2Distance);
    Y2New = new BigDecimal(Double.toString(Center.getY())).subtract(Y2Distance);

    MainLine =
        new Line2D.Double(
            X1New.doubleValue(), Y1New.doubleValue(), X2New.doubleValue(), Y2New.doubleValue());
  }
Ejemplo n.º 4
0
 public double determinant() {
   final double ux = a.getX() - o.getX();
   final double uy = a.getY() - o.getY();
   final double vx = b.getX() - o.getX();
   final double vy = b.getY() - o.getY();
   return ux * vy - uy * vx;
 }
Ejemplo n.º 5
0
 public int compare(Point2D left, Point2D right) {
   if (left.getX() < right.getX()) return -1;
   if (left.getX() > right.getX()) return 1;
   if (left.getY() < right.getY()) return -1;
   if (left.getY() > right.getY()) return 1;
   return 0;
 }
Ejemplo n.º 6
0
 /**
  * Return the raster coordinate denoted by the given world coordinate. This method is CENTER and
  * OUTER aware.
  *
  * @param worldX x position in the world coordinate system, for which raster coordinates should be
  *     calculated.
  * @param worldY y position in the world coordinate system, for which raster coordinates should be
  *     calculated.
  * @return the (rounded) raster coordinate which the given world coordinate maps to.
  */
 public int[] getRasterCoordinate(double worldX, double worldY) {
   Point2D rslt = invTransform.transform(new Point2D.Double(worldX, worldY), null);
   if (location == CENTER) {
     return new int[] {(int) round(rslt.getX()), (int) round(rslt.getY())};
   }
   return new int[] {(int) floor(rslt.getX()), (int) floor(rslt.getY())};
 }
Ejemplo n.º 7
0
  @SuppressWarnings("deprecation")
  private void doOverlayImage(GC gc) {
    Point2D lowerLeft = new Point2D.Double(overlayEnvelope.getMinX(), overlayEnvelope.getMinY());
    worldToScreen.transform(lowerLeft, lowerLeft);

    Point2D upperRight = new Point2D.Double(overlayEnvelope.getMaxX(), overlayEnvelope.getMaxY());
    worldToScreen.transform(upperRight, upperRight);

    Rectangle bounds = overlayImage.getBounds();
    if (overlayDoXor) {
      gc.setXORMode(true);
    }

    gc.drawImage(
        overlayImage, //
        0, //
        0, //
        bounds.width, //
        bounds.height, //
        (int) lowerLeft.getX(), //
        (int) upperRight.getY(), //
        (int) (upperRight.getX() - lowerLeft.getX()), //
        (int) Math.abs(upperRight.getY() - lowerLeft.getY()) //
        );
    if (overlayDoXor) {
      gc.setXORMode(false);
    }
  }
Ejemplo n.º 8
0
 @Override
 public void paint(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   Stroke initialStroke = g2.getStroke();
   Color initialColor = g2.getColor();
   if (drawConcrete) {
     g2.setColor(Color.LIGHT_GRAY);
     g2.fill(getBounds());
   }
   g2.translate(loc.getX(), loc.getY());
   g2.rotate(rot);
   if (picture != null) {
     g2.drawImage(picture, -picture.getWidth(null) / 2, -picture.getHeight(null) / 2, null);
   }
   g2.setStroke(stroke);
   for (int i = 0; i < complexity; i++) {
     g2.translate(rLoc[i].getX(), rLoc[i].getY());
     g2.rotate(rRot[i]);
     g2.setColor(rCol[i]);
     if (rFill[i]) {
       g2.fill(rShape[i]);
     } else {
       g2.draw(rShape[i]);
     }
     g2.rotate(-rRot[i]);
     g2.translate(-rLoc[i].getX(), -rLoc[i].getY());
   }
   g2.setColor(initialColor);
   g2.setStroke(initialStroke);
   g2.rotate(-rot);
   g2.translate(-loc.getX(), -loc.getY());
 }
Ejemplo n.º 9
0
  /**
   * returns the center of the graph layout as a Point 2D The center of the graph is calculated as
   * the median of x and y coordinates of all nodes
   *
   * @return the center of the graph
   */
  public Point2D getCenter() {
    if (this.getVertexCount() > 0) {

      // initialize coords with first vertex location
      VisualNode v = this.getVertices().get(0);
      double minX = this.getLocation(v).getX();
      double minY = this.getLocation(v).getY();
      double maxX = this.getLocation(v).getX();
      double maxY = this.getLocation(v).getY();

      for (VisualNode jungNode : this.getVertices()) {
        if (jungNode.getVisible()) {
          Point2D p = this.getLocation(jungNode);
          minX = (minX > p.getX() ? p.getX() : minX);
          minY = (minY > p.getY() ? p.getY() : minY);
          maxX = (maxX < p.getX() ? p.getX() : maxX);
          maxY = (maxY < p.getY() ? p.getY() : maxY);
        }
      }

      return new Point2D.Double((maxX + minX) / 2, (maxY + minY) / 2);
    }
    // else return default
    return new Point2D.Double();
  }
Ejemplo n.º 10
0
  /**
   * returns the skew transform
   *
   * @param svgHandle a svg handle
   * @param bounds the bounds of the area to transform
   * @param firstPoint the first clicked point by the user
   * @param currentPoint the current point of the drag action by the user
   * @param item the selection item
   * @return the skew transform
   */
  protected AffineTransform getSkewTransform(
      SVGHandle svgHandle,
      Rectangle2D bounds,
      Point2D firstPoint,
      Point2D currentPoint,
      SelectionItem item) {

    // getting the skew factor
    double skewX = 0, skewY = 0;
    boolean isHorizontal =
        (item.getType() == SelectionItem.NORTH || item.getType() == SelectionItem.SOUTH);

    if (bounds.getWidth() > 0 && bounds.getHeight() > 0) {

      if (isHorizontal) {

        skewX = (currentPoint.getX() - firstPoint.getX()) / bounds.getHeight();

      } else {

        skewY = (currentPoint.getY() - firstPoint.getY()) / bounds.getWidth();
      }
    }

    // getting the center point
    Point2D centerPoint = getRotationSkewCenterPoint(svgHandle, bounds);

    // creating the affine transform
    AffineTransform af =
        AffineTransform.getTranslateInstance(-centerPoint.getX(), -centerPoint.getY());
    af.preConcatenate(AffineTransform.getShearInstance(skewX, skewY));
    af.preConcatenate(AffineTransform.getTranslateInstance(centerPoint.getX(), centerPoint.getY()));

    return af;
  }
Ejemplo n.º 11
0
 /**
  * Rotates a two-dimensional vector by the angle alpha.
  *
  * @param p point
  * @param alpha angle in radian
  * @return q point rotated around origin
  */
 public static Point2D rotate(Point2D p, double alpha) {
   double sina = Math.sin(alpha);
   double cosa = Math.cos(alpha);
   Point2D q = new Point2D.Double();
   q.setLocation(p.getX() * cosa - p.getY() * sina, p.getX() * sina + p.getY() * cosa);
   return q;
 }
Ejemplo n.º 12
0
  protected PointOfInterest standingOrder(Point2D whereIAm) {
    Point2D target =
        new Point2D.Double(
            whereIAm.getX() + (spiralHeading.getDx() * MOVEMENT_LENGTH),
            whereIAm.getY() + (spiralHeading.getDy() * MOVEMENT_LENGTH));

    while (!StaticDiver.pointIsOnBoard(target.getX(), target.getY(), boardRadius)) {
      switch (spiralHeading) {
        case N:
          spiralHeading = Direction.W;
          break;
        case E:
          spiralHeading = Direction.N;
          break;
        case S:
          spiralHeading = Direction.E;
          break;
        case W:
          spiralHeading = Direction.S;
          break;
      }

      target =
          new Point2D.Double(
              whereIAm.getX() + (spiralHeading.getDx() * MOVEMENT_LENGTH),
              whereIAm.getY() + (spiralHeading.getDy() * MOVEMENT_LENGTH));
    }

    return new PointOfInterest(target);
  }
Ejemplo n.º 13
0
  private KeyFrame interpolateStraightLine(KeyFrame start, KeyFrame end, double timestamp) {
    Point2D startPoint = start.getPosition();
    Point2D endPoint = end.getPosition();
    double ds = start.getTimestamp();
    double duration = end.getTimestamp() - ds;
    double d = (timestamp - ds) / duration;
    double x1 = startPoint.getX();
    double y1 = startPoint.getY();
    double x2 = endPoint.getX();
    double y2 = endPoint.getY();
    double x = x1 + d * (x2 - x1);
    double y = y1 + d * (y2 - y1);
    Double p = new Point2D.Double(x, y);

    KeyFrame frame =
        new KeyFrame(
            TrajectoryMovement.LINE,
            start.getMovementSpeed(),
            end.getOrientation(),
            0,
            0,
            p,
            timestamp,
            start.getSourceLine());
    return frame;
  }
Ejemplo n.º 14
0
  public ROI2DRectShape(RectangularShape shape, Point2D topLeft, Point2D bottomRight, boolean cm) {
    super(shape);

    this.topLeft = createAnchor(topLeft);
    this.topRight = createAnchor(bottomRight.getX(), topLeft.getY());
    this.bottomLeft = createAnchor(topLeft.getX(), bottomRight.getY());
    this.bottomRight = createAnchor(bottomRight);

    // add to the control point list
    controlPoints.add(this.topLeft);
    controlPoints.add(this.topRight);
    controlPoints.add(this.bottomLeft);
    controlPoints.add(this.bottomRight);

    this.topLeft.addListener(this);
    this.topRight.addListener(this);
    this.bottomLeft.addListener(this);
    this.bottomRight.addListener(this);

    // select the bottom right point as we use it to size the ellipse in "creation mode"
    if (cm) this.bottomRight.setSelected(true);
    setMousePos(bottomRight);

    updateShape();
  }
Ejemplo n.º 15
0
  private PBounds addNode(HierarchyNodeView from, HierarchyNodeView toNode, boolean addChildren) {
    PBounds bounds = toNode.node.getBounds();

    final PSWTPath path = new PSWTPath();
    Point2D to = toNode.node.getCenter();
    Point2D fromP = from.node.getCenter();
    if (!addChildren) {
      fromP.setLocation(fromP.getX(), fromP.getY() - (from.node.getHeight() / 2.0));
      to.setLocation(to.getX(), to.getY() + (toNode.node.getHeight() / 2.0));
    } else {
      fromP.setLocation(fromP.getX(), fromP.getY() + (from.node.getHeight() / 2.0));
      to.setLocation(to.getX(), to.getY() - (toNode.node.getHeight() / 2.0));
    }

    path.setPathToPolyline(new Point2D[] {fromP, to});
    getLayer().addChild(path);
    path.moveToBack();
    path.addInputEventListener(
        new PBasicInputEventHandler() {
          @Override
          public void mouseEntered(PInputEvent event) {
            path.setStrokeColor(Color.LIGHT_GRAY);
          }

          @Override
          public void mouseExited(PInputEvent event) {
            path.setStrokeColor(Color.BLACK);
          }
        });
    return bounds;
  }
  /**
   * check the modifiers. If accepted, use the mouse drag motion to rotate the graph in the master
   * view
   */
  public void mouseDragged(MouseEvent e) {
    if (down == null) return;
    VisualizationViewer vv = (VisualizationViewer) e.getSource();
    boolean accepted = checkModifiers(e);
    if (accepted) {
      if (vv instanceof SatelliteVisualizationViewer) {
        VisualizationViewer vvMaster = ((SatelliteVisualizationViewer) vv).getMaster();

        MutableTransformer modelTransformerMaster = vvMaster.getLayoutTransformer();

        // rotate
        vv.setCursor(cursor);
        // I want to compute rotation based on the view coordinates of the
        // lens center in the satellite view.
        // translate the master view center to layout coords, then translate
        // that point to the satellite view's view coordinate system....
        Point2D center = vv.transform(vvMaster.inverseTransform(vvMaster.getCenter()));
        Point2D q = down;
        Point2D p = e.getPoint();
        Point2D v1 = new Point2D.Double(center.getX() - p.getX(), center.getY() - p.getY());
        Point2D v2 = new Point2D.Double(center.getX() - q.getX(), center.getY() - q.getY());
        double theta = angleBetween(v1, v2);
        modelTransformerMaster.rotate(-theta, vvMaster.inverseViewTransform(vvMaster.getCenter()));
        down.x = e.getX();
        down.y = e.getY();
      }
      e.consume();
    }
  }
Ejemplo n.º 17
0
  /**
   * algorithm taken from DistancePoint.java DistancePointSegmentExample, calculate distance to line
   * Copyright (C) 2008 Pieter Iserbyt <*****@*****.**> Alogrithm found via Stack Overflow
   * page at: http: //stackoverflow.com/questions/849211/shortest-distance-between-a-point-
   * and-a-line-segment
   *
   * @param lineStart point (in degs) for line start
   * @param lineEnd point (in degs) for line end
   * @param tgtPoint point (in degs) for point of interest
   * @return distance in degs from line to point
   */
  private static double distanceToSegment(
      final Point2D lineStart, final Point2D lineEnd, final Point2D tgtPoint) {

    final double xDelta = lineEnd.getX() - lineStart.getX();
    final double yDelta = lineEnd.getY() - lineStart.getY();

    if ((xDelta == 0) && (yDelta == 0)) {
      throw new IllegalArgumentException("lineStart and lineEnd cannot be the same point");
    }

    final double u =
        ((tgtPoint.getX() - lineStart.getX()) * xDelta
                + (tgtPoint.getY() - lineStart.getY()) * yDelta)
            / (xDelta * xDelta + yDelta * yDelta);

    final Point2D closestPoint;
    if (u < 0) {
      closestPoint = lineStart;
    } else if (u > 1) {
      closestPoint = lineEnd;
    } else {
      closestPoint =
          new Point2D.Double(lineStart.getX() + u * xDelta, lineStart.getY() + u * yDelta);
    }

    return closestPoint.distance(tgtPoint);
  }
Ejemplo n.º 18
0
 private Point2D getTextBlockPosition(StringBounder stringBounder) {
   final Point2D pt1 = worm.get(0);
   final Point2D pt2 = worm.get(1);
   final Dimension2D dim = textBlock.calculateDimension(stringBounder);
   final double y = (pt1.getY() + pt2.getY()) / 2 - dim.getHeight() / 2;
   return new Point2D.Double(Math.max(pt1.getX(), pt2.getX()) + 4, y);
 }
Ejemplo n.º 19
0
  @Override
  public void paintComponent(Graphics g) {

    // Get Graphics2D
    Graphics2D g2d = (Graphics2D) g;
    Rectangle box = new Rectangle(5, 10, 15, 20);
    g2d.setColor(new Color(255, 128, 222));
    g2d.draw(box);
    box.translate(
        10,
        30); // move shape and redraw box. cannot call Rectangle box2 = box.translate() as
             // translate() returns void
    g2d.draw(box);
    Ellipse2D comp2 = new Ellipse2D.Double(30, 100, 140, 220);

    Point2D from = new Point2D.Double(30, 90);
    Point2D to = new Point2D.Double(300, 320);
    Line2D comp3 = new Line2D.Double(from, to);
    g2d.draw(comp2);
    g2d.draw(comp3);

    double diffX = Math.abs(from.getX() - to.getX());
    double diffY = Math.abs(from.getY() - to.getY());
    System.out.println(String.format("diffX = %3.2f, diffY = %3.2f", diffX, diffY));
    double pythag = Math.sqrt(Math.pow(diffX, 2) + Math.pow(diffY, 2));
    g2d.drawString(String.format("Line Length = %3.3f", pythag), 200, 20);
  }
Ejemplo n.º 20
0
  private ShapeData getShapes(Vector vPoints) {
    /* A partir d'una seqüència de punts retorna una agrupació d'aquests en
    forma de figura geomètrica*/
    if (vPoints == null) return null;
    ShapeData sd = new ShapeData();
    int iCurrentPoint = 0;
    boolean bFi = false;
    while ((iCurrentPoint + 1) < vPoints.size()) {
      boolean bPassed = false;
      int i = 1;
      for (i = 1; (iCurrentPoint + i) < vPoints.size() && !bPassed; i++) {
        float d = getPerdua(vPoints, iCurrentPoint, iCurrentPoint + i);
        bPassed = (d > maxFactor);
        // float d=getMaxPerdua(vPoints,iCurrentPoint, iCurrentPoint+i);
        // bPassed=(d>.5);
      }
      Line2D.Float l;
      Point2D p;
      if (iCurrentPoint == 0) {
        p = (Point2D) vPoints.elementAt(iCurrentPoint);
        sd.moveTo(p.getX(), p.getY());
      }
      if ((iCurrentPoint + i) < vPoints.size()) p = (Point2D) vPoints.elementAt(iCurrentPoint + i);
      else p = (Point2D) vPoints.elementAt(iCurrentPoint + i - 1);
      sd.lineTo(p.getX(), p.getY());

      iCurrentPoint = iCurrentPoint + i;
    }
    return sd;
  }
Ejemplo n.º 21
0
  /**
   * Draws the graphic item within the specified area.
   *
   * @param g2 the graphics device.
   * @param area the area.
   */
  public void draw(Graphics2D g2, Rectangle2D area) {
    area = (Rectangle2D) area.clone();
    area = trimMargin(area);
    drawBorder(g2, area);
    area = trimBorder(area);
    area = trimPadding(area);

    if (this.lineVisible) {
      Point2D location = RectangleAnchor.coordinates(area, this.shapeLocation);
      Shape aLine =
          ShapeUtilities.createTranslatedShape(
              getLine(), this.shapeAnchor, location.getX(), location.getY());
      g2.setPaint(this.linePaint);
      g2.setStroke(this.lineStroke);
      g2.draw(aLine);
    }

    if (this.shapeVisible) {
      Point2D location = RectangleAnchor.coordinates(area, this.shapeLocation);

      Shape s =
          ShapeUtilities.createTranslatedShape(
              this.shape, this.shapeAnchor, location.getX(), location.getY());
      if (this.shapeFilled) {
        g2.setPaint(this.fillPaint);
        g2.fill(s);
      }
      if (this.shapeOutlineVisible) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.outlineStroke);
        g2.draw(s);
      }
    }
  }
Ejemplo n.º 22
0
  /**
   * Moves a Steiner Point towards the furthest neighbor
   *
   * @param source
   * @param target
   */
  private void moveTowards(Point source, Point target) {

    Point2D s = new Point2D.Double();
    Point2D t = new Point2D.Double();
    Point2D previousLocation = new Point2D.Double();
    s.setLocation(source.x, source.y);
    previousLocation.setLocation(source.x, source.y);
    t.setLocation(target.x, target.y);

    // in each step move 1 unit forward towards the target
    double step_size = 1;
    // previous PCR : Stop moving when previousPCR is better than current one.
    double previousPCR = source.getPCR();

    int distance =
        (int) Math.floor(GraphUtils.euclideanDistance(source.x, source.y, target.x, target.y));
    for (int i = 0; i < distance; i += step_size) {
      Point2D currentLocation =
          GraphUtils.getCoordinates(source.x, source.y, target.x, target.y, step_size);
      source.x = currentLocation.getX();
      source.y = currentLocation.getY();
      double currentPCR = source.getPCR();

      if (currentPCR < previousPCR) {
        previousPCR = currentPCR;
        previousLocation = currentLocation;
      } else {
        // move backwards
        source.x = previousLocation.getX();
        source.y = previousLocation.getY();
      }
    }
  }
  /**
   * Method paint. Paints the rings on the graph.
   *
   * @param g Graphics - the graphics to be painted.
   */
  @Override
  public void paint(Graphics g) {
    Collection<Double> depths = getDepths();
    g.setColor(Color.gray);
    Graphics2D g2d = (Graphics2D) g;
    Point2D center = radialLayout.getCenter();

    Ellipse2D ellipse = new Ellipse2D.Double();
    for (double d : depths) {
      ellipse.setFrameFromDiagonal(
          center.getX() - d, center.getY() - d, center.getX() + d, center.getY() + d);
      AffineTransform at = AffineTransform.getTranslateInstance(0, 0);
      Shape shape = at.createTransformedShape(ellipse);
      // Shape shape =
      //	vv.getRenderContext().getMultiLayerTransformer().transform(ellipse);
      //
      //	vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).transform(ellipse);

      MutableTransformer viewTransformer =
          vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW);

      if (viewTransformer instanceof MutableTransformerDecorator) {
        shape = vv.getRenderContext().getMultiLayerTransformer().transform(shape);
      } else {
        shape = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, shape);
      }
      g2d.draw(shape);
    }
  }
Ejemplo n.º 24
0
 private static boolean isInsideClip(Point2D p, Side side, Rectangle2D boundingBox) {
   if (side == Side.top) return (p.getY() <= boundingBox.getMaxY());
   else if (side == Side.bottom) return (p.getY() >= boundingBox.getMinY());
   else if (side == Side.left) return (p.getX() >= boundingBox.getMinX());
   else if (side == Side.right) return (p.getX() <= boundingBox.getMaxX());
   else throw new RuntimeException("Error in Polygon");
 }
Ejemplo n.º 25
0
  /**
   * Code to paint the WhiteboardShapeRect.
   *
   * @param g graphics context
   * @param t 2D affine transformation
   */
  public void paintShape(Graphics2D g, AffineTransform t) {
    double x = point.getX();
    double y = point.getY();

    g.setStroke(new BasicStroke(this.getThickness(), BasicStroke.CAP_ROUND, BasicStroke.CAP_ROUND));

    Point2D w0 = new Point2D.Double(x, y);
    Point2D v0 = t.transform(w0, null);

    int x0 = (int) v0.getX();
    int y0 = (int) v0.getY();

    Point2D w1 = new Point2D.Double(x + width, y + height);
    Point2D v1 = t.transform(w1, null);

    int xWidth = (int) v1.getX() - x0;
    int yHeight = (int) v1.getY() - y0;

    g.setColor(Color.getColor("", this.getColor()));
    if (fill) {
      g.fillRect(x0, y0, xWidth, yHeight);
    } else {
      g.drawRect(x0, y0, xWidth, yHeight);
    }
  }
 public void run(double frac) {
   TupleSet ts = m_vis.getFocusGroup(Visualization.FOCUS_ITEMS);
   // System.err.println("auto-panning"+frac);
   if (ts.getTupleCount() == 0) return;
   if (frac == 0.0) {
     int xbias = 0, ybias = 0;
     switch (m_orientation) {
       case Constants.ORIENT_LEFT_RIGHT:
         xbias = m_bias;
         break;
       case Constants.ORIENT_RIGHT_LEFT:
         xbias = -m_bias;
         break;
       case Constants.ORIENT_TOP_BOTTOM:
         ybias = m_bias;
         break;
       case Constants.ORIENT_BOTTOM_TOP:
         ybias = -m_bias;
         break;
     }
     VisualItem vi = (VisualItem) ts.tuples().next();
     m_cur.setLocation(getWidth() / 2, getHeight() / 2);
     getAbsoluteCoordinate(m_cur, m_start);
     m_end.setLocation(vi.getX() + xbias, vi.getY() + ybias);
   } else {
     m_cur.setLocation(
         m_start.getX() + frac * (m_end.getX() - m_start.getX()),
         m_start.getY() + frac * (m_end.getY() - m_start.getY()));
     panToAbs(m_cur);
   }
 }
Ejemplo n.º 27
0
  /**
   * Cuando soltamos el botón del ratón desplazamos la imagen a la posición de destino calculando el
   * extent nuevamente.
   */
  public void mouseReleased(MouseEvent e) throws BehaviorException {
    if (!isActiveTool()) return;
    if (e.getButton() == MouseEvent.BUTTON1 && isMoveable) {
      FLyrRasterSE lyr = grBehavior.getLayer();
      if (lyr == null) return;

      ViewPort vp = grBehavior.getMapControl().getMapContext().getViewPort();
      ptoFin = vp.toMapPoint(e.getPoint());

      // Asignamos la nueva matriz de transformación a la capa
      AffineTransform atOld = lyr.getAffineTransform();
      AffineTransform atNew = null;

      double distX = ptoFin.getX() - ptoIni.getX();
      double distY = ptoFin.getY() - ptoIni.getY();

      // La nueva matriz de transformación es la vieja más la distancia desplazada
      atNew =
          new AffineTransform(
              atOld.getScaleX(),
              atOld.getShearY(),
              atOld.getShearX(),
              atOld.getScaleY(),
              atOld.getTranslateX() + distX,
              atOld.getTranslateY() + distY);
      lyr.setAffineTransform(atNew);

      grBehavior.getMapControl().getMapContext().invalidate();
      isMoveable = false;
      super.mouseReleased(e);
    }
  }
 public void run(double frac) {
   System.err.println("auto-centering" + frac);
   if (frac == 0.0) {
     int xbias = 0, ybias = 0;
     switch (m_orientation) {
       case Constants.ORIENT_LEFT_RIGHT:
         xbias = m_bias;
         break;
       case Constants.ORIENT_RIGHT_LEFT:
         xbias = -m_bias;
         break;
       case Constants.ORIENT_TOP_BOTTOM:
         ybias = m_bias;
         break;
       case Constants.ORIENT_BOTTOM_TOP:
         ybias = -m_bias;
         break;
     }
     Rectangle2D vb = m_vis.getBounds(TREE);
     m_cur.setLocation(getWidth() / 2, getHeight() / 2);
     getAbsoluteCoordinate(m_cur, m_start);
     m_end.setLocation(vb.getX() + xbias, vb.getY() + ybias);
   } else {
     m_cur.setLocation(
         m_start.getX() + frac * (m_end.getX() - m_start.getX()),
         m_start.getY() + frac * (m_end.getY() - m_start.getY()));
     panToAbs(m_cur);
   }
 }
Ejemplo n.º 29
0
    /** Turns a List<CubicCurve2D.Float> into a SVG Element representing a sketch of that spline. */
    Element splineToSketch(SVGDocument document, List<CubicCurve2D.Float> spline) {
      String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;

      // <g> is an SVG group
      // TODO: add a random(ish) rotation to the group
      Element group = document.createElementNS(svgNS, "g");

      // For each curve in the path, draw along it using a "brush".  In
      // our case the brush is a simple circle, but this could be changed
      // to something more advanced.
      for (CubicCurve2D.Float curve : spline) {
        // TODO: magic number & step in loop guard
        for (double i = 0.0; i <= 1.0; i += 0.01) {
          Point2D result = evalParametric(curve, i);

          // Add random jitter at some random positive or negative
          // distance along the unit normal to the tangent of the
          // curve
          Point2D n = vectorUnitNormal(evalParametricTangent(curve, i));
          float dx = (float) ((Math.random() - 0.5) * n.getX());
          float dy = (float) ((Math.random() - 0.5) * n.getY());

          Element brush = document.createElementNS(svgNS, "circle");
          brush.setAttribute("cx", Double.toString(result.getX() + dx));
          brush.setAttribute("cy", Double.toString(result.getY() + dy));
          // TODO: magic number for circle radius
          brush.setAttribute("r", Double.toString(1.0));
          brush.setAttribute("fill", "green");
          brush.setAttributeNS(null, "z-index", Integer.toString(zOrder.CONTOUR.ordinal()));
          group.appendChild(brush);
        }
      }

      return group;
    }
Ejemplo n.º 30
0
  public void mousePressed(MouseEvent e) {
    if (getArrowsDrawn()) {
      if (renderXForm != null) {
        double LeftX = ULCornerScreenSpace.getX();
        double RightX = BRCornerScreenSpace.getX();

        double TopYBottomArrow = ULCornerOfBottomArrow.getY();
        double BottomYBottomArrow = BRCornerScreenSpace.getY();
        double BottomYTopArrow = BRCornerOfTopArrow.getY();
        double TopYTopArrow = ULCornerScreenSpace.getY();
        int eX = e.getX();
        int eY = e.getY();

        double tolerance = 0.1;

        if ((eX >= (LeftX - tolerance)) & (eX <= (RightX + tolerance))) {
          if ((eY >= (TopYBottomArrow - tolerance)) & (eY <= (BottomYBottomArrow + tolerance))) {
            changeLoadAmount(-getDeltaPerMouseClick());
          } else if ((eY >= (TopYTopArrow - tolerance)) & (eY <= (BottomYTopArrow + tolerance))) {
            changeLoadAmount(+getDeltaPerMouseClick());
          }
        }
      }
    }
  }