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 import org.simantics.g3d.math.MathTools;
18 public class DoubleArrayPropertyManipulator implements PropertyManipulator {
20 ValueProvider provider;
24 double[] editValue = null;
26 public DoubleArrayPropertyManipulator(ValueProvider provider, Object input) {
27 this.provider = provider;
32 public int getValueCount() {
37 public String getDescription(int i) {
41 private double[] getValue() {
43 return (double[])provider.getValue(input);
44 } catch (Exception e) {
50 public String getValue(int i) {
52 return Arrays.toString(editValue);
55 double[] val = getValue();
56 if (val == null) return null;
57 return Double.toString(MathTools.round(val[i], 10));
58 } catch (Exception e) {
64 public String setValue(String value, int i) {
67 if (value.startsWith("[") && value.endsWith("]")) {
68 value = value.substring(1,value.length()-1);
69 String vals[] = value.split(",");
70 double val[] = new double[vals.length];
71 for (int j = 0; j < vals.length; j++) {
72 val[j] = Double.parseDouble(vals[j]);
74 provider.setValue(input, val);
76 return "Input must be values between [] characters separated with ,";
79 } catch (Exception e) {
80 return e.getMessage();
86 public boolean getEditMode() {
91 public void setEditMode(boolean b) {
95 editValue = getValue();
96 } catch (Exception e) {