]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartData.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.charts / src / org / simantics / charts / ui / ChartData.java
1 package org.simantics.charts.ui;\r
2 \r
3 import java.util.Comparator;\r
4 import java.util.HashSet;\r
5 import java.util.TreeMap;\r
6 \r
7 import org.simantics.databoard.annotations.Optional;\r
8 import org.simantics.databoard.util.Bean;\r
9 import org.simantics.db.common.NamedResource;\r
10 import org.simantics.trend.configuration.TrendItem;\r
11 import org.simantics.trend.configuration.TrendItem.Renderer;\r
12 import org.simantics.trend.configuration.YAxisMode;\r
13 import org.simantics.utils.strings.AlphanumComparator;\r
14 \r
15 public class ChartData extends Bean {\r
16         \r
17         public @Optional String name;\r
18         public @Optional Double timeIncrement;  \r
19         public @Optional Double timeStart;  \r
20         public @Optional Double timeLength;\r
21         \r
22         public boolean showMilestones;\r
23         public boolean showGrid;\r
24         public boolean trackExperimentTime;\r
25         public YAxisMode axisMode;\r
26 \r
27         public boolean backgroundGradient;\r
28         public @Optional float[] backgroundColor1;\r
29         public @Optional float[] backgroundColor2;\r
30         public @Optional float[] gridColor;\r
31         \r
32         public static class ItemKey {\r
33                 public final Renderer renderer;\r
34                 public final int index;\r
35                 public final NamedResource resource;\r
36                 public ItemKey(Renderer renderer, int index, NamedResource resource) {\r
37                         this.renderer = renderer;\r
38                         this.index = index;\r
39                         this.resource = resource;\r
40                 }\r
41         }\r
42 \r
43         // Don't allow databoard to handle these since it just screws them up.\r
44         public transient TreeMap<ItemKey, TrendItem> allItems = new TreeMap<>(ITEM_SORTER);\r
45         public transient HashSet<ItemKey> hiddenItems = new HashSet<>();\r
46 \r
47         private static Comparator<ItemKey> ITEM_SORTER = new Comparator<ItemKey>() {\r
48                 @Override\r
49                 public int compare(ItemKey o1, ItemKey o2) {\r
50                         int c = Integer.compare(o1.renderer.ordinal(), o2.renderer.ordinal());\r
51                         if (c != 0)\r
52                                 return c;\r
53                         c = Integer.compare(o1.index, o2.index);\r
54                         if (c != 0)\r
55                                 return c;\r
56                         return AlphanumComparator.CASE_INSENSITIVE_COMPARATOR.compare(o1.resource.getName(), o2.resource.getName());\r
57                 }\r
58         };\r
59 \r
60         public void readFrom(ChartData other) {\r
61                 super.readFrom(other);\r
62                 this.allItems = new TreeMap<>(ITEM_SORTER);\r
63                 this.allItems.putAll(other.allItems);\r
64                 this.hiddenItems = new HashSet<>(other.hiddenItems);\r
65         }\r
66 \r
67         @Override\r
68         public boolean equals(Object obj) {\r
69                 boolean s = super.equals(obj);\r
70                 if (!s)\r
71                         return false;\r
72                 ChartData other = (ChartData) obj;\r
73                 return allItems.equals(other.allItems)\r
74                                 && hiddenItems.equals(other.hiddenItems);\r
75         }\r
76         \r
77 }\r