Пример #1
0
  /**
   * Initializes this authentication window.
   *
   * @param server the server
   * @param isUserNameEditable indicates if the user name is editable
   * @param icon the icon to show on the authentication window
   */
  private void init(
      String userName,
      char[] password,
      String server,
      boolean isUserNameEditable,
      ImageIcon icon,
      String errorMessage) {
    this.server = server;

    initIcon(icon);

    if (!isUserNameEditable) this.uinValue = new JLabel();
    else this.uinValue = new JTextField();

    this.init();

    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    this.enableKeyActions();

    this.setResizable(false);

    /*
     * Workaround for the following bug:
     * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4446522
     * Need to pack() the window after it's opened in order to obtain the
     * correct size of our infoTextArea, otherwise window size is wrong and
     * buttons on the south are cut.
     */
    this.addWindowListener(
        new WindowAdapter() {
          public void windowOpened(WindowEvent e) {
            pack();
            removeWindowListener(this);
          }
        });

    if (OSUtils.IS_MAC) getRootPane().putClientProperty("apple.awt.brushMetalLook", Boolean.TRUE);

    if (userName != null) {
      if (uinValue instanceof JLabel) ((JLabel) uinValue).setText(userName);
      else if (uinValue instanceof JTextField) ((JTextField) uinValue).setText(userName);
    }

    if (password != null) passwdField.setText(new String(password));

    if (errorMessage != null) {
      this.infoTextArea.setForeground(Color.RED);
      this.infoTextArea.setText(errorMessage);
    }
  }
Пример #2
0
  /**
   * Handles the <tt>ActionEvent</tt> triggered when one of the buttons is clicked. When "Login"
   * button is chosen installs a new account from the user input and logs in.
   *
   * @param evt the action event that has just occurred.
   */
  public void actionPerformed(ActionEvent evt) {
    JButton button = (JButton) evt.getSource();
    String buttonName = button.getName();

    if ("ok".equals(buttonName)) {
      if (uinValue instanceof JLabel) userName = ((JLabel) uinValue).getText();
      else if (uinValue instanceof JTextField) userName = ((JTextField) uinValue).getText();

      password = passwdField.getPassword();
      isRememberPassword = rememberPassCheckBox.isSelected();
    } else {
      isCanceled = true;
    }

    // release the caller that opened the window
    buttonClicked = true;
    synchronized (lock) {
      lock.notify();
    }

    this.dispose();
  }