Home | History | Annotate | Download | only in state
      1 /*
      2  * Copyright (C) 2011 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 an integer value. */
     20 public class GLIntegerProperty extends GLAbstractAtomicProperty {
     21     public enum DisplayRadix { DECIMAL, HEX };
     22 
     23     private final Integer mDefaultValue;
     24     private Integer mCurrentValue;
     25     private final DisplayRadix mRadix;
     26 
     27     public GLIntegerProperty(GLStateType name, Integer defaultValue, DisplayRadix radix) {
     28         super(name);
     29 
     30         mDefaultValue = mCurrentValue = defaultValue;
     31         mRadix = radix;
     32     }
     33 
     34     public GLIntegerProperty(GLStateType name, Integer defaultValue) {
     35         this(name, defaultValue, DisplayRadix.DECIMAL);
     36     }
     37 
     38     @Override
     39     public boolean isDefault() {
     40         return mCurrentValue == mDefaultValue;
     41     }
     42 
     43     public void setValue(Integer newValue) {
     44         mCurrentValue = newValue;
     45     }
     46 
     47     @Override
     48     public String getStringValue() {
     49         if (mRadix == DisplayRadix.HEX) {
     50             return String.format("0x%08x", Integer.valueOf(mCurrentValue));
     51         }
     52 
     53         return mCurrentValue.toString();
     54     }
     55 
     56     @Override
     57     public String toString() {
     58         return getType() + "=" + getStringValue(); //$NON-NLS-1$
     59     }
     60 
     61     @Override
     62     public void setValue(Object value) {
     63         if (value instanceof Integer) {
     64             mCurrentValue = (Integer) value;
     65         } else {
     66             throw new IllegalArgumentException("Attempt to set non-integer value for " //$NON-NLS-1$
     67                                     + getType());
     68         }
     69     }
     70 
     71     @Override
     72     public Object getValue() {
     73         return mCurrentValue;
     74     }
     75 }
     76