Search in sources :

Example 6 with ChatRoomImpl

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);
    }
}
Also used : LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) File(java.io.File) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 7 with ChatRoomImpl

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();
}
Also used : ChatContainer(org.jivesoftware.spark.ui.ChatContainer) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) SwingWorker(org.jivesoftware.spark.util.SwingWorker) ChatManager(org.jivesoftware.spark.ChatManager) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 8 with ChatRoomImpl

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()));
        }
    });
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) GameOfferPacket(battleship.packets.GameOfferPacket) Stanza(org.jivesoftware.smack.packet.Stanza) StanzaListener(org.jivesoftware.smack.StanzaListener) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter) ChatRoomButton(org.jivesoftware.spark.ui.ChatRoomButton)

Example 9 with ChatRoomImpl

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();
}
Also used : Presence(org.jivesoftware.smack.packet.Presence) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 10 with ChatRoomImpl

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);
    }
}
Also used : File(java.io.File) 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