/**
   * 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);
    }
  }
  /**
   * 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);
  }
示例#3
0
  /**
   * Code to paint the specific shape
   *
   * @param w2v 2D affine transform
   * @param g graphics context
   */
  public void paintShape(Graphics2D g, AffineTransform w2v) {
    double x = startPoint.getX();
    double y = startPoint.getY();
    double xEnd = endPoint.getX();
    double yEnd = endPoint.getY();

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

    Point2D v0 = w2v.transform(new Point2D.Double(x, y), null);
    int ix = (int) v0.getX();
    int iy = (int) v0.getY();

    Point2D v1 = w2v.transform(new Point2D.Double(xEnd, yEnd), null);

    g.drawLine(ix, iy, (int) v1.getX(), (int) v1.getY());
  }
示例#4
0
  /**
   * Tests if a point p is over a selection point.
   *
   * @param p point
   * @return nearest selection point
   */
  public WhiteboardPoint getSelectionPoint(Point2D p) {
    WhiteboardPoint givenPoint = new WhiteboardPoint(p.getX(), p.getY());

    if (startPoint.distance(givenPoint) < 10) return startPoint;
    else if (endPoint.distance(givenPoint) < 10) return endPoint;

    return null;
  }
  /**
   * Tests if a point p is over a selection point.
   *
   * @param p point
   * @return nearest selection point
   */
  public WhiteboardPoint getSelectionPoint(Point2D p) {
    WhiteboardPoint givenPoint = new WhiteboardPoint(p.getX(), p.getY());

    for (int i = 0; i < selectionPoints.size(); i++) {
      WhiteboardPoint point = (WhiteboardPoint) selectionPoints.get(i);

      if (point.distance(givenPoint) < 18) return point;
    }

    return null;
  }
示例#6
0
  /**
   * Tests if the shape contains a point.
   *
   * @param p coord point
   * @return true if shape contains p
   */
  public boolean contains(Point2D p) {
    double x = startPoint.getX();
    double y = startPoint.getY();

    double xEnd = endPoint.getX();
    double yEnd = endPoint.getY();

    Line2D line = new Line2D.Double(x, y, xEnd, yEnd);

    return line.intersects(p.getX(), p.getY(), 10, 10);
  }
示例#7
0
  /**
   * WhiteboardShapeLine constructor
   *
   * @param id String that uniquely identifies this WhiteboardObject.
   * @param t number of pixels that this object (or its border)
   * @param c WhiteboardShapeLine's color (or rather it's border)
   * @param startPoint the start coordinates of this line.
   * @param endPoint the end coordinates of this line.
   * @param v2w 2D affine transform
   */
  public WhiteboardShapeLine(
      String id,
      int t,
      Color c,
      WhiteboardPoint startPoint,
      WhiteboardPoint endPoint,
      AffineTransform v2w) {
    super(id);
    this.setThickness(t);
    setColor(c);

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

    this.startPoint = new WhiteboardPoint(w0.getX(), w0.getY());

    Point2D v1 = new Point2D.Double(endPoint.getX(), endPoint.getY());
    Point2D w1 = v2w.transform(v1, null);

    this.endPoint = new WhiteboardPoint(w1.getX(), w1.getY());
  }