Java 类javax.swing.text.html.HTMLDocument 实例源码

项目:Neukoelln_SER316    文件:EditorPanel.java   
public void setDocument(Note note) {
    // Note note = CurrentProject.getNoteList().getActiveNote();
    // try {
    // this.editor.editor.setPage(CurrentStorage.get().getNoteURL(note));
    editor.document = (HTMLDocument) CurrentStorage.get().openNote(note);
    editor.initEditor();
    if (note != null)
        titleField.setText(note.getTitle());
    else
        titleField.setText("");
    initialTitle = titleField.getText();
    /*
     * } catch (Exception ex) { new ExceptionDialog(ex); }
     */
    /*
     * Document doc = CurrentStorage.get().openNote(note); try {
     * this.editor.editor.setText(doc.getText(0, doc.getLength())); } catch
     * (Exception ex){ ex.printStackTrace(); }
     */
    // .setDocument(CurrentStorage.get().openNote(note));
}
项目:jdk8u-jdk    文件:bug8058120.java   
private static void createAndShowGUI() {
    try {
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    JFrame frame = new JFrame("bug8058120");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JEditorPane editorPane = new JEditorPane();
    editorPane.setContentType("text/html");
    editorPane.setEditorKit(new HTMLEditorKit());

    document = (HTMLDocument) editorPane.getDocument();

    editorPane.setText(text);

    frame.add(editorPane);
    frame.setSize(200, 200);
    frame.setVisible(true);
}
项目:Dahlem_SER316    文件:FileStorage.java   
public javax.swing.text.Document openPSP(PSP psp) {

        HTMLDocument doc = (HTMLDocument) editorKit.createDefaultDocument();
        if (psp == null)
            return doc;
        String filename = getPSPPath(psp);
        try {
            /*DEBUG*/

//            Util.debug("Open note: " + filename);
//          Util.debug("Note Title: " + note.getTitle());
            doc.setBase(new URL(getPSPURL(psp)));
            editorKit.read(
                new InputStreamReader(new FileInputStream(filename), "UTF-8"),
                doc,
                0);
        }
        catch (Exception ex) {
            //ex.printStackTrace();
            // Do nothing - we've got a new empty document!
        }

        return doc;
    }
项目:incubator-netbeans    文件:SvnOptionsPanel.java   
/** Creates new form SvnOptionsPanel */
public SvnOptionsPanel() {
    initComponents();
    if(Utilities.isWindows()) {
        jLabel5.setText(org.openide.util.NbBundle.getMessage(SvnOptionsPanel.class, "SvnOptionsPanel.jLabel5.windows.text"));
        jLabel11.setText(org.openide.util.NbBundle.getMessage(SvnOptionsPanel.class, "SvnOptionsPanel.jLabel11.text"));
    } else {
        jLabel5.setText(org.openide.util.NbBundle.getMessage(SvnOptionsPanel.class, "SvnOptionsPanel.jLabel5.unix.text"));
        jLabel11.setText(org.openide.util.NbBundle.getMessage(SvnOptionsPanel.class, "SvnOptionsPanel.jLabel11.unix.text"));
    }
    Document doc = textPaneClient.getDocument();
    if (doc instanceof HTMLDocument) { // Issue 185505
        HTMLDocument htmlDoc = (HTMLDocument)doc;
        Font font = UIManager.getFont("Label.font"); // NOI18N
        String bodyRule = "body { font-family: " + font.getFamily() + "; " // NOI18N
            + "color: " + SvnUtils.getColorString(textPaneClient.getForeground()) + "; " //NOI18N
            + "font-size: " + font.getSize() + "pt; }"; // NOI18N
        htmlDoc.getStyleSheet().addRule(bodyRule);
    }
    textPaneClient.setOpaque(false);
    textPaneClient.setBackground(new Color(0,0,0,0)); // windows and nimbus workaround see issue 145826
}
项目:openjdk-jdk10    文件:bug8058120.java   
private static void createAndShowGUI() {
    try {
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    JFrame frame = new JFrame("bug8058120");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JEditorPane editorPane = new JEditorPane();
    editorPane.setContentType("text/html");
    editorPane.setEditorKit(new HTMLEditorKit());

    document = (HTMLDocument) editorPane.getDocument();

    editorPane.setText(text);

    frame.add(editorPane);
    frame.setSize(200, 200);
    frame.setVisible(true);
}
项目:SER316-Aachen    文件:EditorPanel.java   
public void setDocument(Note note) {
    // Note note = CurrentProject.getNoteList().getActiveNote();
    // try {
    // this.editor.editor.setPage(CurrentStorage.get().getNoteURL(note));
    editor.document = (HTMLDocument) CurrentStorage.get().openNote(note);
    editor.initEditor();
    if (note != null)
        titleField.setText(note.getTitle());
    else
        titleField.setText("");
    initialTitle = titleField.getText();
    /*
     * } catch (Exception ex) { new ExceptionDialog(ex); }
     */
    /*
     * Document doc = CurrentStorage.get().openNote(note); try {
     * this.editor.editor.setText(doc.getText(0, doc.getLength())); } catch
     * (Exception ex){ ex.printStackTrace(); }
     */
    // .setDocument(CurrentStorage.get().openNote(note));
}
项目:jdk8u-jdk    文件:bug8028616.java   
public static void main(String[] args) throws Exception {
    ParserCB cb = new ParserCB();
    HTMLEditorKit htmlKit = new HTMLEditorKit();
    HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();

    htmlDoc.getParser().parse(new StringReader(text), cb, true);

    synchronized (lock) {
        if (!isCallbackInvoked) {
            lock.wait(5000);
        }
    }

    if (!isCallbackInvoked) {
        throw new RuntimeException("Test Failed: ParserCallback.handleText() is not invoked for text - " + text);
    }

    if (exception != null) {
        throw exception;
    }
}
项目:incubator-netbeans    文件:DocumentationScrollPane.java   
private synchronized void setDocumentation(CompletionDocumentation doc) {
    currentDocumentation = doc;
    if (currentDocumentation != null) {
        String text = currentDocumentation.getText();
        URL url = currentDocumentation.getURL();
        if (text != null){
            Document document = view.getDocument();
            document.putProperty(Document.StreamDescriptionProperty, null);
            if (url!=null){
                // fix of issue #58658
                if (document instanceof HTMLDocument){
                    ((HTMLDocument)document).setBase(url);
                }
            }
            view.setContent(text, url != null ? url.getRef() : null);
        } else if (url != null){
            try{
                view.setPage(url);
            }catch(IOException ioe){
                StatusDisplayer.getDefault().setStatusText(ioe.toString());
            }
        }
        bShowWeb.setEnabled(url != null);
        bGoToSource.setEnabled(currentDocumentation.getGotoSourceAction() != null);
    }
}
项目:incubator-netbeans    文件:OverviewControllerUI.java   
public void showInThreads(Instance instance) {
    if (!showThreads) {
        showThreads = true;
        instanceToSelect = instance;
        refreshSummary();
        return;
    }
    String referenceId = String.valueOf(instance.getInstanceId());

    dataArea.scrollToReference(referenceId);
    Document d = dataArea.getDocument();
    HTMLDocument doc = (HTMLDocument) d;
    HTMLDocument.Iterator iter = doc.getIterator(HTML.Tag.A);
    for (; iter.isValid(); iter.next()) {
        AttributeSet a = iter.getAttributes();
        String nm = (String) a.getAttribute(HTML.Attribute.NAME);
        if ((nm != null) && nm.equals(referenceId)) {
            dataArea.select(iter.getStartOffset(),iter.getEndOffset());
            dataArea.requestFocusInWindow();
        }
    }
}
项目:rapidminer    文件:AnnotationsDecorator.java   
/**
 * Calculates the preferred height of the editor pane with the given fixed width.
 *
 * @param width
 *            the width of the pane
 * @return the preferred height given the current editor pane content or {@code -1} if there was
 *         a problem. Value will never exceed {@link WorkflowAnnotation#MAX_HEIGHT}
 */
private int getContentHeightOfEditor(final int width) {
    HTMLDocument document = (HTMLDocument) editPane.getDocument();
    StringWriter writer = new StringWriter();
    try {
        editPane.getEditorKit().write(writer, document, 0, document.getLength());
    } catch (IndexOutOfBoundsException | IOException | BadLocationException e1) {
        // should not happen
        return -1;
    }
    String comment = writer.toString();
    comment = AnnotationDrawUtils.removeStyleFromComment(comment);

    int maxHeight = model.getSelected() instanceof ProcessAnnotation ? ProcessAnnotation.MAX_HEIGHT
            : OperatorAnnotation.MAX_HEIGHT;
    return Math.min(
            AnnotationDrawUtils.getContentHeight(
                    AnnotationDrawUtils.createStyledCommentString(comment, model.getSelected().getStyle()), width),
                    maxHeight);
}
项目:rapidminer    文件:AnnotationDrawUtils.java   
/**
 * Returns plain text from the editor.
 *
 * @param editor
 *            the editor from which to take the text.
 * @param onlySelected
 *            if {@code true} will only return the selected text
 * @return the text of the editor converted to plain text
 * @throws BadLocationException
 * @throws IOException
 */
public static String getPlaintextFromEditor(final JEditorPane editor, final boolean onlySelected) throws IOException,
        BadLocationException {
    if (editor == null) {
        throw new IllegalArgumentException("editor must not be null!");
    }
    HTMLDocument document = (HTMLDocument) editor.getDocument();
    StringWriter writer = new StringWriter();
    int start = 0;
    int length = document.getLength();
    if (onlySelected) {
        start = editor.getSelectionStart();
        length = editor.getSelectionEnd() - start;
    }
    editor.getEditorKit().write(writer, document, start, length);
    String text = writer.toString();
    text = AnnotationDrawUtils.removeStyleFromComment(text);
    // switch <br> and <br/> to actual newline (current system)
    text = text.replaceAll("<br.*?>", System.lineSeparator());
    // kill all other html tags
    text = text.replaceAll("\\<.*?>", "");
    text = StringEscapeUtils.unescapeHtml(text);
    return text;
}
项目:marathonv5    文件:JEditorPaneTagJavaElement.java   
@Override public String getAttribute(final String name) {
    if ("text".equals(name)) {
        return getText();
    }
    if ("hRefIndex".equals(name)) {
        return getHRefIndex() + "";
    }
    if ("textIndex".equals(name)) {
        return getTextIndex() + "";
    }
    return EventQueueWait.exec(new Callable<String>() {
        @Override public String call() throws Exception {
            Iterator iterator = findTag((HTMLDocument) ((JEditorPane) parent.getComponent()).getDocument());
            AttributeSet attributes = iterator.getAttributes();
            Attribute attr = findAttribute(name);
            if (attr != null && attributes.isDefined(attr)) {
                return attributes.getAttribute(attr).toString();
            }
            return null;
        }
    });
}
项目:openjdk-jdk10    文件:Test6933784.java   
private static void checkImages() throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            HTMLEditorKit c = new HTMLEditorKit();
            HTMLDocument doc = new HTMLDocument();

            try {
                c.read(new StringReader("<HTML><TITLE>Test</TITLE><BODY><IMG id=test></BODY></HTML>"), doc, 0);
            } catch (Exception e) {
                throw new RuntimeException("The test failed", e);
            }

            Element elem = doc.getElement("test");
            ImageView iv = new ImageView(elem);

            if (iv.getLoadingImageIcon() == null) {
                throw new RuntimeException("getLoadingImageIcon returns null");
            }

            if (iv.getNoImageIcon() == null) {
                throw new RuntimeException("getNoImageIcon returns null");
            }
        }
    });
}
项目:openjdk-jdk10    文件:bug8028616.java   
public static void main(String[] args) throws Exception {
    ParserCB cb = new ParserCB();
    HTMLEditorKit htmlKit = new HTMLEditorKit();
    HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();

    htmlDoc.getParser().parse(new StringReader(text), cb, true);

    synchronized (lock) {
        if (!isCallbackInvoked) {
            lock.wait(5000);
        }
    }

    if (!isCallbackInvoked) {
        throw new RuntimeException("Test Failed: ParserCallback.handleText() is not invoked for text - " + text);
    }

    if (exception != null) {
        throw exception;
    }
}
项目:marathonv5    文件:REditorPane.java   
public void setHRef(int pos, Document doc) {
    hRef = null;
    text = null;
    if (!(doc instanceof HTMLDocument)) {
        return;
    }
    HTMLDocument hdoc = (HTMLDocument) doc;
    Iterator iterator = hdoc.getIterator(HTML.Tag.A);
    while (iterator.isValid()) {
        if (pos >= iterator.getStartOffset() && pos < iterator.getEndOffset()) {
            AttributeSet attributes = iterator.getAttributes();
            if (attributes != null && attributes.getAttribute(HTML.Attribute.HREF) != null) {
                try {
                    text = hdoc.getText(iterator.getStartOffset(), iterator.getEndOffset() - iterator.getStartOffset()).trim();
                    hRef = attributes.getAttribute(HTML.Attribute.HREF).toString();
                    setIndexOfHrefAndText(hdoc, pos, text, hRef);
                } catch (BadLocationException e) {
                    e.printStackTrace();
                }
                return;
            }
        }
        iterator.next();
    }
}
项目:SER316-Dresden    文件:EditorPanel.java   
public void setDocument(Note note) {
    // Note note = CurrentProject.getNoteList().getActiveNote();
    // try {
    // this.editor.editor.setPage(CurrentStorage.get().getNoteURL(note));
    editor.document = (HTMLDocument) CurrentStorage.get().openNote(note);
    editor.initEditor();
    if (note != null)
        titleField.setText(note.getTitle());
    else
        titleField.setText("");
    initialTitle = titleField.getText();
    /*
     * } catch (Exception ex) { new ExceptionDialog(ex); }
     */
    /*
     * Document doc = CurrentStorage.get().openNote(note); try {
     * this.editor.editor.setText(doc.getText(0, doc.getLength())); } catch
     * (Exception ex){ ex.printStackTrace(); }
     */
    // .setDocument(CurrentStorage.get().openNote(note));
}
项目:Dahlem_SER316    文件:EditorPanel.java   
public void setDocument(Note note) {
    // Note note = CurrentProject.getNoteList().getActiveNote();
    // try {
    // this.editor.editor.setPage(CurrentStorage.get().getNoteURL(note));
    editor.document = (HTMLDocument) CurrentStorage.get().openNote(note);
    editor.initEditor();
    if (note != null) {
        titleField.setText(note.getTitle());
        tagsField.setText(note.getTags());
    }
    else {
        titleField.setText("");
        tagsField.setText("");
    }
    initialTitle = titleField.getText();
    initialTags = tagsField.getText();
    /*
     * } catch (Exception ex) { new ExceptionDialog(ex); }
     */
    /*
     * Document doc = CurrentStorage.get().openNote(note); try {
     * this.editor.editor.setText(doc.getText(0, doc.getLength())); } catch
     * (Exception ex){ ex.printStackTrace(); }
     */
    // .setDocument(CurrentStorage.get().openNote(note));
}
项目:Wilmersdorf_SER316    文件:EditorPanel.java   
public void setDocument(Note note) {
    // Note note = CurrentProject.getNoteList().getActiveNote();
    // try {
    // this.editor.editor.setPage(CurrentStorage.get().getNoteURL(note));
    editor.document = (HTMLDocument) CurrentStorage.get().openNote(note);
    editor.initEditor();
    if (note != null)
        titleField.setText(note.getTitle());
    else
        titleField.setText("");
    initialTitle = titleField.getText();
    /*
     * } catch (Exception ex) { new ExceptionDialog(ex); }
     */
    /*
     * Document doc = CurrentStorage.get().openNote(note); try {
     * this.editor.editor.setText(doc.getText(0, doc.getLength())); } catch
     * (Exception ex){ ex.printStackTrace(); }
     */
    // .setDocument(CurrentStorage.get().openNote(note));
}
项目:SmartQQ4IntelliJ    文件:IMChatConsole.java   
protected void insertDocument(String msg) {
    try {
        HTMLEditorKit kit = (HTMLEditorKit) historyWidget.getEditorKit();
        HTMLDocument doc = (HTMLDocument) historyWidget.getDocument();
        // historyWidget.getDocument().insertString(len - offset,
        // trimMsg(msg), null);
        // Element root = doc.getDefaultRootElement();
        // Element body = root.getElement(1);
        // doc.insertBeforeEnd(body, msg);
        int pos = historyWidget.getCaretPosition();
        kit.insertHTML(doc, doc.getLength(), msg, 0, 0, null);
        historyWidget.setCaretPosition(scrollLock ? pos : doc.getLength());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:gate-core    文件:JTextPaneTableCellRenderer.java   
public JTextPaneTableCellRenderer() {
  textPane.setContentType("text/html");
  textPane.setEditable(false);
  textPane.setOpaque(true);
  textPane.setBorder(null);

  textPane.setForeground(UIManager.getColor("Table.selectionForeground"));
  textPane.setBackground(UIManager.getColor("Table.selectionBackground"));

  Font font = UIManager.getFont("Label.font");
  String bodyRule =
      "body { font-family: " + font.getFamily() + "; " + "font-size: "
          + font.getSize() + "pt; "
          + (font.isBold() ? "font-weight: bold;" : "") + "}";
  ((HTMLDocument)textPane.getDocument()).getStyleSheet().addRule(bodyRule);

  textPane.addHyperlinkListener(new HyperlinkListener() {

    @Override
    public void hyperlinkUpdate(HyperlinkEvent e) {
      if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED))
          MainFrame.getInstance().showHelpFrame(e.getURL().toString(), "CREOLE Plugin Manager");
    }
  });
}
项目:hybris-integration-intellij-idea-plugin    文件:InformationStep.java   
private void createUIComponents() {
    final Font font = UIManager.getFont("Label.font");
    final String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() + "pt; }";
    informationEditorPane = new JEditorPane();
    informationEditorPane.setEditorKit(new HTMLEditorKit());
    ((HTMLDocument) informationEditorPane.getDocument()).getStyleSheet().addRule(bodyRule);
    cvsEditorPane = new JEditorPane();
    cvsEditorPane.setEditorKit(new HTMLEditorKit());
    ((HTMLDocument) cvsEditorPane.getDocument()).getStyleSheet().addRule(bodyRule);
    jrebelEditorPane = new JEditorPane();
    jrebelEditorPane.setEditorKit(new HTMLEditorKit());
    ((HTMLDocument) jrebelEditorPane.getDocument()).getStyleSheet().addRule(bodyRule);
    jiraEditorPane = new JEditorPane();
    jiraEditorPane.setEditorKit(new HTMLEditorKit());
    ((HTMLDocument) jiraEditorPane.getDocument()).getStyleSheet().addRule(bodyRule);
    jiraEditorPane.addHyperlinkListener(BrowserHyperlinkListener.INSTANCE);
}
项目:Yass    文件:MIDI.java   
private JPanel getContentPanel() {
    content = new JPanel(new BorderLayout());
    JTextPane txt = new JTextPane();
    HTMLDocument doc = (HTMLDocument) txt.getEditorKitForContentType("text/html").createDefaultDocument();
    doc.setAsynchronousLoadPriority(-1);
    txt.setDocument(doc);
    URL url = I18.getResource("create_midi.html");
    try {
        txt.setPage(url);
    } catch (Exception ignored) {
    }
    txt.setEditable(false);
    content.add("North", new JScrollPane(txt));

    convert = new YassMIDIConverter();
    convert.setStandAlone(false);
    content.add("Center", gui = convert.getGUI());
    return content;
}
项目:educational-plugin    文件:StudySwingToolWindow.java   
@Override
public JComponent createTaskInfoPanel(Project project) {
  myTaskTextPane = new JTextPane();
  final JBScrollPane scrollPane = new JBScrollPane(myTaskTextPane);
  myTaskTextPane.setContentType(new HTMLEditorKit().getContentType());
  final EditorColorsScheme editorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
  int fontSize = editorColorsScheme.getEditorFontSize();
  final String fontName = editorColorsScheme.getEditorFontName();
  final Font font = new Font(fontName, Font.PLAIN, fontSize);
  String bodyRule = "body { font-family: " + font.getFamily() + "; " +
                    "font-size: " + font.getSize() + "pt; }" +
                    "pre {font-family: Courier; display: inline; ine-height: 50px; padding-top: 5px; padding-bottom: 5px; padding-left: 5px; background-color:"
                    + ColorUtil.toHex(ColorUtil.dimmer(UIUtil.getPanelBackground())) + ";}" +
                    "code {font-family: Courier; display: flex; float: left; background-color:"
                    + ColorUtil.toHex(ColorUtil.dimmer(UIUtil.getPanelBackground())) + ";}";
  ((HTMLDocument)myTaskTextPane.getDocument()).getStyleSheet().addRule(bodyRule);
  myTaskTextPane.setEditable(false);
  if (!UIUtil.isUnderDarcula()) {
    myTaskTextPane.setBackground(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground());
  }
  myTaskTextPane.setBorder(new EmptyBorder(20, 20, 0, 10));
  myTaskTextPane.addHyperlinkListener(BrowserHyperlinkListener.INSTANCE);
  return scrollPane;
}
项目:jdk8u-jdk    文件:bug6636983.java   
void checkComposedTextRun() {
    HTMLDocument d = (HTMLDocument) ep.getDocument();
    ElementIterator it = new ElementIterator(d.getDefaultRootElement());

    while (true) {
        Element e = it.next();
        if (e == null) {
            throw new RuntimeException("no composed text found");
        }
        AttributeSet a = e.getAttributes();
        if (a.isDefined(StyleConstants.ComposedTextAttribute)) {
            if (!AbstractDocument.ContentElementName.equals(a.getAttribute(StyleConstants.NameAttribute))) {
                throw new RuntimeException("AbstractDocument.ContentElementName.equals(a.getAttribute(StyleConstants.NameAttribute)) is false");
            }

            if (a.isDefined(SwingUtilities2.IMPLIED_CR)) {
                throw new RuntimeException("a.isDefined(SwingUtilities2.IMPLIED_CR) is true");
            }

            return;
        }
    }

}
项目:Neukoelln_SER316    文件:AltHTMLWriter.java   
/**
 * Writes out any additional comments (comments outside of the body)
 * stored under the property HTMLDocument.AdditionalComments.
 */
