forked from pharo-project/pharo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
590 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Extension { #name : #SpDatePresenter } | ||
|
||
{ #category : #'*Spec2-Morphic-Examples' } | ||
SpDatePresenter class >> example [ | ||
<sampleInstance> | ||
|
||
^ self new openWithSpec | ||
] | ||
|
||
{ #category : #'*Spec2-Morphic-Examples' } | ||
SpDatePresenter class >> exampleModal [ | ||
<sampleInstance> | ||
|
||
^ self new openModalWithSpec | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
" | ||
Demo page for SpecDemoFormPresenter | ||
" | ||
Class { | ||
#name : #SpDemoFormPage, | ||
#superclass : #SpDemoPage, | ||
#category : #'Spec2-Morphic-Examples-Demo-Forms' | ||
} | ||
|
||
{ #category : #specs } | ||
SpDemoFormPage class >> pageName [ | ||
|
||
^ 'Forms' | ||
] | ||
|
||
{ #category : #specs } | ||
SpDemoFormPage class >> priority [ | ||
|
||
^ 10 | ||
] | ||
|
||
{ #category : #initialization } | ||
SpDemoFormPage >> pageClass [ | ||
|
||
^ SpDemoFormPresenter | ||
|
||
] |
103 changes: 103 additions & 0 deletions
103
src/Spec2-Morphic-Examples/SpDemoFormPresenter.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
" | ||
This demo shows, how to create a simple form with basic elements and how to connect this form to a model. | ||
In this case, the model is represented by instances of the class SpecDemoFormModel created in the #initialize. It is a simple structure-like class with some default values. The model is not held directly but using a value holder named announcingObject (see ComposablePresenterWithModel>>#model:). The encapsulating value holder would not be needed if our model would be a subclass of ""Model"" (instances of Model provide an announcer by default). | ||
This component has two main subcomponents. The form and a table that shows the current state of the model. | ||
The form is a standalone Spec presenter, an instance of SpecDemoStandaloneFormPresenter. It works with two instances of the model, ""workingModel"" which holds a working copy of the model and a model shared with its parent. When the form is restored, the working copy of the model is thrown away and replaced with a new copy of the model. When the form is submitted, the new model is stored (into the value holder and its change is propagated so the table showing the state of the model is refreshed). | ||
The data exchange between the model and form elements is done in these methods: | ||
SpecDemoStandaloneFormPresenter>>#fillFormWithWorkingModel | ||
SpecDemoStandaloneFormPresenter>>#fillModelWithFormContent | ||
The two parts of this window (form and table) should be rendered in boxes with an outline. Spec in Morphic does not have such functionality now. SpecDemoLabeledContainer is used now. | ||
Text input for number 1 is limited directly on the level of user input. See SpecDemoStandaloneFormPresenter>>#initializePresenter. | ||
For displaying of the model state, the FastTable Morph is used. Currently, Spec does not provide a presenter for such tables. The class SpecDemoFormTableDataSource is used for interaction between the table and model. | ||
" | ||
Class { | ||
#name : #SpDemoFormPresenter, | ||
#superclass : #SpPresenterWithModel, | ||
#instVars : [ | ||
'form', | ||
'resultPane', | ||
'table' | ||
], | ||
#category : #'Spec2-Morphic-Examples-Demo-Forms' | ||
} | ||
|
||
{ #category : #specs } | ||
SpDemoFormPresenter class >> defaultSpec [ | ||
^ SpPanedLayout newHorizontal | ||
position: (StandardFonts defaultFont widthOfString: 'M') * 35; | ||
add: #form; | ||
add: #resultPane; | ||
yourself | ||
] | ||
|
||
{ #category : #accessing } | ||
SpDemoFormPresenter >> form [ | ||
^ form | ||
] | ||
|
||
{ #category : #accessing } | ||
SpDemoFormPresenter >> form: anObject [ | ||
form := anObject | ||
] | ||
|
||
{ #category : #initialization } | ||
SpDemoFormPresenter >> initialize [ | ||
self model: SpDemoFormModel new. | ||
super initialize | ||
] | ||
|
||
{ #category : #initialization } | ||
SpDemoFormPresenter >> initializePresenters [ | ||
form := (self instantiate: SpDemoLabeledContainer) | ||
label: 'form'; | ||
subwidget: (self instantiate: SpDemoStandaloneFormPresenter on: self announcingObject). | ||
resultPane := (self instantiate: SpDemoLabeledContainer) | ||
label: 'result'; | ||
subwidget: (table := self newTable). | ||
|
||
table | ||
addColumn: (SpStringTableColumn title: 'Name' evaluated: #key); | ||
addColumn: (SpStringTableColumn title: 'Value' evaluated: #value); | ||
items: self model elements; | ||
beResizable. | ||
|
||
self focusOrder | ||
add: form; | ||
add: table | ||
] | ||
|
||
{ #category : #accessing } | ||
SpDemoFormPresenter >> modelChanged [ | ||
table items: self model elements | ||
] | ||
|
||
{ #category : #accessing } | ||
SpDemoFormPresenter >> resultPane [ | ||
^ resultPane | ||
] | ||
|
||
{ #category : #accessing } | ||
SpDemoFormPresenter >> resultPane: anObject [ | ||
resultPane := anObject | ||
] | ||
|
||
{ #category : #accessing } | ||
SpDemoFormPresenter >> table [ | ||
^ table | ||
] | ||
|
||
{ #category : #accessing } | ||
SpDemoFormPresenter >> table: anObject [ | ||
table := anObject | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
" | ||
A DropListExample is a simple example of how to use drop lists. | ||
self example | ||
" | ||
Class { | ||
#name : #SpDropListExample, | ||
#superclass : #SpPresenter, | ||
#instVars : [ | ||
'container', | ||
'morph1', | ||
'morph2', | ||
'morph3', | ||
'uniformDropList', | ||
'heterogeneousDropList', | ||
'disabledDropList' | ||
], | ||
#category : #'Spec2-Morphic-Examples' | ||
} | ||
|
||
{ #category : #specs } | ||
SpDropListExample class >> defaultSpec [ | ||
^ SpBoxLayout newVertical | ||
add: | ||
(SpBoxLayout newHorizontal | ||
add: #uniformDropList; | ||
add: #heterogeneousDropList; | ||
yourself) | ||
height: self toolbarHeight; | ||
add: #disabledDropList height: self toolbarHeight; | ||
add: #container; | ||
yourself | ||
] | ||
|
||
{ #category : #example } | ||
SpDropListExample class >> example [ | ||
<sampleInstance> | ||
|
||
^ self new openWithSpec | ||
] | ||
|
||
{ #category : #specs } | ||
SpDropListExample class >> title [ | ||
|
||
^ 'Drop list' | ||
] | ||
|
||
{ #category : #accessing } | ||
SpDropListExample >> container [ | ||
^ container | ||
] | ||
|
||
{ #category : #initialization } | ||
SpDropListExample >> containerMorph [ | ||
^ container morph | ||
] | ||
|
||
{ #category : #accessing } | ||
SpDropListExample >> disabledDropList [ | ||
^ disabledDropList | ||
] | ||
|
||
{ #category : #accessing } | ||
SpDropListExample >> heterogeneousDropList [ | ||
^ heterogeneousDropList | ||
] | ||
|
||
{ #category : #initialization } | ||
SpDropListExample >> initializePresenters [ | ||
uniformDropList := self newDropList. | ||
heterogeneousDropList := self newDropList. | ||
container := self newMorph. | ||
disabledDropList := self newDropList. | ||
container morph: PanelMorph new. | ||
self instantiateMorphs. | ||
self containerMorph | ||
changeTableLayout; | ||
listDirection: #bottomToLeft. | ||
disabledDropList | ||
items: #('Disabled' 'Two' 'Three'); | ||
display: [ :each | each ]; | ||
disable. | ||
uniformDropList | ||
items: | ||
{morph1. | ||
morph2. | ||
morph3}; | ||
display: [ :m | m color name capitalized , ' morph' ]; | ||
iconBlock: [ :e | self iconNamed: #testGreenIcon ]; | ||
whenSelectedItemChangedDo: [ :m | | ||
self containerMorph | ||
removeAllMorphs; | ||
addMorph: m ]. | ||
heterogeneousDropList | ||
addItemLabeled: 'Open workspace' | ||
do: [ Smalltalk tools workspace open ] | ||
icon: (self iconNamed: #smallOkIcon); | ||
addItemLabeled: 'Inspect current morph' | ||
do: [ uniformDropList selectedItem inspect ] | ||
icon: (self iconNamed: #testRedIcon). | ||
|
||
"If this is uncommented, it will fire the action of the first item, which is not what we want: | ||
heterogeneousDropList setSelectedIndex: 1. | ||
same for: | ||
heterogeneousDropList setIndex: 1" | ||
uniformDropList selectIndex: 1. | ||
self setFocus | ||
] | ||
|
||
{ #category : #initialization } | ||
SpDropListExample >> instantiateMorphs [ | ||
|
||
morph1 := Morph new | ||
color: Color red; | ||
width: 60; | ||
height: 20. | ||
morph2 := Morph new | ||
color: Color blue; | ||
width: 20; | ||
height: 60. | ||
morph3 := Morph new | ||
color: Color green; | ||
width: 50; | ||
height: 50. | ||
] | ||
|
||
{ #category : #initialization } | ||
SpDropListExample >> setFocus [ | ||
|
||
self focusOrder | ||
add: uniformDropList; | ||
add: heterogeneousDropList; | ||
add: disabledDropList. | ||
|
||
] | ||
|
||
{ #category : #accessing } | ||
SpDropListExample >> uniformDropList [ | ||
|
||
^ uniformDropList | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Extension { #name : #SpLinkPresenter } | ||
|
||
{ #category : #'*Spec2-Morphic-Examples' } | ||
SpLinkPresenter class >> example [ | ||
<sampleInstance> | ||
| example | | ||
example := self new | ||
url: 'https://pharo.org'; | ||
label: 'Pharo website'; | ||
extent: 200 @ 20; | ||
openWithSpec; | ||
yourself. | ||
|
||
example withWindowDo: [ :w | w title: 'Link presenter' ]. | ||
^ example | ||
] |
Oops, something went wrong.