本文整理汇总了Java中javax.swing.text.View.getStartOffset方法的典型用法代码示例。如果您正苦于以下问题:Java View.getStartOffset方法的具体用法?Java View.getStartOffset怎么用?Java View.getStartOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.View
的用法示例。
在下文中一共展示了View.getStartOffset方法的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
}