Ejemplo n.º 1
0
  protected void drawToolTip(
      DrawContext dc,
      java.awt.Rectangle viewport,
      String text,
      int x,
      int y,
      ToolTipAttributes attributes) {
    java.awt.geom.Rectangle2D textBounds = this.computeTextBounds(dc, text, attributes.getFont());
    java.awt.geom.Rectangle2D bgBounds =
        this.computeBackgroundBounds(
            dc, textBounds.getWidth(), textBounds.getHeight(), attributes.getInsets());

    java.awt.Point screenPoint = this.adjustDrawPointToViewport(x, y, bgBounds, viewport);
    java.awt.geom.Point2D textTranslation =
        this.computeTextTranslation(dc, textBounds, attributes.getInsets());

    GL2 gl = dc.getGL();
    OGLStackHandler stackHandler = new OGLStackHandler();

    stackHandler.pushModelview(gl);
    try {
      gl.glTranslated(
          screenPoint.getX() + bgBounds.getX(), screenPoint.getY() + bgBounds.getY(), 0);
      this.drawToolTipInterior(dc, bgBounds.getWidth(), bgBounds.getHeight(), attributes);
      this.drawToolTipOutline(dc, bgBounds.getWidth(), bgBounds.getHeight(), attributes);

      gl.glTranslated(textTranslation.getX(), textTranslation.getY(), 0);
      this.drawToolTipText(dc, text, 0, 0, attributes);
    } finally {
      stackHandler.pop(gl);
    }
  }
Ejemplo n.º 2
0
  protected java.awt.Point adjustDrawPointToViewport(
      int x, int y, java.awt.geom.Rectangle2D bounds, java.awt.Rectangle viewport) {
    if (x + bounds.getMaxX() > viewport.getWidth())
      x = (int) (viewport.getWidth() - bounds.getWidth()) - 1;
    else if (x < 0) x = 0;

    if (y + bounds.getMaxY() > viewport.getHeight())
      y = (int) (viewport.getHeight() - bounds.getHeight()) - 1;
    else if (y < 0) y = 0;

    return new java.awt.Point(x, y);
  }
Ejemplo n.º 3
0
  @SuppressWarnings({"UnusedDeclaration"})
  protected java.awt.geom.Point2D computeTextTranslation(
      DrawContext dc, java.awt.geom.Rectangle2D textBounds, java.awt.Insets insets) {
    // The text bounds are assumed to come from the return value of a call to
    // TextRenderer.getBounds(). The bounds
    // place the origin in the upper left hand corner, with the y axis increasing downward. The y
    // coordinate in the bounds corresponds to the baseline of the leftmost character.

    return new java.awt.geom.Point2D.Double(
        insets.left - textBounds.getX(),
        insets.bottom + textBounds.getY() + textBounds.getHeight());
  }
  private Vec4 computeReferencePoint(DrawContext dc) {
    if (dc.getViewportCenterPosition() != null)
      return dc.getGlobe().computePointFromPosition(dc.getViewportCenterPosition());

    java.awt.geom.Rectangle2D viewport = dc.getView().getViewport();
    int x = (int) viewport.getWidth() / 2;
    for (int y = (int) (0.5 * viewport.getHeight()); y >= 0; y--) {
      Position pos = dc.getView().computePositionFromScreenPoint(x, y);
      if (pos == null) continue;

      return dc.getGlobe().computePointFromPosition(pos.getLatitude(), pos.getLongitude(), 0d);
    }

    return null;
  }