本文整理匯總了Java中javax.swing.text.View.viewToModel方法的典型用法代碼示例。如果您正苦於以下問題:Java View.viewToModel方法的具體用法?Java View.viewToModel怎麽用?Java View.viewToModel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.text.View
的用法示例。
在下文中一共展示了View.viewToModel方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: viewToModel
import javax.swing.text.View; //導入方法依賴的package包/類
/**
* Provides a mapping from the view coordinate space to the logical
* coordinate space of the model. The biasReturn argument will be
* filled in to indicate that the point given is closer to the next
* character in the model or the previous character in the model.
* <p>
* This is expected to be called by the GUI thread, holding a
* read-lock on the associated model. It is implemented to
* locate the child view and determine it's allocation with a
* lock on the ChildLocator object, and to call viewToModel
* on the child view with a lock on the ViewLayoutState object
* to avoid interaction with the layout thread.
*
* @param x the X coordinate >= 0
* @param y the Y coordinate >= 0
* @param a the allocated region to render into
* @return the location within the model that best represents the
* given point in the view >= 0. The biasReturn argument will be
* filled in to indicate that the point given is closer to the next
* character in the model or the previous character in the model.
*/
public int viewToModel(float x, float y, Shape a, Position.Bias[] biasReturn) {
int pos; // return position
int index; // child index to forward to
Shape ca; // child allocation
index = getViewIndexAtPoint(x, y, a);
index = Math.max(index, 0);
if (index < getViewCount()) {
ca = getChildAllocation(index, a);
// forward to the child view
ViewLayoutState child = getChild(index);
View v = child.getView();
pos = v.viewToModel(x, y, ca, biasReturn);
} else { // at the end
int endOff = getEndOffset();
Document doc = getDocument();
pos = (doc!=null && doc.getLength() < endOff) ? doc.getLength() : endOff;
}
return pos;
}
示例2: viewToModel
import javax.swing.text.View; //導入方法依賴的package包/類
static int viewToModel(JTextComponent tc, double x, double y, Position.Bias[] biasReturn) {
int offs = -1;
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);
View documentView = rootView.getView(0);
if (documentView instanceof EditorView) {
documentView.setSize(alloc.width, alloc.height);
offs = ((EditorView) documentView).viewToModelChecked(x, y, alloc, biasReturn);
} else {
rootView.setSize(alloc.width, alloc.height);
offs = rootView.viewToModel((float) x, (float) y, alloc, biasReturn);
}
}
} finally {
if (doc instanceof AbstractDocument) {
((AbstractDocument)doc).readUnlock();
}
}
return offs;
}