Esempio n. 1
0
  /**
   * Sets the text of the TextFlow to the given value.
   *
   * @param newText the new text value.
   */
  public void setText(String newText) {
    if (newText == null) {
      newText = ""; // $NON-NLS-1$
    }

    label.setText(newText);
  }
Esempio n. 2
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();
  }
Esempio n. 3
0
    public int getWidth() {
      if (width == null) {
        width = new int[1];
        int startingIndex = seg + 1;
        TextFlow textFlow = (TextFlow) getFlowFigure();

        if (startingIndex == segs.length) {
          width[0] += trailingBorderSize;
          getContext().getWidthLookahead(textFlow, width);
        } else {
          String rest = segs[startingIndex];
          for (int k = startingIndex + 1; k < segs.length; k++) rest += segs[k];
          if (!textFlow.addLeadingWordWidth(rest, width)) {
            width[0] += trailingBorderSize;
            getContext().getWidthLookahead(textFlow, width);
          }
        }
      }
      return width[0];
    }
Esempio n. 4
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++);
  }
Esempio n. 5
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);
  }
Esempio n. 6
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);
  }
Esempio n. 7
0
 /**
  * Sets the direction property of the Label.
  *
  * @param direction the direction property. this should be one of the following:
  *     DesignChoiceConstants.BIDI_DIRECTION_LTR | DesignChoiceConstants.BIDI_DIRECTION_RTL
  * @author bidi_hcg
  */
 public void setDirection(String direction) {
   label.setDirection(direction);
 }
Esempio n. 8
0
 /**
  * Gets the direction property of the Label.
  *
  * @return the Label direction.
  * @author bidi_hcg
  */
 public String getDirection() {
   return label.getDirection();
 }
Esempio n. 9
0
 /** @param specialPREFIX */
 public void setSpecialPREFIX(String specialPREFIX) {
   label.setSpecialPREFIX(specialPREFIX);
 }
Esempio n. 10
0
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.draw2d.Figure#setFont(org.eclipse.swt.graphics.Font)
  */
 public void setFont(Font f) {
   super.setFont(f);
   label.setFont(f);
 }
Esempio n. 11
0
 /**
  * Sets the vertical text alignment style.
  *
  * @param verticalAlign The verticalAlign to set.
  */
 public void setVerticalAlign(String verticalAlign) {
   label.setVerticalAlign(verticalAlign);
 }
Esempio n. 12
0
 /**
  * Gets the horizontal text alignment style.
  *
  * @return The textAlign.
  */
 public String getTextAlign() {
   return label.getTextAlign();
 }
Esempio n. 13
0
 /**
  * Sets the horizontal text alignment style.
  *
  * @param textAlign The textAlign to set.
  */
 public void setTextAlign(String textAlign) {
   label.setTextAlign(textAlign);
 }
Esempio n. 14
0
 /**
  * Sets the underline style of the text.
  *
  * @param textUnderline The textUnderline to set.
  */
 public void setTextUnderline(String textUnderline) {
   label.setTextUnderline(textUnderline);
 }
Esempio n. 15
0
 /**
  * Sets the line-through style of the text.
  *
  * @param textLineThrough The textLineThrough to set.
  */
 public void setTextLineThrough(String textLineThrough) {
   label.setTextLineThrough(textLineThrough);
 }
Esempio n. 16
0
 /**
  * Returns the text inside the TextFlow.
  *
  * @return the text flow inside the text.
  */
 public String getText() {
   return label.getText();
 }