本文整理汇总了Java中javax.swing.text.Position.Bias.Forward方法的典型用法代码示例。如果您正苦于以下问题:Java Bias.Forward方法的具体用法?Java Bias.Forward怎么用?Java Bias.Forward使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.Position.Bias
的用法示例。
在下文中一共展示了Bias.Forward方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNextMatch
import javax.swing.text.Position.Bias; //导入方法依赖的package包/类
@Override
public int getNextMatch(String prefix, int startIndex, Bias bias) {
ListModel model = getModel();
if (!(model instanceof TableModel)) {
return super.getNextMatch(prefix, startIndex, bias);
}
TableModel tablesModel = (TableModel)model;
int max = tablesModel.getSize();
int increment = (bias == Bias.Forward) ? 1 : -1;
int index = startIndex;
prefix = prefix.toUpperCase();
do {
Table table = tablesModel.getElementAt(index);
String tableName = table.getName().toUpperCase();
if (tableName.startsWith(prefix)) {
return index;
}
index = (index + increment + max) % max;
} while (index != startIndex);
return -1;
}
示例2: 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);
}
}
示例3: 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;
}
示例4: getNextVisualPositionFromChecked
import javax.swing.text.Position.Bias; //导入方法依赖的package包/类
@Override
public int getNextVisualPositionFromChecked(int offset, Bias bias, Shape alloc, int direction, Bias[] biasRet) {
int retOffset;
biasRet[0] = Bias.Forward; // BaseCaret ignores bias
int viewStartOffset = getStartOffset();
switch (direction) {
case View.EAST:
if (offset == -1) {
retOffset = viewStartOffset;
} else {
retOffset = -1;
}
break;
case View.WEST:
if (offset == -1) {
retOffset = viewStartOffset;
} else if (offset == viewStartOffset) { // Regular offset
retOffset = -1;
} else {
retOffset = viewStartOffset;
}
break;
case View.NORTH:
case View.SOUTH:
retOffset = -1;
break;
default:
throw new IllegalArgumentException("Bad direction: " + direction);
}
return retOffset;
}