本文整理汇总了Java中java.text.Annotation类的典型用法代码示例。如果您正苦于以下问题:Java Annotation类的具体用法?Java Annotation怎么用?Java Annotation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Annotation类属于java.text包,在下文中一共展示了Annotation类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: entrySet
import java.text.Annotation; //导入依赖的package包/类
public Set<Entry<Attribute, Object>> entrySet() {
HashSet<Entry<Attribute, Object>> set = new HashSet<>();
synchronized (AttributedString.this) {
int size = runAttributes[runIndex].size();
for (int i = 0; i < size; i++) {
Attribute key = runAttributes[runIndex].get(i);
Object value = runAttributeValues[runIndex].get(i);
if (value instanceof Annotation) {
value = AttributedString.this.getAttributeCheckRange(key,
runIndex, beginIndex, endIndex);
if (value == null) {
continue;
}
}
Entry<Attribute, Object> entry = new AttributeEntry(key, value);
set.add(entry);
}
}
return set;
}
示例2: populateText
import java.text.Annotation; //导入依赖的package包/类
private void populateText(Paragraph p, AttributedString as, boolean insertBreakBefore, Direction blockDirection) {
if (as != null) {
List<Serializable> content = p.getContent();
if (insertBreakBefore)
content.add(ttmlFactory.createBr(ttmlFactory.createBreak()));
AttributedCharacterIterator aci = as.getIterator();
aci.first();
StringBuffer sb = new StringBuffer();
while (aci.current() != CharacterIterator.DONE) {
int i = aci.getRunStart();
int e = aci.getRunLimit();
Annotation annotation = (Annotation) aci.getAttribute(TextAttribute.ANNOTATION);
while (i < e) {
sb.append(aci.setIndex(i++));
}
String text = sb.toString();
if (annotation != null)
content.add(ttmlFactory.createSpan(createSpan(text, (Attribute) annotation.getValue(), blockDirection)));
else
content.add(text);
sb.setLength(0);
aci.setIndex(e);
}
}
}
示例3: main
import java.text.Annotation; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
String text = "Hello world";
AttributedString as = new AttributedString(text);
// add non-Annotation attributes
as.addAttribute(TextAttribute.WEIGHT,
TextAttribute.WEIGHT_LIGHT,
0,
3);
as.addAttribute(TextAttribute.WEIGHT,
TextAttribute.WEIGHT_BOLD,
3,
5);
as.addAttribute(TextAttribute.WEIGHT,
TextAttribute.WEIGHT_EXTRABOLD,
5,
text.length());
// add Annotation attributes
as.addAttribute(TextAttribute.WIDTH,
new Annotation(TextAttribute.WIDTH_EXTENDED),
0,
3);
as.addAttribute(TextAttribute.WIDTH,
new Annotation(TextAttribute.WIDTH_CONDENSED),
3,
4);
AttributedCharacterIterator aci = as.getIterator(null, 2, 4);
aci.first();
int runStart = aci.getRunStart();
if (runStart != 2) {
throw new Exception("1st run start is wrong. ("+runStart+" should be 2.)");
}
int runLimit = aci.getRunLimit();
if (runLimit != 3) {
throw new Exception("1st run limit is wrong. ("+runLimit+" should be 3.)");
}
Object value = aci.getAttribute(TextAttribute.WEIGHT);
if (value != TextAttribute.WEIGHT_LIGHT) {
throw new Exception("1st run attribute is wrong. ("
+value+" should be "+TextAttribute.WEIGHT_LIGHT+".)");
}
value = aci.getAttribute(TextAttribute.WIDTH);
if (value != null) {
throw new Exception("1st run annotation is wrong. ("
+value+" should be null.)");
}
aci.setIndex(runLimit);
runStart = aci.getRunStart();
if (runStart != 3) {
throw new Exception("2nd run start is wrong. ("+runStart+" should be 3.)");
}
runLimit = aci.getRunLimit();
if (runLimit != 4) {
throw new Exception("2nd run limit is wrong. ("+runLimit+" should be 4.)");
}
value = aci.getAttribute(TextAttribute.WEIGHT);
if (value != TextAttribute.WEIGHT_BOLD) {
throw new Exception("2nd run attribute is wrong. ("
+value+" should be "+TextAttribute.WEIGHT_BOLD+".)");
}
value = aci.getAttribute(TextAttribute.WIDTH);
if (!(value instanceof Annotation)
|| (((Annotation)value).getValue() != TextAttribute.WIDTH_CONDENSED)) {
throw new Exception("2nd run annotation is wrong. (" + value + " should be "
+ new Annotation(TextAttribute.WIDTH_CONDENSED)+".)");
}
}
示例4: unpackAttributes
import java.text.Annotation; //导入依赖的package包/类
/**
* Adds InputMethodHighlight to the attributes
* @param attrs - text attributes
* @return patched text attributes
*/
Map<? extends Attribute, ?> unpackAttributes(Map<? extends Attribute, ?> attrs) {
if (attrs.containsKey(TextAttribute.INPUT_METHOD_HIGHLIGHT)) {
Map<TextAttribute, ?> styles = null;
Object val = attrs.get(TextAttribute.INPUT_METHOD_HIGHLIGHT);
if (val instanceof Annotation) {
val = ((Annotation) val).getValue();
}
//
// if (val instanceof InputMethodHighlight) {
// InputMethodHighlight ihl = ((InputMethodHighlight) val);
// styles = ihl.getStyle();
//
// if (styles == null) {
// Toolkit tk = Toolkit.getDefaultToolkit();
// styles = tk.mapInputMethodHighlight(ihl);
// }
// }
if (styles != null) {
HashMap<Attribute, Object> newAttrs = new HashMap<Attribute, Object>();
newAttrs.putAll(attrs);
newAttrs.putAll(styles);
return newAttrs;
}
}
return attrs;
}
示例5: unpackAttributes
import java.text.Annotation; //导入依赖的package包/类
/**
* Adds InputMethodHighlight to the attributes
* @param attrs - text attributes
* @return patched text attributes
*/
Map<? extends Attribute, ?> unpackAttributes(Map<? extends Attribute, ?> attrs) {
if (attrs.containsKey(TextAttribute.INPUT_METHOD_HIGHLIGHT)) {
Map<TextAttribute, ?> styles = null;
Object val = attrs.get(TextAttribute.INPUT_METHOD_HIGHLIGHT);
if (val instanceof Annotation) {
val = ((Annotation) val).getValue();
}
// if (val instanceof InputMethodHighlight) {
// InputMethodHighlight ihl = ((InputMethodHighlight) val);
// styles = ihl.getStyle();
//
// if (styles == null) {
// Toolkit tk = Toolkit.getDefaultToolkit();
// styles = tk.mapInputMethodHighlight(ihl);
// }
// }
if (styles != null) {
HashMap<Attribute, Object> newAttrs = new HashMap<Attribute, Object>();
newAttrs.putAll(attrs);
newAttrs.putAll(styles);
return newAttrs;
}
}
return attrs;
}
示例6: unpackAttributes
import java.text.Annotation; //导入依赖的package包/类
/**
* Adds InputMethodHighlight to the attributes
* @param attrs - text attributes
* @return patched text attributes
*/
Map<? extends Attribute, ?> unpackAttributes(Map<? extends Attribute, ?> attrs) {
if (attrs.containsKey(TextAttribute.INPUT_METHOD_HIGHLIGHT)) {
Map<TextAttribute, ?> styles = null;
Object val = attrs.get(TextAttribute.INPUT_METHOD_HIGHLIGHT);
if (val instanceof Annotation) {
val = ((Annotation) val).getValue();
}
if (val instanceof InputMethodHighlight) {
InputMethodHighlight ihl = ((InputMethodHighlight) val);
styles = ihl.getStyle();
if (styles == null) {
Toolkit tk = Toolkit.getDefaultToolkit();
styles = tk.mapInputMethodHighlight(ihl);
}
}
if (styles != null) {
HashMap<Attribute, Object> newAttrs = new HashMap<Attribute, Object>();
newAttrs.putAll(attrs);
newAttrs.putAll(styles);
return newAttrs;
}
}
return attrs;
}
示例7: testToString
import java.text.Annotation; //导入依赖的package包/类
/**
* @tests java.text.Annotation.toString()
*/
public void testToString() {
Annotation ant = new Annotation("HelloWorld");
assertEquals("toString error.",
"java.text.Annotation[value=HelloWorld]",ant.toString());
assertNotNull(new Annotation(null).toString());
assertNotNull(new Annotation("value").toString());
}
示例8: setInputMethodHighlight
import java.text.Annotation; //导入依赖的package包/类
public void setInputMethodHighlight(Annotation f) {
this.imHighlight = f; update(EINPUT_METHOD_HIGHLIGHT); }
示例9: AnnotatedRange
import java.text.Annotation; //导入依赖的package包/类
public AnnotatedRange(Annotation annotation, int start, int end) {
this.annotation = annotation;
this.start = start;
this.end = end;
}
示例10: testAnnotation
import java.text.Annotation; //导入依赖的package包/类
/**
* @tests java.text.Annotation(Object)
*/
public void testAnnotation() {
assertNotNull(new Annotation(null));
assertNotNull(new Annotation("value"));
}