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; } }
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; }
@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(); }
/** * Creates a new LabelFigure with a MarginBorder that is the given size and a FlowPage containing * a TextFlow with the style WORD_WRAP_HARD. * * @param borderSize the size of the MarginBorder */ public LabelFigure(int borderSize) { setBorder(new MarginBorder(borderSize)); label = new TextFlow() { public void postValidate() { if (DesignChoiceConstants.DISPLAY_BLOCK.equals(display) || DesignChoiceConstants.DISPLAY_INLINE.equals(display)) { List list = getFragments(); FlowBox box; int left = Integer.MAX_VALUE, top = left; int bottom = Integer.MIN_VALUE; for (int i = 0; i < list.size(); i++) { box = (FlowBox) list.get(i); left = Math.min(left, box.getX()); top = Math.min(top, box.getBaseline() - box.getAscent()); bottom = Math.max(bottom, box.getBaseline() + box.getDescent()); } int width = LabelFigure.this.getClientArea().width; if (isFixLayout) { int maxWidth = calcMaxSegment() - getInsets().getWidth(); width = Math.max(width, maxWidth); } setBounds( new Rectangle( left, top, width, Math.max(LabelFigure.this.getClientArea().height, bottom - top))); if (isFixLayout()) { Figure child = (Figure) getParent(); Rectangle rect = child.getBounds(); child.setBounds(new Rectangle(rect.x, rect.y, width, rect.height)); } list = getChildren(); for (int i = 0; i < list.size(); i++) { ((FlowFigure) list.get(i)).postValidate(); } } else { super.postValidate(); } } }; label.setLayoutManager(new ParagraphTextLayout(label, ParagraphTextLayout.WORD_WRAP_SOFT)); flowPage = new FlowPage(); flowPage.add(label); setLayoutManager(new StackLayout()); add(flowPage); }