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();
    }
  }
  public void mouseReleased(MouseEvent mouseEvent) {
    if (MouseEvent.BUTTON1 != mouseEvent.getButton()) return;

    if (this.getShape().isResizeable()) this.setCursor(null);

    this.getShape().setResizeable(false);

    mouseEvent.consume(); // prevent view operations

    this.firePropertyChange(SECTOR_PROPERTY, this.previousSector, null);
  }
  public void mousePressed(MouseEvent mouseEvent) {
    if (MouseEvent.BUTTON1_DOWN_MASK != mouseEvent.getModifiersEx()) return;

    if (!this.isArmed()) return;

    this.getShape().setResizeable(true);
    this.getShape().setStartPosition(null);
    this.setArmed(false);

    mouseEvent.consume();
  }
  public void mouseReleased(MouseEvent e) {
    this.activeControlPoint = null;
    this.activeAction = null;

    setShowAnnotation(false);
    updateAnnotation(null);
    e.consume();
  }
  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();
        }
      }
    }
  }
  public void mouseDragged(MouseEvent e) {
    Point lastMousePoint = this.mousePoint;
    this.mousePoint = e.getPoint();

    if (lastMousePoint == null) lastMousePoint = this.mousePoint;

    // update annotation
    if (isShowAnnotation()) {
      if (this.activeControlPointIndex < 0) updateAnnotation(this.polygon.getReferencePosition());
      else if (this.controlPoints != null)
        updateAnnotation(this.controlPoints.get(this.activeControlPointIndex).getPosition());
    }

    if (MOVE_VERTEX_ACTION.equals(this.activeAction)) {
      this.moveControlPoint(this.activeControlPoint, lastMousePoint, this.mousePoint);
      e.consume();
    } else if (CHANGE_HEIGHT_ACTION.equals(this.activeAction)) {
      this.setPolygonHeight(lastMousePoint, this.mousePoint);
      e.consume();
    } else if (MOVE_POLYGON_ACTION.equals(this.activeAction)) {
      this.movePolygon(lastMousePoint, this.mousePoint);
      e.consume();
    }
  }
  public void mouseDragged(MouseEvent mouseEvent) {
    if (MouseEvent.BUTTON1_DOWN_MASK != mouseEvent.getModifiersEx()) return;

    if (this.getShape().isResizeable()) mouseEvent.consume(); // prevent view operations
  }
  /**
   * Converts the specified mouse event's screen point from WebView coordinates to Windows
   * coordinates, and returns a new event who's screen point is in Windows coordinates, with the
   * origin at the upper left corner of the WebView window.
   *
   * @param e The event to convert.
   * @return A new mouse event in the Windows coordinate system.
   */
  protected MouseEvent convertToWindows(MouseEvent e) {
    int x = e.getX();
    int y = e.getY();

    // Translate OpenGL screen coordinates to Windows by moving the Y origin from the lower left
    // corner to
    // the upper left corner and flipping the direction of the Y axis.
    y = this.frameSize.height - y;

    if (e instanceof MouseWheelEvent) {
      return new MouseWheelEvent(
          (Component) e.getSource(),
          e.getID(),
          e.getWhen(),
          e.getModifiers(),
          x,
          y,
          e.getClickCount(),
          e.isPopupTrigger(),
          ((MouseWheelEvent) e).getScrollType(),
          ((MouseWheelEvent) e).getScrollAmount(),
          ((MouseWheelEvent) e).getWheelRotation());
    } else {
      return new MouseEvent(
          (Component) e.getSource(),
          e.getID(),
          e.getWhen(),
          e.getModifiers(),
          x,
          y,
          e.getClickCount(),
          e.isPopupTrigger(),
          e.getButton());
    }
  }