OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 112 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.openconcerto.modules.operation;

import java.awt.Color;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.openconcerto.sql.users.User;
import org.openconcerto.sql.users.UserManager;

public class UserColor {
    private static UserColor instance;
    private static final String[] COLORS = new String[] { "#303F9F", "#31DE39", "#FFC107", "#C2185B", "#00796B", "#212121", "#00BCD4", "#A6A6A6", "#795548", "#B3E5FC", "#FF0000" };
    private final Map<Integer, Color> map = new HashMap<>();

    public UserColor() {
        final List<User> users = UserManager.getInstance().getAllActiveUsers();
        final int size = users.size();
        for (int i = 0; i < size; i++) {
            final User u = users.get(i);
            map.put(u.getId(), Color.decode(COLORS[i % COLORS.length]));
        }
    }

    public synchronized Color getColor(int id) {
        return map.get(id);
    }

    public static final synchronized UserColor getInstance() {
        if (instance == null) {
            instance = new UserColor();
        }
        return instance;
    }
}