1 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.internal.ui.DebugUIPlugin; 18 import org.eclipse.debug.ui.IDebugUIConstants; 19 20 23 public class HexIntegerRendering extends AbstractIntegerRendering { 24 25 public HexIntegerRendering(String renderingId) 26 { 27 super(renderingId); 28 } 29 30 33 public String getString(String dataType, BigInteger address, 34 MemoryByte[] data) { 35 StringBuffer strBuffer = new StringBuffer (); 36 int endianess = getEndianness(data); 37 38 String paddedStr = DebugUIPlugin.getDefault().getPreferenceStore().getString(IDebugUIConstants.PREF_PADDED_STR); 39 40 if (endianess == RenderingsUtil.LITTLE_ENDIAN) { 41 MemoryByte[] swapped = new MemoryByte[data.length]; 42 for (int i = 0; i < data.length; i++){ 43 swapped[data.length-i-1] = data[i]; 44 } 45 data = swapped; 46 } 47 48 for (int i=0; i<data.length; i++) 49 { 50 if (data[i].isReadable()) 51 { 52 strBuffer.append(new String (RenderingsUtil.convertByteToCharArray(data[i].getValue()))); 53 } 54 else 55 { 56 strBuffer.append(paddedStr); 58 } 59 } 60 61 return strBuffer.toString().toUpperCase(); 62 } 63 64 69 private int getEndianness (MemoryByte[] data) { 70 int endianess = getDisplayEndianess(); 73 if (endianess == RenderingsUtil.ENDIANESS_UNKNOWN) 74 endianess = getBytesEndianess(data); 75 return endianess; 76 } 77 78 81 public byte[] getBytes(String dataType, BigInteger address, 82 MemoryByte[] currentValues, String data) { 83 84 int endianess = getEndianness(currentValues); 85 byte[] bytes = RenderingsUtil.convertHexStringToByteArray(data, currentValues.length, getNumCharsPerByte()); 86 87 88 if (endianess == RenderingsUtil.LITTLE_ENDIAN) { 89 byte[] swapped = new byte[bytes.length]; 90 for (int i = 0; i < bytes.length; i++){ 91 swapped[bytes.length-i-1] = bytes[i]; 92 } 93 bytes = swapped; 94 } 95 96 return bytes; 97 } 98 99 public int getNumCharsPerByte() 100 { 101 return 2; 102 } 103 104 105 } 106 | Popular Tags |