KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 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  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.views.memory.renderings;
12
13 import java.math.BigInteger JavaDoc;
14
15 import org.eclipse.debug.core.model.MemoryByte;
16 import org.eclipse.debug.internal.ui.memory.provisional.AbstractAsyncTextRendering;
17 import org.eclipse.debug.ui.DebugUITools;
18 import org.eclipse.debug.ui.IDebugUIConstants;
19 import org.eclipse.jface.util.PropertyChangeEvent;
20
21
22
23
24 /**
25  * Convert bytes into ASCII string and vice versa
26  * @since 3.1
27  */

28 public class ASCIIRendering extends AbstractAsyncTextRendering{
29     
30     private final int numCharsPerByte = 1;
31     
32
33     public ASCIIRendering(String JavaDoc renderingId)
34     {
35         super(renderingId);
36         String JavaDoc codepage = DebugUITools.getPreferenceStore().getString(IDebugUIConstants.PREF_DEFAULT_ASCII_CODE_PAGE);
37         setCodePage(codepage);
38     }
39     
40     public void dispose() {
41         super.dispose();
42     }
43     
44     /* (non-Javadoc)
45      * @see org.eclipse.debug.ui.memory.AbstractMemoryRendering#getNumCharsPerByte()
46      */

47     public int getNumCharsPerByte() {
48         return numCharsPerByte;
49     }
50     
51
52     /* (non-Javadoc)
53      * @see org.eclipse.debug.ui.memory.AbstractTableRendering#getBytes(java.lang.String, java.math.BigInteger, org.eclipse.debug.core.model.MemoryByte[], java.lang.String)
54      */

55     public byte[] getBytes(
56         String JavaDoc renderingId,
57         BigInteger JavaDoc address,
58         MemoryByte[] currentValues,
59         String JavaDoc data) {
60         
61         byte[] bytes = super.getBytes(renderingId, address, currentValues, data);
62         
63         // undo the replacement of 1's to 0's.
64
for (int i=0; i<bytes.length && i < currentValues.length; i++)
65         {
66             if (bytes[i] == 1 && currentValues[i].getValue() == 0)
67             {
68                 bytes[i] = 0;
69             }
70         }
71         
72         return bytes;
73         
74     }
75
76     /* (non-Javadoc)
77      * @see org.eclipse.debug.ui.memory.AbstractTableRendering#getString(java.lang.String, java.math.BigInteger, org.eclipse.debug.core.model.MemoryByte[])
78      */

79     public String JavaDoc getString(
80         String JavaDoc renderingId,
81         BigInteger JavaDoc address,
82         MemoryByte[] data) {
83         
84         MemoryByte[] copy = new MemoryByte[data.length];
85
86         // If a byte equals zero, it represents null in a string
87
// and often causes subsequent string not displayed or printed properly
88
// Replace all null with 1's
89
for (int i=0; i<data.length; i++){
90             copy[i] = new MemoryByte();
91             if (data[i].getValue() == 0)
92             {
93                 copy[i].setValue((byte)1);
94             }
95             else
96             {
97                 copy[i].setValue(data[i].getValue());
98             }
99             copy[i].setFlags(data[i].getFlags());
100         }
101         
102         return super.getString(renderingId, address, copy);
103     }
104
105     /* (non-Javadoc)
106      * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
107      */

108     public void propertyChange(PropertyChangeEvent event) {
109         
110         // handle code page changed event
111
if (event.getProperty().equals(IDebugUIConstants.PREF_DEFAULT_ASCII_CODE_PAGE))
112         {
113             String JavaDoc codePage = (String JavaDoc)event.getNewValue();
114             setCodePage(codePage);
115             
116             if (isVisible())
117                 // just update labels, don't need to reget memory
118
updateLabels();
119         }
120         
121         super.propertyChange(event);
122     }
123 }
124
Popular Tags