54 lines
1.1 KiB
Smalltalk
54 lines
1.1 KiB
Smalltalk
"
|
|
Leaf node. Any content node is leaf
|
|
"
|
|
Class {
|
|
#name : #GrafoscopioLeafNode,
|
|
#superclass : #GrafoscopioAbstractNode,
|
|
#instVars : [
|
|
'parent'
|
|
],
|
|
#category : #'Grafoscopio-Model'
|
|
}
|
|
|
|
{ #category : #testing }
|
|
GrafoscopioLeafNode class >> isLeaf [
|
|
^ true
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
GrafoscopioLeafNode >> acceptVisitor: aGrafoscopioVisitor [
|
|
aGrafoscopioVisitor visitLeafNode: self.
|
|
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
GrafoscopioLeafNode >> addChild: aBlock ofClass: aClass [
|
|
self error: 'Leaf nodes are abstract. '
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
GrafoscopioLeafNode >> level [
|
|
"Returns the level of the node. See the setter message for details"
|
|
|
|
^ parent ifNil: [ 0 ] ifNotNil: [ 1 + parent level ]
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
GrafoscopioLeafNode >> parent [
|
|
"Returns the parent of the current node"
|
|
^ parent
|
|
]
|
|
|
|
{ #category : #accessing }
|
|
GrafoscopioLeafNode >> parent: aNode [
|
|
"A parent is a node that has the current node in its children"
|
|
aNode ifNil: [
|
|
parent := aNode.
|
|
^self ].
|
|
aNode parent = self ifTrue: [ ^ self ].
|
|
parent := aNode.
|
|
(aNode children includes: self)
|
|
ifFalse: [ aNode addNode: self ]
|
|
|
|
]
|