コード例 #1
0
ファイル: VCardEditor.java プロジェクト: kadet108/blucargo
  /**
   * Builds the UI based on a VCard.
   *
   * @param vcard the vcard used to build the UI.
   */
  private void buildUI(VCard vcard) {
    personalPanel.setFirstName(vcard.getFirstName());
    personalPanel.setMiddleName(vcard.getMiddleName());
    personalPanel.setLastName(vcard.getLastName());
    personalPanel.setEmailAddress(vcard.getEmailHome());
    personalPanel.setNickname(vcard.getNickName());
    personalPanel.setJID(vcard.getJabberId());

    businessPanel.setCompany(vcard.getOrganization());
    businessPanel.setDepartment(vcard.getOrganizationUnit());
    businessPanel.setStreetAddress(vcard.getAddressFieldWork("STREET"));
    businessPanel.setCity(vcard.getAddressFieldWork("LOCALITY"));
    businessPanel.setState(vcard.getAddressFieldWork("REGION"));
    businessPanel.setZipCode(vcard.getAddressFieldWork("PCODE"));
    businessPanel.setCountry(vcard.getAddressFieldWork("CTRY"));
    businessPanel.setJobTitle(vcard.getField("TITLE"));
    businessPanel.setPhone(vcard.getPhoneWork("VOICE"));
    businessPanel.setFax(vcard.getPhoneWork("FAX"));
    businessPanel.setPager(vcard.getPhoneWork("PAGER"));
    businessPanel.setMobile(vcard.getPhoneWork("CELL"));
    businessPanel.setWebPage(vcard.getField("URL"));

    // Load Home Info
    homePanel.setStreetAddress(vcard.getAddressFieldHome("STREET"));
    homePanel.setCity(vcard.getAddressFieldHome("LOCALITY"));
    homePanel.setState(vcard.getAddressFieldHome("REGION"));
    homePanel.setZipCode(vcard.getAddressFieldHome("PCODE"));
    homePanel.setCountry(vcard.getAddressFieldHome("CTRY"));
    homePanel.setPhone(vcard.getPhoneHome("VOICE"));
    homePanel.setFax(vcard.getPhoneHome("FAX"));
    homePanel.setPager(vcard.getPhoneHome("PAGER"));
    homePanel.setMobile(vcard.getPhoneHome("CELL"));

    // Set avatar
    byte[] bytes = vcard.getAvatar();
    if (bytes != null && bytes.length > 0) {
      ImageIcon icon = new ImageIcon(bytes);
      avatarPanel.setAvatar(icon);
      avatarPanel.setAvatarBytes(bytes);
      if (avatarLabel != null) {
        icon = GraphicUtils.scaleImageIcon(icon, 48, 48);

        avatarLabel.setIcon(icon);
      }
    }
  }
コード例 #2
0
  private void handleVCardInformation(VCard vcard, String phoneNumber) {
    if (vcard.getError() != null) {
      return;
    }

    String firstName = vcard.getFirstName();
    String lastName = vcard.getLastName();
    if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
      titleLabel.setText(firstName + " " + lastName);
    } else if (ModelUtil.hasLength(firstName)) {
      titleLabel.setText(firstName);
    }

    phoneLabel.setText(phoneNumber);

    String jobTitle = vcard.getField("TITLE");
    if (jobTitle != null) {
      professionLabel.setText(jobTitle);
    }

    byte[] avatarBytes = null;
    try {
      avatarBytes = vcard.getAvatar();
    } catch (Exception e) {
      Log.error("Cannot retrieve avatar bytes.", e);
    }

    if (avatarBytes != null) {
      try {
        ImageIcon avatarIcon = new ImageIcon(avatarBytes);
        avatarLabel.setIcon(avatarIcon);
        avatarLabel.invalidate();
        avatarLabel.validate();
        avatarLabel.repaint();
      } catch (Exception e) {
        // no issue
      }
    }

    invalidate();
    validate();
    repaint();
  }
