/**
  * Calculate the best size for this label using the class's width to height ratio. This is done by
  * calculating the area that the text would occupy if it was in only one line, then calculate a
  * new width that would give the same area using the width to height ratio, and finally it sends
  * this width to the {@link FlowPage}'s {@link FlowPage#getPreferredSize(int, int)} method which
  * calculates the real height using line breaks.
  *
  * @return A close match to the size that this figure should have to match the required width to
  *     height ratio.
  */
 public Dimension calculateSize() {
   try {
     Dimension lineDimensions =
         TextUtilities.INSTANCE.getStringExtents(textFlow.getText(), getFont());
     double area = lineDimensions.width() * lineDimensions.height();
     double width = Math.sqrt(area / ratio) * ratio;
     invalidate();
     Dimension pSize = textFlow.getPreferredSize((int) width, -1).getCopy();
     if (pSize.width < OPPFigureConstants.MINIMUM_NODE_SIZE) pSize.width = pSize.height;
     return pSize;
   } catch (Exception e) {
     return new Dimension(0, 0);
   }
 }
 public static int getMinimumHeight(IFigure figure) {
   int height = figure.getBounds().height;
   if (figure instanceof FlowPage) {
     FlowPage fp = (FlowPage) figure;
     TextFlow tf = (TextFlow) fp.getChildren().get(0);
     Dimension textExtents = TextUtilities.INSTANCE.getTextExtents(tf.getText(), tf.getFont());
     List<?> fragments = tf.getFragments();
     if (fragments.size() != 0) {
       height = fragments.size() * textExtents.height;
       // include border padding
       height = height + figure.getBorder().getInsets(figure).getHeight();
     }
   }
   return height;
 }
Esempio n. 3
0
 @Override
 protected void paintFigure(Graphics graphics) {
   if (roiInfoProvider != null && roiDataBounds != null) {
     String text =
         roiInfoProvider.getROIInfo(
             roiDataBounds.x, roiDataBounds.y, roiDataBounds.width, roiDataBounds.height);
     Dimension size = TextUtilities.INSTANCE.getTextExtents(text, getFont());
     graphics.pushState();
     graphics.translate(getLocation());
     graphics.fillRectangle(roiGeoBounds.x, roiGeoBounds.y - size.height, size.width, size.height);
     graphics.drawText(text, roiGeoBounds.x, roiGeoBounds.y - size.height);
     graphics.popState();
   }
   super.paintFigure(graphics);
 }