예제 #1
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;
  }
예제 #2
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);
  }
예제 #3
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;
 }
예제 #5
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());
  }
예제 #6
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());
  }
예제 #7
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);
    }
  }