Пример #1
0
  /** Constructs the <tt>LoginWindow</tt>. */
  private void init() {
    String title;

    if (windowTitle != null) title = windowTitle;
    else
      title =
          DesktopUtilActivator.getResources()
              .getI18NString("service.gui.AUTHENTICATION_WINDOW_TITLE", new String[] {server});

    String text;
    if (windowText != null) text = windowText;
    else
      text =
          DesktopUtilActivator.getResources()
              .getI18NString("service.gui.AUTHENTICATION_REQUESTED_SERVER", new String[] {server});

    String uinText;
    if (usernameLabelText != null) uinText = usernameLabelText;
    else uinText = DesktopUtilActivator.getResources().getI18NString("service.gui.IDENTIFIER");

    String passText;
    if (passwordLabelText != null) passText = passwordLabelText;
    else passText = DesktopUtilActivator.getResources().getI18NString("service.gui.PASSWORD");

    setTitle(title);

    infoTextArea.setEditable(false);
    infoTextArea.setOpaque(false);
    infoTextArea.setLineWrap(true);
    infoTextArea.setWrapStyleWord(true);
    infoTextArea.setFont(infoTextArea.getFont().deriveFont(Font.BOLD));
    infoTextArea.setText(text);
    infoTextArea.setAlignmentX(0.5f);

    JLabel uinLabel = new JLabel(uinText);
    uinLabel.setFont(uinLabel.getFont().deriveFont(Font.BOLD));

    JLabel passwdLabel = new JLabel(passText);
    passwdLabel.setFont(passwdLabel.getFont().deriveFont(Font.BOLD));

    TransparentPanel labelsPanel = new TransparentPanel(new GridLayout(0, 1, 8, 8));

    labelsPanel.add(uinLabel);
    labelsPanel.add(passwdLabel);

    TransparentPanel textFieldsPanel = new TransparentPanel(new GridLayout(0, 1, 8, 8));

    textFieldsPanel.add(uinValue);
    textFieldsPanel.add(passwdField);

    JPanel southFieldsPanel = new TransparentPanel(new GridLayout(1, 2));

    this.rememberPassCheckBox.setOpaque(false);
    this.rememberPassCheckBox.setBorder(null);

    southFieldsPanel.add(rememberPassCheckBox);
    if (signupLink != null && signupLink.length() > 0)
      southFieldsPanel.add(
          createWebSignupLabel(
              DesktopUtilActivator.getResources().getI18NString("plugin.simpleaccregwizz.SIGNUP"),
              signupLink));
    else southFieldsPanel.add(new JLabel());

    boolean allowRememberPassword = true;

    String allowRemPassStr =
        DesktopUtilActivator.getResources().getSettingsString(PNAME_ALLOW_SAVE_PASSWORD);
    if (allowRemPassStr != null) {
      allowRememberPassword = Boolean.parseBoolean(allowRemPassStr);
    }
    allowRememberPassword =
        DesktopUtilActivator.getConfigurationService()
            .getBoolean(PNAME_ALLOW_SAVE_PASSWORD, allowRememberPassword);

    setAllowSavePassword(allowRememberPassword);

    JPanel buttonPanel = new TransparentPanel(new FlowLayout(FlowLayout.CENTER));

    buttonPanel.add(loginButton);
    buttonPanel.add(cancelButton);

    JPanel southEastPanel = new TransparentPanel(new BorderLayout());
    southEastPanel.add(buttonPanel, BorderLayout.EAST);

    TransparentPanel mainPanel = new TransparentPanel(new BorderLayout(10, 10));

    mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 0, 20, 20));

    JPanel mainFieldsPanel = new TransparentPanel(new BorderLayout(0, 10));
    mainFieldsPanel.add(labelsPanel, BorderLayout.WEST);
    mainFieldsPanel.add(textFieldsPanel, BorderLayout.CENTER);
    mainFieldsPanel.add(southFieldsPanel, BorderLayout.SOUTH);

    mainPanel.add(infoTextArea, BorderLayout.NORTH);
    mainPanel.add(mainFieldsPanel, BorderLayout.CENTER);
    mainPanel.add(southEastPanel, BorderLayout.SOUTH);

    this.getContentPane().add(mainPanel, BorderLayout.EAST);

    this.loginButton.setName("ok");
    this.cancelButton.setName("cancel");
    if (loginButton.getPreferredSize().width > cancelButton.getPreferredSize().width)
      cancelButton.setPreferredSize(loginButton.getPreferredSize());
    else loginButton.setPreferredSize(cancelButton.getPreferredSize());

    this.loginButton.setMnemonic(
        DesktopUtilActivator.getResources().getI18nMnemonic("service.gui.OK"));
    this.cancelButton.setMnemonic(
        DesktopUtilActivator.getResources().getI18nMnemonic("service.gui.CANCEL"));

    this.loginButton.addActionListener(this);
    this.cancelButton.addActionListener(this);

    this.getRootPane().setDefaultButton(loginButton);
  }
