diff options
Diffstat (limited to 'Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/highlight/ColorCalculator.xtend')
-rw-r--r-- | Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/highlight/ColorCalculator.xtend | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/highlight/ColorCalculator.xtend b/Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/highlight/ColorCalculator.xtend new file mode 100644 index 00000000..d0f9db88 --- /dev/null +++ b/Application/hu.bme.mit.inf.dslreasoner.application.ui/src/hu/bme/mit/inf/dslreasoner/application/ui/highlight/ColorCalculator.xtend | |||
@@ -0,0 +1,38 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.application.ui.highlight | ||
2 | |||
3 | import java.util.List | ||
4 | import java.util.Random | ||
5 | import org.eclipse.emf.ecore.EClass | ||
6 | import org.eclipse.emf.ecore.EEnum | ||
7 | |||
8 | class ColorCalculator { | ||
9 | |||
10 | public def dispatch getColor(EClass c) { | ||
11 | val supertypes = (c.getEAllSuperTypes + #[c]) | ||
12 | val typeHashcodes = supertypes.map[(c.getEPackage.nsURI->c.name).hashCode] | ||
13 | return randomColor(typeHashcodes) | ||
14 | } | ||
15 | public def dispatch getColor(EEnum e) { | ||
16 | return randomColor((e.getEPackage.nsURI->e.name).hashCode) | ||
17 | } | ||
18 | |||
19 | protected def randomColor(Integer seed) { | ||
20 | val Random random = new Random(seed) | ||
21 | val rangePicker = [|random.nextInt(128)+128] | ||
22 | return #[rangePicker.apply(), rangePicker.apply(), rangePicker.apply()] | ||
23 | } | ||
24 | protected def randomColor(Iterable<Integer> seeds) { seeds.map[randomColor].averageColor } | ||
25 | private def averageColor(Iterable<List<Integer>> colors) { | ||
26 | if(colors.empty) { | ||
27 | return #[256,256,256] | ||
28 | } else { | ||
29 | return #[ | ||
30 | colors.map[get(0)].average, | ||
31 | colors.map[get(1)].average, | ||
32 | colors.map[get(2)].average | ||
33 | ] | ||
34 | } | ||
35 | } | ||
36 | private def average(Iterable<Integer> doubles) { return doubles.reduce[p1, p2|p1+p2]/doubles.size } | ||
37 | } | ||
38 | |||