Search in sources :

Example 1 with CustomStatusItem

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

Aggregations

ActionEvent (java.awt.event.ActionEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 AbstractAction (javax.swing.AbstractAction)1 JMenu (javax.swing.JMenu)1 JMenuItem (javax.swing.JMenuItem)1 Presence (org.jivesoftware.smack.packet.Presence)1 CustomStatusItem (org.jivesoftware.spark.ui.status.CustomStatusItem)1 StatusBar (org.jivesoftware.spark.ui.status.StatusBar)1 StatusItem (org.jivesoftware.spark.ui.status.StatusItem)1