void writeAdditionalComments() throws IOException {
    Object comments = getDocument().getProperty(HTMLDocument.AdditionalComments);
    if (comments == null) return; 
    if (comments instanceof Vector) {
        Vector v = (Vector) comments;
        for (int counter = 0, maxCounter = v.size(); counter < maxCounter; counter++) {
            writeComment(v.elementAt(counter).toString());
        }
    }
    //[alex] I've add the following 'else' for single comments:
    else
        writeComment(comments.toString());
    // end add
}
项目:Wilmersdorf_SER316    文件:AltHTMLWriter.java   
/**
 * Writes out any additional comments (comments outside of the body)
 * stored under the property HTMLDocument.AdditionalComments.
 */
void writeAdditionalComments() throws IOException {
    Object comments = getDocument().getProperty(HTMLDocument.AdditionalComments);
    if (comments == null) return; 
    if (comments instanceof Vector) {
        Vector v = (Vector) comments;
        for (int counter = 0, maxCounter = v.size(); counter < maxCounter; counter++) {
            writeComment(v.elementAt(counter).toString());
        }
    }
    //[alex] I've add the following 'else' for single comments:
    else
        writeComment(comments.toString());
    // end add
}
项目:incubator-netbeans    文件:NotifyHtmlPanel.java   
/**
 * Creates new form SwitchToCliPanel
 */
