本文整理汇总了Java中javax.swing.JEditorPane.viewToModel方法的典型用法代码示例。如果您正苦于以下问题:Java JEditorPane.viewToModel方法的具体用法?Java JEditorPane.viewToModel怎么用?Java JEditorPane.viewToModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JEditorPane
的用法示例。
在下文中一共展示了JEditorPane.viewToModel方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkModelToViewConsistency
import javax.swing.JEditorPane; //导入方法依赖的package包/类
private void checkModelToViewConsistency(JEditorPane jep) throws Exception {
Document doc = jep.getDocument();
for(int i = 0; i <= doc.getLength(); i++) {
// model-to-view
Rectangle r = jep.modelToView(i);
assertNotNull("No m2v translation: offset = " + i + ", docLen = " + doc.getLength(), r);
// view-to-model
int offset = jep.viewToModel(r.getLocation());
assertTrue("Invalid v2m translation: " + s(r.getLocation()) + " -> " + offset+ ", docLen = " + doc.getLength(),
offset >= 0 && offset <= doc.getLength());
// check
assertEquals("Inconsistent m2v-v2m translation, offset = " + i
+ ", rectangle = " + s(r) + ", docLen = " + doc.getLength(), i, offset);
}
}
示例2: mouseMoved
import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void mouseMoved (MouseEvent e) {
JEditorPane c = (JEditorPane) e.getComponent ();
final NbEditorDocument doc = (NbEditorDocument) c.getDocument ();
if (highlight != null) highlight.remove ();
highlight = null;
runnable = null;
if (((e.getModifiers() | e.getModifiersEx()) & InputEvent.CTRL_DOWN_MASK) != InputEvent.CTRL_DOWN_MASK) {
return;
}
int offset = c.viewToModel (e.getPoint ());
highlight (doc, offset);
c.repaint ();
}
示例3: checkViewToModelConsistency
import javax.swing.JEditorPane; //导入方法依赖的package包/类
private void checkViewToModelConsistency(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());
Rectangle eodRectangle = null;
Rectangle eolRectangle = null;
for(int y = charHeight / 2 + margin.top; y < jep.getHeight(); y += charHeight) {
if (eodRectangle == null) {
eolRectangle = null;
}
for(int x = charWidth / 2 + margin.left; x < jep.getWidth(); x += charWidth) {
Point p = new Point(x, y);
// view-to-model translation
int offset = jep.viewToModel(p);
assertTrue("Invalid v2m translation: " + s(p) + " -> " + offset+ ", docLen = " + doc.getLength(),
offset >= 0 && offset <= doc.getLength());
// model-to-view
Rectangle r = jep.modelToView(offset);
assertNotNull("No m2v translation: offset = " + offset + ", docLen = " + doc.getLength(), r);
// check
if (eodRectangle == null) {
boolean eod = offset == doc.getLength();
boolean eol = doc.getText(offset, 1).charAt(0) == '\n';
if (eolRectangle == null) {
assertTrue("Inconsistent v2m-m2v translation, point = " + s(p) + " not within " + s(r)
+ ", offset = " + offset + ", docLen = " + doc.getLength(), r.contains(p));
if (eol) {
eolRectangle = r;
}
} else {
assertEquals("Inconsistent v2m-m2v translation, for point = " + s(p) + " behing eol"
+ ", offset = " + offset + ", docLen = " + doc.getLength(), eolRectangle, r);
}
if (eod) {
eodRectangle = r;
}
} else {
Point pointAtTheLastLine = new Point(Math.min(p.x, eolRectangle.x), eodRectangle.y);
assertTrue("Inconsistent v2m-m2v translation, for point = " + s(p)
+ " behing eod, point at the last line " + s(pointAtTheLastLine) + " is outside of " + s(r)
+ ", offset = " + offset + ", docLen = " + doc.getLength(), r.contains(pointAtTheLastLine));
}
}
}
}