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 java.util.Arrays;
16 public class DoubleArrayPropertyManipulator implements PropertyManipulator {
18 ValueProvider provider;
22 double[] editValue = null;
24 public DoubleArrayPropertyManipulator(ValueProvider provider, Object input) {
25 this.provider = provider;
30 public int getValueCount() {
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 return Arrays.toString(editValue);
53 double[] val = getValue();
54 if (val == null) return null;
55 return Arrays.toString(val);
56 } catch (Exception e) {
62 public String setValue(String value, int i) {
65 if (value.startsWith("[") && value.endsWith("]")) {
66 value = value.substring(1,value.length()-1);
67 String vals[] = value.split(",");
68 double val[] = new double[vals.length];
69 for (int j = 0; j < vals.length; j++) {
70 val[j] = Double.parseDouble(vals[j]);
72 provider.setValue(input, val);
74 return "Input must be values between [] characters separated with ,";
77 } catch (Exception e) {
78 return e.getMessage();
84 public boolean getEditMode() {
89 public void setEditMode(boolean b) {
93 editValue = getValue();
94 } catch (Exception e) {