View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

How to use PartsBin

By Sam Young

Want to make use of container widgets like those in the Squeak world flaps? A PartsBin enables the world's HandMorph (cursor) to pick up an entire object, and it provides a nice interface with which to do so. It supports any type of Morph. PartsBin will snapshot its default display (i.e. what you initially see with openInWorld) and also provide a small subscript label.

For this semester's PowerPoint-like project, SqueakPoint, I quickly and easily implemented a PartsBin for dragging/dropping widgets and layouts on to a SqueakPoint slide. My specific implementation was added some nice display effects and itself contained a PartsBin, but PartsBin itself can be used as-is for most situations. Here is a screenshot of the one I used in the project:

Uploaded Image: palette.jpg

This particular example is a RectangleMorph extension. It contains both a PartsBin and a SkechMorph (to provide the background image). But for the purposes of this little tutorial, I'll cover just the PartsBin class.

Much like the Morphic world itself, PartsBin is a PasteUpMorph. Hence it can hold other morphs, particularly the snapshots and labels of the objects it contains. It lays its contents out with a standard TableLayout. The way to create a one is the following class message call:
PartsBin newPartsBinWithOrientation: aListDirection from: quadList
What does this mean? Let's have a look.. The parameter aListDirection represents the direction in which to layout the contents. This is verbatim from setting the listDirection for a TableLayout. You have the following symbols as options:
#leftToRight #rightToLeft #topToBottom #bottomToTop
The last parameter, quadList, is exactly what it sounds like. It is an array in which each element is an array of size four. Here is the code used in the example above:
(PageLinkButton authoringPrototype 'Link Button' 'Add a page link button.')
(SlideTextMain authoringPrototype 'Text' 'Add auto-resizing text.')
(SlideHeaderText authoringPrototype 'Header' 'Add header text.')
(SlideImage authoringPrototype 'Image' 'Add image.')
(TitleSlideLayout authoringPrototype 'Title Slide' 'Add a title slide layout.')
(TitleOnlyLayout authoringPrototype 'Title Only' 'Add a slide with only a title.')
(TwoPicturesAndTextLayout authoringPrototype 'Two Pictures and Text' 'Add a layout with two pictures and text..')
(TwoTextLayout authoringPrototype 'Two Text' 'Add a layout with two texts.')
(FourPicturesLayout authoringPrototype 'Four Pictures' 'Add a layout with four pictures.')
(PictureAndTextLayout authoringPrototype 'Picture and Text' 'Add a layout with a picture and text.')
(PictureLayout authoringPrototype 'Picture Layout' 'Add a layout with a picture.')
(SingleTextLayout authoringPrototype 'Single Text' 'Add a layout with a single text.')
(TextAndPictureLayout authoringPrototype 'Text and Picture' 'Add a text and picture layout.')
(TextAndTwoPicturesLayout authoringPrototype 'Text and Two Pictures' 'Add a layout with a text and two pictures.'))
Although the parameter is called quadList, and although it appears that each subarray contains four elements, the first two elements are actually only one element. ClassName authoringPrototype is a class message call implemented in Morph. It is specifically designed to returned the snapshot representation of a Morph for the PartsBin class. Thus there are only three elements in each subarray, and perhaps the parameter should be called triList. The last two elements are respectively the label and the tool-tip text for each item in the PartsBin.

So, the proper format for each array is:
(ClassName authoringPrototype 'Label' 'Tool-tip text message'
That's about it for creation. Another important thing to note, however, is that PartsBin contains a class reference to a list of all thumbnails. Since this is a class variable, the list of thumbnails is shared across the entire world. In the event of new thumbnails not showing up when you create a new PartsBin, it may be necessary to re-cache the thumbnails using the following class message:
PartsBin cacheAllThumbnails
Lastly, you can dynamically add any Morph to a PartsBin by simpling dropping it inside. So if you would like to add a new type of button you've created, all you have to do is drop it in. The example above is a hard-coded listing of morphs that the example PartsBin will always contain.

Links to this Page