KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > reunion > ReunionUsersProperties


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Jonathan Riboux <jonathan.riboux@wanadoo.fr>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.reunion;
20
21 import java.io.Serializable JavaDoc;
22 import java.util.Hashtable JavaDoc;
23 import java.util.Iterator JavaDoc;
24
25 public class ReunionUsersProperties
26 implements Serializable JavaDoc
27 {
28   private Hashtable JavaDoc users;
29   private ColorsManager colorsManager;
30
31   public ReunionUsersProperties() {
32     users = new Hashtable JavaDoc();
33     colorsManager = new ReunionUsersProperties.ColorsManager();
34   }
35
36   public ReunionUserProperties addUser(String JavaDoc 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 JavaDoc user) {
44     return (ReunionUserProperties) users.remove(user);
45   }
46
47   public ReunionUserProperties getUserProperties(String JavaDoc user) {
48     return (ReunionUserProperties) users.get(user);
49   }
50   
51   public Iterator JavaDoc getUsers()
52   {
53     return users.keySet().iterator();
54   }
55
56
57   class ColorsManager implements Serializable JavaDoc {
58     private final String JavaDoc [] 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 JavaDoc [] 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 JavaDoc getBgColor() {
101       return BG_COLORS[currentColorIndex];
102     }
103     
104     public String JavaDoc getFgColor() {
105       return FG_COLORS[currentColorIndex];
106     }
107   }
108
109 }
110
Popular Tags