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