本文整理汇总了Java中java.text.AttributedCharacterIterator.getBeginIndex方法的典型用法代码示例。如果您正苦于以下问题:Java AttributedCharacterIterator.getBeginIndex方法的具体用法?Java AttributedCharacterIterator.getBeginIndex怎么用?Java AttributedCharacterIterator.getBeginIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.AttributedCharacterIterator
的用法示例。
在下文中一共展示了AttributedCharacterIterator.getBeginIndex方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
}
示例2: drawString
import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
public void drawString(AttributedCharacterIterator iterator,
int x, int y) {
if (iterator == null) {
throw new NullPointerException("AttributedCharacterIterator is null");
}
if (iterator.getBeginIndex() == iterator.getEndIndex()) {
return; /* nothing to draw */
}
TextLayout tl = new TextLayout(iterator, getFontRenderContext());
tl.draw(this, (float) x, (float) y);
}
示例3: deleteChar
import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
/**
* Return a StyledParagraph reflecting the insertion of a single character
* into the text. This method will attempt to reuse the given paragraph,
* but may create a new paragraph.
* @param aci an iterator over the text. The text should be the same as the
* text used to create (or most recently update) oldParagraph, with
* the exception of deleting a single character at deletePos.
* @param chars the characters in aci
* @param deletePos the index where a character was removed
* @param oldParagraph a StyledParagraph for the text in aci before the
* insertion
*/
public static StyledParagraph deleteChar(AttributedCharacterIterator aci,
char[] chars,
int deletePos,
StyledParagraph oldParagraph) {
// We will reuse oldParagraph unless there was a length-1 run
// at deletePos. We could do more work and check the individual
// Font and Decoration runs, but we don't right now...
deletePos -= aci.getBeginIndex();
if (oldParagraph.decorations == null && oldParagraph.fonts == null) {
oldParagraph.length -= 1;
return oldParagraph;
}
if (oldParagraph.getRunLimit(deletePos) == deletePos+1) {
if (deletePos == 0 || oldParagraph.getRunLimit(deletePos-1) == deletePos) {
return new StyledParagraph(aci, chars);
}
}
oldParagraph.length -= 1;
if (oldParagraph.decorations != null) {
deleteFrom(deletePos,
oldParagraph.decorationStarts,
oldParagraph.decorations.size());
}
if (oldParagraph.fonts != null) {
deleteFrom(deletePos,
oldParagraph.fontStarts,
oldParagraph.fonts.size());
}
return oldParagraph;
}
示例4: drawString
import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
public void drawString(AttributedCharacterIterator iterator,
float x, float y) {
if (iterator == null) {
throw new NullPointerException("AttributedCharacterIterator is null");
}
if (iterator.getBeginIndex() == iterator.getEndIndex()) {
return; /* nothing to draw */
}
TextLayout tl = new TextLayout(iterator, getFontRenderContext());
tl.draw(this, x, y);
}
示例5: 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);
}
示例6: 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);
}
}
示例7: LineBreakMeasurer
import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
/**
* Constructs a <code>LineBreakMeasurer</code> for the specified text.
*
* @param text the text for which this <code>LineBreakMeasurer</code>
* produces <code>TextLayout</code> objects; the text must contain
* at least one character; if the text available through
* <code>iter</code> changes, further calls to this
* <code>LineBreakMeasurer</code> instance are undefined (except,
* in some cases, when <code>insertChar</code> or
* <code>deleteChar</code> are invoked afterward - see below)
* @param breakIter the {@link BreakIterator} which defines line
* breaks
* @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>LineBreakMeasurer</code> and user space
* @throws IllegalArgumentException if the text has less than one character
* @see LineBreakMeasurer#insertChar
* @see LineBreakMeasurer#deleteChar
*/
public LineBreakMeasurer(AttributedCharacterIterator text,
BreakIterator breakIter,
FontRenderContext frc) {
if (text.getEndIndex() - text.getBeginIndex() < 1) {
throw new IllegalArgumentException("Text must contain at least one character.");
}
this.breakIter = breakIter;
this.measurer = new TextMeasurer(text, frc);
this.limit = text.getEndIndex();
this.pos = this.start = text.getBeginIndex();
charIter = new CharArrayIterator(measurer.getChars(), this.start);
this.breakIter.setText(charIter);
}
示例8: LineBreakMeasurer
import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
/**
* Constructs a {@code LineBreakMeasurer} for the specified text.
*
* @param text the text for which this {@code LineBreakMeasurer}
* produces {@code TextLayout} objects; the text must contain
* at least one character; if the text available through
* {@code iter} changes, further calls to this
* {@code LineBreakMeasurer} instance are undefined (except,
* in some cases, when {@code insertChar} or
* {@code deleteChar} are invoked afterward - see below)
* @param breakIter the {@link BreakIterator} which defines line
* breaks
* @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 LineBreakMeasurer} and user space
* @throws IllegalArgumentException if the text has less than one character
* @see LineBreakMeasurer#insertChar
* @see LineBreakMeasurer#deleteChar
*/
public LineBreakMeasurer(AttributedCharacterIterator text,
BreakIterator breakIter,
FontRenderContext frc) {
if (text.getEndIndex() - text.getBeginIndex() < 1) {
throw new IllegalArgumentException("Text must contain at least one character.");
}
this.breakIter = breakIter;
this.measurer = new TextMeasurer(text, frc);
this.limit = text.getEndIndex();
this.pos = this.start = text.getBeginIndex();
charIter = new CharArrayIterator(measurer.getChars(), this.start);
this.breakIter.setText(charIter);
}
示例9: dispatchCommittedText
import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
/**
* Dispatches committed text to a client component.
* Called by composition window.
*
* @param client The component that the text should get dispatched to.
* @param text The iterator providing access to the committed
* (and possible composed) text.
* @param committedCharacterCount The number of committed characters in the text.
*/
synchronized void dispatchCommittedText(Component client,
AttributedCharacterIterator text,
int committedCharacterCount) {
// note that the client is not always the current client component -
// some host input method adapters may dispatch input method events
// through the Java event queue, and we may have switched clients while
// the event was in the queue.
if (committedCharacterCount == 0
|| text.getEndIndex() <= text.getBeginIndex()) {
return;
}
long time = System.currentTimeMillis();
dispatchingCommittedText = true;
try {
InputMethodRequests req = client.getInputMethodRequests();
if (req != null) {
// active client -> send text as InputMethodEvent
int beginIndex = text.getBeginIndex();
AttributedCharacterIterator toBeCommitted =
(new AttributedString(text, beginIndex, beginIndex + committedCharacterCount)).getIterator();
InputMethodEvent inputEvent = new InputMethodEvent(
client,
InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
toBeCommitted,
committedCharacterCount,
null, null);
client.dispatchEvent(inputEvent);
} else {
// passive client -> send text as KeyEvents
char keyChar = text.first();
while (committedCharacterCount-- > 0 && keyChar != CharacterIterator.DONE) {
KeyEvent keyEvent = new KeyEvent(client, KeyEvent.KEY_TYPED,
time, 0, KeyEvent.VK_UNDEFINED, keyChar);
client.dispatchEvent(keyEvent);
keyChar = text.next();
}
}
} finally {
dispatchingCommittedText = false;
}
}
示例10: InputMethodEvent
import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
/**
* Constructs an <code>InputMethodEvent</code> with the specified
* source component, type, time, text, caret, and visiblePosition.
* <p>
* The offsets of caret and visiblePosition are relative to the current
* composed text; that is, the composed text within <code>text</code>
* if this is an <code>INPUT_METHOD_TEXT_CHANGED</code> event,
* the composed text within the <code>text</code> of the
* preceding <code>INPUT_METHOD_TEXT_CHANGED</code> event otherwise.
* <p>Note that passing in an invalid <code>id</code> results in
* unspecified behavior. This method throws an
* <code>IllegalArgumentException</code> if <code>source</code>
* is <code>null</code>.
*
* @param source the object where the event originated
* @param id the event type
* @param when a long integer that specifies the time the event occurred
* @param text the combined committed and composed text,
* committed text first; must be <code>null</code>
* when the event type is <code>CARET_POSITION_CHANGED</code>;
* may be <code>null</code> for
* <code>INPUT_METHOD_TEXT_CHANGED</code> if there's no
* committed or composed text
* @param committedCharacterCount the number of committed
* characters in the text
* @param caret the caret (a.k.a. insertion point);
* <code>null</code> if there's no caret within current
* composed text
* @param visiblePosition the position that's most important
* to be visible; <code>null</code> if there's no
* recommendation for a visible position within current
* composed text
* @throws IllegalArgumentException if <code>id</code> is not
* in the range
* <code>INPUT_METHOD_FIRST</code>..<code>INPUT_METHOD_LAST</code>;
* or if id is <code>CARET_POSITION_CHANGED</code> and
* <code>text</code> is not <code>null</code>;
* or if <code>committedCharacterCount</code> is not in the range
* <code>0</code>..<code>(text.getEndIndex() - text.getBeginIndex())</code>
* @throws IllegalArgumentException if <code>source</code> is null
*
* @since 1.4
*/
public InputMethodEvent(Component source, int id, long when,
AttributedCharacterIterator text, int committedCharacterCount,
TextHitInfo caret, TextHitInfo visiblePosition) {
super(source, id);
if (id < INPUT_METHOD_FIRST || id > INPUT_METHOD_LAST) {
throw new IllegalArgumentException("id outside of valid range");
}
if (id == CARET_POSITION_CHANGED && text != null) {
throw new IllegalArgumentException("text must be null for CARET_POSITION_CHANGED");
}
this.when = when;
this.text = text;
int textLength = 0;
if (text != null) {
textLength = text.getEndIndex() - text.getBeginIndex();
}
if (committedCharacterCount < 0 || committedCharacterCount > textLength) {
throw new IllegalArgumentException("committedCharacterCount outside of valid range");
}
this.committedCharacterCount = committedCharacterCount;
this.caret = caret;
this.visiblePosition = visiblePosition;
}
示例11: insertChar
import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
/**
* Updates this {@code LineBreakMeasurer} after a single
* character is inserted into the text, and sets the current
* position to the beginning of the paragraph.
*
* @param newParagraph the text after the insertion
* @param insertPos the position in the text at which the character
* is inserted
* @throws IndexOutOfBoundsException if {@code insertPos} is less
* than the start of {@code newParagraph} or greater than
* or equal to the end of {@code newParagraph}
* @throws NullPointerException if {@code newParagraph} is
* {@code null}
* @see #deleteChar
*/
public void insertChar(AttributedCharacterIterator newParagraph,
int insertPos) {
measurer.insertChar(newParagraph, insertPos);
limit = newParagraph.getEndIndex();
pos = start = newParagraph.getBeginIndex();
charIter.reset(measurer.getChars(), newParagraph.getBeginIndex());
breakIter.setText(charIter);
}
示例12: InputMethodEvent
import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
/**
* Constructs an {@code InputMethodEvent} with the specified
* source component, type, time, text, caret, and visiblePosition.
* <p>
* The offsets of caret and visiblePosition are relative to the current
* composed text; that is, the composed text within {@code text}
* if this is an {@code INPUT_METHOD_TEXT_CHANGED} event,
* the composed text within the {@code text} of the
* preceding {@code INPUT_METHOD_TEXT_CHANGED} event otherwise.
* <p>Note that passing in an invalid {@code id} results in
* unspecified behavior. This method throws an
* {@code IllegalArgumentException} if {@code source}
* is {@code null}.
*
* @param source the object where the event originated
* @param id the event type
* @param when a long integer that specifies the time the event occurred
* @param text the combined committed and composed text,
* committed text first; must be {@code null}
* when the event type is {@code CARET_POSITION_CHANGED};
* may be {@code null} for
* {@code INPUT_METHOD_TEXT_CHANGED} if there's no
* committed or composed text
* @param committedCharacterCount the number of committed
* characters in the text
* @param caret the caret (a.k.a. insertion point);
* {@code null} if there's no caret within current
* composed text
* @param visiblePosition the position that's most important
* to be visible; {@code null} if there's no
* recommendation for a visible position within current
* composed text
* @throws IllegalArgumentException if {@code id} is not
* in the range
* {@code INPUT_METHOD_FIRST}..{@code INPUT_METHOD_LAST};
* or if id is {@code CARET_POSITION_CHANGED} and
* {@code text} is not {@code null};
* or if {@code committedCharacterCount} is not in the range
* {@code 0}..{@code (text.getEndIndex() - text.getBeginIndex())}
* @throws IllegalArgumentException if {@code source} is null
*
* @since 1.4
*/
public InputMethodEvent(Component source, int id, long when,
AttributedCharacterIterator text, int committedCharacterCount,
TextHitInfo caret, TextHitInfo visiblePosition) {
super(source, id);
if (id < INPUT_METHOD_FIRST || id > INPUT_METHOD_LAST) {
throw new IllegalArgumentException("id outside of valid range");
}
if (id == CARET_POSITION_CHANGED && text != null) {
throw new IllegalArgumentException("text must be null for CARET_POSITION_CHANGED");
}
this.when = when;
this.text = text;
int textLength = 0;
if (text != null) {
textLength = text.getEndIndex() - text.getBeginIndex();
}
if (committedCharacterCount < 0 || committedCharacterCount > textLength) {
throw new IllegalArgumentException("committedCharacterCount outside of valid range");
}
this.committedCharacterCount = committedCharacterCount;
this.caret = caret;
this.visiblePosition = visiblePosition;
}
示例13: deleteChar
import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
/**
* Updates this <code>LineBreakMeasurer</code> after a single
* character is deleted from the text, and sets the current
* position to the beginning of the paragraph.
* @param newParagraph the text after the deletion
* @param deletePos the position in the text at which the character
* is deleted
* @throws IndexOutOfBoundsException if <code>deletePos</code> is
* less than the start of <code>newParagraph</code> or greater
* than the end of <code>newParagraph</code>
* @throws NullPointerException if <code>newParagraph</code> is
* <code>null</code>
* @see #insertChar
*/
public void deleteChar(AttributedCharacterIterator newParagraph,
int deletePos) {
measurer.deleteChar(newParagraph, deletePos);
limit = newParagraph.getEndIndex();
pos = start = newParagraph.getBeginIndex();
charIter.reset(measurer.getChars(), start);
breakIter.setText(charIter);
}