コード例 #1
0
ファイル: ChatRoomImpl.java プロジェクト: kadet108/blucargo
  public void sendMessage(String text) {
    final Message message = new Message();

    if (threadID == null) {
      threadID = StringUtils.randomString(6);
    }
    message.setThread(threadID);

    // Set the body of the message using typedMessage
    message.setBody(text);

    // IF there is no body, just return and do nothing
    if (!ModelUtil.hasLength(text)) {
      return;
    }

    // Fire Message Filters
    SparkManager.getChatManager().filterOutgoingMessage(this, message);

    // Fire Global Filters
    SparkManager.getChatManager().fireGlobalMessageSentListeners(this, message);

    sendMessage(message);

    sendNotification = true;
  }
コード例 #2
0
ファイル: Notes.java プロジェクト: justin0127/IM
  private void saveNotes() {
    String note = textPane.getText();

    // Check for empty note.
    if (!ModelUtil.hasLength(note)) {
      return;
    }

    // Save note.
    AgentSession agentSession = FastpathPlugin.getAgentSession();
    try {
      agentSession.setNote(sessionID, note);
      saveButton.setEnabled(false);
      statusLabel.setText(" " + FpRes.getString("message.notes.updated"));
      SwingWorker worker =
          new SwingWorker() {
            public Object construct() {
              try {
                Thread.sleep(3000);
              } catch (InterruptedException e1) {
                Log.error(e1);
              }
              return true;
            }

            public void finished() {
              statusLabel.setText("");
            }
          };
      worker.start();
    } catch (XMPPException e1) {
      showError(FpRes.getString("message.unable.to.update.notes"));
      Log.error("Could not commit note.", e1);
    }
  }
コード例 #3
0
ファイル: ChatRoomImpl.java プロジェクト: kadet108/blucargo
  private void loadHistory() {
    // Add VCard Panel
    final VCardPanel vcardPanel = new VCardPanel(participantJID);

    vcardPanel.setPreferredSize(new Dimension(10, 71));
    vcardPanel.setMaximumSize(new Dimension(1100, 71));
    vcardPanel.setMinimumSize(new Dimension(1100, 71));

    getToolBar()
        .add(
            vcardPanel,
            new GridBagConstraints(
                0,
                1,
                1,
                1,
                1.0,
                0.0,
                GridBagConstraints.NORTHWEST,
                GridBagConstraints.HORIZONTAL,
                new Insets(0, 2, 0, 2),
                0,
                0));

    final LocalPreferences localPreferences = SettingsManager.getLocalPreferences();
    if (!localPreferences.isChatHistoryEnabled()) {
      return;
    }

    if (!localPreferences.isPrevChatHistoryEnabled()) {
      return;
    }

    final String bareJID = StringUtils.parseBareAddress(getParticipantJID());
    final ChatTranscript chatTranscript = ChatTranscripts.getCurrentChatTranscript(bareJID);
    final String personalNickname = SparkManager.getUserManager().getNickname();

    for (HistoryMessage message : chatTranscript.getMessages()) {
      String nickname = SparkManager.getUserManager().getUserNicknameFromJID(message.getFrom());
      String messageBody = message.getBody();
      if (nickname.equals(message.getFrom())) {
        String otherJID = StringUtils.parseBareAddress(message.getFrom());
        String myJID = SparkManager.getSessionManager().getBareAddress();

        if (otherJID.equals(myJID)) {
          nickname = personalNickname;
        } else {
          nickname = StringUtils.parseName(nickname);
        }
      }

      if (ModelUtil.hasLength(messageBody) && messageBody.startsWith("/me ")) {
        messageBody = messageBody.replaceFirst("/me", nickname);
      }

      final Date messageDate = message.getDate();
      getTranscriptWindow().insertHistoryMessage(nickname, messageBody, messageDate);
    }
  }
コード例 #4
0
  /**
   * Calls an individual user by their VCard information.
   *
   * @param jid the users JID.
   */
  public void callByJID(String jid) {
    if (getStatus() == SipRegisterStatus.Registered) {
      final VCard vcard =
          SparkManager.getVCardManager().getVCard(XmppStringUtils.parseBareJid(jid));

      if (vcard != null) {
        String number = vcard.getPhoneWork("VOICE");
        if (!ModelUtil.hasLength(number)) {
          number = vcard.getPhoneHome("VOICE");
        }

        if (ModelUtil.hasLength(number)) {
          getDefaultGuiManager().dial(number);
        }
      }
    }
  }