コード例 #3
0
ファイル: VCardEditor.java プロジェクト: kadet108/blucargo
  /** Saves the VCard. */
  private void saveVCard() {
    final VCard vcard = new VCard();

    // Save personal info
    vcard.setFirstName(personalPanel.getFirstName());
    vcard.setLastName(personalPanel.getLastName());
    vcard.setMiddleName(personalPanel.getMiddleName());
    vcard.setEmailHome(personalPanel.getEmailAddress());
    vcard.setNickName(personalPanel.getNickname());

    // Save business info
    vcard.setOrganization(businessPanel.getCompany());
    vcard.setAddressFieldWork("STREET", businessPanel.getStreetAddress());
    vcard.setAddressFieldWork("LOCALITY", businessPanel.getCity());
    vcard.setAddressFieldWork("REGION", businessPanel.getState());
    vcard.setAddressFieldWork("PCODE", businessPanel.getZipCode());
    vcard.setAddressFieldWork("CTRY", businessPanel.getCountry());
    vcard.setField("TITLE", businessPanel.getJobTitle());
    vcard.setOrganizationUnit(businessPanel.getDepartment());
    vcard.setPhoneWork("VOICE", businessPanel.getPhone());
    vcard.setPhoneWork("FAX", businessPanel.getFax());
    vcard.setPhoneWork("PAGER", businessPanel.getPager());
    vcard.setPhoneWork("CELL", businessPanel.getMobile());
    vcard.setField("URL", businessPanel.getWebPage());

    // Save Home Info
    vcard.setAddressFieldHome("STREET", homePanel.getStreetAddress());
    vcard.setAddressFieldHome("LOCALITY", homePanel.getCity());
    vcard.setAddressFieldHome("REGION", homePanel.getState());
    vcard.setAddressFieldHome("PCODE", homePanel.getZipCode());
    vcard.setAddressFieldHome("CTRY", homePanel.getCountry());
    vcard.setPhoneHome("VOICE", homePanel.getPhone());
    vcard.setPhoneHome("FAX", homePanel.getFax());
    vcard.setPhoneHome("PAGER", homePanel.getPager());
    vcard.setPhoneHome("CELL", homePanel.getMobile());

    // Save Avatar
    final File avatarFile = avatarPanel.getAvatarFile();
    byte[] avatarBytes = avatarPanel.getAvatarBytes();

    if (avatarFile != null) {
      try {
        // Make it 48x48
        ImageIcon icon = new ImageIcon(avatarFile.toURI().toURL());
        Image image = icon.getImage();
        image = image.getScaledInstance(-1, 48, Image.SCALE_SMOOTH);
        avatarBytes = GraphicUtils.getBytesFromImage(image);
      } catch (MalformedURLException e) {
        Log.error("Unable to set avatar.", e);
      }
    }

    // If avatar bytes, persist as vcard.
    if (avatarBytes != null) {
      vcard.setAvatar(avatarBytes);
    }

    try {
      final VCardManager vcardManager = SparkManager.getVCardManager();
      vcardManager.setPersonalVCard(vcard);

      vcard.save(SparkManager.getConnection());

      // Notify users.
      if (avatarFile != null || avatarBytes != null) {
        Presence presence = SparkManager.getWorkspace().getStatusBar().getPresence();
        Presence newPresence =
            new Presence(
                presence.getType(),
                presence.getStatus(),
                presence.getPriority(),
                presence.getMode());

        // Change my own presence
        SparkManager.getSessionManager().changePresence(newPresence);

        // Chnage avatar in status bar.
        StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
        statusBar.setAvatar(new ImageIcon(vcard.getAvatar()));
      } else {
        String firstName = vcard.getFirstName();
        String lastName = vcard.getLastName();
        StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
        if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
          statusBar.setNickname(firstName + " " + lastName);
        } else if (ModelUtil.hasLength(firstName)) {
          statusBar.setNickname(firstName);
        }

        statusBar.setAvatar(null);
      }

      // Notify listenres
      SparkManager.getVCardManager().notifyVCardListeners();
    } catch (XMPPException e) {
      Log.error(e);
      JOptionPane.showMessageDialog(
          SparkManager.getMainWindow(),
          Res.getString("message.vcard.not.supported"),
          Res.getString("title.error"),
          JOptionPane.ERROR_MESSAGE);
    }
  }