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


Java JEditorPane.setDocument方法代码示例

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


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

示例1: getToolTip

import javax.swing.JEditorPane; //导入方法依赖的package包/类
@Override
public JComponent getToolTip(double x, double y, Shape allocation) {
    Container container = getContainer();
    if (container instanceof JEditorPane) {
        JEditorPane editorPane = (JEditorPane) getContainer();
        JEditorPane tooltipPane = new JEditorPane();
        EditorKit kit = editorPane.getEditorKit();
        Document doc = getDocument();
        if (kit != null && doc != null) {
            Element lineRootElement = doc.getDefaultRootElement();
            tooltipPane.putClientProperty(FoldViewFactory.DISPLAY_ALL_FOLDS_EXPANDED_PROPERTY, true);
            try {
                // Start-offset of the fold => line start => position
                int lineIndex = lineRootElement.getElementIndex(fold.getStartOffset());
                Position pos = doc.createPosition(
                        lineRootElement.getElement(lineIndex).getStartOffset());
                // DocumentView.START_POSITION_PROPERTY
                tooltipPane.putClientProperty("document-view-start-position", pos); // NOI18N
                // End-offset of the fold => line end => position
                lineIndex = lineRootElement.getElementIndex(fold.getEndOffset());
                pos = doc.createPosition(lineRootElement.getElement(lineIndex).getEndOffset());
                // DocumentView.END_POSITION_PROPERTY
                tooltipPane.putClientProperty("document-view-end-position", pos); // NOI18N
                tooltipPane.putClientProperty("document-view-accurate-span", true); // NOI18N
                // Set the same kit and document
                tooltipPane.setEditorKit(kit);
                tooltipPane.setDocument(doc);
                tooltipPane.setEditable(false);
                return new FoldToolTip(editorPane, tooltipPane, getBorderColor());
            } catch (BadLocationException e) {
                // => return null
            }
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:FoldView.java

示例2: FlickrSettingsPanel

import javax.swing.JEditorPane; //导入方法依赖的package包/类
public FlickrSettingsPanel()
{
	apiKey = new JTextField();
	apiSharedSecret = new JTextField();

	// Yuck, this seems to be the minimal amount of code to get a clickable
	// and styled link
	// (copied from the Cron link in the scheduler)
	JEditorPane apiKeyHelp = new JEditorPane();
	apiKeyHelp.setEditorKit(new HTMLEditorKit());
	apiKeyHelp.setDocument(new HTMLDocument());
	apiKeyHelp.setEditable(false);
	apiKeyHelp.setText("<html><head><style>" + "<!--a{color:#0000cc;text-decoration: none;}//--></style></head>"
		+ "<body>" + getString("settings.label.apikeyhelp"));
	apiKeyHelp.addHyperlinkListener(new HyperlinkListener()
	{
		@Override
		public void hyperlinkUpdate(HyperlinkEvent e)
		{
			if( e.getEventType() == HyperlinkEvent.EventType.ACTIVATED )
			{
				getClientService().showDocument(e.getURL(), null);
			}
		}
	});
	apiKeyHelp.setBackground(new JPanel().getBackground());

	add(apiKeyHelp, "span 2");

	add(new JLabel(getString("settings.label.apikey")));
	add(apiKey);
	add(new JLabel(getString("settings.label.apisharedsecret")));
	add(apiSharedSecret);
}
 
开发者ID:equella,项目名称:Equella,代码行数:35,代码来源:FlickrSettingsPanel.java

示例3: testToolTipView

import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testToolTipView() throws Exception {
        loggingOn();
        RandomTestContainer container = createContainer();
        final JEditorPane pane = container.getInstance(JEditorPane.class);
        final Document doc = pane.getDocument();
        doc.putProperty("mimeType", "text/plain");
        RandomTestContainer.Context context = container.context();
//        ViewHierarchyRandomTesting.disableHighlighting(container);
        DocumentTesting.setSameThreadInvoke(context, true); // Do not post to EDT
        DocumentTesting.insert(context, 0, "abc\ndef\nghi\n");
        final JEditorPane[] toolTipPaneRef = new JEditorPane[1];
        final BadLocationException[] excRef = new BadLocationException[1];
        final JFrame[] toolTipFrameRef = new JFrame[1];
        Runnable tooltipRun = new Runnable() {
            @Override
            public void run() {
                JEditorPane toolTipPane = new JEditorPane();
                toolTipPaneRef[0] = toolTipPane;
                toolTipPane.setEditorKit(pane.getEditorKit());
                try {
                    Position startPos = doc.createPosition(4); // Line begining
                    Position endPos = doc.createPosition(8); // Line boundary too
                    toolTipPane.putClientProperty("document-view-start-position", startPos);
                    toolTipPane.putClientProperty("document-view-end-position", endPos);
                    toolTipPane.setDocument(doc);
                    JFrame toolTipFrame = new JFrame("ToolTip Frame");
                    toolTipFrameRef[0] = toolTipFrame;
                    toolTipFrame.getContentPane().add(new JScrollPane(toolTipPane));
                    toolTipFrame.setSize(100, 100);
                    toolTipFrame.setVisible(true);

                    doc.insertString(4, "o", null);
                    toolTipPane.setFont(new Font("Monospaced", Font.PLAIN, 22)); // Force VH rebuild
                    toolTipPane.modelToView(6);
                    doc.remove(3, 3);
                    doc.insertString(4, "ab", null);
                    
                    assert (endPos.getOffset() == 8);
                    doc.remove(7, 2);
                    toolTipPane.setFont(new Font("Monospaced", Font.PLAIN, 23)); // Force VH rebuild
                    toolTipPane.modelToView(6);

                } catch (BadLocationException ex) {
                    excRef[0] = ex;
                }

            }
        };
        SwingUtilities.invokeAndWait(tooltipRun);
        if (excRef[0] != null) {
            throw new IllegalStateException(excRef[0]);
        }

        DocumentTesting.setSameThreadInvoke(context, false);
        DocumentTesting.undo(context, 2);
        DocumentTesting.undo(context, 1);
        DocumentTesting.undo(context, 1);
        DocumentTesting.redo(context, 4);
        
        // Hide tooltip's frame
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                if (toolTipFrameRef[0] != null) {
                    toolTipFrameRef[0].setVisible(false);
                }
            }
        });
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:70,代码来源:JavaViewHierarchyRandomTest.java

示例4: testRandomModsPlainText

import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testRandomModsPlainText() throws Exception {
        loggingOn();
        RandomTestContainer container = createContainer();
        final JEditorPane pane = container.getInstance(JEditorPane.class);
        final Document doc = pane.getDocument();
        doc.putProperty("mimeType", "text/plain");
        ViewHierarchyRandomTesting.initRandomText(container);
        ViewHierarchyRandomTesting.addRound(container).setOpCount(OP_COUNT);
        ViewHierarchyRandomTesting.testFixedScenarios(container);
        container.run(1271950385168L); // Failed at op=750
//        container.run(1270806278503L);
//        container.run(1270806786819L);
//        container.run(1270806387223L);
//        container.run(1271372510390L);

//        RandomTestContainer.Context context = container.context();
//        DocumentTesting.undo(context, 2);
//        DocumentTesting.redo(context, 2);
        // Simulate tooltip pane
        final JEditorPane[] toolTipPaneRef = new JEditorPane[1];
        final BadLocationException[] excRef = new BadLocationException[1];
        final JFrame[] toolTipFrameRef = new JFrame[1];
        Runnable tooltipRun = new Runnable() {
            @Override
            public void run() {
                JEditorPane toolTipPane = new JEditorPane();
                toolTipPaneRef[0] = toolTipPane;
                toolTipPane.setEditorKit(pane.getEditorKit());
                try {
                    toolTipPane.putClientProperty("document-view-start-position", doc.createPosition(4));
                    toolTipPane.putClientProperty("document-view-end-position", doc.createPosition(20));
                } catch (BadLocationException ex) {
                    excRef[0] = ex;
                }
                toolTipPane.setDocument(doc);
                JFrame toolTipFrame = new JFrame("ToolTip Frame");
                toolTipFrameRef[0] = toolTipFrame;
                toolTipFrame.getContentPane().add(new JScrollPane(toolTipPane));
                toolTipFrame.setSize(100, 100);
                toolTipFrame.setVisible(true);
            }
        };
        SwingUtilities.invokeAndWait(tooltipRun);
        if (excRef[0] != null) {
            throw new IllegalStateException(excRef[0]);
        }

        container.run(0L); // Test random ops
        // Exclude caret row highlighting
        excludeHighlights(pane);
        container.run(0L); // Re-run test

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                if (toolTipFrameRef[0] != null) {
                    toolTipFrameRef[0].setVisible(false);
                }
            }
        });
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:62,代码来源:JavaViewHierarchyRandomTest.java

