[Newbies] [4.1] How do I use ToolBuilder to construct a three pane browser?

Hannes Hirzel hannes.hirzel at gmail.com
Tue Apr 20 09:50:35 UTC 2010


And here is the code written along the same lines for a simple
dictionary browser (the initial example).

     MyDictionaryInspector example

or

d := Dictionary new.
d at: 'green' put: 'gruen'.
d at: 'red' put: 'rot'.
d at: 'blue' put: 'blau'.
inspector := MyDictionaryInspector new dictionary: d.
ToolBuilder open: inspector label: 'MyDictionaryInspector'.



Hannes

"-------------------------------------------------------------------------------------------------------------------------"

'From Squeak4.1 of 17 April 2010 [latest update: #9956] on 20 April
2010 at 9:06:08 am'!
Model subclass: #MyDictionaryInspector
	instanceVariableNames: 'dictionary key'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'HHWorkplace2010'!
!MyDictionaryInspector commentStamp: 'hjh 4/20/2010 04:41' prior: 0!
A MyDictionaryInspector is a Model for a dictionary which has a
user-friendly view. It does not show internal things like the regular
DictionaryInspector which is as well a subclass of Model. Note: It
might have been an idea to subclass StringHolder instead of model.

more see class side example

April 2010
!


!MyDictionaryInspector methodsFor: 'toolbuilder' stamp: 'hjh 4/20/2010 04:08'!
buildWith: builder
	"self example"
	^builder build:
		(builder pluggableWindowSpec new
			model: self;
			children: {
				(builder pluggableListSpec new)
					model: self;
					list: #keysList;
					getSelected: #key;
					setSelected: #key:;
					frame: (0 at 0 corner: 0.5 at 1.0).
				(builder pluggableTextSpec new)
					model: self;
					getText: #contents;
					setText: #contents:;
					frame: (0.5 at 0 corner: 1.0 at 1.0).
			})
! !


!MyDictionaryInspector methodsFor: 'accessing' stamp: 'hjh 4/20/2010 04:21'!
contents
	key isNil ifTrue: [^''].
	^dictionary at: key! !

!MyDictionaryInspector methodsFor: 'accessing' stamp: 'hjh 4/20/2010 04:19'!
dictionary: aDictionary
	dictionary := aDictionary! !

!MyDictionaryInspector methodsFor: 'accessing' stamp: 'hjh 4/20/2010 04:10'!
key
	^ key! !

!MyDictionaryInspector methodsFor: 'accessing' stamp: 'hjh 4/20/2010 04:25'!
key: aString
	key := aString.
	self changed: #contents.! !

!MyDictionaryInspector methodsFor: 'accessing' stamp: 'hjh 4/20/2010 04:20'!
keysList
	^ dictionary keys! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

MyDictionaryInspector class
	instanceVariableNames: ''!

!MyDictionaryInspector class methodsFor: 'documentation' stamp: 'hjh
4/20/2010 04:41'!
example
"self example"
	| example |
	example := self new.
	example dictionary: self exampleDictionary.
	^ToolBuilder open: example label: 'MyDictionaryInspector - Colors'! !

!MyDictionaryInspector class methodsFor: 'documentation' stamp: 'hjh
4/20/2010 04:18'!
exampleDictionary

	| d |
	d := Dictionary new.
	d at: 'red' put: 'rot'.
	d at: 'blue' put: 'blau'.
	d at: 'green' put: 'gruen'.
	d at: 'yellow' put: 'gelb'.
	d at: 'orange' put: 'orange'.
	d at: 'brown' put: 'braun'.
	d at: 'white' put: 'weiss'.
	d at: 'black' put: 'schwarz'.
	^d! !


On 4/19/10, Hannes Hirzel <hannes.hirzel at gmail.com> wrote:
> Bert
>
> This was a very helpful learning experience.
>
> Crucial is that lesson and section are the keys (strings) of the
> dictionaries.
>
> Very neat that only a model class with the GUI code defined in one
> method is needed.
>
> Thank you!
>
> Hannes
>
> On 4/19/10, Hannes Hirzel <hannes.hirzel at gmail.com> wrote:
>> Bert
>> Thank you for this second mail. I actually was struggling with
>> converting the 'lesson1', 'lesson2' etc back to the index.
>>
>> I had a method
>>
>> lessonListIndex: aLessonString
>> 	lessonListIndex := self lessonList indexOf: aLessonString.
>> 	self changed: #sectionList
>>
>> Your 'buildWith: builder' looks very need. So I'll go for that do not
>> go for Integer indices.
>>
>> I'll try it - without looking at your solution :-)
>>
>> Hannes
>>
>> On 4/19/10, Bert Freudenberg <bert at freudenbergs.de> wrote:
>>> On 19.04.2010, at 12:02, Bert Freudenberg wrote:
>>>>
>>>> On 19.04.2010, at 11:45, Hannes Hirzel wrote:
>>>>>
>>>>> Hello
>>>>>
>>>>> I would like to construct a three pane browser to inspect a dictionary
>>>>> of dictionaries (see data structure example code below). How do I do
>>>>> this using the ToolBuilder? I would like to learn to use it.
>>>>
>>>> Maybe look at Browser>>buildWith: or all the other buildWith:
>>>> implementations? No need to subclass DictionaryInspector, I'd simply
>>>> subclass Model.
>>>>
>>>> You would have two lists, and a text pane. Your model will have to
>>>> provide
>>>> methods to get the list and get/set the current index. E.g.
>>>> #lessonList,
>>>> #lessonListIndex, #lessonListIndex: and #sectionList,
>>>> #sectionListIndex,
>>>> #sectionListIndex:.
>>>>
>>>> When you select something in the lesson list, #lessonListIndex: will be
>>>> sent. In response, you would send "self changed: #sectionList" which
>>>> will
>>>> cause the section list to be updated. Etc.
>>>>
>>>> - Bert -
>>>
>>> After actually having a look, Browser>>buildWith: etc. are already
>>> specialized for code tools. No need for that.
>>>
>>> Also, for lists as in your case, working with indices for the selection
>>> is
>>> less convenient than with objects.
>>>
>>> So here's a build method for your model - just implement all the
>>> accessors
>>> and it works. A complete UI in one method ;)
>>>
>>> buildWith: builder
>>> 	^builder build:
>>> 		(builder pluggableWindowSpec new
>>> 			model: self;
>>> 			children: {
>>> 				(builder pluggableListSpec new)
>>> 					model: self;
>>> 					list: #lessonList;
>>> 					getSelected: #lesson;
>>> 					setSelected: #lesson:;
>>> 					frame: (0 at 0 corner: 0.5 at 0.2).
>>> 				(builder pluggableListSpec new)
>>> 					model: self;
>>> 					list: #sectionList;
>>> 					getSelected: #section;
>>> 					setSelected: #section:;
>>> 					frame: (0.5 at 0 corner: 1 at 0.2).
>>> 				(builder pluggableTextSpec new)
>>> 					model: self;
>>> 					getText: #contents;
>>> 					frame: (0 at 0.2 corner: 1 at 1).
>>> 			})
>>>
>>>
>>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MyDictionaryInspector.png
Type: image/png
Size: 10623 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/beginners/attachments/20100420/5ebeb67e/MyDictionaryInspector-0001.png


More information about the Beginners mailing list