Search in sources :

Example 26 with ChatRoom

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

the class PresenceChangePlugin method initialize.

public void initialize() {
    // Listen for right-clicks on ContactItem
    final ContactList contactList = SparkManager.getWorkspace().getContactList();
    final Action listenAction = new AbstractAction() {

        private static final long serialVersionUID = 7705539667621148816L;

        public void actionPerformed(ActionEvent e) {
            for (ContactItem item : contactList.getSelectedUsers()) {
                String bareAddress = XmppStringUtils.parseBareJid(item.getJID());
                sparkContacts.add(bareAddress);
            }
        }
    };
    listenAction.putValue(Action.NAME, Res.getString("menuitem.alert.when.online"));
    listenAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_ALARM_CLOCK));
    final Action removeAction = new AbstractAction() {

        private static final long serialVersionUID = -8726129089417116105L;

        public void actionPerformed(ActionEvent e) {
            for (ContactItem item : contactList.getSelectedUsers()) {
                String bareAddress = XmppStringUtils.parseBareJid(item.getJID());
                sparkContacts.remove(bareAddress);
            }
        }
    };
    removeAction.putValue(Action.NAME, Res.getString("menuitem.remove.alert.when.online"));
    removeAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_DELETE));
    contactList.addContextMenuListener(new ContextMenuListener() {

        public void poppingUp(Object object, JPopupMenu popup) {
            if (object instanceof ContactItem) {
                ContactItem item = (ContactItem) object;
                String bareAddress = XmppStringUtils.parseBareJid(item.getJID());
                if (!item.getPresence().isAvailable() || item.getPresence().isAway()) {
                    if (sparkContacts.contains(bareAddress)) {
                        popup.add(removeAction);
                    } else {
                        popup.add(listenAction);
                    }
                }
            }
        }

        public void poppingDown(JPopupMenu popup) {
        }

        public boolean handleDefaultAction(MouseEvent e) {
            return false;
        }
    });
    // Check presence changes
    SparkManager.getConnection().addAsyncStanzaListener(stanza -> {
        try {
            Presence presence = (Presence) stanza;
            if (!presence.isAvailable() || presence.isAway()) {
                return;
            }
            String from = presence.getFrom();
            ArrayList<String> removelater = new ArrayList<>();
            for (final String jid : sparkContacts) {
                if (jid.equals(XmppStringUtils.parseBareJid(from))) {
                    removelater.add(jid);
                    // sparkContacts.remove(jid);
                    String nickname = SparkManager.getUserManager().getUserNicknameFromJID(jid);
                    String time = SparkManager.DATE_SECOND_FORMATTER.format(new Date());
                    String infoText = Res.getString("message.user.now.available.to.chat", nickname, time);
                    if (localPref.getShowToasterPopup()) {
                        EventQueue.invokeLater(() -> {
                            SparkToaster toaster = new SparkToaster();
                            toaster.setDisplayTime(5000);
                            toaster.setBorder(BorderFactory.createBevelBorder(0));
                            toaster.setToasterHeight(150);
                            toaster.setToasterWidth(200);
                            toaster.setTitle(nickname);
                            toaster.showToaster(null, infoText);
                            toaster.setCustomAction(new AbstractAction() {

                                private static final long serialVersionUID = 4827542713848133369L;

                                @Override
                                public void actionPerformed(ActionEvent e) {
                                    SparkManager.getChatManager().getChatRoom(jid);
                                }
                            });
                        });
                    }
                    ChatRoom room = SparkManager.getChatManager().getChatRoom(jid);
                    if (localPref.getWindowTakesFocus()) {
                        EventQueue.invokeLater(() -> SparkManager.getChatManager().activateChat(jid, nickname));
                    }
                    EventQueue.invokeLater(() -> room.getTranscriptWindow().insertNotificationMessage(infoText, ChatManager.NOTIFICATION_COLOR));
                }
            }
            for (String s : removelater) {
                sparkContacts.remove(s);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }, new StanzaTypeFilter(Presence.class));
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) MouseEvent(java.awt.event.MouseEvent) SparkToaster(org.jivesoftware.sparkimpl.plugin.alerts.SparkToaster) ActionEvent(java.awt.event.ActionEvent) ContactItem(org.jivesoftware.spark.ui.ContactItem) ContextMenuListener(org.jivesoftware.spark.plugin.ContextMenuListener) ArrayList(java.util.ArrayList) ContactList(org.jivesoftware.spark.ui.ContactList) JPopupMenu(javax.swing.JPopupMenu) Date(java.util.Date) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) Presence(org.jivesoftware.smack.packet.Presence) AbstractAction(javax.swing.AbstractAction)

