コード例 #1
0
 /**
  * Sets the photo of the user.
  *
  * @param image The image to set.
  */
 void setUserPhoto(BufferedImage image) {
   if (image == null) return;
   BufferedImage img = Factory.scaleBufferedImage(image, UserProfileCanvas.WIDTH);
   userPicture.setImage(img);
 }
コード例 #2
0
  /** Initializes the components composing this display. */
  private void initComponents() {
    admin = false;
    active = false;
    groupOwner = false;

    userPicture = new UserProfileCanvas();
    userPicture.setBackground(UIUtilities.BACKGROUND_COLOR);
    userPicture.setToolTipText("Click to upload your picture.");
    IconManager icons = IconManager.getInstance();
    userPicture.setImage(icons.getImageIcon(IconManager.USER_PHOTO_32).getImage());
    loginArea = new JTextField();
    boolean a = MetadataViewerAgent.isAdministrator();
    loginArea.setEnabled(a);
    loginArea.setEditable(a);
    adminBox = new JCheckBox();
    adminBox.setVisible(false);
    adminBox.setBackground(UIUtilities.BACKGROUND_COLOR);
    ownerBox = new JCheckBox();
    ownerBox.setBackground(UIUtilities.BACKGROUND_COLOR);
    activeBox = new JCheckBox();
    activeBox.setBackground(UIUtilities.BACKGROUND_COLOR);
    activeBox.setVisible(false);
    passwordButton = new JButton("Change password");
    passwordButton.setEnabled(false);
    passwordButton.setBackground(UIUtilities.BACKGROUND_COLOR);
    passwordButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            changePassword();
          }
        });
    manageButton = new JButton("Group");
    manageButton.setEnabled(false);
    manageButton.setBackground(UIUtilities.BACKGROUND_COLOR);
    manageButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            manageGroup();
          }
        });
    passwordNew = new JPasswordField();
    passwordNew.setBackground(UIUtilities.BACKGROUND_COLOR);
    passwordConfirm = new JPasswordField();
    passwordConfirm.setBackground(UIUtilities.BACKGROUND_COLOR);
    oldPassword = new JPasswordField();
    oldPassword.setBackground(UIUtilities.BACKGROUND_COLOR);
    items = new HashMap<String, JTextField>();
    ExperimenterData user = (ExperimenterData) model.getRefObject();
    GroupData defaultGroup = user.getDefaultGroup();

    permissionsPane =
        new PermissionsPane(defaultGroup.getPermissions(), UIUtilities.BACKGROUND_COLOR);
    permissionsPane.disablePermissions();
    groupLabel = new JLabel(defaultGroup.getName());
    groupLabel.setBackground(UIUtilities.BACKGROUND_COLOR);

    long groupID = defaultGroup.getId();
    boolean owner = false;
    /*
    if (defaultGroup.getLeaders() != null)
    	owner = setGroupOwner(defaultGroup);
    else {
    	GroupData g = model.loadGroup(groupID);
    	if (g != null)
    		owner = setGroupOwner(g);
    }
    */
    Object parentRootObject = model.getParentRootObject();
    if (parentRootObject instanceof GroupData) {
      owner = setGroupOwner((GroupData) parentRootObject);
    }
    // Build the array for box.
    /*
    Iterator i = userGroups.iterator();
    GroupData g;

    List<GroupData> validGroups = new ArrayList<GroupData>();
    while (i.hasNext()) {
    	g = (GroupData) i.next();
    	if (model.isValidGroup(g))
    		validGroups.add(g);
    }
    groupData = new GroupData[validGroups.size()];
    admin = false;
    active = false;
    int selectedIndex = 0;
    int index = 0;
    i = validGroups.iterator();
    boolean owner = false;
    while (i.hasNext()) {
    	g = (GroupData) i.next();
    	groupData[index] = g;
    	if (g.getId() == groupID) {
    		if (g.getLeaders() != null) {
    			owner = setGroupOwner(g);
    			originalIndex = index;
    		}
    	}
    	index++;
    }
    selectedIndex = originalIndex;
    groups = EditorUtil.createComboBox(groupData, 0);
    groups.setEnabled(false);
    groups.setRenderer(new GroupsRenderer());
    if (groupData.length != 0)
    	groups.setSelectedIndex(selectedIndex);
    */

    if (MetadataViewerAgent.isAdministrator()) {
      // Check that the user is not the one currently logged.
      oldPassword.setVisible(false);
      owner = true;
      adminBox.setVisible(true);
      activeBox.setVisible(true);
      adminBox.addChangeListener(this);
      active = user.isActive();
      activeBox.setSelected(active);
      activeBox.setEnabled(!model.isSelf());
      activeBox.addChangeListener(this);
      // indicate if the user is an administrator.a
      admin = isUserAdministrator();
      adminBox.setSelected(admin);
      ownerBox.addChangeListener(this);
      // admin = false;
      // Now check if the user is the last administrator
    } else {
      ownerBox.setEnabled(false);
      passwordConfirm
          .getDocument()
          .addDocumentListener(
              new DocumentListener() {

                /**
                 * Allows the user to interact with the password controls depending on the value
                 * entered.
                 *
                 * @see DocumentListener#removeUpdate(DocumentEvent)
                 */
                public void removeUpdate(DocumentEvent e) {
                  handlePasswordEntered();
                }

                /**
                 * Allows the user to interact with the password controls depending on the value
                 * entered.
                 *
                 * @see DocumentListener#insertUpdate(DocumentEvent)
                 */
                public void insertUpdate(DocumentEvent e) {
                  handlePasswordEntered();
                }

                /**
                 * Required by the {@link DocumentListener} I/F but no-operation implementation in
                 * our case.
                 *
                 * @see DocumentListener#changedUpdate(DocumentEvent)
                 */
                public void changedUpdate(DocumentEvent e) {}
              });
    }
    passwordNew
        .getDocument()
        .addDocumentListener(
            new DocumentListener() {

              /**
               * Allows the user to interact with the password controls depending on the value
               * entered.
               *
               * @see DocumentListener#removeUpdate(DocumentEvent)
               */
              public void removeUpdate(DocumentEvent e) {
                handlePasswordEntered();
              }

              /**
               * Allows the user to interact with the password controls depending on the value
               * entered.
               *
               * @see DocumentListener#insertUpdate(DocumentEvent)
               */
              public void insertUpdate(DocumentEvent e) {
                handlePasswordEntered();
              }

              /**
               * Required by the {@link DocumentListener} I/F but no-operation implementation in our
               * case.
               *
               * @see DocumentListener#changedUpdate(DocumentEvent)
               */
              public void changedUpdate(DocumentEvent e) {}
            });
    ExperimenterData logUser = MetadataViewerAgent.getUserDetails();
    if (user.getId() == logUser.getId()) {
      userPicture.addMouseListener(
          new MouseAdapter() {

            /** Brings up a chooser to load the user image. */
            public void mouseReleased(MouseEvent e) {
              uploadPicture();
            }
          });
    }
  }