Пример #1
0
  public void mousePressed(MouseEvent e) {
    this.mousePoint = e.getPoint();

    Object topObject = null;
    PickedObjectList pickedObjects = this.wwd.getObjectsAtCurrentPosition();
    if (pickedObjects != null) topObject = pickedObjects.getTopObject();

    if (topObject instanceof ControlPointMarker) {
      this.activeControlPoint = (ControlPointMarker) topObject;
      this.activeAction = this.activeControlPoint.getType();

      setShowAnnotation(true);
      updateAnnotation(this.activeControlPoint.getPosition());

      // update controlPointIndex;
      int i = 0;
      for (Marker controlPoint : this.controlPoints) {
        if (controlPoint.equals(topObject)) break;
        i++;
      }
      this.activeControlPointIndex = i;
      e.consume();
    } else if (topObject == this.getPolygon()) {
      this.activeAction = MOVE_POLYGON_ACTION;

      // set the shape to be the "active control point"
      this.activeControlPointIndex = -1;

      setShowAnnotation(true);
      updateAnnotation(this.polygon.getReferencePosition());
      e.consume();
    }
  }
  // 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();
      }
    }
  }
  protected PickedObject getCurrentSelection() {
    if (this.sceneController == null) return null;

    PickedObjectList pol = this.getSceneController().getPickedObjectList();
    if (pol == null || pol.size() < 1) return null;

    PickedObject top = pol.getTopPickedObject();
    return top.isTerrain() ? null : top;
  }
  public Position getCurrentPosition() {
    if (this.sceneController == null) return null;

    PickedObjectList pol = this.getSceneController().getPickedObjectList();
    if (pol == null || pol.size() < 1) return null;

    Position p = null;
    PickedObject top = pol.getTopPickedObject();
    if (top != null && top.hasPosition()) p = top.getPosition();
    else if (pol.getTerrainObject() != null) p = pol.getTerrainObject().getPosition();

    return p;
  }
  @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();
    }
  }
Пример #6
0
  public void mouseClicked(MouseEvent e) {
    if (this.isArmed()) {
      if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
        Object topObject = null;
        PickedObjectList pickedObjects = this.wwd.getObjectsAtCurrentPosition();
        if (pickedObjects != null) topObject = pickedObjects.getTopObject();

        if (topObject instanceof ControlPointMarker) {
          this.removeVertex((ControlPointMarker) topObject);
          e.consume();
        } else {
          this.addVertex(e.getPoint());
          e.consume();
        }
      }
    }
  }
Пример #7
0
    protected void handleSelect() {
      // If the picked object is null or something other than an airspace, then ignore the mouse
      // click. If we
      // deselect the current entry at this point, the user cannot easily navigate without loosing
      // the selection.

      PickedObjectList pickedObjects = this.getApp().getWwd().getObjectsAtCurrentPosition();

      Object topObject = pickedObjects.getTopObject();
      if (!(topObject instanceof Airspace)) return;

      AirspaceEntry pickedEntry = this.getEntryFor((Airspace) topObject);
      if (pickedEntry == null) return;

      if (this.getSelectedEntry() != pickedEntry) {
        this.selectEntry(pickedEntry, true);
      }
    }
Пример #8
0
    @Override
    public void render(DrawContext dc) {
      if (dc.isPickingMode() && this.isResizeable()) return;

      // This is called twice: once during normal rendering, then again during ordered surface
      // rendering. During
      // normal renering we render both the interior and border shapes. During ordered surface
      // rendering, both
      // shapes are already added to the DrawContext and both will be individually processed.
      // Therefore we just
      // call our superclass behavior
      if (dc.isOrderedRenderingMode()) {
        super.render(dc);
        return;
      }

      if (!this.isResizeable()) {
        if (this.hasSelection()) {
          this.doRender(dc);
        }
        return;
      }

      PickedObjectList pos = dc.getPickedObjects();
      PickedObject terrainObject = pos != null ? pos.getTerrainObject() : null;

      if (terrainObject == null) return;

      if (this.getStartPosition() != null) {
        Position end = terrainObject.getPosition();
        if (!this.getStartPosition().equals(end)) {
          this.setEndPosition(end);
          this.setSector(Sector.boundingSector(this.getStartPosition(), this.getEndPosition()));
          this.doRender(dc);
        }
      } else {
        this.setStartPosition(pos.getTerrainObject().getPosition());
      }
    }
Пример #9
0
    public void selected(SelectEvent event) {
      // Have rollover events highlight the rolled-over object.
      if (event.getEventAction().equals(SelectEvent.ROLLOVER) && !this.dragger.isDragging()) {
        this.highlight(event.getTopObject());
        this.wwd.redraw();
      }

      // Drag the selected object.
      if (event.getEventAction().equals(SelectEvent.DRAG)
          || event.getEventAction().equals(SelectEvent.DRAG_END)) {
        this.dragger.selected(event);

        if (this.dragger.isDragging()) this.wwd.redraw();
      }

      // We missed any roll-over events while dragging, so highlight any under the cursor now.
      if (event.getEventAction().equals(SelectEvent.DRAG_END)) {
        PickedObjectList pol = this.wwd.getObjectsAtCurrentPosition();
        if (pol != null) {
          this.highlight(pol.getTopObject());
          this.wwd.redraw();
        }
      }
    }
  protected PickedObjectList getCurrentBoxSelection() {
    if (this.sceneController == null) return null;

    PickedObjectList pol = this.sceneController.getObjectsInPickRectangle();
    return pol != null && pol.size() > 0 ? pol : null;
  }