Search in sources :

Example 11 with StyleSheet

use of javax.swing.text.html.StyleSheet 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 12 with StyleSheet

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

the class DetailPanel method setSelectionStyle.

static void setSelectionStyle(JTextPane textPane, boolean selected) {
    Document doc = textPane.getDocument();
    if (doc instanceof HTMLDocument) {
        HTMLDocument html = (HTMLDocument) doc;
        StyleSheet styleSheet = html.getStyleSheet();
        if (selected) {
            styleSheet.addRule("a { text-decoration:underline } ");
        } else {
            styleSheet.addRule("a { text-decoration:none }");
        }
    }
}
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 13 with StyleSheet

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

the class UnusedDeclarationPresentation method getCustomPreviewPanel.

@Override
public JComponent getCustomPreviewPanel(RefEntity entity) {
    final Project project = entity.getRefManager().getProject();
    JEditorPane htmlView = new JEditorPane() {

        @Override
        public String getToolTipText(MouseEvent evt) {
            int pos = viewToModel(evt.getPoint());
            if (pos >= 0) {
                HTMLDocument hdoc = (HTMLDocument) getDocument();
                javax.swing.text.Element e = hdoc.getCharacterElement(pos);
                AttributeSet a = e.getAttributes();
                SimpleAttributeSet value = (SimpleAttributeSet) a.getAttribute(HTML.Tag.A);
                if (value != null) {
                    String objectPackage = (String) value.getAttribute("qualifiedname");
                    if (objectPackage != null) {
                        return objectPackage;
                    }
                }
            }
            return null;
        }
    };
    htmlView.setContentType(UIUtil.HTML_MIME);
    htmlView.setEditable(false);
    htmlView.setOpaque(false);
    htmlView.setBackground(UIUtil.getLabelBackground());
    htmlView.addHyperlinkListener(new HyperlinkAdapter() {

        @Override
        protected void hyperlinkActivated(HyperlinkEvent e) {
            URL url = e.getURL();
            if (url == null) {
                return;
            }
            @NonNls String ref = url.getRef();
            int offset = Integer.parseInt(ref);
            String fileURL = url.toExternalForm();
            fileURL = fileURL.substring(0, fileURL.indexOf('#'));
            VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(fileURL);
            if (vFile == null) {
                vFile = VfsUtil.findFileByURL(url);
            }
            if (vFile != null) {
                final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, vFile, offset);
                FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
            }
        }
    });
    final StyleSheet css = ((HTMLEditorKit) htmlView.getEditorKit()).getStyleSheet();
    css.addRule("p.problem-description-group {text-indent: " + JBUI.scale(9) + "px;font-weight:bold;}");
    css.addRule("div.problem-description {margin-left: " + JBUI.scale(9) + "px;}");
    css.addRule("ul {margin-left:" + JBUI.scale(10) + "px;text-indent: 0}");
    css.addRule("code {font-family:" + UIUtil.getLabelFont().getFamily() + "}");
    final StringBuffer buf = new StringBuffer();
    getComposer().compose(buf, entity, false);
    final String text = buf.toString();
    SingleInspectionProfilePanel.readHTML(htmlView, SingleInspectionProfilePanel.toHTML(htmlView, text, false));
    return ScrollPaneFactory.createScrollPane(htmlView, true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MouseEvent(java.awt.event.MouseEvent) HyperlinkEvent(javax.swing.event.HyperlinkEvent) HTMLDocument(javax.swing.text.html.HTMLDocument) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) URL(java.net.URL) SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) Project(com.intellij.openapi.project.Project) StyleSheet(javax.swing.text.html.StyleSheet) AttributeSet(javax.swing.text.AttributeSet) SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) HyperlinkAdapter(com.intellij.ui.HyperlinkAdapter)

Example 14 with StyleSheet

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

the class UIUtil method getHTMLEditorKit.

public static HTMLEditorKit getHTMLEditorKit(boolean noGapsBetweenParagraphs) {
    Font font = getLabelFont();
    @NonNls String family = !SystemInfo.isWindows && font != null ? font.getFamily() : "Tahoma";
    final int size = font != null ? font.getSize() : JBUI.scale(11);
    String customCss = String.format("body, div, p { font-family: %s; font-size: %s; }", family, size);
    if (noGapsBetweenParagraphs) {
        customCss += " p { margin-top: 0; }";
    }
    final StyleSheet style = new StyleSheet();
    style.addStyleSheet(isUnderDarcula() ? (StyleSheet) UIManager.getDefaults().get("StyledEditorKit.JBDefaultStyle") : DEFAULT_HTML_KIT_CSS);
    style.addRule(customCss);
    return new HTMLEditorKit() {

        @Override
        public StyleSheet getStyleSheet() {
            return style;
        }
    };
}
Also used : NonNls(org.jetbrains.annotations.NonNls) 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