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();
60 return Double.toString(val[i]);
61 } catch (Exception e) {
67 public String setValue(String value, int i) {
69 double[] val = editValue;
70 if (value.length() == 0 && i == val.length -1) {
71 double[] newVal = new double[val.length-1];
72 System.arraycopy(val, 0, newVal, 0, val.length-1);
74 } else if (i < val.length)
75 val[i] = Double.parseDouble(value);
76 else if (i == val.length) {
77 double[] newVal = new double[val.length+1];
78 System.arraycopy(val, 0, newVal, 0, val.length);
81 provider.setValue(input, val);
82 } catch (Exception e) {
83 return e.getMessage();
89 public boolean getEditMode() {
94 public void setEditMode(boolean b) {
98 editValue = getValue();
99 } catch (Exception e) {