示例5: testRandomModsJava

import javax.swing.JEditorPane; //导入方法依赖的package包/类
public void testRandomModsJava() throws Exception {
    RandomTestContainer container = createContainer();
    final JEditorPane pane = container.getInstance(JEditorPane.class);
    final 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);
    loggingOn();
    container.setLogOp(true);
    DocumentTesting.setLogDoc(container, true);
    ViewHierarchyRandomTesting.testFixedScenarios(container);
    assert (Logger.getLogger("org.netbeans.editor.view.check").isLoggable(Level.FINEST));
    Logger.getLogger("org.netbeans.editor.view.build").setLevel(Level.FINE);
    container.runInit(1271946202898L);
    container.runOps(0);
    
    // Simulate tooltip pane
    final JEditorPane[] toolTipPaneRef = new JEditorPane[1];
    final BadLocationException[] excRef = new BadLocationException[1];
    final JFrame[] toolTipFrameRef = new JFrame[1];
    Runnable tooltipRun = new Runnable() {
        @Override
        public void run() {
            JEditorPane toolTipPane = new JEditorPane();
            toolTipPaneRef[0] = toolTipPane;
            toolTipPane.setEditorKit(pane.getEditorKit());
            try {
                toolTipPane.putClientProperty("document-view-start-position", doc.createPosition(4));
                toolTipPane.putClientProperty("document-view-end-position", doc.createPosition(20));
            } catch (BadLocationException ex) {
                excRef[0] = ex;
            }
            toolTipPane.setDocument(doc);
            JFrame toolTipFrame = new JFrame("ToolTip Frame");
            toolTipFrameRef[0] = toolTipFrame;
            toolTipFrame.getContentPane().add(new JScrollPane(toolTipPane));
            toolTipFrame.setSize(100, 100);
            toolTipFrame.setVisible(true);
        }
    };
    SwingUtilities.invokeAndWait(tooltipRun);
    if (excRef[0] != null) {
        throw new IllegalStateException(excRef[0]);
    }

    
    container.run(1290550667174L);
    container.run(0L); // Test random ops
    // Exclude caret row highlighting
    excludeHighlights(pane);
    container.run(0L); // Re-run test

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            if (toolTipFrameRef[0] != null) {
                toolTipFrameRef[0].setVisible(false);
            }
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:63,代码来源:JavaViewHierarchyRandomTest.java