Example 27 with ChatRoom

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

the class EmoticonPlugin method chatRoomOpened.

public void chatRoomOpened(final ChatRoom room) {
    // Check to see if emoticons are enabled.
    if (!SettingsManager.getLocalPreferences().areEmoticonsEnabled()) {
        return;
    }
    // final String activeEmoticonSetName =
    // emoticonManager.getActiveEmoticonSetName();
    emoticonManager = EmoticonManager.getInstance();
    Collection<String> emoticonPacks;
    emoticonPacks = emoticonManager.getEmoticonPacks();
    if (emoticonPacks != null) {
        // Add Emoticon button
        final RolloverButton emoticonPicker = UIComponentRegistry.getButtonFactory().createEmoticonButton();
        room.addEditorComponent(emoticonPicker);
        emoticonPicker.addMouseListener(new MouseAdapter() {

            public void mouseClicked(MouseEvent e) {
                // Show popup
                final JPopupMenu popup = new JPopupMenu();
                EmoticonUI emoticonUI = new EmoticonUI();
                emoticonUI.setEmoticonPickListener(emoticon -> {
                    try {
                        popup.setVisible(false);
                        final ChatInputEditor editor = room.getChatInputEditor();
                        String currentText = editor.getText();
                        if (currentText.length() == 0 || currentText.endsWith(" ")) {
                            room.getChatInputEditor().insertText(emoticon + " ");
                        } else {
                            room.getChatInputEditor().insertText(" " + emoticon + " ");
                        }
                        room.getChatInputEditor().requestFocus();
                    } catch (BadLocationException e1) {
                        Log.error(e1);
                    }
                });
                popup.add(emoticonUI);
                popup.show(emoticonPicker, e.getX(), e.getY());
            }
        });
        room.addClosingListener(() -> room.removeEditorComponent(emoticonPicker));
    }
}
Also used : ChatManager(org.jivesoftware.spark.ChatManager) Collection(java.util.Collection) JPopupMenu(javax.swing.JPopupMenu) SettingsManager(org.jivesoftware.sparkimpl.settings.local.SettingsManager) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) UIComponentRegistry(org.jivesoftware.spark.util.UIComponentRegistry) BadLocationException(javax.swing.text.BadLocationException) Log(org.jivesoftware.spark.util.log.Log) Plugin(org.jivesoftware.spark.plugin.Plugin) MouseEvent(java.awt.event.MouseEvent) ThemePreference(org.jivesoftware.spark.ui.themes.ThemePreference) SparkManager(org.jivesoftware.spark.SparkManager) MouseAdapter(java.awt.event.MouseAdapter) ChatInputEditor(org.jivesoftware.spark.ui.ChatInputEditor) RolloverButton(org.jivesoftware.spark.component.RolloverButton) ChatRoomListener(org.jivesoftware.spark.ui.ChatRoomListener) ChatInputEditor(org.jivesoftware.spark.ui.ChatInputEditor) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) RolloverButton(org.jivesoftware.spark.component.RolloverButton) JPopupMenu(javax.swing.JPopupMenu) BadLocationException(javax.swing.text.BadLocationException)

Example 28 with ChatRoom

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

the class BroadcastPlugin method initialize.

