下面列出了javax.swing.text.Position#Bias ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
static int viewToModel(JTextComponent tc, double x, double y, Position.Bias[] biasReturn) {
int offs = -1;
Document doc = tc.getDocument();
if (doc instanceof AbstractDocument) {
((AbstractDocument)doc).readLock();
}
try {
Rectangle alloc = getVisibleEditorRect(tc);
if (alloc != null) {
View rootView = tc.getUI().getRootView(tc);
View documentView = rootView.getView(0);
if (documentView instanceof EditorView) {
documentView.setSize(alloc.width, alloc.height);
offs = ((EditorView) documentView).viewToModelChecked(x, y, alloc, biasReturn);
} else {
rootView.setSize(alloc.width, alloc.height);
offs = rootView.viewToModel((float) x, (float) y, alloc, biasReturn);
}
}
} finally {
if (doc instanceof AbstractDocument) {
((AbstractDocument)doc).readUnlock();
}
}
return offs;
}
/**
* Invokes the <code>getNextVisualPositionFrom</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int getNextVisualPositionFrom(JTextComponent a, int b, Position.Bias c, int d, Position.Bias[] e)
throws BadLocationException {
int returnValue =
((TextUI) (uis.elementAt(0))).getNextVisualPositionFrom(a,b,c,d,e);
for (int i = 1; i < uis.size(); i++) {
((TextUI) (uis.elementAt(i))).getNextVisualPositionFrom(a,b,c,d,e);
}
return returnValue;
}
boolean setDotAndMark(@NonNull CaretItem caretItem, @NonNull Position dotPos, @NonNull Position.Bias dotBias,
@NonNull Position markPos, @NonNull Position.Bias markBias)
{
assert (dotPos != null) : "dotPos must not be null";
assert (markPos != null) : "markPos must not be null";
int index = findCaretItemIndex(origCaretItems, caretItem);
if (index != -1) {
Position origDotPos = caretItem.getDotPosition();
Position origMarkPos = caretItem.getMarkPosition();
boolean dotChanged = origDotPos == null || ComplexPositions.compare(dotPos, origDotPos) != 0 ||
dotBias != caretItem.getDotBias();
boolean markChanged = origMarkPos == null || ComplexPositions.compare(markPos, origMarkPos) != 0 ||
markBias != caretItem.getMarkBias();
scrollToLastCaret = true; // Scroll even if setDot() to same offset
if (dotChanged || markChanged) {
editorCaret.ensureValidInfo(caretItem);
if (expandFoldPositions == null) {
expandFoldPositions = new ArrayList<>(2);
}
if (dotChanged) {
caretItem.setDotPos(dotPos);
expandFoldPositions.add(dotPos);
anyDotChanged = true;
}
if (markChanged) {
caretItem.setMarkPos(markPos);
expandFoldPositions.add(markPos);
anyMarkChanged = true;
}
updateAffectedIndexes(index, index + 1);
caretItem.markUpdateCaretBounds();
caretItem.markInfoObsolete();
return true;
}
return false;
}
return false;
//caret.setDotCaret(offset, this, true);
}
/**
* Invokes the <code>viewToModel</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int viewToModel(JTextComponent a, Point b, Position.Bias[] c) {
int returnValue =
((TextUI) (uis.elementAt(0))).viewToModel(a,b,c);
for (int i = 1; i < uis.size(); i++) {
((TextUI) (uis.elementAt(i))).viewToModel(a,b,c);
}
return returnValue;
}
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
}
/**
* {@inheritDoc}
*/
@Override
public final Shape modelToView(int offset0, Position.Bias bias0, int offset1, Position.Bias bias1,
Shape alloc) throws BadLocationException
{
checkBounds(offset0);
checkBias(bias0);
checkBounds(offset1);
checkBias(bias1);
if (alloc != null) {
return modelToViewChecked(offset0, bias0, offset1, bias1, alloc);
} else {
return null;
}
}
@Override
public int viewToModel2D(JTextComponent a, Point2D b, Position.Bias[] c) {
int returnValue =
((TextUI) (uis.elementAt(0))).viewToModel2D(a,b,c);
for (int i = 1; i < uis.size(); i++) {
((TextUI) (uis.elementAt(i))).viewToModel2D(a,b,c);
}
return returnValue;
}
/**
* 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;
}
@Override
public void setDot(FilterBypass fb, int dot, Position.Bias bias) {
if (previous != null) {
previous.setDot(fb, dot, bias);
} else {
super.setDot(fb, dot, bias);
}
}
/**
* Invokes the <code>viewToModel</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
@Deprecated(since = "9")
@Override
public int viewToModel(JTextComponent a, Point b, Position.Bias[] c) {
int returnValue =
((TextUI) (uis.elementAt(0))).viewToModel(a,b,c);
for (int i = 1; i < uis.size(); i++) {
((TextUI) (uis.elementAt(i))).viewToModel(a,b,c);
}
return returnValue;
}
/**
* Invokes the <code>viewToModel</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public int viewToModel(JTextComponent a, Point b, Position.Bias[] c) {
int returnValue =
((TextUI) (uis.elementAt(0))).viewToModel(a,b,c);
for (int i = 1; i < uis.size(); i++) {
((TextUI) (uis.elementAt(i))).viewToModel(a,b,c);
}
return returnValue;
}
/**
* Invokes the <code>modelToView</code> method on each UI handled by this object.
*
* @return the value obtained from the first UI, which is
* the UI obtained from the default <code>LookAndFeel</code>
*/
public Rectangle modelToView(JTextComponent a, int b, Position.Bias c)
throws BadLocationException {
Rectangle returnValue =
((TextUI) (uis.elementAt(0))).modelToView(a,b,c);
for (int i = 1; i < uis.size(); i++) {
((TextUI) (uis.elementAt(i))).modelToView(a,b,c);
}
return returnValue;
}
public int viewToModelChecked(double x, double y, Shape alloc, Position.Bias[] biasReturn, int index) {
return getStartOffset();
}
/** Construct bias mark */
MultiMark(BasePosition pos, MarkVector markVector, int offset, Position.Bias bias) {
this(pos, markVector, offset,
(bias == Position.Bias.Backward) ? BACKWARD_BIAS : 0);
}
@Override
public Shape modelToViewChecked(int offset, Shape alloc, Position.Bias bias) {
return HighlightsViewUtils.indexToView(getTextLayout(), null, offset - getStartOffset(),
bias, getLength(), alloc);
}
/**
* Invokes the <code>damageRange</code> method on each UI handled by this object.
*/
public void damageRange(JTextComponent a, int b, int c, Position.Bias d, Position.Bias e) {
for (int i = 0; i < uis.size(); i++) {
((TextUI) (uis.elementAt(i))).damageRange(a,b,c,d,e);
}
}
static Position.Bias getBias(int offsetAndBias) {
return ((offsetAndBias & BACKWARD_BIAS_BIT) != 0)
? Position.Bias.Backward
: Position.Bias.Forward;
}
/**
* Invokes the <code>damageRange</code> method on each UI handled by this object.
*/
public void damageRange(JTextComponent a, int b, int c, Position.Bias d, Position.Bias e) {
for (int i = 0; i < uis.size(); i++) {
((TextUI) (uis.elementAt(i))).damageRange(a,b,c,d,e);
}
}
/**
* Returns the child view index representing the given position in
* the model.
*
* @param offset the position >= 0.
* @param b either forward or backward bias.
* @return index of the view representing the given position, or
* -1 if no view represents that position
*/
public @Override int getViewIndex(int offset, Position.Bias b) {
if (b == Position.Bias.Backward) {
offset -= 1;
}
return getViewIndex(offset);
}
/** 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);
}