Search in sources :

Example 31 with ChatRoom

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

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

the class RoarMessageListener method messageReceived.

@Override
public void messageReceived(ChatRoom room, Message message) {
    try {
        ChatRoom activeroom = SparkManager.getChatManager().getChatContainer().getActiveChatRoom();
        int framestate = SparkManager.getChatManager().getChatContainer().getChatFrame().getState();
        if (framestate == JFrame.NORMAL && activeroom.equals(room) && room.isShowing() && (isOldGroupChat(room) || isMessageFromRoom(room, message))) {
        // Do Nothing
        } else {
            decideForRoomAndMessage(room, message);
        }
    } catch (ChatRoomNotFoundException e) {
    // i dont care
    }
}
Also used : ChatRoom(org.jivesoftware.spark.ui.ChatRoom) GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException)

Example 33 with ChatRoom

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

the class NonRosterPanel method callStarted.

/**
 * Called when a new call is established.
 */
private void callStarted() {
    redialButton.setVisible(false);
    hangUpButton.setVisible(true);
    hangUpButton.setEnabled(true);
    muteButton.setEnabled(true);
    holdButton.setEnabled(true);
    transferButton.setEnabled(true);
    setStatus(CONNECTED, false);
    // Show History
    historyPanel.removeAll();
    historyPanel.addPreviousConversations(phoneNumber);
    // Add notification to ChatRoom if one exists.
    final ChatRoom chatRoom = callManager.getAssociatedChatRoom(this);
    if (chatRoom != null) {
        final SimpleDateFormat formatter = new SimpleDateFormat("h:mm a");
        String time = formatter.format(new Date());
        chatRoom.getTranscriptWindow().insertNotificationMessage(PhoneRes.getIString("phone.callstartedat") + " " + time, ChatManager.NOTIFICATION_COLOR);
    }
}
Also used : ChatRoom(org.jivesoftware.spark.ui.ChatRoom) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 34 with ChatRoom

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

the class NonRosterPanel method callEnded.

/**
 * Called when the call is ended. This does basic container cleanup.
 */
public void callEnded() {
    if (!callWasTransferred) {
        historyPanel.callEnded();
        setStatus(PhoneRes.getIString("phone.callended"), new Color(211, 0, 0));
    }
    hangUpButton.setVisible(false);
    redialButton.setVisible(true);
    muteButton.setEnabled(false);
    holdButton.setEnabled(false);
    transferButton.setEnabled(false);
    // Add notification to ChatRoom if one exists.
    final ChatRoom chatRoom = callManager.getAssociatedChatRoom(this);
    if (chatRoom != null) {
        final SimpleDateFormat formatter = new SimpleDateFormat("h:mm a");
        String time = formatter.format(new Date());
        chatRoom.getTranscriptWindow().insertNotificationMessage(PhoneRes.getIString("phone.callendedat") + " " + time, ChatManager.NOTIFICATION_COLOR);
    }
    changeState(CallRoomState.callWasEnded);
}
Also used : ChatRoom(org.jivesoftware.spark.ui.ChatRoom) Color(java.awt.Color) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 35 with ChatRoom

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

the class SoftPhoneTabHandler method handleChatRoom.

private void handleChatRoom(Component component, SparkTab tab, boolean chatFrameFocused, boolean isSelectedTab) {
    final ChatRoom chatRoom = (ChatRoom) component;
    if (!chatFrameFocused || !isSelectedTab) {
        if (chatRoom.getUnreadMessageCount() > 0) {
            // Make tab red.
            tab.setTitleColor(Color.red);
            tab.setTabBold(true);
        }
        // Handle unread message count.
        int unreadMessageCount = chatRoom.getUnreadMessageCount();
        String appendedMessage = "";
        if (unreadMessageCount > 1) {
            appendedMessage = " (" + unreadMessageCount + ")";
        }
        tab.setTabTitle(chatRoom.getTabTitle() + appendedMessage);
    }
    // and the tab is the selected component.
    if (isSelectedTab && chatFrameFocused) {
        tab.setTitleColor(Color.black);
        tab.setTabFont(tab.getDefaultFont());
        tab.setTabTitle(chatRoom.getTabTitle());
        // Clear unread message count.
        chatRoom.clearUnreadMessageCount();
    }
}
Also used : ChatRoom(org.jivesoftware.spark.ui.ChatRoom)

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