Search in sources :

Example 1 with HTMLEditorKit

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

the class HtmlCopyPastePreProcessor method convertFromRtfStream.

private static String convertFromRtfStream(InputStream stream) {
    final DefaultStyledDocument document = new DefaultStyledDocument();
    try {
        new RTFEditorKit().read(stream, document, 0);
        final StringWriter writer = new StringWriter();
        new HTMLEditorKit().write(writer, document, 0, document.getLength());
        return writer.toString();
    } catch (IOException | BadLocationException e) {
        LOG.error(e);
    }
    return null;
}
Also used : StringWriter(java.io.StringWriter) RTFEditorKit(javax.swing.text.rtf.RTFEditorKit) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) IOException(java.io.IOException) DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) BadLocationException(javax.swing.text.BadLocationException)

Example 2 with HTMLEditorKit

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

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

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

the class JBTabsDemo method main.

public static void main(String[] args) {
    System.out.println("JBTabs.main");
    IconLoader.activate();
    final JFrame frame = new JFrame();
    frame.getContentPane().setLayout(new BorderLayout(0, 0));
    final int[] count = new int[1];
    final JBTabsImpl tabs = new JBTabsImpl(null, ActionManager.getInstance(), null, Disposer.newDisposable());
    tabs.setTestMode(true);
    //final JPanel flow = new JPanel(new FlowLayout(FlowLayout.CENTER));
    //frame.getContentPane().add(flow);
    //flow.add(tabs.getComponent());
    frame.getContentPane().add(tabs.getComponent(), BorderLayout.CENTER);
    JPanel south = new JPanel(new FlowLayout());
    south.setOpaque(true);
    south.setBackground(Color.white);
    final JComboBox pos = new JComboBox(new Object[] { JBTabsPosition.top, JBTabsPosition.left, JBTabsPosition.right, JBTabsPosition.bottom });
    pos.setSelectedIndex(0);
    south.add(pos);
    pos.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            final JBTabsPosition p = (JBTabsPosition) pos.getSelectedItem();
            if (p != null) {
                tabs.getPresentation().setTabsPosition(p);
            }
        }
    });
    final JCheckBox bb = new JCheckBox("Buffered", true);
    bb.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            tabs.setUseBufferedPaint(bb.isSelected());
        }
    });
    south.add(bb);
    final JCheckBox f = new JCheckBox("Focused");
    f.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            tabs.setFocused(f.isSelected());
        }
    });
    south.add(f);
    final JCheckBox v = new JCheckBox("Vertical");
    v.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            tabs.setSideComponentVertical(v.isSelected());
        }
    });
    south.add(v);
    final JCheckBox row = new JCheckBox("Single row", true);
    row.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            tabs.setSingleRow(row.isSelected());
        }
    });
    south.add(row);
    final JCheckBox ghosts = new JCheckBox("Ghosts always visible", false);
    ghosts.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            tabs.setGhostsAlwaysVisible(ghosts.isSelected());
        }
    });
    south.add(ghosts);
    final JCheckBox stealth = new JCheckBox("Stealth tab", tabs.isStealthTabMode());
    stealth.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            tabs.setStealthTabMode(stealth.isSelected());
        }
    });
    south.add(stealth);
    final JCheckBox hide = new JCheckBox("Hide tabs", tabs.isHideTabs());
    hide.addItemListener(new ItemListener() {

        public void itemStateChanged(final ItemEvent e) {
            tabs.setHideTabs(hide.isSelected());
        }
    });
    south.add(hide);
    frame.getContentPane().add(south, BorderLayout.SOUTH);
    tabs.addListener(new TabsListener.Adapter() {

        public void selectionChanged(final TabInfo oldSelection, final TabInfo newSelection) {
            System.out.println("TabsWithActions.selectionChanged old=" + oldSelection + " new=" + newSelection);
        }
    });
    final JTree someTree = new Tree() {

        public void addNotify() {
            //To change body of overridden methods use File | Settings | File Templates.
            super.addNotify();
            System.out.println("JBTabs.addNotify");
        }

        public void removeNotify() {
            System.out.println("JBTabs.removeNotify");
            //To change body of overridden methods use File | Settings | File Templates.
            super.removeNotify();
        }
    };
    //someTree.setBorder(new LineBorder(Color.cyan));
    tabs.addTab(new TabInfo(someTree)).setText("Tree1").setActions(new DefaultActionGroup(), null).setIcon(AllIcons.Debugger.Frame);
    final JTree component = new Tree();
    final TabInfo toAnimate1 = new TabInfo(component);
    //toAnimate1.setIcon(IconLoader.getIcon("/debugger/console.png"));
    final JCheckBox attract1 = new JCheckBox("Attract 1");
    attract1.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            if (attract1.isSelected()) {
                toAnimate1.fireAlert();
            } else {
                toAnimate1.stopAlerting();
            }
        }
    });
    south.add(attract1);
    final JCheckBox hide1 = new JCheckBox("Hide 1", toAnimate1.isHidden());
    hide1.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            toAnimate1.setHidden(!toAnimate1.isHidden());
        }
    });
    south.add(hide1);
    final JCheckBox block = new JCheckBox("Block", false);
    block.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            tabs.setPaintBlocked(!block.isSelected(), true);
        }
    });
    south.add(block);
    final JCheckBox fill = new JCheckBox("Tab fill in", true);
    fill.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            tabs.getPresentation().setActiveTabFillIn(fill.isSelected() ? Color.white : null);
        }
    });
    south.add(fill);
    final JButton refire = new JButton("Re-fire attraction");
    refire.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            toAnimate1.fireAlert();
        }
    });
    south.add(refire);
    final JEditorPane text = new JEditorPane();
    text.setEditorKit(new HTMLEditorKit());
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < 50; i++) {
        buffer.append("1234567890abcdefghijklmnopqrstv1234567890abcdefghijklmnopqrstv1234567890abcdefghijklmnopqrstv<br>");
    }
    text.setText(buffer.toString());
    final JLabel tb = new JLabel("Side comp");
    tb.setBorder(new LineBorder(Color.red));
    tabs.addTab(new TabInfo(ScrollPaneFactory.createScrollPane(text)).setSideComponent(tb)).setText("Text text text");
    tabs.addTab(toAnimate1).append("Tree2", new SimpleTextAttributes(SimpleTextAttributes.STYLE_WAVED, Color.black, Color.red));
    tabs.addTab(new TabInfo(new JTable())).setText("Table 1").setActions(new DefaultActionGroup(), null);
    tabs.addTab(new TabInfo(new JTable())).setText("Table 2").setActions(new DefaultActionGroup(), null);
    tabs.addTab(new TabInfo(new JTable())).setText("Table 3").setActions(new DefaultActionGroup(), null);
    tabs.addTab(new TabInfo(new JTable())).setText("Table 4").setActions(new DefaultActionGroup(), null);
    tabs.addTab(new TabInfo(new JTable())).setText("Table 5").setActions(new DefaultActionGroup(), null);
    tabs.addTab(new TabInfo(new JTable())).setText("Table 6").setActions(new DefaultActionGroup(), null);
    tabs.addTab(new TabInfo(new JTable())).setText("Table 7").setActions(new DefaultActionGroup(), null);
    tabs.addTab(new TabInfo(new JTable())).setText("Table 8").setActions(new DefaultActionGroup(), null);
    tabs.addTab(new TabInfo(new JTable())).setText("Table 9").setActions(new DefaultActionGroup(), null);
    //tabs.getComponent().setBorder(new EmptyBorder(5, 5, 5, 5));
    tabs.setTabSidePaintBorder(5);
    tabs.setPaintBorder(1, 1, 1, 1);
    tabs.getPresentation().setActiveTabFillIn(Color.white);
    tabs.setGhostsAlwaysVisible(true);
    //tabs.setBorder(new LineBorder(Color.blue, 5));
    tabs.setBorder(new EmptyBorder(30, 30, 30, 30));
    tabs.setUiDecorator(new UiDecorator() {

        public UiDecoration getDecoration() {
            return new UiDecoration(null, new Insets(0, -1, 0, -1));
        }
    });
    tabs.setStealthTabMode(true);
    frame.setBounds(1400, 200, 1000, 800);
    frame.show();
}
Also used : JBTabsPosition(com.intellij.ui.tabs.JBTabsPosition) ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) LineBorder(javax.swing.border.LineBorder) TabsListener(com.intellij.ui.tabs.TabsListener) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) Tree(com.intellij.ui.treeStructure.Tree) TabInfo(com.intellij.ui.tabs.TabInfo) EmptyBorder(javax.swing.border.EmptyBorder) UiDecorator(com.intellij.ui.tabs.UiDecorator) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) ActionListener(java.awt.event.ActionListener) ItemListener(java.awt.event.ItemListener)

Example 5 with HTMLEditorKit

use of javax.swing.text.html.HTMLEditorKit 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)

Aggregations

HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)47 HTMLDocument (javax.swing.text.html.HTMLDocument)18 JEditorPane (javax.swing.JEditorPane)10 StyleSheet (javax.swing.text.html.StyleSheet)9 IOException (java.io.IOException)8 JScrollPane (javax.swing.JScrollPane)8 Dimension (java.awt.Dimension)7 URL (java.net.URL)7 Document (javax.swing.text.Document)6 MouseEvent (java.awt.event.MouseEvent)5 StringReader (java.io.StringReader)5 HyperlinkEvent (javax.swing.event.HyperlinkEvent)5 ActionListener (java.awt.event.ActionListener)4 HyperlinkListener (javax.swing.event.HyperlinkListener)4 BorderLayout (java.awt.BorderLayout)3 ActionEvent (java.awt.event.ActionEvent)3 InputStream (java.io.InputStream)3 BadLocationException (javax.swing.text.BadLocationException)3 MouseAdapter (java.awt.event.MouseAdapter)2 InputStreamReader (java.io.InputStreamReader)2