java.text.AttributedCharacterIterator#Attribute ( )源码实例Demo

下面列出了java.text.AttributedCharacterIterator#Attribute ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: pentaho-reporting   文件: RichTextSpecTest.java
private RichTextSpec createText() {
  Map<AttributedCharacterIterator.Attribute, Object> attrs =
      new HashMap<AttributedCharacterIterator.Attribute, Object>();
  List<RichTextSpec.StyledChunk> chunks = new ArrayList<RichTextSpec.StyledChunk>();
  InstanceID id = new InstanceID();
  chunks.add( new RichTextSpec.StyledChunk( 0, 3, new SpacerRenderNode(), attrs, new ReportAttributeMap<Object>(),
      ElementDefaultStyleSheet.getDefaultStyle(), new InstanceID(), "ABC" ) );
  chunks.add( new RichTextSpec.StyledChunk( 3, 6, new SpacerRenderNode(), attrs, new ReportAttributeMap<Object>(),
      ElementDefaultStyleSheet.getDefaultStyle(), new InstanceID(), "def" ) );
  chunks.add( new RichTextSpec.StyledChunk( 6, 9, new SpacerRenderNode(), attrs, new ReportAttributeMap<Object>(),
      ElementDefaultStyleSheet.getDefaultStyle(), new InstanceID(), "GHI" ) );
  chunks.add( new RichTextSpec.StyledChunk( 9, 12, new SpacerRenderNode(), attrs, new ReportAttributeMap<Object>(),
      ElementDefaultStyleSheet.getDefaultStyle(), new InstanceID(), "jkl" ) );
  chunks.add( new RichTextSpec.StyledChunk( 12, 15, new SpacerRenderNode(), attrs, new ReportAttributeMap<Object>(),
      ElementDefaultStyleSheet.getDefaultStyle(), new InstanceID(), "MNO" ) );
  return new RichTextSpec( "ABCdefGHIjklMNO", TextDirection.LTR, chunks );
}
 
源代码2 项目: j2objc   文件: Support_Format.java
/**
 * finds attributes with regards to char index in this
 * AttributedCharacterIterator, and puts them in a vector
 *
 * @param iterator
 * @return a vector, each entry in this vector are of type FieldContainer,
 *       which stores start and end indexes and an attribute this range has
 */
protected static Vector<FieldContainer> findFields(AttributedCharacterIterator iterator) {
  Vector<FieldContainer> result = new Vector<FieldContainer>();
  while (iterator.getIndex() != iterator.getEndIndex()) {
    int start = iterator.getRunStart();
    int end = iterator.getRunLimit();

    Iterator<Attribute> it = iterator.getAttributes().keySet().iterator();
    while (it.hasNext()) {
      AttributedCharacterIterator.Attribute attribute = it.next();
      Object value = iterator.getAttribute(attribute);
      result.add(new FieldContainer(start, end, attribute, value));
      // System.out.println(start + " " + end + ": " + attribute + ",
      // " + value );
      // System.out.println("v.add(new FieldContainer(" + start +"," +
      // end +"," + attribute+ "," + value+ "));");
    }
    iterator.setIndex(end);
  }
  return result;
}
 
源代码3 项目: buffer_bci   文件: FXGraphics2D.java
/**
 * Draws a string of attributed characters at {@code (x, y)}. 
 * 
 * @param iterator  an iterator over the characters ({@code null} not 
 *     permitted).
 * @param x  the x-coordinate.
 * @param y  the y-coordinate.
 */
@Override
public void drawString(AttributedCharacterIterator iterator, float x, 
        float y) {
    Set<AttributedCharacterIterator.Attribute> 
            s = iterator.getAllAttributeKeys();
    if (!s.isEmpty()) {
        TextLayout layout = new TextLayout(iterator, 
                getFontRenderContext());
        layout.draw(this, x, y);
    } else {
        StringBuilder strb = new StringBuilder();
        iterator.first();
        for (int i = iterator.getBeginIndex(); i < iterator.getEndIndex(); 
                i++) {
            strb.append(iterator.current());
            iterator.next();
        }
        drawString(strb.toString(), x, y);
    }
}
 
源代码4 项目: pentaho-reporting   文件: RichTextSpec.java
public StyledChunk( final int start, final int end, final RenderNode originatingTextNode,
    final Map<AttributedCharacterIterator.Attribute, Object> attributes,
    final ReportAttributeMap<Object> originalAttributes, final StyleSheet styleSheet, final InstanceID instanceID,
    final String text ) {
  ArgumentNullException.validate( "originatingTextNode", originatingTextNode );
  ArgumentNullException.validate( "attributes", attributes );
  ArgumentNullException.validate( "text", text );
  ArgumentNullException.validate( "originalAttributes", originalAttributes );
  ArgumentNullException.validate( "styleSheet", styleSheet );
  ArgumentNullException.validate( "instanceID", instanceID );

  this.instanceID = instanceID;
  this.start = start;
  this.end = end;
  this.originatingTextNode = originatingTextNode;
  this.attributes = Collections.unmodifiableMap( attributes );
  this.originalAttributes = originalAttributes;
  this.styleSheet = styleSheet;
  this.text = text;
}
 
