mirror of
https://github.com/igniterealtime/Spark.git
synced 2026-02-04 06:35:37 +00:00
SPARK-1730: Extract CONTACT_ITEM_COMPARATOR
This commit is contained in:
committed by
Guus der Kinderen
parent
acbae2405e
commit
af24d345e1
@ -70,6 +70,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import static org.jivesoftware.spark.ui.ContactItem.CONTACT_ITEM_COMPARATOR;
|
||||
|
||||
/**
|
||||
* Handles all users in the agent application. Each user or chatting user can be referenced from the User
|
||||
* Manager. You would use the UserManager to get visitors in a chat room or secondary agents.
|
||||
@ -402,7 +404,7 @@ public class UserManager {
|
||||
}
|
||||
|
||||
// Sort
|
||||
contacts.sort(itemComparator);
|
||||
contacts.sort(CONTACT_ITEM_COMPARATOR);
|
||||
|
||||
final JContactItemField contactField = new JContactItemField( new ArrayList<>( contacts ));
|
||||
|
||||
@ -515,11 +517,6 @@ public class UserManager {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts ContactItems.
|
||||
*/
|
||||
final Comparator<ContactItem> itemComparator = Comparator.comparing(item -> item.getDisplayName().toLowerCase());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -38,6 +38,8 @@ import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import static org.jivesoftware.spark.ui.ContactItem.CONTACT_ITEM_COMPARATOR;
|
||||
|
||||
/**
|
||||
* Container representing a RosterGroup within the Contact List.
|
||||
*/
|
||||
@ -238,7 +240,7 @@ public class ContactGroup extends CollapsiblePane implements MouseListener {
|
||||
}
|
||||
|
||||
if (!preferences.isOfflineGroupVisible()) {
|
||||
offlineContacts.sort(itemComparator);
|
||||
offlineContacts.sort(CONTACT_ITEM_COMPARATOR);
|
||||
int index = offlineContacts.indexOf(offlineItem);
|
||||
|
||||
int totalListSize = contactItems.size();
|
||||
@ -543,7 +545,7 @@ public class ContactGroup extends CollapsiblePane implements MouseListener {
|
||||
*/
|
||||
public List<ContactItem> getContactItems() {
|
||||
final List<ContactItem> list = new ArrayList<>(contactItems);
|
||||
list.sort(itemComparator);
|
||||
list.sort(CONTACT_ITEM_COMPARATOR);
|
||||
return list;
|
||||
}
|
||||
|
||||
@ -809,15 +811,10 @@ public class ContactGroup extends CollapsiblePane implements MouseListener {
|
||||
|
||||
public Collection<ContactItem> getOfflineContacts() {
|
||||
final List<ContactItem> list = new ArrayList<>(offlineContacts);
|
||||
list.sort(itemComparator);
|
||||
list.sort(CONTACT_ITEM_COMPARATOR);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts ContactItems.
|
||||
*/
|
||||
private final static Comparator<ContactItem> itemComparator = Comparator.comparing(item -> item.getDisplayName().toLowerCase());
|
||||
|
||||
/**
|
||||
* Returns true if this ContactGroup is the Offline Group.
|
||||
*
|
||||
|
||||
@ -24,6 +24,7 @@ import java.awt.Insets;
|
||||
import java.io.File;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Comparator;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
@ -58,6 +59,9 @@ import org.jxmpp.util.XmppStringUtils;
|
||||
public class ContactItem extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1514044406550293152L;
|
||||
|
||||
public final static Comparator<ContactItem> CONTACT_ITEM_COMPARATOR = Comparator.comparing(ContactItem::getDisplayName, String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
private final JLabel imageLabel;
|
||||
private final JLabel displayNameLabel;
|
||||
private final JLabel descriptionLabel;
|
||||
|
||||
@ -79,7 +79,7 @@ public class RosterPickList extends JPanel {
|
||||
}
|
||||
|
||||
// Sort Users
|
||||
userList.sort(itemComparator);
|
||||
userList.sort(ContactItem.CONTACT_ITEM_COMPARATOR);
|
||||
|
||||
for (ContactItem item : userList) {
|
||||
model.addElement(item);
|
||||
@ -148,18 +148,4 @@ public class RosterPickList extends JPanel {
|
||||
return selectedContacts;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sorts ContactItems.
|
||||
*/
|
||||
final Comparator<ContactItem> itemComparator = ( item1, item2 ) -> {
|
||||
String nickname1 = item1.getDisplayName();
|
||||
String nickname2 = item2.getDisplayName();
|
||||
if (nickname1 == null || nickname2 == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return nickname1.compareToIgnoreCase(nickname2);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -23,7 +23,6 @@ import java.awt.Insets;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -51,6 +50,8 @@ import org.jivesoftware.spark.component.TitlePanel;
|
||||
import org.jivesoftware.spark.ui.ContactItem;
|
||||
import org.jivesoftware.spark.util.log.Log;
|
||||
|
||||
import static org.jivesoftware.spark.ui.ContactItem.CONTACT_ITEM_COMPARATOR;
|
||||
|
||||
/**
|
||||
* @author Bergunde Holger
|
||||
*/
|
||||
@ -138,7 +139,7 @@ public class PrivacyAddDialogUI extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
_userList.sort(itemComparator);
|
||||
_userList.sort(CONTACT_ITEM_COMPARATOR);
|
||||
model.clear();
|
||||
for (ContactItem item : _userList) {
|
||||
|
||||
@ -234,16 +235,5 @@ public class PrivacyAddDialogUI extends JPanel {
|
||||
|
||||
return selectedContacts;
|
||||
}
|
||||
/**
|
||||
* Sorts ContactItems.
|
||||
*/
|
||||
final Comparator<ContactItem> itemComparator = ( item1, item2 ) -> {
|
||||
String nickname1 = item1.getDisplayName();
|
||||
String nickname2 = item2.getDisplayName();
|
||||
if (nickname1 == null || nickname2 == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return nickname1.compareToIgnoreCase(nickname2);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user