X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fproperty%2FVectorPropertyManipulator.java;h=e0a8021925ff87635da054ced8170e9c71926a13;hb=01441002a94a1f4ad2b078d63cb719ce617bd6cf;hp=7a8df5e1ce83648ad759e1007c8e5984bae53abd;hpb=c666bd50b9ef05b6f78adb83c68557955e3132e9;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 index 7a8df5e1..e0a80219 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/property/VectorPropertyManipulator.java +++ b/org.simantics.g3d/src/org/simantics/g3d/property/VectorPropertyManipulator.java @@ -1,114 +1,111 @@ -/******************************************************************************* - * Copyright (c) 2012, 2013 Association for Decentralized Information Management in - * Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -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) { - - } - } - - } - -} +/******************************************************************************* + * Copyright (c) 2012, 2013 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.g3d.property; + +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) { + + } + } + + } + +}