Search in sources :

Example 11 with ChatManager

use of org.jivesoftware.spark.ChatManager 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 12 with ChatManager

use of org.jivesoftware.spark.ChatManager in project Spark by igniterealtime.

the class BroadcastPlugin method broadcastInChat.

/**
 * Displays the Serverbroadcast like all other messages
 * in its on chatcontainer with transcript history
 * @param message
 * @param from
 */
private void broadcastInChat(Message message) {
    String from = message.getFrom() != null ? message.getFrom() : "";
    ChatManager chatManager = SparkManager.getChatManager();
    ChatContainer container = chatManager.getChatContainer();
    ChatRoomImpl chatRoom;
    try {
        chatRoom = (ChatRoomImpl) container.getChatRoom(from);
    } catch (ChatRoomNotFoundException e) {
        String windowtitle = message.getSubject() != null ? message.getSubject() : Res.getString("administrator");
        chatRoom = new ChatRoomImpl("serveralert@" + from, Res.getString("broadcast"), windowtitle);
        chatRoom.getBottomPanel().setVisible(false);
        chatRoom.hideToolbar();
        SparkManager.getChatManager().getChatContainer().addChatRoom(chatRoom);
    }
    chatRoom.getTranscriptWindow().insertNotificationMessage(message.getBody(), ChatManager.NOTIFICATION_COLOR);
    broadcastRooms.add(chatRoom);
}
Also used : ChatContainer(org.jivesoftware.spark.ui.ChatContainer) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) ChatManager(org.jivesoftware.spark.ChatManager) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 13 with ChatManager

use of org.jivesoftware.spark.ChatManager in project Spark by igniterealtime.

the class ReversiPlugin method removeToolbarButton.

/**
 * Removes the Reversi toolbar button.
 */
private void removeToolbarButton() {
    ChatManager manager = SparkManager.getChatManager();
    manager.removeChatRoomListener(chatRoomListener);
// TODO: remove actual buttons from toolbar.
}
Also used : ChatManager(org.jivesoftware.spark.ChatManager)

Example 14 with ChatManager

use of org.jivesoftware.spark.ChatManager in project Spark by igniterealtime.

the class ReversiPlugin method addToolbarButton.

/**
 * Adds the Reversi toolbar button.
 */
