]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/utils/variable/DynamicObject.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / utils / variable / DynamicObject.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in 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.scenegraph.utils.variable;
13
14 /**
15  * A container for a single dynamic-enabled float variable of a scene graph
16  * node. Dynamic-enabled means a variable that potentially has two values: one
17  * static (~ default) and one dynamic. If the dynamic part has a non-null value
18  * it should always be used instead of the static value. Use
19  * {@link #getActiveValue()} to get the current variable value to follow this
20  * policy in your client code.
21  * 
22  * <p>
23  * Variables generally determine the way a node gets rendered.
24  * 
25  * @author Tuukka Lehtonen
26  */
27 public class DynamicObject<T> extends DynamicVariable<T> {
28
29     private T value;
30
31     public static <T> DynamicObject<T> make(T initialValue) {
32         return new DynamicObject<T>(initialValue);
33     }
34
35     public DynamicObject(T initialValue) {
36         this.value = initialValue;
37     }
38
39     public T getValue() {
40         return value;
41     }
42
43     public T getActiveValue() {
44         return dynamicValue != null ? dynamicValue : value;
45     }
46
47     /**
48      * Sets the static value of the variable.
49      * 
50      * @param value new static value
51      */
52     public void setValue(T value) {
53         this.value = value;
54     }
55
56     public boolean hasDynamicValue() {
57         return dynamicValue != null && getValue() != getActiveValue();
58     }
59
60 }