X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fproperty%2FDoublePropertyManipulator.java;h=46f892f3c849b3c0171981c56965f0f6d7dcf523;hb=refs%2Fchanges%2F88%2F3688%2F2;hp=9c23332b923ce505898a42fef0ec97762f5f8fe1;hpb=289aaab900078ef56efc8779e4b15830e472149e;p=simantics%2F3d.git diff --git a/org.simantics.g3d/src/org/simantics/g3d/property/DoublePropertyManipulator.java b/org.simantics.g3d/src/org/simantics/g3d/property/DoublePropertyManipulator.java index 9c23332b..46f892f3 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/property/DoublePropertyManipulator.java +++ b/org.simantics.g3d/src/org/simantics/g3d/property/DoublePropertyManipulator.java @@ -1,80 +1,85 @@ -/******************************************************************************* - * 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.Method; - -public class DoublePropertyManipulator implements PropertyManipulator { - - ValueProvider provider; - Object input; - - boolean editMode; - String editValue = null; - - public DoublePropertyManipulator(ValueProvider provider, Object input) { - this.provider = provider; - this.input = input; - } - - @Override - public int getValueCount() { - return 1; - } - - @Override - public String getDescription(int i) { - if (i == 0) - return "Value"; - return null; - } - - @Override - public String getValue(int i) { - if (editMode) - return editValue; - try { - return provider.getValue(input).toString(); - } catch (Exception e) { - return null; - } - } - - @Override - public String setValue(String value, int i) { - try { - editValue = value; - provider.setValue(input, Double.parseDouble(value)); - } catch (Exception e) { - return e.getMessage(); - } - return null; - } - - @Override - public boolean getEditMode() { - return editMode; - } - - @Override - public void setEditMode(boolean b) { - editMode = b; - if (editMode) { - try { - editValue = provider.getValue(input).toString(); - } 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 org.simantics.g3d.math.MathTools; + +public class DoublePropertyManipulator implements PropertyManipulator { + + ValueProvider provider; + Object input; + + boolean editMode; + String editValue = null; + + public DoublePropertyManipulator(ValueProvider provider, Object input) { + this.provider = provider; + this.input = input; + } + + @Override + public int getValueCount() { + return 1; + } + + @Override + public String getDescription(int i) { + if (i == 0) + return "Value"; + return null; + } + + @Override + public String getValue(int i) { + if (editMode) + return editValue; + try { + Object value = provider.getValue(input); + if (value == null) return null; + if (value instanceof Double) + return Double.toString(MathTools.round((Double)value, 10)); + return value.toString(); + } catch (Exception e) { + return null; + } + } + + @Override + public String setValue(String value, int i) { + try { + editValue = value; + provider.setValue(input, Double.parseDouble(value)); + } catch (Exception e) { + return e.getMessage(); + } + return null; + } + + @Override + public boolean getEditMode() { + return editMode; + } + + @Override + public void setEditMode(boolean b) { + editMode = b; + if (editMode) { + try { + Object value = provider.getValue(input); + editValue = value.toString(); + } catch (Exception e) { + + } + } + + } +}