本文整理匯總了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);
}