本文整理汇总了Java中javax.swing.text.View.modelToView方法的典型用法代码示例。如果您正苦于以下问题:Java View.modelToView方法的具体用法?Java View.modelToView怎么用?Java View.modelToView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.View
的用法示例。
在下文中一共展示了View.modelToView方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: modelToView
import javax.swing.text.View; //导入方法依赖的package包/类
/**
* Provides a mapping from the document model coordinate space
* to the coordinate space of the view mapped to it.
*
* @param pos the position to convert >= 0
* @param a the allocated region to render into
* @param b the bias toward the previous character or the
* next character represented by the offset, in case the
* position is a boundary of two views.
* @return the bounding box of the given position is returned
* @exception BadLocationException if the given position does
* not represent a valid location in the associated document
* @exception IllegalArgumentException for an invalid bias argument
* @see View#viewToModel
*/
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
int index = getViewIndex(pos, b);
if (index >= 0) {
Shape ca = getChildAllocation(index, a);
// forward to the child view
ViewLayoutState child = getChild(index);
View cv = child.getView();
return cv.modelToView(pos, ca, b);
} else {
Document doc = getDocument();
int docLen = (doc != null) ? doc.getLength() : -1;
throw new BadLocationException("Offset " + pos + " with bias " + b + " is outside of the view" //NOI18N
+ ", children = " + getViewCount() //NOI18N
+ (getViewCount() > 0 ? " covering offsets <" + //NOI18N
getView(0).getStartOffset() + ", " + //NOI18N
getView(getViewCount() - 1).getEndOffset() + ">" : "") + //NOI18N
", docLen=" + docLen
, pos);
}
}
示例2: modelToView
import javax.swing.text.View; //导入方法依赖的package包/类
static Rectangle2D modelToView(JTextComponent tc, int pos, Position.Bias bias) throws BadLocationException {
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);
rootView.setSize(alloc.width, alloc.height);
Shape s = rootView.modelToView(pos, alloc, bias);
if (s != null) {
return s.getBounds2D();
}
}
} finally {
if (doc instanceof AbstractDocument) {
((AbstractDocument)doc).readUnlock();
}
}
return null;
}
示例3: 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);
}