use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.
the class ChatTranscriptPlugin method chatRoomOpened.
public void chatRoomOpened(final ChatRoom room) {
LocalPreferences pref = SettingsManager.getLocalPreferences();
if (!pref.isChatHistoryEnabled()) {
return;
}
final String jid = room.getRoomname();
File transcriptFile = ChatTranscripts.getTranscriptFile(jid);
if (!transcriptFile.exists()) {
return;
}
if (room instanceof ChatRoomImpl) {
new ChatRoomDecorator(room);
}
}
use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.
the class OnlineAgents method activateChat.
/**
* Activate a chat room with the selected user.
*/
private void activateChat(final String userJID, final String nickname) {
if (!ModelUtil.hasLength(userJID)) {
return;
}
SwingWorker worker = new SwingWorker() {
final ChatManager chatManager = SparkManager.getChatManager();
ChatRoom chatRoom;
public Object construct() {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
Log.error("Error in activate chat.", e);
}
ChatContainer chatRooms = chatManager.getChatContainer();
try {
chatRoom = chatRooms.getChatRoom(userJID);
} catch (ChatRoomNotFoundException e) {
Log.warning("Room not found for jid: " + userJID, e);
}
return chatRoom;
}
public void finished() {
if (chatRoom == null) {
chatRoom = new ChatRoomImpl(userJID, nickname, nickname);
chatManager.getChatContainer().addChatRoom(chatRoom);
}
chatManager.getChatContainer().activateChatRoom(chatRoom);
}
};
worker.start();
}
use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.
the class ChatRoomOpeningListener method chatRoomOpened.
@Override
public void chatRoomOpened(final ChatRoom room) {
if (// Check for 1on1 Chat
!(room instanceof ChatRoomImpl)) {
return;
}
final ChatRoomButton sendGameButton = new ChatRoomButton("BS");
room.getToolBar().addChatRoomButton(sendGameButton);
final String opponentJID = ((ChatRoomImpl) room).getJID();
sendGameButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final GameOfferPacket offer = new GameOfferPacket();
offer.setTo(opponentJID);
offer.setType(IQ.Type.get);
room.getTranscriptWindow().insertCustomText(BsRes.getString("request"), false, false, Color.BLUE);
try {
SparkManager.getConnection().sendStanza(offer);
} catch (SmackException.NotConnectedException e1) {
Log.warning("Unable to send offer to " + opponentJID, e1);
}
SparkManager.getConnection().addAsyncStanzaListener(new StanzaListener() {
@Override
public void processPacket(Stanza stanza) {
GameOfferPacket answer = (GameOfferPacket) stanza;
answer.setStartingPlayer(offer.isStartingPlayer());
answer.setGameID(offer.getGameID());
String name = XmppStringUtils.parseLocalpart(opponentJID);
if (answer.getType() == IQ.Type.result) {
// ACCEPT
room.getTranscriptWindow().insertCustomText(BsRes.getString("accepted", name), false, false, Color.BLUE);
createWindow(answer, opponentJID);
} else {
// DECLINE
room.getTranscriptWindow().insertCustomText(BsRes.getString("declined", name), false, false, Color.RED);
}
}
}, new PacketIDFilter(offer.getPacketID()));
}
});
}
use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.
the class SparkTabHandler method decorateStaleTab.
/**
* Updates the SparkTab to show it is in a stale state.
*
* @param tab the SparkTab.
* @param chatRoom the ChatRoom of the SparkTab.
*/
protected void decorateStaleTab(SparkTab tab, ChatRoom chatRoom) {
tab.setTitleColor(Color.gray);
tab.setTabFont(tab.getDefaultFont());
String jid = ((ChatRoomImpl) chatRoom).getParticipantJID();
Presence presence = PresenceManager.getPresence(jid);
if (!presence.isAvailable()) {
tab.setIcon(SparkRes.getImageIcon(SparkRes.IM_UNAVAILABLE_STALE_IMAGE));
} else {
Presence.Mode mode = presence.getMode();
if (mode == Presence.Mode.available || mode == null) {
tab.setIcon(SparkRes.getImageIcon(SparkRes.IM_AVAILABLE_STALE_IMAGE));
} else if (mode == Presence.Mode.away) {
tab.setIcon(SparkRes.getImageIcon(SparkRes.IM_AWAY_STALE_IMAGE));
} else if (mode == Presence.Mode.chat) {
tab.setIcon(SparkRes.getImageIcon(SparkRes.IM_FREE_CHAT_STALE_IMAGE));
} else if (mode == Presence.Mode.dnd) {
tab.setIcon(SparkRes.getImageIcon(SparkRes.IM_DND_STALE_IMAGE));
} else if (mode == Presence.Mode.xa) {
tab.setIcon(SparkRes.getImageIcon(SparkRes.IM_DND_STALE_IMAGE));
}
}
tab.validateTab();
}
use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.
the class ChatRoomTransferDecorator method filesDropped.
@Override
public void filesDropped(Collection<File> files, Component component) {
if (component instanceof ChatRoomImpl) {
ChatRoomImpl roomImpl = (ChatRoomImpl) component;
for (File file : files) {
SparkManager.getTransferManager().sendFile(file, roomImpl.getParticipantJID());
}
SparkManager.getChatManager().getChatContainer().activateChatRoom(roomImpl);
}
}
Aggregations