/**
 * 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;
}
 
源代码6 项目: netbeans   文件: AttributedCharacters.java
public int getRunStart(AttributedCharacterIterator.Attribute att) {
    if ((att != TextAttribute.FONT) && (att != TextAttribute.FOREGROUND)) {
        return 0; // undefined attribute
    }

    return getRunStart();
}
 
源代码7 项目: Java8CN   文件: TextLayoutStrategy.java
/**
 * Returns the index of the first character of the run
 * with respect to the given attribute containing the current character.
 */
public int getRunStart(AttributedCharacterIterator.Attribute attribute) {
    if (attribute instanceof TextAttribute) {
        int pos = toModelPosition(getIndex());
        int i = v.getViewIndex(pos, Position.Bias.Forward);
        if (attribute == TextAttribute.FONT) {
            return toIteratorIndex(getFontBoundary(i, -1));
        }
    }
    return getBeginIndex();
}
 
源代码8 项目: netbeans   文件: AttributedCharacters.java
public int getRunLimit(Set<? extends AttributedCharacterIterator.Attribute> attributes) {
    if (attributes.contains(TextAttribute.FONT) || attributes.contains(TextAttribute.FOREGROUND)) {
        return getRunLimit();
    } else {
        return getEndIndex();
    }
}
 
源代码9 项目: dragonwell8_jdk   文件: TextLayoutStrategy.java
/**
 * Returns the value of the named attribute for the current character.
 * Returns null if the attribute is not defined.
 * @param attribute the key of the attribute whose value is requested.
 */
public Object getAttribute(AttributedCharacterIterator.Attribute attribute) {
    int pos = toModelPosition(getIndex());
    int childIndex = v.getViewIndex(pos, Position.Bias.Forward);
    if (attribute == TextAttribute.FONT) {
        return getFont(childIndex);
    } else if( attribute == TextAttribute.RUN_DIRECTION ) {
        return
            v.getDocument().getProperty(TextAttribute.RUN_DIRECTION);
    } else if (attribute == TextAttribute.NUMERIC_SHAPING) {
        return shaper;
    }
    return null;
}
 
源代码10 项目: CrossMobile   文件: SwingFont.java
@SuppressWarnings("UseSpecificCatch")
static SwingFont getFont(String name, float size, boolean bold, boolean italic) {
    if (!Theme.Font.FONTNAME.equals(name))
        DesktopGraphicsBridge.loadFonts();
    Map<AttributedCharacterIterator.Attribute, Object> attributes = new HashMap<>();
    attributes.put(FAMILY, name);
    attributes.put(WEIGHT, bold ? WEIGHT_BOLD : WEIGHT_REGULAR);
    attributes.put(POSTURE, italic ? POSTURE_OBLIQUE : POSTURE_REGULAR);
    attributes.put(SIZE, size);
    return new SwingFont(new Font(attributes));
}
 
源代码11 项目: openjdk-jdk9   文件: TextLayoutStrategy.java
/**
 * Returns the value of the named attribute for the current character.
 * Returns null if the attribute is not defined.
 * @param attribute the key of the attribute whose value is requested.
 */
public Object getAttribute(AttributedCharacterIterator.Attribute attribute) {
    int pos = toModelPosition(getIndex());
    int childIndex = v.getViewIndex(pos, Position.Bias.Forward);
    if (attribute == TextAttribute.FONT) {
        return getFont(childIndex);
    } else if( attribute == TextAttribute.RUN_DIRECTION ) {
        return
            v.getDocument().getProperty(TextAttribute.RUN_DIRECTION);
    } else if (attribute == TextAttribute.NUMERIC_SHAPING) {
        return shaper;
    }
    return null;
}
 
源代码12 项目: TencentKona-8   文件: TextLayoutStrategy.java
/**
 * Returns the index of the first character following the run
 * with respect to the given attribute containing the current character.
 */
public int getRunLimit(AttributedCharacterIterator.Attribute attribute) {
    if (attribute instanceof TextAttribute) {
        int pos = toModelPosition(getIndex());
        int i = v.getViewIndex(pos, Position.Bias.Forward);
        if (attribute == TextAttribute.FONT) {
            return toIteratorIndex(getFontBoundary(i, 1));
        }
    }
    return getEndIndex();
}
 
源代码13 项目: TencentKona-8   文件: TextLayoutStrategy.java
/**
 * Returns the value of the named attribute for the current character.
 * Returns null if the attribute is not defined.
 * @param attribute the key of the attribute whose value is requested.
 */
