use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.
the class BuzzPlugin method shakeWindow.
private void shakeWindow(Message message) {
String bareJID = XmppStringUtils.parseBareJid(message.getFrom());
ContactItem contact = SparkManager.getWorkspace().getContactList().getContactItemByJID(bareJID);
String nickname = XmppStringUtils.parseLocalpart(bareJID);
if (contact != null) {
nickname = contact.getDisplayName();
}
ChatRoom room;
try {
room = SparkManager.getChatManager().getChatContainer().getChatRoom(bareJID);
} catch (ChatRoomNotFoundException e) {
// Create the room if it does not exist.
room = SparkManager.getChatManager().createChatRoom(bareJID, nickname, nickname);
}
ChatFrame chatFrame = SparkManager.getChatManager().getChatContainer().getChatFrame();
if (chatFrame != null) {
if (SettingsManager.getLocalPreferences().isBuzzEnabled()) {
chatFrame.buzz();
SparkManager.getChatManager().getChatContainer().activateChatRoom(room);
}
}
// Insert offline message
room.getTranscriptWindow().insertNotificationMessage(Res.getString("message.buzz.message", nickname), ChatManager.NOTIFICATION_COLOR);
room.scrollToBottom();
}
use of org.jivesoftware.spark.ui.ContactItem 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.ContactItem 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.ContactItem 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();
}
}
use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.
the class FrequentContactsPlugin method showPopup.
/**
* Displays your favorite contacts.
*/
private void showPopup() {
// Get Transcript Directory
if (!transcriptDir.exists()) {
return;
}
jidMap.clear();
model.clear();
final ContactList contactList = SparkManager.getWorkspace().getContactList();
for (final String user : getFavoriteContacts()) {
ContactItem contactItem = contactList.getContactItemByJID(user);
Icon icon;
if (contactItem != null) {
icon = contactItem.getIcon();
if (icon == null) {
icon = SparkRes.getImageIcon(SparkRes.CLEAR_BALL_ICON);
}
JLabel label = new JLabel();
label.setText(contactItem.getDisplayName());
label.setIcon(icon);
model.addElement(label);
jidMap.put(label, user);
}
}
window.setSize(200, 200);
GraphicUtils.centerWindowOnComponent(window, SparkManager.getMainWindow());
if (model.size() > 0) {
contacts.setSelectedIndex(0);
}
window.setVisible(true);
}
Aggregations