public void initialize() {
    // See if we should disable all "Broadcast" menu items
    if (Default.getBoolean("DISABLE_BROADCAST_MENU_ITEM") || !Enterprise.containsFeature(Enterprise.BROADCAST_FEATURE))
        return;
    // Add as ContainerDecoratr
    SparkManager.getChatManager().addSparkTabHandler(this);
    StanzaFilter serverFilter = new StanzaTypeFilter(Message.class);
    SparkManager.getConnection().addAsyncStanzaListener(this, serverFilter);
    // Register with action menu
    final JMenu actionsMenu = SparkManager.getMainWindow().getMenuByName(Res.getString("menuitem.actions"));
    JMenuItem broadcastHistoryMenu = new JMenuItem(Res.getString("title.broadcast.history"), SparkRes.getImageIcon(SparkRes.HISTORY_16x16));
    JMenuItem broadcastMenu = new JMenuItem(Res.getString("title.broadcast.message"), SparkRes.getImageIcon(SparkRes.MEGAPHONE_16x16));
    ResourceUtils.resButton(broadcastMenu, Res.getString("title.broadcast.message"));
    actionsMenu.add(broadcastHistoryMenu);
    actionsMenu.add(broadcastMenu);
    broadcastMenu.addActionListener(e -> broadcastToRoster());
    broadcastHistoryMenu.addActionListener(e -> {
        new BroadcastHistoryFrame().run();
    });
    // Register with action menu
    JMenuItem startConversationtMenu = new JMenuItem("", SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_IMAGE));
    ResourceUtils.resButton(startConversationtMenu, Res.getString("menuitem.start.a.chat"));
    if (!Default.getBoolean("HIDE_START_A_CHAT") && Enterprise.containsFeature(Enterprise.START_A_CHAT_FEATURE)) {
        actionsMenu.add(startConversationtMenu, 0);
    }
    startConversationtMenu.addActionListener(e -> {
        ContactList contactList = SparkManager.getWorkspace().getContactList();
        Collection<ContactItem> selectedUsers = contactList.getSelectedUsers();
        String selectedUser = "";
        Iterator<ContactItem> selectedUsersIterator = selectedUsers.iterator();
        if (selectedUsersIterator.hasNext()) {
            ContactItem contactItem = selectedUsersIterator.next();
            selectedUser = contactItem.getJID();
        }
        UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
        UIManager.put("OptionPane.cancelButtonText", Res.getString("cancel"));
        String jid = (String) JOptionPane.showInputDialog(SparkManager.getMainWindow(), Res.getString("label.enter.address"), Res.getString("title.start.chat"), JOptionPane.QUESTION_MESSAGE, null, null, selectedUser);
        if (ModelUtil.hasLength(jid) && ModelUtil.hasLength(XmppStringUtils.parseDomain(jid))) {
            if (ModelUtil.hasLength(jid) && jid.indexOf('@') == -1) {
                // Append server address
                jid = jid + "@" + SparkManager.getConnection().getServiceName();
            }
            String nickname = SparkManager.getUserManager().getUserNicknameFromJID(jid);
            jid = UserManager.escapeJID(jid);
            ChatRoom chatRoom = SparkManager.getChatManager().createChatRoom(jid, nickname, nickname);
            SparkManager.getChatManager().getChatContainer().activateChatRoom(chatRoom);
        }
    });
    // Add send to selected users.
    final ContactList contactList = SparkManager.getWorkspace().getContactList();
    contactList.addContextMenuListener(new ContextMenuListener() {

        public void poppingUp(Object component, JPopupMenu popup) {
            if (component instanceof ContactGroup) {
                final ContactGroup group = (ContactGroup) component;
                Action broadcastMessageAction = new AbstractAction() {

                    private static final long serialVersionUID = -6411248110270296726L;

                    public void actionPerformed(ActionEvent e) {
                        broadcastToGroup(group);
                    }
                };
                broadcastMessageAction.putValue(Action.NAME, Res.getString("menuitem.broadcast.to.group"));
                broadcastMessageAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.MEGAPHONE_16x16));
                popup.add(broadcastMessageAction);
            }
        }

        public void poppingDown(JPopupMenu popup) {
        }

        public boolean handleDefaultAction(MouseEvent e) {
            return false;
        }
    });
    // Add Broadcast to roster
    StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
    RolloverButton broadcastToRosterButton = new RolloverButton(SparkRes.getImageIcon(SparkRes.MEGAPHONE_16x16));
    broadcastToRosterButton.setToolTipText(Res.getString("message.send.a.broadcast"));
    statusBar.invalidate();
    statusBar.validate();
    statusBar.repaint();
    broadcastToRosterButton.addActionListener(e -> broadcastToRoster());
}
Also used : AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) StanzaFilter(org.jivesoftware.smack.filter.StanzaFilter) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) ContactItem(org.jivesoftware.spark.ui.ContactItem) ContextMenuListener(org.jivesoftware.spark.plugin.ContextMenuListener) ContactList(org.jivesoftware.spark.ui.ContactList) StatusBar(org.jivesoftware.spark.ui.status.StatusBar) RolloverButton(org.jivesoftware.spark.component.RolloverButton) JPopupMenu(javax.swing.JPopupMenu) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) JMenuItem(javax.swing.JMenuItem) BroadcastHistoryFrame(org.jivesoftware.spark.ui.BroadcastHistoryFrame) ContactGroup(org.jivesoftware.spark.ui.ContactGroup) AbstractAction(javax.swing.AbstractAction) JMenu(javax.swing.JMenu)

