Package java.text

Examples of java.text.AttributedString$AttributedStringIterator


    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


   * @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

   */
  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

      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

           * 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

   */
  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

        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

      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

      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

     * @param column    0-based index of the column
     * @param useMergedCells    whether to use merged cells
     * @return  the width in pixels
     */
    public static double getColumnWidth(Sheet sheet, int column, boolean useMergedCells){
        AttributedString str;
        TextLayout layout;

        Workbook wb = sheet.getWorkbook();
        DataFormatter formatter = new DataFormatter();
        Font defaultFont = wb.getFontAt((short) 0);

        str = new AttributedString(String.valueOf(defaultChar));
        copyAttributes(defaultFont, str, 0, 1);
        layout = new TextLayout(str.getIterator(), fontRenderContext);
        int defaultCharWidth = (int)layout.getAdvance();

        double width = -1;
        rows:
        for (Row row : sheet) {
            Cell cell = row.getCell(column);

            if (cell == null) {
                continue;
            }

            int colspan = 1;
            for (int i = 0 ; i < sheet.getNumMergedRegions(); i++) {
                CellRangeAddress region = sheet.getMergedRegion(i);
                if (containsCell(region, row.getRowNum(), column)) {
                    if (!useMergedCells) {
                        // If we're not using merged cells, skip this one and move on to the next.
                        continue rows;
                    }
                    cell = row.getCell(region.getFirstColumn());
                    colspan = 1 + region.getLastColumn() - region.getFirstColumn();
                }
            }

            CellStyle style = cell.getCellStyle();
            int cellType = cell.getCellType();

            // for formula cells we compute the cell width for the cached formula result
            if(cellType == Cell.CELL_TYPE_FORMULA) cellType = cell.getCachedFormulaResultType();

            Font font = wb.getFontAt(style.getFontIndex());

            if (cellType == Cell.CELL_TYPE_STRING) {
                RichTextString rt = cell.getRichStringCellValue();
                String[] lines = rt.getString().split("\\n");
                for (int i = 0; i < lines.length; i++) {
                    String txt = lines[i] + defaultChar;

                    str = new AttributedString(txt);
                    copyAttributes(font, str, 0, txt.length());

                    if (rt.numFormattingRuns() > 0) {
                        // TODO: support rich text fragments
                    }

                    layout = new TextLayout(str.getIterator(), fontRenderContext);
                    if(style.getRotation() != 0){
                        /*
                         * Transform the text using a scale so that it's height is increased by a multiple of the leading,
                         * and then rotate the text before computing the bounds. The scale results in some whitespace around
                         * the unrotated top and bottom of the text that normally wouldn't be present if unscaled, but
                         * is added by the standard Excel autosize.
                         */
                        AffineTransform trans = new AffineTransform();
                        trans.concatenate(AffineTransform.getRotateInstance(style.getRotation()*2.0*Math.PI/360.0));
                        trans.concatenate(
                        AffineTransform.getScaleInstance(1, fontHeightMultiple)
                        );
                        width = Math.max(width, ((layout.getOutline(trans).getBounds().getWidth() / colspan) / defaultCharWidth) + cell.getCellStyle().getIndention());
                    } else {
                        width = Math.max(width, ((layout.getBounds().getWidth() / colspan) / defaultCharWidth) + cell.getCellStyle().getIndention());
                    }
                }
            } else {
                String sval = null;
                if (cellType == Cell.CELL_TYPE_NUMERIC) {
                    // Try to get it formatted to look the same as excel
                    try {
                        sval = formatter.formatCellValue(cell, dummyEvaluator);
                    } catch (Exception e) {
                        sval = String.valueOf(cell.getNumericCellValue());
                    }
                } else if (cellType == Cell.CELL_TYPE_BOOLEAN) {
                    sval = String.valueOf(cell.getBooleanCellValue()).toUpperCase();
                }
                if(sval != null) {
                    String txt = sval + defaultChar;
                    str = new AttributedString(txt);
                    copyAttributes(font, str, 0, txt.length());

                    layout = new TextLayout(str.getIterator(), fontRenderContext);
                    if(style.getRotation() != 0){
                        /*
                         * Transform the text using a scale so that it's height is increased by a multiple of the leading,
                         * and then rotate the text before computing the bounds. The scale results in some whitespace around
                         * the unrotated top and bottom of the text that normally wouldn't be present if unscaled, but
View Full Code Here

TOP

Related Classes of java.text.AttributedString$AttributedStringIterator

Copyright © 2018 www.massapicom. 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.