// Handle mouse actions
 public void mousePressed(MouseEvent mouseEvent) {
   if (this.isArmed() && this.isUseRubberBand() && mouseEvent.getButton() == MouseEvent.BUTTON1) {
     if ((mouseEvent.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) != 0) {
       if (!mouseEvent.isControlDown()) {
         this.setActive(true);
         measureTool.addControlPoint();
         if (measureTool.getControlPoints().size() == 1) {
           measureTool.addControlPoint(); // Simulate a second click
         }
         // Set the rubber band target to the last control point or the relevant control for
         // regular shapes.
         if (measureTool.isRegularShape()) {
           String initControl =
               measureTool.getShapeInitialControl(measureTool.getWwd().getCurrentPosition());
           rubberBandTarget = measureTool.getControlPoint(initControl);
         } else {
           rubberBandTarget =
               (MeasureTool.ControlPoint)
                   measureTool.getControlPoints().get(measureTool.getControlPoints().size() - 1);
         }
         measureTool.firePropertyChange(MeasureTool.EVENT_RUBBERBAND_START, null, null);
       }
     }
     mouseEvent.consume();
   } else if (!this.isArmed()
       && mouseEvent.getButton() == MouseEvent.BUTTON1
       && mouseEvent.isAltDown()) {
     if (!this.measureTool.isRegularShape()) {
       this.setMoving(true);
       this.movingTarget = this.lastPickedObject;
     }
     mouseEvent.consume();
   }
 }
  protected void highlight(Object o) {
    // Manage highlighting of control points
    if (this.lastPickedObject == o) return; // Same thing selected

    // Turn off highlight if on.
    if (this.lastPickedObject != null) {
      this.lastPickedObject.getAttributes().setHighlighted(false);
      this.lastPickedObject.getAttributes().setBackgroundColor(null); // use default
      this.lastPickedObject = null;
      if (measureTool.isShowAnnotation()) measureTool.updateAnnotation(null);
      this.setCursor(null);
    }

    // Turn on highlight if object selected is a control point and belongs to this controller's
    // MeasureTool.
    if (this.lastPickedObject == null
        && o instanceof MeasureTool.ControlPoint
        && ((MeasureTool.ControlPoint) o).getParent() == measureTool) {
      this.lastPickedObject = (MeasureTool.ControlPoint) o;
      this.lastPickedObject.getAttributes().setHighlighted(true);
      // Highlite using text color
      this.lastPickedObject
          .getAttributes()
          .setBackgroundColor(this.lastPickedObject.getAttributes().getTextColor());
      if (measureTool.isShowAnnotation())
        measureTool.updateAnnotation(this.lastPickedObject.getPosition());
      this.setCursor(this.lastPickedObject);
    }
  }
  // Handle single click for removing control points
  public void mouseClicked(MouseEvent mouseEvent) {
    if (measureTool == null) return;

    if (this.isArmed() && mouseEvent.getButton() == MouseEvent.BUTTON1) {
      if (mouseEvent.isControlDown()) measureTool.removeControlPoint();
      else if (!this.isUseRubberBand()) {
        measureTool.addControlPoint();
        // Disarm after second control point of a line or regular shape
        autoDisarm();
      }
      mouseEvent.consume();
    }
  }
  // Wait for end of rendering to update metrics - length, area...
  public void stageChanged(RenderingEvent event) {
    if (measureTool == null) return;

    if (event.getStage().equals(RenderingEvent.AFTER_BUFFER_SWAP)) {
      measureTool.firePropertyChange(MeasureTool.EVENT_METRIC_CHANGED, null, null);
    }
  }
  // Handle dragging of control points
  public void selected(SelectEvent event) {
    // Ignore select events if the tools is armed, or in a move/rotate action. In either case we
    // don't
    // want to change the currently selected or hightlighted control point.
    if (measureTool == null || (this.isArmed() && this.isUseRubberBand()) || this.isMoving())
      return;

    if (dragger == null) dragger = new BasicDragger(measureTool.getWwd());

    // Have rollover events highlight the rolled-over object.
    if (event.getEventAction().equals(SelectEvent.ROLLOVER) && !dragger.isDragging()) {
      this.highlight(event.getTopObject());
      this.measureTool.getWwd().redraw();
    }

    this.doSelected(event);

    // We missed any roll-over events while dragging, so highlight any under the cursor now,
    // or de-highlight the dragged control point if it's no longer under the cursor.
    if (event.getEventAction().equals(SelectEvent.DRAG_END)) {
      PickedObjectList pol = this.measureTool.getWwd().getObjectsAtCurrentPosition();
      if (pol != null) {
        this.highlight(pol.getTopObject());
        this.measureTool.getWwd().redraw();
      }
    }
  }
 public void mouseReleased(MouseEvent mouseEvent) {
   if (this.isArmed() && this.isUseRubberBand() && mouseEvent.getButton() == MouseEvent.BUTTON1) {
     if (this.isUseRubberBand() && measureTool.getPositions().size() == 1)
       measureTool.removeControlPoint();
     this.setActive(false);
     rubberBandTarget = null;
     // Disarm after second control point of a line or regular shape
     autoDisarm();
     mouseEvent.consume();
     measureTool.firePropertyChange(MeasureTool.EVENT_RUBBERBAND_STOP, null, null);
   } else if (this.isMoving() && mouseEvent.getButton() == MouseEvent.BUTTON1) {
     this.setMoving(false);
     this.movingTarget = null;
     mouseEvent.consume();
   }
 }
  protected void dragSelected(SelectEvent event) {
    MeasureTool.ControlPoint point = (MeasureTool.ControlPoint) event.getTopObject();

    LatLon lastPosition = point.getPosition();
    if (point.getValue(MeasureTool.CONTROL_TYPE_LOCATION_INDEX) != null)
      lastPosition =
          measureTool
              .getPositions()
              .get((Integer) point.getValue(MeasureTool.CONTROL_TYPE_LOCATION_INDEX));

    // Delegate dragging computations to a dragger.
    this.dragger.selected(event);

    measureTool.moveControlPoint(point);
    if (measureTool.isShowAnnotation()) measureTool.updateAnnotation(point.getPosition());
    measureTool.firePropertyChange(
        MeasureTool.EVENT_POSITION_REPLACE, lastPosition, point.getPosition());
    measureTool.getWwd().redraw();
  }
 protected void autoDisarm() {
   // Disarm after second control point of a line or regular shape
   if (measureTool.isRegularShape()
       || measureTool.getMeasureShapeType().equals(MeasureTool.SHAPE_LINE))
     if (measureTool.getControlPoints().size() > 1) this.setArmed(false);
 }
 /**
  * Move the shape to the specified new position
  *
  * @param oldPosition Previous position of shape
  * @param newPosition New position for shape
  */
 protected void moveToPosition(Position oldPosition, Position newPosition) {
   Angle distanceAngle = LatLon.greatCircleDistance(oldPosition, newPosition);
   Angle azimuthAngle = LatLon.greatCircleAzimuth(oldPosition, newPosition);
   measureTool.moveMeasureShape(azimuthAngle, distanceAngle);
   measureTool.firePropertyChange(MeasureTool.EVENT_POSITION_REPLACE, oldPosition, newPosition);
 }
