Example usage for com.intellij.openapi.actionSystem ActionPlaces JAVADOC_TOOLBAR

List of usage examples for com.intellij.openapi.actionSystem ActionPlaces JAVADOC_TOOLBAR

Introduction

In this page you can find the example usage for com.intellij.openapi.actionSystem ActionPlaces JAVADOC_TOOLBAR.

Prototype

String JAVADOC_TOOLBAR

To view the source code for com.intellij.openapi.actionSystem ActionPlaces JAVADOC_TOOLBAR.

Click Source Link

Usage

From source file:com.gogh.plugin.ui.TranslationComponent.java

License:Apache License

public TranslationComponent(final TranslationManager manager, final AnAction[] additionalActions) {
    myManager = manager;/* w  ww.ja  va 2  s  .  c  om*/
    myIsEmpty = true;
    myIsShown = false;

    myEditorPane = new JEditorPane(UIUtil.HTML_MIME, "") {
        @Override
        public Dimension getPreferredScrollableViewportSize() {
            int em = myEditorPane.getFont().getSize();
            int prefWidth = PREFERRED_WIDTH_EM * em;
            int prefHeightMin = PREFERRED_HEIGHT_MIN_EM * em;
            int prefHeightMax = PREFERRED_HEIGHT_MAX_EM * em;

            if (getWidth() == 0 || getHeight() == 0) {
                setSize(prefWidth, prefHeightMax);
            }

            Insets ins = myEditorPane.getInsets();
            View rootView = myEditorPane.getUI().getRootView(myEditorPane);
            rootView.setSize(prefWidth, prefHeightMax); // Necessary! Without this line, the size won't increase when the content does

            int prefHeight = (int) rootView.getPreferredSpan(View.Y_AXIS) + ins.bottom + ins.top
                    + myScrollPane.getHorizontalScrollBar().getMaximumSize().height;

            prefHeight = Math.max(prefHeightMin, Math.min(prefHeightMax, prefHeight));
            return new Dimension(prefWidth, prefHeight);
        }

        {
            enableEvents(AWTEvent.KEY_EVENT_MASK);
        }

        @Override
        protected void processKeyEvent(KeyEvent e) {
            KeyStroke keyStroke = KeyStroke.getKeyStrokeForEvent(e);
            ActionListener listener = myKeyboardActions.get(keyStroke);
            if (listener != null) {
                listener.actionPerformed(new ActionEvent(TranslationComponent.this, 0, ""));
                e.consume();
                return;
            }
            super.processKeyEvent(e);
        }

        @Override
        public void paintComponents(Graphics g) {
            GraphicsUtil.setupAntialiasing(g);
            super.paintComponents(g);
        }
    };

    myText = "";
    myEditorPane.setEditable(false);
    myEditorPane.setBackground(HintUtil.INFORMATION_COLOR);
    myEditorPane.setEditorKit(UIUtil.getHTMLEditorKit(false));

    myScrollPane = new JBScrollPane(myEditorPane) {
        @Override
        protected void processMouseWheelEvent(MouseWheelEvent e) {
            if (!EditorSettingsExternalizable.getInstance().isWheelFontChangeEnabled()
                    || !EditorUtil.isChangeFontSize(e)) {
                super.processMouseWheelEvent(e);
                return;
            }

            int change = Math.abs(e.getWheelRotation());
            boolean increase = e.getWheelRotation() <= 0;
            EditorColorsManager colorsManager = EditorColorsManager.getInstance();
            EditorColorsScheme scheme = colorsManager.getGlobalScheme();
            FontSize newFontSize = scheme.getQuickDocFontSize();
            for (; change > 0; change--) {
                if (increase) {
                    newFontSize = newFontSize.larger();
                } else {
                    newFontSize = newFontSize.smaller();
                }
            }

            if (newFontSize == scheme.getQuickDocFontSize()) {
                return;
            }

            scheme.setQuickDocFontSize(newFontSize);
            //            applyFontSize();
            setFontSizeSliderSize(newFontSize);
        }
    };

    myScrollPane.setBorder(null);

    final MouseListener mouseAdapter = new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            myShowSettingsButton.hideSettings();
        }
    };
    myEditorPane.addMouseListener(mouseAdapter);

    Disposer.register(this, () -> myEditorPane.removeMouseListener(mouseAdapter));

    final FocusListener focusAdapter = new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            Component previouslyFocused = WindowManagerEx.getInstanceEx()
                    .getFocusedComponent(manager.getProject());

            if (previouslyFocused != myEditorPane) {
                if (myHint != null && !myHint.isDisposed()) {
                    myHint.cancel();
                }
            }
        }
    };
    myEditorPane.addFocusListener(focusAdapter);

    Disposer.register(this, () -> myEditorPane.removeFocusListener(focusAdapter));

    setLayout(new BorderLayout());
    JLayeredPane layeredPane = new JBLayeredPane() {
        @Override
        public void doLayout() {
            final Rectangle r = getBounds();
            for (Component component : getComponents()) {
                if (component instanceof JScrollPane) {
                    component.setBounds(0, 0, r.width, r.height);
                } else {
                    int insets = 2;
                    Dimension d = component.getPreferredSize();
                    component.setBounds(r.width - d.width - insets, insets, d.width, d.height);
                }
            }
        }

        @Override
        public Dimension getPreferredSize() {
            Dimension editorPaneSize = myEditorPane.getPreferredScrollableViewportSize();
            Dimension controlPanelSize = myControlPanel.getPreferredSize();
            return getSize(editorPaneSize, controlPanelSize);
        }

        @Override
        public Dimension getMinimumSize() {
            Dimension editorPaneSize = new JBDimension(20, 20);
            Dimension controlPanelSize = myControlPanel.getMinimumSize();
            return getSize(editorPaneSize, controlPanelSize);
        }

        private Dimension getSize(Dimension editorPaneSize, Dimension controlPanelSize) {
            return new Dimension(Math.max(editorPaneSize.width, controlPanelSize.width),
                    editorPaneSize.height + controlPanelSize.height);
        }
    };
    layeredPane.add(myScrollPane);
    layeredPane.setLayer(myScrollPane, 0);

    mySettingsPanel = createSettingsPanel();
    layeredPane.add(mySettingsPanel);
    layeredPane.setLayer(mySettingsPanel, JLayeredPane.POPUP_LAYER);
    add(layeredPane, BorderLayout.CENTER);
    setOpaque(true);
    myScrollPane.setViewportBorder(JBScrollPane.createIndentBorder());

    final DefaultActionGroup actions = new DefaultActionGroup();
    actions.add(myExternalTranslationAction = new ExternalTranslationAction());

    myExternalTranslationAction.registerCustomShortcutSet(CustomShortcutSet.fromString("UP"), this);

    if (additionalActions != null) {
        for (final AnAction action : additionalActions) {
            actions.add(action);
            ShortcutSet shortcutSet = action.getShortcutSet();
            if (shortcutSet != null) {
                action.registerCustomShortcutSet(shortcutSet, this);
            }
        }
    }

    myToolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.JAVADOC_TOOLBAR, actions, true);

    myControlPanel = new JPanel(new BorderLayout(5, 5));
    myControlPanel.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));

    myTranslatorLabel = new JLabel();
    myTranslatorLabel.setMinimumSize(new Dimension(100, 0)); // do not recalculate size according to the text

    myControlPanel.add(myToolBar.getComponent(), BorderLayout.WEST);
    myControlPanel.add(myTranslatorLabel, BorderLayout.CENTER);
    myControlPanel.add(myShowSettingsButton = new MyShowSettingsButton(), BorderLayout.EAST);
    myControlPanelVisible = false;

    registerActions();

    updateControlState();
}

