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 return Arrays.toString(val);
55 } catch (Exception e) {
61 public String setValue(String value, int i) {
64 if (value.startsWith("[") && value.endsWith("]")) {
65 value = value.substring(1,value.length()-1);
66 String vals[] = value.split(",");
67 double val[] = new double[vals.length];
68 for (int j = 0; j < vals.length; j++) {
69 val[j] = Double.parseDouble(vals[j]);
71 provider.setValue(input, val);
73 return "Input must be values between [] characters separated with ,";
76 } catch (Exception e) {
77 return e.getMessage();
83 public boolean getEditMode() {
88 public void setEditMode(boolean b) {
92 editValue = getValue();
93 } catch (Exception e) {