예제 #1
0
  protected void dragWholeShape(DragSelectEvent dragEvent, Movable dragObject) {
    View view = getWwd().getView();
    EllipsoidalGlobe globe = (EllipsoidalGlobe) getWwd().getModel().getGlobe();

    // Compute ref-point position in screen coordinates.
    Position refPos = dragObject.getReferencePosition();
    if (refPos == null) return;

    Vec4 refPoint = globe.computePointFromPosition(refPos);
    Vec4 screenRefPoint = view.project(refPoint);

    // Compute screen-coord delta since last event.
    int dx = dragEvent.getPickPoint().x - dragEvent.getPreviousPickPoint().x;
    int dy = dragEvent.getPickPoint().y - dragEvent.getPreviousPickPoint().y;

    // Find intersection of screen coord ref-point with globe.
    double x = screenRefPoint.x + dx;
    double y =
        dragEvent.getMouseEvent().getComponent().getSize().height - screenRefPoint.y + dy - 1;
    Line ray = view.computeRayFromScreenPoint(x, y);
    Intersection inters[] = globe.intersect(ray, refPos.getElevation());

    if (inters != null) {
      // Intersection with globe. Move reference point to the intersection point.
      Position p = globe.computePositionFromPoint(inters[0].getIntersectionPoint());
      dragObject.moveTo(p);
    }
  }
예제 #2
0
  public void selected(SelectEvent event) {
    if (event == null) {
      String msg = Logging.getMessage("nullValue.EventIsNull");
      Logging.logger().log(java.util.logging.Level.FINE, msg);
      throw new IllegalArgumentException(msg);
    }

    if (event.getTopObject() != null && !(event.getTopObject() instanceof RegionShape)) {
      this.setCursor(null);
      return;
    }

    if (event.getEventAction().equals(SelectEvent.LEFT_PRESS)) {
      this.setPreviousPosition(this.getWwd().getCurrentPosition());
    } else if (event.getEventAction().equals(SelectEvent.DRAG)) {
      DragSelectEvent dragEvent = (DragSelectEvent) event;
      Object topObject = dragEvent.getTopObject();
      if (topObject == null) return;

      RegionShape dragObject = (RegionShape) topObject;

      if (this.getOperation() == SIZING) {
        Sector newSector = this.resizeShape(dragObject, this.getSide());
        if (newSector != null) dragObject.setSector(newSector);
      } else {
        this.setSide(this.determineAdjustmentSide(dragObject, this.getEdgeFactor()));

        if (this.getSide() == NONE || this.getOperation() == MOVING) {
          this.setOperation(MOVING);
          this.dragWholeShape(dragEvent, dragObject);
        } else {
          Sector newSector = this.resizeShape(dragObject, this.getSide());
          if (newSector != null) dragObject.setSector(newSector);
          this.setOperation(SIZING);
        }
      }

      this.setPreviousPosition(this.getWwd().getCurrentPosition());
      this.notifySectorChanged();
    } else if (event.getEventAction().equals(SelectEvent.DRAG_END)) {
      this.setOperation(NONE);
      this.setPreviousPosition(null);
    } else if (event.getEventAction().equals(SelectEvent.ROLLOVER)) {
      if (!(this.getWwd() instanceof Component)) return;

      if (event.getTopObject() == null || event.getTopPickedObject().isTerrain()) {
        this.setCursor(null);
        return;
      }

      if (!(event.getTopObject() instanceof Movable)) return;

      this.setCursor(
          this.determineAdjustmentSide((Movable) event.getTopObject(), this.getEdgeFactor()));
    }
  }