001 /* 002 Copyright (C) 2003 Adam Olsen 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU General Public License as published by 006 the Free Software Foundation; either version 1, or (at your option) 007 any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU General Public License for more details. 013 014 You should have received a copy of the GNU General Public License 015 along with this program; if not, write to the Free Software 016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 017 */ 018 019 package com.valhalla.jbother.jabber.smack; 020 021 import org.jivesoftware.smack.PacketListener; 022 import org.jivesoftware.smack.packet.Message; 023 import org.jivesoftware.smack.packet.Packet; 024 025 import com.valhalla.jbother.*; 026 import com.valhalla.jbother.groupchat.*; 027 import javax.swing.SwingUtilities; 028 029 /** 030 * Listens for Group Chat Messages 031 * 032 * @author Adam Olsen 033 * @version 1.0 034 */ 035 public class GroupChatMessagePacketListener implements PacketListener 036 { 037 private ChatRoomPanel window; 038 039 /** 040 * Sets up the group chat message listener 041 * @param window the window that this litener belongs to 042 */ 043 public GroupChatMessagePacketListener( ChatRoomPanel window ) 044 { 045 this.window = window; 046 } 047 048 /** 049 * Processes the packet 050 */ 051 public void processPacket( Packet message ) 052 { 053 final Message packet = (Message)message; 054 055 if( packet.getType() != Message.Type.GROUP_CHAT ) return; 056 057 final String from = packet.getFrom(); 058 if( from != null ) 059 { 060 SwingUtilities.invokeLater( new Runnable() 061 { 062 public void run() 063 { 064 final String messageBody = packet.getBody(); 065 066 if( packet.getSubject() != null ) 067 window.setSubject( packet.getSubject() ); 068 069 if( messageBody != null ) window.recieveMessage( from.replaceAll( ".*\\/", "" ), messageBody ); 070 } 071 } ); 072 } 073 } 074 }