]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartItemImageRule.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.charts / src / org / simantics / charts / ui / ChartItemImageRule.java
diff --git a/bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartItemImageRule.java b/bundles/org.simantics.charts/src/org/simantics/charts/ui/ChartItemImageRule.java
new file mode 100644 (file)
index 0000000..2b790f5
--- /dev/null
@@ -0,0 +1,67 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.charts.ui;\r
+\r
+import java.awt.Color;\r
+import java.util.Map;\r
+\r
+import org.eclipse.jface.resource.ImageDescriptor;\r
+import org.simantics.browsing.ui.model.images.ImageRule;\r
+import org.simantics.charts.ontology.ChartResource;\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.stubs.G2DResource;\r
+import org.simantics.trend.impl.JarisPaints;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
+\r
+public enum ChartItemImageRule implements ImageRule {\r
+\r
+    INSTANCE;\r
+    public static ChartItemImageRule get() { return INSTANCE; }\r
+\r
+    public static final String COLUMN_KEY         = "single";\r
+    public static final String[] COLUMN_KEYS      = { COLUMN_KEY };\r
+\r
+    ChartItemIcon chartIcons = new ChartItemIcon();\r
+\r
+    @Override\r
+    public boolean isCompatible(Class<?> contentType) {\r
+        return contentType.equals(Resource.class);\r
+    }\r
+\r
+    @Override\r
+    public Map<String, ImageDescriptor> getImage(ReadGraph graph, Object content) throws DatabaseException {\r
+        Resource item = (Resource) content;\r
+        ChartResource CHART = ChartResource.getInstance(graph);\r
+        G2DResource G2D = G2DResource.getInstance(graph);\r
+\r
+        Color color = null;\r
+        float[] customColor = graph.getPossibleRelatedValue(item, G2D.HasColor, Bindings.FLOAT_ARRAY);\r
+        if (customColor != null && customColor.length >= 3)\r
+            color = new Color(customColor[0], customColor[1], customColor[2]);\r
+        if (color == null) {\r
+            Integer index = graph.getPossibleRelatedValue(item, CHART.Chart_Item_Index);\r
+            if ( index == null ) index = 1;\r
+            color = JarisPaints.getColor( index );\r
+        }\r
+\r
+        Resource rend = graph.getPossibleObject(item, CHART.Chart_Item_Renderer);\r
+        boolean binary = CHART.Renderer_Binary.equals(rend); \r
+\r
+        ImageDescriptor icon = chartIcons.createIcon(!binary, color, false);\r
+\r
+        return ArrayMap.make(COLUMN_KEYS, new ImageDescriptor[] { icon });\r
+    }\r
+\r
+}\r