From source file:com.intellij.codeInsight.documentation.DocumentationComponent.java

License:Apache License

public DocumentationComponent(final DocumentationManager manager, final AnAction[] additionalActions) {
    myManager = manager;//from   ww  w.  ja va  2  s . c o m
    myIsEmpty = true;
    myIsShown = false;

    myEditorPane = new JEditorPane(UIUtil.HTML_MIME, "") {
        @Override
        public EditorKit getEditorKit() {
            return new HTMLEditorKit();
        }

        @Override
        public Dimension getPreferredScrollableViewportSize() {
            int em = myEditorPane.getFont().getSize();
            int prefWidth = PREFERRED_WIDTH_EM * em;
            int prefHeightMin = PREFERRED_HEIGHT_MIN_EM * em;
            int prefHeightMax = PREFERRED_HEIGHT_MAX_EM * em;

            if (getWidth() == 0 || getHeight() == 0) {
                setSize(prefWidth, prefHeightMax);
            }

            Insets ins = myEditorPane.getInsets();
            View rootView = myEditorPane.getUI().getRootView(myEditorPane);
            rootView.setSize(prefWidth, prefHeightMax); // Necessary! Without this line, the size won't increase when the content does

            int prefHeight = (int) rootView.getPreferredSpan(View.Y_AXIS) + ins.bottom + ins.top
                    + myScrollPane.getHorizontalScrollBar().getMaximumSize().height;
            prefHeight = Math.max(prefHeightMin, Math.min(prefHeightMax, prefHeight));
            return new Dimension(prefWidth, prefHeight);
        }

        {
            enableEvents(AWTEvent.KEY_EVENT_MASK);
        }

        @Override
        protected void processKeyEvent(KeyEvent e) {
            KeyStroke keyStroke = KeyStroke.getKeyStrokeForEvent(e);
            ActionListener listener = myKeyboardActions.get(keyStroke);
            if (listener != null) {
                listener.actionPerformed(new ActionEvent(DocumentationComponent.this, 0, ""));
                e.consume();
                return;
            }
            super.processKeyEvent(e);
        }

        @Override
        protected void paintComponent(Graphics g) {
            GraphicsUtil.setupAntialiasing(g);
            super.paintComponent(g);
        }

        @Override
        public void setDocument(Document doc) {
            super.setDocument(doc);
            if (doc instanceof StyledDocument) {
                doc.putProperty("imageCache", myImageProvider);
            }
        }
    };
    DataProvider helpDataProvider = new DataProvider() {
        @Override
        public Object getData(@NonNls String dataId) {
            return PlatformDataKeys.HELP_ID.is(dataId) ? DOCUMENTATION_TOPIC_ID : null;
        }
    };
    myEditorPane.putClientProperty(DataManager.CLIENT_PROPERTY_DATA_PROVIDER, helpDataProvider);
    myText = "";
    myEditorPane.setEditable(false);
    myEditorPane.setBackground(HintUtil.INFORMATION_COLOR);
    myEditorPane.setEditorKit(UIUtil.getHTMLEditorKit());
    myScrollPane = new JBScrollPane(myEditorPane) {
        @Override
        protected void processMouseWheelEvent(MouseWheelEvent e) {
            if (!EditorSettingsExternalizable.getInstance().isWheelFontChangeEnabled()
                    || !EditorUtil.isChangeFontSize(e)) {
                super.processMouseWheelEvent(e);
                return;
            }

            int change = Math.abs(e.getWheelRotation());
            boolean increase = e.getWheelRotation() <= 0;
            EditorColorsManager colorsManager = EditorColorsManager.getInstance();
            EditorColorsScheme scheme = colorsManager.getGlobalScheme();
            FontSize newFontSize = scheme.getQuickDocFontSize();
            for (; change > 0; change--) {
                if (increase) {
                    newFontSize = newFontSize.larger();
                } else {
                    newFontSize = newFontSize.smaller();
                }
            }

            if (newFontSize == scheme.getQuickDocFontSize()) {
                return;
            }

            scheme.setQuickDocFontSize(newFontSize);
            applyFontSize();
            setFontSizeSliderSize(newFontSize);
        }
    };
    myScrollPane.setBorder(null);
    myScrollPane.putClientProperty(DataManager.CLIENT_PROPERTY_DATA_PROVIDER, helpDataProvider);

    final MouseAdapter mouseAdapter = new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            myManager.requestFocus();
            myShowSettingsButton.hideSettings();
        }
    };
    myEditorPane.addMouseListener(mouseAdapter);
    Disposer.register(this, new Disposable() {
        @Override
        public void dispose() {
            myEditorPane.removeMouseListener(mouseAdapter);
        }
    });

    final FocusAdapter focusAdapter = new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            Component previouslyFocused = WindowManagerEx.getInstanceEx()
                    .getFocusedComponent(manager.getProject(getElement()));

            if (!(previouslyFocused == myEditorPane)) {
                if (myHint != null && !myHint.isDisposed())
                    myHint.cancel();
            }
        }
    };
    myEditorPane.addFocusListener(focusAdapter);

    Disposer.register(this, new Disposable() {
        @Override
        public void dispose() {
            myEditorPane.removeFocusListener(focusAdapter);
        }
    });

    setLayout(new BorderLayout());
    JLayeredPane layeredPane = new JBLayeredPane() {
        @Override
        public void doLayout() {
            final Rectangle r = getBounds();
            for (Component component : getComponents()) {
                if (component instanceof JScrollPane) {
                    component.setBounds(0, 0, r.width, r.height);
                } else {
                    int insets = 2;
                    Dimension d = component.getPreferredSize();
                    component.setBounds(r.width - d.width - insets, insets, d.width, d.height);
                }
            }
        }

        @Override
        public Dimension getPreferredSize() {
            Dimension editorPaneSize = myEditorPane.getPreferredScrollableViewportSize();
            Dimension controlPanelSize = myControlPanel.getPreferredSize();
            return new Dimension(Math.max(editorPaneSize.width, controlPanelSize.width),
                    editorPaneSize.height + controlPanelSize.height);
        }
    };
    layeredPane.add(myScrollPane);
    layeredPane.setLayer(myScrollPane, 0);

    mySettingsPanel = createSettingsPanel();
    layeredPane.add(mySettingsPanel);
    layeredPane.setLayer(mySettingsPanel, JLayeredPane.POPUP_LAYER);
    add(layeredPane, BorderLayout.CENTER);
    setOpaque(true);
    myScrollPane.setViewportBorder(JBScrollPane.createIndentBorder());

    final DefaultActionGroup actions = new DefaultActionGroup();
    final BackAction back = new BackAction();
    final ForwardAction forward = new ForwardAction();
    EditDocumentationSourceAction edit = new EditDocumentationSourceAction();
    actions.add(back);
    actions.add(forward);
    actions.add(myExternalDocAction = new ExternalDocAction());
    actions.add(edit);

    back.registerCustomShortcutSet(CustomShortcutSet.fromString("LEFT"), this);
    forward.registerCustomShortcutSet(CustomShortcutSet.fromString("RIGHT"), this);
    myExternalDocAction.registerCustomShortcutSet(CustomShortcutSet.fromString("UP"), this);
    edit.registerCustomShortcutSet(CommonShortcuts.getEditSource(), this);
    if (additionalActions != null) {
        for (final AnAction action : additionalActions) {
            actions.add(action);
            ShortcutSet shortcutSet = action.getShortcutSet();
            if (shortcutSet != null) {
                action.registerCustomShortcutSet(shortcutSet, this);
            }
        }
    }

    myToolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.JAVADOC_TOOLBAR, actions, true);

    myControlPanel = new JPanel(new BorderLayout(5, 5));
    myControlPanel.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));

    myElementLabel = new JLabel();
    myElementLabel.setMinimumSize(new Dimension(100, 0)); // do not recalculate size according to the text

    myControlPanel.add(myToolBar.getComponent(), BorderLayout.WEST);
    myControlPanel.add(myElementLabel, BorderLayout.CENTER);
    myControlPanel.add(myShowSettingsButton = new MyShowSettingsButton(), BorderLayout.EAST);
    myControlPanelVisible = false;

    final HyperlinkListener hyperlinkListener = new HyperlinkListener() {
        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            HyperlinkEvent.EventType type = e.getEventType();
            if (type == HyperlinkEvent.EventType.ACTIVATED) {
                manager.navigateByLink(DocumentationComponent.this, e.getDescription());
            }
        }
    };
    myEditorPane.addHyperlinkListener(hyperlinkListener);
    Disposer.register(this, new Disposable() {
        @Override
        public void dispose() {
            myEditorPane.removeHyperlinkListener(hyperlinkListener);
        }
    });

    registerActions();

    updateControlState();
}

