MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / updateBounds

Method updateBounds

ij/src/main/java/ij/gui/TextRoi.java:496–530  ·  view source on GitHub ↗

Increases the size of bounding rectangle so it's large enough to hold the text.

()

Source from the content-addressed store, hash-verified

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) {

Callers 7

initMethod · 0.95
addCharMethod · 0.95
setFontMethod · 0.95
setJustificationMethod · 0.95
handleMouseUpMethod · 0.95
setTextMethod · 0.95
setCurrentFontMethod · 0.95

Calls 10

getScaledFontMethod · 0.95
getFontGraphicsMethod · 0.95
setAntialiasedTextMethod · 0.95
stringWidthMethod · 0.95
getAntiAliasMethod · 0.80
getMagnificationMethod · 0.45
getFontMetricsMethod · 0.45
getHeightMethod · 0.45
getFloatBoundsMethod · 0.45
setBoundsMethod · 0.45

Tested by

no test coverage detected