Search in sources :

Example 1 with StatusItem

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

the class SparkSystemTray method actionPerformed.

public void actionPerformed(ActionEvent e) {
    Object o = e.getSource();
    if (!(o instanceof MenuItem)) {
        /*
            MainWindow window = SparkManager.getMainWindow();
            if (window.isVisible() && window.getState() == Frame.NORMAL) {
                long now = System.currentTimeMillis();
                if (now - madeVisibleTime > 1000) {
                    window.setVisible(false);
                    return;
                }
            }

            madeVisibleTime = System.currentTimeMillis();
            */
        showMainWindow();
        return;
    }
    final JMenuItem item = (JMenuItem) e.getSource();
    if (item == openMenu) {
        showMainWindow();
    } else if (item == hideMenu) {
        SparkManager.getMainWindow().setVisible(false);
        hideMenu.setEnabled(false);
    } else if (item == exitMenu) {
        SparkManager.getMainWindow().shutdown();
    } else {
        final String status = item.getText();
        // Change Status
        Workspace workspace = SparkManager.getWorkspace();
        StatusItem statusItem = workspace.getStatusBar().getStatusItem(status);
        if (statusItem != null) {
            SparkManager.getSessionManager().changePresence(statusItem.getPresence());
        }
    }
}
Also used : StatusItem(org.jivesoftware.spark.ui.status.StatusItem) MenuItem(java.awt.MenuItem) Workspace(org.jivesoftware.spark.Workspace)

Example 2 with StatusItem

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

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

the class SparkSystemTray method addStatusMenuItems.

/**
 * Add all Registered DND's to MenuItems.
 */
private void addStatusMenuItems() {
    Workspace workspace = SparkManager.getWorkspace();
    StatusBar statusBar = workspace.getStatusBar();
    for (Object o : statusBar.getStatusList()) {
        StatusItem item = (StatusItem) o;
        final JMenuItem menuItem = new JMenuItem(item.getText());
        menuItem.addActionListener(this);
        statusMenu.add(menuItem);
    }
}
Also used : StatusItem(org.jivesoftware.spark.ui.status.StatusItem) StatusBar(org.jivesoftware.spark.ui.status.StatusBar) Workspace(org.jivesoftware.spark.Workspace)

Example 4 with StatusItem

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

the class ApplePlugin method sparkIsIdle.

private void sparkIsIdle() {
    LocalPreferences localPref = SettingsManager.getLocalPreferences();
    if (!localPref.isIdleOn()) {
        return;
    }
    try {
        // Handle if spark is not connected to the server.
        if (SparkManager.getConnection() == null || !SparkManager.getConnection().isConnected()) {
            return;
        }
        // Change Status
        Workspace workspace = SparkManager.getWorkspace();
        if (workspace != null) {
            Presence presence = workspace.getStatusBar().getPresence();
            long diff = System.currentTimeMillis() - lastActive;
            boolean idle = diff > 60000 * 60;
            if (presence.getMode() == Presence.Mode.available && idle) {
                unavailable = true;
                StatusItem away = workspace.getStatusBar().getStatusItem("Away");
                Presence p = away.getPresence();
                p.setStatus(Res.getString("message.away.idle"));
                previousPriority = presence.getPriority();
                p.setPriority(0);
                SparkManager.getSessionManager().changePresence(p);
            }
        }
    } catch (Exception e) {
        Log.error("Error with IDLE status.", e);
    }
}
Also used : StatusItem(org.jivesoftware.spark.ui.status.StatusItem) Presence(org.jivesoftware.smack.packet.Presence) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) IOException(java.io.IOException) Workspace(org.jivesoftware.spark.Workspace)

Aggregations

StatusItem (org.jivesoftware.spark.ui.status.StatusItem)4 Workspace (org.jivesoftware.spark.Workspace)3 Presence (org.jivesoftware.smack.packet.Presence)2 StatusBar (org.jivesoftware.spark.ui.status.StatusBar)2 MenuItem (java.awt.MenuItem)1 ActionEvent (java.awt.event.ActionEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 IOException (java.io.IOException)1 AbstractAction (javax.swing.AbstractAction)1 JMenu (javax.swing.JMenu)1 JMenuItem (javax.swing.JMenuItem)1 CustomStatusItem (org.jivesoftware.spark.ui.status.CustomStatusItem)1 LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)1