Example #1
0
  /**
   * Returns the list of selected points.
   *
   * @return list of selected points
   */
  public List<WhiteboardPoint> getSelectionPoints() {
    ArrayList<WhiteboardPoint> selectionPoints = new ArrayList<WhiteboardPoint>();

    selectionPoints.add(startPoint);
    selectionPoints.add(endPoint);

    return selectionPoints;
  }
  /**
   * 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));
  }
  /**
   * 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;
  }