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 public class DoubleArrayPropertyManipulator2 implements PropertyManipulator {
16 ValueProvider provider;
20 double[] editValue = null;
22 public DoubleArrayPropertyManipulator2(ValueProvider provider, Object input) {
23 this.provider = provider;
28 public int getValueCount() {
29 return getValue().length+1;
33 public String getDescription(int i) {
37 private double[] getValue() {
39 return (double[])provider.getValue(input);
40 } catch (Exception e) {
46 public String getValue(int i) {
48 if (i < editValue.length)
49 return Double.toString(editValue[i]);
53 double[] val = getValue();
58 return Double.toString(val[i]);
59 } catch (Exception e) {
65 public String setValue(String value, int i) {
67 double[] val = editValue;
68 if (value.length() == 0 && i == val.length -1) {
69 double[] newVal = new double[val.length-1];
70 System.arraycopy(val, 0, newVal, 0, val.length-1);
72 } else if (i < val.length)
73 val[i] = Double.parseDouble(value);
74 else if (i == val.length) {
75 double[] newVal = new double[val.length+1];
76 System.arraycopy(val, 0, newVal, 0, val.length);
79 provider.setValue(input, val);
80 } catch (Exception e) {
81 return e.getMessage();
87 public boolean getEditMode() {
92 public void setEditMode(boolean b) {
96 editValue = getValue();
97 } catch (Exception e) {