for (char c = paragraphIter.first(); c != paragraphIter.DONE; c = paragraphIter.next()) {
for (char c = paragraphIter.first(); c != CharacterIterator.DONE; c = paragraphIter.next()) {
	protected float drawText(Graphics g, Rectangle displayBox) {		Graphics2D g2 = null;		Shape savedClipArea = null;		Color savedFontColor = null;		Rectangle2D clipRect = null;		RenderingHints savedRenderingHints = null;		if (g != null) {			g2 = (Graphics2D)g;			savedRenderingHints = g2.getRenderingHints();			g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,					RenderingHints.VALUE_ANTIALIAS_ON);			g2.setRenderingHint(RenderingHints.KEY_RENDERING,					RenderingHints.VALUE_RENDER_QUALITY);			//Font savedFont = g2.getFont();			savedFontColor = g2.getColor();			savedClipArea = g2.getClip();			if(savedClipArea != null) {			clipRect = displayBox.createIntersection((Rectangle2D)savedClipArea);			} else {				clipRect = displayBox;			}			g2.setClip(clipRect);			Color textColor = getTextColor();			if (!ColorMap.isTransparent(textColor)) {				g2.setColor(textColor);			}			g2.setFont(getFont());		}		FontRenderContext fontRenderCtx = new FontRenderContext(null, false, false);		// split the text into paragraphs		prepareText();		float leftMargin = displayBox.x + ((Float)getAttribute("LeftMargin")).floatValue();		float rightMargin = displayBox.x + displayBox.width - ((Float)getAttribute("RightMargin")).floatValue();		float topMargin = displayBox.y + ((Float)getAttribute("TopMargin")).floatValue();		/**		 * @todo   we prepare stops for 40 tabs which should be enough to handle		 * all normal cases, but a better means should/could be implemented		 */		float[] tabStops = new float[40];		// tabSize is in pixels		float tabSize = ((Float)getAttribute("TabSize")).floatValue() * getFontWidth();		float tabPos = tabSize;		for (int tabCnt = 0; tabCnt < 40; tabCnt++) {			tabStops[tabCnt] = tabPos + leftMargin;			tabPos += tabSize;		}		/** Iterate on the paragraphs displaying each one in turn */		float verticalPos = topMargin;		Iterator paragraphs = fParagraphs.iterator();		while (paragraphs.hasNext()) {			String paragraphText = (String)paragraphs.next();			// prepare tabs. Here we build an array with the character positions			// of the tabs within the paragraph			AttributedString attrText = new AttributedString(paragraphText);			AttributedCharacterIterator paragraphIter = attrText.getIterator();			int[] tabLocations = new int[paragraphText.length()];			int tabCount = 0;			for (char c = paragraphIter.first(); c != paragraphIter.DONE; c = paragraphIter.next()) {				if (c == '\t') {					tabLocations[tabCount++] = paragraphIter.getIndex();				}			}			tabLocations[tabCount] = paragraphIter.getEndIndex() - 1;			// tabs done. Replace tab characters with spaces. This to avoid			// a strange behaviour where the layout is a lot slower and			// the font get's changed. If anybody knows why this so please			// tell me.			paragraphText = paragraphText.replace('\t', ' ');			attrText = new AttributedString(paragraphText, attributesMap);			paragraphIter = attrText.getIterator();			// Now tabLocations has an entry for every tab's offset in			// the text.  For convenience, the last entry in tabLocations			// is the offset of the last character in the text.			LineBreakMeasurer measurer = new LineBreakMeasurer(paragraphIter, fontRenderCtx);			int currentTab = 0;			while (measurer.getPosition() < paragraphIter.getEndIndex()) {				// Lay out and draw each line.  All segments on a line				// must be computed before any drawing can occur, since				// we must know the largest ascent on the line.				// TextLayouts are computed and stored in a collection;				// their horizontal positions are stored in a parallel				// collection.				// lineContainsText is true after first segment is drawn				boolean lineContainsText = false;				boolean lineComplete = false;				float maxAscent = 0;				float maxDescent = 0;				float horizontalPos = leftMargin;				List layouts = CollectionsFactory.current().createList(1);				List penPositions = CollectionsFactory.current().createList(1);				while (!lineComplete) {					float wrappingWidth = rightMargin - horizontalPos;					// ensure wrappingWidth is at least 1					wrappingWidth = Math.max(1, wrappingWidth);					TextLayout layout =							measurer.nextLayout(wrappingWidth,							tabLocations[currentTab] + 1,							lineContainsText);					// layout can be null if lineContainsText is true					if (layout != null) {						layouts.add(layout);						penPositions.add(new Float(horizontalPos));						horizontalPos += layout.getAdvance();						maxAscent = Math.max(maxAscent, layout.getAscent());						maxDescent = Math.max(maxDescent,								layout.getDescent() + layout.getLeading());					}					else {						lineComplete = true;					}					lineContainsText = true;					if (measurer.getPosition() == tabLocations[currentTab] + 1) {						currentTab++;					}					if (measurer.getPosition() == paragraphIter.getEndIndex()) {						lineComplete = true;					}					else if (horizontalPos >= tabStops[tabStops.length - 1]) {						lineComplete = true;					}					if (!lineComplete) {						// move to next tab stop						int j;						for (j = 0; horizontalPos >= tabStops[j]; j++) {						}						horizontalPos = tabStops[j];					}				}				// set the vertical position for the line				verticalPos += maxAscent;				// now iterate through layouts and draw them				Iterator layoutEnum = layouts.iterator();				Iterator positionEnum = penPositions.iterator();				while (layoutEnum.hasNext()) {					TextLayout nextLayout = (TextLayout)layoutEnum.next();					Float nextPosition = (Float)positionEnum.next();					if (g2 != null) {						nextLayout.draw(g2, nextPosition.floatValue(), verticalPos);					}				}				// keep track of the highest (actually lowest) position for the				// next iteration				verticalPos += maxDescent;			}		}		// if the last displayed line is not visible because the displayBox is		// too small then draw a dashed red line at the bottom		if (g2 != null && verticalPos > clipRect.getMaxY() && clipRect.getMaxY() == displayBox.getMaxY()) {			Stroke savedStroke = g2.getStroke();			float[] dash = new float[2];			dash[0] = 2f;			dash[1] = 4f;			g2.setStroke(new BasicStroke(					1f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER,					1f, dash, 0f));			g2.setColor(Color.red);			g2.drawLine((int)clipRect.getMinX() + 1, (int)clipRect.getMaxY() - 1,					(int)clipRect.getMaxX() - 1, (int)clipRect.getMaxY() - 1);			g2.setStroke(savedStroke);		}		// restore saved graphic attributes		if (g2 != null) {			if(savedClipArea != null) {			g2.setClip(savedClipArea);			}			g2.setColor(savedFontColor);			g2.setRenderingHints(savedRenderingHints);		}		// and return the final text height		return verticalPos;	}