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().getGL2(); // GL initialization checks for GL2 compatibility.
    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());
  }