Search in sources :

Example 1 with DarculaButtonUI

use of com.intellij.ide.ui.laf.darcula.ui.DarculaButtonUI in project intellij-community by JetBrains.

the class NotificationsManagerImpl method createButtons.

@Nullable
private static JPanel createButtons(@NotNull Notification notification, @NotNull final JPanel content, @Nullable HyperlinkListener listener) {
    if (notification instanceof NotificationActionProvider) {
        JPanel buttons = new JPanel(new HorizontalLayout(5));
        buttons.setOpaque(false);
        content.add(BorderLayout.SOUTH, buttons);
        final Ref<JButton> defaultButton = new Ref<>();
        NotificationActionProvider provider = (NotificationActionProvider) notification;
        for (NotificationActionProvider.Action action : provider.getActions(listener)) {
            JButton button = new JButton(action) {

                @Override
                public void setUI(ButtonUI ui) {
                    boolean isDarcula = ui instanceof DarculaButtonUI && UIUtil.isUnderDarcula();
                    if (isDarcula) {
                        ui = new DarculaButtonUI() {

                            @Override
                            protected Color getButtonColor1() {
                                return new ColorUIResource(0x464b4c);
                            }

                            @Override
                            protected Color getButtonColor2() {
                                return new ColorUIResource(0x383c3d);
                            }
                        };
                    }
                    super.setUI(ui);
                    if (isDarcula) {
                        setBorder(new DarculaButtonPainter() {

                            @Override
                            protected Color getBorderColor() {
                                return new ColorUIResource(0x616263);
                            }
                        });
                    }
                }
            };
            button.setOpaque(false);
            if (action.isDefaultAction()) {
                defaultButton.setIfNull(button);
            }
            buttons.add(HorizontalLayout.RIGHT, button);
        }
        if (!defaultButton.isNull()) {
            UIUtil.addParentChangeListener(content, new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent event) {
                    if (event.getOldValue() == null && event.getNewValue() != null) {
                        UIUtil.removeParentChangeListener(content, this);
                        JRootPane rootPane = UIUtil.getRootPane(content);
                        if (rootPane != null) {
                            rootPane.setDefaultButton(defaultButton.get());
                        }
                    }
                }
            });
        }
        return buttons;
    }
    return null;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) DarculaButtonPainter(com.intellij.ide.ui.laf.darcula.ui.DarculaButtonPainter) ButtonUI(javax.swing.plaf.ButtonUI) DarculaButtonUI(com.intellij.ide.ui.laf.darcula.ui.DarculaButtonUI) ColorUIResource(javax.swing.plaf.ColorUIResource) HorizontalLayout(com.intellij.ui.components.panels.HorizontalLayout) Ref(com.intellij.openapi.util.Ref) DarculaButtonUI(com.intellij.ide.ui.laf.darcula.ui.DarculaButtonUI) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

DarculaButtonPainter (com.intellij.ide.ui.laf.darcula.ui.DarculaButtonPainter)1 DarculaButtonUI (com.intellij.ide.ui.laf.darcula.ui.DarculaButtonUI)1 Ref (com.intellij.openapi.util.Ref)1 HorizontalLayout (com.intellij.ui.components.panels.HorizontalLayout)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 ButtonUI (javax.swing.plaf.ButtonUI)1 ColorUIResource (javax.swing.plaf.ColorUIResource)1 Nullable (org.jetbrains.annotations.Nullable)1