本文整理汇总了Java中java.text.AttributedCharacterIterator类的典型用法代码示例。如果您正苦于以下问题:Java AttributedCharacterIterator类的具体用法?Java AttributedCharacterIterator怎么用?Java AttributedCharacterIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AttributedCharacterIterator类属于java.text包,在下文中一共展示了AttributedCharacterIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFontAtCurrentPos
import java.text.AttributedCharacterIterator; //导入依赖的package包/类
static Font getFontAtCurrentPos(AttributedCharacterIterator aci) {
Object value = aci.getAttribute(TextAttribute.FONT);
if (value != null) {
return (Font) value;
}
if (aci.getAttribute(TextAttribute.FAMILY) != null) {
return Font.getFont(aci.getAttributes());
}
int ch = CodePointIterator.create(aci).next();
if (ch != CodePointIterator.DONE) {
FontResolver resolver = FontResolver.getInstance();
return resolver.getFont(resolver.getFontIndex(ch), aci.getAttributes());
}
return null;
}
示例2: write
import java.text.AttributedCharacterIterator; //导入依赖的package包/类
@Override
public void write(Text text, Writer writer) throws IOException {
AttributedCharacterIterator iterator = text.getIterator();
Entry<Attribute, Object> lastAttribute = null;
while (true) {
if (iterator.getIndex() == iterator.getEndIndex()) {
break;
}
Entry<Attribute, Object> entry = getAttribute(iterator);
if (!Objects.equals(entry, lastAttribute)) {
endEntity(lastAttribute, writer);
beginEntity(entry, writer);
}
writer.write(iterator.current());
lastAttribute = entry;
iterator.next();
}
endEntity(lastAttribute, writer);
}
示例3: while
import java.text.AttributedCharacterIterator; //导入依赖的package包/类
private static AttributedCharacterIterator getTrimmedTrailingSpacesIterator
(AttributedCharacterIterator iterator) {
int curIdx = iterator.getIndex();
char c = iterator.last();
while(c != CharacterIterator.DONE && Character.isWhitespace(c)) {
c = iterator.previous();
}
if (c != CharacterIterator.DONE) {
int endIdx = iterator.getIndex();
if (endIdx == iterator.getEndIndex() - 1) {
iterator.setIndex(curIdx);
return iterator;
} else {
AttributedString trimmedText = new AttributedString(iterator,
iterator.getBeginIndex(), endIdx + 1);
return trimmedText.getIterator();
}
} else {
return null;
}
}
示例4: checkIteratorText
import java.text.AttributedCharacterIterator; //导入依赖的package包/类
private static final void checkIteratorText(AttributedCharacterIterator iterator, String expectedText) throws Exception {
if (iterator.getEndIndex() - iterator.getBeginIndex() != expectedText.length()) {
throwException(iterator, "text length doesn't match between original text and iterator");
}
char c = iterator.first();
for (int i = 0; i < expectedText.length(); i++) {
if (c != expectedText.charAt(i)) {
throwException(iterator, "text content doesn't match between original text and iterator");
}
c = iterator.next();
}
if (c != CharacterIterator.DONE) {
throwException(iterator, "iterator text doesn't end with DONE");
}
}
示例5: select
import java.text.AttributedCharacterIterator; //导入依赖的package包/类
/**
* Selects the passed in field, returning true if it is found, false
* otherwise.
*/
private boolean select(JFormattedTextField ftf, AttributedCharacterIterator iterator, DateFormat.Field field)
{
int max = ftf.getDocument().getLength();
iterator.first();
do
{
Map<Attribute, Object> attrs = iterator.getAttributes();
if( attrs != null && attrs.containsKey(field) )
{
int start = iterator.getRunStart(field);
int end = iterator.getRunLimit(field);
if( start != -1 && end != -1 && start <= max && end <= max )
{
ftf.select(start, end);
}
return true;
}
}
while( iterator.next() != CharacterIterator.DONE );
return false;
}
示例6: getAttribute
import java.text.AttributedCharacterIterator; //导入依赖的package包/类
public Object getAttribute(AttributedCharacterIterator.Attribute att) {
if (att == TextAttribute.FONT) {
return fonts[getIndex()];
} else if (att == TextAttribute.FOREGROUND) {
return colors[getIndex()];
} else {
return null;
}
}
示例7: getAttributes
import java.text.AttributedCharacterIterator; //导入依赖的package包/类
public Map<AttributedCharacterIterator.Attribute,Object> getAttributes() {
Map<AttributedCharacterIterator.Attribute,Object> m = new HashMap<AttributedCharacterIterator.Attribute,Object>(1);
m.put(TextAttribute.FONT, fonts[getIndex()]);
m.put(TextAttribute.FOREGROUND, colors[getIndex()]);
return m;
}
示例8: getRunLimit
import java.text.AttributedCharacterIterator; //导入依赖的package包/类
public int getRunLimit(AttributedCharacterIterator.Attribute att) {
if ((att != TextAttribute.FONT) && (att != TextAttribute.FOREGROUND)) {
return getEndIndex(); // undefined attribute
}
return getRunLimit();
}
示例9: standardCreateTextLine
import java.text.AttributedCharacterIterator; //导入依赖的package包/类
/**
* Create a TextLine from the text. chars is just the text in the iterator.
*/
public static TextLine standardCreateTextLine(FontRenderContext frc,
AttributedCharacterIterator text,
char[] chars,
float[] baselineOffsets) {
StyledParagraph styledParagraph = new StyledParagraph(text, chars);
Bidi bidi = new Bidi(text);
if (bidi.isLeftToRight()) {
bidi = null;
}
int layoutFlags = 0; // no extra info yet, bidi determines run and line direction
TextLabelFactory factory = new TextLabelFactory(frc, chars, bidi, layoutFlags);
boolean isDirectionLTR = true;
if (bidi != null) {
isDirectionLTR = bidi.baseIsLeftToRight();
}
return createLineFromText(chars, styledParagraph, factory, isDirectionLTR, baselineOffsets);
}
示例10: ComponentLine
import java.text.AttributedCharacterIterator; //导入依赖的package包/类
ComponentLine(AttributedCharacterIterator it, Font defaultFont, Color defaultColor) {
for (char c = it.first(); c != CharacterIterator.DONE; c = it.next()) {
Font font = (Font) it.getAttribute(TextAttribute.FONT);
Color color = (Color) it.getAttribute(TextAttribute.FOREGROUND);
mySymbols.add(new Symbol(c, createFont(font, defaultFont), createColor(color, defaultColor)));
}
checkSpaces(defaultFont, defaultColor);
}
示例11: getRunLimit
import java.text.AttributedCharacterIterator; //导入依赖的package包/类
/**
* 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();
}
示例12: advanceToFirstFont
import java.text.AttributedCharacterIterator; //导入依赖的package包/类
/**
* When this returns, the ACI's current position will be at the start of the
* first run which does NOT contain a GraphicAttribute. If no such run exists
* the ACI's position will be at the end, and this method will return false.
*/
static boolean advanceToFirstFont(AttributedCharacterIterator aci) {
for (char ch = aci.first();
ch != CharacterIterator.DONE;
ch = aci.setIndex(aci.getRunLimit()))
{
if (aci.getAttribute(TextAttribute.CHAR_REPLACEMENT) == null) {
return true;
}
}
return false;
}
示例13: translateAttributes
import java.text.AttributedCharacterIterator; //导入依赖的package包/类
private AttributeSet translateAttributes(Map<AttributedCharacterIterator.Attribute, ?> source) {
for(AttributedCharacterIterator.Attribute sourceKey : source.keySet()) {
Object sourceValue = source.get(sourceKey);
// Ignore any non-input method related highlights
if (!(sourceValue instanceof InputMethodHighlight)) {
continue;
}
InputMethodHighlight imh = (InputMethodHighlight) sourceValue;
if (imh.isSelected()) {
return highlightInverse;
} else {
return highlightUnderlined;
}
}
LOG.fine("No translation for " + source);
return SimpleAttributeSet.EMPTY;
}
示例14: getEntitiesWithValues
import java.text.AttributedCharacterIterator; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <T> List<Map.Entry<String, T>> getEntitiesWithValues(TextEntity entity) {
AttributedCharacterIterator iterator = getIterator();
List<Map.Entry<String, T>> entities = new ArrayList<>();
StringBuilder builder = new StringBuilder();
Map<AttributedCharacterIterator.Attribute, T> last = Collections.emptyMap();
while (iterator.getIndex() != iterator.getEndIndex()) {
Map<AttributedCharacterIterator.Attribute, T> curr =
(Map<AttributedCharacterIterator.Attribute, T>) iterator.getAttributes();
if (curr.containsKey(entity)) {
builder.append(iterator.current());
} else {
if (last.containsKey(entity)) {
entities.add(
new AbstractMap.SimpleImmutableEntry<>(builder.toString(), last.get(entity))
);
builder.setLength(0);
}
}
last = curr;
iterator.next();
}
if (last.containsKey(entity)) {
entities.add(
new AbstractMap.SimpleImmutableEntry<>(builder.toString(), last.get(entity))
);
}
return entities;
}
示例15: TextLayout
import java.text.AttributedCharacterIterator; //导入依赖的package包/类
/**
* Constructs a {@code TextLayout} from an iterator over styled text.
* <p>
* The iterator must specify a single paragraph of text because an
* entire paragraph is required for the bidirectional
* algorithm.
* @param text the styled text to display
* @param frc contains information about a graphics device which is needed
* to measure the text correctly.
* Text measurements can vary slightly depending on the
* device resolution, and attributes such as antialiasing. This
* parameter does not specify a translation between the
* {@code TextLayout} and user space.
*/
public TextLayout(AttributedCharacterIterator text, FontRenderContext frc) {
if (text == null) {
throw new IllegalArgumentException("Null iterator passed to TextLayout constructor.");
}
int start = text.getBeginIndex();
int limit = text.getEndIndex();
if (start == limit) {
throw new IllegalArgumentException("Zero length iterator passed to TextLayout constructor.");
}
int len = limit - start;
text.first();
char[] chars = new char[len];
int n = 0;
for (char c = text.first();
c != CharacterIterator.DONE;
c = text.next())
{
chars[n++] = c;
}
text.first();
if (text.getRunLimit() == limit) {
Map<? extends Attribute, ?> attributes = text.getAttributes();
Font font = singleFont(chars, 0, len, attributes);
if (font != null) {
fastInit(chars, font, attributes, frc);
return;
}
}
standardInit(text, chars, frc);
}