Search in sources :

Example 11 with ChatRoomImpl

use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.

the class SparkTransferManager method sendImage.

/**
 * Send an image to a user.
 *
 * @param image the image to send.
 * @param room  the ChatRoom of the user you wish to send the image to.
 */
public void sendImage(final BufferedImage image, final ChatRoom room) {
    File tmpDirectory = new File(Spark.getSparkUserHome(), "/tempImages");
    tmpDirectory.mkdirs();
    String imageName = "image_" + StringUtils.randomString(2) + ".png";
    final File imageFile = new File(tmpDirectory, imageName);
    // Write image to system.
    room.setCursor(new Cursor(Cursor.WAIT_CURSOR));
    SwingWorker writeImageThread = new SwingWorker() {

        public Object construct() {
            try {
                // Write out file in separate thread.
                ImageIO.write(image, "png", imageFile);
            } catch (IOException e) {
                Log.error(e);
            }
            return true;
        }

        public void finished() {
            ChatRoomImpl roomImpl = (ChatRoomImpl) room;
            sendFile(imageFile, roomImpl.getParticipantJID());
            SparkManager.getChatManager().getChatContainer().activateChatRoom(room);
            room.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
    };
    writeImageThread.start();
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker) IOException(java.io.IOException) Cursor(java.awt.Cursor) File(java.io.File) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 12 with ChatRoomImpl

use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.

the class SparkTransferManager method addSendFileButton.

private void addSendFileButton() {
    final ChatManager chatManager = SparkManager.getChatManager();
    chatManager.addChatRoomListener(new ChatRoomListenerAdapter() {

        public void chatRoomOpened(final ChatRoom room) {
            if (!(room instanceof ChatRoomImpl)) {
                return;
            }
            // Otherwise,
            new ChatRoomTransferDecorator(room);
        }

        public void chatRoomClosed(ChatRoom room) {
        }
    });
}
Also used : ChatRoomListenerAdapter(org.jivesoftware.spark.ui.ChatRoomListenerAdapter) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatManager(org.jivesoftware.spark.ChatManager) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 13 with ChatRoomImpl

use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.

the class ConferenceServices method addChatRoomListener.

private void addChatRoomListener() {
    ChatManager chatManager = SparkManager.getChatManager();
    chatManager.addChatRoomListener(new ChatRoomListener() {

        public void chatRoomOpened(final ChatRoom room) {
            if (room instanceof ChatRoomImpl) {
                final ChatRoomDecorator decorator = new ChatRoomDecorator(room);
                decorator.decorate();
            }
        }

        public void chatRoomLeft(ChatRoom room) {
        }

        public void chatRoomClosed(ChatRoom room) {
        }

        public void chatRoomActivated(ChatRoom room) {
        }

        public void userHasJoined(ChatRoom room, String userid) {
        }

        public void userHasLeft(ChatRoom room, String userid) {
        }
    });
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) ChatManager(org.jivesoftware.spark.ChatManager) MultiUserChatManager(org.jivesoftware.smackx.muc.MultiUserChatManager) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 14 with ChatRoomImpl

use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.

the class GroupChatParticipantList method startChat.

protected void startChat(ChatRoom groupChat, String groupJID) {
    String userNickname = XmppStringUtils.parseResource(groupJID);
    String roomTitle = userNickname + " - " + XmppStringUtils.parseLocalpart(groupChat.getRoomname());
    String nicknameOfUser = XmppStringUtils.parseResource(groupJID);
    String nickname = groupChat.getNickname();
    if (nicknameOfUser.equals(nickname)) {
        return;
    }
    ChatRoom chatRoom;
    try {
        chatRoom = chatManager.getChatContainer().getChatRoom(groupJID);
    } catch (ChatRoomNotFoundException e) {
        Log.debug("Could not find chat room - " + groupJID);
        // Create new room
        chatRoom = new ChatRoomImpl(groupJID, nicknameOfUser, roomTitle);
        chatManager.getChatContainer().addChatRoom(chatRoom);
    }
    chatManager.getChatContainer().activateChatRoom(chatRoom);
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 15 with ChatRoomImpl

use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.

the class BroadcastPlugin method isTabHandled.

public boolean isTabHandled(SparkTab tab, Component component, boolean isSelectedTab, boolean chatFrameFocused) {
    if (component instanceof ChatRoom) {
        ChatRoom chatroom = (ChatRoom) component;
        if (broadcastRooms.contains(chatroom)) {
            final ChatRoomImpl room = (ChatRoomImpl) component;
            tab.setIcon(SparkRes.getImageIcon(SparkRes.INFORMATION_IMAGE));
            String nickname = room.getTabTitle();
            nickname = Res.getString("message.broadcast.from", nickname);
            tab.setTabTitle(nickname);
            if ((!chatFrameFocused || !isSelectedTab) && room.getUnreadMessageCount() > 0) {
                // Make tab red.
                tab.setTitleColor(Color.red);
                tab.setTabBold(true);
            } else {
                tab.setTitleColor(Color.black);
                tab.setTabFont(tab.getDefaultFont());
                room.clearUnreadMessageCount();
            }
            return true;
        }
    }
    return false;
}
Also used : ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Aggregations

ChatRoomImpl (org.jivesoftware.spark.ui.rooms.ChatRoomImpl)25 ChatRoom (org.jivesoftware.spark.ui.ChatRoom)9 ChatManager (org.jivesoftware.spark.ChatManager)8 GroupChatRoom (org.jivesoftware.spark.ui.rooms.GroupChatRoom)6 SwingWorker (org.jivesoftware.spark.util.SwingWorker)5 File (java.io.File)4 StanzaListener (org.jivesoftware.smack.StanzaListener)4 Message (org.jivesoftware.smack.packet.Message)4 Presence (org.jivesoftware.smack.packet.Presence)4 ChatRoomButton (org.jivesoftware.spark.ui.ChatRoomButton)4 ChatRoomNotFoundException (org.jivesoftware.spark.ui.ChatRoomNotFoundException)4 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 SmackException (org.jivesoftware.smack.SmackException)3 Stanza (org.jivesoftware.smack.packet.Stanza)3 SparkManager (org.jivesoftware.spark.SparkManager)3 ChatRoomListenerAdapter (org.jivesoftware.spark.ui.ChatRoomListenerAdapter)3 LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)3 java.awt.event (java.awt.event)2 TimerTask (java.util.TimerTask)2