本文整理匯總了Java中javax.swing.JEditorPane.modelToView方法的典型用法代碼示例。如果您正苦於以下問題:Java JEditorPane.modelToView方法的具體用法?Java JEditorPane.modelToView怎麽用?Java JEditorPane.modelToView使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JEditorPane
的用法示例。
在下文中一共展示了JEditorPane.modelToView方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: performOpen
import javax.swing.JEditorPane; //導入方法依賴的package包/類
private void performOpen(JEditorPane[] panes) {
if (panes == null || panes.length == 0) {
StatusDisplayer.getDefault().setStatusText(Bundle.ERR_ShellConsoleClosed());
return;
}
JEditorPane p = panes[0];
Rng[] fragments = theHandle.getFragments();
int to = fragments[0].start;
p.requestFocus();
int pos = Math.min(p.getDocument().getLength() - 1, to);
p.setCaretPosition(pos);
try {
Rectangle r = p.modelToView(pos);
p.scrollRectToVisible(r);
} catch (BadLocationException ex) {
}
}
示例3: _makeVisible
import javax.swing.JEditorPane; //導入方法依賴的package包/類
@Override public Object _makeVisible() {
JEditorPane editor = (JEditorPane) parent.getComponent();
Iterator iterator = findTag((HTMLDocument) editor.getDocument());
int startOffset = iterator.getStartOffset();
int endOffset = iterator.getEndOffset();
try {
Rectangle bounds = editor.modelToView(startOffset + (endOffset - startOffset) / 2);
if (bounds != null) {
bounds.height = editor.getVisibleRect().height;
editor.scrollRectToVisible(bounds);
}
} catch (BadLocationException e) {
throw new InvalidElementStateException("Unable to get text for tag " + tag + " in document with index " + index, e);
}
return null;
}
示例4: testLongLineInsert
import javax.swing.JEditorPane; //導入方法依賴的package包/類
public void testLongLineInsert() throws Exception {
loggingOn();
ViewUpdatesTesting.setTestValues(ViewUpdatesTesting.NO_OP_TEST_VALUE);
JEditorPane pane = ViewUpdatesTesting.createPane();
Document doc = pane.getDocument();
DocumentView docView = DocumentView.get(pane);
pane.modelToView(0); // Cause initialization
int offset;
String text;
offset = 0;
int lineLen = 4000;
StringBuilder sb = new StringBuilder(lineLen + 10);
for (int i = 0; i < lineLen; i++) {
sb.append('a');
}
sb.append('\n');
text = sb.toString();
ViewUpdatesTesting.setTestValues(
/*rebuildCause*/ ViewBuilder.RebuildCause.MOD_UPDATE,
/*createLocalViews*/ false,
/*startCreationOffset*/ 0,
/*matchOffset*/ offset + text.length() + 1, // createLocalViews == false
/*endCreationOffset*/ offset + text.length() + 1,
/*bmReuseOffset*/ 0,
/*bmReusePView*/ docView.getParagraphView(0),
/*bmReuseLocalIndex*/ 0,
/*amReuseOffset*/ Integer.MAX_VALUE, // createLocalViews == false
/*amReusePIndex*/ 1,
/*amReusePView*/ null,
/*amReuseLocalIndex*/ 0
);
doc.insertString(offset, text, null);
ViewUpdatesTesting.checkViews(docView, 0, -1,
4001, P_VIEW /* e:4001 */,
1, P_VIEW /* e:4002 */
);
ViewUpdatesTesting.setTestValues();
}
示例5: testSimpleUndoRedo
import javax.swing.JEditorPane; //導入方法依賴的package包/類
public void testSimpleUndoRedo() throws Exception {
loggingOn();
JEditorPane pane = ViewUpdatesTesting.createPane();
Document doc = pane.getDocument();
UndoManager undoManager = ViewUpdatesTesting.getUndoManager(doc);
doc.insertString(0, "abc\ndef\nghi\n", null);
ViewUpdatesTesting.setViewBounds(pane, 4, 8);
pane.modelToView(0);
doc.insertString(4, "o", null);
doc.remove(3, 3);
doc.insertString(4, "ab", null);
doc.remove(7, 2);
pane.modelToView(0);
undoManager.undo(); // insert(7,2)
undoManager.undo(); // remove(4,2)
undoManager.undo(); // insert(3,3)
undoManager.undo();
undoManager.redo();
undoManager.redo();
undoManager.redo();
undoManager.redo();
}
示例6: testLongLineUndo
import javax.swing.JEditorPane; //導入方法依賴的package包/類
public void testLongLineUndo() throws Exception {
loggingOn();
JEditorPane pane = ViewUpdatesTesting.createPane();
Document doc = pane.getDocument();
UndoManager undoManager = ViewUpdatesTesting.getUndoManager(doc);
int lineLen = 4000;
StringBuilder sb = new StringBuilder(lineLen + 10);
for (int i = 0; i < lineLen; i++) {
sb.append('a');
}
sb.append('\n');
doc.insertString(0, sb.toString(), null);
pane.modelToView(0);
doc.remove(0, lineLen);
pane.modelToView(0);
undoManager.undo();
undoManager.redo();
}
示例7: testRemoveNewline
import javax.swing.JEditorPane; //導入方法依賴的package包/類
public void testRemoveNewline() throws Exception {
loggingOn();
JEditorPane pane = ViewUpdatesTesting.createPane();
Document doc = pane.getDocument();
UndoManager undoManager = ViewUpdatesTesting.getUndoManager(doc);
doc.insertString(0, "a\nb", null);
doc.remove(1, 1);
undoManager.undo();
pane.modelToView(0);
}
示例8: testCustomBounds
import javax.swing.JEditorPane; //導入方法依賴的package包/類
public void testCustomBounds() throws Exception {
loggingOn();
JEditorPane pane = ViewUpdatesTesting.createPane();
Document doc = pane.getDocument();
doc.insertString(0, "hello\nworld\ngood\nmorning", null);
Position startPos = doc.createPosition(3);
pane.putClientProperty(DocumentView.START_POSITION_PROPERTY, startPos);
pane.modelToView(0); // Force rebuild of VH
doc.insertString(startPos.getOffset(), "a", null);
doc.insertString(startPos.getOffset() - 1, "a", null);
Element line0 = doc.getDefaultRootElement().getElement(0);
Position endPos = doc.createPosition(line0.getEndOffset() + 3); // Middle of line 1
pane.putClientProperty(DocumentView.END_POSITION_PROPERTY, endPos);
pane.modelToView(0); // Force rebuild of VH
TestHighlightsViewFactory testFactory = ViewUpdatesTesting.getTestFactory(pane);
List<TestHighlight> hlts = ViewUpdatesTesting.getHighlightsCopy(testFactory);
int hlStartOffset = startPos.getOffset() + 1;
int hlEndOffset = endPos.getOffset() - 1;
TestHighlight hi = TestHighlight.create(doc, hlStartOffset, hlEndOffset, colorAttrs[0]);
hlts.add(hi);
testFactory.setHighlights(hlts);
testFactory.fireChange(hlStartOffset, hlEndOffset);
pane.modelToView(0); // Force rebuild of VH
doc.insertString(doc.getLength(), "test\ntest2", null);
Position endPos2 = doc.createPosition(doc.getLength() - 3);
pane.putClientProperty(DocumentView.END_POSITION_PROPERTY, endPos2);
pane.modelToView(0); // Force rebuild of VH
doc.remove(endPos2.getOffset() - 2, 3);
pane.putClientProperty(DocumentView.START_POSITION_PROPERTY, null);
pane.modelToView(0); // Force rebuild of VH
}
示例9: testEmptyCustomBounds
import javax.swing.JEditorPane; //導入方法依賴的package包/類
public void testEmptyCustomBounds() throws Exception {
loggingOn();
JEditorPane pane = ViewUpdatesTesting.createPane();
Document doc = pane.getDocument();
pane.modelToView(0);
doc.insertString(0, "hello\nworld\ngood\nmorning", null);
Position startPos = doc.createPosition(3);
pane.putClientProperty(DocumentView.START_POSITION_PROPERTY, startPos);
pane.putClientProperty(DocumentView.END_POSITION_PROPERTY, startPos);
pane.modelToView(0); // Force rebuild of VH
Position endPos = doc.createPosition(2);
pane.putClientProperty(DocumentView.END_POSITION_PROPERTY, endPos);
pane.modelToView(0); // Force rebuild of VH
}
示例10: testInsertNewlineIntoPartial
import javax.swing.JEditorPane; //導入方法依賴的package包/類
public void testInsertNewlineIntoPartial() throws Exception {
loggingOn();
JEditorPane pane = ViewUpdatesTesting.createPane();
Document doc = pane.getDocument();
pane.modelToView(0);
doc.insertString(0, "x\nya\n\nbc\nmorning", null);
ViewUpdatesTesting.setViewBounds(pane, 3, doc.getLength() - 3);
pane.modelToView(0);
doc.insertString(8, "\n\n", null);
pane.modelToView(0);
}
示例11: run
import javax.swing.JEditorPane; //導入方法依賴的package包/類
@Override
protected void run(Context context) throws Exception {
List<JEditorPane> paneList = getPaneList(context);
Random random = context.container().random();
StringBuilder log = context.logOpBuilder();
if (CREATE_PANE == name()) { // Just use ==
if (log != null) {
log.append("CREATE_ROOT_VIEW");
}
boolean createBounded = !paneList.isEmpty();
JEditorPane pane = ViewUpdatesTesting.createPane(DocumentTesting.getDocument(context));
paneList.add(pane);
if (createBounded) {
Document doc = pane.getDocument();
int startOffset = random.nextInt(doc.getLength());
int endOffset = startOffset + random.nextInt(doc.getLength() - startOffset) + 1;
ViewUpdatesTesting.setViewBounds(pane, startOffset, endOffset);
if (log != null) {
log.append("(").append(startOffset).append(",").append(endOffset).append(")");
}
}
if (log != null) {
log.append("\n");
context.logOp(log);
}
pane.modelToView(0);
} else if (RELEASE_PANE == name()) { // Just use ==
if (!paneList.isEmpty()) {
int index = random.nextInt(paneList.size());
paneList.remove(index);
if (log != null) {
log.append("DESTROY_ROOT_VIEW[" + index + "]\n");
}
}
}
}
示例12: clickForTextPopup
import javax.swing.JEditorPane; //導入方法依賴的package包/類
protected void clickForTextPopup(EditorOperator eo, String menu) {
JEditorPaneOperator txt = eo.txtEditorPane();
JEditorPane epane = (JEditorPane) txt.getSource();
try {
Rectangle rct = epane.modelToView(epane.getCaretPosition());
txt.clickForPopup(rct.x, rct.y);
JPopupMenuOperator popup = new JPopupMenuOperator();
popup.pushMenu(menu);
} catch (BadLocationException ex) {
System.out.println("=== Bad location");
}
}
示例13: _moveto
import javax.swing.JEditorPane; //導入方法依賴的package包/類
@Override public void _moveto() {
JEditorPane editor = (JEditorPane) parent.getComponent();
Iterator iterator = findTag((HTMLDocument) editor.getDocument());
int startOffset = iterator.getStartOffset();
int endOffset = iterator.getEndOffset();
try {
Rectangle bounds = editor.modelToView(startOffset + (endOffset - startOffset) / 2);
getDriver().getDevices().moveto(parent.getComponent(), bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
} catch (BadLocationException e) {
throw new InvalidElementStateException("Unable to get text for tag " + tag + " in document with index " + index, e);
}
}
示例14: _getMidpoint
import javax.swing.JEditorPane; //導入方法依賴的package包/類
@Override public Point _getMidpoint() {
JEditorPane editor = (JEditorPane) parent.getComponent();
Iterator iterator = findTag((HTMLDocument) editor.getDocument());
int startOffset = iterator.getStartOffset();
int endOffset = iterator.getEndOffset();
try {
Rectangle bounds = editor.modelToView(startOffset + (endOffset - startOffset) / 2);
return new Point(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
} catch (BadLocationException e) {
throw new InvalidElementStateException("Unable to get text for tag " + tag + " in document with index " + index + "("
+ "StartOffset: " + startOffset + " EndOffset: " + endOffset + ")", e);
}
}
示例15: _makeVisible
import javax.swing.JEditorPane; //導入方法依賴的package包/類
@Override public Object _makeVisible() {
JEditorPane editor = (JEditorPane) parent.getComponent();
try {
Rectangle bounds = editor.modelToView(pos);
if (bounds != null) {
bounds.height = editor.getVisibleRect().height;
editor.scrollRectToVisible(bounds);
}
} catch (BadLocationException e) {
throw new InvalidElementStateException("Invalid position " + pos + "(" + e.getMessage() + ")", e);
}
return null;
}