本文整理汇总了Java中java.text.AttributedCharacterIterator.getRunLimit方法的典型用法代码示例。如果您正苦于以下问题:Java AttributedCharacterIterator.getRunLimit方法的具体用法?Java AttributedCharacterIterator.getRunLimit怎么用?Java AttributedCharacterIterator.getRunLimit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.AttributedCharacterIterator
的用法示例。
在下文中一共展示了AttributedCharacterIterator.getRunLimit方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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();
}
示例3: 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);
}
示例4: 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);
}
示例5: checkIteratorSubranges
import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
private static final void checkIteratorSubranges(AttributedCharacterIterator iterator, int[] expectedLimits) throws Exception {
int previous = 0;
char c = iterator.first();
for (int i = 0; i < expectedLimits.length; i++) {
if (iterator.getRunStart() != previous || iterator.getRunLimit() != expectedLimits[i]) {
throwException(iterator, "run boundaries are not as expected: " + iterator.getRunStart() + ", " + iterator.getRunLimit());
}
previous = expectedLimits[i];
c = iterator.setIndex(previous);
}
if (c != CharacterIterator.DONE) {
throwException(iterator, "iterator's run sequence doesn't end with DONE");
}
}
示例6: 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);
}
}
}
示例7: iterateRun
import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
private boolean iterateRun(AttributedCharacterIterator iterator, StringBuilder sb) {
sb.setLength(0);
int charCount = iterator.getRunLimit() - iterator.getRunStart();
while (charCount-- >= 0) {
char c = iterator.current();
iterator.next();
if (c == AttributedCharacterIterator.DONE) {
return false;
} else {
sb.append(c);
}
}
return true;
}
示例8: 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);
}
}
示例9: main
import java.text.AttributedCharacterIterator; //导入方法依赖的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)+".)");
}
}