private void addToolbarButton() {
    ChatManager manager = SparkManager.getChatManager();
    chatRoomListener = new ChatRoomListenerAdapter() {

        ImageIcon icon = ReversiRes.getImageIcon(ReversiRes.REVERSI_ICON);

        public void chatRoomOpened(final ChatRoom room) {
            if (!(room instanceof ChatRoomImpl)) {
                // Don't do anything if this is not a 1on1-Chat
                return;
            }
            ChatRoomButton button = new ChatRoomButton(icon);
            button.setToolTipText("Reversi");
            room.getToolBar().addChatRoomButton(button);
            // Add a button listener that sends out a game invite on a user
            // click.
            button.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    // Show "requesting a game panel"
                    final JPanel request = new JPanel();
                    request.setLayout(new BorderLayout());
                    JPanel requestPanel = new JPanel() {

                        private static final long serialVersionUID = 4490592207923738251L;

                        protected void paintComponent(Graphics g) {
                            g.drawImage(icon.getImage(), 0, 0, null);
                        }
                    };
                    requestPanel.setPreferredSize(new Dimension(24, 24));
                    request.add(requestPanel, BorderLayout.WEST);
                    String opponentJID = ((ChatRoomImpl) room).getJID();
                    // TODO:
                    String opponentName = "[" + opponentJID + "]";
                    // convert
                    // to
                    // more
                    // readable
                    // name.
                    final JPanel content = new JPanel(new BorderLayout());
                    final JLabel label = new JLabel("Requesting a Reversi game with " + opponentName + ", please wait...");
                    content.add(label, BorderLayout.CENTER);
                    JPanel buttonPanel = new JPanel();
                    final JButton cancelButton = new JButton("Cancel");
                    cancelButton.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            GameOffer reply = new GameOffer();
                            reply.setTo(((ChatRoomImpl) room).getJID());
                            reply.setType(IQ.Type.error);
                            try {
                                SparkManager.getConnection().sendStanza(reply);
                            } catch (SmackException.NotConnectedException e1) {
                                Log.warning("Unable to send invitation cancellation to " + reply.getTo(), e1);
                            }
                            cancelButton.setText("Canceled");
                            cancelButton.setEnabled(false);
                        }
                    });
                    buttonPanel.add(cancelButton, BorderLayout.SOUTH);
                    content.add(buttonPanel, BorderLayout.SOUTH);
                    request.add(content, BorderLayout.CENTER);
                    room.getTranscriptWindow().addComponent(request);
                    final GameOffer offer = new GameOffer();
                    offer.setTo(opponentJID);
                    // Add a listener for a reply to our offer.
                    SparkManager.getConnection().addAsyncStanzaListener(new StanzaListener() {

                        public void processPacket(Stanza stanza) {
                            GameOffer offerReply = ((GameOffer) stanza);
                            if (offerReply.getType() == IQ.Type.result) {
                                // Remove the offer panel
                                room.getTranscriptWindow().remove(request);
                                content.remove(1);
                                label.setText("Starting game...");
                                // Show game board (using original offer!).
                                showReversiBoard(offer.getGameID(), room, offer.isStartingPlayer(), offerReply.getFrom());
                            } else if (offerReply.getType() == IQ.Type.error) {
                                cancelButton.setVisible(false);
                                JPanel userDeclinedPanel = new JPanel(new BorderLayout());
                                JLabel userDeclined = new JLabel("User declined...");
                                userDeclinedPanel.add(userDeclined, BorderLayout.SOUTH);
                                request.add(userDeclinedPanel, BorderLayout.SOUTH);
                            }
                        // TODO: Handle error case
                        }
                    }, new StanzaIdFilter(offer.getStanzaId()));
                    try {
                        SparkManager.getConnection().sendStanza(offer);
                    } catch (SmackException.NotConnectedException e1) {
                        Log.warning("Unable to send invitation to " + offer.getTo(), e1);
                    }
                }
            });
        }

        public void chatRoomClosed(ChatRoom room) {
            super.chatRoomClosed(room);
        // TODO: if game is in progress, close it down. What we need is
        // an API that lets us see
        // TODO: if there's a transcript alert currently there.
        }
    };
    manager.addChatRoomListener(chatRoomListener);
}
Also used : ImageIcon(javax.swing.ImageIcon) JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) Stanza(org.jivesoftware.smack.packet.Stanza) SmackException(org.jivesoftware.smack.SmackException) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) StanzaListener(org.jivesoftware.smack.StanzaListener) Dimension(java.awt.Dimension) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl) Graphics(java.awt.Graphics) ChatRoomListenerAdapter(org.jivesoftware.spark.ui.ChatRoomListenerAdapter) ActionListener(java.awt.event.ActionListener) BorderLayout(java.awt.BorderLayout) StanzaIdFilter(org.jivesoftware.smack.filter.StanzaIdFilter) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatManager(org.jivesoftware.spark.ChatManager) ChatRoomButton(org.jivesoftware.spark.ui.ChatRoomButton)

Example 15 with ChatManager

use of org.jivesoftware.spark.ChatManager in project Spark by igniterealtime.

the class UserInvitationPane method startFastpathChat.

