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


Java JEditorPane.getDocument方法代码示例

本文整理汇总了Java中javax.swing.JEditorPane.getDocument方法的典型用法代码示例。如果您正苦于以下问题:Java JEditorPane.getDocument方法的具体用法?Java JEditorPane.getDocument怎么用?Java JEditorPane.getDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JEditorPane的用法示例。


在下文中一共展示了JEditorPane.getDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testBeyondEndDocHighlightsLayer

import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testBeyondEndDocHighlightsLayer() throws Exception {
        loggingOn();
        String mimeType = "text/plain";
//        MimeLookup.getLookup(MimePath.get(mimeType)).lookup(HighlightsLayer.class); // Init ML
//        HighlightsLayerProvider.clear();
        HighlightsLayerProvider.add("text/x-java", new HLFactory());
        HighlightsLayerProvider.add(mimeType, new HLFactory());
//        MemoryMimeDataProvider.reset(null);
//        MemoryMimeDataProvider.addInstances("text/x-java", new HLFactory());
//        MemoryMimeDataProvider.addInstances(mimeType, new HLFactory());

        RandomTestContainer container = createContainer();
        JEditorPane pane = container.getInstance(JEditorPane.class);
        Document doc = pane.getDocument();
        doc.putProperty("mimeType", mimeType);
        DocumentTesting.setSameThreadInvoke(container.context(), true); // Do not post to EDT
        RandomTestContainer.Context gContext = container.context();
        DocumentTesting.insert(gContext, 0, "a\nb");
        DocumentTesting.insert(gContext, 1, "c");
        DocumentTesting.remove(gContext, 2, 1);
        DocumentTesting.insert(gContext, 1, "d\nx");
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:JavaViewHierarchyRandomTest.java

示例2: testMemoryRelease

import javax.swing.JEditorPane; //导入方法依赖的package包/类
@RandomlyFails
public void testMemoryRelease() throws Exception { // Issue #147984
    org.netbeans.junit.Log.enableInstances(Logger.getLogger("TIMER"), "CodeTemplateInsertHandler", Level.FINEST);

    JEditorPane pane = new JEditorPane();
    NbEditorKit kit = new NbEditorKit();
    pane.setEditorKit(kit);
    Document doc = pane.getDocument();
    assertTrue(doc instanceof BaseDocument);
    CodeTemplateManager mgr = CodeTemplateManager.get(doc);
    String templateText = "Test with parm ";
    CodeTemplate ct = mgr.createTemporary(templateText + " ${a}");
    ct.insert(pane);
    assertEquals(templateText + " a", doc.getText(0, doc.getLength()));

    // Send Enter to stop editing
    KeyEvent enterKeyEvent = new KeyEvent(pane, KeyEvent.KEY_PRESSED,
            EventQueue.getMostRecentEventTime(),
            0, KeyEvent.VK_ENTER, KeyEvent.CHAR_UNDEFINED);

    SwingUtilities.processKeyBindings(enterKeyEvent);
    // CT editing should be finished

    org.netbeans.junit.Log.assertInstances("CodeTemplateInsertHandler instances not GCed");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:CodeTemplatesTest.java

示例3: testDeleteAterInsertBreak

import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testDeleteAterInsertBreak() throws Exception {
        loggingOn();
        RandomTestContainer container = createContainer();
        JEditorPane pane = container.getInstance(JEditorPane.class);
        Document doc = pane.getDocument();
        doc.putProperty("mimeType", "text/plain");
        ViewHierarchyRandomTesting.initRandomText(container);
        RandomTestContainer.Context context = container.context();
        DocumentTesting.insert(context, 0,
" osen   \n\n\n  esl\t\ta \t\t \n\n\nabcd\td  m\t\tabcdef\te\t\tab\tcdef\tef\tkojd \t\t \n\n\n        t\t vpjm\ta\ngooywzmj           q\tugos\tdefy\t   i  xs    us tg z"
        );

        EditorPaneTesting.setCaretOffset(context, 70);
        DocumentTesting.remove(context, 50, 10);
        EditorPaneTesting.performAction(context, pane, DefaultEditorKit.insertBreakAction);
        EditorPaneTesting.performAction(context, pane, DefaultEditorKit.deleteNextCharAction);
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:JavaViewHierarchyRandomTest.java

示例4: testAddCaretUndoableEdit

import javax.swing.JEditorPane; //导入方法依赖的package包/类
@Test
public void testAddCaretUndoableEdit() throws Exception {
    final JEditorPane pane = new JEditorPane("text/plain", "Haf");
    //final CompoundEdit compoundEdit = new CompoundEdit();
    final boolean[] editAdded = { false };
    final Document doc = pane.getDocument();
    doc.putProperty(CustomUndoDocument.class, new CustomUndoDocument() {
        @Override
        public void addUndoableEdit(UndoableEdit edit) {
            editAdded[0] = true;
        }
    });
    final EditorCaret editorCaret = new EditorCaret();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            pane.setCaret(editorCaret);
            EditorUtilities.addCaretUndoableEdit(doc, editorCaret);
        }
    });
    
    assertTrue(editAdded[0]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:EditorUtilitiesTest.java

示例5: testNewlineInEmptyDoc

import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testNewlineInEmptyDoc() throws Exception {
    loggingOn();
    RandomTestContainer container = createContainer();
    JEditorPane pane = container.getInstance(JEditorPane.class);
    Document doc = pane.getDocument();
    doc.putProperty("mimeType", "text/plain");
    RandomTestContainer.Context gContext = container.context();
    DocumentTesting.insert(gContext, 0, "\n");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:JavaViewHierarchyRandomTest.java

示例6: testRemoveAtBegining

import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testRemoveAtBegining() throws Exception {
        loggingOn();
        RandomTestContainer container = createContainer();
        JEditorPane pane = container.getInstance(JEditorPane.class);
        Document doc = pane.getDocument();
        doc.putProperty("mimeType", "text/plain");
        ViewHierarchyRandomTesting.initRandomText(container);
        RandomTestContainer.Context context = container.context();
        DocumentTesting.insert(context, 0,
" \t\tabcdef\ta\nebxsu"
        );
        DocumentTesting.remove(context, 0, 1);
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:JavaViewHierarchyRandomTest.java

示例7: getApplicableFileObject

import javax.swing.JEditorPane; //导入方法依赖的package包/类
private FileObject getApplicableFileObject(int[] caretPosHolder) {
    if (!EventQueue.isDispatchThread()) {
        // Unsafe to ask for an editor pane from a random thread.
        // E.g. org.netbeans.lib.uihandler.LogRecords.write asking for getName().
        Collection<? extends FileObject> dobs = Utilities.actionsGlobalContext().lookupAll(FileObject.class);
        return dobs.size() == 1 ? dobs.iterator().next() : null;
    }

    // TODO: Use the new editor library to compute this:
    // JTextComponent pane = EditorRegistry.lastFocusedComponent();

    TopComponent comp = TopComponent.getRegistry().getActivated();
    if(comp == null) {
        return null;
    }
    Node[] nodes = comp.getActivatedNodes();
    if (nodes != null && nodes.length == 1) {
        if (comp instanceof CloneableEditorSupport.Pane) { //OK. We have an editor
            EditorCookie ec = nodes[0].getLookup().lookup(EditorCookie.class);
            if (ec != null) {
                JEditorPane editorPane = NbDocument.findRecentEditorPane(ec);
                if (editorPane != null) {
                    if (editorPane.getCaret() != null) {
                            caretPosHolder[0] = editorPane.getCaret().getDot();
                    }
                    Document document = editorPane.getDocument();
                    return Source.create(document).getFileObject();
                }
            }
        } else {
            return UICommonUtils.getFileObjectFromNode(nodes[0]);
        }
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:GotoOppositeAction.java

示例8: getDocument

import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
 * Get document from test container by consulting either an editor pane's document
 * or a document property.
 *
 * @param provider non-null property provider
 * @return document instance or null.
 */
public static Document getDocument(PropertyProvider provider) {
    JEditorPane pane = provider.getInstanceOrNull(JEditorPane.class);
    if (pane != null) {
        return pane.getDocument();
    } else {
        return provider.getInstanceOrNull(Document.class);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:DocumentContentTesting.java

示例9: insertNewline

import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void insertNewline(String source, String reformatted, IndentPrefs preferences) throws Exception {
    int sourcePos = source.indexOf('^');
    assertNotNull(sourcePos);
    source = source.substring(0, sourcePos) + source.substring(sourcePos+1);
    Formatter formatter = getFormatter(null);

    int reformattedPos = reformatted.indexOf('^');
    assertNotNull(reformattedPos);
    reformatted = reformatted.substring(0, reformattedPos) + reformatted.substring(reformattedPos+1);

    JEditorPane ta = getPane(source);
    Caret caret = ta.getCaret();
    caret.setDot(sourcePos);
    BaseDocument doc = (BaseDocument) ta.getDocument();
    if (formatter != null) {
        configureIndenters(doc, formatter, true);
    }

    setupDocumentIndentation(doc, preferences);

    runKitAction(ta, DefaultEditorKit.insertBreakAction, "\n");

    String formatted = doc.getText(0, doc.getLength());
    assertEquals(reformatted, formatted);

    if (reformattedPos != -1) {
        assertEquals(reformattedPos, caret.getDot());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:CslTestBase.java

示例10: ResultPanelOutput

import javax.swing.JEditorPane; //导入方法依赖的package包/类
/**
 * Creates a new instance of ResultPanelOutput
 */
ResultPanelOutput(ResultDisplayHandler displayHandler) {
    super();
    if (LOG) {
        System.out.println("ResultPanelOutput.<init>");
    }
    
    textPane = new JEditorPane();
    textPane.setFont(new Font("monospaced", Font.PLAIN, getFont().getSize()));
    textPane.setEditorKit(new OutputEditorKit());
    textPane.setEditable(false);
    textPane.getCaret().setVisible(true);
    textPane.getCaret().setBlinkRate(0);
    textPane.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
    setViewportView(textPane);

    /*
     * On GTK L&F, background of the text pane is gray, even though it is
     * white on a JTextArea. The following is a hack to fix it:
     */
    Color background = UIManager.getColor("TextPane.background");   //NOI18N
    if (background != null) {
        textPane.setBackground(background);
    }

    doc = textPane.getDocument();

    AccessibleContext ac = textPane.getAccessibleContext();
    ac.setAccessibleName(NbBundle.getMessage(getClass(),
                                            "ACSN_OutputTextPane"));//NOI18N
    ac.setAccessibleDescription(NbBundle.getMessage(getClass(),
                                            "ACSD_OutputTextPane"));//NOI18N
    
    this.displayHandler = displayHandler;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:ResultPanelOutput.java

示例11: testSimple1

import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testSimple1() throws Exception {
    loggingOn();
    RandomTestContainer container = createContainer();
    JEditorPane pane = container.getInstance(JEditorPane.class);
    Document doc = pane.getDocument();
    doc.putProperty("mimeType", "text/plain");
    RandomTestContainer.Context gContext = container.context();
    DocumentTesting.insert(gContext, 0, "a\nb");
    DocumentTesting.insert(gContext, 1, "c");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:JavaViewHierarchyRandomTest.java

示例12: testRandomModsJavaSeed1

import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testRandomModsJavaSeed1() throws Exception {
    loggingOn();
    RandomTestContainer container = createContainer();
    JEditorPane pane = container.getInstance(JEditorPane.class);
    Document doc = pane.getDocument();
    doc.putProperty(Language.class, JavaTokenId.language());
    doc.putProperty("mimeType", "text/x-java");
    ViewHierarchyRandomTesting.initRandomText(container);
    ViewHierarchyRandomTesting.addRound(container).setOpCount(OP_COUNT);
    ViewHierarchyRandomTesting.testFixedScenarios(container);
    container.run(1286796912276L);
    // Exclude caret row highlighting
    excludeHighlights(pane);
    container.run(1286796912276L);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:JavaViewHierarchyRandomTest.java

示例13: getMostRecentEditorCookie

import javax.swing.JEditorPane; //导入方法依赖的package包/类
private EditorCookie getMostRecentEditorCookie() {
    JEditorPane editor = getMostRecentEditor();
    if (editor != null) {
        Document document = editor.getDocument();
        DataObject dataObject = NbEditorUtilities.getDataObject(document);
        if (dataObject != null) {
            EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class);
            return ec;
        }
    }
    return null;

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:EditorContextDispatcher.java

示例14: testUndoRedoSimple

import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testUndoRedoSimple() throws Exception {
    loggingOn();
    RandomTestContainer container = createContainer();
    JEditorPane pane = container.getInstance(JEditorPane.class);
    Document doc = pane.getDocument();
    doc.putProperty("mimeType", "text/plain");
    ViewHierarchyRandomTesting.initRandomText(container);
    RandomTestContainer.Context context = container.context();
    DocumentTesting.insert(context, 0, "ab\nglanm\nq\n        \nv  nyk\n    \ndy qucjfn\tfh cdk \t\t \nj\nsm\n t\ngqa \nsjj\n\n\n");
    EditorPaneTesting.setCaretOffset(context, 38);
    EditorPaneTesting.moveCaret(context, 31);
    EditorPaneTesting.moveOrSelect(context, SwingConstants.EAST, true);
    EditorPaneTesting.moveOrSelect(context, SwingConstants.EAST, false);
    EditorPaneTesting.typeChar(context, 'j'); // #1: INSERT: off=38 len=1 "j"
    EditorPaneTesting.moveOrSelect(context, SwingConstants.NORTH, false);
    EditorPaneTesting.moveOrSelect(context, SwingConstants.NORTH, false);
    EditorPaneTesting.moveOrSelect(context, SwingConstants.WEST, false);
    EditorPaneTesting.moveOrSelect(context, SwingConstants.SOUTH, false);
    EditorPaneTesting.moveOrSelect(context, SwingConstants.NORTH, true);
    EditorPaneTesting.moveOrSelect(context, SwingConstants.WEST, true);
    EditorPaneTesting.typeChar(context, 'q'); // #2: REMOVE: off=23 len=8; INSERT: off=23 len=1 text="q"
    EditorPaneTesting.moveOrSelect(context, SwingConstants.SOUTH, true);
    EditorPaneTesting.moveOrSelect(context, SwingConstants.WEST, false);
    EditorPaneTesting.performAction(context, pane, DefaultEditorKit.insertTabAction); // #3: INSERT: off=24 len=4 "    "
    // #3.replaceEdit(#2) => false (not replaced; added)
    EditorPaneTesting.moveOrSelect(context, SwingConstants.NORTH, true);
    DocumentTesting.undo(context, 1);
    // #3.undo() (AtomicCompoundEdit)
    EditorPaneTesting.moveOrSelect(context, SwingConstants.WEST, true);
    EditorPaneTesting.moveOrSelect(context, SwingConstants.EAST, false);
    EditorPaneTesting.moveOrSelect(context, SwingConstants.NORTH, true);
    EditorPaneTesting.moveOrSelect(context, SwingConstants.WEST, true);
    EditorPaneTesting.moveOrSelect(context, SwingConstants.SOUTH, false);
    EditorPaneTesting.moveOrSelect(context, SwingConstants.SOUTH, false);
    EditorPaneTesting.performAction(context, pane, DefaultEditorKit.insertTabAction); // #4: INSERT: off=28 len=1 " "
    // 
    DocumentTesting.undo(context, 1);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:JavaViewHierarchyRandomTest.java

示例15: testInsertTextWithNewlines

import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testInsertTextWithNewlines() throws Exception {
    loggingOn();
    RandomTestContainer container = createContainer();
    JEditorPane pane = container.getInstance(JEditorPane.class);
    Document doc = pane.getDocument();
    doc.putProperty("mimeType", "text/plain");
    RandomTestContainer.Context context = container.context();
    DocumentTesting.insert(context, 0, "a\n");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:JavaViewHierarchyRandomTest.java


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