KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 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  * David Pickens - [Memory View] Endian in hex view and ASCII view doesn't work
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.ui.IDebugUIConstants;
19
20 /**
21  * @since 3.3
22  */

23 public class HexIntegerRendering extends AbstractIntegerRendering {
24     
25     public HexIntegerRendering(String JavaDoc renderingId)
26     {
27         super(renderingId);
28     }
29
30     /* (non-Javadoc)
31      * @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)
32      */

33     public String JavaDoc getString(String JavaDoc dataType, BigInteger JavaDoc address,
34             MemoryByte[] data) {
35         StringBuffer JavaDoc strBuffer = new StringBuffer JavaDoc();
36         int endianess = getEndianness(data);
37
38         String JavaDoc 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 JavaDoc(RenderingsUtil.convertByteToCharArray(data[i].getValue())));
53             }
54             else
55             {
56                 // pad with padded string
57
strBuffer.append(paddedStr);
58             }
59         }
60         
61         return strBuffer.toString().toUpperCase();
62     }
63
64     /**
65      * @todo davidp needs to add a method comment.
66      * @param data
67      * @return
68      */

69     private int getEndianness (MemoryByte[] data) {
70         // if the user has not set an endianess to the rendering
71
// take default
72
int endianess = getDisplayEndianess();
73         if (endianess == RenderingsUtil.ENDIANESS_UNKNOWN)
74             endianess = getBytesEndianess(data);
75         return endianess;
76     }
77
78     /* (non-Javadoc)
79      * @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)
80      */

81     public byte[] getBytes(String JavaDoc dataType, BigInteger JavaDoc address,
82             MemoryByte[] currentValues, String JavaDoc 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