Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Pluggable Morphs Demo
Last updated at 2:00 pm UTC on 30 May 2018

2018

Elaboration of PluggableTextMorph demo 1.

2008


General Information


If you are looking for some information concerning pluggable morphs, perhaps this set of simple demos will show you how to use them.

This project was created in order to ease the understanding this stuff. (NOTE: An error is thrown when loading the project into Squeak5.1-16548, however, the code does get loaded. 20170330. Loads fine into Squeak6.0alpha-17058)

It shows you how to use:
Project file:


Instruction for loading it into Squeak



With Squeak web-browser plugin you may find it online: PluggableMorphsDemo


All categories provided by this project are put to `Demo' package.


Details about the Demo


When you open the project, you can see several morphs placed around.

The recommended order in which it is recommended to study the demos is :

You may first try to run the demos and see what they are about and then you can browse the appropriate code to find out how it works.


The first two demos show what can be done with PluggableButtonMorph.

ButtonDemo1


The first demo can be started with the ButtonDemo1 label. It will invoke the ButtonDemo1 class>>example method. The code shows you how you can create a PluggableButtonMorph instance which when it is pressed will send a message with given unary selector to a given target.

The button is constructed in the following way:

b := PluggableButtonMorph
on: [Transcript show: 'something'; cr]
getState: nil
action: #value.
b label: 'show ''something'' on Transcript!'.
b position: 100 @ 200; openInWorld


During the object construction we have specified the following two important things:
NOTE: Please ignore the parameter after keyword getState: for now. It will be explained in one of the following demos.

The second command sets up the constant label of the button.

The third command positions and shows the button in the world.


ButtonDemo2


The second demo can be started with the ButtonDemo2 label. It will invoke the ButtonDemo2 class>>example method. This demo is somewhat similar to the previous one. We also specify some sort of target, selector to be sent to it. Look at the code which creates the PluggableButtonMorph instance:

model := ButtonDemo2Object new.
button := PluggableButtonMorph on: model getState: nil action: #act label: #asString.
button position: 100 @ 220; openInWorld.

Druring the PluggableButtonMorph instance construction we specify the following three things:
NOTE: Please ignore the parameter after keyword getState: for now. It will be explained in one of the following demos.


ButtonDemo3


It demonstrates how you can create a button whose color will reflect model's internal state. It is constructed as follows:

example
b := PluggableButtonMorph
on: Switch new turnOff
getState: #isOn
action: #switch
label: nil.
b label: 'some constant label'.
b onColor: Color red offColor: Color lightGreen.
b position: 100 @ 240.
b openInWorld.

The selector #isOn will be used to ask the model whether the button should be "on-colored" or "off-colored".


The following three demos demonstrate the PluggableTextMorph
PluggableTextMorph demo 1


TextDemo2


Similar to the previous demo but when the user yellow-clicks the PluggableTextMorph, some menu appears. If you want to see how this can be achieved, you might want to look at the TextDemo2 class>>example method. Notice the #menu parameter of PluggableTextMorph constructor. It determines the selector of the message wich will be sent to the model when user yellow-clicks that morph.

Related methods:

Menu can also be added in the similar way to the other pluggable morphs.


TextDemo3


It is similar to TextDemo1 but the PluggableTextMorphs are configured in such a way that the user may accept the contents of the PluggableTextMorph not only with Alt+S but also with Enter.

Related methods:



ListDemo1


It shows how you can create pluggable list morph

Related stuff:


ListDemo2


It shows how you can create multi-column pluggable list morph

Related stuff:

author: Matej Kosik (contact me if you if you have suggestions or complains concerning this demo)

PluggableMorphsDemo-0001.pr