KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > memory > renderings > HexRendering


1 /*******************************************************************************
2  * Copyright (c) 2004, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * Ken Dyck - Bug 90154: [Memory View] Short Input Rejected by Hex Rendering
11  *******************************************************************************/

12 package org.eclipse.debug.internal.ui.views.memory.renderings;
13
14 import java.math.BigInteger JavaDoc;
15
16 import org.eclipse.debug.core.model.MemoryByte;
17 import org.eclipse.debug.internal.ui.DebugUIPlugin;
18 import org.eclipse.debug.internal.ui.memory.provisional.AbstractAsyncTableRendering;
19 import org.eclipse.debug.ui.IDebugUIConstants;
20
21 /**
22  * @since 3.1
23  */

24 public class HexRendering extends AbstractAsyncTableRendering {
25     
26     public HexRendering(String JavaDoc renderingId)
27     {
28         super(renderingId);
29     }
30
31     /* (non-Javadoc)
32      * @see org.eclipse.debug.internal.ui.views.memory.AbstractTableRendering#getString(java.lang.String, java.math.BigInteger, org.eclipse.debug.core.model.MemoryByte[], java.lang.String)
33      */

34     public String JavaDoc getString(String JavaDoc dataType, BigInteger JavaDoc address,
35             MemoryByte[] data) {
36         StringBuffer JavaDoc strBuffer = new StringBuffer JavaDoc();
37
38         String JavaDoc paddedStr = DebugUIPlugin.getDefault().getPreferenceStore().getString(IDebugUIConstants.PREF_PADDED_STR);
39         
40         for (int i=0; i<data.length; i++)
41         {
42             if (data[i].isReadable())
43             {
44                 strBuffer.append(new String JavaDoc(RenderingsUtil.convertByteToCharArray(data[i].getValue())));
45             }
46             else
47             {
48                 // pad with padded string
49
strBuffer.append(paddedStr);
50             }
51         }
52         
53         return strBuffer.toString().toUpperCase();
54     }
55
56     /* (non-Javadoc)
57      * @see org.eclipse.debug.internal.ui.views.memory.AbstractTableRendering#getBytes(java.lang.String, java.math.BigInteger, org.eclipse.debug.core.model.MemoryByte[], java.lang.String)
58      */

59     public byte[] getBytes(String JavaDoc dataType, BigInteger JavaDoc address,
60             MemoryByte[] currentValues, String JavaDoc data) {
61         byte[] bytes = RenderingsUtil.convertHexStringToByteArray(data, currentValues.length, getNumCharsPerByte());
62         
63         return bytes;
64     }
65     
66     public int getNumCharsPerByte()
67     {
68         return 2;
69     }
70     
71 }
72
Popular Tags