Home | History | Annotate | Download | only in state
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.ide.eclipse.gltrace.state;
     18 
     19 /** Properties that hold float values. */
     20 public class GLFloatProperty extends GLAbstractAtomicProperty {
     21     private final Float mDefaultValue;
     22     private Float mCurrentValue;
     23 
     24     public GLFloatProperty(GLStateType name, Float defaultValue) {
     25         super(name);
     26 
     27         mDefaultValue = mCurrentValue = defaultValue;
     28     }
     29 
     30     @Override
     31     public boolean isDefault() {
     32         return Math.abs(mCurrentValue - mDefaultValue) < 0.000000001;
     33     }
     34 
     35     public void setValue(Float newValue) {
     36         mCurrentValue = newValue;
     37     }
     38 
     39     @Override
     40     public void setValue(Object value) {
     41         if (value instanceof Float) {
     42             mCurrentValue = (Float) value;
     43         } else {
     44             throw new IllegalArgumentException("Attempt to set non float value for "
     45                     + getType());
     46         }
     47     }
     48 
     49     @Override
     50     public Object getValue() {
     51         return mCurrentValue;
     52     }
     53 
     54     @Override
     55     public String getStringValue() {
     56         return mCurrentValue.toString();
     57     }
     58 
     59     @Override
     60     public String toString() {
     61         return getType() + "=" + getStringValue(); //$NON-NLS-1$
     62     }
     63 }
     64