contactitem.java.svn-base
来自「开源项目openfire的完整源程序」· SVN-BASE 代码 · 共 493 行 · 第 1/2 页
SVN-BASE
493 行
// Handle vCard update packet.
if (packetExtension != null) {
DefaultPacketExtension o = (DefaultPacketExtension)packetExtension;
String hash = o.getValue("photo");
if (hash != null) {
this.hash = hash;
if (!hashExists(hash)) {
updateAvatar();
}
updateAvatarInSideIcon();
}
}
updatePresenceIcon(presence);
}
/**
* Checks to see if the hash already exists.
*
* @param hash the hash.
* @return true if the hash exists, otherwise false.
*/
private boolean hashExists(String hash) {
contactsDir.mkdirs();
final File imageFile = new File(contactsDir, hash);
return imageFile.exists();
}
/**
* Returns the url of the avatar belonging to this contact.
*
* @return the url of the avatar.
* @throws MalformedURLException thrown if the address is invalid.
*/
public URL getAvatarURL() throws MalformedURLException {
contactsDir.mkdirs();
if (ModelUtil.hasLength(hash)) {
final File imageFile = new File(contactsDir, hash);
if (imageFile.exists()) {
return imageFile.toURL();
}
}
return SparkManager.getVCardManager().getAvatarURL(getJID());
}
/**
* Persists the avatar locally based on the new hash.
*/
private void updateAvatar() {
SparkManager.getVCardManager().addToQueue(getJID());
}
public String toString() {
return nicknameLabel.getText();
}
/**
* Updates the icon of the user based on their presence.
*
* @param presence the users presence.
*/
public void updatePresenceIcon(Presence presence) {
ChatManager chatManager = SparkManager.getChatManager();
boolean handled = chatManager.fireContactItemPresenceChanged(this, presence);
if (handled) {
return;
}
String status = presence.getStatus();
Icon statusIcon = SparkRes.getImageIcon(SparkRes.GREEN_BALL);
boolean isAvailable = false;
if (status == null && presence.isAvailable()) {
Presence.Mode mode = presence.getMode();
if (mode == Presence.Mode.available) {
status = "Available";
isAvailable = true;
}
else if (mode == Presence.Mode.away) {
status = "I'm away";
statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
}
else if (mode == Presence.Mode.chat) {
status = "I'm free to chat";
}
else if (mode == Presence.Mode.dnd) {
status = "Do not disturb";
statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
}
else if (mode == Presence.Mode.xa) {
status = "Extended away";
statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
}
}
if (presence.isAvailable() && (presence.getMode() == Presence.Mode.dnd || presence.getMode() == Presence.Mode.away || presence.getMode() == Presence.Mode.xa)) {
statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
}
else if (presence.isAvailable()) {
isAvailable = true;
}
else if (!presence.isAvailable()) {
getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
getNicknameLabel().setForeground((Color)UIManager.get("ContactItemOffline.color"));
RosterEntry entry = SparkManager.getConnection().getRoster().getEntry(getJID());
if (entry != null && (entry.getType() == RosterPacket.ItemType.none || entry.getType() == RosterPacket.ItemType.from)
&& RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) {
// Do not move out of group.
setIcon(SparkRes.getImageIcon(SparkRes.SMALL_QUESTION));
getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
setStatusText("Pending");
}
else {
setIcon(null);
setFont(new Font("Dialog", Font.PLAIN, fontSize));
getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
setAvailable(false);
if (ModelUtil.hasLength(status)) {
setStatusText(status);
}
else {
setStatusText("");
}
}
sideIcon.setIcon(null);
setAvailable(false);
return;
}
Icon sIcon = PresenceManager.getIconFromPresence(presence);
if (sIcon != null) {
setIcon(sIcon);
}
else {
setIcon(statusIcon);
}
if (status != null) {
setStatus(status);
}
if (status != null && status.toLowerCase().indexOf("phone") != -1) {
statusIcon = SparkRes.getImageIcon(SparkRes.ON_PHONE_IMAGE);
setIcon(statusIcon);
}
// Always change nickname label to black.
getNicknameLabel().setForeground((Color)UIManager.get("ContactItemNickname.foreground"));
if (isAvailable) {
getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
if ("Online".equals(status) || Res.getString("available").equalsIgnoreCase(status)) {
setStatusText("");
}
else {
setStatusText(status);
}
}
else if (presence.isAvailable()) {
getNicknameLabel().setFont(new Font("Dialog", Font.ITALIC, fontSize));
getNicknameLabel().setForeground(Color.gray);
if (status != null) {
setStatusText(status);
}
}
setAvailable(true);
}
/**
* Sets the status label text based on the users status.
*
* @param status the users status.
*/
public void setStatusText(String status) {
setStatus(status);
if (ModelUtil.hasLength(status)) {
getDescriptionLabel().setText(" - " + status);
}
else {
getDescriptionLabel().setText("");
}
}
/**
* The icon to use to show extra information about this contact. An example would be to
* represent that this user is from a 3rd party transport.
*
* @param icon the icon to use.
*/
public void setSideIcon(Icon icon) {
sideIcon.setIcon(icon);
}
/**
* Shows that the user is coming online.
*/
public void showUserComingOnline() {
// Change Font
getNicknameLabel().setFont(new Font("Dialog", Font.BOLD, fontSize));
getNicknameLabel().setForeground(new Color(255, 128, 0));
}
/**
* Shows that the user is going offline.
*/
public void showUserGoingOfflineOnline() {
// Change Font
getNicknameLabel().setFont(new Font("Dialog", Font.BOLD, fontSize));
getNicknameLabel().setForeground(Color.red);
}
/**
* Update avatar icon.
*/
public void updateAvatarInSideIcon() {
try {
final URL url = getAvatarURL();
if (url != null) {
if (!avatarsShowing) {
setSideIcon(null);
}
else {
ImageIcon icon = new ImageIcon(url);
icon = GraphicUtils.scale(icon, iconSize, iconSize);
setSideIcon(icon);
}
}
}
catch (MalformedURLException e) {
Log.error(e);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?