Search in sources :

Example 16 with ChatRoomImpl

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

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

the class BuzzRoomDecorator method actionPerformed.

public void actionPerformed(ActionEvent e) {
    final String jid = ((ChatRoomImpl) chatRoom).getParticipantJID();
    Message message = new Message();
    message.setTo(jid);
    message.addExtension(new BuzzPacket());
    try {
        SparkManager.getConnection().sendStanza(message);
    } catch (SmackException.NotConnectedException e1) {
        Log.warning("Unable to send stanza to " + jid, e1);
    }
    chatRoom.getTranscriptWindow().insertNotificationMessage(Res.getString("message.buzz.sent"), ChatManager.NOTIFICATION_COLOR);
    buzzButton.setEnabled(false);
    // Enable the button after 30 seconds to prevent abuse.
    final TimerTask enableTask = new SwingTimerTask() {

        public void doRun() {
            buzzButton.setEnabled(true);
        }
    };
    TaskEngine.getInstance().schedule(enableTask, 30000);
}
Also used : SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) Message(org.jivesoftware.smack.packet.Message) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) TimerTask(java.util.TimerTask) SmackException(org.jivesoftware.smack.SmackException) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 18 with ChatRoomImpl

use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl 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 19 with ChatRoomImpl

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

the class OTRManager method chatRoomClosed.

@Override
public void chatRoomClosed(ChatRoom room) {
    super.chatRoomClosed(room);
    if (OTRProperties.getInstance().getOTRCloseOnChatClose()) {
        if (room instanceof ChatRoomImpl) {
            ChatRoomImpl myroom = (ChatRoomImpl) room;
            if (_activeSessions.containsKey(myroom.getParticipantJID())) {
                OTRSession searchedSession = _activeSessions.get(myroom.getParticipantJID());
                searchedSession.stopSession();
                _activeSessions.remove(myroom.getParticipantJID());
            }
        }
    }
}
Also used : ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl) OTRSession(org.jivesoftware.spark.otrplug.impl.OTRSession)

Example 20 with ChatRoomImpl

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

the class PhonePlugin method setupPhoneSystem.

private void setupPhoneSystem() {
    // Add Dial Menu
    final JMenu viewMenu = SparkManager.getMainWindow().getMenuByName(Res.getString("menuitem.actions"));
    JMenuItem dialNumberMenu = new JMenuItem(SparkRes.getImageIcon(SparkRes.ON_PHONE_IMAGE));
    ResourceUtils.resButton(dialNumberMenu, Res.getString("button.dial.number"));
    // Add Listener
    dialNumberMenu.addActionListener(e -> {
        dialPanel = new DialPanel();
        dialPanel.getDialButton().addActionListener(e1 -> {
            String number = dialPanel.getNumberToDial();
            if (ModelUtil.hasLength(number)) {
                dialPanel.setText(Res.getString("message.calling", number));
                dialPanel.changeToRinging();
                callExtension(number);
            }
        });
        dialDialog = PhoneDialog.invoke(dialPanel, Res.getString("title.dial.phone"), Res.getString("message.number.to.call"), null);
        dialPanel.getDialField().requestFocusInWindow();
        dialPanel.getDialField().addKeyListener(new KeyAdapter() {

            public void keyPressed(KeyEvent e) {
                if (e.getKeyChar() == KeyEvent.VK_ENTER) {
                    try {
                        String number = dialPanel.getNumberToDial();
                        if (ModelUtil.hasLength(number)) {
                            dialPanel.setText(Res.getString("message.calling", number));
                            dialPanel.changeToRinging();
                            callExtension(number);
                        }
                        e.consume();
                    } catch (Exception ex) {
                        Log.error(ex);
                    }
                }
            }
        });
    });
    viewMenu.add(dialNumberMenu);
    // Add ChatRoomListener to call users based on JID
    SparkManager.getChatManager().addChatRoomListener(new ChatRoomListenerAdapter() {

        public void chatRoomOpened(final ChatRoom room) {
            if (room instanceof ChatRoomImpl) {
                final ChatRoomButton callButton = new ChatRoomButton("", SparkRes.getImageIcon(SparkRes.TELEPHONE_24x24));
                callButton.setToolTipText(Res.getString("tooltip.place.a.call"));
                final ChatRoomImpl chatRoom = (ChatRoomImpl) room;
                boolean phoneEnabled = false;
                try {
                    phoneEnabled = phoneClient.isPhoneEnabled(XmppStringUtils.parseBareJid(chatRoom.getParticipantJID()));
                } catch (Exception e) {
                    Log.error(e);
                }
                if (phoneEnabled) {
                    room.addChatRoomButton(callButton);
                    callButton.addActionListener(e -> callJID(chatRoom.getParticipantJID()));
                }
            }
        }
    });
    ContactList contactList = SparkManager.getWorkspace().getContactList();
    contactList.addContextMenuListener(new ContextMenuListener() {

        public void poppingUp(Object object, final JPopupMenu popup) {
            if (object instanceof ContactItem) {
                final ContactItem item = (ContactItem) object;
                boolean phoneEnabled = false;
                try {
                    phoneEnabled = phoneClient.isPhoneEnabled(item.getJID());
                } catch (Exception e) {
                    Log.error("There was an error retrieving phone information.", e);
                }
                if (phoneEnabled) {
                    Action callAction = new AbstractAction() {

                        private static final long serialVersionUID = 7221741748743018431L;

                        public void actionPerformed(ActionEvent e) {
                            callJID(item.getJID());
                        }
                    };
                    callAction.putValue(Action.NAME, "Call");
                    callAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.ON_PHONE_IMAGE));
                    popup.add(callAction);
                }
            }
        }

        public void poppingDown(JPopupMenu popup) {
        }

        public boolean handleDefaultAction(MouseEvent e) {
            return false;
        }
    });
}
Also used : PhoneActionIQProvider(org.jivesoftware.phone.client.action.PhoneActionIQProvider) Presence(org.jivesoftware.smack.packet.Presence) SparkRes(org.jivesoftware.resource.SparkRes) SettingsManager(org.jivesoftware.sparkimpl.settings.local.SettingsManager) Res(org.jivesoftware.resource.Res) ProviderManager(org.jivesoftware.smack.provider.ProviderManager) SwingWorker(org.jivesoftware.spark.util.SwingWorker) Log(org.jivesoftware.spark.util.log.Log) Plugin(org.jivesoftware.spark.plugin.Plugin) org.jivesoftware.spark.ui(org.jivesoftware.spark.ui) XmppStringUtils(org.jxmpp.util.XmppStringUtils) org.jivesoftware.phone.client(org.jivesoftware.phone.client) PhoneEventPacketExtensionProvider(org.jivesoftware.phone.client.event.PhoneEventPacketExtensionProvider) ContextMenuListener(org.jivesoftware.spark.plugin.ContextMenuListener) UserIdlePlugin(org.jivesoftware.sparkimpl.plugin.idle.UserIdlePlugin) PhoneManager(org.jivesoftware.spark.phone.PhoneManager) SparkManager(org.jivesoftware.spark.SparkManager) java.awt.event(java.awt.event) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl) SparkToaster(org.jivesoftware.sparkimpl.plugin.alerts.SparkToaster) TimerTask(java.util.TimerTask) org.jivesoftware.spark.util(org.jivesoftware.spark.util) XMPPConnection(org.jivesoftware.smack.XMPPConnection) javax.swing(javax.swing) ContextMenuListener(org.jivesoftware.spark.plugin.ContextMenuListener) 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