Пример #1
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);
  }
Пример #2
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);
    }
  }
Пример #3
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;
  }
Пример #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());

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

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

    return null;
  }
Пример #5
0
  /**
   * Translates the shape.
   *
   * @param deltaX x coordinate
   * @param deltaY y coordinate
   */
  public void translate(double deltaX, double deltaY) {
    double x = point.getX();
    double y = point.getY();

    x += deltaX;
    y += deltaY;

    this.point = new WhiteboardPoint(x, y);

    this.recalculateSelectionPoints();
  }
Пример #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
 /**
  * Translates the shape.
  *
  * @param deltaX x coordinate
  * @param deltaY y coordinate
  */
 public void translate(double deltaX, double deltaY) {
   double x = startPoint.getX();
   double y = startPoint.getY();
   double xEnd = endPoint.getX();
   double yEnd = endPoint.getY();
   x += deltaX;
   xEnd += deltaX;
   y += deltaY;
   yEnd += deltaY;
   startPoint = new WhiteboardPoint(x, y);
   endPoint = new WhiteboardPoint(xEnd, yEnd);
 }
 /**
  * Returns the XML reppresentation of the PacketExtension.
  *
  * @return the packet extension as XML.
  * @todo Implement this org.jivesoftware.smack.packet.PacketExtension method
  */
 public String toXML() {
   String s =
       "<text id=\"#i\" x=\"#x\" y=\"#y\" "
           + "fill=\"#fi\" font-family=\"#ff\" font-size=\"#fs\">#t</text>";
   s = s.replaceAll("#i", getID());
   s = s.replaceAll("#fi", colorToHex(getColor()));
   WhiteboardPoint p = getWhiteboardPoint();
   s = s.replaceAll("#x", "" + p.getX());
   s = s.replaceAll("#y", "" + p.getY());
   s = s.replaceAll("#ff", getFontName());
   s = s.replaceAll("#fs", "" + getFontSize());
   s = s.replaceAll("#t", getText());
   return s;
 }
Пример #9
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());
  }
Пример #10
0
  /**
   * Recalculates the selection points coordinates and adds the new selection points to the list of
   * selection points.
   */
  private void recalculateSelectionPoints() {
    selectionPoints.clear();

    selectionPoints.add(new WhiteboardPoint(point.getX(), point.getY()));

    selectionPoints.add(new WhiteboardPoint(point.getX() + width, point.getY()));

    selectionPoints.add(new WhiteboardPoint(point.getX(), point.getY() + height));

    selectionPoints.add(new WhiteboardPoint(point.getX() + width, point.getY() + height));
  }
Пример #11
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());
  }
Пример #12
0
  /**
   * Translates a point from the shape.
   *
   * @param deltaX x coordinate
   * @param deltaY y coordinate
   */
  public void translateSelectedPoint(double deltaX, double deltaY) {
    if (getModifyPoint() == null) return;

    if (getModifyPoint().equals(startPoint)) {
      startPoint.setX(startPoint.getX() + deltaX);
      startPoint.setY(startPoint.getY() + deltaY);

      this.setModifyPoint(startPoint);
    } else if (getModifyPoint().equals(endPoint)) {
      endPoint.setX(endPoint.getX() + deltaX);
      endPoint.setY(endPoint.getY() + deltaY);

      this.setModifyPoint(endPoint);
    }
  }
Пример #13
0
  /**
   * Translates a point from the shape.
   *
   * @param p point position
   * @param deltaX x coordinate
   * @param deltaY y coordinate
   */
  public void translateSelectedPoint(double deltaX, double deltaY) {
    WhiteboardPoint modifyPoint = getModifyPoint();

    if (modifyPoint == null) return;

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

    if (modifyPoint.getX() == x && modifyPoint.getY() == y) {
      this.point.setX(x + deltaX);
      this.point.setY(y + deltaY);
      this.width -= deltaX;
      this.height -= deltaY;

      modifyPoint.setX(x + deltaX);
      modifyPoint.setY(y + deltaY);
    } else if (modifyPoint.getX() == x + width && modifyPoint.getY() == y) {
      this.point.setY(y + deltaY);
      this.width += deltaX;
      this.height -= deltaY;

      modifyPoint.setX(x + width);
      modifyPoint.setY(y + deltaY);
    } else if (modifyPoint.getX() == x && modifyPoint.getY() == y + height) {
      this.point.setX(x + deltaX);
      this.width -= deltaX;
      this.height += deltaY;

      modifyPoint.setX(x + deltaX);
      modifyPoint.setY(y + height);
    } else if (modifyPoint.getX() == x + width && modifyPoint.getY() == y + height) {
      this.width += deltaX;
      this.height += deltaY;

      modifyPoint.setX(x + width);
      modifyPoint.setY(y + height);
    }

    this.setModifyPoint(modifyPoint);
    this.recalculateSelectionPoints();
  }
Пример #14
0
 /**
  * Tests if the shape contains a point.
  *
  * @param p coord point
  * @return true if shape contains p
  */
 public boolean contains(Point2D p) {
   Rectangle2D rect = new Rectangle2D.Double(point.getX(), point.getY(), width, height);
   return rect.contains(p);
 }