Example 29 with ChatRoom

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

the class BroadcastPlugin method isTabHandled.

public boolean isTabHandled(SparkTab tab, Component component, boolean isSelectedTab, boolean chatFrameFocused) {
    if (component instanceof ChatRoom) {
        ChatRoom chatroom = (ChatRoom) component;
        if (broadcastRooms.contains(chatroom)) {
            final ChatRoomImpl room = (ChatRoomImpl) component;
            tab.setIcon(SparkRes.getImageIcon(SparkRes.INFORMATION_IMAGE));
            String nickname = room.getTabTitle();
            nickname = Res.getString("message.broadcast.from", nickname);
            tab.setTabTitle(nickname);
            if ((!chatFrameFocused || !isSelectedTab) && room.getUnreadMessageCount() > 0) {
                // Make tab red.
                tab.setTitleColor(Color.red);
                tab.setTabBold(true);
            } else {
                tab.setTitleColor(Color.black);
                tab.setTabFont(tab.getDefaultFont());
                room.clearUnreadMessageCount();
            }
            return true;
        }
    }
    return false;
}
Also used : ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 30 with ChatRoom

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

the class BuzzPlugin method shakeWindow.

private void shakeWindow(Message message) {
    String bareJID = XmppStringUtils.parseBareJid(message.getFrom());
    ContactItem contact = SparkManager.getWorkspace().getContactList().getContactItemByJID(bareJID);
    String nickname = XmppStringUtils.parseLocalpart(bareJID);
    if (contact != null) {
        nickname = contact.getDisplayName();
    }
    ChatRoom room;
    try {
        room = SparkManager.getChatManager().getChatContainer().getChatRoom(bareJID);
    } catch (ChatRoomNotFoundException e) {
        // Create the room if it does not exist.
        room = SparkManager.getChatManager().createChatRoom(bareJID, nickname, nickname);
    }
    ChatFrame chatFrame = SparkManager.getChatManager().getChatContainer().getChatFrame();
    if (chatFrame != null) {
        if (SettingsManager.getLocalPreferences().isBuzzEnabled()) {
            chatFrame.buzz();
            SparkManager.getChatManager().getChatContainer().activateChatRoom(room);
        }
    }
    // Insert offline message
    room.getTranscriptWindow().insertNotificationMessage(Res.getString("message.buzz.message", nickname), ChatManager.NOTIFICATION_COLOR);
    room.scrollToBottom();
}
Also used : ChatFrame(org.jivesoftware.spark.ui.ChatFrame) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) ContactItem(org.jivesoftware.spark.ui.ContactItem)

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