From source file:com.intellij.translation.TranslationComponent.java

License:Apache License

public TranslationComponent(final TranslationManager manager, final AnAction[] additionalActions) {
    myManager = manager;//from w w  w.  j  ava 2  s.  co  m
    myIsEmpty = true;
    myIsShown = false;

    myEditorPane = new JEditorPane(UIUtil.HTML_MIME, "") {
        @Override
        public Dimension getPreferredScrollableViewportSize() {
            int em = myEditorPane.getFont().getSize();
            int prefWidth = PREFERRED_WIDTH_EM * em;
            int prefHeightMin = PREFERRED_HEIGHT_MIN_EM * em;
            int prefHeightMax = PREFERRED_HEIGHT_MAX_EM * em;

            if (getWidth() == 0 || getHeight() == 0) {
                setSize(prefWidth, prefHeightMax);
            }

            Insets ins = myEditorPane.getInsets();
            View rootView = myEditorPane.getUI().getRootView(myEditorPane);
            rootView.setSize(prefWidth, prefHeightMax); // Necessary! Without this line, the size won't increase when the content does

            int prefHeight = (int) rootView.getPreferredSpan(View.Y_AXIS) + ins.bottom + ins.top
                    + myScrollPane.getHorizontalScrollBar().getMaximumSize().height;

            prefHeight = Math.max(prefHeightMin, Math.min(prefHeightMax, prefHeight));
            return new Dimension(prefWidth, prefHeight);
        }

        {
            enableEvents(AWTEvent.KEY_EVENT_MASK);
        }

        @Override
        protected void processKeyEvent(KeyEvent e) {
            KeyStroke keyStroke = KeyStroke.getKeyStrokeForEvent(e);
            ActionListener listener = myKeyboardActions.get(keyStroke);
            if (listener != null) {
                listener.actionPerformed(new ActionEvent(TranslationComponent.this, 0, ""));
                e.consume();
                return;
            }
            super.processKeyEvent(e);
        }

        @Override
        public void paintComponents(Graphics g) {
            GraphicsUtil.setupAntialiasing(g);
            super.paintComponents(g);
        }
    };

    myText = "";
    myEditorPane.setEditable(false);
    myEditorPane.setBackground(HintUtil.INFORMATION_COLOR);
    myEditorPane.setEditorKit(UIUtil.getHTMLEditorKit(false));

    myScrollPane = new JBScrollPane(myEditorPane) {
        @Override
        protected void processMouseWheelEvent(MouseWheelEvent e) {
            if (!EditorSettingsExternalizable.getInstance().isWheelFontChangeEnabled()
                    || !EditorUtil.isChangeFontSize(e)) {
                super.processMouseWheelEvent(e);
                return;
            }

            int change = Math.abs(e.getWheelRotation());
            boolean increase = e.getWheelRotation() <= 0;
            EditorColorsManager colorsManager = EditorColorsManager.getInstance();
            EditorColorsScheme scheme = colorsManager.getGlobalScheme();
            FontSize newFontSize = scheme.getQuickDocFontSize();
            for (; change > 0; change--) {
                if (increase) {
                    newFontSize = newFontSize.larger();
                } else {
                    newFontSize = newFontSize.smaller();
                }
            }

            if (newFontSize == scheme.getQuickDocFontSize()) {
                return;
            }

            scheme.setQuickDocFontSize(newFontSize);
            applyFontSize();
            setFontSizeSliderSize(newFontSize);
        }
    };

    myScrollPane.setBorder(null);

    final MouseListener mouseAdapter = new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            myShowSettingsButton.hideSettings();
        }
    };
    myEditorPane.addMouseListener(mouseAdapter);

    Disposer.register(this, () -> myEditorPane.removeMouseListener(mouseAdapter));

    final FocusListener focusAdapter = new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            Component previouslyFocused = WindowManagerEx.getInstanceEx()
                    .getFocusedComponent(manager.getProject());

            if (previouslyFocused != myEditorPane) {
                if (myHint != null && !myHint.isDisposed()) {
                    myHint.cancel();
                }
            }
        }
    };
    myEditorPane.addFocusListener(focusAdapter);

    Disposer.register(this, () -> myEditorPane.removeFocusListener(focusAdapter));

    setLayout(new BorderLayout());
    JLayeredPane layeredPane = new JBLayeredPane() {
        @Override
        public void doLayout() {
            final Rectangle r = getBounds();
            for (Component component : getComponents()) {
                if (component instanceof JScrollPane) {
                    component.setBounds(0, 0, r.width, r.height);
                } else {
                    int insets = 2;
                    Dimension d = component.getPreferredSize();
                    component.setBounds(r.width - d.width - insets, insets, d.width, d.height);
                }
            }
        }

        @Override
        public Dimension getPreferredSize() {
            Dimension editorPaneSize = myEditorPane.getPreferredScrollableViewportSize();
            Dimension controlPanelSize = myControlPanel.getPreferredSize();
            return getSize(editorPaneSize, controlPanelSize);
        }

        @Override
        public Dimension getMinimumSize() {
            Dimension editorPaneSize = new JBDimension(20, 20);
            Dimension controlPanelSize = myControlPanel.getMinimumSize();
            return getSize(editorPaneSize, controlPanelSize);
        }

        private Dimension getSize(Dimension editorPaneSize, Dimension controlPanelSize) {
            return new Dimension(Math.max(editorPaneSize.width, controlPanelSize.width),
                    editorPaneSize.height + controlPanelSize.height);
        }
    };
    layeredPane.add(myScrollPane);
    layeredPane.setLayer(myScrollPane, 0);

    mySettingsPanel = createSettingsPanel();
    layeredPane.add(mySettingsPanel);
    layeredPane.setLayer(mySettingsPanel, JLayeredPane.POPUP_LAYER);
    add(layeredPane, BorderLayout.CENTER);
    setOpaque(true);
    myScrollPane.setViewportBorder(JBScrollPane.createIndentBorder());

    final DefaultActionGroup actions = new DefaultActionGroup();
    actions.add(myExternalTranslationAction = new ExternalTranslationAction());

    myExternalTranslationAction.registerCustomShortcutSet(CustomShortcutSet.fromString("UP"), this);

    if (additionalActions != null) {
        for (final AnAction action : additionalActions) {
            actions.add(action);
            ShortcutSet shortcutSet = action.getShortcutSet();
            if (shortcutSet != null) {
                action.registerCustomShortcutSet(shortcutSet, this);
            }
        }
    }

    myToolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.JAVADOC_TOOLBAR, actions, true);

    myControlPanel = new JPanel(new BorderLayout(5, 5));
    myControlPanel.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));

    myTranslatorLabel = new JLabel();
    myTranslatorLabel.setMinimumSize(new Dimension(100, 0)); // do not recalculate size according to the text

    myControlPanel.add(myToolBar.getComponent(), BorderLayout.WEST);
    myControlPanel.add(myTranslatorLabel, BorderLayout.CENTER);
    myControlPanel.add(myShowSettingsButton = new MyShowSettingsButton(), BorderLayout.EAST);
    myControlPanelVisible = false;

    registerActions();

    updateControlState();
}