private void startFastpathChat(String fullRoomJID, String roomName) {
    // Add to Chat window
    ChatManager chatManager = SparkManager.getChatManager();
    GroupChatRoom chatRoom;
    try {
        chatRoom = chatManager.getGroupChat(fullRoomJID);
        if (!chatRoom.isActive()) {
            // Remove old room, add new room.
            chatManager.removeChat(chatRoom);
            MultiUserChat chat = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getMultiUserChat(fullRoomJID);
            chatRoom = new GroupChatRoom(chat);
        } else {
            // Already in the room, do not process invitation
            try {
                offer.reject();
            } catch (SmackException.NotConnectedException e) {
                Log.warning("Unable to reject offer " + offer, e);
            }
            return;
        }
    } catch (ChatNotFoundException e) {
        MultiUserChat chat = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getMultiUserChat(fullRoomJID);
        chatRoom = new GroupChatRoom(chat);
    }
    chatRoom.getSplitPane().setDividerSize(5);
    chatRoom.getSplitPane().getRightComponent().setVisible(true);
    chatRoom.getBottomPanel().setVisible(true);
    chatRoom.getScrollPaneForTranscriptWindow().setVisible(true);
    chatRoom.getEditorBar().setVisible(true);
    chatRoom.getChatInputEditor().setEnabled(true);
    chatRoom.getToolBar().setVisible(true);
    chatRoom.getVerticalSlipPane().setDividerLocation(0.8);
    chatRoom.getSplitPane().setDividerLocation(0.6);
    try {
        chatRoom.setTabTitle(roomName);
        chatRoom.getConferenceRoomInfo().setNicknameChangeAllowed(false);
        chatRoom.getToolBar().setVisible(true);
        chatRoom.getEditorBar().setVisible(true);
        chatRoom.getChatInputEditor().setEnabled(true);
        ChatContainer chatContainer = SparkManager.getChatManager().getChatContainer();
        chatContainer.addChatRoom(chatRoom);
        FastpathPlugin.getLitWorkspace().addFastpathChatRoom(chatRoom, Workpane.RoomState.activeRoom);
        chatContainer.setChatRoomTitle(chatRoom, roomName);
        if (chatContainer.getActiveChatRoom() == chatRoom) {
            chatContainer.getChatFrame().setTitle(roomName);
        }
    } catch (Exception e) {
        Log.error(e);
    }
    ConferenceUtils.enterRoomOnSameThread(roomName, fullRoomJID, null);
    removeOwner(chatRoom.getMultiUserChat());
    FastpathPlugin.getLitWorkspace().checkForDecoration(chatRoom, offer.getSessionID());
    if (listener != null) {
        listener.yesOption();
        listener = null;
    }
}
Also used : GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) ChatContainer(org.jivesoftware.spark.ui.ChatContainer) MultiUserChat(org.jivesoftware.smackx.muc.MultiUserChat) ChatNotFoundException(org.jivesoftware.spark.ChatNotFoundException) SmackException(org.jivesoftware.smack.SmackException) ChatManager(org.jivesoftware.spark.ChatManager) MultiUserChatManager(org.jivesoftware.smackx.muc.MultiUserChatManager) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException) ChatNotFoundException(org.jivesoftware.spark.ChatNotFoundException)

Aggregations

ChatManager (org.jivesoftware.spark.ChatManager)19 ChatRoom (org.jivesoftware.spark.ui.ChatRoom)8 ChatRoomImpl (org.jivesoftware.spark.ui.rooms.ChatRoomImpl)7 SmackException (org.jivesoftware.smack.SmackException)6 ChatContainer (org.jivesoftware.spark.ui.ChatContainer)5 MultiUserChatManager (org.jivesoftware.smackx.muc.MultiUserChatManager)4 GroupChatRoom (org.jivesoftware.spark.ui.rooms.GroupChatRoom)4 ActionEvent (java.awt.event.ActionEvent)3 Message (org.jivesoftware.smack.packet.Message)3 ChatRoomListenerAdapter (org.jivesoftware.spark.ui.ChatRoomListenerAdapter)3 ChatRoomNotFoundException (org.jivesoftware.spark.ui.ChatRoomNotFoundException)3 LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)3 BorderLayout (java.awt.BorderLayout)2 File (java.io.File)2 ImageIcon (javax.swing.ImageIcon)2 JButton (javax.swing.JButton)2 JComboBox (javax.swing.JComboBox)2 JLabel (javax.swing.JLabel)2 JPanel (javax.swing.JPanel)2 Presence (org.jivesoftware.smack.packet.Presence)2