]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d/src/org/simantics/g3d/property/DoublePropertyManipulator.java
Force zero offset for concentric reducers
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / g3d / property / DoublePropertyManipulator.java
1 /*******************************************************************************
2  * Copyright (c) 2012, 2013 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g3d.property;
13
14 public class DoublePropertyManipulator implements PropertyManipulator {
15         
16         ValueProvider provider;
17         Object input;
18         
19         boolean editMode;
20         String editValue = null;
21         
22         public DoublePropertyManipulator(ValueProvider provider, Object input) {
23                 this.provider = provider;
24                 this.input = input;
25         }
26         
27         @Override
28         public int getValueCount() {
29                 return 1;
30         }
31         
32         @Override
33         public String getDescription(int i) {
34                 if (i == 0)
35                         return "Value";
36                 return null;
37         }
38         
39         @Override
40         public String getValue(int i) {
41                 if (editMode)
42                         return editValue;
43                 try {
44                         Object value = provider.getValue(input);
45                         if (value == null) return null;
46                         return value.toString();
47                 } catch (Exception e) {
48                         return null;
49                 }
50         }
51         
52         @Override
53         public String setValue(String value, int i) {
54                 try {
55                         editValue = value;
56                         provider.setValue(input, Double.parseDouble(value));
57                 } catch (Exception e) {
58                         return e.getMessage();
59                 }
60                 return null;
61         }
62
63         @Override
64         public boolean getEditMode() {
65                 return editMode;
66         }
67         
68         @Override
69         public void setEditMode(boolean b) {
70                 editMode = b;
71                 if (editMode) {
72                         try {
73                                 editValue = provider.getValue(input).toString();
74                         } catch (Exception e) {
75                                 
76                         }
77                 }
78                 
79         }
80 }