]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.trend/src/org/simantics/trend/impl/ViewRenderingProfile.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.trend / src / org / simantics / trend / impl / ViewRenderingProfile.java
1 package org.simantics.trend.impl;\r
2 \r
3 import java.awt.Color;\r
4 \r
5 import org.simantics.trend.configuration.ViewProfile;\r
6 \r
7 /**\r
8  * Internal caching class for chart rendering related data that only needs to be\r
9  * recreated when the rendered TrendSpec changes, not on every rendered frame.\r
10  * \r
11  * @author Tuukka Lehtonen\r
12  */\r
13 class ViewRenderingProfile {\r
14 \r
15     public Color backgroundColor1 = Plot.PLOT_AREA_BG_GRADIENT_COLOR_BOTTOM;\r
16     public Color backgroundColor2 = Plot.PLOT_AREA_BG_GRADIENT_COLOR_TOP;;\r
17     public Color gridColor = Plot.GRID_LINE_COLOR;\r
18 \r
19     public ViewRenderingProfile read(ViewProfile p) {\r
20         if (p.backgroundColor != null) {\r
21             float[] bg = p.backgroundColor;\r
22             int len = bg.length;\r
23             if (len >= 6) {\r
24                 backgroundColor1 = toColor(bg, 0);\r
25                 backgroundColor2 = toColor(bg, 3);\r
26             } else if (len >= 3) {\r
27                 backgroundColor1 = toColor(bg, 0);\r
28                 backgroundColor2 = null;\r
29             }\r
30         } else {\r
31             backgroundColor1 = Plot.PLOT_AREA_BG_GRADIENT_COLOR_BOTTOM;\r
32             backgroundColor2 = Plot.PLOT_AREA_BG_GRADIENT_COLOR_TOP;\r
33         }\r
34 \r
35         if (p.gridColor != null && p.gridColor.length >= 3) {\r
36             gridColor = toColor(p.gridColor, 0);\r
37         } else {\r
38             gridColor = Plot.GRID_LINE_COLOR;\r
39         }\r
40 \r
41         return this;\r
42     }\r
43 \r
44     private static Color toColor(float[] array, int offset) {\r
45         return new Color(clamp(array[offset]), clamp(array[offset+1]), clamp(array[offset+2]));\r
46     }\r
47 \r
48     private static float clamp(float v) {\r
49         return Math.max(0, Math.min(v, 1));\r
50     }\r
51 \r
52 }\r