]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.network/src/org/simantics/district/network/profile/DNElementColorStyle.java
First version of throttled profile results - configure via proeprty view
[simantics/district.git] / org.simantics.district.network / src / org / simantics / district / network / profile / DNElementColorStyle.java
1 package org.simantics.district.network.profile;
2
3 import java.awt.Color;
4
5 import org.simantics.Simantics;
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.Resource;
8 import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.diagram.profile.StyleBase;
11 import org.simantics.scenegraph.INode;
12 import org.simantics.scenegraph.g2d.nodes.SingleElementNode;
13 import org.simantics.scenegraph.profile.EvaluationContext;
14 import org.simantics.scenegraph.profile.common.ProfileVariables;
15
16 /**
17  * @author Tuukka Lehtonen
18  * @since 1.35.0
19  */
20 public class DNElementColorStyle extends ThrottledStyleBase<Color> {
21
22         private static final boolean DEBUG = false;
23
24         @Override
25         public Color calculateThrottledStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource groupItem) throws DatabaseException {
26                 DiagramSettings ds = graph.syncRequest(new DiagramSettingsRequest(runtimeDiagram), TransientCacheAsyncListener.instance());
27                 if (ds.elementColoringFunction.isPresent()) {
28                         if (DEBUG)
29                                 System.out.print("elementColoringFunction: " + ds.elementColoringFunction + "(" + groupItem + "): ");
30                         Double t = Simantics.applySCLRead(graph, ds.elementColoringFunction.get(), groupItem);
31                         if (DEBUG)
32                                 System.out.print(t);
33                         if (t != null) {
34                                 Color result = ds.coloringGradient.get(t);
35                                 //System.out.println("color(" + t + "): " + result);
36                                 return result;
37                         }
38                 }
39                 return null;
40         }
41
42         @Override
43         public void applyThrottledStyleForNode(EvaluationContext observer, INode node, Color color) {
44                 SingleElementNode n = (SingleElementNode) node;
45                 for (INode nn : n.getNodes())
46                         ProfileVariables.claimNodeProperty(nn, "dynamicColor", color, observer);
47         }
48
49         @Override
50         protected void cleanupStyleForNode(EvaluationContext evaluationContext, INode node) {
51                 SingleElementNode n = (SingleElementNode) node;
52                 for (INode nn : n.getNodes())
53                         ProfileVariables.claimNodeProperty(nn, "dynamicColor", null, evaluationContext);
54         }
55
56 }