Skip to content

Commit

Permalink
Merge pull request #45 from hpi-swa-teaching/load_json
Browse files Browse the repository at this point in the history
Load json
  • Loading branch information
lwenner committed May 23, 2021
2 parents 0170bcb + bb6e3c3 commit b6f0b67
Show file tree
Hide file tree
Showing 63 changed files with 368 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ addColorFrame: aTreeNode
with: #properties -> {
Dictionary
with: #name -> aTreeNode title asLowercase
with: #value -> aTreeNode targetColor rgbTriplet.
with: #value -> aTreeNode targetColor printHtmlString asSymbol.
}.

^ jsonFrame.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
loadJson
addMorphFromSpec: aDictionary
| morph morphProperty |
morph := (self createMorphFromString: (aDictionary at: 'type')) openInWorld.
self loadStartProperties: (aDictionary at: 'properties') with: morph.
morphProperty := self addTargetMorph: morph.
self loadFramesFromJson: (aDictionary at: 'frames') with: morphProperty.




Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ addTargetMorph: aMorph
newTarget targetMorph: aMorph.
newTarget title: '', (self propertyList size ), ' - ', aMorph className.

newTarget subproperties add: (self createRotationPropertyFrom: aMorph).
newTarget subproperties add: (self createColorPropertyFrom: aMorph).
newTarget subproperties add: (self createPositionPropertyFrom: aMorph).
newTarget subproperties add: (self createSizePropertyFrom: aMorph).
newTarget subproperties at: 'rotation' put: (self createRotationPropertyFrom: aMorph).
newTarget subproperties at: 'color' put: (self createColorPropertyFrom: aMorph).
newTarget subproperties at: 'position' put: (self createPositionPropertyFrom: aMorph).
newTarget subproperties at: 'size' put: (self createSizePropertyFrom: aMorph).
self propertyList add: newTarget.
self propertyTreeMorph update: self propertyTreeMorph getChildrenSelector.
self addTimeline.
self addTimeline.
^ newTarget.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildAddMorphButtonWith: aBuilder
frame: (LayoutFrame new
topFraction: 0;
bottomFraction: 1;
rightFraction: 0.25;
rightFraction: 0.2;
leftFraction: 0;
yourself);
yourself.
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ buildButtonBarWith: aBuilder
children: {self buildAddMorphButtonWith: aBuilder.
self buildSaveButtonWith: aBuilder.
self buildPlayButtonWith: aBuilder.
self buildResetButtonWith: aBuilder. };
self buildResetButtonWith: aBuilder.
self buildLoadJsonButtonWith: aBuilder.};
yourself.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
buildComponents
buildLoadJsonButtonWith: aBuilder
^ aBuilder pluggableButtonSpec new model: self;
label: 'Load JSON';
action: #handleLoadJsonButton;
frame: (LayoutFrame new
topFraction: 0;
bottomFraction: 1;
rightFraction: 1;
leftFraction: 0.8;
yourself);
yourself.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
buildComponents
buildLoadingMainWindow: aBuilder
| loadingMainWindow |

PluggableWindowSpec new openInHand.
loadingMainWindow:= (aBuilder build: (aBuilder pluggableWindowSpec new
model: self;
label: #editorTitle;
extent: 500@350;
children: { self buildButtonBarWith: aBuilder.
self buildPropertiesTreeWith: aBuilder.
self buildPositionUIPanelWith: aBuilder.
self buildTimeline: aBuilder.
self buildInformationBarWith: aBuilder.
};
yourself)).

