]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.network.ui/src/org/simantics/district/network/ui/adapters/DistrictNetworkAdditionalColor.java
Hide "enabled" column for non-component type tech type tables
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / adapters / DistrictNetworkAdditionalColor.java
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     private static final org.simantics.utils.ui.color.Color lightBlue = new org.simantics.utils.ui.color.Color(34, 167, 240);
22     private static final org.simantics.utils.ui.color.Color lightRed = new org.simantics.utils.ui.color.Color(236, 100, 75);
23     private static final org.simantics.utils.ui.color.Color lightGreen = new org.simantics.utils.ui.color.Color(135, 211, 124);
24     private static final org.simantics.utils.ui.color.Color gray = new org.simantics.utils.ui.color.Color(108, 122, 137);
25     private static final org.simantics.utils.ui.color.Color orange = new org.simantics.utils.ui.color.Color(243, 156, 18);
26     private static final org.simantics.utils.ui.color.Color purple = new org.simantics.utils.ui.color.Color(190, 144, 212);
27
28     public static final ElementHandler INSTANCE = new DistrictNetworkAdditionalColor();
29
30     private ColorPool colorPool = new ColorPool();
31     private List<Resource> mappings = new ArrayList<>();
32     
33     public DistrictNetworkAdditionalColor() {
34         colorPool.add(lightBlue);
35         colorPool.add(lightRed);
36         colorPool.add(lightGreen);
37         colorPool.add(gray);
38         colorPool.add(orange);
39         colorPool.add(purple);
40     }
41     
42     @Override
43     public void setAdditionalColor(IElement e, Color c) {
44         throw new UnsupportedOperationException("Not needed!");
45     }
46
47     @Override
48     public Color getAdditionalColor(IElement e) {
49         Resource mapping = e.getHint(KEY_DN_MAPPING_RESOURCE);
50         if (!mappings.contains(mapping))
51             mappings.add(mapping);
52         
53         int index = mappings.indexOf(mapping);
54         Color color = colorPool.getColor(index).getAWTColor();
55         return color;
56     }
57
58 }