Small update to broadcasting.

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@5086 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Derek DeMoro
2006-08-29 18:56:21 +00:00
committed by derek
parent a5666d21e8
commit f7073d8776
5 changed files with 142 additions and 41 deletions

View File

@ -207,9 +207,15 @@ public class ChatManager implements MessageEventNotificationListener {
catch (ChatRoomNotFoundException e) {
ContactList contactList = SparkManager.getWorkspace().getContactList();
ContactItem item = contactList.getContactItemByJID(jid);
if (item != null) {
String nickname = item.getNickname();
chatRoom = new ChatRoomImpl(jid, nickname, nickname);
}
else {
chatRoom = new ChatRoomImpl(jid, jid, jid);
}
String nickname = item.getNickname();
chatRoom = new ChatRoomImpl(jid, nickname, nickname);
getChatContainer().addChatRoom(chatRoom);
}

View File

@ -92,6 +92,7 @@ public class AlertUI extends JPanel implements ActionListener {
SparkManager.getWorkspace().addAlert(this);
SparkManager.getAlertManager().flashWindowStopOnFocus(SparkManager.getMainWindow());
setBackground(new Color(195, 217, 255));
}
public void actionPerformed(ActionEvent actionEvent) {

View File

@ -948,9 +948,11 @@ public class ChatContainer extends SparkTabbedPane implements MessageListener, C
if (room instanceof ChatRoomImpl) {
final ChatRoomImpl chatRoomImpl = (ChatRoomImpl)room;
Presence presence = chatRoomImpl.getPresence();
Icon icon = SparkManager.getUserManager().getIconFromPresence(presence);
tab.setIcon(icon);
if (!chatRoomImpl.isIconHandler()) {
Presence presence = chatRoomImpl.getPresence();
Icon icon = SparkManager.getUserManager().getIconFromPresence(presence);
tab.setIcon(icon);
}
}
titleLabel.setForeground(Color.black);
@ -1241,6 +1243,11 @@ public class ChatContainer extends SparkTabbedPane implements MessageListener, C
titleLabel.setFont(tab.getDefaultFont());
if (chatRoom instanceof ChatRoomImpl) {
ChatRoomImpl impl = (ChatRoomImpl)chatRoom;
if(impl.isIconHandler()){
return;
}
String jid = ((ChatRoomImpl)chatRoom).getParticipantJID();
Presence presence = SparkManager.getConnection().getRoster().getPresence(jid);

View File

@ -84,6 +84,8 @@ public class ChatRoomImpl extends ChatRoom {
private long lastActivity;
private boolean iconHandler;
/**
* Constructs a 1-to-1 ChatRoom.
@ -295,10 +297,22 @@ public class ChatRoomImpl extends ChatRoom {
return tabIcon;
}
public void setTabIcon(Icon icon) {
this.tabIcon = icon;
}
public String getTabTitle() {
return tabTitle;
}
public void setTabTitle(String tabTitle) {
this.tabTitle = tabTitle;
}
public void setRoomTitle(String roomTitle) {
this.roomTitle = roomTitle;
}
public String getRoomTitle() {
return roomTitle;
}
@ -554,5 +568,13 @@ public class ChatRoomImpl extends ChatRoom {
return presence;
}
public boolean isIconHandler() {
return iconHandler;
}
public void setIconHandler(boolean iconHandler) {
this.iconHandler = iconHandler;
}
}

View File

@ -18,25 +18,39 @@ import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smackx.packet.DelayInformation;
import org.jivesoftware.smackx.packet.VCard;
import org.jivesoftware.spark.ChatManager;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.component.AlertUI;
import org.jivesoftware.spark.component.InputDialog;
import org.jivesoftware.spark.component.RolloverButton;
import org.jivesoftware.spark.component.tabbedPane.SparkTab;
import org.jivesoftware.spark.plugin.ContextMenuListener;
import org.jivesoftware.spark.plugin.Plugin;
import org.jivesoftware.spark.ui.ChatContainer;
import org.jivesoftware.spark.ui.ChatRoom;
import org.jivesoftware.spark.ui.ChatRoomNotFoundException;
import org.jivesoftware.spark.ui.ContactGroup;
import org.jivesoftware.spark.ui.ContactItem;
import org.jivesoftware.spark.ui.ContactList;
import org.jivesoftware.spark.ui.MessageListener;
import org.jivesoftware.spark.ui.TranscriptWindow;
import org.jivesoftware.spark.ui.rooms.ChatRoomImpl;
import org.jivesoftware.spark.ui.status.StatusBar;
import org.jivesoftware.spark.util.GraphicUtils;
import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.spark.util.ResourceUtils;
import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.plugin.manager.Enterprise;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
@ -45,17 +59,6 @@ import java.awt.event.MouseEvent;
import java.util.Collection;
import java.util.Iterator;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
/**
* Handles broadcasts from server and allows for roster wide broadcasts.
*/
@ -231,29 +234,91 @@ public class BroadcastPlugin implements Plugin, PacketListener {
String title = host;
if (message.getFrom() != null) {
VCard vcard = SparkManager.getVCardManager().getVCard(StringUtils.parseBareAddress(message.getFrom()));
ImageIcon icon = null;
if (vcard != null && vcard.getAvatar() != null) {
icon = new ImageIcon(vcard.getAvatar());
icon = GraphicUtils.scaleImageIcon(icon, 48, 48);
}
else if (icon == null || icon.getIconWidth() == -1) {
icon = SparkRes.getImageIcon(SparkRes.INFORMATION_IMAGE);
}
String nickname = SparkManager.getUserManager().getUserNicknameFromJID(message.getFrom());
title = nickname;
toaster.setTitle(title);
toaster.setToasterHeight(250);
toaster.setToasterWidth(250);
toaster.showToaster(icon, buf.toString());
}
else {
toaster.setTitle(title);
toaster.showToaster(SparkRes.getImageIcon(SparkRes.INFORMATION_IMAGE), buf.toString());
}
new AlertUI("Broadcast", buf.toString());
if (!from.contains("@")) {
ChatManager chatManager = SparkManager.getChatManager();
ChatContainer container = chatManager.getChatContainer();
ChatRoomImpl chatRoom = null;
try {
chatRoom = (ChatRoomImpl)container.getChatRoom(from);
}
catch (ChatRoomNotFoundException e) {
chatRoom = new ChatRoomImpl(from, from, "Broadcast from " + from);
chatRoom.setTabIcon(SparkRes.getImageIcon(SparkRes.INFORMATION_IMAGE));
chatRoom.setIconHandler(true);
chatRoom.getBottomPanel().setVisible(false);
chatRoom.getToolBar().setVisible(false);
SparkManager.getChatManager().getChatContainer().addChatRoom(chatRoom);
}
chatRoom.insertMessage(message);
container.makeTabRed(chatRoom);
}
else if (message.getFrom() != null) {
String jid = StringUtils.parseBareAddress(from);
String nickname = SparkManager.getUserManager().getUserNicknameFromJID(jid);
ChatManager chatManager = SparkManager.getChatManager();
ChatContainer container = chatManager.getChatContainer();
ChatRoomImpl chatRoom = null;
try {
chatRoom = (ChatRoomImpl)container.getChatRoom(from);
}
catch (ChatRoomNotFoundException e) {
chatRoom = new ChatRoomImpl(jid, nickname, "Broadcast from " + nickname);
chatRoom.setTabIcon(SparkRes.getImageIcon(SparkRes.INFORMATION_IMAGE));
chatRoom.setIconHandler(true);
SparkManager.getChatManager().getChatContainer().addChatRoom(chatRoom);
}
chatRoom.insertMessage(message);
container.makeTabRed(chatRoom);
chatRoom.addMessageListener(new MessageListener() {
boolean waiting = true;
public void messageReceived(ChatRoom room, Message message) {
if (waiting) {
useDefaultRoomSettings((ChatRoomImpl)room);
waiting = false;
}
}
public void messageSent(ChatRoom room, Message message) {
if (waiting) {
useDefaultRoomSettings((ChatRoomImpl)room);
waiting = false;
}
}
});
}
}
private void useDefaultRoomSettings(ChatRoomImpl room) {
try {
room.setIconHandler(false);
String jid = StringUtils.parseBareAddress(room.getParticipantJID());
String nickname = SparkManager.getUserManager().getUserNicknameFromJID(jid);
Icon icon = SparkManager.getUserManager().getIconFromPresence(room.getPresence());
room.setTabIcon(icon);
room.setTabTitle(nickname);
int index = SparkManager.getChatManager().getChatContainer().indexOfComponent(room);
if (index != -1) {
SparkTab tab = SparkManager.getChatManager().getChatContainer().getTabAt(index);
tab.getTitleLabel().setText(nickname);
tab.setIcon(icon);
}
}
catch (Exception e) {
Log.error(e);
}
}
/**