Example #1
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();
  }
Example #2
0
  /**
   * 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);
  }