Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
PluggableTextMorph demo 1
Last updated at 1:23 pm UTC on 30 May 2018
Download: PluggableMorphsDemo-0001.pr


The project file with all the demos:

Installation: drop file PluggableMorphsDemo-0001.pr (2003) onto Squeak desktop.

Tests:

PluggableMorphsDemo-0001.pr

For the code of only the PluggableTextMorph demo 1 see below.


All demos after loading the project file

PluggableMorphsDemo-0001.pr_dropped_onto_Squeak3.6_desktop_screenshot.png


PluggableText demo 1

Code: Demo-TextDemo1_page_1143.st

TextDemo1 explanations



Purpose: The demo shows how you can create a PluggableTextMorph bound to a model.

Steps:

1. The construction script for the demo is on the class side of the TextDemo2 class>>example.
2. We first create or model which will hold the textual data. This textual data is shown in the two PluggableTextMorph instances.
3. If you change the contents of the first one, it will affect the other one because they are all "plugged-on" the same model.



Thanks to the changed: invocation when the text: message is sent to the model, the model will notify all its dependants (morphs which were plugged on that model) so that all the model's dependents will update itself approriatelly.

Related stuff:

(you may what to put a breakpoints to those methods, play with the demo and see how it all works).



PluggableTextDemo1_Screenshot.png

Squeak 3.10.2 (BabySRE)

TextDataObject_with_two_PluggableTextMorph_objects_Screenshot_2018-05-30.png
The code
"Creates two PluggableTextMorph objects which have a common model.	 

If you change editing the text in one PluggableTextMorph you may save it with press Alt+S.

The display in the other PluggableTextMorph is also updated as the two views share the same model."
						
| object textMorph1 textMorph2 |	
	object := TextDataObject new.		
			
			
textMorph1 := PluggableTextMorph on: object 
                        text: #text 
                       accept: #text:.
textMorph1 position:  660@400.
textMorph1 extent: 200 @ 120.
textMorph1 color: Color white.
textMorph1 openInWorld.		

textMorph2 := PluggableTextMorph on: object 
                        text: #text 
                       accept: #text:.
textMorph2 position: 660@540.
textMorph2 extent: 200 @ 120.
textMorph2 color: Color white.
textMorph2 openInWorld.												

PluggableTextMorph_collaboration_diagram_Screenshot_2018-05-30.png

Note: Every object which implements


text	
	^ text

(getter method)

text: aText	
	
	text _ aText.	
		
	^ self changed: #text

(setter method)

may serve as a model object.