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