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 import com.android.ide.eclipse.gltrace.GLEnum; 20 21 /** Properties that hold a {@link GLEnum}. */ 22 public final class GLEnumProperty extends GLAbstractAtomicProperty { 23 private GLEnum mCurrentValue; 24 private final GLEnum mDefaultValue; 25 26 public GLEnumProperty(GLStateType name, GLEnum defaultValue) { 27 super(name); 28 29 mCurrentValue = mDefaultValue = defaultValue; 30 } 31 32 @Override 33 public boolean isDefault() { 34 return mDefaultValue == mCurrentValue; 35 } 36 37 public void setValue(GLEnum newValue) { 38 mCurrentValue = newValue; 39 } 40 41 @Override 42 public String getStringValue() { 43 return mCurrentValue.toString(); 44 } 45 46 @Override 47 public String toString() { 48 return getType() + "=" + getStringValue(); //$NON-NLS-1$ 49 } 50 51 @Override 52 public void setValue(Object value) { 53 if (value instanceof GLEnum) { 54 mCurrentValue = (GLEnum) value; 55 } else { 56 throw new IllegalArgumentException("Attempt to set invalid value for " + getType()); //$NON-NLS-1$ 57 } 58 } 59 60 @Override 61 public Object getValue() { 62 return mCurrentValue; 63 } 64 } 65