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());
}
}
}
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);
}
}
}
}
}
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);
}
}
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);
}
}
Aggregations