Search in sources :

Example 1 with BroadcastHistoryFrame

use of org.jivesoftware.spark.ui.BroadcastHistoryFrame 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)

Aggregations

ActionEvent (java.awt.event.ActionEvent)1 MouseEvent (java.awt.event.MouseEvent)1 AbstractAction (javax.swing.AbstractAction)1 Action (javax.swing.Action)1 JMenu (javax.swing.JMenu)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 StanzaFilter (org.jivesoftware.smack.filter.StanzaFilter)1 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)1 RolloverButton (org.jivesoftware.spark.component.RolloverButton)1 ContextMenuListener (org.jivesoftware.spark.plugin.ContextMenuListener)1 BroadcastHistoryFrame (org.jivesoftware.spark.ui.BroadcastHistoryFrame)1 ChatRoom (org.jivesoftware.spark.ui.ChatRoom)1 ContactGroup (org.jivesoftware.spark.ui.ContactGroup)1 ContactItem (org.jivesoftware.spark.ui.ContactItem)1 ContactList (org.jivesoftware.spark.ui.ContactList)1 StatusBar (org.jivesoftware.spark.ui.status.StatusBar)1