/** * */ public AttributedString getAttributedString() { if (attributedString == null) { attributedString = new AttributedString(sbuffer.toString()); for(int i = runs.size() - 1; i >= 0; i--) { Run run = (Run)runs.get(i); if (run.startIndex != run.endIndex && run.attributes != null) { attributedString.addAttributes(run.attributes, run.startIndex, run.endIndex); } } } return attributedString; }
private AttributedString createTickLabelAttributedString(double logy, Format exponentFormatter) { String baseStr = this.baseSymbol; if (baseStr == null) { baseStr = this.baseFormatter.format(this.base); } String exponentStr = exponentFormatter.format(logy); AttributedString as = new AttributedString(baseStr + exponentStr); as.addAttributes(getTickLabelFont().getAttributes(), 0, (baseStr + exponentStr).length()); as.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, baseStr.length(), baseStr.length() + exponentStr.length()); return as; }
/** * Creates and returns an {@code AttributedString} with the specified * text and the labelFont and labelPaint applied as attributes. * * @param label the label ({@code null} permitted). * * @return An attributed string or {@code null}. * * @since 1.0.16 */ public AttributedString createAttributedLabel(String label) { if (label == null) { return null; } AttributedString s = new AttributedString(label); s.addAttributes(this.labelFont.getAttributes(), 0, label.length()); return s; }
int limit = stream.readInt(); Map atts = (Map) stream.readObject(); result.addAttributes(atts, start, limit); start = limit; c = stream.readChar();
/** * Reads the object from the object input stream. * * @param stream the object input stream from where to read the serialized data. * @return the generated object. * @throws IOException if reading the stream failed. * @throws ClassNotFoundException if serialized object class cannot be found. */ public Object readObject( final ObjectInputStream stream ) throws IOException, ClassNotFoundException { // read string and attributes then create result final String plainStr = (String) stream.readObject(); final AttributedString result = new AttributedString( plainStr ); char c = stream.readChar(); int start = 0; while ( c != CharacterIterator.DONE ) { final int limit = stream.readInt(); final Map<AttributedCharacterIterator.Attribute, Object> atts = (Map<AttributedCharacterIterator.Attribute, Object>) stream.readObject(); result.addAttributes( atts, start, limit ); start = limit; c = stream.readChar(); } return result; }
int limit = stream.readInt(); Map atts = (Map) stream.readObject(); result.addAttributes(atts, start, limit); start = limit; c = stream.readChar();
int limit = stream.readInt(); Map atts = (Map) stream.readObject(); result.addAttributes(atts, start, limit); start = limit; c = stream.readChar();
int limit = stream.readInt(); Map atts = (Map) stream.readObject(); result.addAttributes(atts, start, limit); start = limit; c = stream.readChar();
@Override public MBFImage getNextFrame() { // draw scene this.updateBall(); this.frame.fill(RGBColour.BLACK); this.renderer.drawShapeFilled(this.borderTop, RGBColour.GRAY); this.renderer.drawShapeFilled(this.borderBottom, RGBColour.GRAY); this.renderer.drawShapeFilled(this.paddleLeft, RGBColour.RED); this.renderer.drawShapeFilled(this.paddleRight, RGBColour.BLUE); this.renderer.drawShapeFilled(this.ball, RGBColour.WHITE); // if(contactPoint!=null) renderer.drawPoint(contactPoint, 1.0f, 10); final int scorLeftLength = new String("" + this.scoreLeft).length(); final int scorRightLength = new String("" + this.scoreRight).length(); final int sepLength = new String(" : ").length(); final String allString = this.scoreLeft + " : " + this.scoreRight; final AttributedString str = new AttributedString(allString); str.addAttributes(this.allFont, 0, allString.length()); str.addAttributes(this.redText, 0, scorLeftLength); str.addAttributes(this.blueText, scorLeftLength + sepLength, scorLeftLength + sepLength + scorRightLength); this.renderer.drawText(str, this.frame_width / 2, 40); this.lastFrame.drawImage(this.frame, 0, 0); this.currentFrame++; return this.frame; }
public void append(String text, Color foreground) { if(text.length() == 0) { throw new IllegalArgumentException("text must not be empty"); } AttributedString replacementText = new AttributedString(plainText + text); replacementText.addAttributes(paragraphText.getIterator().getAttributes(), 0, plainText.length()); AttributedCharacterIterator charIt = paragraphText.getIterator(); while(charIt.current() != AttributedCharacterIterator.DONE) { replacementText.addAttributes(charIt.getAttributes(), charIt.getIndex(), charIt.getEndIndex() + 1); charIt.next(); } replacementText.addAttribute(TextAttribute.FOREGROUND, foreground, plainText.length(), plainText.length() + text.length()); paragraphText = replacementText; computePlainString(); invalidateLayout(); }
@Override public MBFImage getNextFrame() { // draw scene this.updateBall(); this.frame.fill(RGBColour.BLACK); this.renderer.drawShapeFilled(this.borderTop, RGBColour.GRAY); this.renderer.drawShapeFilled(this.borderBottom, RGBColour.GRAY); this.renderer.drawShapeFilled(this.paddleLeft, RGBColour.RED); this.renderer.drawShapeFilled(this.paddleRight, RGBColour.BLUE); this.renderer.drawShapeFilled(this.ball, RGBColour.WHITE); // if(contactPoint!=null) renderer.drawPoint(contactPoint, 1.0f, 10); final int scorLeftLength = new String("" + this.scoreLeft).length(); final int scorRightLength = new String("" + this.scoreRight).length(); final int sepLength = new String(" : ").length(); final String allString = this.scoreLeft + " : " + this.scoreRight; final AttributedString str = new AttributedString(allString); str.addAttributes(this.allFont, 0, allString.length()); str.addAttributes(this.redText, 0, scorLeftLength); str.addAttributes(this.blueText, scorLeftLength + sepLength, scorLeftLength + sepLength + scorRightLength); this.renderer.drawText(str, this.frame_width / 2, 40); this.lastFrame.drawImage(this.frame, 0, 0); this.currentFrame++; return this.frame; }
public TextLayout( String string, Map<? extends java.text.AttributedCharacterIterator.Attribute, ?> attributes, FontRenderContext frc ) { if (string == null){ // awt.01='{0}' parameter is null throw new IllegalArgumentException(Messages.getString("awt.01", "string")); //$NON-NLS-1$ //$NON-NLS-2$ } if (attributes == null){ // awt.01='{0}' parameter is null throw new IllegalArgumentException(Messages.getString("awt.01", "attributes")); //$NON-NLS-1$ //$NON-NLS-2$ } if (string.length() == 0){ // awt.02='{0}' parameter has zero length throw new IllegalArgumentException(Messages.getString("awt.02", "string")); //$NON-NLS-1$ //$NON-NLS-2$ } AttributedString as = new AttributedString(string); as.addAttributes(attributes, 0, string.length()); this.breaker = new TextRunBreaker(as.getIterator(), frc); caretManager = new CaretManager(breaker); }
public void append(String text, Color foreground) { if(text.length() == 0) { throw new IllegalArgumentException("text must not be empty"); } AttributedString replacementText = new AttributedString(plainText + text); replacementText.addAttributes(paragraphText.getIterator().getAttributes(), 0, plainText.length()); AttributedCharacterIterator charIt = paragraphText.getIterator(); while(charIt.current() != AttributedCharacterIterator.DONE) { replacementText.addAttributes(charIt.getAttributes(), charIt.getIndex(), charIt.getEndIndex() + 1); charIt.next(); } replacementText.addAttribute(TextAttribute.FOREGROUND, foreground, plainText.length(), plainText.length() + text.length()); paragraphText = replacementText; computePlainString(); invalidateLayout(); }
public void append(String text, Color foreground) { AttributedString replacementText = new AttributedString(plainText + text); replacementText.addAttributes(paragraphText.getIterator().getAttributes(), 0, plainText.length()); AttributedCharacterIterator charIt = paragraphText.getIterator(); while(charIt.current() != AttributedCharacterIterator.DONE) { replacementText.addAttributes(charIt.getAttributes(), charIt.getIndex(), charIt.getEndIndex() + 1); charIt.next(); } replacementText.addAttribute(TextAttribute.FOREGROUND, foreground, plainText.length(), plainText.length() + text.length()); paragraphText = replacementText; computePlainString(); invalidateLayout(); }
private AttributedString createText() { AttributedString str = new AttributedString( text ); str.addAttribute( TextAttribute.RUN_DIRECTION, TextDirection.RTL.equals( runDirection ) ); int startPosition = 0; for ( final StyledChunk chunk : styleChunks ) { int length = chunk.getText().length(); int endIndex = startPosition + length; str.addAttributes( chunk.getAttributes(), startPosition, endIndex ); startPosition = endIndex; } return str; }
string.addAttributes(map, start, start + text.getText().length());
AttributedCharacterIterator aci1 = attributedString1.getIterator(); AttributedCharacterIterator aci2 = attributedString2.getIterator(); StringBuilder sb = new StringBuilder(); char ch = aci1.current(); while( ch != CharacterIterator.DONE) { sb.append( ch); ch = aci1.next(); } ch = aci2.current(); while( ch != CharacterIterator.DONE) { sb.append( ch); ch = aci2.next(); } AttributedString combined = new AttributedString( sb.toString()); combined.addAttributes( aci1.getAttributes(), 0, aci1.getEndIndex()); combined.addAttributes( aci2.getAttributes(), aci1.getEndIndex(), aci1.getEndIndex() + aci2.getEndIndex());
/** * Creates a tick label for the specified value based on the current * tick unit (used for formatting the exponent). * * @param value the value. * * @return The label. * * @since 1.0.18 */ protected AttributedString createTickLabel(double value) { if (this.numberFormatOverride != null) { return new AttributedString( this.numberFormatOverride.format(value)); } else { String baseStr = this.baseSymbol; if (baseStr == null) { baseStr = this.baseFormatter.format(this.base); } double logy = calculateLog(value); String exponentStr = getTickUnit().valueToString(logy); AttributedString as = new AttributedString(baseStr + exponentStr); as.addAttributes(getTickLabelFont().getAttributes(), 0, (baseStr + exponentStr).length()); as.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, baseStr.length(), baseStr.length() + exponentStr.length()); return as; } }
str.addAttributes(redText, 4, 8); str.addAttributes(cursiveText, 8, 12);
str.addAttributes(redText, 4, 8); str.addAttributes(cursiveText, 8, 12);