Exemplo n.º 10
0
  @SuppressWarnings({"UnusedDeclaration"})
  protected void doMoved(PositionEvent event) {
    if (this.active
        && rubberBandTarget != null
        && this.measureTool.getWwd().getObjectsAtCurrentPosition() != null
        && this.measureTool.getWwd().getObjectsAtCurrentPosition().getTerrainObject() != null) {
      if (!isFreeHand()
          || (!measureTool.getMeasureShapeType().equals(MeasureTool.SHAPE_PATH)
              && !measureTool.getMeasureShapeType().equals(MeasureTool.SHAPE_POLYGON))) {
        // Rubber band - Move control point and update shape
        Position lastPosition = rubberBandTarget.getPosition();
        PickedObjectList pol = measureTool.getWwd().getObjectsAtCurrentPosition();
        PickedObject to = pol.getTerrainObject();
        rubberBandTarget.setPosition(new Position(to.getPosition(), 0));
        measureTool.moveControlPoint(rubberBandTarget);
        measureTool.firePropertyChange(
            MeasureTool.EVENT_POSITION_REPLACE, lastPosition, rubberBandTarget.getPosition());
        measureTool.getWwd().redraw();
      } else {
        // Free hand - Compute distance from current control point (rubber band target)
        Position lastPosition = rubberBandTarget.getPosition();
        Position newPosition = measureTool.getWwd().getCurrentPosition();
        double distance =
            LatLon.greatCircleDistance(lastPosition, newPosition).radians
                * measureTool.getWwd().getModel().getGlobe().getRadius();
        if (distance >= freeHandMinSpacing) {
          // Add new control point
          measureTool.addControlPoint();
          rubberBandTarget =
              (MeasureTool.ControlPoint)
                  getMeasureTool()
                      .getControlPoints()
                      .get(getMeasureTool().getControlPoints().size() - 1);
          measureTool.getWwd().redraw();
        }
      }
    } else if (this.moving
        && movingTarget != null
        && measureTool.getWwd().getCurrentPosition() != null) {
      // Moving the whole shape
      Position lastPosition = movingTarget.getPosition();
      Position newPosition = measureTool.getWwd().getCurrentPosition();
      this.moveToPosition(lastPosition, newPosition);

      // Update the tool tip to follow the shape as it moves.
      if (measureTool.isShowAnnotation()) measureTool.updateAnnotation(movingTarget.getPosition());

      measureTool.getWwd().redraw();
    }
  }