Ejemplo n.º 1
0
  /**
   * Handles a message received from the remote party.
   *
   * @param msg The Message object that was received.
   */
  private void doMessageReceived(Message msg) {
    assert (SwingUtilities.isEventDispatchThread()) : "not in UI thread";

    if (msg.getType() == Message.Type.ERROR) {
      JOptionPane.showMessageDialog(
          this,
          msg.getError().getMessage(),
          JavolinApp.getAppName() + ": Error",
          JOptionPane.ERROR_MESSAGE);
    } else if (msg.getType() == Message.Type.HEADLINE) {
      // Do nothing
    } else {
      String jid = msg.getFrom();
      if (jid != null) setUserResource(jid);

      Date date = null;
      PacketExtension ext = msg.getExtension("x", "jabber:x:delay");
      if (ext != null && ext instanceof DelayInformation) {
        date = ((DelayInformation) ext).getStamp();
      }

      mLog.message(mRemoteIdFull, mRemoteNick, msg.getBody(), date);
      Audio.playMessage();
    }
  }
Ejemplo n.º 2
0
  /** Sends the message that the user typed in the input text area. */
  private void doSendMessage() {
    assert (SwingUtilities.isEventDispatchThread()) : "not in UI thread";

    try {
      String message = mInputText.getText();

      /* Make sure we've got the right resource. */
      mRemoteIdFull = applyLastKnownResource(mRemoteIdBare);
      mChatObject.setParticipant(mRemoteIdFull);

      mChatObject.sendMessage(message);
      mInputText.setText("");
      mLog.message(mLocalId, mLocalId, message);
      // Make the noise, since we won't get an incoming copy of this
      Audio.playMessage();
    } catch (XMPPException ex) {
      new ErrorWrapper(ex);
      JOptionPane.showMessageDialog(
          this, ex.toString(), JavolinApp.getAppName() + ": Error", JOptionPane.ERROR_MESSAGE);
    }
  }