Examples of AttributedString


Examples of java.text.AttributedString

   
    if (lastParagraphText == null)
    {
      lastParagraphText = " ";
      paragraph =
        new AttributedString(
          lastParagraphText,
          new AttributedString(
            allParagraphs,
            lastParagraphStart,
            lastParagraphStart + lastParagraphText.length()
            ).getIterator().getAttributes()
          ).getIterator();
    }
    else
    {
      paragraph =
        new AttributedString(
          allParagraphs,
          lastParagraphStart,
          lastParagraphStart + lastParagraphText.length()
          ).getIterator();
    }

    List<Integer> tabIndexes = JRStringUtil.getTabIndexes(lastParagraphText);
   
    int currentTab = 0;
    int lines = 0;
    float endX = 0;
   
    TabStop nextTabStop = null;
    boolean requireNextWord = false;
 
    LineBreakMeasurer lineMeasurer = new LineBreakMeasurer(paragraph, getFontRenderContext());//grx.getFontRenderContext()

    // the paragraph is rendered one line at a time
    while (lineMeasurer.getPosition() < paragraph.getEndIndex() && !isMaxHeightReached)
    {
      boolean lineComplete = false;

      float maxAscent = 0;
      float maxDescent = 0;
      float maxLeading = 0;
     
      // each line is split into segments, using the tab character as delimiter
      segments = new ArrayList<TabSegment>(1);

      TabSegment oldSegment = null;
      TabSegment crtSegment = null;

      // splitting the current line into tab segments
      while (!lineComplete)
      {
        // the current segment limit is either the next tab character or the paragraph end
        int tabIndexOrEndIndex = (tabIndexes == null || currentTab >= tabIndexes.size() ? paragraph.getEndIndex() : tabIndexes.get(currentTab) + 1);
       
        float startX = (lineMeasurer.getPosition() == 0 ? text.getParagraph().getFirstLineIndent() : 0);
        endX = width - text.getParagraph().getRightIndent() - rightPadding;
        endX = endX < startX ? startX : endX;
        //formatWidth = endX - startX;
        //formatWidth = endX;
       
        int startIndex = lineMeasurer.getPosition();

        int rightX = 0;

        if (segments.size() == 0)
        {
          rightX = (int)startX;
          //nextTabStop = nextTabStop;
        }
        else
        {
          rightX = oldSegment.rightX;
          nextTabStop = ParagraphUtil.getNextTabStop(text.getParagraph(), endX, rightX);
        }

        //float availableWidth = formatWidth - ParagraphUtil.getSegmentOffset(nextTabStop, rightX); // nextTabStop can be null here; and that's OK
        float availableWidth = endX - text.getParagraph().getLeftIndent() - ParagraphUtil.getSegmentOffset(nextTabStop, rightX); // nextTabStop can be null here; and that's OK
       
        // creating a text layout object for each tab segment
        TextLayout layout =
          lineMeasurer.nextLayout(
            availableWidth,
            tabIndexOrEndIndex,
            requireNextWord
            );
       
        if (layout != null)
        {
           AttributedString tmpText =
            new AttributedString(
              paragraph,
              startIndex,
              startIndex + layout.getCharacterCount()
              );
          
          if (isMinimizePrinterJobSize)
          {
            //eugene fix - start
            layout = new TextLayout(tmpText.getIterator(), getFontRenderContext());
            //eugene fix - end
          }
   
          if (
            text.getHorizontalAlignmentValue() == HorizontalAlignEnum.JUSTIFIED
            && lineMeasurer.getPosition() < paragraph.getEndIndex()
            )
          {
            layout = layout.getJustifiedLayout(availableWidth);
          }
         
          maxAscent = Math.max(maxAscent, layout.getAscent());
          maxDescent = Math.max(maxDescent, layout.getDescent());
          maxLeading = Math.max(maxLeading, layout.getLeading());

          //creating the current segment
          crtSegment = new TabSegment();
          crtSegment.layout = layout;
          crtSegment.as = tmpText;
          crtSegment.text = lastParagraphText.substring(startIndex, startIndex + layout.getCharacterCount());

          int leftX = ParagraphUtil.getLeftX(nextTabStop, layout.getAdvance()); // nextTabStop can be null here; and that's OK
          if (rightX > leftX)
          {
            crtSegment.leftX = rightX;
            crtSegment.rightX = (int)(rightX + layout.getAdvance());//FIXMETAB some rounding issues here
          }
          else
          {
            crtSegment.leftX = leftX;
            // we need this special tab stop based utility call because adding the advance to leftX causes rounding issues
            crtSegment.rightX = ParagraphUtil.getRightX(nextTabStop, layout.getAdvance()); // nextTabStop can be null here; and that's OK
          }

          segments.add(crtSegment);
        }
       
        requireNextWord = true;

        if (lineMeasurer.getPosition() == tabIndexOrEndIndex)
        {
          // the segment limit was a tab; going to the next tab
          currentTab++;
        }

        if (lineMeasurer.getPosition() == paragraph.getEndIndex())
        {
          // the segment limit was the paragraph end; line completed and next line should start at normal zero x offset
          lineComplete = true;
          nextTabStop = null;
        }
        else
        {
          // there is paragraph text remaining
          if (lineMeasurer.getPosition() == tabIndexOrEndIndex)
          {
            // the segment limit was a tab
            if (crtSegment.rightX >= ParagraphUtil.getLastTabStop(text.getParagraph(), endX).getPosition())
            {
              // current segment stretches out beyond the last tab stop; line complete
              lineComplete = true;
              // next line should should start at first tab stop indent
              nextTabStop = ParagraphUtil.getFirstTabStop(text.getParagraph(), endX);
            }
            else
            {
              //nothing; this leaves lineComplete=false
            }
          }
          else
          {
            // the segment did not fit entirely
            lineComplete = true;
            if (layout == null)
            {
              // nothing fitted; next line should start at first tab stop indent
              if (nextTabStop.getPosition() == ParagraphUtil.getFirstTabStop(text.getParagraph(), endX).getPosition())//FIXMETAB check based on segments.size()
              {
                // at second attempt we give up to avoid infinite loop
                nextTabStop = null;
                requireNextWord = false;
               
                //provide dummy maxFontSize because it is used for the line height of this empty line when attempting drawing below
                 AttributedString tmpText =
                  new AttributedString(
                    paragraph,
                    startIndex,
                    startIndex + 1
                    );
                 LineBreakMeasurer lbm = new LineBreakMeasurer(tmpText.getIterator(), getFontRenderContext());
                 TextLayout tlyt = lbm.nextLayout(100);
                maxAscent = tlyt.getAscent();
                maxDescent = tlyt.getDescent();
                maxLeading = tlyt.getLeading();
              }
View Full Code Here

Examples of java.text.AttributedString

    return (String)labels.get( arg1 );
  }

  public AttributedString generateAttributedSectionLabel(PieDataset arg0, Comparable arg1)
  {
    return new AttributedString(generateSectionLabel(arg0, arg1));//FIXMECHART check this
  }
View Full Code Here

Examples of java.text.AttributedString

   * @see #write(Map, AttributedCharacterIterator, String)
   */
  public String write(JRStyledText styledText,
      int startIndex, int endIndex)
  {
    AttributedCharacterIterator subIterator = new AttributedString(
        styledText.getAttributedString().getIterator(),
        startIndex, endIndex).getIterator();
    String subText = styledText.getText().substring(startIndex, endIndex);
    return write(styledText.getGlobalAttributes(), subIterator, subText);
  }
View Full Code Here

Examples of java.text.AttributedString

   */
  public Sprite createTextBox(final String text, final int width, final Color textColor,
      final Color fillColor, final boolean isTalking) {

    // Format before splitting to get the coloring right
    final AttributedString formattedString = formatLine(text.trim(), graphics.getFont(), textColor);
    // split it to max width long pieces
    final List<AttributedCharacterIterator> formattedLines = splitFormatted(formattedString, width);
   
    // Find the actual width of the text
    final int lineLengthPixels = getMaxPixelWidth(formattedLines);
View Full Code Here

Examples of java.text.AttributedString

      final StringBuilder temp = new StringBuilder();
      FormatTextParser parser = new FormatTextParserExtension(temp);
      parser.format(line);

      // create the attribute string including formating
      final AttributedString aStyledText = new AttributedString(temp.toString());

      parser = new FormatTextParser() {
        private int s = 0;

        @Override
        public void normalText(final String tok) {
          if (tok.length() > 0) {
            aStyledText.addAttribute(TextAttribute.FONT, normalFont, s, s
                + tok.length());
            aStyledText.addAttribute(TextAttribute.FOREGROUND, normalColor, s, s
                + tok.length());
            s += tok.length();
          }
        }

        @Override
        public void colorText(final String tok) {
          if (tok.length() > 0) {
            aStyledText.addAttribute(TextAttribute.FONT, specialFont, s, s
                + tok.length());
            aStyledText.addAttribute(TextAttribute.FOREGROUND, Color.blue, s, s
                + tok.length());
            s += tok.length();
          }
        }
      };
View Full Code Here

Examples of java.text.AttributedString

           * where the last text line would fit on the space the
           * ellipsis occupies.
           */
          lines.remove(lines.size() - 1);
          lines.remove(lines.size() - 1);
          lines.add(new AttributedString("...").getIterator());
          return lines;
        }
      }
    }

View Full Code Here

Examples of java.text.AttributedString

   */
  private AttributedCharacterIterator splitAggressively(final AttributedCharacterIterator text, final int width) {
    final int offset = text.getBeginIndex();
    final BreakIterator wordIterator = BreakIterator.getWordInstance();
   
    final AttributedString tmpText = new AttributedString(text);
    // return the original iterator if there are no suitable break points
    AttributedCharacterIterator best = text;
    wordIterator.setText(text);
   
    while (wordIterator.next() != BreakIterator.DONE) {
      final AttributedCharacterIterator candidate = tmpText.getIterator(null, tmpText.getIterator().getBeginIndex(), wordIterator.current() - offset);
     
      if (getPixelWidth(candidate) <= width) {
        best = candidate;
      } else {
        return best;
View Full Code Here

Examples of java.text.AttributedString

        FontRenderContext frc = joglRenderer.getFontRenderContext();

        String paragraph = text.getLine().getText();
        Map attrs = new HashMap();
        attrs.put(TextAttribute.FONT, joglRenderer.getFont());
        AttributedString str = new AttributedString(paragraph, attrs);
        LineBreakMeasurer measurer = new LineBreakMeasurer(str.getIterator(), frc);
        int curPos = 0;
        while (measurer.getPosition() < paragraph.length()) {
            int nextPos = measurer.nextOffset(width);
            String line = paragraph.substring(curPos, nextPos);
            TextDataImpl.TextLine textLine = new TextDataImpl.TextLine(line);
View Full Code Here

Examples of java.text.AttributedString

      height += fontHeight + gap;

      // The description text
      int descriptionTextHeight = 0;
      for (String descText : tooltipInfo.getDescriptionSections()) {
        AttributedString attributedDescription = new AttributedString(
            descText);
        attributedDescription.addAttribute(TextAttribute.FONT, font);
        LineBreakMeasurer lineBreakMeasurer = new LineBreakMeasurer(
            attributedDescription.getIterator(), frc);
        while (true) {
          TextLayout tl = lineBreakMeasurer.nextLayout(descTextWidth);
          if (tl == null)
            break;
          descriptionTextHeight += fontHeight;
        }
        // add an empty line after the paragraph
        descriptionTextHeight += fontHeight;
      }
      // remove the empty line after the last paragraph
      descriptionTextHeight -= fontHeight;

      if (tooltipInfo.getMainImage() != null) {
        height += Math.max(descriptionTextHeight, new JLabel(
            new ImageIcon(tooltipInfo.getMainImage()))
            .getPreferredSize().height);
      } else {
        height += descriptionTextHeight;
      }

      if ((tooltipInfo.getFooterImage() != null)
          || (tooltipInfo.getFooterSections().size() > 0)) {
        height += gap;
        // The footer separator
        height += new JSeparator(JSeparator.HORIZONTAL)
            .getPreferredSize().height;

        height += gap;

        int footerTextHeight = 0;
        int availableWidth = descTextWidth;
        if (tooltipInfo.getFooterImage() != null) {
          availableWidth -= tooltipInfo.getFooterImage().getWidth(
              null);
        }
        if (tooltipInfo.getMainImage() != null) {
          availableWidth += tooltipInfo.getMainImage().getWidth(null);
        }
        for (String footerText : tooltipInfo.getFooterSections()) {
          AttributedString attributedDescription = new AttributedString(
              footerText);
          attributedDescription
              .addAttribute(TextAttribute.FONT, font);
          LineBreakMeasurer lineBreakMeasurer = new LineBreakMeasurer(
              attributedDescription.getIterator(), frc);
          while (true) {
            TextLayout tl = lineBreakMeasurer
                .nextLayout(availableWidth);
            if (tl == null)
              break;
View Full Code Here

Examples of java.text.AttributedString

      x += 2 * gap;

      // The description text
      int descLabelWidth = parent.getWidth() - x - ins.right;
      for (String descText : tooltipInfo.getDescriptionSections()) {
        AttributedString attributedDescription = new AttributedString(
            descText);
        attributedDescription.addAttribute(TextAttribute.FONT, font);
        LineBreakMeasurer lineBreakMeasurer = new LineBreakMeasurer(
            attributedDescription.getIterator(), frc);
        int currOffset = 0;
        while (true) {
          TextLayout tl = lineBreakMeasurer
              .nextLayout(descLabelWidth);
          if (tl == null)
            break;
          int charCount = tl.getCharacterCount();
          String line = descText.substring(currOffset, currOffset
              + charCount);

          JLabel descLabel = new JLabel(line);
          descriptionLabels.add(descLabel);
          richTooltipPanel.add(descLabel);
          descLabel.setBounds(x, y,
              descLabel.getPreferredSize().width, fontHeight);
          y += descLabel.getHeight();

          currOffset += charCount;
        }
        // add an empty line after the paragraph
        y += titleLabel.getHeight();
      }
      // remove the empty line after the last paragraph
      y -= titleLabel.getHeight();

      if (mainImageLabel != null) {
        y = Math.max(y, mainImageLabel.getY()
            + mainImageLabel.getHeight());
      }

      if ((tooltipInfo.getFooterImage() != null)
          || (tooltipInfo.getFooterSections().size() > 0)) {
        y += gap;
        // The footer separator
        footerSeparator = new JSeparator(JSeparator.HORIZONTAL);
        richTooltipPanel.add(footerSeparator);
        footerSeparator.setBounds(ins.left, y, parent.getWidth()
            - ins.left - ins.right, footerSeparator
            .getPreferredSize().height);

        y += footerSeparator.getHeight() + gap;

        // The footer image
        x = ins.left;
        if (tooltipInfo.getFooterImage() != null) {
          footerImageLabel = new JLabel(new ImageIcon(tooltipInfo
              .getFooterImage()));
          richTooltipPanel.add(footerImageLabel);
          footerImageLabel.setBounds(x, y, footerImageLabel
              .getPreferredSize().width, footerImageLabel
              .getPreferredSize().height);
          x += footerImageLabel.getWidth() + 2 * gap;
        }

        // The footer text
        int footerLabelWidth = parent.getWidth() - x - ins.right;
        for (String footerText : tooltipInfo.getFooterSections()) {
          AttributedString attributedDescription = new AttributedString(
              footerText);
          attributedDescription
              .addAttribute(TextAttribute.FONT, font);
          LineBreakMeasurer lineBreakMeasurer = new LineBreakMeasurer(
              attributedDescription.getIterator(), frc);
          int currOffset = 0;
          while (true) {
            TextLayout tl = lineBreakMeasurer
                .nextLayout(footerLabelWidth);
            if (tl == null)
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.