X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.selection.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fselection%2Fui%2FElementSelectionTools.java;h=06622b82baa73c8125556067a0c39782f30dcb0e;hb=5618901b005fe275d5218e6c5e8243941f9a1e2f;hp=130e3f4f3550d8e98dc5b9795743dba56a6d867a;hpb=fc5581727a984b57dade7a627ac408ea5ad3f811;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/ElementSelectionTools.java b/org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/ElementSelectionTools.java index 130e3f4f..06622b82 100644 --- a/org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/ElementSelectionTools.java +++ b/org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/ElementSelectionTools.java @@ -22,6 +22,7 @@ import org.simantics.layer0.Layer0; import org.simantics.ui.selection.AnyResource; import org.simantics.ui.selection.AnyVariable; import org.simantics.ui.selection.WorkbenchSelectionContentType; +import org.simantics.utils.ui.color.Color; public class ElementSelectionTools { @@ -37,8 +38,9 @@ public class ElementSelectionTools { return (T)element; } else if (contentType instanceof AnyVariable) { + AnyVariable type = (AnyVariable) contentType; try { - return (T) Simantics.getSession().syncRequest(new ResourceRead(element) { + return (T) type.processor.syncRequest(new ResourceRead(element) { public Variable perform(ReadGraph graph) throws DatabaseException { return ElementSelector.getVariableForElement(graph, resource); } @@ -81,4 +83,19 @@ public class ElementSelectionTools { } } + public static float[] colorToLiteral(Color color) { + // BGRA float values out + return new float[] { + (float)color.getB() / 255, + (float)color.getG() / 255, + (float)color.getR() / 255, + 1.f, + }; + } + + public static Color literalToColor(float[] color) { + // BGRA float values in + return new Color((int) (color[2] * 255), (int) (color[1] * 255), (int) (color[0] * 255)); + } + }