1 package org.simantics.district.network.ui.adapters;
4 import java.util.ArrayList;
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;
15 public class DistrictNetworkAdditionalColor implements AdditionalColor {
17 public static final Key KEY_DN_MAPPING_RESOURCE = new KeyOf(Resource.class, "DN_MAPPING_RESOURCE");
19 private static final long serialVersionUID = -6290147660355075322L;
21 public static final ElementHandler INSTANCE = new DistrictNetworkAdditionalColor();
23 private ColorPool colorPool = new ColorPool();
24 private List<Resource> mappings = new ArrayList<>();
27 public void setAdditionalColor(IElement e, Color c) {
28 throw new UnsupportedOperationException("Not needed!");
32 public Color getAdditionalColor(IElement e) {
33 Resource mapping = e.getHint(KEY_DN_MAPPING_RESOURCE);
34 if (!mappings.contains(mapping))
35 mappings.add(mapping);
37 int index = mappings.indexOf(mapping);
38 Color color = colorPool.getColor(index).getAWTColor();