Search in sources :

Example 6 with ContextMenuListener

use of org.jivesoftware.spark.plugin.ContextMenuListener 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

ContextMenuListener (org.jivesoftware.spark.plugin.ContextMenuListener)6 ActionEvent (java.awt.event.ActionEvent)5 MouseEvent (java.awt.event.MouseEvent)5 AbstractAction (javax.swing.AbstractAction)4 Action (javax.swing.Action)4 JPopupMenu (javax.swing.JPopupMenu)4 ContactList (org.jivesoftware.spark.ui.ContactList)4 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)3 ContactItem (org.jivesoftware.spark.ui.ContactItem)3 Collection (java.util.Collection)2 Date (java.util.Date)2 JMenu (javax.swing.JMenu)2 JMenuItem (javax.swing.JMenuItem)2 StanzaFilter (org.jivesoftware.smack.filter.StanzaFilter)2 Presence (org.jivesoftware.smack.packet.Presence)2 ChatRoom (org.jivesoftware.spark.ui.ChatRoom)2 ContactGroup (org.jivesoftware.spark.ui.ContactGroup)2 SparkToaster (org.jivesoftware.sparkimpl.plugin.alerts.SparkToaster)2 java.awt.event (java.awt.event)1 ArrayList (java.util.ArrayList)1