X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fproperty%2FVectorPropertyManipulator.java;fp=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fproperty%2FVectorPropertyManipulator.java;h=84095edab07078641bc5fee2ee98cc496add8b76;hb=87b3241ec277ba3d8e414b26186a032c9cdcaeed;hp=0000000000000000000000000000000000000000;hpb=1f0bcd66274375f2278d2e6c486cb28257a5f7b2;p=simantics%2F3d.git diff --git a/org.simantics.g3d/src/org/simantics/g3d/property/VectorPropertyManipulator.java b/org.simantics.g3d/src/org/simantics/g3d/property/VectorPropertyManipulator.java new file mode 100644 index 00000000..84095eda --- /dev/null +++ b/org.simantics.g3d/src/org/simantics/g3d/property/VectorPropertyManipulator.java @@ -0,0 +1,103 @@ +package org.simantics.g3d.property; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import javax.vecmath.Vector3d; + +public class VectorPropertyManipulator implements PropertyManipulator { + + ValueProvider provider; + protected Object input; + + boolean editMode; + Vector3d editValue = null; + + public VectorPropertyManipulator(ValueProvider provider, Object input) { + this.provider = provider; + this.input = input; + } + + @Override + public int getValueCount() { + return 3; + } + + @Override + public String getDescription(int i) { + if (i == 0) + return "X"; + if (i == 1) + return "Y"; + if (i == 2) + return "Z"; + return null; + } + + @Override + public String getValue(int i) { + try { + Vector3d v = _getValue(); + if (v == null) + return null; + if (i == 0) + return Double.toString(v.x); + if (i == 1) + return Double.toString(v.y); + if (i == 2) + return Double.toString(v.z); + return null; + } catch (Exception e) { + return null; + } + } + + @Override + public String setValue(String value, int i) { + try { + Double d = Double.parseDouble(value); + Vector3d v = _getValue(); + v = new Vector3d(v.x, v.y, v.z); + if (i == 0) + v.x = d; + if (i == 1) + v.y = d; + if (i == 2) + v.z = d; + editValue = v; + setValue(v); + } catch (Exception e) { + return e.getMessage(); + } + return null; + } + + protected void setValue(Vector3d v) throws Exception { + provider.setValue(input, v); + } + + private Vector3d _getValue() throws Exception{ + if (editMode) + return editValue; + return (Vector3d) provider.getValue(input); + } + + @Override + public boolean getEditMode() { + return editMode; + } + + @Override + public void setEditMode(boolean b) { + editMode = b; + if (editMode) { + try { + editValue = (Vector3d) provider.getValue(input); + } catch (Exception e) { + + } + } + + } + +}