當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。