Example usage for com.intellij.openapi.ui DialogWrapper isModal

List of usage examples for com.intellij.openapi.ui DialogWrapper isModal

Introduction

In this page you can find the example usage for com.intellij.openapi.ui DialogWrapper isModal.

Prototype

public boolean isModal() 

Source Link

Usage

From source file:com.intellij.ui.BalloonImpl.java

License:Apache License

private static boolean hasModalDialog(MouseEvent e) {
    final Component c = e.getComponent();
    final DialogWrapper dialog = DialogWrapper.findInstance(c);
    return dialog != null && dialog.isModal();
}

From source file:com.mbeddr.pluginmanager.com.intellij.ide.plugins.PluginHeaderPanel.java

License:Apache License

private void createUIComponents() {
    myInstallButton = new JButton() {
        {/*from   ww w  .j  a va2  s .  c  o  m*/
            setOpaque(false);
            setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        }

        @Override
        public Dimension getPreferredSize() {
            final FontMetrics metrics = getFontMetrics(getFont());
            final int textWidth = metrics.stringWidth(getText());
            final int width = 8 + 16 + 4 + textWidth + 8;
            final int height = 2 + Math.max(16, metrics.getHeight()) + 2;
            return new Dimension(width, height);
        }

        @Override
        public void paint(Graphics g2) {
            final Graphics2D g = (Graphics2D) g2;
            final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
            final int w = g.getClipBounds().width;
            final int h = g.getClipBounds().height;

            g.setPaint(getBackgroundBorderPaint());
            g.fillRoundRect(0, 0, w, h, 7, 7);

            g.setPaint(getBackgroundPaint());
            g.fillRoundRect(1, 1, w - 2, h - 2, 6, 6);
            g.setColor(getButtonForeground());
            int offset = 8;
            g.drawString(getText(), offset + 16 + 4, getBaseline(w, h));
            getIcon().paintIcon(this, g, offset, (getHeight() - getIcon().getIconHeight()) / 2);
            config.restore();
        }

        private Color getButtonForeground() {
            switch (myActionId) {
            case UPDATE:
                return new JBColor(Gray._240, Gray._210);
            case INSTALL:
                return new JBColor(Gray._240, Gray._210);
            case RESTART:
            case UNINSTALL:
                return new JBColor(Gray._0, Gray._210);
            }

            return new JBColor(Gray._80, Gray._60);
        }

        private Paint getBackgroundPaint() {
            switch (myActionId) {
            case UPDATE:
                return new JBGradientPaint(this, new JBColor(new Color(98, 158, 225), new Color(98, 158, 225)),
                        new JBColor(new Color(58, 91, 181), new Color(58, 91, 181)));
            case INSTALL:
                return new JBGradientPaint(this, new JBColor(new Color(96, 204, 105), new Color(81, 149, 87)),
                        new JBColor(new Color(50, 101, 41), new Color(40, 70, 47)));
            case RESTART:
            case UNINSTALL:
                return UIUtil.isUnderDarcula()
                        ? new JBGradientPaint(this, UIManager.getColor("Button.darcula.color1"),
                                UIManager.getColor("Button.darcula.color2"))
                        : Gray._240;
            }
            return Gray._238;
        }

        private Paint getBackgroundBorderPaint() {
            switch (myActionId) {
            case UPDATE:
                return new JBColor(new Color(166, 180, 205), Gray._85);
            case INSTALL:
                return new JBColor(new Color(201, 223, 201), Gray._70);
            case RESTART:
            case UNINSTALL:
                return new JBColor(Gray._220, Gray._100.withAlpha(180));
            }
            return Gray._208;
        }

        @Override
        public String getText() {
            switch (myActionId) {
            case UPDATE:
                return "Update";
            case INSTALL:
                return "Install";
            case UNINSTALL:
                return "Uninstall";
            case RESTART:
                return "Restart " + ApplicationNamesInfo.getInstance().getFullProductName();
            }
            return super.getText();
        }

        @Override
        public Icon getIcon() {
            switch (myActionId) {
            case UPDATE:
                return AllIcons.General.DownloadPlugin;
            case INSTALL:
                return AllIcons.General.DownloadPlugin;
            case UNINSTALL:
                return AllIcons.Actions.Delete;
            case RESTART:
                return AllIcons.Actions.Restart;
            }
            return super.getIcon();

        }
    };
    myInstallButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            switch (myActionId) {
            case UPDATE:
            case INSTALL:
                new InstallPluginAction(myManager.getAvailable(), myManager.getInstalled())
                        .install(new Runnable() {
                            @Override
                            public void run() {
                                setPlugin(myPlugin);
                            }
                        }, true);
                break;
            case UNINSTALL:
                UninstallPluginAction.uninstall(myManager.getInstalled(), true, myPlugin);
                break;
            case RESTART:
                if (myManager != null) {
                    myManager.apply();
                }
                final DialogWrapper dialog = DialogWrapper
                        .findInstance(KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());
                if (dialog != null && dialog.isModal()) {
                    dialog.close(DialogWrapper.OK_EXIT_CODE);
                }
                //noinspection SSBasedInspection
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        final DialogWrapper settings = DialogWrapper
                                .findInstance(IdeFocusManager.findInstance().getFocusOwner());
                        if (settings instanceof SettingsDialog) {
                            ((SettingsDialog) settings).doOKAction();
                            ApplicationManager.getApplication().restart();
                        } else {
                            ApplicationManager.getApplication().restart();
                        }
                    }
                });
                break;
            }
            setPlugin(myPlugin);
        }
    });
}