Esempio n. 1
0
 public void receiveMsg(Message msg) {
   // System.out.println(msg.getSubject() + " : " + msg.getBody());
   String subject = msg.getSubject();
   if (subject != null) {
     if (subject.equals("online")) {
       onlineUsers.addElement(new HostItem(msg.getBody()));
       displayMessage(msg.getBody() + " : Online", onlineClientAttrSet);
     } else if (subject.equals("offline")) {
       onlineUsers.removeElement(new HostItem(msg.getBody()));
       displayMessage(msg.getBody() + " : Offline", offlineClientAttrSet);
     } else if (subject.equals("eavesdrop enabled")) {
       Object[] values = jListOnlineUsers.getSelectedValues();
       if (values == null) return;
       for (int i = 0; i < values.length; i++) {
         ((HostItem) values[i]).eavesDroppingEnabled = true;
       }
       jListOnlineUsers.updateUI();
     } else if (subject.equals("eavesdrop disabled")) {
       Object[] values = jListOnlineUsers.getSelectedValues();
       if (values == null) return;
       for (int i = 0; i < values.length; i++) {
         ((HostItem) values[i]).eavesDroppingEnabled = false;
       }
       jListOnlineUsers.updateUI();
     } else if (subject.equals("globaleavesdrop enabled")) {
       displayMessage("Global Eavesdropping Enabled", onlineClientAttrSet);
     } else if (subject.equals("globaleavesdrop disabled")) {
       displayMessage("Global Eavesdropping Disabled", offlineClientAttrSet);
     } else {
       String to = msg.getTo();
       String from = msg.getFrom() == null ? "server" : msg.getFrom();
       String body = msg.getBody() != null ? msg.getBody() : "";
       if (jTextFieldUser.getText().equals(to)) { // this message is sent to us
         displayMessage(subject, from, body, incomingMsgAttrSet);
       } else { // this is an eavesdrop message
         displayMessage(subject, to, from, body, eavesdropAttrSet);
       }
     }
   } else {
     subject = "";
     String to = msg.getTo();
     String from = msg.getFrom() == null ? "server" : msg.getFrom();
     String body = msg.getBody() != null ? msg.getBody() : "";
     if (jTextFieldUser.getText().equals(to)) { // this message is sent to us
       displayMessage(subject, from, body, incomingMsgAttrSet);
     } else { // this is an eavesdrop message
       displayMessage(subject, to, from, body, eavesdropAttrSet);
     }
   }
 }
Esempio n. 2
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();
    }
  }