コード例 #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);
    }
  }
コード例 #2
0
ファイル: Axis.java プロジェクト: christinapanto/project
 /**
  * handy little utility for determining the length in pixels the given string will use if drawn
  * into the given Graphics object. Note: perhaps belongs in some utility package.
  */
 public static Dimension stringSize(String str, Graphics g) {
   if (g instanceof Graphics2D) {
     java.awt.geom.Rectangle2D bounds =
         g.getFont().getStringBounds(str, ((Graphics2D) g).getFontRenderContext());
     return new Dimension((int) (bounds.getWidth() + .5), (int) (bounds.getHeight() + .5));
   } else
     return new Dimension(g.getFontMetrics().stringWidth(str), g.getFontMetrics().getHeight());
 }
コード例 #3
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);
  }
コード例 #4
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());
  }
コード例 #5
0
ファイル: Title.java プロジェクト: dledlow/HighschoolGame
  public void paint(Graphics g) {
    try {
      Thread.sleep(5);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    g.setColor(Color.black);
    g.fillRect(0, 0, width, height);

    g.setColor(Color.darkGray);

    for (int x = 0; x < gpSize; x++) {
      g.drawLine(
          (int) width / gpSize * x + width / gpSize,
          (int) 0,
          (int) width / gpSize * x + width / gpSize,
          (int) height);
    }
    for (int y = 0; y < gpSize; y++) {
      g.drawLine((int) 0, (int) height / gpSize * y, (int) width, (int) height / gpSize * y);
    }

    for (int i = 0; i < gravList.size(); i++) {
      gravList.get(i).draw(g);
    }

    g.setColor(Color.GREEN);
    for (int y = 0; y < numLines; y++) {

      for (int x = 0; x < size; x++) {
        try {
          grid[x][y].draw(g);
        } catch (Exception e) {

        }
      }
    }

    if (!showGuide) {
      go.draw(g);
      info.draw(g);
    } else {
      FontMetrics fm = g.getFontMetrics(g.getFont());
      java.awt.geom.Rectangle2D rect = fm.getStringBounds("DEAL WITH IT.", g);

      int textHeight = (int) (rect.getHeight());
      int textWidth = (int) (rect.getWidth());
      int panelHeight = height;
      int panelWidth = width;

      // Center text horizontally and vertically
      int x2 = (panelWidth - textWidth) / 2;
      int y2 = (panelHeight - textHeight) / 2 + fm.getAscent();

      g.drawString("DEAL WITH IT.", x2, y2);

      g.drawRect(width / 4, height / 4 + 100, width / 2 + 50, height / 4 + 25);

      back.draw(g);
    }

    for (int i = 0; i < boomList.size(); i++) {
      boomList.get(i).draw(g);
    }
  }