Example usage for com.intellij.openapi.wm IdeFrame getComponent

List of usage examples for com.intellij.openapi.wm IdeFrame getComponent

Introduction

In this page you can find the example usage for com.intellij.openapi.wm IdeFrame getComponent.

Prototype

JComponent getComponent();

Source Link

Usage

From source file:automation.commands.ParkMouseCommand.java

License:Apache License

@Override
public void process(final Queue<Command> script) throws Exception {

    //Project View item name
    final IdeFrame ideFrame = IdeFocusManager.findInstance().getLastFocusedFrame();
    final RobotControl rc = RobotControlManager.getInstance().getRobotControl();

    switch (myPosition) {
    case CENTER://from   w w w. ja v  a  2  s  .  c o  m
        rc.navigateAndClick(ideFrame.getComponent(), runNext(script));
        break;
    }

}

From source file:com.chrisrm.idea.notifications.Notify.java

License:Open Source License

/**
 * Show a notification using the Balloon API instead of the bus
 * Credit to @vladsch/*  w ww.j a v  a2s  .  c om*/
 *
 * @param project      the project to display into
 * @param notification the notification to display
 */
private static void showFullNotification(final Project project, final Notification notification) {
    {
        final IdeFrame frame = WindowManager.getInstance().getIdeFrame(project);
        final Rectangle bounds = frame.getComponent().getBounds();
        final RelativePoint target = new RelativePoint(new Point(bounds.x + bounds.width, 0));

        try {
            // Create a notification balloon using the manager
            final Balloon balloon = NotificationsManagerImpl.createBalloon(frame, notification, true, true,
                    BalloonLayoutData.fullContent(), () -> {
                    });
            // Display the balloon at the top right
            balloon.show(target, Balloon.Position.atLeft);
        } catch (final NoSuchMethodError | NoClassDefFoundError | NoSuchFieldError e) {
            notification.notify(project);
        }
    }
}

From source file:com.codeflections.typengo.CommandInputForm.java

License:Open Source License

private void centerOnIdeFrameOrScreen(@NotNull AnActionEvent actionEvent) {
    WindowManagerEx windowManager = WindowManagerEx.getInstanceEx();
    IdeFrame frame = windowManager.getFrame(actionEvent.getProject());
    int x = 0;//from ww w. j a va2 s  .  c  o m
    int y = 0;
    if (frame != null) {
        Component frameComponent = frame.getComponent();
        if (frameComponent != null) {
            Point origin = frameComponent.getLocationOnScreen();
            x = (int) (origin.getX() + (frameComponent.getWidth() - this.getWidth()) / 2);
            y = (int) (origin.getY() + (frameComponent.getHeight() - this.getHeight()) / 2);
        }
    } else {
        Rectangle screenBounds = windowManager.getScreenBounds();
        x = (int) (screenBounds.getX() + (screenBounds.getWidth() - this.getWidth()) / 2);
        y = (int) (screenBounds.getY() + (screenBounds.getHeight() - this.getHeight()) / 2);
    }
    this.setLocation(x, y);
}

From source file:com.intellij.ide.impl.DataManagerImpl.java

License:Apache License

@Nullable
private Component getFocusedComponent() {
    if (myWindowManager == null) {
        return null;
    }/* ww w  .j  av a  2  s . co m*/
    Window activeWindow = myWindowManager.getMostRecentFocusedWindow();
    if (activeWindow == null) {
        activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
        if (activeWindow == null) {
            activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
            if (activeWindow == null)
                return null;
        }
    }

    if (Registry.is("actionSystem.noContextComponentWhileFocusTransfer")) {
        IdeFocusManager fm = IdeFocusManager.findInstanceByComponent(activeWindow);
        if (fm.isFocusBeingTransferred()) {
            return null;
        }
    }

    // In case we have an active floating toolwindow and some component in another window focused,
    // we want this other component to receive key events.
    // Walking up the window ownership hierarchy from the floating toolwindow would have led us to the main IdeFrame
    // whereas we want to be able to type in other frames as well.
    if (activeWindow instanceof FloatingDecorator) {
        IdeFocusManager ideFocusManager = IdeFocusManager.findInstanceByComponent(activeWindow);
        IdeFrame lastFocusedFrame = ideFocusManager.getLastFocusedFrame();
        JComponent frameComponent = lastFocusedFrame != null ? lastFocusedFrame.getComponent() : null;
        Window lastFocusedWindow = frameComponent != null ? SwingUtilities.getWindowAncestor(frameComponent)
                : null;
        boolean toolWindowIsNotFocused = myWindowManager.getFocusedComponent(activeWindow) == null;
        if (toolWindowIsNotFocused && lastFocusedWindow != null) {
            activeWindow = lastFocusedWindow;
        }
    }

    // try to find first parent window that has focus
    Window window = activeWindow;
    Component focusedComponent = null;
    while (window != null) {
        focusedComponent = myWindowManager.getFocusedComponent(window);
        if (focusedComponent != null) {
            break;
        }
        window = window.getOwner();
    }
    if (focusedComponent == null) {
        focusedComponent = activeWindow;
    }

    return focusedComponent;
}

