KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.debug.core.model.IMemoryBlock;
14 import org.eclipse.debug.core.model.IMemoryBlockExtension;
15 import org.eclipse.debug.core.model.MemoryByte;
16 import org.eclipse.debug.internal.ui.memory.provisional.AbstractAsyncTableRendering;
17 import org.eclipse.debug.ui.memory.IMemoryRenderingContainer;
18
19 /**
20  * Abstract implementation to an integer rendering.
21  * @since 3.1
22  *
23  */

24 public abstract class AbstractIntegerRendering extends AbstractAsyncTableRendering {
25     
26     private int fDisplayEndianess = RenderingsUtil.ENDIANESS_UNKNOWN;
27     
28     public AbstractIntegerRendering(String JavaDoc renderingId){
29         super(renderingId);
30     }
31     
32     public void init(IMemoryRenderingContainer container, IMemoryBlock block) {
33         super.init(container, block);
34         
35         // default to big endian for simple memory block
36
if (!(block instanceof IMemoryBlockExtension))
37             fDisplayEndianess = RenderingsUtil.BIG_ENDIAN;
38     }
39     
40     /**
41      * @return Returns the currentEndianess.
42      */

43     public int getDisplayEndianess() {
44         return fDisplayEndianess;
45     }
46
47     /**
48      * @param currentEndianess The currentEndianess to set.
49      */

50     public void setDisplayEndianess(int currentEndianess) {
51         fDisplayEndianess = currentEndianess;
52     }
53
54     protected int getBytesEndianess(MemoryByte[] data) {
55         int endianess = RenderingsUtil.ENDIANESS_UNKNOWN;
56         
57         if (!data[0].isEndianessKnown())
58             return endianess;
59         
60         if (data[0].isBigEndian())
61             endianess = RenderingsUtil.BIG_ENDIAN;
62         else
63             endianess = RenderingsUtil.LITTLE_ENDIAN;
64         for (int i=1; i<data.length; i++)
65         {
66             // if endianess is not known for a byte, return unknown
67
if (!data[i].isEndianessKnown())
68                 return RenderingsUtil.ENDIANESS_UNKNOWN;
69             
70             int byteEndianess = data[i].isBigEndian()?RenderingsUtil.BIG_ENDIAN:RenderingsUtil.LITTLE_ENDIAN;
71             if (byteEndianess != endianess)
72             {
73                 endianess = RenderingsUtil.ENDIANESS_UNKNOWN;
74                 break;
75             }
76         }
77         return endianess;
78     }
79 }
80
Popular Tags