]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartData.java b/bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartData.java
new file mode 100644 (file)
index 0000000..d161208
--- /dev/null
@@ -0,0 +1,77 @@
+package org.simantics.charts.ui;\r
+\r
+import java.util.Comparator;\r
+import java.util.HashSet;\r
+import java.util.TreeMap;\r
+\r
+import org.simantics.databoard.annotations.Optional;\r
+import org.simantics.databoard.util.Bean;\r
+import org.simantics.db.common.NamedResource;\r
+import org.simantics.trend.configuration.TrendItem;\r
+import org.simantics.trend.configuration.TrendItem.Renderer;\r
+import org.simantics.trend.configuration.YAxisMode;\r
+import org.simantics.utils.strings.AlphanumComparator;\r
+\r
+public class ChartData extends Bean {\r
+       \r
+       public @Optional String name;\r
+       public @Optional Double timeIncrement;  \r
+       public @Optional Double timeStart;  \r
+       public @Optional Double timeLength;\r
+       \r
+       public boolean showMilestones;\r
+       public boolean showGrid;\r
+       public boolean trackExperimentTime;\r
+       public YAxisMode axisMode;\r
+\r
+       public boolean backgroundGradient;\r
+       public @Optional float[] backgroundColor1;\r
+       public @Optional float[] backgroundColor2;\r
+       public @Optional float[] gridColor;\r
+       \r
+       public static class ItemKey {\r
+               public final Renderer renderer;\r
+               public final int index;\r
+               public final NamedResource resource;\r
+               public ItemKey(Renderer renderer, int index, NamedResource resource) {\r
+                       this.renderer = renderer;\r
+                       this.index = index;\r
+                       this.resource = resource;\r
+               }\r
+       }\r
+\r
+       // Don't allow databoard to handle these since it just screws them up.\r
+       public transient TreeMap<ItemKey, TrendItem> allItems = new TreeMap<>(ITEM_SORTER);\r
+       public transient HashSet<ItemKey> hiddenItems = new HashSet<>();\r
+\r
+       private static Comparator<ItemKey> ITEM_SORTER = new Comparator<ItemKey>() {\r
+               @Override\r
+               public int compare(ItemKey o1, ItemKey o2) {\r
+                       int c = Integer.compare(o1.renderer.ordinal(), o2.renderer.ordinal());\r
+                       if (c != 0)\r
+                               return c;\r
+                       c = Integer.compare(o1.index, o2.index);\r
+                       if (c != 0)\r
+                               return c;\r
+                       return AlphanumComparator.CASE_INSENSITIVE_COMPARATOR.compare(o1.resource.getName(), o2.resource.getName());\r
+               }\r
+       };\r
+\r
+       public void readFrom(ChartData other) {\r
+               super.readFrom(other);\r
+               this.allItems = new TreeMap<>(ITEM_SORTER);\r
+               this.allItems.putAll(other.allItems);\r
+               this.hiddenItems = new HashSet<>(other.hiddenItems);\r
+       }\r
+\r
+       @Override\r
+       public boolean equals(Object obj) {\r
+               boolean s = super.equals(obj);\r
+               if (!s)\r
+                       return false;\r
+               ChartData other = (ChartData) obj;\r
+               return allItems.equals(other.allItems)\r
+                               && hiddenItems.equals(other.hiddenItems);\r
+       }\r
+       \r
+}\r