From source file:com.intellij.notification.impl.NotificationsManagerImpl.java

License:Apache License

public static Balloon createBalloon(@NotNull final IdeFrame window, final Notification notification,
        final boolean showCallout, final boolean hideOnClickOutside) {
    final JEditorPane text = new JEditorPane();
    text.setEditorKit(UIUtil.getHTMLEditorKit());

    final HyperlinkListener listener = NotificationsUtil.wrapListener(notification);
    if (listener != null) {
        text.addHyperlinkListener(listener);
    }/*from www  .ja v a  2 s  . co m*/

    final JLabel label = new JLabel(NotificationsUtil.buildHtml(notification, null));
    text.setText(NotificationsUtil.buildHtml(notification,
            "width:" + Math.min(350, label.getPreferredSize().width) + "px;"));
    text.setEditable(false);
    text.setOpaque(false);

    if (UIUtil.isUnderNimbusLookAndFeel()) {
        text.setBackground(UIUtil.TRANSPARENT_COLOR);
    }

    text.setBorder(null);

    final JPanel content = new NonOpaquePanel(
            new BorderLayout((int) (label.getIconTextGap() * 1.5), (int) (label.getIconTextGap() * 1.5)));

    if (text.getCaret() != null) {
        text.setCaretPosition(0);
    }
    JScrollPane pane = ScrollPaneFactory.createScrollPane(text,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    pane.setBorder(null);
    pane.setOpaque(false);
    pane.getViewport().setOpaque(false);
    content.add(pane, BorderLayout.CENTER);

    final NonOpaquePanel north = new NonOpaquePanel(new BorderLayout());
    north.add(new JLabel(NotificationsUtil.getIcon(notification)), BorderLayout.NORTH);
    content.add(north, BorderLayout.WEST);

    content.setBorder(new EmptyBorder(2, 4, 2, 4));

    Dimension preferredSize = text.getPreferredSize();
    text.setSize(preferredSize);

    Dimension paneSize = new Dimension(text.getPreferredSize());
    int maxHeight = Math.min(400, window.getComponent().getHeight() - 20);
    int maxWidth = Math.min(600, window.getComponent().getWidth() - 20);
    if (paneSize.height > maxHeight) {
        pane.setPreferredSize(
                new Dimension(Math.min(maxWidth, paneSize.width + UIUtil.getScrollBarWidth()), maxHeight));
    } else if (paneSize.width > maxWidth) {
        pane.setPreferredSize(new Dimension(maxWidth, paneSize.height + UIUtil.getScrollBarWidth()));
    }

    final BalloonBuilder builder = JBPopupFactory.getInstance().createBalloonBuilder(content);
    builder.setFillColor(new JBColor(Gray._234, Gray._92)).setCloseButtonEnabled(true)
            .setShowCallout(showCallout).setShadow(false).setHideOnClickOutside(hideOnClickOutside)
            .setHideOnAction(hideOnClickOutside).setHideOnKeyOutside(hideOnClickOutside)
            .setHideOnFrameResize(false).setBorderColor(new JBColor(Gray._180, Gray._110));

    final Balloon balloon = builder.createBalloon();
    balloon.setAnimationEnabled(false);
    notification.setBalloon(balloon);
    return balloon;
}

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

License:Apache License

private static JComponent rootComponent(Project project) {
    if (project != null) {
        IdeFrame frame = WindowManager.getInstance().getIdeFrame(project);
        if (frame != null)
            return frame.getComponent();
    }/*w w  w. j av a 2s.  c o m*/

    JFrame frame = WindowManager.getInstance().findVisibleFrame();
    return frame != null ? frame.getRootPane() : null;
}

From source file:com.intellij.util.net.HttpConfigurable.java

License:Apache License

@Deprecated
public void writeExternal(Element element) throws WriteExternalException {
    XmlSerializer.serializeInto(getState(), element);
    if (USE_PROXY_PAC && USE_HTTP_PROXY && !ApplicationManager.getApplication().isDisposed()) {
        ApplicationManager.getApplication().invokeLater(new Runnable() {
            @Override/*from  w w w . ja  va 2s.  c o  m*/
            public void run() {
                IdeFrame frame = IdeFocusManager.findInstance().getLastFocusedFrame();
                if (frame != null) {
                    USE_PROXY_PAC = false;
                    Messages.showMessageDialog(frame.getComponent(),
                            "Proxy: both 'use proxy' and 'autodetect proxy' settings were set."
                                    + "\nOnly one of these options should be selected.\nPlease re-configure.",
                            "Proxy Setup", Messages.getWarningIcon());
                    editConfigurable(frame.getComponent());
                }
            }
        }, ModalityState.NON_MODAL);
    }
}

From source file:com.intellij.util.net.HTTPProxySettingsPanel.java

License:Apache License

public HTTPProxySettingsPanel(final HttpConfigurable httpConfigurable) {
    final ButtonGroup group = new ButtonGroup();
    group.add(myUseHTTPProxyRb);/*from   www . ja  va2  s  .c  o  m*/
    group.add(myAutoDetectProxyRb);
    group.add(myNoProxyRb);
    myNoProxyRb.setSelected(true);

    final ButtonGroup proxyTypeGroup = new ButtonGroup();
    proxyTypeGroup.add(myHTTP);
    proxyTypeGroup.add(mySocks);
    myHTTP.setSelected(true);

    myProxyExceptions.setBorder(UIUtil.getTextFieldBorder());

    final Boolean property = Boolean.getBoolean(JavaProxyProperty.USE_SYSTEM_PROXY);
    mySystemProxyDefined.setVisible(Boolean.TRUE.equals(property));
    if (Boolean.TRUE.equals(property)) {
        mySystemProxyDefined.setIcon(Messages.getWarningIcon());
        mySystemProxyDefined.setFont(mySystemProxyDefined.getFont().deriveFont(Font.BOLD));
        mySystemProxyDefined.setUI(new MultiLineLabelUI());
    }

    myProxyAuthCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            enableProxyAuthentication(myProxyAuthCheckBox.isSelected());
        }
    });

    final ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            enableProxy(myUseHTTPProxyRb.isSelected());
        }
    };
    myUseHTTPProxyRb.addActionListener(listener);
    myAutoDetectProxyRb.addActionListener(listener);
    myNoProxyRb.addActionListener(listener);
    myHttpConfigurable = httpConfigurable;

    myClearPasswordsButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            myHttpConfigurable.clearGenericPasswords();
            Messages.showMessageDialog(myMainPanel, "Proxy passwords were cleared.", "Auto-detected proxy",
                    Messages.getInformationIcon());
        }
    });

    if (HttpConfigurable.getInstance() != null) {
        myCheckButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                final String title = "Check Proxy Settings";
                final String answer = Messages.showInputDialog(myMainPanel,
                        "Warning: your settings will be saved.\n\nEnter any URL to check connection to:", title,
                        Messages.getQuestionIcon(), "http://", null);
                if (!StringUtil.isEmptyOrSpaces(answer)) {
                    apply();
                    final HttpConfigurable instance = HttpConfigurable.getInstance();
                    final AtomicReference<IOException> exc = new AtomicReference<IOException>();
                    myCheckButton.setEnabled(false);
                    myCheckButton.setText("Check connection (in progress...)");
                    myConnectionCheckInProgress = true;
                    final Application application = ApplicationManager.getApplication();
                    application.executeOnPooledThread(new Runnable() {
                        @Override
                        public void run() {
                            HttpURLConnection connection = null;
                            try {
                                //already checked for null above
                                //noinspection ConstantConditions
                                connection = instance.openHttpConnection(answer);
                                connection.setReadTimeout(3 * 1000);
                                connection.setConnectTimeout(3 * 1000);
                                connection.connect();
                                final int code = connection.getResponseCode();
                                if (HttpURLConnection.HTTP_OK != code) {
                                    exc.set(new IOException("Error code: " + code));
                                }
                            } catch (IOException e1) {
                                exc.set(e1);
                            } finally {
                                if (connection != null) {
                                    connection.disconnect();
                                }
                            }
                            //noinspection SSBasedInspection
                            SwingUtilities.invokeLater(new Runnable() {
                                @Override
                                public void run() {
                                    myConnectionCheckInProgress = false;
                                    reset(); // since password might have been set
                                    Component parent = null;
                                    if (myMainPanel.isShowing()) {
                                        parent = myMainPanel;
                                        myCheckButton.setText("Check connection");
                                        myCheckButton.setEnabled(canEnableConnectionCheck());
                                    } else {
                                        final IdeFrame frame = IdeFocusManager.findInstance()
                                                .getLastFocusedFrame();
                                        if (frame == null) {
                                            return;
                                        }
                                        parent = frame.getComponent();
                                    }
                                    //noinspection ThrowableResultOfMethodCallIgnored
                                    final IOException exception = exc.get();
                                    if (exception == null) {
                                        Messages.showMessageDialog(parent, "Connection successful", title,
                                                Messages.getInformationIcon());
                                    } else {
                                        final String message = exception.getMessage();
                                        if (instance.USE_HTTP_PROXY) {
                                            instance.LAST_ERROR = message;
                                        }
                                        Messages.showErrorDialog(parent, errorText(message));
                                    }
                                }
                            });
                        }
                    });
                }
            }
        });
    } else {
        myCheckButton.setVisible(false);
    }
}

