Increases the size of bounding rectangle so it's large enough to hold the text.
()
| 494 | |
| 495 | /** Increases the size of bounding rectangle so it's large enough to hold the text. */ |
| 496 | private void updateBounds() { |
| 497 | if (firstChar ) |
| 498 | return; |
| 499 | double lineHeight = 0; |
| 500 | double mag = getMagnification(); |
| 501 | Font font = getScaledFont(); |
| 502 | Graphics g = getFontGraphics(font); |
| 503 | Java2.setAntialiasedText(g, getAntiAlias()); |
| 504 | FontMetrics metrics = g.getFontMetrics(font); |
| 505 | double fontHeight = metrics.getHeight()/mag; |
| 506 | int i=0, nLines=0; |
| 507 | Rectangle2D.Double b = getFloatBounds(); |
| 508 | double newWidth = 10; |
| 509 | while (i<MAX_LINES && theText[i]!=null) { |
| 510 | nLines++; |
| 511 | double w = stringWidth(theText[i],metrics,g)/mag; |
| 512 | if (w>newWidth) |
| 513 | newWidth = w; |
| 514 | i++; |
| 515 | } |
| 516 | newWidth += 2.0; |
| 517 | b.width = newWidth; |
| 518 | switch (justification) { |
| 519 | case LEFT: |
| 520 | break; |
| 521 | case CENTER: |
| 522 | b.x = this.oldX+this.oldWidth - newWidth/2.0; |
| 523 | break; |
| 524 | case RIGHT: |
| 525 | b.x = this.oldX+this.oldWidth - newWidth; |
| 526 | break; |
| 527 | } |
| 528 | b.height = nLines*fontHeight+2; |
| 529 | setBounds(b); |
| 530 | } |
| 531 | |
| 532 | private Graphics getFontGraphics(Font font) { |
| 533 | if (fontGraphics==null) { |
no test coverage detected