use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.
the class JContactItemRenderer method getListCellRendererComponent.
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
basicPanelRenderer.getListCellRendererComponent(list, this, index, isSelected, cellHasFocus);
ContactItem renderItem = (ContactItem) value;
setFocusable(false);
setNickname(renderItem.getNickname());
setAlias(renderItem.getAlias());
if (this.getDisplayName().trim().isEmpty()) {
// Fallback hack to show something other than empty string.
// JID can't be set after object creation, so alias is reset.
setAlias(renderItem.getDisplayName());
}
setIcon(renderItem.getIcon());
setStatus(renderItem.getStatus());
getNicknameLabel().setFont(renderItem.getNicknameLabel().getFont());
getNicknameLabel().setForeground(renderItem.getNicknameLabel().getForeground());
getDescriptionLabel().setFont(renderItem.getDescriptionLabel().getFont());
getDescriptionLabel().setText(renderItem.getDescriptionLabel().getText());
getSpecialImageLabel().setIcon(renderItem.getSpecialImageLabel().getIcon());
getSideIcon().setIcon(renderItem.getSideIcon().getIcon());
return this;
}
use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.
the class SparkTransferManager method sendFile.
/**
* Send a file to a user.
*
* @param file the file to send.
* @param jid the jid of the user to send the file to.
* @return the ChatRoom of the user.
*/
public ChatRoom sendFile(File file, String jid) {
long maxsize = Long.parseLong(Default.getString(Default.FILE_TRANSFER_MAXIMUM_SIZE));
long warningsize = Long.parseLong(Default.getString(Default.FILE_TRANSFER_WARNING_SIZE));
if (file.length() >= maxsize && maxsize != -1) {
String maxsizeString = TransferUtils.getAppropriateByteWithSuffix(maxsize);
String yoursizeString = TransferUtils.getAppropriateByteWithSuffix(file.length());
String output = Res.getString("message.file.transfer.file.too.big.error", maxsizeString, yoursizeString);
UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
JOptionPane.showMessageDialog(null, output, Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
return null;
}
if (file.length() >= warningsize && warningsize != -1) {
int result = JOptionPane.showConfirmDialog(null, Res.getString("message.file.transfer.file.too.big.warning"), Res.getString("title.error"), JOptionPane.YES_NO_OPTION);
if (result != 0) {
return null;
}
}
final ContactList contactList = SparkManager.getWorkspace().getContactList();
String bareJID = XmppStringUtils.parseBareJid(jid);
String fullJID = PresenceManager.getFullyQualifiedJID(jid);
if (!PresenceManager.isOnline(jid)) {
ArrayList<File> list = waitMap.get(jid);
if (list == null) {
list = new ArrayList<>();
}
list.add(file);
waitMap.put(jid, list);
ChatRoom chatRoom;
ContactItem contactItem = contactList.getContactItemByJID(jid);
if (contactItem != null) {
chatRoom = SparkManager.getChatManager().createChatRoom(jid, contactItem.getDisplayName(), contactItem.getDisplayName());
} else {
chatRoom = SparkManager.getChatManager().createChatRoom(jid, jid, jid);
}
chatRoom.getTranscriptWindow().insertNotificationMessage("The user is offline. Will auto-send \"" + file.getName() + "\" when user comes back online.", ChatManager.ERROR_COLOR);
return null;
}
// Create the outgoing file transfer
final OutgoingFileTransfer transfer = transferManager.createOutgoingFileTransfer(fullJID);
ContactItem contactItem = contactList.getContactItemByJID(bareJID);
ChatRoom chatRoom;
if (contactItem != null) {
chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, contactItem.getDisplayName(), contactItem.getDisplayName());
} else {
chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, bareJID, bareJID);
}
TranscriptWindow transcriptWindow = chatRoom.getTranscriptWindow();
SendFileTransfer sendingUI = new SendFileTransfer();
try {
transfer.sendFile(file, "Sending file");
} catch (SmackException e) {
Log.error(e);
}
// Add listener to cancel transfer is sending file to user who just went offline.
AndFilter presenceFilter = new AndFilter(new StanzaTypeFilter(Presence.class), FromMatchesFilter.createBare(bareJID));
final StanzaListener packetListener = stanza -> {
Presence presence = (Presence) stanza;
if (!presence.isAvailable()) {
if (transfer != null) {
transfer.cancel();
}
}
};
// Add presence listener to check if user is offline and cancel sending.
SparkManager.getConnection().addAsyncStanzaListener(packetListener, presenceFilter);
chatRoom.addClosingListener(() -> {
SparkManager.getConnection().removeAsyncStanzaListener(packetListener);
if (!transfer.isDone()) {
transfer.cancel();
}
});
try {
sendingUI.sendFile(transfer, transferManager, fullJID, contactItem.getDisplayName());
} catch (NullPointerException e) {
Log.error(e);
}
transcriptWindow.addComponent(sendingUI);
chatRoom.scrollToBottom();
return chatRoom;
}
use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.
the class ContactInfoWindow method display.
public void display(ContactGroup group, MouseEvent e) {
int loc = group.getList().locationToIndex(e.getPoint());
ContactItem item = (ContactItem) group.getList().getModel().getElementAt(loc);
if (item == null || item.getJID() == null) {
return;
}
if (getContactItem() != null && getContactItem() == item) {
return;
}
iconLabel.setIcon(item.getIcon());
Point point = group.getList().indexToLocation(loc);
window.setFocusableWindowState(false);
setContactItem(item);
window.pack();
Point mainWindowLocation = SparkManager.getMainWindow().getLocationOnScreen();
Point listLocation = group.getList().getLocationOnScreen();
int x = (int) mainWindowLocation.getX() + SparkManager.getMainWindow().getWidth();
int y = (int) listLocation.getY() + (int) point.getY();
setWindowLocation(x, y);
if (!window.isVisible()) {
window.setVisible(true);
}
}
use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.
the class VCardManager method reloadVCard.
/**
* Forces a reload of a <code>VCard</code>. To load a VCard you should use
* getVCard(String jid) instead. This method will perform a network lookup
* which could take some time. If you're having problems with request
* timeout you should also use getVCard(String jid). Use addToQueue(String
* jid) if you want VCardManager to update the VCard by the given jid. The
* method will block until the result is available or a timeout occurs.
*
* @param jid
* the jid of the user.
*
* @return the new network vCard or a vCard with an error
*/
public VCard reloadVCard(String jid) {
jid = XmppStringUtils.parseBareJid(jid);
VCard vcard = new VCard();
try {
vcard.setJabberId(jid);
vcard.load(SparkManager.getConnection(), jid);
if (vcard.getNickName() != null && vcard.getNickName().length() > 0) {
// update nickname.
ContactItem item = SparkManager.getWorkspace().getContactList().getContactItemByJID(jid);
item.setNickname(vcard.getNickName());
// TODO: this doesn't work if someone removes his nickname. If we remove it in that case, it will cause problems with people using another way to manage their nicknames.
}
addVCard(jid, vcard);
persistVCard(jid, vcard);
} catch (XMPPException | SmackException e) {
// //System.out.println(jid+" Fehler in reloadVCard ----> null");
vcard.setError(new XMPPError(XMPPError.Condition.resource_constraint));
vcard.setJabberId(jid);
delayedContacts.add(jid);
return vcard;
// We dont want cards with error
// vcard.setError(new XMPPError(XMPPError.Condition.request_timeout));
// addVCard(jid, vcard);
}
return vcard;
}
Aggregations