当前位置: 首页>>代码示例>>Java>>正文


Java JEditorPane.modelToView方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:DrawEngineTest.java

示例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) {
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:OpenAction.java

示例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;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:17,代码来源:JEditorPaneTagJavaElement.java

示例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();
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:41,代码来源:ViewUpdatesTest.java

示例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();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:ViewHierarchyTest.java

示例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();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ViewHierarchyTest.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:ViewHierarchyTest.java

示例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
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:ViewHierarchyTest.java

示例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
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:ViewHierarchyTest.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:ViewHierarchyTest.java

示例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");
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:RootViewRandomTesting.java

示例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");
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:GeneralCSSPrep.java

示例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);
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:13,代码来源:JEditorPaneTagJavaElement.java

示例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);
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:14,代码来源:JEditorPaneTagJavaElement.java

示例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;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:14,代码来源:JEditorPanePosJavaElement.java


注:本文中的javax.swing.JEditorPane.modelToView方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。