Search in sources :

Example 16 with HTMLDocument

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

the class NotificationMessageElement method updateStyle.

protected void updateStyle(@NotNull JEditorPane editorPane, @Nullable JTree tree, Object value, boolean selected, boolean hasFocus) {
    final HTMLDocument htmlDocument = (HTMLDocument) editorPane.getDocument();
    final Style style = htmlDocument.getStyleSheet().getStyle(MSG_STYLE);
    if (value instanceof LoadingNode) {
        StyleConstants.setForeground(style, JBColor.GRAY);
    } else {
        if (selected) {
            StyleConstants.setForeground(style, hasFocus ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeTextForeground());
        } else {
            StyleConstants.setForeground(style, UIUtil.getTreeTextForeground());
        }
    }
    if (UIUtil.isUnderGTKLookAndFeel() || UIUtil.isUnderNimbusLookAndFeel() && selected && hasFocus || tree != null && WideSelectionTreeUI.isWideSelection(tree)) {
        editorPane.setOpaque(false);
    } else {
        editorPane.setOpaque(selected && hasFocus);
    }
    htmlDocument.setCharacterAttributes(0, htmlDocument.getLength(), style, false);
}
Also used : HTMLDocument(javax.swing.text.html.HTMLDocument) Style(javax.swing.text.Style) LoadingNode(com.intellij.ui.LoadingNode)

Example 17 with HTMLDocument

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

the class NotificationMessageElement method installJep.

protected JEditorPane installJep(@NotNull JEditorPane myEditorPane) {
    String message = StringUtil.join(this.getText(), "<br>");
    myEditorPane.setEditable(false);
    myEditorPane.setOpaque(false);
    myEditorPane.setEditorKit(UIUtil.getHTMLEditorKit());
    myEditorPane.setHighlighter(null);
    final StyleSheet styleSheet = ((HTMLDocument) myEditorPane.getDocument()).getStyleSheet();
    final Style style = styleSheet.addStyle(MSG_STYLE, null);
    styleSheet.addStyle(LINK_STYLE, style);
    myEditorPane.setText(message);
    return myEditorPane;
}
Also used : StyleSheet(javax.swing.text.html.StyleSheet) HTMLDocument(javax.swing.text.html.HTMLDocument) Style(javax.swing.text.Style)

Example 18 with HTMLDocument

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

the class AppUIUtil method showPrivacyPolicyAgreement.

/**
   * @param htmlText Updated version of Privacy Policy text if any.
   *                 If it's {@code null}, the standard text from bundled resources would be used.
   */
