]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/utils/variable/DynamicDouble.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / utils / variable / DynamicDouble.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.scenegraph.utils.variable;\r
13 \r
14 /**\r
15  * A container for a single dynamic-enabled double variable of a scene graph\r
16  * node. Dynamic-enabled means a variable that potentially has two values: one\r
17  * static (~ default) and one dynamic. If the dynamic part has a non-null value\r
18  * it should always be used instead of the static value. Use\r
19  * {@link #getActiveValue()} to get the current variable value to follow this\r
20  * policy in your client code.\r
21  * \r
22  * <p>\r
23  * Variables generally determine the way a node gets rendered.\r
24  * \r
25  * @author Tuukka Lehtonen\r
26  */\r
27 public class DynamicDouble extends DynamicVariable<Double> {\r
28 \r
29     private double value;\r
30 \r
31     public static DynamicDouble make(double initialValue) {\r
32         return new DynamicDouble(initialValue);\r
33     }\r
34 \r
35     public DynamicDouble(double initialValue) {\r
36         this.value = initialValue;\r
37     }\r
38 \r
39     public double getValue() {\r
40         return value;\r
41     }\r
42 \r
43     public double getActiveValue() {\r
44         return dynamicValue != null ? dynamicValue : value;\r
45     }\r
46 \r
47     /**\r
48      * Sets the static value of the variable.\r
49      * \r
50      * @param value new static value\r
51      */\r
52     public void setValue(double value) {\r
53         this.value = value;\r
54     }\r
55 \r
56     public boolean hasDynamicValue() {\r
57         return dynamicValue != null && getValue() != getActiveValue();\r
58     }\r
59 \r
60 }\r