public NotifyHtmlPanel () {
    initComponents();
    Document doc = msgPanel.getDocument();
    if (doc instanceof HTMLDocument) { // Issue 185505
        HTMLDocument htmlDoc = (HTMLDocument)doc;
        Font font = UIManager.getFont("Label.font"); // NOI18N
        String bodyRule = "body { font-family: " + font.getFamily() + "; " // NOI18N
            + "color: " + SvnUtils.getColorString(msgPanel.getForeground()) + "; " //NOI18N
            + "font-size: " + font.getSize() + "pt; }"; // NOI18N
        htmlDoc.getStyleSheet().addRule(bodyRule);
    }
    msgPanel.setOpaque(false);
    msgPanel.setBackground(new Color(0,0,0,0)); // windows and nimbus workaround see issue 145826
}
项目:incubator-netbeans    文件:OverviewControllerUI.java   
@Override
public Document createDefaultDocument() {
    StyleSheet styles = getStyleSheet();
    StyleSheet ss = new StyleSheet();

    ss.addStyleSheet(styles);

    HTMLDocument doc = new CustomHTMLDocument(ss);
    doc.setParser(getParser());
    doc.setAsynchronousLoadPriority(4);
    doc.setTokenThreshold(100);
    return doc;
}
项目:openjdk-jdk10    文件:bug4960629.java   
private void test() {
    View root = ((View)label.getClientProperty(BasicHTML.propertyKey))
            .getView(0);
    int n = root.getViewCount();
    View v  = root.getView(n - 1);
    AttributeSet attrs = v.getAttributes();
    StyleSheet ss = ((HTMLDocument) v.getDocument()).getStyleSheet();
    Font font = ss.getFont(attrs);
    System.out.println(font.getSize());
    passed = (font.getSize() == 12);
    if(!passed) {
        throw new RuntimeException("Test failed.");
    }
}
项目:Dahlem_SER316    文件:HTMLFileExport.java   
/**
 * Constructor for HTMLFileExport.
 */
