MOD.SCLImageRule <T VP.VisualsRule
>-- MOD.SCLImageRule.getImages ==> "Resource -> <ReadGraph> [(String,ImageDescriptor)]" <R L0.HasProperty : L0.FunctionalRelation
+MOD.SCLLabelForegroundColorRule <T VP.VisualsRule
+ >-- MOD.SCLLabelForegroundColorRule.getColor ==> "Resource -> Maybe (Double, Double, Double) -> String -> Integer -> <ReadGraph> Maybe (Double, Double, Double)]" <R L0.HasProperty : L0.FunctionalRelation
+
+MOD.SCLLabelBackgroundColorRule <T VP.VisualsRule
+ >-- MOD.SCLLabelBackgroundColorRule.getColor ==> "Resource -> Maybe (Double, Double, Double) -> String -> Integer -> <ReadGraph> Maybe (Double, Double, Double)]" <R L0.HasProperty : L0.FunctionalRelation
+
MOD.SCLAction <T ACT.Action
--> MOD.SCLAction.action ==> "Resource -> <Proc> ()" <R L0.HasProperty : L0.FunctionalRelation
L0.SCLValue.expression %expression
L0.HasValueType "Resource -> <ReadGraph> [(String,ImageDescriptor)]"
+MOD.sclLabelForegroundColorRule : L0.Template
+ @template %action %expression
+ %action : MOD.SCLLabelForegroundColorRule
+ MOD.SCLLabelForegroundColorRule.getColor _ : MOD.SCLValue
+ L0.SCLValue.expression %expression
+ L0.HasValueType "Resource -> Maybe (Double, Double, Double) -> String -> Integer -> <ReadGraph> Maybe (Double, Double, Double)"
+
+MOD.sclLabelBackgroundColorRule : L0.Template
+ @template %action %expression
+ %action : MOD.SCLLabelBackgroundColorRule
+ MOD.SCLLabelBackgroundColorRule.getColor _ : MOD.SCLValue
+ L0.SCLValue.expression %expression
+ L0.HasValueType "Resource -> Maybe (Double, Double, Double) -> String -> Integer -> <ReadGraph> Maybe (Double, Double, Double)"
+
MOD.sclAction : L0.Template
@template %action %expression
%action : MOD.SCLAction
importJava "org.eclipse.jface.resource.DeviceResourceDescriptor" where
data FontDescriptor
+
+importJava "org.eclipse.jface.resource.ColorDescriptor" where
data ColorDescriptor
importJava "org.eclipse.jface.resource.FontDescriptor" where
@JavaName createFrom
createFontDescriptorFrom :: String -> Integer -> Integer -> FontDescriptor
+importJava "org.simantics.modeling.ColorDescriptorUtil" where
+ colorDescriptorAsHex :: ColorDescriptor -> <Proc> String
+ colorDescriptorAsTuple3 :: ColorDescriptor -> <Proc> (Double, Double, Double)
+ colorDescriptor :: (Double, Double, Double) -> <Proc> ColorDescriptor
+
defaultFontDescriptor = createFontDescriptorFrom "Arial" 12 0
importJava "org.simantics.browsing.ui.content.LabelDecorator" where
org.slf4j.api,
org.simantics.graphfile.ontology,
org.apache.batik,
- org.simantics.graph.compiler
+ org.simantics.graph.compiler,
+ org.simantics.browsing.ui;bundle-version="1.1.0"
Export-Package: org.simantics.modeling,
org.simantics.modeling.actions,
org.simantics.modeling.adapters,
</type>
</target>
+ <target interface="org.simantics.browsing.ui.model.visuals.VisualsRule">
+ <type uri="http://www.simantics.org/Modeling-0.0/SCLLabelForegroundColorRule"
+ class="org.simantics.modeling.adapters.SCLLabelForegroundColorRule">
+ <graph />
+ <this />
+ </type>
+ </target>
+
+ <target interface="org.simantics.browsing.ui.model.visuals.VisualsRule">
+ <type uri="http://www.simantics.org/Modeling-0.0/SCLLabelBackgroundColorRule"
+ class="org.simantics.modeling.adapters.SCLLabelBackgroundColorRule">
+ <graph />
+ <this />
+ </type>
+ </target>
+
<target interface="org.simantics.browsing.ui.model.tests.Test">
<type uri="http://www.simantics.org/Modeling-0.0/SCLTest"
class="org.simantics.modeling.adapters.SCLTest">
--- /dev/null
+package org.simantics.modeling;
+
+import org.eclipse.jface.resource.ColorDescriptor;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+import org.simantics.scl.runtime.tuple.Tuple3;
+
+public class ColorDescriptorUtil {
+ public static ColorDescriptor colorDescriptor(Tuple3 color) {
+ return ColorDescriptor.createFrom(new RGB((int)(((double)color.c0) * 255), (int)(((double)color.c1) * 255), (int)(((double)color.c2) * 255)));
+ }
+
+ public static Tuple3 colorDescriptorAsTuple3(ColorDescriptor descriptor) {
+ Color color = ((ColorDescriptor)descriptor).createColor(Display.getDefault());
+ return new Tuple3(color.getRed(), color.getGreen(), color.getBlue());
+ }
+
+ public synchronized static String colorDescriptorAsHex(ColorDescriptor descriptor) {
+ Color color = ((ColorDescriptor)descriptor).createColor(Display.getDefault());
+ return String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue());
+ }
+}
--- /dev/null
+package org.simantics.modeling.adapters;
+
+import org.simantics.browsing.ui.content.LabelDecorator;
+import org.simantics.browsing.ui.model.labeldecorators.AbstractLabelDecorator;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.modeling.ModelingResources;
+
+public class SCLLabelBackgroundColorRule extends SCLLabelColorRule {
+
+ public SCLLabelBackgroundColorRule(ReadGraph graph, Resource rule) {
+ super(graph, rule, ModelingResources.getInstance(graph).SCLLabelBackgroundColorRule_getColor);
+ }
+
+ @Override
+ public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {
+ return new AbstractLabelDecorator() {
+
+ @Override
+ public <Color> Color decorateBackground(Color color, String column, int itemIndex) {
+ return decorateColor(graph, content, color, column, itemIndex);
+ }
+ };
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.simantics.modeling.adapters;
+
+import org.eclipse.jface.resource.ColorDescriptor;
+import org.eclipse.swt.graphics.RGB;
+import org.simantics.Simantics;
+import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.variable.Variable;
+import org.simantics.db.layer0.variable.Variables;
+import org.simantics.modeling.ColorDescriptorUtil;
+import org.simantics.scl.runtime.function.Function;
+import org.simantics.scl.runtime.tuple.Tuple3;
+
+public abstract class SCLLabelColorRule implements LabelDecorationRule {
+
+ private Resource rule;
+ private Resource predicate;
+
+ public SCLLabelColorRule(ReadGraph graph, Resource rule, Resource predicate) {
+ this.rule = rule;
+ this.predicate = predicate;
+ }
+
+ @Override
+ public boolean isCompatible(Class<?> contentType) {
+ return contentType.equals(Resource.class);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected <Color> Color decorateColor(ReadGraph graph, Object content, Color color, String column, int itemIndex) {
+ try {
+ Variable ruleVariable = Variables.getVariable(graph, rule);
+ Function fn = ruleVariable.getPossiblePropertyValue(graph, predicate);
+ if (fn != null) {
+ Tuple3 prevColor = color != null ? ColorDescriptorUtil.colorDescriptorAsTuple3((ColorDescriptor)color) : null;
+ Tuple3 result = Simantics.applySCLRead(graph, fn, content, prevColor, column, itemIndex);
+ int r = (int)(((double)result.c0) * 255);
+ int g = (int)(((double)result.c1) * 255);
+ int b = (int)(((double)result.c2) * 255);
+ return (Color)ColorDescriptor.createFrom(new RGB(r, g, b));
+ } else {
+ return color;
+ }
+ } catch (DatabaseException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.simantics.modeling.adapters;
+
+import org.simantics.browsing.ui.content.LabelDecorator;
+import org.simantics.browsing.ui.model.labeldecorators.AbstractLabelDecorator;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.modeling.ModelingResources;
+
+public class SCLLabelForegroundColorRule extends SCLLabelColorRule {
+
+ public SCLLabelForegroundColorRule(ReadGraph graph, Resource rule) {
+ super(graph, rule, ModelingResources.getInstance(graph).SCLLabelForegroundColorRule_getColor);
+ }
+
+ @Override
+ public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException {
+ return new AbstractLabelDecorator() {
+
+ @Override
+ public <Color> Color decorateForeground(Color color, String column, int itemIndex) {
+ return decorateColor(graph, content, color, column, itemIndex);
+ }
+ };
+ }
+}
\ No newline at end of file