Пример #2
0
  /** Shows a dialog with input for logs description. */
  private void uploadLogs() {
    ResourceManagementService resources = LoggingUtilsActivator.getResourceService();

    final SIPCommDialog dialog =
        new SIPCommDialog(false) {
          /** Serial version UID. */
          private static final long serialVersionUID = 0L;

          /**
           * Dialog is closed. Do nothing.
           *
           * @param escaped <tt>true</tt> if this dialog has been closed by pressing
           */
          @Override
          protected void close(boolean escaped) {}
        };

    dialog.setModal(true);
    dialog.setTitle(resources.getI18NString("plugin.loggingutils.UPLOAD_LOGS_BUTTON"));

    Container container = dialog.getContentPane();
    container.setLayout(new GridBagLayout());

    JLabel descriptionLabel = new JLabel("Add a comment:");
    final JTextArea commentTextArea = new JTextArea();
    commentTextArea.setRows(4);
    final JButton uploadButton =
        new JButton(resources.getI18NString("plugin.loggingutils.UPLOAD_BUTTON"));
    final SIPCommTextField emailField =
        new SIPCommTextField(resources.getI18NString("plugin.loggingutils.ARCHIVE_UPREPORT_EMAIL"));
    final JCheckBox emailCheckBox =
        new SIPCommCheckBox("Email me when more information is available");
    emailCheckBox.setSelected(true);
    emailCheckBox.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (!emailCheckBox.isSelected()) {
              uploadButton.setEnabled(true);
              emailField.setEnabled(false);
            } else {
              emailField.setEnabled(true);

              if (emailField.getText() != null && emailField.getText().trim().length() > 0)
                uploadButton.setEnabled(true);
              else uploadButton.setEnabled(false);
            }
          }
        });

    emailField
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {
              public void insertUpdate(DocumentEvent e) {
                updateButtonsState();
              }

              public void removeUpdate(DocumentEvent e) {
                updateButtonsState();
              }

              public void changedUpdate(DocumentEvent e) {}

              /** Check whether we should enable upload button. */
              private void updateButtonsState() {
                if (emailCheckBox.isSelected()
                    && emailField.getText() != null
                    && emailField.getText().trim().length() > 0) uploadButton.setEnabled(true);
                else uploadButton.setEnabled(false);
              }
            });

    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.insets = new Insets(10, 10, 3, 10);
    c.weightx = 1.0;
    c.gridx = 0;
    c.gridy = 0;

    container.add(descriptionLabel, c);

    c.insets = new Insets(0, 10, 10, 10);
    c.gridy = 1;
    container.add(new JScrollPane(commentTextArea), c);

    c.insets = new Insets(0, 10, 0, 10);
    c.gridy = 2;
    container.add(emailCheckBox, c);

    c.insets = new Insets(0, 10, 10, 10);
    c.gridy = 3;
    container.add(emailField, c);

    JButton cancelButton = new JButton(resources.getI18NString("service.gui.CANCEL"));
    cancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            dialog.dispose();
          }
        });

    uploadButton.setEnabled(false);
    uploadButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              final ArrayList<String> paramNames = new ArrayList<String>();
              final ArrayList<String> paramValues = new ArrayList<String>();

              if (emailCheckBox.isSelected()) {
                paramNames.add("Email");
                paramValues.add(emailField.getText());
              }

              paramNames.add("Description");
              paramValues.add(commentTextArea.getText());

              // don't block the UI thread we may need to show
              // some ui for password input if protected area on the way
              new Thread(
                      new Runnable() {
                        public void run() {
                          uploadLogs(
                              getUploadLocation(),
                              LogsCollector.getDefaultFileName(),
                              paramNames.toArray(new String[] {}),
                              paramValues.toArray(new String[] {}));
                        }
                      })
                  .start();
            } finally {
              dialog.dispose();
            }
          }
        });
    JPanel buttonsPanel = new TransparentPanel(new FlowLayout(FlowLayout.RIGHT));
    buttonsPanel.add(uploadButton);
    buttonsPanel.add(cancelButton);

    c.anchor = GridBagConstraints.LINE_END;
    c.weightx = 0;
    c.gridy = 4;
    container.add(buttonsPanel, c);

    dialog.setVisible(true);
  }