本文整理匯總了Java中javax.swing.text.View.getEndOffset方法的典型用法代碼示例。如果您正苦於以下問題:Java View.getEndOffset方法的具體用法?Java View.getEndOffset怎麽用?Java View.getEndOffset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.text.View
的用法示例。
在下文中一共展示了View.getEndOffset方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: modelToView
import javax.swing.text.View; //導入方法依賴的package包/類
@Override
public Shape modelToView(int pos, Shape a, Position.Bias b)
throws BadLocationException {
if (! isAllocationValid()) {
Rectangle alloc = a.getBounds();
setSize(alloc.width, alloc.height);
}
boolean isBackward = (b == Position.Bias.Backward);
int testPos = (isBackward) ? Math.max(0, pos - 1) : pos;
if(isBackward && testPos < getStartOffset()) {
return null;
}
int vIndex = getViewIndexAtPosition(testPos);
if ((vIndex != -1) && (vIndex < getViewCount())) {
View v = getView(vIndex);
if(v != null && testPos >= v.getStartOffset() &&
testPos < v.getEndOffset()) {
Shape childShape = getChildAllocation(vIndex, a);
if (childShape == null) {
// We are likely invalid, fail.
return null;
}
Shape retShape = v.modelToView(pos, childShape, b);
if(retShape == null && v.getEndOffset() == pos) {
if(++vIndex < getViewCount()) {
v = getView(vIndex);
retShape = v.modelToView(pos, getChildAllocation(vIndex, a), b);
}
}
return retShape;
}
}
throw new BadLocationException("Position not represented by view", pos);
}
示例2: findViewIndexBounded
import javax.swing.text.View; //導入方法依賴的package包/類
/**
* Find child index representing the given offset
* or -1 if the offset is not represented by any child view
* i.e. it is outside of the bounds of this view
* or when the given view does not have any children.
*
* @param view view having children to be inspected.
* @param offset the position >= 0.
* @return index of the child view representing the given position
* or -1 if <code>
* offset < view.getStartOffset()
* || offset >= view.getEndOffset()</code>
* || getViewCount() == 0
* </code>.
*/
public static int findViewIndexBounded(View view, int offset) {
int viewStartOffset = view.getStartOffset();
if (offset == viewStartOffset)
return 0;
if ((offset >= viewStartOffset) && (offset < view.getEndOffset())) {
return findViewIndex(view, offset);
}
return -1; // outside of view bounds
}