"This method first removes aTree from whatever tree it is already in (if any) and then it adds it as the left child of the receiver."
(leftChild notNil) ifTrue: [
leftChild remove
].
(aTree notNil) ifTrue: [
aTree remove.
aTree parent: self
].
leftChild _ aTree! !
!Tree methodsFor: 'tree functions'!
addRightChild: aTree
"This method first removes aTree from whatever tree it is already in (if any) and then it adds it as the right child of the receiver."
(rightChild notNil) ifTrue: [
rightChild remove
].
(aTree notNil) ifTrue: [
aTree remove.
aTree parent: self
].
rightChild _ aTree! !
!Tree methodsFor: 'tree functions'!
remove
"This method removes the receiver from whatever tree it is in (if any)."
(parent notNil) ifTrue: [
(parent leftChild = self) ifTrue: [
parent leftChild: nil
].
(parent rightChild = self) ifTrue: [
parent rightChild: nil
]
].
parent _ nil! !
!Tree methodsFor: 'tree functions'!
remove: aLabel
"Search the tree whose root is the receiver for a node labelled with aLabel and remove that node. Return the modified tree's new root."
^ self "Unimplemented..."! !
!Tree methodsFor: 'tree functions'!
removeNode: aNode
"This method is passed aNode. It searches the sub-tree self for the node and removes it. (It does not remove the children of aNode.) If the tree contains aNode, it returns the modified sub-tree, otherwise it returns 'false'."
| gotIt |
(self = aNode) ifTrue: [
^ self removeRoot
].
leftChild notNil ifTrue: [
gotIt _ leftChild removeNode: aNode.
(gotIt ~~ false) ifTrue: [^ self]
].
rightChild notNil ifTrue: [
gotIt _ rightChild removeNode: aNode.
(gotIt ~~ false) ifTrue: [^ self]
].
^false! !
!Tree methodsFor: 'tree functions'!
removeRoot
"This method returns a sub-tree containing all the nodes in the tree whose root is the receiver, except the root node. If the left sub-tree is nil, it just returns the right sub-tree. Otherwise, it adds the right sub-tree as the right child of the left sub-tree's right-most descendent and returns the modified left sub-tree."
"This sub-tree is to display itself on the given Form. It displays arcs leading down to its sub-trees and then uses itself recursively to obtain a display of its sub-trees."
| leftPoint rightPoint bottomPoint aBitBlt |
"DISPLAY THE NODE ICON."
NodeIcon
displayOn: Display
at: (aPoint x - 12) @ (aPoint y)
clippingBox: clipBox.
(aTree label asDisplayText)
displayOn: Display
at: (aPoint x - 3) @ (aPoint y + 3)
clippingBox: clipBox.
"SET UP A BITBLT FOR USE BELOW."
aBitBlt _ BitBlt
destForm: Display
sourceForm: (Form extent: 1@1) fillBlack
fillColor: Color black
combinationRule: 3
destOrigin: 0 @ 0
sourceOrigin: 0 @ 0
extent: Display computeBoundingBox extent
clipRect: clipBox.
"DISPLAY THE LEFT SUB-TREE AND A LINE DOWN TO IT."
bottomPoint _ (aPoint x ) @ (aPoint y + 24).
leftPoint _ (aPoint x - xIncr) @ (aPoint y + yIncr).
(aTree leftChild) notNil ifTrue: [
aBitBlt drawFrom: bottomPoint to: leftPoint.
self
displayNode: aTree leftChild
at: leftPoint
clippingBox: clipBox
xIncr: xIncr//2
yIncr: yIncr
].
"DISPLAY THE RIGHT SUB-TREE AND A LINE DOWN TO IT."
rightPoint _ (aPoint x + xIncr) @ (aPoint y + yIncr).
"This routine is called to display the tree. It makes use of the (inherited) instance variable 'model' and of the 'insetDisplayBox' instance variable to find out what area of the screen is to be displayed on."
"Imagine that we are displaying this tree, but do not display anything. Instead, ask which node would contain mousePoint within its NodeIcon and return that node. Return nil if no node contains mousePoint."
| whereWouldBeDisplayed leftPoint ans rightPoint |
"SEE WHERE WE WOULD HAVE DISPLAYED NodeIcon AND SEE IF IT CONTAINS mousePoint."
whereWouldBeDisplayed _
((aPoint x - 12) @ (aPoint y) extent: (NodeIcon extent))