1 package org.simantics.charts.ui;
3 import java.util.Comparator;
4 import java.util.HashSet;
5 import java.util.TreeMap;
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;
15 public class ChartData extends Bean {
17 public @Optional String name;
18 public @Optional Double timeIncrement;
19 public @Optional Double timeStart;
20 public @Optional Double timeLength;
22 public boolean showMilestones;
23 public boolean showGrid;
24 public boolean trackExperimentTime;
25 public YAxisMode axisMode;
27 public boolean backgroundGradient;
28 public @Optional float[] backgroundColor1;
29 public @Optional float[] backgroundColor2;
30 public @Optional float[] gridColor;
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;
39 this.resource = resource;
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<>();
47 private static Comparator<ItemKey> ITEM_SORTER = new Comparator<ItemKey>() {
49 public int compare(ItemKey o1, ItemKey o2) {
50 int c = Integer.compare(o1.renderer.ordinal(), o2.renderer.ordinal());
53 c = Integer.compare(o1.index, o2.index);
56 return AlphanumComparator.CASE_INSENSITIVE_COMPARATOR.compare(o1.resource.getName(), o2.resource.getName());
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);
68 public boolean equals(Object obj) {
69 boolean s = super.equals(obj);
72 ChartData other = (ChartData) obj;
73 return allItems.equals(other.allItems)
74 && hiddenItems.equals(other.hiddenItems);