diff options
author | Damian Minkov <damencho@jitsi.org> | 2009-04-21 10:09:37 +0000 |
---|---|---|
committer | Damian Minkov <damencho@jitsi.org> | 2009-04-21 10:09:37 +0000 |
commit | bd4b9a2471e0f04359ae57bd138af1d7338a0155 (patch) | |
tree | 14d35626a3537542766beceb74a776271cebb1a9 /src/net/java/sip/communicator/impl/gui/main/contactlist/DefaultContactList.java | |
parent | f1be39ed74591a2a8d351bcd55853572ce01f0e2 (diff) | |
download | jitsi-bd4b9a2471e0f04359ae57bd138af1d7338a0155.zip jitsi-bd4b9a2471e0f04359ae57bd138af1d7338a0155.tar.gz jitsi-bd4b9a2471e0f04359ae57bd138af1d7338a0155.tar.bz2 |
Issue #544 (User list in chat rooms not searchable with keyboard).
Diffstat (limited to 'src/net/java/sip/communicator/impl/gui/main/contactlist/DefaultContactList.java')
-rw-r--r-- | src/net/java/sip/communicator/impl/gui/main/contactlist/DefaultContactList.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/DefaultContactList.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/DefaultContactList.java index 528e336..b89e5ae 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/DefaultContactList.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/DefaultContactList.java @@ -11,8 +11,10 @@ import java.awt.event.*; import java.util.*; import javax.swing.*; +import javax.swing.text.*; import net.java.sip.communicator.impl.gui.main.chat.*; +import net.java.sip.communicator.impl.gui.main.chat.conference.*; import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.protocol.*; @@ -200,4 +202,57 @@ public class DefaultContactList return null; } + + /** + * Returns the next list element that starts with a prefix. + * + * @param prefix the string to test for a match + * @param startIndex the index for starting the search + * @param bias the search direction, either Position.Bias.Forward or + * Position.Bias.Backward. + * @return the index of the next list element that starts with the prefix; + * otherwise -1 + */ + public int getNextMatch(String prefix, int startIndex, Position.Bias bias) + { + int max = getModel().getSize(); + + if (prefix == null) + throw new IllegalArgumentException("prefix"); + if (startIndex < 0 || startIndex >= max) + throw new IllegalArgumentException("startIndex"); + + prefix = prefix.toUpperCase(); + + // start search from the next element after the selected element + int increment = (bias == Position.Bias.Forward) ? 1 : -1; + int index = startIndex; + do + { + Object o = getModel().getElementAt(index); + + if (o != null) + { + String contactName = null; + + if (o instanceof MetaContact) + { + contactName = ((MetaContact) o).getDisplayName() + .toUpperCase(); + } + else if(o instanceof ConferenceChatContact) + { + contactName = ((ConferenceChatContact) o).getName() + .toUpperCase(); + } + + if (contactName != null && contactName.startsWith(prefix)) + { + return index; + } + } + index = (index + increment + max) % max; + } while (index != startIndex); + return -1; + } } |