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