1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g3d.property;
14 import org.simantics.g3d.math.MathTools;
16 public class DoubleArrayPropertyManipulator2 implements PropertyManipulator {
18 ValueProvider provider;
22 double[] editValue = null;
24 public DoubleArrayPropertyManipulator2(ValueProvider provider, Object input) {
25 this.provider = provider;
30 public int getValueCount() {
31 return getValue().length+1;
35 public String getDescription(int i) {
39 private double[] getValue() {
41 return (double[])provider.getValue(input);
42 } catch (Exception e) {
48 public String getValue(int i) {
50 if (i < editValue.length)
51 return Double.toString(editValue[i]);
55 double[] val = getValue();
62 return Double.toString(MathTools.round(val[i], 10));
63 } catch (Exception e) {
69 public String setValue(String value, int i) {
71 double[] val = editValue;
72 if (value.length() == 0 && i == val.length -1) {
73 double[] newVal = new double[val.length-1];
74 System.arraycopy(val, 0, newVal, 0, val.length-1);
76 } else if (i < val.length)
77 val[i] = Double.parseDouble(value);
78 else if (i == val.length) {
79 double[] newVal = new double[val.length+1];
80 System.arraycopy(val, 0, newVal, 0, val.length);
83 provider.setValue(input, val);
84 } catch (Exception e) {
85 return e.getMessage();
91 public boolean getEditMode() {
96 public void setEditMode(boolean b) {
100 editValue = getValue();
101 } catch (Exception e) {