001 package users; 002 003 import java.io.*; 004 005 import java.util.*; 006 007 import users.events.*; 008 import users.swing.*; 009 import users.events.*; 010 011 import util.*; 012 013 /** 014 * Filters a UserManager's users with help of a UserFilter 015 * 016 * @see UserManager 017 * @see UserFilter 018 * 019 * @author Andreas Bartho 020 * @version 3.1 05/03/2003 021 * @since v3.1 022 */ 023 public class UserManagerFilter extends UserManager { 024 025 /** 026 * The UserManager to be filtered. 027 */ 028 UserManager m_umManager = UserManager.getGlobalUM(); 029 030 /** 031 * The filter to be applied to the UserManager. 032 */UserFilter m_ufFilter = new UserFilter() { 033 public boolean match(User u) { 034 return true; 035 } 036 }; 037 038 /** 039 * Creates a new UserManagerFilter. The UserManager used is the globally set UserManager. 040 * All Users are visible, which means that the applied UserFilter returns true for every User. 041 * The UserManagerFilter created with this constructor behaves like a normal UserManager. 042 * 043 * @see UserManager#setGlobalUM 044 */public UserManagerFilter() { 045 } 046 047 /** 048 * Creates a new UserManagerFilter from a given UserManager. All Users are visible, 049 * which means that the applied UserFilter returns true for every User. 050 * 051 * @param um The UserManager to be filtered. 052 */ 053 public UserManagerFilter(UserManager um) { 054 m_umManager = um; 055 } 056 057 /** 058 * Creates a new UserManagerFilter. The UserManager used is the globally set UserManager. 059 * 060 * @param uf The UserFilter to be applied. 061 * 062 * @see UserManager#setGlobalUM 063 * 064 */ 065 public UserManagerFilter(UserFilter uf) { 066 m_ufFilter = uf; 067 } 068 069 /** 070 * Creates a new UserManagerFilter from a given UserManager and a UserFilter. 071 * 072 * @param um The UserManager to be filtered. 073 * @param uf The UserFilter to be applied. 074 */ 075 public UserManagerFilter(UserManager um, UserFilter uf) { 076 m_umManager = um; 077 m_ufFilter = uf; 078 } 079 080 /** 081 * Sets the UserFilter. A previously set UserFilter will be replaced. 082 * 083 * @param uf The new UserFilter. 084 */ 085 public void setFilter(UserFilter uf) { 086 m_ufFilter = uf; 087 } 088 089 /** 090 * Returns all users registered with this UserManagerFilter's UserManager that match the filter. 091 */ 092 public Collection getUsers() { 093 SortedMap sm = new TreeMap(); 094 Iterator it = m_umManager.getUsers().iterator(); 095 while (it.hasNext()) { 096 User u = (User)it.next(); 097 if (m_ufFilter.match(u)) { 098 sm.put(u.getName(), u); 099 } 100 } 101 return Collections.unmodifiableCollection(sm.values()); 102 } 103 104 public void addUserDataListener(UserDataListener udl) { 105 m_umManager.addUserDataListener(udl); 106 } 107 }