X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fproperty%2FDoubleArrayPropertyManipulator2.java;fp=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fproperty%2FDoubleArrayPropertyManipulator2.java;h=82e9a0622b56be02123b27d33889f85af2968236;hb=01441002a94a1f4ad2b078d63cb719ce617bd6cf;hp=0000000000000000000000000000000000000000;hpb=c666bd50b9ef05b6f78adb83c68557955e3132e9;p=simantics%2F3d.git diff --git a/org.simantics.g3d/src/org/simantics/g3d/property/DoubleArrayPropertyManipulator2.java b/org.simantics.g3d/src/org/simantics/g3d/property/DoubleArrayPropertyManipulator2.java new file mode 100644 index 00000000..82e9a062 --- /dev/null +++ b/org.simantics.g3d/src/org/simantics/g3d/property/DoubleArrayPropertyManipulator2.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * 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; + +public class DoubleArrayPropertyManipulator2 implements PropertyManipulator { + + ValueProvider provider; + Object input; + + boolean editMode; + double[] editValue = null; + + public DoubleArrayPropertyManipulator2(ValueProvider provider, Object input) { + this.provider = provider; + this.input = input; + } + + @Override + public int getValueCount() { + return getValue().length+1; + } + + @Override + public String getDescription(int i) { + return "Value " + i; + } + + private double[] getValue() { + try { + return (double[])provider.getValue(input); + } catch (Exception e) { + return new double[0]; + } + } + + @Override + public String getValue(int i) { + if (editMode) { + if (i < editValue.length) + return Double.toString(editValue[i]); + return ""; + } + try { + double[] val = getValue(); + if (val.length == i) + return "New"; + if (val.length < i) + return null; + return Double.toString(val[i]); + } catch (Exception e) { + return null; + } + } + + @Override + public String setValue(String value, int i) { + try { + double[] val = editValue; + if (value.length() == 0 && i == val.length -1) { + double[] newVal = new double[val.length-1]; + System.arraycopy(val, 0, newVal, 0, val.length-1); + val = newVal; + } else if (i < val.length) + val[i] = Double.parseDouble(value); + else if (i == val.length) { + double[] newVal = new double[val.length+1]; + System.arraycopy(val, 0, newVal, 0, val.length); + val = newVal; + } + provider.setValue(input, val); + } 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 = getValue(); + } catch (Exception e) { + + } + } + + } +}