1 11 12 package org.eclipse.debug.internal.ui.views.memory.renderings; 13 14 import java.math.BigInteger ; 15 16 import org.eclipse.debug.core.model.MemoryByte; 17 import org.eclipse.debug.ui.memory.AbstractTableRendering; 18 import org.eclipse.debug.ui.memory.MemoryRenderingElement; 19 import org.eclipse.jface.viewers.IColorProvider; 20 import org.eclipse.jface.viewers.IFontProvider; 21 import org.eclipse.jface.viewers.ILabelProvider; 22 import org.eclipse.jface.viewers.ITableColorProvider; 23 import org.eclipse.jface.viewers.ITableFontProvider; 24 import org.eclipse.swt.graphics.Color; 25 import org.eclipse.swt.graphics.Font; 26 import org.eclipse.swt.graphics.Image; 27 28 34 public class TableRenderingLabelProviderEx extends TableRenderingLabelProvider implements ITableColorProvider, ITableFontProvider { 35 36 private IFontProvider fFontProvider; 37 private ILabelProvider fLabelProvider; 38 private IColorProvider fColorProvider; 39 40 public TableRenderingLabelProviderEx(AbstractTableRendering rendering) { 41 super(rendering); 42 fLabelProvider = (ILabelProvider) rendering.getAdapter(ILabelProvider.class); 43 fColorProvider = (IColorProvider) rendering.getAdapter(IColorProvider.class); 44 fFontProvider = (IFontProvider) rendering.getAdapter(IFontProvider.class); 45 } 46 47 52 public void dispose() { 53 if (fFontProvider != null) { 54 fFontProvider = null; 55 } 56 if (fColorProvider != null) { 57 fColorProvider = null; 58 } 59 if (fLabelProvider != null) { 60 fLabelProvider.dispose(); 61 fLabelProvider = null; 62 } 63 super.dispose(); 64 } 65 66 69 public Color getBackground(Object element, int columnIndex) { 70 if (fColorProvider != null && columnIndex > 0) { 71 MemoryRenderingElement renderingElement = getMemoryRenderingElement(element, columnIndex); 72 if (renderingElement != null) { 73 Color color = fColorProvider.getBackground(renderingElement); 74 if (color != null) 75 return color; 76 } 77 } 78 return super.getBackground(element); 79 } 80 81 84 public Color getForeground(Object element, int columnIndex) { 85 if (fColorProvider != null && columnIndex > 0) { 86 MemoryRenderingElement renderingElement = getMemoryRenderingElement(element, columnIndex); 87 if (renderingElement != null) { 88 Color color = fColorProvider.getForeground(renderingElement); 89 if (color != null) 90 return color; 91 } 92 } 93 return super.getForeground(element); 94 } 95 96 99 public Image getColumnImage(Object element, int columnIndex) { 100 if (fLabelProvider != null && columnIndex > 0) { 101 MemoryRenderingElement renderingElement = getMemoryRenderingElement(element, columnIndex); 102 if (renderingElement != null) { 103 Image image = fLabelProvider.getImage(renderingElement); 104 if (image != null) 105 return image; 106 } 107 } 108 return super.getColumnImage(element, columnIndex); 109 } 110 111 114 public Font getFont(Object element, int columnIndex) { 115 if (fFontProvider != null && columnIndex > 0) { 116 MemoryRenderingElement renderingElement = getMemoryRenderingElement(element, columnIndex); 117 if (renderingElement != null) { 118 Font font = fFontProvider.getFont(renderingElement); 119 if (font != null) 120 return font; 121 } 122 } 123 return null; 124 } 125 126 134 private MemoryRenderingElement getMemoryRenderingElement(Object element, int columnIndex) { 135 if (element instanceof TableRenderingLine) { 136 TableRenderingLine line = (TableRenderingLine) element; 137 BigInteger lineAddress = new BigInteger (line.getAddress(), 16); 138 int offset = (columnIndex - 1) * fRendering.getBytesPerColumn(); 139 if (offset < fRendering.getBytesPerLine() && (offset + fRendering.getBytesPerColumn()) <= fRendering.getBytesPerLine()) { 140 return getMemoryRenderingElement(line, lineAddress, offset); 141 } 142 } 143 return null; 144 } 145 146 private MemoryRenderingElement getMemoryRenderingElement(TableRenderingLine line, BigInteger lineAddress, int offset) { 147 BigInteger cellAddress = lineAddress.add(BigInteger.valueOf(offset)); 148 MemoryByte[] bytes = line.getBytes(offset, offset 149 + fRendering.getBytesPerColumn()); 150 MemoryByte[] copy = new MemoryByte[bytes.length]; 153 System.arraycopy(bytes, 0, copy, 0, bytes.length); 154 MemoryRenderingElement renderingElement = new MemoryRenderingElement( 155 fRendering, cellAddress, copy); 156 return renderingElement; 157 } 158 } 159 | Popular Tags |