当前位置: 首页>>代码示例>>Java>>正文


Java View.modelToView方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:GapBoxView.java

示例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;
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:Utilities.java

示例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);

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:40,代码来源:WrappedSyntaxView.java


注:本文中的javax.swing.text.View.modelToView方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。