Exemplo n.º 1
0
  private int calcMaxSegment() {
    String text = label.getText();
    char[] chars = text.toCharArray();
    int position = 0;
    int maxWidth = 0;

    for (int i = 0; i < chars.length; i++) {
      if (canBreakAfter(chars[i])) {
        int tempMaxWidth;
        String st = text.substring(position, i + 1);
        tempMaxWidth = FigureUtilities.getStringExtents(st, getFont()).width;

        if (tempMaxWidth > maxWidth) {
          maxWidth = tempMaxWidth;
        }
        position = i;
      }
    }
    String st = text.substring(position, chars.length);
    int tempMaxWidth = FigureUtilities.getStringExtents(st, getFont()).width;

    if (tempMaxWidth > maxWidth) {
      maxWidth = tempMaxWidth;
    }
    return maxWidth + getInsets().getWidth();
  }
Exemplo n.º 2
0
  /** @see org.eclipse.draw2d.text.FlowFigureLayout#layout() */
  protected void layout() {
    TextFlow textFlow = (TextFlow) getFlowFigure();
    String text = textFlow.getText();
    List fragments = textFlow.getFragments();
    Font font = textFlow.getFont();
    TextFragmentBox fragment;
    int i = 0;
    int offset = 0;
    FlowUtilities flowUtilities = textFlow.getFlowUtilities();

    do {
      nextLineBreak(text, offset);
      fragment = getFragment(i++, fragments);
      fragment.length = result - offset;
      fragment.offset = offset;
      fragment.setWidth(-1);
      flowUtilities.setupFragment(fragment, font, text.substring(offset, result));
      getContext().addToCurrentLine(fragment);
      getContext().endLine();
      offset = result + delimeterLength;
    } while (offset < text.length());
    // Remove the remaining unused fragments.
    while (i < fragments.size()) fragments.remove(i++);
  }
Exemplo n.º 3
0
  /** @see org.eclipse.draw2d.text.FlowFigureLayout#layout() */
  protected void layout() {
    TextFlow textFlow = (TextFlow) getFlowFigure();
    int offset = 0;

    FlowContext context = getContext();
    List fragments = textFlow.getFragments();
    Font font = textFlow.getFont();
    int fragIndex = 0;
    int advance = 0;

    TextFragmentBox fragment;
    int levelInfo[] =
        (textFlow.getBidiInfo() == null) ? new int[] {-1} : textFlow.getBidiInfo().levelInfo;

    String segment, segments[] = getSegments(textFlow.getText(), levelInfo);
    FlowBorder border = null;
    if (textFlow.getBorder() instanceof FlowBorder) border = (FlowBorder) textFlow.getBorder();

    SegmentLookahead lookahead =
        new SegmentLookahead(segments, border == null ? 0 : border.getRightMargin());
    int seg;

    if (border != null) {
      fragment = getFragment(fragIndex++, fragments);
      fragment.setBidiLevel(levelInfo[0]);
      fragment.setTruncated(false);
      fragment.offset = fragment.length = -1;
      fragment.setWidth(border.getLeftMargin() + border.getInsets(textFlow).left);
      if (context.getRemainingLineWidth() < fragment.getWidth() + lookahead.getWidth())
        context.endLine();
      context.addToCurrentLine(fragment);
    }

    FlowUtilities flowUtilities = textFlow.getFlowUtilities();
    for (seg = 0; seg < segments.length; seg++) {
      segment = segments[seg];
      lookahead.setIndex(seg);

      do {
        fragment = getFragment(fragIndex++, fragments);

        fragment.offset = offset;
        fragment.setBidiLevel(levelInfo[seg * 2]);

        advance =
            flowUtilities.wrapFragmentInContext(
                fragment, segment, context, lookahead, font, wrappingStyle);
        segment = segment.substring(advance);
        offset += advance;
        if ((segment.length() > 0 || fragment.length < advance) || fragment.isTruncated())
          context.endLine();
      } while (segment.length() > 0 || (!fragment.isTruncated() && fragment.length < advance));
    }

    if (border != null) {
      fragment = getFragment(fragIndex++, fragments);
      fragment.setBidiLevel(levelInfo[0]);
      fragment.setTruncated(false);
      fragment.offset = fragment.length = -1;
      fragment.setWidth(border.getRightMargin() + border.getInsets(textFlow).right);
      context.addToCurrentLine(fragment);
    }

    // Remove the remaining unused fragments.
    while (fragIndex < fragments.size()) fragments.remove(fragments.size() - 1);
  }
Exemplo n.º 4
0
 /**
  * Returns the text inside the TextFlow.
  *
  * @return the text flow inside the text.
  */
 public String getText() {
   return label.getText();
 }