コード例 #5
0
ファイル: ContactItem.java プロジェクト: enson16855/Spark
  /**
   * Sets the status label text based on the users status.
   *
   * @param status the users status.
   */
  public void setStatusText(String status) {
    setStatus(status);

    if (ModelUtil.hasLength(status)) {
      getDescriptionLabel().setText(" - " + status);
    } else {
      getDescriptionLabel().setText("");
    }
  }
コード例 #6
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();
  }
コード例 #7
0
ファイル: ContactItem.java プロジェクト: enson16855/Spark
  /**
   * Returns the url of the avatar belonging to this contact.
   *
   * @return the url of the avatar.
   * @throws MalformedURLException thrown if the address is invalid.
   */
  public URL getAvatarURL() throws MalformedURLException {
    contactsDir.mkdirs();

    if (ModelUtil.hasLength(hash)) {
      final File imageFile = new File(contactsDir, hash);
      if (imageFile.exists()) {
        return imageFile.toURI().toURL();
      }
    }

    return SparkManager.getVCardManager().getAvatarURLIfAvailable(getJID());
  }
コード例 #8
0
ファイル: BroadcastDialog.java プロジェクト: kevintich/IM-1
  /**
   * Sends a broadcast message to all users selected.
   *
   * @param dlg
   */
  private boolean sendBroadcasts(JDialog dlg) {
    final Set<String> jids = new HashSet<String>();

    for (CheckNode node : nodes) {
      if (node.isSelected()) {
        String jid = (String) node.getAssociatedObject();
        jids.add(jid);
      }
    }

    if (jids.size() == 0) {
      JOptionPane.showMessageDialog(
          dlg,
          Res.getString("message.broadcast.no.user.selected"),
          Res.getString("title.error"),
          JOptionPane.ERROR_MESSAGE);
      return false;
    }

    String text = messageBox.getText();
    if (!ModelUtil.hasLength(text)) {
      JOptionPane.showMessageDialog(
          dlg,
          Res.getString("message.broadcast.no.text"),
          Res.getString("title.error"),
          JOptionPane.ERROR_MESSAGE);
      return false;
    }

    for (String jid : jids) {
      final Message message = new Message();
      message.setTo(jid);
      message.setBody(text);

      if (normalMessageButton.isSelected()) {
        message.setType(Message.Type.normal);
      } else {
        message.setType(Message.Type.headline);
      }
      SparkManager.getConnection().sendPacket(message);
    }

    return true;
  }
コード例 #9
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);
    }
  }
コード例 #10
0
ファイル: ContactItem.java プロジェクト: enson16855/Spark
  /**
   * Updates the icon of the user based on their presence.
   *
   * @param presence the users presence.
   */
  public void updatePresenceIcon(Presence presence) {
    ChatManager chatManager = SparkManager.getChatManager();
    boolean handled = chatManager.fireContactItemPresenceChanged(this, presence);
    if (handled) {
      return;
    }

    String status = presence.getStatus();
    Icon statusIcon = SparkRes.getImageIcon(SparkRes.GREEN_BALL);
    boolean isAvailable = false;
    if (status == null && presence.isAvailable()) {
      Presence.Mode mode = presence.getMode();
      if (mode == Presence.Mode.available) {
        status = Res.getString("status.online");
        isAvailable = true;
      } else if (mode == Presence.Mode.away) {
        status = Res.getString("status.away");
        statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
      } else if (mode == Presence.Mode.chat) {
        status = Res.getString("status.free.to.chat");
      } else if (mode == Presence.Mode.dnd) {
        status = Res.getString("status.do.not.disturb");
        statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
      } else if (mode == Presence.Mode.xa) {
        status = Res.getString("status.extended.away");
        statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
      }
    }

    if (presence.isAvailable()
        && (presence.getMode() == Presence.Mode.dnd
            || presence.getMode() == Presence.Mode.away
            || presence.getMode() == Presence.Mode.xa)) {
      statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
    } else if (presence.isAvailable()) {
      isAvailable = true;
    } else if (!presence.isAvailable()) {
      getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
      getNicknameLabel().setForeground((Color) UIManager.get("ContactItemOffline.color"));

      RosterEntry entry = SparkManager.getConnection().getRoster().getEntry(getJID());
      if (entry != null
          && (entry.getType() == RosterPacket.ItemType.none
              || entry.getType() == RosterPacket.ItemType.from)
          && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) {
        // Do not move out of group.
        setIcon(SparkRes.getImageIcon(SparkRes.SMALL_QUESTION));
        getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
        setStatusText(Res.getString("status.pending"));
      } else {
        // We should keep the offline bullet (not available) instead of putting icon null.
        setIcon(SparkRes.getImageIcon(SparkRes.CLEAR_BALL_ICON));
        setFont(new Font("Dialog", Font.PLAIN, fontSize));
        getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
        setAvailable(false);
        if (ModelUtil.hasLength(status)) {
          setStatusText(status);
        } else {
          setStatusText("");
        }
      }

      sideIcon.setIcon(null);
      setAvailable(false);
      return;
    }

    Icon sIcon = PresenceManager.getIconFromPresence(presence);
    if (sIcon != null) {
      setIcon(sIcon);
    } else {
      setIcon(statusIcon);
    }
    if (status != null) {
      setStatus(status);
    }

    if (PresenceManager.isOnPhone(presence)) {
      statusIcon = SparkRes.getImageIcon(SparkRes.ON_PHONE_IMAGE);
      setIcon(statusIcon);
    }

    // Always change nickname label to black.
    getNicknameLabel().setForeground((Color) UIManager.get("ContactItemNickname.foreground"));

    if (isAvailable) {
      getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
      if (Res.getString("status.online").equals(status)
          || Res.getString("available").equalsIgnoreCase(status)) {
        setStatusText("");
      } else {
        setStatusText(status);
      }
    } else if (presence.isAvailable()) {
      LocalPreferences pref = SettingsManager.getLocalPreferences();
      if (pref.isGrayingOutEnabled()) {
        getNicknameLabel().setFont(new Font("Dialog", Font.ITALIC, fontSize));
        getNicknameLabel().setForeground(Color.gray);
      } else {
        getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
        getNicknameLabel().setForeground(Color.black);
      }
      if (status != null) {
        setStatusText(status);
      }
    }

    setAvailable(true);
  }
