Example usage for javax.swing.text.html HTMLEditorKit setStyleSheet

List of usage examples for javax.swing.text.html HTMLEditorKit setStyleSheet

Introduction

In this page you can find the example usage for javax.swing.text.html HTMLEditorKit setStyleSheet.

Prototype

public void setStyleSheet(StyleSheet s) 

Source Link

Document

Set the set of styles to be used to render the various HTML elements.

Usage

From source file:com.vladsch.idea.multimarkdown.editor.MultiMarkdownPreviewEditor.java

public static void setStyleSheet(JEditorPane jEditorPane) {
    HTMLEditorKit htmlKit = new HTMLEditorKit();

    final StyleSheet style = new StyleSheet();

    if (!MultiMarkdownGlobalSettings.getInstance().useCustomCss(false)) {
        style.importStyleSheet(MultiMarkdownGlobalSettings.getInstance().getCssFileURL(false));
    } else {/* w  w w.j  av  a2  s.  c  o m*/
        try {
            style.loadRules(new StringReader(MultiMarkdownGlobalSettings.getInstance().getCssText(false)),
                    null);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    htmlKit.setStyleSheet(style);
    jEditorPane.setEditorKit(htmlKit);
}

From source file:org.knime.ext.textprocessing.nodes.view.documentviewer2.DocumentPanel2.java

/**
 * Creates new instance of {@code DocumentPanel} with given document view model to show, and the preferred width and
 * height to set./*from   www.  ja  v  a 2  s.co m*/
 *
 * @param docViewModel The document view model.
 * @param preferredWidth The preferred width to set.
 * @param preferredHeight The preferred height to set.
 */
public DocumentPanel2(final DocumentViewModel docViewModel, final int preferredWidth,
        final int preferredHeight) {
    super(new BorderLayout());

    if (docViewModel == null) {
        throw new IllegalArgumentException("Document view model may not be null!");
    }
    m_docViewModel = docViewModel;

    m_fulltextPane = new JEditorPane();
    m_fulltextPane.setContentType("text/html");
    m_fulltextPane.setEditable(false);
    m_fulltextPane.setCaretPosition(0);
    m_fulltextPane.addHyperlinkListener(new LinkListener());
    m_fulltextPane.setToolTipText("Select text and right click.");

    HTMLEditorKit editorKit = new HTMLEditorKit();

    // Adding stylesheet to the document
    StyleSheet sheet = editorKit.getStyleSheet();
    sheet.addRule(
            "html, body {margin: 0; padding: 4px; color: #000000; font-family: 'Roboto', sans-serif; background: #ffffff; font-size: 12px;}");
    sheet.addRule("table { border-collapse: collapse; }");
    sheet.addRule("th, td { border: 1px solid #000000; padding: 10px 15px; }");
    sheet.addRule(
            ".docHeading {display: block; font-size: 15px; font-weight: bold; margin: 5px 0 30px 0; width: 100%;}");
    sheet.addRule(
            ".sep {  width:100%; border-bottom: 1px dashed #8c8b8b ; top: 10%; bottom: 20%; position: absolute; margin: 10px 0 10px 0;}");
    sheet.addRule(".subHeading { font-weight: 500; font-style: italic; text-transform: lowercase; }");

    editorKit.setStyleSheet(sheet);
    m_fulltextPane.setEditorKit(editorKit);

    Document doc = editorKit.createDefaultDocument();
    m_fulltextPane.setDocument(doc);
    m_fulltextPane.setText(getPreparedText());

    m_rightClickMenue = new JPopupMenu();
    JMenuItem item;
    for (String source : SearchEngines.getInstance().getSearchEngineNames()) {
        item = new JMenuItem(source);
        item.addActionListener(new RightClickMenueListener());
        m_rightClickMenue.add(item);
    }
    m_fulltextPane.setComponentPopupMenu(m_rightClickMenue);

    JScrollPane jsp = new JScrollPane(m_fulltextPane);
    jsp.setPreferredSize(new Dimension(preferredWidth, preferredHeight));
    add(jsp, BorderLayout.CENTER);
}