VASmalltalk – How to change the presentation within the Inspector …

Whenever you inspect an object and its attributes you use the inspector. Within the inspector you select on the left side the object (the whole object or an attribute) you want to inspect and on the right side you see the content of that selected object.

With the enabled VAAssist tool you even get a very comfortable content view on the left side:

But for some kind of data (here a subclass of ByteArray representing the binary data of a disc iage) you may want to change the representation of the object:

and you get this very simple: just implement a method named “debugPrintOn:” on the instance side of your class.

debugPrintOn: aStream

|  start end |

aStream
  nextPutAll: '        '.
1 to: 16 do: [ :anIndex |
  aStream 
    nextPutAll: ((anIndex - 1) printPaddedWith: $0 to: 2 base: 16) ; space.
].
aStream cr.
				
1 to: self size do: [ :anIndex |
  (anIndex-1) \\ 16 = 0 
    ifTrue:[
      ((anIndex-2) > 2) ifTrue:[
        start := (((anIndex-2) // 16) * 16) + 1.
	end := start + 15.
	aStream nextPutAll: '     '.
	start to: end do: [ :anotherIndex | | value |
	  value := self at: anotherIndex.
	  value > 32 
	    ifTrue:[ aStream nextPut: (Character codePoint: value) ]
	    ifFalse:[ aStream space ]
        ]
    ]. 
  aStream 
    cr ;
    nextPutAll: ((anIndex-1) printPaddedWith: $0 to: 3 base: 16) ;
    space ; 
    space
  ].

aStream 
  nextPutAll: ((self at: anIndex) printPaddedWith: $0 to: 2 base: 16) ; s
  pace.
].

start := (((self size-2) // 16) * 16) + 1.
end := start + 15.
aStream nextPutAll: '     '.
start to: end do: [ :anotherIndex | | value |
  value := self at: anotherIndex.
  value > 32 
    ifTrue:[ aStream nextPut: (Character codePoint: value) ]
    ifFalse:[ aStream space ]
]
This entry was posted in Smalltalk and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s