コード例 #11
0
  /** Builds the part of the incoming call UI with the Callers information. */
  private void buildCallerBlock(String callerID, String phoneNumber) {
    final JPanel panel = new JPanel(new GridBagLayout());
    panel.setBackground(Color.white);
    panel.setBorder(BorderFactory.createLineBorder(new Color(197, 213, 230), 1));

    // Add Avatar
    panel.add(
        avatarLabel,
        new GridBagConstraints(
            0,
            0,
            1,
            3,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(5, 0, 5, 0),
            0,
            0));

    // Add Avatar information
    panel.add(
        titleLabel,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 0),
            0,
            0));
    panel.add(
        professionLabel,
        new GridBagConstraints(
            1,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 7, 0, 0),
            0,
            0));
    panel.add(
        phoneLabel,
        new GridBagConstraints(
            1,
            2,
            1,
            1,
            0.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 7, 0, 0),
            0,
            0));

    // Add History labels
    panel.add(
        lastCalledLabel,
        new GridBagConstraints(
            0,
            3,
            2,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(15, 5, 0, 0),
            0,
            0));
    panel.add(
        durationLabel,
        new GridBagConstraints(
            0,
            4,
            2,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 0),
            0,
            0));

    // Set default settings
    titleLabel.setForeground(new Color(64, 103, 162));
    titleLabel.setFont(new Font("Dialog", Font.BOLD, 16));

    final VCard vcard = SparkManager.getVCardManager().searchPhoneNumber(phoneNumber);
    if (vcard != null) {
      handleVCardInformation(vcard, phoneNumber);
    } else {
      avatarLabel.setVisible(false);
      professionLabel.setVisible(false);
      phoneLabel.setVisible(true);

      titleLabel.setText(callerID);
      phoneLabel.setText(phoneNumber);
    }

    // Update with previous call history.
    Date lastDate = null;
    long callLength = 0;
    for (HistoryCall call : SoftPhoneManager.getInstance().getLogManager().getCallHistory()) {
      String number = TelephoneUtils.removeInvalidChars(call.getNumber());
      if (number.equals(TelephoneUtils.removeInvalidChars(phoneNumber))) {
        lastDate = new Date(call.getTime());
      }

      callLength = call.getCallLength();
    }

    final StringBuilder builder = new StringBuilder();
    builder.append(PhoneRes.getIString("phone.lastcalled") + ": ");
    if (lastDate == null) {
      builder.append(PhoneRes.getIString("phone.never"));
      durationLabel.setVisible(false);
    } else {
      builder.append(formatter.format(lastDate));
      durationLabel.setText(
          PhoneRes.getIString("phone.duration")
              + ": "
              + ModelUtil.getTimeFromLong(callLength * 1000));
    }

    lastCalledLabel.setText(builder.toString());

    // Add To Panel
    add(
        panel,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0));
  }