Search in sources :

Example 1 with StatusBar

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

the class TransportRegistrationDialog method actionPerformed.

public void actionPerformed(ActionEvent e) {
    String username = getScreenName();
    String password = getPassword();
    String nickname = getNickname();
    UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
    if (transport.requiresUsername() && !ModelUtil.hasLength(username)) {
        JOptionPane.showMessageDialog(this, Res.getString("message.gateway.username.error"), Res.getString("title.registration.error"), JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (transport.requiresPassword() && !ModelUtil.hasLength(password)) {
        JOptionPane.showMessageDialog(this, Res.getString("message.gateway.password.error"), Res.getString("title.registration.error"), JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (transport.requiresNickname() && !ModelUtil.hasLength(nickname)) {
        JOptionPane.showMessageDialog(this, Res.getString("message.gateway.nickname.error"), Res.getString("title.registration.error"), JOptionPane.ERROR_MESSAGE);
        return;
    }
    try {
        TransportUtils.registerUser(SparkManager.getConnection(), serviceName, username, password, nickname, stanza -> {
            IQ result = (IQ) stanza;
            if (result.getType() == IQ.Type.error) {
                JOptionPane.showMessageDialog(TransportRegistrationDialog.this, Res.getString("message.registration.transport.failed"), Res.getString("title.registration.error"), JOptionPane.ERROR_MESSAGE);
            } else {
                // Send Directed Presence
                final StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
                Presence presence = statusBar.getPresence();
                presence.setTo(transport.getServiceName());
                SparkManager.getConnection().sendStanza(presence);
            }
        });
    } catch (SmackException e1) {
        JOptionPane.showMessageDialog(TransportRegistrationDialog.this, Res.getString("message.registration.transport.failed"), Res.getString("title.registration.error"), JOptionPane.ERROR_MESSAGE);
    }
    dialog.dispose();
}
Also used : SmackException(org.jivesoftware.smack.SmackException) IQ(org.jivesoftware.smack.packet.IQ) Presence(org.jivesoftware.smack.packet.Presence) StatusBar(org.jivesoftware.spark.ui.status.StatusBar)

Example 2 with StatusBar

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

the class SparkSystemTray method stopFlashing.

/**
 * Stops the icon from flashing.
 */
public void stopFlashing() {
    Workspace workspace = SparkManager.getWorkspace();
    StatusBar statusBox = workspace.getStatusBar();
    Presence presence = statusBox.getPresence();
    changePresence(presence);
}
Also used : Presence(org.jivesoftware.smack.packet.Presence) StatusBar(org.jivesoftware.spark.ui.status.StatusBar) Workspace(org.jivesoftware.spark.Workspace)

Example 3 with StatusBar

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

the class VCardEditor method saveVCard.

/**
 * Saves the VCard.
 */
private void saveVCard() {
    final VCard vcard = new VCard();
    // Save personal info
    vcard.setFirstName(personalPanel.getFirstName());
    vcard.setLastName(personalPanel.getLastName());
    vcard.setMiddleName(personalPanel.getMiddleName());
    vcard.setEmailHome(personalPanel.getEmailAddress());
    vcard.setNickName(personalPanel.getNickname());
    // Save business info
    vcard.setOrganization(businessPanel.getCompany());
    vcard.setAddressFieldWork("STREET", businessPanel.getStreetAddress());
    vcard.setAddressFieldWork("LOCALITY", businessPanel.getCity());
    vcard.setAddressFieldWork("REGION", businessPanel.getState());
    vcard.setAddressFieldWork("PCODE", businessPanel.getZipCode());
    vcard.setAddressFieldWork("CTRY", businessPanel.getCountry());
    vcard.setField("TITLE", businessPanel.getJobTitle());
    vcard.setOrganizationUnit(businessPanel.getDepartment());
    vcard.setPhoneWork("VOICE", businessPanel.getPhone());
    vcard.setPhoneWork("FAX", businessPanel.getFax());
    vcard.setPhoneWork("PAGER", businessPanel.getPager());
    vcard.setPhoneWork("CELL", businessPanel.getMobile());
    vcard.setField("URL", businessPanel.getWebPage());
    // Save Home Info
    vcard.setAddressFieldHome("STREET", homePanel.getStreetAddress());
    vcard.setAddressFieldHome("LOCALITY", homePanel.getCity());
    vcard.setAddressFieldHome("REGION", homePanel.getState());
    vcard.setAddressFieldHome("PCODE", homePanel.getZipCode());
    vcard.setAddressFieldHome("CTRY", homePanel.getCountry());
    vcard.setPhoneHome("VOICE", homePanel.getPhone());
    vcard.setPhoneHome("FAX", homePanel.getFax());
    vcard.setPhoneHome("PAGER", homePanel.getPager());
    vcard.setPhoneHome("CELL", homePanel.getMobile());
    // Save Avatar
    byte[] avatarBytes = null;
    if (avatarPanel != null) {
        avatarBytes = avatarPanel.getAvatarBytes();
        // If avatar bytes, persist as vcard.
        if (avatarBytes != null) {
            vcard.setAvatar(avatarBytes);
        }
    }
    try {
        final VCardManager vcardManager = SparkManager.getVCardManager();
        vcardManager.setPersonalVCard(vcard);
        vcard.save(SparkManager.getConnection());
        // Notify users.
        if (avatarBytes != null) {
            Presence presence = SparkManager.getWorkspace().getStatusBar().getPresence();
            Presence newPresence = new Presence(presence.getType(), presence.getStatus(), presence.getPriority(), presence.getMode());
            // Change my own presence
            SparkManager.getSessionManager().changePresence(newPresence);
            // Chnage avatar in status bar.
            StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
            statusBar.setAvatar(new ImageIcon(vcard.getAvatar()));
        } else {
            String firstName = vcard.getFirstName();
            String lastName = vcard.getLastName();
            StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
            if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
                statusBar.setNickname(firstName + " " + lastName);
            } else if (ModelUtil.hasLength(firstName)) {
                statusBar.setNickname(firstName);
            }
            statusBar.setAvatar(null);
        }
        // Notify listenres
        SparkManager.getVCardManager().notifyVCardListeners();
    } catch (XMPPException | SmackException e) {
        Log.error(e);
        UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
        JOptionPane.showMessageDialog(SparkManager.getMainWindow(), Res.getString("message.vcard.not.supported"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) SmackException(org.jivesoftware.smack.SmackException) Presence(org.jivesoftware.smack.packet.Presence) XMPPException(org.jivesoftware.smack.XMPPException) VCard(org.jivesoftware.smackx.vcardtemp.packet.VCard) StatusBar(org.jivesoftware.spark.ui.status.StatusBar)

Example 4 with StatusBar

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

the class SysTrayPlugin method addStatusMessages.

public void addStatusMessages() {
    StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
    for (Object o : statusBar.getStatusList()) {
        final StatusItem statusItem = (StatusItem) o;
        final AbstractAction action = new AbstractAction() {

            private static final long serialVersionUID = 1L;

            @Override
            public void actionPerformed(ActionEvent e) {
                StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
                SparkManager.getSessionManager().changePresence(statusItem.getPresence());
                statusBar.setStatus(statusItem.getText());
            }
        };
        action.putValue(Action.NAME, statusItem.getText());
        action.putValue(Action.SMALL_ICON, statusItem.getIcon());
        boolean hasChildren = false;
        for (Object aCustom : SparkManager.getWorkspace().getStatusBar().getCustomStatusList()) {
            final CustomStatusItem cItem = (CustomStatusItem) aCustom;
            String type = cItem.getType();
            if (type.equals(statusItem.getText())) {
                hasChildren = true;
            }
        }
        if (!hasChildren) {
            JMenuItem status = new JMenuItem(action);
            statusMenu.add(status);
        } else {
            final JMenu status = new JMenu(action);
            statusMenu.add(status);
            status.addMouseListener(new MouseAdapter() {

                @Override
                public void mouseClicked(MouseEvent mouseEvent) {
                    action.actionPerformed(null);
                    popupMenu.setVisible(false);
                }
            });
            for (Object aCustom : SparkManager.getWorkspace().getStatusBar().getCustomStatusList()) {
                final CustomStatusItem customItem = (CustomStatusItem) aCustom;
                String type = customItem.getType();
                if (type.equals(statusItem.getText())) {
                    AbstractAction customAction = new AbstractAction() {

                        private static final long serialVersionUID = 1L;

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
                            Presence oldPresence = statusItem.getPresence();
                            Presence presence = StatusBar.copyPresence(oldPresence);
                            presence.setStatus(customItem.getStatus());
                            presence.setPriority(customItem.getPriority());
                            SparkManager.getSessionManager().changePresence(presence);
                            statusBar.setStatus(statusItem.getName() + " - " + customItem.getStatus());
                        }
                    };
                    customAction.putValue(Action.NAME, customItem.getStatus());
                    customAction.putValue(Action.SMALL_ICON, statusItem.getIcon());
                    JMenuItem menuItem = new JMenuItem(customAction);
                    status.add(menuItem);
                }
            }
        }
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) CustomStatusItem(org.jivesoftware.spark.ui.status.CustomStatusItem) MouseAdapter(java.awt.event.MouseAdapter) StatusBar(org.jivesoftware.spark.ui.status.StatusBar) CustomStatusItem(org.jivesoftware.spark.ui.status.CustomStatusItem) StatusItem(org.jivesoftware.spark.ui.status.StatusItem) Presence(org.jivesoftware.smack.packet.Presence) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) JMenu(javax.swing.JMenu)

Example 5 with StatusBar

use of org.jivesoftware.spark.ui.status.StatusBar 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

StatusBar (org.jivesoftware.spark.ui.status.StatusBar)6 Presence (org.jivesoftware.smack.packet.Presence)4 ActionEvent (java.awt.event.ActionEvent)2 MouseEvent (java.awt.event.MouseEvent)2 AbstractAction (javax.swing.AbstractAction)2 JMenu (javax.swing.JMenu)2 JMenuItem (javax.swing.JMenuItem)2 SmackException (org.jivesoftware.smack.SmackException)2 Workspace (org.jivesoftware.spark.Workspace)2 StatusItem (org.jivesoftware.spark.ui.status.StatusItem)2 MouseAdapter (java.awt.event.MouseAdapter)1 Action (javax.swing.Action)1 ImageIcon (javax.swing.ImageIcon)1 JPopupMenu (javax.swing.JPopupMenu)1 XMPPException (org.jivesoftware.smack.XMPPException)1 StanzaFilter (org.jivesoftware.smack.filter.StanzaFilter)1 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)1 IQ (org.jivesoftware.smack.packet.IQ)1 VCard (org.jivesoftware.smackx.vcardtemp.packet.VCard)1 RolloverButton (org.jivesoftware.spark.component.RolloverButton)1