use of org.jivesoftware.spark.ui.ContactList in project Spark by igniterealtime.
the class PresenceChangePlugin method initialize.
public void initialize() {
// Listen for right-clicks on ContactItem
final ContactList contactList = SparkManager.getWorkspace().getContactList();
final Action listenAction = new AbstractAction() {
private static final long serialVersionUID = 7705539667621148816L;
public void actionPerformed(ActionEvent e) {
for (ContactItem item : contactList.getSelectedUsers()) {
String bareAddress = XmppStringUtils.parseBareJid(item.getJID());
sparkContacts.add(bareAddress);
}
}
};
listenAction.putValue(Action.NAME, Res.getString("menuitem.alert.when.online"));
listenAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_ALARM_CLOCK));
final Action removeAction = new AbstractAction() {
private static final long serialVersionUID = -8726129089417116105L;
public void actionPerformed(ActionEvent e) {
for (ContactItem item : contactList.getSelectedUsers()) {
String bareAddress = XmppStringUtils.parseBareJid(item.getJID());
sparkContacts.remove(bareAddress);
}
}
};
removeAction.putValue(Action.NAME, Res.getString("menuitem.remove.alert.when.online"));
removeAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_DELETE));
contactList.addContextMenuListener(new ContextMenuListener() {
public void poppingUp(Object object, JPopupMenu popup) {
if (object instanceof ContactItem) {
ContactItem item = (ContactItem) object;
String bareAddress = XmppStringUtils.parseBareJid(item.getJID());
if (!item.getPresence().isAvailable() || item.getPresence().isAway()) {
if (sparkContacts.contains(bareAddress)) {
popup.add(removeAction);
} else {
popup.add(listenAction);
}
}
}
}
public void poppingDown(JPopupMenu popup) {
}
public boolean handleDefaultAction(MouseEvent e) {
return false;
}
});
// Check presence changes
SparkManager.getConnection().addAsyncStanzaListener(stanza -> {
try {
Presence presence = (Presence) stanza;
if (!presence.isAvailable() || presence.isAway()) {
return;
}
String from = presence.getFrom();
ArrayList<String> removelater = new ArrayList<>();
for (final String jid : sparkContacts) {
if (jid.equals(XmppStringUtils.parseBareJid(from))) {
removelater.add(jid);
// sparkContacts.remove(jid);
String nickname = SparkManager.getUserManager().getUserNicknameFromJID(jid);
String time = SparkManager.DATE_SECOND_FORMATTER.format(new Date());
String infoText = Res.getString("message.user.now.available.to.chat", nickname, time);
if (localPref.getShowToasterPopup()) {
EventQueue.invokeLater(() -> {
SparkToaster toaster = new SparkToaster();
toaster.setDisplayTime(5000);
toaster.setBorder(BorderFactory.createBevelBorder(0));
toaster.setToasterHeight(150);
toaster.setToasterWidth(200);
toaster.setTitle(nickname);
toaster.showToaster(null, infoText);
toaster.setCustomAction(new AbstractAction() {
private static final long serialVersionUID = 4827542713848133369L;
@Override
public void actionPerformed(ActionEvent e) {
SparkManager.getChatManager().getChatRoom(jid);
}
});
});
}
ChatRoom room = SparkManager.getChatManager().getChatRoom(jid);
if (localPref.getWindowTakesFocus()) {
EventQueue.invokeLater(() -> SparkManager.getChatManager().activateChat(jid, nickname));
}
EventQueue.invokeLater(() -> room.getTranscriptWindow().insertNotificationMessage(infoText, ChatManager.NOTIFICATION_COLOR));
}
}
for (String s : removelater) {
sparkContacts.remove(s);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}, new StanzaTypeFilter(Presence.class));
}
use of org.jivesoftware.spark.ui.ContactList 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());
}
use of org.jivesoftware.spark.ui.ContactList in project Spark by igniterealtime.
the class NotificationPlugin method registerListener.
private void registerListener() {
preferences = SettingsManager.getLocalPreferences();
// Iterate through all online users and add them to the list.
ContactList contactList = SparkManager.getWorkspace().getContactList();
for (ContactGroup contactGroup : contactList.getContactGroups()) {
for (ContactItem item : contactGroup.getContactItems()) {
if (item != null && item.getJID() != null && item.getPresence().isAvailable()) {
String bareJID = XmppStringUtils.parseBareJid(item.getJID());
onlineUsers.add(bareJID);
}
}
}
// Add Presence Listener
SparkManager.getConnection().addAsyncStanzaListener(this, new StanzaTypeFilter(Presence.class));
}
use of org.jivesoftware.spark.ui.ContactList in project Spark by igniterealtime.
the class JabberVersion method initialize.
public void initialize() {
// Create IQ Filter
StanzaFilter packetFilter = new StanzaTypeFilter(IQ.class);
SparkManager.getConnection().addAsyncStanzaListener(stanza -> {
IQ iq = (IQ) stanza;
try {
// Handle Version Request
if (iq instanceof Version && iq.getType() == IQ.Type.get) {
// Send Version
Version version = new Version(JiveInfo.getName(), JiveInfo.getVersion(), JiveInfo.getOS());
// Send back as a reply
version.setStanzaId(iq.getStanzaId());
version.setType(IQ.Type.result);
version.setTo(iq.getFrom());
version.setFrom(iq.getTo());
SparkManager.getConnection().sendStanza(version);
} else // Send time
if (iq instanceof Time && iq.getType() == IQ.Type.get) {
Time time = new Time();
time.setStanzaId(iq.getStanzaId());
time.setFrom(iq.getTo());
time.setTo(iq.getFrom());
time.setTime(new Date());
time.setType(IQ.Type.result);
// Send Time
SparkManager.getConnection().sendStanza(time);
}
} catch (SmackException.NotConnectedException e) {
Log.warning("Unable to answer request: " + stanza, e);
}
}, packetFilter);
final ContactList contactList = SparkManager.getWorkspace().getContactList();
contactList.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("control F11"), "viewClient");
contactList.addContextMenuListener(new ContextMenuListener() {
public void poppingUp(final Object component, JPopupMenu popup) {
if (!(component instanceof ContactItem)) {
return;
}
ContactItem contactItem = (ContactItem) component;
if (contactItem.getPresence() == null) {
return;
}
Action versionRequest = new AbstractAction() {
private static final long serialVersionUID = -5619737417315441711L;
public void actionPerformed(ActionEvent e) {
viewClient();
}
};
versionRequest.putValue(Action.NAME, Res.getString("menuitem.view.client.version"));
popup.add(versionRequest);
}
public void poppingDown(JPopupMenu popup) {
}
public boolean handleDefaultAction(MouseEvent e) {
return false;
}
});
contactList.getActionMap().put("viewClient", new AbstractAction("viewClient") {
private static final long serialVersionUID = 8282301357403753561L;
public void actionPerformed(ActionEvent evt) {
viewClient();
}
});
}
use of org.jivesoftware.spark.ui.ContactList in project Spark by igniterealtime.
the class JabberVersion method viewClient.
private void viewClient() {
final ContactList contactList = SparkManager.getWorkspace().getContactList();
Collection<ContactItem> selectedUsers = contactList.getSelectedUsers();
if (selectedUsers.size() == 1) {
ContactItem item = (ContactItem) selectedUsers.toArray()[0];
Presence presence = item.getPresence();
final String jid = presence.getFrom();
SwingWorker worker = new SwingWorker() {
public Object construct() {
try {
Thread.sleep(10);
} catch (InterruptedException e1) {
// Nothing to do
}
return jid;
}
public void finished() {
VersionViewer.viewVersion(jid);
}
};
worker.start();
}
}
Aggregations