示例6: performTest

import javax.swing.JEditorPane; //导入方法依赖的package包/类
protected void performTest(String source, int caretPos, String textToInsert, String toPerformItemRE, String goldenFileName, String sourceLevel) throws Exception {
    this.sourceLevel.set(sourceLevel);
    File testSource = new File(getWorkDir(), "test/Test.java");
    testSource.getParentFile().mkdirs();
    copyToWorkDir(new File(getDataDir(), "org/netbeans/modules/java/editor/completion/data/" + source + ".java"), testSource);
    FileObject testSourceFO = FileUtil.toFileObject(testSource);
    assertNotNull(testSourceFO);
    DataObject testSourceDO = DataObject.find(testSourceFO);
    assertNotNull(testSourceDO);
    EditorCookie ec = (EditorCookie) testSourceDO.getCookie(EditorCookie.class);
    assertNotNull(ec);
    final Document doc = ec.openDocument();
    assertNotNull(doc);
    doc.putProperty(Language.class, JavaTokenId.language());
    doc.putProperty("mimeType", "text/x-java");
    int textToInsertLength = textToInsert != null ? textToInsert.length() : 0;
    if (textToInsertLength > 0)
        doc.insertString(caretPos, textToInsert, null);
    Source s = Source.create(doc);
    List<? extends CompletionItem> items = JavaCompletionProvider.query(s, CompletionProvider.COMPLETION_QUERY_TYPE, caretPos + textToInsertLength, caretPos + textToInsertLength);
    Collections.sort(items, CompletionItemComparator.BY_PRIORITY);
    
    String version = System.getProperty("java.specification.version") + "/";
    
    assertNotNull(goldenFileName);            

    Pattern p = Pattern.compile(toPerformItemRE);
    CompletionItem item = null;            
    for (CompletionItem i : items) {
        if (p.matcher(i.toString()).find()) {
            item = i;
            break;
        }
    }            
    assertNotNull(item);

    JEditorPane editor = new JEditorPane();
    editor.setDocument(doc);
    editor.setCaretPosition(caretPos + textToInsertLength);
    item.defaultAction(editor);

    File output = new File(getWorkDir(), getName() + ".out2");
    Writer out = new FileWriter(output);            
    out.write(doc.getText(0, doc.getLength()));
    out.close();

    File goldenFile = new File(getDataDir(), "/goldenfiles/org/netbeans/modules/java/editor/completion/JavaCompletionProviderTest/" + version + goldenFileName);
    File diffFile = new File(getWorkDir(), getName() + ".diff");

    assertFile(output, goldenFile, diffFile, new WhitespaceIgnoringDiff());
    
    LifecycleManager.getDefault().saveAll();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:54,代码来源:CompletionTestBase.java

示例7: EditorPaneDemo

import javax.swing.JEditorPane; //导入方法依赖的package包/类
public EditorPaneDemo(Language language, boolean maintainLookbacks,
String initialContent) {

    super(new PlainDocument(), language, maintainLookbacks);
    
    JFrame frame = new JFrame();
    frame.addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent evt) {
            System.exit(0);
        }
    });

    frame.setTitle("Test of " + splitClassName(language.getClass().getName())[1]
        + " - Use Ctrl+L to dump tokens");

    JEditorPane jep = new JEditorPane();
    
    Document doc = getDocument();
    jep.setDocument(doc);
    // Insert initial content string
    try {
        if (initialContent != null) {
            doc.insertString(0, initialContent, null);
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
        return;
    }
    
    // Initially debug token changes
    setDebugTokenChanges(true);

    frame.getContentPane().add(jep);
    
    DumpAction da = new DumpAction();
    jep.registerKeyboardAction(da,
        KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_MASK), 0);
    
    DebugTokenChangesAction dtca = new DebugTokenChangesAction();
    jep.registerKeyboardAction(dtca,
        KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.CTRL_MASK), 0);
    
    
    System.err.println("NOTE: Press Ctrl+L to dump the document's token list.\n");
    System.err.println("      Press Ctrl+T to toggle debugging of token changes.\n");
    
    // Debug initially
    dump();

    frame.setSize(400, 300);
    frame.setVisible(true);
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:54,代码来源:EditorPaneDemo.java


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