本文整理汇总了Java中javax.swing.text.Position.Bias方法的典型用法代码示例。如果您正苦于以下问题:Java Position.Bias方法的具体用法?Java Position.Bias怎么用?Java Position.Bias使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.Position
的用法示例。
在下文中一共展示了Position.Bias方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addSaveSet
import javax.swing.text.Position; //导入方法依赖的package包/类
/** Add the save-set to the registry and perform the checking
* whether the offsets are OK.
*/
synchronized void addSaveSet(int baseOffset, int writtenLen,
int[] offsets, Position.Bias[] biases) {
// Check whether the offsets are OK
for (int i = 0; i < offsets.length; i++) {
if (offsets[i] < 0 || offsets[i] > writtenLen) {
throw new IllegalArgumentException(
"Invalid save-offset=" + offsets[i] + " at index=" + i // NOI18N
+ ". Written length is " + writtenLen); // NOI18N
}
}
SaveSet newSet = new SaveSet(baseOffset, offsets, biases);
if (firstSet != null) {
lastSet.next = newSet;
lastSet = newSet;
} else { // first set
firstSet = lastSet = newSet;
}
}
示例2: modelToViewChecked
import javax.swing.text.Position; //导入方法依赖的package包/类
@Override
public Shape modelToViewChecked(int offset, Shape alloc, Position.Bias bias) {
// TextLayout textLayout = getTextLayout();
// if (textLayout == null) {
// return alloc; // Leave given bounds
// }
// Rectangle2D.Double bounds = ViewUtils.shape2Bounds(alloc);
// return bounds;
return alloc;
}
示例3: restoreEditorCaret
import javax.swing.text.Position; //导入方法依赖的package包/类
protected void restoreEditorCaret(EditorCaret caret) throws BadLocationException {
Position dotPos = doc.createPosition(getOffset(dotOffsetAndBias));
List<Position.Bias> biases = isBackwardBias(dotOffsetAndBias)
? Arrays.asList(Position.Bias.Backward, Position.Bias.Backward)
: null;
caret.replaceCarets(Arrays.asList(dotPos, dotPos), biases); // TODO handle biases
}
示例4: documentInsertAtZeroOffset
import javax.swing.text.Position; //导入方法依赖的package包/类
void documentInsertAtZeroOffset(int insertEndOffset) {
// Nested insert inside active transaction for caret moving
// Since carets may already be moved - do the operations with CaretItems directly
Position insertEndPos = null;
for (CaretItem caretItem : editorCaret.getSortedCaretItems()) {
Position dotPos = caretItem.getDotPosition();
Position.Bias dotBias = caretItem.getDotBias();
boolean modifyDot = (dotPos == null || dotPos.getOffset() == 0);
Position markPos = caretItem.getMarkPosition();
Position.Bias markBias = caretItem.getMarkBias();
boolean modifyMark = (markPos == null || markPos.getOffset() == 0);
if (modifyDot || modifyMark) {
if (insertEndPos == null) {
try {
insertEndPos = doc.createPosition(insertEndOffset);
} catch (BadLocationException ex) {
// Should never happen
return;
}
}
if (modifyDot) {
dotPos = insertEndPos;
// current impl retains dotBias
}
if (modifyMark) {
markPos = insertEndPos;
// current impl retains markBias
}
setDotAndMark(caretItem, dotPos, dotBias, markPos, markBias);
}
// Do not break the loop when caret's pos is above zero offset
// since the carets may be already moved during the transaction
// - possibly to offset zero. But there could be optimization
// at least scan position of only the caret items that were modified and not others.
}
if (insertEndPos != null) {
updateAffectedOffsets(0, insertEndOffset); // TODO isn't this extra work that setDotAndMark() already did??
fullResort = true;
}
}
示例5: getNextMatch
import javax.swing.text.Position; //导入方法依赖的package包/类
/**
* Returns the next list element whose {@code toString} value
* starts with the given prefix.
*
* @param prefix the string to test for a match
* @param startIndex the index for starting the search
* @param bias the search direction, either
* Position.Bias.Forward or Position.Bias.Backward.
* @return the index of the next list element that
* starts with the prefix; otherwise {@code -1}
* @exception IllegalArgumentException if prefix is {@code null}
* or startIndex is out of bounds
* @since 1.4
*/
public int getNextMatch(String prefix, int startIndex, Position.Bias bias) {
ListModel<E> model = getModel();
int max = model.getSize();
if (prefix == null) {
throw new IllegalArgumentException();
}
if (startIndex < 0 || startIndex >= max) {
throw new IllegalArgumentException();
}
prefix = prefix.toUpperCase();
// start search from the next element after the selected element
int increment = (bias == Position.Bias.Forward) ? 1 : -1;
int index = startIndex;
do {
E element = model.getElementAt(index);
if (element != null) {
String string;
if (element instanceof String) {
string = ((String)element).toUpperCase();
}
else {
string = element.toString();
if (string != null) {
string = string.toUpperCase();
}
}
if (string != null && string.startsWith(prefix)) {
return index;
}
}
index = (index + increment + max) % max;
} while (index != startIndex);
return -1;
}
示例6: viewToModelChecked
import javax.swing.text.Position; //导入方法依赖的package包/类
@Override
public int viewToModelChecked(double x, double y, Shape alloc, Position.Bias[] biasReturn) {
int startOffset = getStartOffset();
return startOffset;
}
示例7: getViewIndex
import javax.swing.text.Position; //导入方法依赖的package包/类
public int getViewIndex(int pos, Position.Bias b) {
return 0;
}
示例8: getNextVisualPositionFrom
import javax.swing.text.Position; //导入方法依赖的package包/类
@Override
public int getNextVisualPositionFrom(JTextComponent t, int pos, Position.Bias b, int direction, Position.Bias[] biasRet) throws BadLocationException {
return 0;
}
示例9: modelToViewChecked
import javax.swing.text.Position; //导入方法依赖的package包/类
@Override
public Shape modelToViewChecked(int offset, Shape alloc, Position.Bias bias) {
Rectangle2D.Double mutableBounds = ViewUtils.shape2Bounds(alloc);
mutableBounds.width = getPreferredSpan(X_AXIS);
return mutableBounds;
}
示例10: moveDot
import javax.swing.text.Position; //导入方法依赖的package包/类
/**
* Moves the caret position (dot) to some other position, leaving behind the
* mark.
* <p>
* In addition to {@link #setDot(int)},
* the caller may identify the operation that originated the caret movement.
* This information is received by {@link NavigationFilter}s or {@link EditorCaretListener}s
* and may be used to react or modify the caret movements.
* </p><p>
* Use {@code null} or {@link MoveCaretsOrigin#DEFAULT} if the operation not known. Use
* {@link MoveCaretsOrigin#DIRECT_NAVIGATION} action type to identify simple navigational
* actions (pg up, pg down, left, right, ...).
* </p>
*
* @param offset new offset for the caret
* @param bias new bias for the caret. Use either {@link Position.Bias.Forward}
* or {@link Position.Bias.Backward} depending on whether the caret should bias
* towards the next character or previous one. Use forward bias for non-bidirectional text document.
* @param origin specifies the operation which caused the caret to move.
* @see #moveDot(int)
* @since 2.10
*/
public void moveDot(final int offset, Position.Bias bias, MoveCaretsOrigin origin) {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("EditorCaret.moveDot: offset=" + offset + ", bias=" + bias + ", origin=" + origin + "\n"); //NOI18N
}
runTransaction(CaretTransaction.RemoveType.NO_REMOVE, 0, null, new CaretMoveHandler() {
@Override
public void moveCarets(CaretMoveContext context) {
Document doc = context.getComponent().getDocument();
if (doc != null) {
try {
Position pos = doc.createPosition(offset);
context.moveDot(context.getOriginalLastCaret(), pos, Position.Bias.Forward);
} catch (BadLocationException ex) {
// Ignore the setDot() request
}
}
}
}, origin);
}
示例11: ExtTokenPosition
import javax.swing.text.Position; //导入方法依赖的package包/类
ExtTokenPosition(TokenItem token, int offset, Position.Bias bias) {
this.token = token;
this.offset = offset;
this.bias = bias;
}
示例12: viewToModelChecked
import javax.swing.text.Position; //导入方法依赖的package包/类
@Override
public int viewToModelChecked(double x, double y, Shape alloc, Position.Bias[] biasReturn) {
return start;
}
示例13: modelToView
import javax.swing.text.Position; //导入方法依赖的package包/类
@Override
public Rectangle modelToView(JTextComponent t, int pos, Position.Bias bias) throws BadLocationException {
return null;
}
示例14: getNextVisualPositionFromChecked
import javax.swing.text.Position; //导入方法依赖的package包/类
/**
* Provides a way to determine the next visually represented model
* location at which one might place a caret.
* Some views may not be visible,
* they might not be in the same order found in the model, or they just
* might not allow access to some of the locations in the model.
*
* @param offset the position to convert >= 0. -1 can be passed to request
* "first available position" at the view's start in the particular direction.
* For example -1 with SwingConstants.WEST means getStartOffset().
* @param bias bias for the offset.
* @param alloc non-null bounds allocated to this view.
* @param direction the direction from the current position that can
* be thought of as the arrow keys typically found on a keyboard.
* This will be one of the following values:
* <ul>
* <li>SwingConstants.WEST
* <li>SwingConstants.EAST
* <li>SwingConstants.NORTH
* <li>SwingConstants.SOUTH
* </ul>
* @return the location within the model that best represents the next
* location visual position
* @exception IllegalArgumentException if <code>direction</code>
* doesn't have one of the legal values above
*/
public int getNextVisualPositionFromChecked(int offset, Position.Bias bias, Shape alloc,
int direction, Position.Bias[] biasRet)
{
try {
return super.getNextVisualPositionFrom(offset, bias, alloc, direction, biasRet);
} catch (BadLocationException e) {
return getStartOffset(); // Should not happen
}
}
示例15: PositionRef
import javax.swing.text.Position; //导入方法依赖的package包/类
/** Creates new <code>PositionRef</code> using the given manager at the specified
* position offset.
* @param manager manager for the position
* @param offset - position in the document
* @param bias the bias for the position
*/
PositionRef(Manager manager, int offset, Position.Bias bias) {
this(manager, new Manager.OffsetKind(offset, manager), bias);
}