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


Java JEditorPane类代码示例

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


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

示例1: testPerform

import javax.swing.JEditorPane; //导入依赖的package包/类
/**Currently, this method is supposed to be runned inside the AWT thread.
 * If this condition is not fullfilled, an IllegalStateException is
 * thrown. Do NOT modify this behaviour, or deadlock (or even Swing
 * or NetBeans winsys data corruption) may occur.
 *
 * Currently threading model of this method is compatible with
 * editor code completion threading model. Revise if this changes
 * in future.
 */
private void testPerform(PrintWriter out, PrintWriter log,
        JEditorPane editor,
        boolean unsorted,
        String assign,
        int lineIndex,
        int queryType) throws BadLocationException, IOException {
    if (!SwingUtilities.isEventDispatchThread())
        throw new IllegalStateException("The testPerform method may be called only inside AWT event dispatch thread.");
    
    BaseDocument doc        = Utilities.getDocument(editor);
    int          lineOffset = Utilities.getRowStartFromLineOffset(doc, lineIndex -1);
    
    editor.grabFocus();
    editor.getCaret().setDot(lineOffset);
    doc.insertString(lineOffset, assign, null);
    reparseDocument((DataObject) doc.getProperty(doc.StreamDescriptionProperty));
    completionQuery(out, log, editor, unsorted, queryType);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:CompletionTestCase.java

示例2: setupContext

import javax.swing.JEditorPane; //导入依赖的package包/类
private static void setupContext(final JEditorPane editorPane, Pair<Line.Part, FileObject> context) {
    assert SwingUtilities.isEventDispatchThread();
    if (context != null) {
        final Line.Part lp = context.first();
        final FileObject file = context.second();
        //System.err.println("WatchPanel.setupContext("+file+", "+line+", "+offset+")");
        // Do the binding for text files only:
        if (file != null && file.getMIMEType().startsWith("text/")) { // NOI18N
            String origText = editorPane.getText();
            DialogBinding.bindComponentToFile(file,
                                              lp.getLine().getLineNumber(),
                                              lp.getColumn(),
                                              lp.getLength(),
                                              editorPane);
            Document editPaneDoc = editorPane.getDocument();
            //editPaneDoc.putProperty("org.netbeans.modules.editor.java.JavaCompletionProvider.skipAccessibilityCheck", "true");
            editorPane.setText(origText);
        }
    }
    setupUI(editorPane);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:EditorContextSetter.java

示例3: getTextComponent

import javax.swing.JEditorPane; //导入依赖的package包/类
protected JTextComponent getTextComponent(URL url) {
    FileObject f = org.openide.filesystems.URLMapper.findFileObject(url);
    
    if (f != null) {
        DataObject d = null;
        
        try {
            d = DataObject.find(f);
        } catch (DataObjectNotFoundException e) {
            LOG.log(Level.WARNING, "Can't get DataObject for " + f, e); //NOI18N
        }
        
        if (d != null) {
            EditorCookie cookie = d.getLookup().lookup(EditorCookie.class);
            if (cookie != null) {
                JEditorPane [] allJeps = cookie.getOpenedPanes();
                if (allJeps != null) {
                    return allJeps[0];
                }
            }
        }
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:NbURLMapper.java

示例4: testInsertRemoveTransaction

import javax.swing.JEditorPane; //导入依赖的package包/类
public void testInsertRemoveTransaction() throws Exception {
        loggingOn();
        RandomTestContainer container = createContainer();
        JEditorPane pane = container.getInstance(JEditorPane.class);
        final Document doc = pane.getDocument();
        doc.putProperty("mimeType", "text/plain");
        final RandomTestContainer.Context context = container.context();
//        ViewHierarchyRandomTesting.disableHighlighting(container);
        DocumentTesting.setSameThreadInvoke(container.context(), true); // Do not post to EDT
        ((BaseDocument)doc).runAtomic(new Runnable() {
            @Override
            public void run() {
                try {
                    for (int i = 0; i < 100; i++) {
                        DocumentTesting.insert(context, 0, "a\nb\n\n");
                        DocumentTesting.remove(context, i * 3, 1);
                    }
                } catch (Exception ex) {
                    throw new IllegalStateException(ex);
                }
            }
        });
        DocumentTesting.setSameThreadInvoke(container.context(), false);
        DocumentTesting.undo(context, 1);
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:JavaViewHierarchyRandomTest.java

示例5: testWrapperAction

import javax.swing.JEditorPane; //导入依赖的package包/类
@Test
public void testWrapperAction() {
    Map attrs = new HashMap(SIMPLE_ATTRS);
    attrs.put(AbstractEditorAction.WRAPPER_ACTION_KEY, true);
    final MyAction a = new MyAction(); // No attrs passed
    attrs.put("delegate", a);
    WrapperEditorAction wrapperAction = WrapperEditorAction.create(attrs);
    JTextComponent c = new JEditorPane();
    assertEquals("my-name", wrapperAction.getValue(Action.NAME));
    assertNull(a.getValue(Action.NAME));
    
    ActionEvent evt = new ActionEvent(c, 0, "");
    wrapperAction.actionPerformed(evt);
    assertEquals(Thread.currentThread(), a.actionPerformedThread);

    // Properties transferred
    assertEquals("my-name", a.getValue(Action.NAME));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:AbstractEditorActionTest.java

示例6: isExcludedProperty1

import javax.swing.JEditorPane; //导入依赖的package包/类
private boolean isExcludedProperty1(FormProperty prop) {
    if (!Boolean.TRUE.equals(prop.getValue(EXCLUSION_DETERMINED))) {
        prop.setValue(EXCLUSION_DETERMINED, true);
        Object propOwner = prop.getPropertyContext().getOwner();
        Class type = null;
        if (propOwner instanceof RADComponent) {
            type = ((RADComponent)propOwner).getBeanClass();
        } else if (propOwner instanceof FormProperty) {
            type = ((FormProperty)propOwner).getValueType();
        }
        String propName = prop.getName();
        boolean excl = (Component.class.isAssignableFrom(type) && "name".equals(propName)) // NOI18N
                || (JEditorPane.class.isAssignableFrom(type) && "contentType".equals(propName)); // NOI18N
        prop.setValue(EXCLUDE_FROM_RESOURCING, excl);
        return excl;
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ResourceSupport.java

示例7: performContextAction

import javax.swing.JEditorPane; //导入依赖的package包/类
@Override
protected void performContextAction(Node[] nodes) {
    if (visible(nodes)) {
        JEditorPane pane = activatedEditorPane(nodes);
        AnnotationBarManager.hideAnnotationBar(pane);
    } else {
        EditorCookie ec = activatedEditorCookie(nodes);
        if (ec == null) return;

        final File file = activatedFile(nodes);

        JEditorPane[] panes = ec.getOpenedPanes();
        if (panes == null) {
            ec.open();
            panes = ec.getOpenedPanes();
        }

        if (panes == null) {
            return;
        }
        final JEditorPane currentPane = panes[0];
        showAnnotations(currentPane, file, null, true);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:AnnotateAction.java

示例8: getCaretPos

import javax.swing.JEditorPane; //导入依赖的package包/类
private static int getCaretPos(FoldHierarchy h) {
    int caretPos = -1;
    JTextComponent c = h.getComponent();
    if (c == null) {
        return -1;
    }
    Document doc = getDocument(h);
    Object od = doc.getProperty(Document.StreamDescriptionProperty);
    if (od instanceof DataObject) {
        DataObject d = (DataObject)od;
        EditorCookie cake = d.getCookie(EditorCookie.class);
        JEditorPane[] panes = cake.getOpenedPanes();
        int idx = panes == null ? -1 : Arrays.asList(panes).indexOf(c);
        if (idx != -1) {
            caretPos = c.getCaret().getDot();
        }
    }
    return caretPos;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:ParsingFoldSupport.java

示例9: getEditorPane

import javax.swing.JEditorPane; //导入依赖的package包/类
/** Returns editor pane. Returns null if document loading was canceled by user
 * through answering UserQuestionException or when CloneableEditor is closed.
 *
 * @return editor pane or null
 */
public JEditorPane getEditorPane() {
    assert SwingUtilities.isEventDispatchThread();
    //User selected not to load document
    if (!componentCreated) {
        return null;
    }
    //#175528: This case should not happen as modal dialog handling UQE should
    //not be displayed during IDE start ie. during component deserialization.
    if (CloneableEditorInitializer.modalDialog) {
        LOG.log(Level.WARNING,"AWT is blocked by modal dialog. Return null from CloneableEditor.getEditorPane."
        + " Please report this to IZ.");
        LOG.log(Level.WARNING,"support:" + support.getClass().getName());
        Exception ex = new Exception();
        StringWriter sw = new StringWriter(500);
        PrintWriter pw = new PrintWriter(sw);
        ex.printStackTrace(pw);
        LOG.log(Level.WARNING,sw.toString());
        return null;
    }

    initialize();

    CloneableEditorInitializer.waitForFinishedInitialization(this);
    return pane;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:CloneableEditor.java

示例10: actionPerformed

import javax.swing.JEditorPane; //导入依赖的package包/类
/**
 * Sets the foreground color.
 *
 * @param e the action event
 */
public void actionPerformed(ActionEvent e) {
    JEditorPane editor = getEditor(e);
    if (editor != null) {
        Color fg = this.fg;
        if ((e != null) && (e.getSource() == editor)) {
            String s = e.getActionCommand();
            try {
                fg = Color.decode(s);
            } catch (NumberFormatException nfe) {
            }
        }
        if (fg != null) {
            MutableAttributeSet attr = new SimpleAttributeSet();
            StyleConstants.setForeground(attr, fg);
            setCharacterAttributes(editor, attr, false);
        } else {
            UIManager.getLookAndFeel().provideErrorFeedback(editor);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:StyledEditorKit.java

示例11: getTextIndex

import javax.swing.JEditorPane; //导入依赖的package包/类
public int getTextIndex() {
    return EventQueueWait.exec(new Callable<Integer>() {
        @Override public Integer call() throws Exception {
            String href = getText();
            int hRefIndex = 0;
            int current = 0;
            JEditorPane editor = (JEditorPane) parent.getComponent();
            HTMLDocument document = (HTMLDocument) editor.getDocument();
            Iterator iterator = document.getIterator(Tag.A);
            while (iterator.isValid()) {
                if (current++ >= index) {
                    return hRefIndex;
                }
                String attribute = ((HTMLDocument) ((JEditorPane) parent.getComponent()).getDocument())
                        .getText(iterator.getStartOffset(), iterator.getEndOffset() - iterator.getStartOffset());
                if (attribute != null && attribute.equals(href)) {
                    hRefIndex++;
                }
                iterator.next();
            }
            return -1;
        }
    });
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:25,代码来源:JEditorPaneTagJavaElement.java

示例12: testFormatterDoesNotIncludeHashOnEditor

import javax.swing.JEditorPane; //导入依赖的package包/类
public void testFormatterDoesNotIncludeHashOnEditor() throws ClassNotFoundException {
    LogRecord r = new LogRecord(Level.INFO, "EDIT");
    JEditorPane ep = new javax.swing.JEditorPane();
    ep.setName("SomeName");
    r.setParameters(new Object[] { ep });
    Formatter formatter = new LogFormatter();
    String s = formatter.format(r);
    assertEquals("No @\n" + s, -1, s.indexOf("@"));
    if (s.indexOf("SomeName") == -1) {
        fail("SomeName should be there:\n" + s);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:LogFormatterTest.java

示例13: canDrop

import javax.swing.JEditorPane; //导入依赖的package包/类
@Override
public boolean canDrop(DropTargetDragEvent e) {
    //check if the JEditorPane contains html document
    JEditorPane pane = findPane(e.getDropTargetContext().getComponent());
    if (pane == null) {
        return false;
    }
    int offset = getLineEndOffset(pane, e.getLocation());
    if (!containsLanguageAtOffset(pane.getDocument(), offset)) {
        return false;
    } else {
        //update the caret as the user drags the object
        //needs to be done explicitly here as QuietEditorPane doesn't call
        //the original Swings DropTarget which does this
        pane.setCaretPosition(offset);

        pane.requestFocusInWindow(); //pity we need to call this all the time when dragging, but  ExternalDropHandler don't handle dragEnter event

        return canDrop(e.getCurrentDataFlavors());
    }

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

示例14: testExceptionThrownWhenDocumentIsBeingReadNo

import javax.swing.JEditorPane; //导入依赖的package包/类
public void testExceptionThrownWhenDocumentIsBeingReadNo () throws Exception {
    MyEx my = new MyEx();

    toThrow = my;

    DD.options = null;
    DD.toReturn = NotifyDescriptor.NO_OPTION;
    
    support.open ();
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            JEditorPane[] panes = support.getOpenedPanes();
            assertNull(panes);
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:CloneableEditorUserQuestionAsync2Test.java

示例15: testInitializeAndBlockInAWT

import javax.swing.JEditorPane; //导入依赖的package包/类
public void testInitializeAndBlockInAWT() throws Exception {
    assertTrue("Running in AWT", SwingUtilities.isEventDispatchThread());
    
    class R implements PropertyChangeListener {
        JEditorPane p;
        public void run() {
            p = support.getOpenedPanes()[0];
        }

        public void propertyChange(PropertyChangeEvent evt) {
            if (TopComponent.Registry.PROP_ACTIVATED.equals(evt.getPropertyName())) {
                run();
            }
        }
    }
    R r = new R();
    WindowManager.getDefault().getRegistry().addPropertyChangeListener(r);
    
    final Object LOCK = new JPanel().getTreeLock();
    synchronized (LOCK) {
        support.open();
        assertNotNull(r.p);
    }
    
    assertKit(r.p.getEditorKit());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:InitializeInAWTTest.java


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