^ loadingMainWindow.


Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildPlayButtonWith: aBuilder
frame: (LayoutFrame new
topFraction: 0;
bottomFraction: 1;
rightFraction: 0.75;
leftFraction: 0.50;
rightFraction: 0.6;
leftFraction: 0.4;
yourself);
yourself.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildResetButtonWith: aBuilder
frame: (LayoutFrame new
topFraction: 0;
bottomFraction: 1;
rightFraction: 1;
leftFraction: 0.75;
rightFraction: 0.8;
leftFraction: 0.6;
yourself);
yourself.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildSaveButtonWith: aBuilder
frame: (LayoutFrame new
topFraction: 0;
bottomFraction: 1;
rightFraction: 0.5;
leftFraction: 0.25;
rightFraction: 0.4;
leftFraction: 0.2;
yourself);
yourself.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
loadJson
createMorphFromString: aString
^ (self morphTypes at: aString asSymbol ifAbsent: [Morph new]) value.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ createRotationPropertyFrom: aMorph
| rotationTarget |
rotationTarget := (AnimationsEditorPropertyRotation new).
rotationTarget targetMorph: aMorph.
rotationTarget targetRotation: aMorph rotationDegrees.
^ rotationTarget.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
loadJson
framePropertiesDictionary
^ {#rotation -> [:anDictionary :aValue | (anDictionary at: 'rotation') targetRotation: aValue].
#positionX -> [:anDictionary :aValue | (anDictionary at: 'position') positionX: aValue].
#positionY -> [:anDictionary :aValue | (anDictionary at: 'position') positionY: aValue].
#width -> [:anDictionary :aValue | (anDictionary at: 'size') targetWidth: aValue].
#height -> [:anDictionary :aValue | (anDictionary at: 'size') targetHeight: aValue].
#color -> [:anDictionary :aValue | (anDictionary at: 'color') targetColor: aValue]} as: IdentityDictionary.




Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eventHandling
handleLoadJsonButton
| path |
path := UIManager default chooseFileMatching: '*.json'.
path isString
ifTrue: [self loadJsonWithExceptionHandling: (FileStream readOnlyFileNamed: path) contents].

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
loadJson
loadFramesFromJson: anArray with: anAnimationEditorProperty
(anArray first at: 'properties')
do: [:each | (self framePropertiesDictionary at: (each at: 'name') asSymbol)
value: anAnimationEditorProperty subproperties
value: (each at: 'value')].
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
loadJson
loadJson: aText
| data |
data:= STON fromString: aText.
self loadStartEnd: data.
self loadMorphs: (data at: 'morphs').
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
loadJson
loadJsonWithExceptionHandling: aText
[self loadJson: aText.
self updateInformationText: 'Animation loaded']
on: KeyNotFound
do: [:error | self updateInformationText: 'Invalid JSON (' , error messageText , ')'].

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
loadJson
loadMorphs: anArray
anArray do: [:each | self addMorphFromSpec: each].
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
loadJson
loadStartEnd: aDictionary
self propertyStartEnd startTime: (self propertyStartEnd startTime min: (aDictionary at: 'start')).
self propertyStartEnd endTime: (self propertyStartEnd endTime max: (aDictionary at: 'end')).
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
loadJson
loadStartProperties: anArray with: aMorph

anArray
do: [:each | (self propertiesDictionary at: (each at: 'name') asSymbol)
value: aMorph
value: (each at: 'value')].


Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
loadJson
morphTypes
^ {#Morph -> [Morph new].
#CircleMorph -> [CircleMorph new].
#RectangleMorph -> [RectangleMorph new].
#TextMorph -> [TextMorph new]} as: IdentityDictionary
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
loadJson
propertiesDictionary
^ {#rotation -> [:aMorph :aValue | aMorph rotationDegrees: aValue].
#positionX -> [:aMorph :aValue | aMorph left: aValue].
#positionY -> [:aMorph :aValue | aMorph top: aValue].
#width -> [:aMorph :aValue | aMorph width: aValue].
#height -> [:aMorph :aValue | aMorph height: aValue].
#color -> [:aMorph :aValue | aMorph color: (Color colorFrom: aValue)]} as: IdentityDictionary.




Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,36 @@
"class" : {
"open" : "DM 8/4/2020 13:18" },
"instance" : {
"addColorFrame:" : "MH 5/20/2021 09:25",
"addColorFrame:" : "LW 5/23/2021 12:23",
"addFrame:" : "NB 5/12/2021 09:25",
"addMorphFromSpec:" : "LW 5/15/2021 14:31",
"addMorphToJson:with:" : "MH 5/15/2021 11:15",
"addPositionFrame:" : "MH 5/20/2021 09:32",
"addRotationFrame:" : "NB 5/19/2021 12:43",
"addSelectedMorphFor:" : "DM 8/5/2020 21:11",
"addSizeFrame:" : "NB 5/19/2021 12:43",
"addTargetMorph:" : "MH 5/13/2021 11:32",
"addTargetMorph:" : "FH 5/13/2021 11:26",
"addTimeline" : "DM 8/7/2020 21:26",
"buildAddMorphButtonWith:" : "LH 8/4/2020 15:42",
"buildButtonBarWith:" : "LH 8/4/2020 15:42",
"buildAddMorphButtonWith:" : "FH 5/9/2021 13:19",
"buildButtonBarWith:" : "FH 5/20/2021 16:47",
"buildInformationBarWith:" : "DM 8/4/2020 16:12",
"buildLoadJsonButtonWith:" : "FH 5/20/2021 16:47",
"buildLoadingMainWindow:" : "FH 5/9/2021 13:58",
"buildMainWindowWith:" : "DM 8/4/2020 16:12",
"buildPlayButtonWith:" : "LH 8/4/2020 15:42",
"buildPlayButtonWith:" : "FH 5/9/2021 13:18",
"buildPositionUIPanelWith:" : "DM 6/18/2020 13:32",
"buildPropertiesTreeWith:" : "DM 7/8/2020 14:27",
"buildResetButtonWith:" : "DM 7/8/2020 14:38",
"buildSaveButtonWith:" : "LH 8/4/2020 15:42",
"buildResetButtonWith:" : "FH 5/9/2021 13:19",
"buildSaveButtonWith:" : "FH 5/9/2021 13:19",
"buildTimeline:" : "DM 8/4/2020 16:12",
"buildWith:" : "DM 8/5/2020 21:02",
"buildWith:" : "FH 5/9/2021 13:57",
"collectAllEmptyPanels" : "DM 8/5/2020 21:02",
"collectInformationBar" : "DM 8/5/2020 21:02",
"collectPropertyTreeMorph" : "DM 8/5/2020 21:02",
"createColorPropertyFrom:" : "DM 8/7/2020 10:48",
"createMorphFromString:" : "LW 5/15/2021 14:12",
"createPositionPropertyFrom:" : "DM 8/6/2020 10:09",
"createRotationPropertyFrom:" : "DM 7/8/2020 14:29",
"createRotationPropertyFrom:" : "FH 5/13/2021 10:16",
"createSizePropertyFrom:" : "DM 7/8/2020 14:29",
"createStartInformation:" : "MH 5/20/2021 11:24",
"createStructure:with:" : "NB 5/13/2021 10:25",
Expand All @@ -38,19 +42,29 @@
"editorTitle:" : "DM 8/3/2020 15:40",
"emptyPanels" : "DM 8/7/2020 17:37",
"emptyPanels:" : "DM 6/12/2020 20:40",
"framePropertiesDictionary" : "LW 5/23/2021 12:20",
"getDeepestMorph:at:" : "DM 6/22/2020 01:25",
"handleListenEvent:" : "DM 8/5/2020 21:11",
"handleLoadJsonButton" : "FH 5/20/2021 18:12",
"informationBar" : "DM 7/8/2020 15:03",
"informationBar:" : "DM 7/8/2020 15:03",
"informationBarText" : "DM 6/22/2020 01:26",
"informationBarText:" : "DM 6/4/2020 13:24",
"initialize" : "DM 6/22/2020 01:26",
"initializePropertyEditorPanel" : "DM 8/6/2020 10:38",
"insertMorph:Into:" : "JIZ 6/3/2020 16:56",
"loadFramesFromJson:with:" : "LW 5/15/2021 14:31",
"loadJson:" : "LW 5/15/2021 14:30",
"loadJsonWithExceptionHandling:" : "FH 5/20/2021 17:44",
"loadMorphs:" : "LW 5/15/2021 14:14",
"loadStartEnd:" : "FH 5/13/2021 10:40",
"loadStartProperties:with:" : "FH 5/15/2021 13:16",
"mainWindow" : "JIZ 6/3/2020 17:04",
"mainWindow:" : "JIZ 6/3/2020 17:04",
"morphTypes" : "LW 5/15/2021 14:00",
"outputFileDirectory" : "NB 5/21/2021 09:07",
"playAnimations" : "MH 5/10/2021 11:48",
"propertiesDictionary" : "LW 5/15/2021 15:05",
"propertyEditorPanel" : "DM 6/22/2020 01:27",
"propertyEditorPanel:" : "DM 6/12/2020 20:41",
"propertyEditorPanelChildren" : "DM 6/22/2020 01:27",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
code-generation
codeGeneration
animationString
self subclassResponsibility.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
build-component
buildComponents
buildUIWith: aBuilder
self subclassResponsibility.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
code-generation
codeGeneration
createAnimationFor: aMorph
self subclassResponsibility.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
code-generation
codeGeneration
createAnimationFor: aMorph withDuration: aNumber
self animationsEditor updateInformationText: 'Please select a valid Animation Field!'.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
defaults
defaultSubproperties
^ (OrderedCollection new).
^ (Dictionary new).
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
animation
resetTargetMorph

self targetMorph position: (self copyOfTargetMorph) position.
self targetMorph color: (self copyOfTargetMorph) color.
self targetMorph extent: (self copyOfTargetMorph) extent.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
animation
resetTargetMorphForAllProperties
self subproperties collect: [ :each | each resetTargetMorph ].
self subproperties valuesDo: [ :each | each resetTargetMorph ].
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
"copyOfTargetMorph:" : "DM 7/8/2020 13:45",
"createAnimationFor:" : "DM 8/6/2020 11:05",
"createAnimationFor:withDuration:" : "DM 8/6/2020 11:01",
"defaultSubproperties" : "DM 8/6/2020 10:59",
"defaultSubproperties" : "FH 5/13/2021 11:24",
"defaultTargetDuration" : "DM 8/6/2020 10:39",
"hasSubproperties" : "DM 8/6/2020 11:02",
"playAnimationWithDuration:" : "DM 8/6/2020 10:29",
"resetTargetMorph" : "DM 8/6/2020 10:33",
"resetTargetMorphForAllProperties" : "DM 8/5/2020 21:08",
"resetTargetMorph" : "FH 5/13/2021 12:03",
"resetTargetMorphForAllProperties" : "FH 5/13/2021 12:02",
"subproperties" : "DM 8/6/2020 10:58",
"subproperties:" : "DM 5/20/2020 14:04",
"targetDuration" : "DM 8/6/2020 10:39",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"defaultTargetColor" : "DM 8/7/2020 17:34",
"initialize" : "DM 7/7/2020 10:44",
"targetColor" : "DM 8/7/2020 17:19",
"targetColor:" : "DM 8/6/2020 10:41",
"targetColor:" : "LW 5/15/2021 13:57",
"targetColorAsString" : "DM 8/7/2020 10:49" } }
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
accessing
contents
^ self item subproperties sorted collect: [ :each |

^ self item subproperties sorted asOrderedCollection collect: [ :each |
self class
with: each
model: self model].
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
},
"instance" : {
"asString" : "DM 5/14/2020 15:02",
"contents" : "DM 8/6/2020 11:04",
"contents" : "FH 5/13/2021 12:22",
"hasContents" : "DM 5/20/2020 14:05",
"icon" : "DM 5/14/2020 14:00",
"setItem:model:parent:" : "DM 5/14/2020 15:11" } }
Loading

0 comments on commit b6f0b67

Please sign in to comment.