public static int getMinimumWidth(IFigure figure) {
   if (figure instanceof FlowPage) {
     FlowPage fp = (FlowPage) figure;
     TextFlow tf = (TextFlow) fp.getChildren().get(0);
     List<?> fragments = tf.getFragments();
     int width = getLongestFragment(fragments) + figure.getBorder().getInsets(figure).getWidth();
     return width;
   } else {
     return figure.getBounds().width;
   }
 }
 /**
  * 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;
 }
  /**
   * Create a new smart label with the given width to height ratio (width = ratio * height)
   *
   * @param ratio ratio to use when calculating the smart size of the label.
   */
  public SmartLabelFigure(double ratio) {
    super();
    this.ratio = ratio;

    textFlow = new TextFlow();
    textFlow.setLayoutManager(
        new ParagraphTextLayout(textFlow, ParagraphTextLayout.WORD_WRAP_HARD));
    add(textFlow);

    setHorizontalAligment(PositionConstants.CENTER);
  }
示例#5
0
  @Override
  protected void setUI() {
    setLayoutManager(new GridLayout());

    FlowPage flowPage = new FlowPage();
    BlockFlow block = new BlockFlow();
    fTextFlow = new TextFlow();
    fTextFlow.setLayoutManager(
        new ParagraphTextLayout(fTextFlow, ParagraphTextLayout.WORD_WRAP_HARD));
    block.add(fTextFlow);
    flowPage.add(block);

    add(flowPage, new GridData(SWT.CENTER, SWT.CENTER, true, true));
    fTextPositionDelegate = new TextPositionDelegate(this, flowPage, getDiagramModelObject());

    fIconicDelegate = new IconicDelegate(getDiagramModelObject());
    fIconicDelegate.updateImage();
  }
示例#6
0
  public void refreshVisuals() {
    // Text
    setText();

    // Font
    setFont();

    // Fill Color
    setFillColor();

    // Font Color
    setFontColor();

    // Border Color
    setBorderColor();

    // Text Alignment
    ((BlockFlow) fTextFlow.getParent())
        .setHorizontalAligment(getDiagramModelObject().getTextAlignment());

    // Text Position
    fTextPositionDelegate.updateTextPosition();
  }
 public String getText() {
   return textFlow.getText();
 }
 public void setText(String text) {
   textFlow.setText(text);
 }