Search in sources :

Example 6 with StyleSheet

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

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

the class TipUIUtil method createTipBrowser.

@NotNull
public static JEditorPane createTipBrowser() {
    JEditorPane browser = new JEditorPane();
    browser.setEditable(false);
    browser.setBackground(UIUtil.getTextFieldBackground());
    browser.addHyperlinkListener(new HyperlinkListener() {

        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                BrowserUtil.browse(e.getURL());
            }
        }
    });
    URL resource = ResourceUtil.getResource(TipUIUtil.class, "/tips/css/", UIUtil.isUnderDarcula() ? "tips_darcula.css" : "tips.css");
    final StyleSheet styleSheet = UIUtil.loadStyleSheet(resource);
    HTMLEditorKit kit = new HTMLEditorKit() {

        @Override
        public StyleSheet getStyleSheet() {
            return styleSheet != null ? styleSheet : super.getStyleSheet();
        }
    };
    browser.setEditorKit(kit);
    return browser;
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) StyleSheet(javax.swing.text.html.StyleSheet) HyperlinkListener(javax.swing.event.HyperlinkListener) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) URL(java.net.URL) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with StyleSheet

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

the class UIUtil method loadStyleSheet.

@Nullable
public static StyleSheet loadStyleSheet(@Nullable URL url) {
    if (url == null)
        return null;
    try {
        StyleSheet styleSheet = new StyleSheet();
        styleSheet.loadRules(new InputStreamReader(url.openStream(), CharsetToolkit.UTF8), url);
        return styleSheet;
    } catch (IOException e) {
        LOG.warn(url + " loading failed", e);
        return null;
    }
}
Also used : StyleSheet(javax.swing.text.html.StyleSheet) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with StyleSheet

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

the class PluginManagerMain method init.

protected void init() {
    GuiUtils.replaceJSplitPaneWithIDEASplitter(main);
    HTMLEditorKit kit = new HTMLEditorKit();
    StyleSheet sheet = kit.getStyleSheet();
    // list-style-type: none;
    sheet.addRule("ul {margin-left: 16px}");
    myDescriptionTextArea.setEditorKit(kit);
    myDescriptionTextArea.setEditable(false);
    myDescriptionTextArea.addHyperlinkListener(new MyHyperlinkListener());
    JScrollPane installedScrollPane = createTable();
    myPluginHeaderPanel = new PluginHeaderPanel(this);
    myHeader.setBackground(UIUtil.getTextFieldBackground());
    myPluginHeaderPanel.getPanel().setBackground(UIUtil.getTextFieldBackground());
    myPluginHeaderPanel.getPanel().setOpaque(true);
    myHeader.add(myPluginHeaderPanel.getPanel(), BorderLayout.CENTER);
    installTableActions();
    myTablePanel.add(installedScrollPane, BorderLayout.CENTER);
    UIUtil.applyStyle(UIUtil.ComponentStyle.SMALL, myPanelDescription);
    myPanelDescription.setBorder(JBUI.Borders.emptyLeft(7));
    final JPanel header = new JPanel(new BorderLayout()) {

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            final Color bg = UIUtil.getTableBackground(false);
            ((Graphics2D) g).setPaint(new GradientPaint(0, 0, ColorUtil.shift(bg, 1.4), 0, getHeight(), ColorUtil.shift(bg, 0.9)));
            g.fillRect(0, 0, getWidth(), getHeight());
        }
    };
    header.setBorder(new CustomLineBorder(1, 1, 0, 1));
    final JLabel mySortLabel = new JLabel();
    mySortLabel.setForeground(UIUtil.getLabelDisabledForeground());
    mySortLabel.setBorder(JBUI.Borders.empty(1, 1, 1, 5));
    mySortLabel.setIcon(AllIcons.General.SplitDown);
    mySortLabel.setHorizontalTextPosition(SwingConstants.LEADING);
    header.add(mySortLabel, BorderLayout.EAST);
    myTablePanel.add(header, BorderLayout.NORTH);
    myToolbarPanel.setLayout(new BorderLayout());
    myActionToolbar = ActionManager.getInstance().createActionToolbar("PluginManager", getActionGroup(true), true);
    final JComponent component = myActionToolbar.getComponent();
    myToolbarPanel.add(component, BorderLayout.CENTER);
    myToolbarPanel.add(myFilter, BorderLayout.WEST);
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent event, int clickCount) {
            JBPopupFactory.getInstance().createActionGroupPopup("Sort by:", createSortersGroup(), DataManager.getInstance().getDataContext(pluginTable), JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true).showUnderneathOf(mySortLabel);
            return true;
        }
    }.installOn(mySortLabel);
    final TableModelListener modelListener = new TableModelListener() {

        @Override
        public void tableChanged(TableModelEvent e) {
            String text = "Sort by:";
            if (pluginsModel.isSortByStatus()) {
                text += " status,";
            }
            if (pluginsModel.isSortByRating()) {
                text += " rating,";
            }
            if (pluginsModel.isSortByDownloads()) {
                text += " downloads,";
            }
            if (pluginsModel.isSortByUpdated()) {
                text += " updated,";
            }
            text += " name";
            mySortLabel.setText(text);
        }
    };
    pluginTable.getModel().addTableModelListener(modelListener);
    modelListener.tableChanged(null);
    myDescriptionScrollPane.setBackground(UIUtil.getTextFieldBackground());
    Border border = new BorderUIResource.LineBorderUIResource(new JBColor(Gray._220, Gray._55), 1);
    myInfoPanel.setBorder(border);
}
Also used : MouseEvent(java.awt.event.MouseEvent) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) CustomLineBorder(com.intellij.ui.border.CustomLineBorder) StyleSheet(javax.swing.text.html.StyleSheet) Border(javax.swing.border.Border) CustomLineBorder(com.intellij.ui.border.CustomLineBorder)

Example 10 with StyleSheet

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

the class DarculaLaf method patchStyledEditorKit.

@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
private void patchStyledEditorKit(UIDefaults defaults) {
    URL url = getClass().getResource(getPrefix() + (JBUI.isUsrHiDPI() ? "@2x.css" : ".css"));
    StyleSheet styleSheet = UIUtil.loadStyleSheet(url);
    defaults.put("StyledEditorKit.JBDefaultStyle", styleSheet);
    try {
        Field keyField = HTMLEditorKit.class.getDeclaredField("DEFAULT_STYLES_KEY");
        keyField.setAccessible(true);
        AppContext.getAppContext().put(keyField.get(null), UIUtil.loadStyleSheet(url));
    } catch (Exception e) {
        log(e);
    }
}
Also used : Field(java.lang.reflect.Field) StyleSheet(javax.swing.text.html.StyleSheet) URL(java.net.URL) IOException(java.io.IOException)

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