OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 147 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
112 ilm 1
package org.openconcerto.modules.operation;
2
 
3
import java.awt.Color;
4
import java.util.HashMap;
5
import java.util.List;
6
import java.util.Map;
7
 
8
import org.openconcerto.sql.users.User;
9
import org.openconcerto.sql.users.UserManager;
10
 
11
public class UserColor {
12
    private static UserColor instance;
147 ilm 13
    private static final String[] COLORS = new String[] { "#303F9F", "#31DE39", "#FFC107", "#C2185B", "#00796B", "#212121", "#00BCD4", "#A6A6A6", "#795548", "#B3E5FC", "#FF0000" };
14
    private final Map<Integer, Color> map = new HashMap<>();
112 ilm 15
 
16
    public UserColor() {
147 ilm 17
        final List<User> users = UserManager.getInstance().getAllActiveUsers();
112 ilm 18
        final int size = users.size();
19
        for (int i = 0; i < size; i++) {
147 ilm 20
            final User u = users.get(i);
181 ilm 21
            if (u.getColor() == null) {
22
                this.map.put(u.getId(), Color.decode(COLORS[i % COLORS.length]));
23
            } else {
24
                this.map.put(u.getId(), u.getColor());
25
            }
112 ilm 26
        }
27
    }
28
 
29
    public synchronized Color getColor(int id) {
181 ilm 30
        return this.map.get(id);
112 ilm 31
    }
32
 
147 ilm 33
    public static final synchronized UserColor getInstance() {
112 ilm 34
        if (instance == null) {
35
            instance = new UserColor();
36
        }
37
        return instance;
38
    }
39
}