public static void showPrivacyPolicyAgreement(@NotNull String htmlText) {
    DialogWrapper dialog = new DialogWrapper(true) {

        @Nullable
        @Override
        protected JComponent createCenterPanel() {
            JPanel centerPanel = new JPanel(new BorderLayout(JBUI.scale(5), JBUI.scale(5)));
            JEditorPane viewer = SwingHelper.createHtmlViewer(true, null, JBColor.WHITE, JBColor.BLACK);
            viewer.setFocusable(true);
            viewer.addHyperlinkListener(new HyperlinkAdapter() {

                @Override
                protected void hyperlinkActivated(HyperlinkEvent e) {
                    URL url = e.getURL();
                    if (url != null) {
                        BrowserUtil.browse(url);
                    } else {
                        SwingHelper.scrollToReference(viewer, e.getDescription());
                    }
                }
            });
            viewer.setText(htmlText);
            StyleSheet styleSheet = ((HTMLDocument) viewer.getDocument()).getStyleSheet();
            styleSheet.addRule("body {font-family: \"Segoe UI\", Tahoma, sans-serif;}");
            styleSheet.addRule("body {margin-top:0;padding-top:0;}");
            styleSheet.addRule("body {font-size:" + JBUI.scaleFontSize(13) + "pt;}");
            styleSheet.addRule("h2, em {margin-top:" + JBUI.scaleFontSize(20) + "pt;}");
            styleSheet.addRule("h1, h2, h3, p, h4, em {margin-bottom:0;padding-bottom:0;}");
            styleSheet.addRule("p, h1 {margin-top:0;padding-top:" + JBUI.scaleFontSize(6) + "pt;}");
            styleSheet.addRule("li {margin-bottom:" + JBUI.scaleFontSize(6) + "pt;}");
            styleSheet.addRule("h2 {margin-top:0;padding-top:" + JBUI.scaleFontSize(13) + "pt;}");
            viewer.setCaretPosition(0);
            viewer.setBorder(JBUI.Borders.empty(0, 5, 5, 5));
            centerPanel.add(new JLabel("Please read and accept these terms and conditions:"), BorderLayout.NORTH);
            centerPanel.add(new JBScrollPane(viewer, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
            return centerPanel;
        }

        @Override
        protected void createDefaultActions() {
            super.createDefaultActions();
            init();
            setOKButtonText("Accept");
            setCancelButtonText("Reject and Exit");
            setAutoAdjustable(false);
        }

        @Override
        public void doCancelAction() {
            super.doCancelAction();
            ApplicationEx application = ApplicationManagerEx.getApplicationEx();
            if (application == null) {
                System.exit(Main.PRIVACY_POLICY_REJECTION);
            } else {
                ((ApplicationImpl) application).exit(true, true, false);
            }
        }
    };
    dialog.setModal(true);
    dialog.setTitle(ApplicationNamesInfo.getInstance().getFullProductName() + " Privacy Policy Agreement");
    dialog.setSize(JBUI.scale(509), JBUI.scale(395));
    dialog.show();
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) HTMLDocument(javax.swing.text.html.HTMLDocument) ApplicationImpl(com.intellij.openapi.application.impl.ApplicationImpl) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) URL(java.net.URL) StyleSheet(javax.swing.text.html.StyleSheet) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 19 with HTMLDocument

use of javax.swing.text.html.HTMLDocument in project sling by apache.

the class WebloaderJob method getDocumentUrlsFromGoogle.

private URL[] getDocumentUrlsFromGoogle(String currentFiletype, int start) throws IOException, BadLocationException {
    final List urls = new ArrayList();
    String query = webQuery + " filetype:" + currentFiletype;
    final URL google = new URL("http://www.google.com/search?q=" + URLEncoder.encode(query, "UTF-8") + "&start=" + start);
    log.debug("Querying {}", google.toString());
    statusInfo = "Querying " + google.toString();
    statusDetails = "";
    URLConnection con = google.openConnection();
    con.setRequestProperty("User-Agent", "");
    InputStream in = con.getInputStream();
    try {
        HTMLEditorKit kit = new HTMLEditorKit();
        HTMLDocument doc = new HTMLDocument();
        doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
        kit.read(new InputStreamReader(in, "UTF-8"), doc, 0);
        HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
        while (it.isValid()) {
            if (it.getAttributes() != null) {
                String href = (String) it.getAttributes().getAttribute(HTML.Attribute.HREF);
                if (href != null && href.endsWith("." + currentFiletype)) {
                    URL url = new URL(new URL("http", "www.google.com", "dummy"), href);
                    if (url.getHost().indexOf("google") == -1) {
                        log.debug("Got document URL from google: {}", url);
                        statusDetails = "Got URL " + url;
                        urls.add(url);
                    }
                }
            }
            it.next();
        }
    } finally {
        in.close();
    }
    return (URL[]) urls.toArray(new URL[urls.size()]);
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) HTMLDocument(javax.swing.text.html.HTMLDocument) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) URL(java.net.URL) URLConnection(java.net.URLConnection)

Example 20 with HTMLDocument

use of javax.swing.text.html.HTMLDocument in project languagetool by languagetool-org.

the class ResultAreaHelper method appendMain.

private void appendMain(String html) {
    HTMLDocument d = (HTMLDocument) statusPane.getDocument();
    Element e = d.getElement(MAIN);
    try {
        d.insertBeforeEnd(e, html);
    } catch (BadLocationException ex) {
        Tools.showError(ex);
    } catch (IOException ex) {
        Tools.showError(ex);
    }
}
Also used : HTMLDocument(javax.swing.text.html.HTMLDocument) Element(javax.swing.text.Element) IOException(java.io.IOException) BadLocationException(javax.swing.text.BadLocationException)

Aggregations

HTMLDocument (javax.swing.text.html.HTMLDocument)30 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)10 Element (javax.swing.text.Element)6 StyleSheet (javax.swing.text.html.StyleSheet)6 URL (java.net.URL)5 AttributeSet (javax.swing.text.AttributeSet)5 BadLocationException (javax.swing.text.BadLocationException)5 IOException (java.io.IOException)4 Document (javax.swing.text.Document)4 Style (javax.swing.text.Style)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 StringReader (java.io.StringReader)2 URLConnection (java.net.URLConnection)2 ArrayList (java.util.ArrayList)2 HyperlinkEvent (javax.swing.event.HyperlinkEvent)2 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)2 HTMLFrameHyperlinkEvent (javax.swing.text.html.HTMLFrameHyperlinkEvent)2 NlModel (com.android.tools.idea.uibuilder.model.NlModel)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1