本文整理汇总了Java中javax.swing.text.Position.Bias.Backward方法的典型用法代码示例。如果您正苦于以下问题:Java Bias.Backward方法的具体用法?Java Bias.Backward怎么用?Java Bias.Backward使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.Position.Bias
的用法示例。
在下文中一共展示了Bias.Backward方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insert
import javax.swing.text.Position.Bias; //导入方法依赖的package包/类
void insert(BaseDocument doc, int offset) throws InvalidMarkException, BadLocationException {
BaseDocument ldoc = this.doc;
if (ldoc != null) {
throw new InvalidMarkException("Mark already inserted: mark=" + this // NOI18N
+ ", class=" + this.getClass()); // NOI18N
}
this.doc = doc;
ldoc = this.doc;
synchronized (ldoc) {
if (pos != null) {
throw new IllegalStateException("Mark already inserted: mark=" + this // NOI18N
+ ", class=" + this.getClass()); // NOI18N
}
if (offset < 0 || offset > ldoc.getLength() + 1) { // doc.getEndPosition() is valid
throw new BadLocationException("Invalid offset", offset); // NOI18N
}
// Deal with supplementary characters #164820
if (offset <= ldoc.getLength() && Character.isLowSurrogate(org.netbeans.lib.editor.util.swing.DocumentUtilities.getText(ldoc).charAt(offset))) {
if (bias == Bias.Forward && offset < ldoc.getLength()) {
offset++;
} else if (bias == Bias.Backward && offset > 0) {
offset--;
}
// If there is still a low surrogate after recalculating,
// treat it as an invalid document, just ignore and pass through.
// Since there should be a surrogate pair in Java and Unicode to
// represent a supplementary character.
}
pos = doc.createPosition(offset, bias);
}
}
示例2: getNextVisualPositionFromChecked
import javax.swing.text.Position.Bias; //导入方法依赖的package包/类
@Override
public int getNextVisualPositionFromChecked(int offset, Bias bias, Shape alloc, int direction, Bias[] biasRet) {
int startOffset = getStartOffset();
int endOffset = startOffset + getLength();
int retOffset = -1;
switch (direction) {
case EAST:
biasRet[0] = Bias.Forward;
if (offset == -1) {
retOffset = getStartOffset();
} else {
retOffset = offset + 1;
if (retOffset >= endOffset) {
retOffset = endOffset;
biasRet[0] = Bias.Backward;
}
}
break;
case WEST:
biasRet[0] = Bias.Forward;
if (offset == -1) {
retOffset = endOffset - 1;
} else {
retOffset = offset - 1;
if (retOffset < startOffset) {
retOffset = -1;
}
}
break;
case View.NORTH:
case View.SOUTH:
break; // Return -1
default:
throw new IllegalArgumentException("Bad direction: " + direction);
}
return retOffset;
}