本文整理汇总了Java中javax.swing.text.View.getViewIndex方法的典型用法代码示例。如果您正苦于以下问题:Java View.getViewIndex方法的具体用法?Java View.getViewIndex怎么用?Java View.getViewIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.View
的用法示例。
在下文中一共展示了View.getViewIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import javax.swing.text.View; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, JTextComponent target) {
AbstractDocument adoc = (AbstractDocument)target.getDocument();
// Dump fold hierarchy
FoldHierarchy hierarchy = FoldHierarchy.get(target);
adoc.readLock();
try {
hierarchy.lock();
try {
/*DEBUG*/System.err.println("FOLD HIERARCHY DUMP:\n" + hierarchy); // NOI18N
TokenHierarchy<?> th = TokenHierarchy.get(adoc);
/*DEBUG*/System.err.println("TOKEN HIERARCHY DUMP:\n" + (th != null ? th : "<NULL-TH>")); // NOI18N
} finally {
hierarchy.unlock();
}
} finally {
adoc.readUnlock();
}
View rootView = null;
TextUI textUI = target.getUI();
if (textUI != null) {
rootView = textUI.getRootView(target); // Root view impl in BasicTextUI
if (rootView != null && rootView.getViewCount() == 1) {
rootView = rootView.getView(0); // Get DocumentView
}
}
if (rootView != null) {
String rootViewDump = (rootView instanceof DocumentView)
? ((DocumentView)rootView).toStringDetail()
: rootView.toString();
/*DEBUG*/System.err.println("DOCUMENT VIEW: " + System.identityHashCode(rootView) + // NOI18N
"\n" + rootViewDump); // NOI18N
int caretOffset = target.getCaretPosition();
int caretViewIndex = rootView.getViewIndex(caretOffset, Position.Bias.Forward);
/*DEBUG*/System.err.println("caretOffset=" + caretOffset + ", caretViewIndex=" + caretViewIndex); // NOI18N
if (caretViewIndex >= 0 && caretViewIndex < rootView.getViewCount()) {
View caretView = rootView.getView(caretViewIndex);
/*DEBUG*/System.err.println("caretView: " + caretView); // NOI18N
}
/*DEBUG*/System.err.println(FixLineSyntaxState.lineInfosToString(adoc));
// Check the hierarchy correctness
//org.netbeans.editor.view.spi.ViewUtilities.checkViewHierarchy(rootView);
}
if (adoc instanceof BaseDocument) {
/*DEBUG*/System.err.println("DOCUMENT:\n" + ((BaseDocument)adoc).toStringDetail()); // NOI18N
}
}
示例2: checkModelToViewCorrectness
import javax.swing.text.View; //导入方法依赖的package包/类
private void checkModelToViewCorrectness(JEditorPane jep) throws Exception {
Document doc = jep.getDocument();
assertTrue("Expecting BaseTextUI", jep.getUI() instanceof BaseTextUI);
BaseTextUI btui = (BaseTextUI) jep.getUI();
Insets margin = btui.getEditorUI().getTextMargin();
int charWidth = btui.getEditorUI().defaultSpaceWidth;
int charHeight = btui.getEditorUI().getLineHeight();
// System.out.println("### charWidth = " + charWidth + ", charHeight = " + charHeight
// + ", docLen = " + doc.getLength()
// + ", jep.width = " + jep.getWidth()
// + ", jep.height = " + jep.getHeight());
for(int offset = 0; offset <= doc.getLength(); offset++) {
// model-to-view translation
Rectangle r = jep.modelToView(offset);
assertNotNull("No m2v translation: offset = " + offset + ", docLen = " + doc.getLength(), r);
View rootView = Utilities.getRootView(jep, DrawEngineDocView.class);
int line = rootView.getViewIndex(offset, Position.Bias.Forward);
int col = offset - rootView.getView(line).getStartOffset();
// XXX: this would be necessary for handling tabs, but it uses DrawEngineLineView
// and therefore is not independent from the tested code, the inverse transformation
// will be needed in checkViewToModel
// int col = Utilities.getVisualColumn((BaseDocument)doc, offset);
// int nextCol = offset >= rootView.getView(line).getEndOffset() - 1 ? col + 1 : Utilities.getVisualColumn((BaseDocument)doc, offset + 1);
// System.out.println("### offset = " + offset + ", col = " + col + ", nextCol = " + nextCol + ", docLen = " + doc.getLength());
Rectangle r2 = new Rectangle(
margin.left + col * charWidth,
margin.top + line * charHeight,
// XXX: see above comment about the tabs handling
// (nextCol - col) * charWidth,
charWidth,
charHeight
);
assertEquals("Incorrect m2v translation: offset = " + offset + ", docLen = " + doc.getLength(), r2, r);
}
}