1 19 package org.lucane.applications.reunion; 20 21 import java.io.Serializable ; 22 import java.util.Hashtable ; 23 import java.util.Iterator ; 24 25 public class ReunionUsersProperties 26 implements Serializable 27 { 28 private Hashtable users; 29 private ColorsManager colorsManager; 30 31 public ReunionUsersProperties() { 32 users = new Hashtable (); 33 colorsManager = new ReunionUsersProperties.ColorsManager(); 34 } 35 36 public ReunionUserProperties addUser(String user) { 37 ReunionUserProperties rup = new ReunionUserProperties(user, colorsManager.getFgColor(), colorsManager.getBgColor()); 38 colorsManager.moveToNextColor(); 39 users.put(user, rup); 40 return rup; 41 } 42 43 public ReunionUserProperties removeUser(String user) { 44 return (ReunionUserProperties) users.remove(user); 45 } 46 47 public ReunionUserProperties getUserProperties(String user) { 48 return (ReunionUserProperties) users.get(user); 49 } 50 51 public Iterator getUsers() 52 { 53 return users.keySet().iterator(); 54 } 55 56 57 class ColorsManager implements Serializable { 58 private final String [] FG_COLORS = { 59 "#444444", 60 "#880000", 61 "#008800", 62 "#000088", 63 "#884400", 64 "#880044", 65 "#008844", 66 "#448800", 67 "#440088", 68 "#004488" 69 }; 70 private final String [] BG_COLORS = { 71 "#eeeeee", 72 "#ffdddd", 73 "#ddffdd", 74 "#ddddff", 75 "#ffeedd", 76 "#ffddee", 77 "#ddffee", 78 "#eeffdd", 79 "#eeddff", 80 "#ddeeff" 81 }; 82 private int currentColorIndex=0; 83 private final int NUMBER_OF_COLORS=BG_COLORS.length; 84 85 public ColorsManager(){ 86 } 87 88 public int moveToNextColor() { 89 currentColorIndex++; 90 if (currentColorIndex>=NUMBER_OF_COLORS) { 91 currentColorIndex=0; 92 } 93 return currentColorIndex; 94 } 95 96 public void moveToFirstColor() { 97 currentColorIndex=0; 98 } 99 100 public String getBgColor() { 101 return BG_COLORS[currentColorIndex]; 102 } 103 104 public String getFgColor() { 105 return FG_COLORS[currentColorIndex]; 106 } 107 } 108 109 } 110 | Popular Tags |