Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Spec2-Tutorial-Tests/SptMetadataPresenter.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Extension { #name : 'SptMetadataPresenter' }
{ #category : '*Spec2-Tutorial-Tests' }
SptMetadataPresenter >> metadataNamed: aString [

^ (table items detect: [ :association |
^ (metadataPresenter items detect: [ :association |
association key = aString asSymbol ]) value
]
15 changes: 10 additions & 5 deletions src/Spec2-Tutorial/SptImageAnnotationApplication.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Small application to visualize images and their metadata.

```
SptImageAnnotationApplication new start.
SptImageAnnotationApplication new run.
```
"
Class {
Expand All @@ -17,12 +17,17 @@ Class {
SptImageAnnotationApplication class >> startNewApplication [
<script>

^ self new
start;
yourself
^ self new run
]

{ #category : 'accessing' }
SptImageAnnotationApplication >> defaultConfigurationForMorphic [

^ SptImageAnnotationConfiguration new
]

{ #category : 'running' }
SptImageAnnotationApplication >> start [
SptImageAnnotationPresenter new open

(SptImageAnnotationPresenter newApplication: self) open
]
30 changes: 30 additions & 0 deletions src/Spec2-Tutorial/SptImageAnnotationConfiguration.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Class {
#name : 'SptImageAnnotationConfiguration',
#superclass : 'SpMorphicConfiguration',
#category : 'Spec2-Tutorial',
#package : 'Spec2-Tutorial'
}

{ #category : 'configuring' }
SptImageAnnotationConfiguration >> configure: anApplication [

super configure: anApplication.
self addStyleSheetFromString: self style
]

{ #category : 'accessing' }
SptImageAnnotationConfiguration >> style [

^ '.application [
.sptAnnotation [
Container { #borderWidth: 2, #borderColor: EnvironmentColor(#background) },
Draw { #backgroundColor: EnvironmentColor(#background) } ] ,
.sptHeader [
Draw {
#backgroundColor : EnvironmentColor(#window),
#color : EnvironmentColor(#selectionText) },
Font {
#name : EnvironmentFont(#default),
#size : 12 } ]
]'
]
54 changes: 33 additions & 21 deletions src/Spec2-Tutorial/SptImageAnnotationPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Class {
#instVars : [
'directoryPresenter',
'filesPresenter',
'imagePresenter'
'imagePresenter',
'directoryLabelPresenter',
'filesLabelPresenter'
],
#category : 'Spec2-Tutorial-Presenters',
#package : 'Spec2-Tutorial',
Expand Down Expand Up @@ -39,40 +41,50 @@ SptImageAnnotationPresenter >> connectPresenters [
SptImageAnnotationPresenter >> defaultLayout [

^ SpPanedLayout newLeftToRight
add: (SpBoxLayout newTopToBottom
add: directoryPresenter;
add: filesPresenter;
positionOfSlider: 25 percent;
add: (SpBoxLayout newTopToBottom
spacing: 5;
add: (SpBoxLayout newTopToBottom
add: directoryLabelPresenter expand: false;
add: directoryPresenter;
yourself);
add: (SpBoxLayout newTopToBottom
add: filesLabelPresenter expand: false;
add: filesPresenter;
yourself);
yourself);
add: imagePresenter;
positionOfSlider: 20 percent;
yourself
]

{ #category : 'initialization' }
SptImageAnnotationPresenter >> initializePresenters [
directoryPresenter := self newTreeTable
addColumn:
(SpCompositeTableColumn new
title: 'Directories';
addColumn:
(SpImageTableColumn new
width: 20;
evaluated: #icon;
yourself);
addColumn:
(SpStringTableColumn new
evaluated: #label;
yourself);
yourself);

self addStyle: 'sptAnnotation'.

directoryLabelPresenter := self newLabel
addStyle: 'sptHeader';
label: 'Directories';
yourself.
directoryPresenter := self newTree
addStyle: 'sptAnnotationDirectory';
displayIcon: #icon;
display: #label;
roots: { StDirectoryWrapper on: FileLocator downloads };
children: [ :aClass | aClass subdirectories ];
expandRoots;
beResizable;
yourself.

filesLabelPresenter := self newLabel
addStyle: 'sptHeader';
label: 'Files';
yourself.
filesPresenter := self newList
display: [ :each | each basename ];
display: #basename;
yourself.
imagePresenter := self instantiate: (SptImageMetadataPresenter on: nil).

imagePresenter := self instantiate: SptImageMetadataPresenter on: nil
]

{ #category : 'initialization' }
Expand Down
6 changes: 6 additions & 0 deletions src/Spec2-Tutorial/SptImageMetadata.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ SptImageMetadata >> basicUpdateMetadataNamed: aSymbol with: aString [
LibC runCommand: command
]

{ #category : 'testing' }
SptImageMetadata >> exists [

^ self file exists
]

{ #category : 'accessing' }
SptImageMetadata >> file [
^ file
Expand Down
85 changes: 59 additions & 26 deletions src/Spec2-Tutorial/SptImageMetadataPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ Class {
'metadataPresenter',
'tag1Button',
'resetDescButton',
'editMetadataButton'
'editMetadataButton',
'imageLabelPresenter',
'noImageLabelPresenter'
],
#category : 'Spec2-Tutorial-Presenters',
#package : 'Spec2-Tutorial',
Expand All @@ -31,13 +33,27 @@ SptImageMetadataPresenter class >> example [
{ #category : 'layout' }
SptImageMetadataPresenter >> defaultLayout [

^ SpBoxLayout newLeftToRight
spacing: 5;
^ SpPanedLayout newTopToBottom
positionOfSlider: 65 percent;
add: (SpBoxLayout newTopToBottom
spacing: 10;
add: imagePresenter;
add: tag1Button expand: false;
add: resetDescButton expand: false;
add: (SpOverlayLayout new
addOverlay: noImageLabelPresenter;
child: (SpBoxLayout newTopToBottom
add: (SpBoxLayout newLeftToRight
hAlignCenter;
borderWidth: 5;
add: imageLabelPresenter;
yourself) expand: false;
add: imagePresenter;
yourself);
yourself);
add: (SpBoxLayout newLeftToRight
spacing: 5;
add: tag1Button;
add: resetDescButton;
yourself)
expand: false;
yourself);
add: metadataPresenter;
yourself
Expand Down Expand Up @@ -77,36 +93,53 @@ SptImageMetadataPresenter >> imageFromFile [
{ #category : 'initialization' }
SptImageMetadataPresenter >> initializePresenters [

metadataPresenter := self
instantiate: SptMetadataPresenter
on: self model.
metadataPresenter := self instantiate: SptMetadataPresenter on: self model.

noImageLabelPresenter := self newLabel
label: 'No image selected';
yourself.

imageLabelPresenter := self newLabel
addStyle: 'title';
yourself.

imagePresenter := self newImage
image: self emptyImage;
autoScale: true;
yourself.
autoScale: true;
yourself.

tag1Button := self newButton
label: 'expo 1';
action: [ self imageDescription: 'expo 1' ];
yourself.
label: 'expo 1';
action: [ self imageDescription: 'expo 1' ];
yourself.

editMetadataButton := self newButton
label: 'Edit metadata';
action: [ self openMetadataEditor ];
yourself.
label: 'Edit metadata';
action: [ self openMetadataEditor ];
yourself.

resetDescButton := self newButton
label: 'reset image description';
action: [ self resetImageDescription ];
enabled: self hasImageDescriptionMetadata;
yourself
label: 'Reset Metadata';
action: [ self resetImageDescription ];
enabled: self hasImageDescriptionMetadata;
yourself
]

{ #category : 'initialization' }
SptImageMetadataPresenter >> modelChanged [

self model ifNil: [
self model: SptNullImageMetadata new.
^ self ].

imagePresenter image: self imageFromFile.
self model: SptNullImageMetadata new.
^ self ].

self model exists
ifTrue: [
noImageLabelPresenter hide.
imageLabelPresenter label: self model file basename.
imagePresenter image: self imageFromFile ]
ifFalse: [
noImageLabelPresenter show.
imageLabelPresenter label: ''.
imagePresenter image: nil ].
metadataPresenter model: self model
]

Expand Down
25 changes: 16 additions & 9 deletions src/Spec2-Tutorial/SptMetadataPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Class {
#name : 'SptMetadataPresenter',
#superclass : 'SpPresenterWithModel',
#instVars : [
'table'
'metadataPresenter',
'metadataLabelPresenter'
],
#category : 'Spec2-Tutorial-Presenters',
#package : 'Spec2-Tutorial',
Expand All @@ -24,24 +25,30 @@ SptMetadataPresenter class >> example [
SptMetadataPresenter >> defaultLayout [

^ SpBoxLayout newTopToBottom
add: 'Image metadata' expand: false;
add: table;
add: metadataLabelPresenter expand: false;
add: metadataPresenter;
yourself
]

{ #category : 'initialization' }
SptMetadataPresenter >> initializePresenters [
table := self newTable
addColumn: (SpStringTableColumn title: 'Key' evaluated: [ :association | association key]);
addColumn: (SpStringTableColumn title: 'Value' evaluated: [ :association | association value]);
"addActionWith: [ :action | action name: 'zoom'; action: [ 1 halt ] ];"
yourself.


metadataLabelPresenter := self newLabel
addStyle: 'sptHeader';
label: 'Image Metadata';
yourself.

metadataPresenter := self newTable
addColumn: (SpStringTableColumn title: 'Key' evaluated: [ :association | association key]);
addColumn: (SpStringTableColumn title: 'Value' evaluated: [ :association | association value]);
yourself.
]

{ #category : 'initialization' }
SptMetadataPresenter >> modelChanged [

table items: (self model
metadataPresenter items: (self model
ifNotNil: [ :aModel | aModel metadata associations ]
ifNil: [ #() ])
]
6 changes: 6 additions & 0 deletions src/Spec2-Tutorial/SptNullImageMetadata.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ Class {
#tag : 'Model'
}

{ #category : 'testing' }
SptNullImageMetadata >> exists [

^ false
]

{ #category : 'accessing' }
SptNullImageMetadata >> file [
^ (FileSystem memory root / 'null.image') ensureCreateFile
Expand Down