public void addActionListener(final ActionListener actionListener) {
    myProxyLoginTextField.addActionListener(actionListener);
    DocumentListener docListener =
        new DocumentListener() {
          public void insertUpdate(DocumentEvent e) {
            actionListener.actionPerformed(null);
          }

          public void removeUpdate(DocumentEvent e) {
            actionListener.actionPerformed(null);
          }

          public void changedUpdate(DocumentEvent e) {
            actionListener.actionPerformed(null);
          }
        };
    myProxyPasswordTextField.getDocument().addDocumentListener(docListener);
    myProxyAuthCheckBox.addActionListener(actionListener);
    myProxyPortTextField.getDocument().addDocumentListener(docListener);
    myProxyHostTextField.getDocument().addDocumentListener(docListener);
    myUseHTTPProxyRb.addActionListener(actionListener);
    myRememberProxyPasswordCheckBox.addActionListener(actionListener);
  }
  public HttpProxySettingsUi(@NotNull final HttpConfigurable settings) {
    ButtonGroup group = new ButtonGroup();
    group.add(myUseHTTPProxyRb);
    group.add(myAutoDetectProxyRb);
    group.add(myNoProxyRb);
    myNoProxyRb.setSelected(true);

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

    Boolean property = Boolean.getBoolean(JavaProxyProperty.USE_SYSTEM_PROXY);
    mySystemProxyDefined.setVisible(Boolean.TRUE.equals(property));
    if (Boolean.TRUE.equals(property)) {
      mySystemProxyDefined.setIcon(Messages.getWarningIcon());
      RelativeFont.BOLD.install(mySystemProxyDefined);
    }

    myProxyAuthCheckBox.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(@NotNull ActionEvent e) {
            enableProxyAuthentication(myProxyAuthCheckBox.isSelected());
          }
        });
    myPacUrlCheckBox.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(@NotNull ActionEvent e) {
            myPacUrlTextField.setEnabled(myPacUrlCheckBox.isSelected());
          }
        });

    ActionListener listener =
        new ActionListener() {
          @Override
          public void actionPerformed(@NotNull ActionEvent e) {
            enableProxy(myUseHTTPProxyRb.isSelected());
          }
        };
    myUseHTTPProxyRb.addActionListener(listener);
    myAutoDetectProxyRb.addActionListener(listener);
    myNoProxyRb.addActionListener(listener);

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

    configureCheckButton();
  }
  public HTTPProxySettingsPanel(final HttpConfigurable httpConfigurable) {
    final ButtonGroup group = new ButtonGroup();
    group.add(myUseHTTPProxyRb);
    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());
          }
        });
    myPacUrlCheckBox.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            myPacUrlTextField.setEnabled(myPacUrlCheckBox.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);
    }
  }