public Object getAttribute(AttributedCharacterIterator.Attribute attribute) {
    int pos = toModelPosition(getIndex());
    int childIndex = v.getViewIndex(pos, Position.Bias.Forward);
    if (attribute == TextAttribute.FONT) {
        return getFont(childIndex);
    } else if( attribute == TextAttribute.RUN_DIRECTION ) {
        return
            v.getDocument().getProperty(TextAttribute.RUN_DIRECTION);
    } else if (attribute == TextAttribute.NUMERIC_SHAPING) {
        return shaper;
    }
    return null;
}
 
源代码14 项目: jdk8u-jdk   文件: BidiBase.java
@SuppressWarnings("serial")
private static AttributedCharacterIterator.Attribute
    getTextAttribute(String name)
{
    if (clazz == null) {
        // fake attribute
        return new AttributedCharacterIterator.Attribute(name) { };
    } else {
        return (AttributedCharacterIterator.Attribute)getStaticField(clazz, name);
    }
}
 
源代码15 项目: jdk8u-jdk   文件: BidiBase.java
@SuppressWarnings("serial")
private static AttributedCharacterIterator.Attribute
    getTextAttribute(String name)
{
    if (clazz == null) {
        // fake attribute
        return new AttributedCharacterIterator.Attribute(name) { };
    } else {
        return (AttributedCharacterIterator.Attribute)getStaticField(clazz, name);
    }
}
 
源代码16 项目: openjdk-8-source   文件: TextLayoutStrategy.java
/**
 * Returns the index of the first character following the run
 * with respect to the given attribute containing the current character.
 */
public int getRunLimit(AttributedCharacterIterator.Attribute attribute) {
    if (attribute instanceof TextAttribute) {
        int pos = toModelPosition(getIndex());
        int i = v.getViewIndex(pos, Position.Bias.Forward);
        if (attribute == TextAttribute.FONT) {
            return toIteratorIndex(getFontBoundary(i, 1));
        }
    }
    return getEndIndex();
}
 
源代码17 项目: ttt   文件: IMSC11ResourceConverterState.java
private void populateAttributedText(List<Serializable> content, String text, Map<AttributedCharacterIterator.Attribute,Object> attributes, Direction blockDirection) {
    Span sEmphasis      = null;
    Span sRuby          = null;
    Span sCombine       = null;
    Span sWideBar       = null;
    Span sOuter         = null;
    int numExclusive    = 0;
    for (Map.Entry<AttributedCharacterIterator.Attribute,Object> e : attributes.entrySet()) {
        Attribute a = (Attribute) e.getValue();
        if (a.isEmphasis()) {
            sEmphasis = createEmphasis(text, a, blockDirection);
            ++numExclusive;
        } else if (a.isRuby()) {
            sRuby = createRuby(text, a, blockDirection);
            ++numExclusive;
        } else if (a.isCombine()) {
            sCombine = createCombine(text, a, blockDirection);
            ++numExclusive;
        } else if (a.isStretchWide() && isHorizontalBar(text)) {
            sWideBar = createWideBar(text, a, blockDirection);
            ++numExclusive;
        } else {
            if (sOuter == null)
                sOuter = createStyledSpan(null, a);
            else
                sOuter = augmentStyledSpan(sOuter, a);
        }
    }
    if (numExclusive > 1)
        throw new IllegalStateException();
    if (sOuter == null) {
        if (sEmphasis != null)
            sOuter = sEmphasis;
        else if (sRuby != null)
            sOuter = sRuby;
        else if (sCombine != null)
            sOuter = sCombine;
        else if (sWideBar != null)
            sOuter = sWideBar;
    } else {
        Span sInner = null;
        if (sEmphasis != null)
            sInner = sEmphasis;
        else if (sRuby != null)
            sInner = sRuby;
        else if (sCombine != null)
            sInner = sCombine;
        else if (sWideBar != null)
            sInner = sWideBar;
        if (sInner != null) {
            sOuter.getContent().add(ttmlFactory.createSpan(sInner));
        } else {
            sOuter.getContent().add(text);
        }
    }
    if (sOuter != null)
        content.add(ttmlFactory.createSpan(sOuter));
}
 
源代码18 项目: pentaho-reporting   文件: RichTextSpec.java
public Map<AttributedCharacterIterator.Attribute, Object> getAttributes() {
  return attributes;
}
 
源代码19 项目: j2objc   文件: IntlTestDecimalFormatAPIC.java
public FieldContainer(int start, int end, AttributedCharacterIterator.Attribute attribute, int value) {
this(start, end, attribute, new Integer(value));
}
 
源代码20 项目: radiance   文件: FontSets.java
@Override
public Font deriveFont(final Map<? extends AttributedCharacterIterator.Attribute, ?> attributes) {
	return new DefaultUIResourceFont(super.deriveFont(attributes));
}