Search in sources :

Example 16 with ChatRoom

use of org.jivesoftware.spark.ui.ChatRoom 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 17 with ChatRoom

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

the class ApplePlugin method handleIdle.

private void handleIdle() {
    SparkManager.getMainWindow().addComponentListener(new ComponentListener() {

        public void componentResized(ComponentEvent componentEvent) {
            setActivity();
        }

        public void componentMoved(ComponentEvent componentEvent) {
            setActivity();
        }

        public void componentShown(ComponentEvent componentEvent) {
            setActivity();
        }

        public void componentHidden(ComponentEvent componentEvent) {
            setActivity();
        }
    });
    SparkManager.getChatManager().addChatRoomListener(new ChatRoomListenerAdapter() {

        public void chatRoomOpened(ChatRoom room) {
            if (!addedFrameListener) {
                chatFrame = SparkManager.getChatManager().getChatContainer().getChatFrame();
                chatFrame.addComponentListener(new ComponentListener() {

                    public void componentResized(ComponentEvent componentEvent) {
                        setActivity();
                    }

                    public void componentMoved(ComponentEvent componentEvent) {
                        setActivity();
                    }

                    public void componentShown(ComponentEvent componentEvent) {
                        setActivity();
                    }

                    public void componentHidden(ComponentEvent componentEvent) {
                        setActivity();
                    }
                });
                addedFrameListener = true;
            }
            setActivity();
        }

        public void chatRoomClosed(ChatRoom room) {
            setActivity();
        }
    });
    SparkManager.getSessionManager().addPresenceListener(new PresenceListener() {

        public void presenceChanged(Presence presence) {
            if (presence.isAvailable() && !presence.isAway()) {
                lastActive = System.currentTimeMillis();
            }
        }
    });
    final Timer timer = new Timer();
    timer.scheduleAtFixedRate(new TimerTask() {

        public void run() {
            sparkIsIdle();
        }
    }, 10000, 10000);
    lastActive = System.currentTimeMillis();
}
Also used : PresenceListener(org.jivesoftware.spark.ui.PresenceListener) ComponentListener(java.awt.event.ComponentListener) ChatRoomListenerAdapter(org.jivesoftware.spark.ui.ChatRoomListenerAdapter) Timer(java.util.Timer) TimerTask(java.util.TimerTask) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) Presence(org.jivesoftware.smack.packet.Presence) ComponentEvent(java.awt.event.ComponentEvent)

Example 18 with ChatRoom

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

the class FastpathTabHandler method isTabHandled.

public boolean isTabHandled(SparkTab tab, Component component, boolean isSelectedTab, boolean chatFrameFocused) {
    if (component instanceof ChatRoom) {
        RoomState roomState = FastpathPlugin.getLitWorkspace().getRoomState((ChatRoom) component);
        if (roomState == null) {
            // This is not a fastpath room.
            return false;
        }
        // This is a fastpath room.
        handleFastpathRoom(tab, (ChatRoom) component, isSelectedTab, chatFrameFocused);
        return true;
    }
    return false;
}
Also used : ChatRoom(org.jivesoftware.spark.ui.ChatRoom) RoomState(org.jivesoftware.fastpath.workspace.Workpane.RoomState)

Example 19 with ChatRoom

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

the class GrowlTalker method onClickCallback.

@Override
public void onClickCallback(GntpNotification notification) {
    Log.debug("Callback clicked: " + notification);
    final String jid = XmppStringUtils.parseBareJid((String) notification.getContext());
    final ChatRoom room = SparkManager.getChatManager().getChatRoom(jid);
    SparkManager.getChatManager().getChatContainer().activateChatRoom(room);
    SparkManager.getChatManager().getChatContainer().requestFocusInWindow();
}
Also used : ChatRoom(org.jivesoftware.spark.ui.ChatRoom)

Example 20 with ChatRoom

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

the class AnswerFormDialog method sendAnswerForm.

/**
 * Sends the Answer Form
 * @param answer <u>must be an answer-form</u>
 * @param chat
 */
private void sendAnswerForm(Form answer, MultiUserChat chat) {
    ChatRoom room = SparkManager.getChatManager().getChatRoom(chat.getRoom());
    for (String key : _map.keySet()) {
        String value = getValueFromComponent(key);
        answer.setAnswer(key, value);
    }
    try {
        chat.sendRegistrationForm(answer);
        String reg = Res.getString("message.groupchat.registered.member", chat.getRoom());
        room.getTranscriptWindow().insertNotificationMessage(reg, ChatManager.NOTIFICATION_COLOR);
    } catch (XMPPException | SmackException e) {
        room.getTranscriptWindow().insertNotificationMessage(e.getMessage(), ChatManager.ERROR_COLOR);
    }
}
Also used : ChatRoom(org.jivesoftware.spark.ui.ChatRoom) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

ChatRoom (org.jivesoftware.spark.ui.ChatRoom)45 ChatManager (org.jivesoftware.spark.ChatManager)10 ChatRoomImpl (org.jivesoftware.spark.ui.rooms.ChatRoomImpl)10 ActionEvent (java.awt.event.ActionEvent)8 Message (org.jivesoftware.smack.packet.Message)8 ChatRoomNotFoundException (org.jivesoftware.spark.ui.ChatRoomNotFoundException)8 ContactItem (org.jivesoftware.spark.ui.ContactItem)7 Presence (org.jivesoftware.smack.packet.Presence)6 ChatRoomListenerAdapter (org.jivesoftware.spark.ui.ChatRoomListenerAdapter)6 ActionListener (java.awt.event.ActionListener)5 MouseEvent (java.awt.event.MouseEvent)5 Date (java.util.Date)5 JButton (javax.swing.JButton)5 JLabel (javax.swing.JLabel)5 JPanel (javax.swing.JPanel)5 SmackException (org.jivesoftware.smack.SmackException)5 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)5 SimpleDateFormat (java.text.SimpleDateFormat)4 JPopupMenu (javax.swing.JPopupMenu)4 SparkManager (org.jivesoftware.spark.SparkManager)4