public HTMLFileExport(File f, Document doc, Note note, String charset, boolean num, String templFile, boolean xhtml) {
    this.f = f;
    this.doc = (HTMLDocument)doc;
    this.note = note;
    this.charset = charset;
    this.num = num;
    this.templFile = templFile;
    this.xhtml = xhtml;
    doExport();
}
项目:incubator-netbeans    文件:OutputTabTest.java   
/**
 * Test for bug 230402 - NullPointerException at
 * org.netbeans.core.output2.ui.AbstractOutputPane.run. No exception should
 * be thrown.
 *
 * @throws java.lang.InterruptedException
 * @throws java.lang.reflect.InvocationTargetException
 */
public void testEnsureCaretPosition() throws InterruptedException,
        InvocationTargetException {

    EventQueue.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            tab.setDocument(new HTMLDocument());
            tab.getOutputPane().run();
        }
    });
}
项目:rapidminer    文件:AnnotationsDecorator.java   
/**
 * Saves the content of the comment editor as the new comment for the given
 * {@link WorkflowAnnotation}.
 *
 * @param selected
 *            the annotation for which the content of the editor pane should be saved as new
 *            comment
 */
private void saveEdit(final WorkflowAnnotation selected) {
    if (editPane == null) {
        return;
    }
    HTMLDocument document = (HTMLDocument) editPane.getDocument();
    StringWriter writer = new StringWriter();
    try {
        editPane.getEditorKit().write(writer, document, 0, document.getLength());
    } catch (IndexOutOfBoundsException | IOException | BadLocationException e1) {
        // should not happen
        LogService.getRoot().log(Level.WARNING,
                "com.rapidminer.gui.flow.processrendering.annotations.AnnotationsDecorator.cannot_save");
    }
    String comment = writer.toString();
    comment = AnnotationDrawUtils.removeStyleFromComment(comment);
    Rectangle2D loc = selected.getLocation();
    Rectangle2D newLoc = new Rectangle2D.Double(loc.getX(), loc.getY(), editPane.getBounds().getWidth(), editPane
            .getBounds().getHeight());
    selected.setLocation(newLoc);

    boolean overflowing = false;
    int prefHeight = AnnotationDrawUtils.getContentHeight(
            AnnotationDrawUtils.createStyledCommentString(comment, selected.getStyle()), (int) newLoc.getWidth());
    if (prefHeight > newLoc.getHeight()) {
        overflowing = true;
    }
    selected.setOverflowing(overflowing);

    model.setAnnotationComment(selected, comment);
}
项目:marathonv5    文件:JEditorPaneTagJavaElement.java   
@Override public String _getText() {
    Iterator iterator = findTag((HTMLDocument) ((JEditorPane) parent.getComponent()).getDocument());
    int startOffset = iterator.getStartOffset();
    int endOffset = iterator.getEndOffset();
    try {
        return ((HTMLDocument) ((JEditorPane) parent.getComponent()).getDocument()).getText(startOffset,
                endOffset - startOffset);
    } catch (BadLocationException e) {
        throw new InvalidElementStateException("Unable to get text for tag " + tag + " in document with index " + index, e);
    }
}
项目:marathonv5    文件:JEditorPaneTagJavaElement.java   
private Iterator findTag(HTMLDocument doc) {
    Iterator iterator = doc.getIterator(tag);
    int current = 0;
    while (iterator.isValid()) {
        if (current++ == index) {
            break;
        }
        iterator.next();
    }
    if (!iterator.isValid()) {
        throw new NoSuchElementException("Unable to find tag " + tag + " in document with index " + index, null);
    }
    return iterator;
}
项目:marathonv5    文件:JEditorPaneTagJavaElement.java   
@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);
    }
}
项目:marathonv5    文件:JEditorPaneTagJavaElement.java   
@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);
    }
}
项目:marathonv5    文件:JEditorPaneTagJavaElement.java   
public int getHRefIndex() {
    return EventQueueWait.exec(new Callable<Integer>() {
        @Override public Integer call() throws Exception {
            String href = getAttribute("href");
            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;
                }
                AttributeSet attributes = iterator.getAttributes();
                if (attributes != null) {
                    Object attributeObject = attributes.getAttribute(HTML.Attribute.HREF);
                    if (attributeObject != null) {
                        String attribute = attributeObject.toString();
                        if (attribute.equals(href)) {
                            hRefIndex++;
                        }
                    }
                }
                iterator.next();
            }
            return -1;
        }
    });
}
项目:marathonv5    文件:REditorPane.java   
private void setIndexOfHrefAndText(HTMLDocument hdoc, int pos, String text, String hRef) {
    this.hRefIndex = 0;
    this.textIndex = 0;
    Iterator iterator = hdoc.getIterator(HTML.Tag.A);
    while (iterator.isValid()) {
        if (pos >= iterator.getStartOffset() && pos < iterator.getEndOffset()) {
            return;
        } else {
            AttributeSet attributes = iterator.getAttributes();
            if (attributes != null && attributes.getAttribute(HTML.Attribute.HREF) != null) {
                try {
                    String t = hdoc.getText(iterator.getStartOffset(), iterator.getEndOffset() - iterator.getStartOffset())
                            .trim();
                    String h = attributes.getAttribute(HTML.Attribute.HREF).toString();
                    if (t.equals(text)) {
                        this.textIndex++;
                    }
                    if (h.equals(hRef)) {
                        this.hRefIndex++;
                    }
                } catch (BadLocationException e) {
                    e.printStackTrace();
                }
            }
        }
        iterator.next();
    }
}
项目:Dahlem_SER316    文件:ProjectExporter.java   
private static String getNoteHTML(Note note) {
    String text = "";
    StringWriter sw = new StringWriter();
    AltHTMLWriter writer = new AltHTMLWriter(sw,
            (HTMLDocument) CurrentStorage.get().openNote(note), _charset,
            _num);
    try {
        writer.write();
        sw.flush();
        sw.close();
    }
    catch (Exception ex) {
        new ExceptionDialog(ex);
    }
    text = sw.toString();
    if (_xhtml)
        text = HTMLFileExport.convertToXHTML(text);
    text = Pattern
            .compile("<body(.*?)>", java.util.regex.Pattern.DOTALL
                    + java.util.regex.Pattern.CASE_INSENSITIVE).split(text)[1];
    text = Pattern
            .compile("</body>", java.util.regex.Pattern.DOTALL
                    + java.util.regex.Pattern.CASE_INSENSITIVE).split(text)[0];
    /*
             * if (_copyImages) { ?)\"" + java.util.regex.Pattern.DOTALL +
             * java.util.regex.Pattern.CASE_INSENSITIVE); Matcher m =
             * p.matcher(text); for (int i = 1; i < m.groupCount(); i++) { String g =
             * m.group(i); String url = g.split("\"")[1];
             *  }
             */
    text = "<div class=\"note\">" + text + "</div>";

    if (_titlesAsHeaders)
                    text = "\n\n<div class=\"date\">"
                + note.getDate().getFullDateString()
                + ":</div>\n<h1 class=\"title\">" + note.getTitle()
                + "</h1>\n" + text;
    return text;
}
项目:SER316-Dresden    文件:AltHTMLWriter.java   
/**
 * Writes out any additional comments (comments outside of the body)
 * stored under the property HTMLDocument.AdditionalComments.
 */
void writeAdditionalComments() throws IOException {
    Object comments = getDocument().getProperty(HTMLDocument.AdditionalComments);
    if (comments == null) return; 
    if (comments instanceof Vector) {
        Vector v = (Vector) comments;
        for (int counter = 0, maxCounter = v.size(); counter < maxCounter; counter++) {
            writeComment(v.elementAt(counter).toString());
        }
    }
    //[alex] I've add the following 'else' for single comments:
    else
        writeComment(comments.toString());
    // end add
}