From source file:com.intellij.util.net.HttpProxySettingsUi.java

License:Apache License

private void configureCheckButton() {
    if (HttpConfigurable.getInstance() == null) {
        myCheckButton.setVisible(false);
        return;/*from  w ww. j  a v a  2 s.co m*/
    }

    myCheckButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(@NotNull ActionEvent e) {
            final String title = "Check Proxy Settings";
            final String answer = Messages.showInputDialog(myMainPanel,
                    "Warning: your settings will be saved.\n\nEnter any URL to check connection to:", title,
                    Messages.getQuestionIcon(), "http://", null);
            if (StringUtil.isEmptyOrSpaces(answer)) {
                return;
            }

            final HttpConfigurable settings = HttpConfigurable.getInstance();
            apply(settings);
            final AtomicReference<IOException> exceptionReference = new AtomicReference<IOException>();
            myCheckButton.setEnabled(false);
            myCheckButton.setText("Check connection (in progress...)");
            myConnectionCheckInProgress = true;
            ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
                @Override
                public void run() {
                    HttpURLConnection connection = null;
                    try {
                        //already checked for null above
                        //noinspection ConstantConditions
                        connection = settings.openHttpConnection(answer);
                        connection.setReadTimeout(3 * 1000);
                        connection.setConnectTimeout(3 * 1000);
                        connection.connect();
                        final int code = connection.getResponseCode();
                        if (HttpURLConnection.HTTP_OK != code) {
                            exceptionReference.set(new IOException("Error code: " + code));
                        }
                    } catch (IOException e) {
                        exceptionReference.set(e);
                    } finally {
                        if (connection != null) {
                            connection.disconnect();
                        }
                    }
                    //noinspection SSBasedInspection
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            myConnectionCheckInProgress = false;
                            reset(settings); // since password might have been set
                            Component parent;
                            if (myMainPanel.isShowing()) {
                                parent = myMainPanel;
                                myCheckButton.setText("Check connection");
                                myCheckButton.setEnabled(canEnableConnectionCheck());
                            } else {
                                IdeFrame frame = IdeFocusManager.findInstance().getLastFocusedFrame();
                                if (frame == null) {
                                    return;
                                }
                                parent = frame.getComponent();
                            }
                            //noinspection ThrowableResultOfMethodCallIgnored
                            final IOException exception = exceptionReference.get();
                            if (exception == null) {
                                Messages.showMessageDialog(parent, "Connection successful", title,
                                        Messages.getInformationIcon());
                            } else {
                                final String message = exception.getMessage();
                                if (settings.USE_HTTP_PROXY) {
                                    settings.LAST_ERROR = message;
                                }
                                Messages.showErrorDialog(parent, errorText(message));
                            }
                        }
                    });
                }
            });
        }
    });
}

From source file:org.jetbrains.idea.svn.SvnAuthenticationNotifier.java

License:Apache License

private boolean showAlreadyChecking() {
    final IdeFrame frameFor = WindowManagerEx.getInstanceEx().findFrameFor(myProject);
    if (frameFor != null) {
        final JComponent component = frameFor.getComponent();
        Point point = component.getMousePosition();
        if (point == null) {
            point = new Point((int) (component.getWidth() * 0.7), 0);
        }//from  ww w .  j a va2  s.com
        SwingUtilities.convertPointToScreen(point, component);
        JBPopupFactory.getInstance()
                .createHtmlTextBalloonBuilder("Already checking...", MessageType.WARNING, null).createBalloon()
                .show(new RelativePoint(point), Balloon.Position.below);
    }
    return false;
}