1 11 package org.eclipse.debug.internal.ui.views.memory.renderings; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.runtime.PlatformObject; 16 import org.eclipse.debug.core.model.MemoryByte; 17 18 21 22 public class TableRenderingLine extends PlatformObject { 23 private String fAddress; 24 private String fStrRep; 25 private MemoryByte[] fBytes; 26 private byte[] fByteArray; 27 private int fTableIndex = -1; 28 private String fPaddedString; 29 public boolean isMonitored; 30 31 public static final String P_ADDRESS = "address"; 33 private static final int numCharPerByteForHex = 2; 35 36 public TableRenderingLine(String address, MemoryByte[] bytes, int tableIndex, String paddedString) { 37 fAddress = address; 38 fBytes = bytes; 39 fTableIndex = tableIndex; 40 fPaddedString = paddedString; 41 } 42 43 public String getAddress() { 44 return fAddress; 45 } 46 47 public void setAddress(String address) { 48 fAddress = address; 49 } 50 51 public MemoryByte[] getBytes() 52 { 53 return fBytes; 54 } 55 56 public MemoryByte getByte(int offset) 57 { 58 if (fBytes == null) 59 return null; 60 61 if (offset < fBytes.length) { 62 return fBytes[offset]; 63 } 64 65 return null; 66 } 67 68 public MemoryByte[] getBytes(int start, int end) 69 { 70 ArrayList ret = new ArrayList (); 71 72 for (int i=start; i<end; i++) 73 { 74 ret.add(fBytes[i]); 75 } 76 return (MemoryByte[]) ret.toArray(new MemoryByte[ret.size()]); 77 } 78 79 public String getRawMemoryString() 80 { 81 if (fStrRep == null) 82 { 83 StringBuffer buffer = new StringBuffer (); 84 fStrRep = RenderingsUtil.convertByteArrayToHexString(getByteArray()); 85 fStrRep = fStrRep.toUpperCase(); 86 87 buffer = buffer.append(fStrRep); 88 89 String paddedString = null; 91 int bufferCounter = 0; 92 for (int i=0; i<fBytes.length; i++) 93 { 94 if (!fBytes[i].isReadable()) 96 { 97 if (paddedString == null) 98 { 99 paddedString = fPaddedString; 100 101 if (paddedString.length() > TableRenderingLine.numCharPerByteForHex) 102 paddedString = paddedString.substring(0, TableRenderingLine.numCharPerByteForHex); 103 } 104 buffer.replace(bufferCounter, bufferCounter+TableRenderingLine.numCharPerByteForHex, paddedString); 105 } 106 bufferCounter += TableRenderingLine.numCharPerByteForHex; 107 } 108 109 fStrRep = buffer.toString(); 110 } 111 112 return fStrRep; 113 } 114 115 120 public boolean isAvailable(int start, int end) { 121 boolean available = true; 122 for (int i=start; i<end; i++) 123 { 124 if (!fBytes[i].isReadable()) 125 { 126 available = false; 127 break; 128 } 129 } 130 return available; 131 } 132 133 134 public byte[] getByteArray() 135 { 136 if (fByteArray == null) 137 { 138 fByteArray = new byte[fBytes.length]; 139 for (int i=0; i<fBytes.length; i++) 140 { 141 fByteArray[i] = fBytes[i].getValue(); 142 } 143 } 144 145 return fByteArray; 146 } 147 148 public byte[] getByteArray(int start, int end) 149 { 150 byte[] ret = new byte[end-start]; 151 int j=0; 152 153 for (int i=start; i<end; i++) 154 { 155 ret[j] = fBytes[i].getValue(); 156 j++; 157 } 158 return ret; 159 } 160 161 public void markDeltas(TableRenderingLine oldData) 162 { 163 if (oldData == null) 164 return; 165 166 if (!oldData.getAddress().equals(this.getAddress())) 168 return; 169 170 if (oldData.getRawMemoryString().equals(getRawMemoryString())) 172 { 173 for (int i=0; i<fBytes.length; i++) 174 { 175 fBytes[i].setHistoryKnown(true); 177 } 178 return; 179 } 180 181 MemoryByte[] oldMemory = oldData.getBytes(); 182 183 if (oldMemory.length != fBytes.length) 184 return; 185 186 for (int i=0; i<fBytes.length; i++) 187 { 188 fBytes[i].setHistoryKnown(true); 190 191 if ((fBytes[i].getFlags() & MemoryByte.READABLE) != (oldMemory[i].getFlags() & MemoryByte.READABLE)) 192 { 193 fBytes[i].setChanged(true); 194 continue; 195 } 196 197 if (fBytes[i].isReadable() && oldMemory[i].isReadable()) 198 { 199 if (fBytes[i].getValue() != oldMemory[i].getValue()) 200 { 201 fBytes[i].setChanged(true); 202 } 203 } 204 } 205 } 206 207 public void copyDeltas(TableRenderingLine oldData) 208 { 209 if (oldData == null) 210 return; 211 212 if (!oldData.getAddress().equals(this.getAddress())) 214 return; 215 216 MemoryByte[] oldMemory = oldData.getBytes(); 218 219 if (oldMemory.length != fBytes.length) 220 return; 221 222 for (int i=0; i<fBytes.length; i++) 223 { 224 fBytes[i].setFlags(oldMemory[i].getFlags()); 225 } 226 } 227 228 public boolean isLineChanged(TableRenderingLine oldData) 229 { 230 if (oldData == null) 231 return false; 232 233 if (!oldData.getAddress().equals(this.getAddress())) 235 return false; 236 237 if (oldData.getRawMemoryString().equals(getRawMemoryString())) { 239 return false; 240 } 241 return true; 242 } 243 244 249 250 public boolean isRangeChange(int offset, int endOffset) 251 { 252 boolean allBytesKnown = true; 253 boolean allBytesUnchanged = true; 254 255 for (int i=offset; i<=endOffset; i++) 256 { 257 if (!fBytes[i].isHistoryKnown()) 258 allBytesKnown = false; 259 if (fBytes[i].isChanged()) 260 allBytesUnchanged = false; 261 } 262 263 if (allBytesKnown && !allBytesUnchanged) { 264 return true; 265 } 266 return false; 267 } 268 269 public void unmarkDeltas() 270 { 271 for (int i=0; i<fBytes.length; i++) 272 { 273 if (fBytes[i].isChanged()) 275 fBytes[i].setChanged(false); 276 } 277 } 278 279 282 public String toString() 283 { 284 StringBuffer buf = new StringBuffer (); 285 buf.append(getAddress()); 286 287 buf.append(": "); 289 buf.append(getRawMemoryString()); 290 291 return buf.toString(); 292 } 293 294 public int getTableIndex() 295 { 296 return fTableIndex; 297 } 298 299 public int getLength() 300 { 301 return fBytes.length; 302 } 303 304 } 305 306 | Popular Tags |