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.editors; 18 19 import com.android.ide.eclipse.gltrace.state.GLListProperty; 20 import com.android.ide.eclipse.gltrace.state.GLSparseArrayProperty; 21 import com.android.ide.eclipse.gltrace.state.GLStateType; 22 import com.android.ide.eclipse.gltrace.state.IGLProperty; 23 24 import org.eclipse.jface.viewers.ColumnLabelProvider; 25 import org.eclipse.jface.viewers.ViewerCell; 26 import org.eclipse.swt.SWT; 27 import org.eclipse.swt.graphics.Color; 28 import org.eclipse.swt.widgets.Display; 29 30 import java.util.Set; 31 32 public class StateLabelProvider extends ColumnLabelProvider { 33 private Set<IGLProperty> mChangedProperties; 34 35 private Color mHighlightForegroundColor; 36 private Color mNormalForegroundColor; 37 38 public StateLabelProvider() { 39 mHighlightForegroundColor = Display.getDefault().getSystemColor(SWT.COLOR_BLUE); 40 mNormalForegroundColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); 41 } 42 43 public String getColumnText(IGLProperty property, int columnIndex) { 44 switch (columnIndex) { 45 case 0: 46 return getName(property); 47 case 1: 48 return getValue(property); 49 default: 50 return ""; 51 } 52 } 53 54 private String getValue(IGLProperty element) { 55 return element.getStringValue(); 56 } 57 58 private String getName(IGLProperty element) { 59 IGLProperty parent = element.getParent(); 60 if (parent instanceof GLListProperty) { 61 // For members of list, use the index in the list as the name as opposed to 62 // the property type 63 int index = ((GLListProperty) parent).indexOf(element); 64 if (element.getType() == GLStateType.GL_STATE_ES1) { 65 return String.format("Context %d (ES1)", index); 66 } else if (element.getType() == GLStateType.GL_STATE_ES2) { 67 return String.format("Context %d (ES2)", index); 68 } else { 69 return Integer.toString(index); 70 } 71 } else if (parent instanceof GLSparseArrayProperty) { 72 // For members of sparse array, use the key as the name as opposed to 73 // the property type 74 int index = ((GLSparseArrayProperty) parent).keyFor(element); 75 return Integer.toString(index); 76 } 77 78 return element.getType().getDescription(); 79 } 80 81 @Override 82 public void update(ViewerCell cell) { 83 Object element = cell.getElement(); 84 if (!(element instanceof IGLProperty)) { 85 return; 86 } 87 88 IGLProperty prop = (IGLProperty) element; 89 90 String text = getColumnText(prop, cell.getColumnIndex()); 91 cell.setText(text); 92 93 if (mChangedProperties != null && mChangedProperties.contains(prop)) { 94 cell.setForeground(mHighlightForegroundColor); 95 } else { 96 cell.setForeground(mNormalForegroundColor); 97 } 98 } 99 100 public void setChangedProperties(Set<IGLProperty> changedProperties) { 101 mChangedProperties = changedProperties; 102 } 103 } 104