本文整理汇总了Java中java.text.AttributedCharacterIterator.getAttributes方法的典型用法代码示例。如果您正苦于以下问题:Java AttributedCharacterIterator.getAttributes方法的具体用法?Java AttributedCharacterIterator.getAttributes怎么用?Java AttributedCharacterIterator.getAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.AttributedCharacterIterator
的用法示例。
在下文中一共展示了AttributedCharacterIterator.getAttributes方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEntities
import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
private List<String> getEntities(TextEntity entity) {
AttributedCharacterIterator iterator = getIterator();
List<String> entities = new ArrayList<>();
StringBuilder builder = new StringBuilder();
Map<AttributedCharacterIterator.Attribute, Object> last = Collections.emptyMap();
while (iterator.getIndex() != iterator.getEndIndex()) {
Map<AttributedCharacterIterator.Attribute, Object> curr = iterator.getAttributes();
if (curr.containsKey(entity)) {
builder.append(iterator.current());
} else {
if (last.containsKey(entity)) {
entities.add(builder.toString());
builder.setLength(0);
}
}
last = curr;
iterator.next();
}
if (last.containsKey(entity)) {
entities.add(builder.toString());
}
return entities;
}
示例2: 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;
}
示例3: 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;
}
示例4: equals
import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if(!(obj instanceof Text)) {
return false;
}
Text text = (Text) obj;
if (this.length() != text.length()) {
return false;
}
AttributedCharacterIterator it1 = this.getIterator();
AttributedCharacterIterator it2 = text.getIterator();
while (true) {
if (it1.getIndex() == it1.getEndIndex()) {
break;
}
if (it1.next() != it2.next()) {
return false;
}
Map map1 = it1.getAttributes();
Map map2 = it2.getAttributes();
if (!map1.equals(map2)) {
return false;
}
}
return true;
}
示例5: format
import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
@Override
String format(
AttributedCharacterIterator iterator,
String preExponent) {
int copyFromOffset = 0;
StringBuilder result = new StringBuilder();
for (
iterator.first();
iterator.current() != CharacterIterator.DONE;
) {
Map<Attribute, Object> attributeSet = iterator.getAttributes();
if (attributeSet.containsKey(NumberFormat.Field.EXPONENT_SYMBOL)) {
append(
iterator,
copyFromOffset,
iterator.getRunStart(NumberFormat.Field.EXPONENT_SYMBOL),
result);
copyFromOffset = iterator.getRunLimit(NumberFormat.Field.EXPONENT_SYMBOL);
iterator.setIndex(copyFromOffset);
result.append(preExponent);
result.append(beginMarkup);
} else if (attributeSet.containsKey(NumberFormat.Field.EXPONENT)) {
int limit = iterator.getRunLimit(NumberFormat.Field.EXPONENT);
append(
iterator,
copyFromOffset,
limit,
result);
copyFromOffset = limit;
iterator.setIndex(copyFromOffset);
result.append(endMarkup);
} else {
iterator.next();
}
}
append(iterator, copyFromOffset, iterator.getEndIndex(), result);
return result.toString();
}
示例6: TextLayout
import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
/**
* Constructs a <code>TextLayout</code> 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</code> 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);
}
示例7: 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);
}
示例8: dumpIterator
import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
private static final void dumpIterator(AttributedCharacterIterator iterator) {
Set attributeKeys = iterator.getAllAttributeKeys();
System.out.print("All attributes: ");
Iterator keyIterator = attributeKeys.iterator();
while (keyIterator.hasNext()) {
Attribute key = (Attribute) keyIterator.next();
System.out.print(key);
}
for(char c = iterator.first(); c != CharacterIterator.DONE; c = iterator.next()) {
if (iterator.getIndex() == iterator.getBeginIndex() ||
iterator.getIndex() == iterator.getRunStart()) {
System.out.println();
Map attributes = iterator.getAttributes();
Set entries = attributes.entrySet();
Iterator attributeIterator = entries.iterator();
while (attributeIterator.hasNext()) {
Map.Entry entry = (Map.Entry) attributeIterator.next();
System.out.print("<" + entry.getKey() + ": "
+ entry.getValue() + ">");
}
}
System.out.print(" ");
System.out.print(c);
}
System.out.println();
System.out.println("done");
System.out.println();
}
示例9: formatAndAppend
import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
public void formatAndAppend(Format formatter, Object arg) {
if (attributes == null) {
append(formatter.format(arg));
} else {
AttributedCharacterIterator formattedArg = formatter.formatToCharacterIterator(arg);
int prevLength = length;
append(formattedArg);
// Copy all of the attributes from formattedArg to our attributes list.
formattedArg.first();
int start = formattedArg.getIndex(); // Should be 0 but might not be.
int limit = formattedArg.getEndIndex(); // == start + length - prevLength
int offset = prevLength - start; // Adjust attribute indexes for the result string.
while (start < limit) {
Map<Attribute, Object> map = formattedArg.getAttributes();
int runLimit = formattedArg.getRunLimit();
if (map.size() != 0) {
for (Map.Entry<Attribute, Object> entry : map.entrySet()) {
attributes.add(
new AttributeAndPosition(
entry.getKey(), entry.getValue(),
offset + start, offset + runLimit));
}
}
start = runLimit;
formattedArg.setIndex(start);
}
}
}
示例10: StyledParagraph
import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
/**
* Create a new StyledParagraph over the given styled text.
* @param aci an iterator over the text
* @param chars the characters extracted from aci
*/
public StyledParagraph(AttributedCharacterIterator aci,
char[] chars) {
int start = aci.getBeginIndex();
int end = aci.getEndIndex();
length = end - start;
int index = start;
aci.first();
do {
final int nextRunStart = aci.getRunLimit();
final int localIndex = index-start;
Map<? extends Attribute, ?> attributes = aci.getAttributes();
attributes = addInputMethodAttrs(attributes);
Decoration d = Decoration.getDecoration(attributes);
addDecoration(d, localIndex);
Object f = getGraphicOrFont(attributes);
if (f == null) {
addFonts(chars, attributes, localIndex, nextRunStart-start);
}
else {
addFont(f, localIndex);
}
aci.setIndex(nextRunStart);
index = nextRunStart;
} while (index < end);
// Add extra entries to starts arrays with the length
// of the paragraph. 'this' is used as a dummy value
// in the Vector.
if (decorations != null) {
decorationStarts = addToVector(this, length, decorations, decorationStarts);
}
if (fonts != null) {
fontStarts = addToVector(this, length, fonts, fontStarts);
}
}