本文整理汇总了Java中java.text.AttributedCharacterIterator.Attribute类的典型用法代码示例。如果您正苦于以下问题:Java Attribute类的具体用法?Java Attribute怎么用?Java Attribute使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Attribute类属于java.text.AttributedCharacterIterator包,在下文中一共展示了Attribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import java.text.AttributedCharacterIterator.Attribute; //导入依赖的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);
}
示例2: insertText
import java.text.AttributedCharacterIterator.Attribute; //导入依赖的package包/类
/**
* Tell the component to commit all of the characters in the string to the current
* text view. This effectively wipes out any text in progress.
*/
private synchronized void insertText(String aString) {
AttributedString attribString = new AttributedString(aString);
// Set locale information on the new string.
attribString.addAttribute(Attribute.LANGUAGE, getLocale(), 0, aString.length());
TextHitInfo theCaret = TextHitInfo.afterOffset(aString.length() - 1);
InputMethodEvent event = new InputMethodEvent(fAwtFocussedComponent,
InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
attribString.getIterator(),
aString.length(),
theCaret,
theCaret);
LWCToolkit.postEvent(LWCToolkit.targetToAppContext(fAwtFocussedComponent), event);
fCurrentText = null;
fCurrentTextAsString = null;
fCurrentTextLength = 0;
}
示例3: insertText
import java.text.AttributedCharacterIterator.Attribute; //导入依赖的package包/类
/**
* Tell the component to commit all of the characters in the string to the current
* text view. This effectively wipes out any text in progress.
*/
synchronized private void insertText(String aString) {
AttributedString attribString = new AttributedString(aString);
// Set locale information on the new string.
attribString.addAttribute(Attribute.LANGUAGE, getLocale(), 0, aString.length());
TextHitInfo theCaret = TextHitInfo.afterOffset(aString.length() - 1);
InputMethodEvent event = new InputMethodEvent(fAwtFocussedComponent,
InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
attribString.getIterator(),
aString.length(),
theCaret,
theCaret);
LWCToolkit.postEvent(LWCToolkit.targetToAppContext(fAwtFocussedComponent), event);
fCurrentText = null;
fCurrentTextAsString = null;
fCurrentTextLength = 0;
}
示例4: fromSerializableHashtable
import java.text.AttributedCharacterIterator.Attribute; //导入依赖的package包/类
public static AttributeValues
fromSerializableHashtable(Hashtable<Object, Object> ht)
{
AttributeValues result = new AttributeValues();
if (ht != null && !ht.isEmpty()) {
for (Map.Entry<Object, Object> e: ht.entrySet()) {
Object key = e.getKey();
Object val = e.getValue();
if (key.equals(DEFINED_KEY)) {
result.defineAll(((Integer)val).intValue());
} else {
try {
EAttribute ea =
EAttribute.forAttribute((Attribute)key);
if (ea != null) {
result.set(ea, val);
}
}
catch (ClassCastException ex) {
}
}
}
}
return result;
}
示例5: beginEntity
import java.text.AttributedCharacterIterator.Attribute; //导入依赖的package包/类
private void beginEntity(Entry<Attribute, Object> entry, Writer writer) throws IOException {
if (entry == null) {
return;
}
Attribute entity = entry.getKey();
if (entity == TextEntity.BOLD) {
writer.write("<b>");
} else if (entity == TextEntity.ITALIC) {
writer.write("<i>");
} else if (entity == TextEntity.CODE) {
writer.write("<code>");
} else if (entity == TextEntity.CODE_BLOCK) {
writer.write("<pre>");
} else if (entity == TextEntity.LINK) {
writer.write("<a href=\"" + escape(entry.getValue().toString()) + "\">");
} else if (entity == TextEntity.TEXT_MENTION) {
User user = (User) entry.getValue();
writer.write("<a href=\"" + escape(TextEntity.TEXT_MENTION_LINK) + user.getId() + "\">");
}
}
示例6: checkIteratorAttribute
import java.text.AttributedCharacterIterator.Attribute; //导入依赖的package包/类
private static final void checkIteratorAttribute(AttributedCharacterIterator iterator, int index, Attribute key, Object expectedValue) throws Exception {
iterator.setIndex(index);
Object value = iterator.getAttribute(key);
if (!((expectedValue == null && value == null) || (expectedValue != null && expectedValue.equals(value)))) {
throwException(iterator, "iterator returns wrong attribute value - " + value + " instead of " + expectedValue);
}
value = iterator.getAttributes().get(key);
if (!((expectedValue == null && value == null) || (expectedValue != null && expectedValue.equals(value)))) {
throwException(iterator, "iterator's map returns wrong attribute value - " + value + " instead of " + expectedValue);
}
}
示例7: beginEntity
import java.text.AttributedCharacterIterator.Attribute; //导入依赖的package包/类
private void beginEntity(Entry<Attribute, Object> entry, Writer writer) throws IOException {
if (entry == null) {
return;
}
Attribute entity = entry.getKey();
if (entity == TextEntity.BOLD) {
writer.write('*');
} else if (entity == TextEntity.ITALIC) {
writer.write('_');
} else if (entity == TextEntity.CODE) {
writer.write('`');
} else if (entity == TextEntity.CODE_BLOCK) {
writer.write("```");
} else if (entity == TextEntity.LINK || entity == TextEntity.TEXT_MENTION) {
writer.write("[");
}
}
示例8: getRunStart
import java.text.AttributedCharacterIterator.Attribute; //导入依赖的package包/类
public int getRunStart(Attribute attribute) {
if (currentRunStart == beginIndex || currentRunIndex == -1) {
return currentRunStart;
} else {
Object value = getAttribute(attribute);
int runStart = currentRunStart;
int runIndex = currentRunIndex;
while (runStart > beginIndex &&
valuesMatch(value, AttributedString.this.getAttribute(attribute, runIndex - 1))) {
runIndex--;
runStart = runStarts[runIndex];
}
if (runStart < beginIndex) {
runStart = beginIndex;
}
return runStart;
}
}
示例9: select
import java.text.AttributedCharacterIterator.Attribute; //导入依赖的package包/类
/**
* Selects the passed in field, returning true if it is found,
* false otherwise.
*/
private boolean select(final JFormattedTextField ftf, final AttributedCharacterIterator iterator, final DateFormat.Field field) {
final int max = ftf.getDocument().getLength();
iterator.first();
do {
final Map<Attribute,Object> attrs = iterator.getAttributes();
if (attrs == null || !attrs.containsKey(field)) continue;
final int start = iterator.getRunStart(field);
final 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;
}
示例10: TextLayout
import java.text.AttributedCharacterIterator.Attribute; //导入依赖的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);
}
示例11: paragraphInit
import java.text.AttributedCharacterIterator.Attribute; //导入依赖的package包/类
/**
* Initialize the paragraph-specific data.
*/
private void paragraphInit(byte aBaseline, CoreMetrics lm,
Map<? extends Attribute, ?> paragraphAttrs,
char[] text) {
baseline = aBaseline;
// normalize to current baseline
baselineOffsets = TextLine.getNormalizedOffsets(lm.baselineOffsets, baseline);
justifyRatio = AttributeValues.getJustification(paragraphAttrs);
NumericShaper shaper = AttributeValues.getNumericShaping(paragraphAttrs);
if (shaper != null) {
shaper.shape(text, 0, text.length);
}
}
示例12: TextLayout
import java.text.AttributedCharacterIterator.Attribute; //导入依赖的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);
}
示例13: fastInit
import java.text.AttributedCharacterIterator.Attribute; //导入依赖的package包/类
private void fastInit(char[] chars, Font font,
Map<? extends Attribute, ?> attrs,
FontRenderContext frc) {
// Object vf = attrs.get(TextAttribute.ORIENTATION);
// isVerticalLine = TextAttribute.ORIENTATION_VERTICAL.equals(vf);
isVerticalLine = false;
LineMetrics lm = font.getLineMetrics(chars, 0, chars.length, frc);
CoreMetrics cm = CoreMetrics.get(lm);
byte glyphBaseline = (byte) cm.baselineIndex;
if (attrs == null) {
baseline = glyphBaseline;
baselineOffsets = cm.baselineOffsets;
justifyRatio = 1.0f;
} else {
paragraphInit(glyphBaseline, cm, attrs, chars);
}
characterCount = chars.length;
textLine = TextLine.fastCreateTextLine(frc, chars, font, cm, attrs);
}
示例14: getGraphicOrFont
import java.text.AttributedCharacterIterator.Attribute; //导入依赖的package包/类
/**
* Extract a GraphicAttribute or Font from the given attributes.
* If attributes does not contain a GraphicAttribute, Font, or
* Font family entry this method returns null.
*/
private static Object getGraphicOrFont(
Map<? extends Attribute, ?> attributes) {
Object value = attributes.get(TextAttribute.CHAR_REPLACEMENT);
if (value != null) {
return value;
}
value = attributes.get(TextAttribute.FONT);
if (value != null) {
return value;
}
if (attributes.get(TextAttribute.FAMILY) != null) {
return Font.getFont(attributes);
}
else {
return null;
}
}
示例15: checkIteratorSubranges
import java.text.AttributedCharacterIterator.Attribute; //导入依赖的package包/类
private static final void checkIteratorSubranges(AttributedCharacterIterator iterator, Attribute key, int[] expectedLimits) throws Exception {
int previous = 0;
char c = iterator.first();
for (int i = 0; i < expectedLimits.length; i++) {
if (iterator.getRunStart(key) != previous || iterator.getRunLimit(key) != expectedLimits[i]) {
throwException(iterator, "run boundaries are not as expected: " + iterator.getRunStart(key) + ", " + iterator.getRunLimit(key) + " for key " + key);
}
previous = expectedLimits[i];
c = iterator.setIndex(previous);
}
if (c != CharacterIterator.DONE) {
throwException(iterator, "iterator's run sequence doesn't end with DONE");
}
}