Beispiel #1
0
  private void onOK() {
    if (!isValidInput()) {
      return;
    }
    dispose();
    String firstName = firstNameField.getText().trim();
    String lastName = lastNameField.getText().trim();
    String emailAddress = emailAddressField.getText().trim();
    SexOfPerson sexOfPerson;
    if (femaleRadioButton.isSelected()) {
      sexOfPerson = SexOfPerson.FEMALE;
    } else {
      sexOfPerson = SexOfPerson.MALE;
    }
    String country = (String) countryComboBox.getSelectedObject();
    Integer birthdayYear = (Integer) birthdayYearComboBox.getSelectedItem();
    Month birthdayMonth = (Month) birthdayMonthComboBox.getSelectedItem();
    Integer birthdayDay = (Integer) birthdayDayComboBox.getSelectedItem();
    char[] passwordArr = passwordField.getPassword();
    String password = new String(passwordArr);
    Arrays.fill(passwordArr, (char) 0);
    Image profilePicture = null;
    if (imageFromFileRadioButton.isSelected()) {
      if (fileSelector.getFilePath() != null) {
        profilePicture = new FileImage(fileSelector.getFilePath());
      }
    }
    Request request =
        new CreateUserRequest(
            communicator.getHttpClient(),
            frame,
            firstName,
            lastName,
            emailAddress,
            sexOfPerson,
            country,
            birthdayYear,
            birthdayMonth,
            birthdayDay,
            password,
            profilePicture) {

          @Override
          protected void onCreateUser(String status, Person person) {
            if (status.equals("INVALID_PROFILE_PICTURE")) {
              communicator.promptForCreateAccount("Invalid profile picture");
            } else if (status.equals("ERROR_CREATING_USER")) {
              communicator.promptForCreateAccount("Error creating user");
            } else if (status.equals("CONNECTION_ERROR")) {
              communicator.promptForCreateAccount("Error connecting to Modeling Commons");
            } else if (status.equals("SUCCESS")) {
              communicator.setPerson(person);
              communicator.promptForUpload();
            } else {
              communicator.promptForCreateAccount("Unknown server error");
            }
          }
        };
    request.execute();
  }
Beispiel #2
0
  public NewUserDialog(Frame frame, ModelingCommons communicator, String errorLabelText) {
    super(frame);
    this.communicator = communicator;
    this.frame = frame;
    initializeGUIComponents();
    errorLabel.setText(errorLabelText);
    getRootPane().setDefaultButton(createAccountButton);
    for (String country : communicator.getPriorityCountries()) {
      countryComboBox.addItem(country, true);
    }
    countryComboBox.addItem("--------", false);
    for (String country : communicator.getUnpriorityCountries()) {
      countryComboBox.addItem(country, true);
    }
    femaleRadioButton.setSelected(true);
    userAgreementTextPane.setText(communicator.getNewUserAgreement());
    userAgreementTextPane.setCaretPosition(0);
    int startYear = 1930;
    birthdayYearComboBox.addItem(null);
    for (int y = Calendar.getInstance().get(Calendar.YEAR); y >= startYear; y--) {
      birthdayYearComboBox.addItem(y);
    }
    birthdayMonthComboBox.addItem(null);
    for (Month month : Month.getMonths()) {
      birthdayMonthComboBox.addItem(month);
    }
    birthdayDayComboBox.addItem(null);
    for (int d = 1; d <= 31; d++) {
      birthdayDayComboBox.addItem(d);
    }
    imageFromFileRadioButton.addChangeListener(
        new ChangeListener() {

          @Override
          public void stateChanged(ChangeEvent changeEvent) {
            if (imageFromFileRadioButton.isSelected()) {
              fileSelector.setEnabled(true);
            } else {
              fileSelector.setEnabled(false);
            }
          }
        });
    imageFromFileRadioButton.setSelected(true);
    createAccountButton.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            onOK();
          }
        });
    cancelButton.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            onCancel();
          }
        });
    loginButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent actionEvent) {
            dispose();
            NewUserDialog.this.communicator.promptForLogin();
          }
        });
    // call onCancel() when cross is clicked
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(
        new WindowAdapter() {

          public void windowClosing(WindowEvent e) {
            onCancel();
          }
        });
    // call onCancel() on ESCAPE
    topLevelContainer.registerKeyboardAction(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            onCancel();
          }
        },
        KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
        JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    setModal(true);
    pack();
    setLocationRelativeTo(frame);
    setResizable(true);
  }