Search in sources :

Example 1 with StyleSheet

use of javax.swing.text.html.StyleSheet in project processing by processing.

the class DetailPanel method setTextStyle.

static void setTextStyle(JTextPane textPane, String fontSize) {
    Document doc = textPane.getDocument();
    if (doc instanceof HTMLDocument) {
        HTMLDocument html = (HTMLDocument) doc;
        StyleSheet stylesheet = html.getStyleSheet();
        stylesheet.addRule("body { " + "  margin: 0; padding: 0;" + "  font-family: " + Toolkit.getSansFontName() + ", Arial, Helvetica, sans-serif;" + "  font-size: 100%;" + "font-size: " + fontSize + "; " + "}");
    }
}
Also used : StyleSheet(javax.swing.text.html.StyleSheet) HTMLDocument(javax.swing.text.html.HTMLDocument) HTMLDocument(javax.swing.text.html.HTMLDocument) Document(javax.swing.text.Document)

Example 2 with StyleSheet

use of javax.swing.text.html.StyleSheet in project processing by processing.

the class DetailPanel method setForegroundStyle.

// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/**
   * Sets coloring based on whether installed or not;
   * also makes ugly blue HTML links into the specified color (black).
   */
static void setForegroundStyle(JTextPane textPane, boolean installed, boolean selected) {
    Document doc = textPane.getDocument();
    if (doc instanceof HTMLDocument) {
        HTMLDocument html = (HTMLDocument) doc;
        StyleSheet stylesheet = html.getStyleSheet();
        // slightly grayed when installed
        String c = (installed && !selected) ? "#555555" : "#000000";
        stylesheet.addRule("body { color:" + c + "; }");
        stylesheet.addRule("a { color:" + c + "; }");
    }
}
Also used : StyleSheet(javax.swing.text.html.StyleSheet) HTMLDocument(javax.swing.text.html.HTMLDocument) HTMLDocument(javax.swing.text.html.HTMLDocument) Document(javax.swing.text.Document)

Example 3 with StyleSheet

use of javax.swing.text.html.StyleSheet in project jdk8u_jdk by JetBrains.

the class Test6817933 method main.

public static void main(String[] args) throws Exception {
    try {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception exception) {
        exception.printStackTrace();
        // ignore test on non-Windows machines
        return;
    }
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            StyleSheet css = new StyleSheet();
            css.addRule(STYLE);
            HTMLEditorKit kit = new HTMLEditorKit();
            kit.setStyleSheet(css);
            JFrame frame = new JFrame(STYLE);
            frame.add(chooser = new JFileChooser());
            frame.setSize(640, 480);
            frame.setVisible(true);
        }
    });
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    toolkit.realSync(500);
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            try {
                JToggleButton button = get(JToggleButton.class, get(WindowsPlacesBar.class, chooser));
                int width = button.getWidth();
                int height = button.getHeight() / 3;
                Point point = new Point(0, height * 2);
                SwingUtilities.convertPointToScreen(point, button);
                width += point.x;
                height += point.y;
                int count = 0;
                Robot robot = new Robot();
                for (int x = point.x; x < width; x++) {
                    for (int y = point.y; y < height; y++) {
                        count += COLOR.equals(robot.getPixelColor(x, y)) ? -2 : 1;
                    }
                }
                if (count < 0) {
                    throw new Exception("TEST ERROR: a lot of red pixels");
                }
            } catch (Exception exception) {
                throw new Error(exception);
            } finally {
                SwingUtilities.getWindowAncestor(chooser).dispose();
            }
        }
    });
}
Also used : StyleSheet(javax.swing.text.html.StyleSheet) JFileChooser(javax.swing.JFileChooser) JToggleButton(javax.swing.JToggleButton) JFrame(javax.swing.JFrame) SunToolkit(sun.awt.SunToolkit) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) Point(java.awt.Point) Robot(java.awt.Robot)

Example 4 with StyleSheet

use of javax.swing.text.html.StyleSheet in project pcgen by PCGen.

the class ExtendedHTMLEditorKit method createDefaultDocument.

/* WACKY GERMAN CODE */
@Override
public Document createDefaultDocument() {
    StyleSheet styles = getStyleSheet();
    StyleSheet ss = new StyleSheet();
    ss.addStyleSheet(styles);
    ExtendedHTMLDocument doc = new ExtendedHTMLDocument(ss);
    doc.setParser(getParser());
    doc.setAsynchronousLoadPriority(4);
    doc.setTokenThreshold(100);
    return doc;
}
Also used : StyleSheet(javax.swing.text.html.StyleSheet)

Example 5 with StyleSheet

use of javax.swing.text.html.StyleSheet in project intellij-community by JetBrains.

the class JBLabel method updateStyle.

private void updateStyle(@NotNull JEditorPane pane) {
    EditorKit kit = pane.getEditorKit();
    if (kit instanceof HTMLEditorKit) {
        StyleSheet css = ((HTMLEditorKit) kit).getStyleSheet();
        css.addRule("body, p {" + "color:#" + ColorUtil.toHex(getForeground()) + ";" + "font-family:" + getFont().getFamily() + ";" + "font-size:" + getFont().getSize() + "pt;" + "white-space:nowrap;}");
    }
}
Also used : EditorKit(javax.swing.text.EditorKit) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) StyleSheet(javax.swing.text.html.StyleSheet) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit)

Aggregations

StyleSheet (javax.swing.text.html.StyleSheet)14 HTMLDocument (javax.swing.text.html.HTMLDocument)6 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)6 URL (java.net.URL)4 HyperlinkEvent (javax.swing.event.HyperlinkEvent)3 Document (javax.swing.text.Document)3 MouseEvent (java.awt.event.MouseEvent)2 IOException (java.io.IOException)2 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)1 ApplicationImpl (com.intellij.openapi.application.impl.ApplicationImpl)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 Project (com.intellij.openapi.project.Project)1 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 HyperlinkAdapter (com.intellij.ui.HyperlinkAdapter)1 CustomLineBorder (com.intellij.ui.border.CustomLineBorder)1 JBScrollPane (com.intellij.ui.components.JBScrollPane)1 Point (java.awt.Point)1 Robot (java.awt.Robot)1 InputStreamReader (java.io.InputStreamReader)1