]> gerrit.simantics Code Review - simantics/district.git/blob
ef3b10c939a244217cff00615342b0622972f0f1
[simantics/district.git] /
1 package org.simantics.district.network.ui.adapters;
2
3 import java.awt.Color;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import org.simantics.db.Resource;
8 import org.simantics.g2d.element.IElement;
9 import org.simantics.g2d.element.handler.AdditionalColor;
10 import org.simantics.g2d.element.handler.ElementHandler;
11 import org.simantics.utils.datastructures.hints.IHintContext.Key;
12 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
13 import org.simantics.utils.ui.color.ColorPool;
14
15 public class DistrictNetworkAdditionalColor implements AdditionalColor {
16
17     public static final Key KEY_DN_MAPPING_RESOURCE = new KeyOf(Resource.class, "DN_MAPPING_RESOURCE");
18     
19     private static final long serialVersionUID = -6290147660355075322L;
20
21     public static final ElementHandler INSTANCE = new DistrictNetworkAdditionalColor();
22
23     private ColorPool colorPool = new ColorPool();
24     private List<Resource> mappings = new ArrayList<>();
25     
26     @Override
27     public void setAdditionalColor(IElement e, Color c) {
28         throw new UnsupportedOperationException("Not needed!");
29     }
30
31     @Override
32     public Color getAdditionalColor(IElement e) {
33         Resource mapping = e.getHint(KEY_DN_MAPPING_RESOURCE);
34         if (!mappings.contains(mapping))
35             mappings.add(mapping);
36         
37         int index = mappings.indexOf(mapping);
38         Color color = colorPool.getColor(index).getAWTColor();
39         return color;
40     }
41
42 }