UIPainterTreeView.st
changeset 43 3dd91a85c243
child 49 7f58dd5fc836
equal deleted inserted replaced
42:877a25e8f5aa 43:3dd91a85c243
       
     1 "
       
     2  COPYRIGHT (c) 1995 by Claus Gittinger
       
     3 	      All Rights Reserved
       
     4 
       
     5  This software is furnished under a license and may be used
       
     6  only in accordance with the terms of that license and with the
       
     7  inclusion of the above copyright notice.   This software may not
       
     8  be provided or otherwise made available to, or used by, any
       
     9  other person.  No title to or ownership of the software is
       
    10  hereby transferred.
       
    11 "
       
    12 
       
    13 ObjectView subclass:#UIPainterTreeView
       
    14 	instanceVariableNames:'builderView indent yPos maxX'
       
    15 	classVariableNames:''
       
    16 	poolDictionaries:''
       
    17 	category:'Interface-UIPainter'
       
    18 !
       
    19 
       
    20 !UIPainterTreeView class methodsFor:'documentation'!
       
    21 
       
    22 copyright
       
    23 "
       
    24  COPYRIGHT (c) 1995 by Claus Gittinger
       
    25 	      All Rights Reserved
       
    26 
       
    27  This software is furnished under a license and may be used
       
    28  only in accordance with the terms of that license and with the
       
    29  inclusion of the above copyright notice.   This software may not
       
    30  be provided or otherwise made available to, or used by, any
       
    31  other person.  No title to or ownership of the software is
       
    32  hereby transferred.
       
    33 "
       
    34 !
       
    35 
       
    36 documentation
       
    37 "
       
    38     not yet finished, not yet published, not yet released.
       
    39 "
       
    40 ! !
       
    41 
       
    42 !UIPainterTreeView class methodsFor:'startup'!
       
    43 
       
    44 start
       
    45     |topView v|
       
    46 
       
    47     topView := StandardSystemView 
       
    48 		    label:'View hierarchy'
       
    49 		    icon:(Form fromFile:'BuildTreeV.icon' resolution:100).
       
    50     v  := HVScrollableView for:self in:topView.
       
    51     v origin:(0 @ 0) extent:(1.0 @ 1.0).
       
    52 
       
    53     topView realize.
       
    54     ^ v scrolledView
       
    55 
       
    56     "BuilderTreeView start"
       
    57 
       
    58 
       
    59 ! !
       
    60 
       
    61 !UIPainterTreeView methodsFor:'BuilderView interface'!
       
    62 
       
    63 builderView:aBuilderView
       
    64     builderView := aBuilderView.
       
    65 
       
    66 
       
    67 !
       
    68 
       
    69 selectName:aString
       
    70     contents do:[:obj |
       
    71         (obj text asString withoutSeparators = aString) ifTrue:[
       
    72             ^ self select:obj.
       
    73         ]
       
    74    ]
       
    75 
       
    76 !
       
    77 
       
    78 selectNameAdd:aString
       
    79     contents do:[:obj |
       
    80         (obj text asString withoutSeparators = aString) ifTrue:[
       
    81             ^ self addToSelection:obj.
       
    82         ]
       
    83    ]
       
    84 
       
    85 
       
    86 !
       
    87 
       
    88 update:something
       
    89     |sel|
       
    90 
       
    91     something == #tree ifTrue:[
       
    92         ^ self updateTree.
       
    93     ].
       
    94 
       
    95     something == #widgetName ifTrue:[
       
    96         self updateTree
       
    97     ] ifFalse:[
       
    98         something == #selection ifFalse:[
       
    99             ^ self
       
   100         ]
       
   101     ].
       
   102 
       
   103     sel := builderView selection.
       
   104 
       
   105     (sel isKindOf:Collection) ifTrue:[
       
   106         sel do:[:v | self selectNameAdd:(builderView variableNameOf:v)]
       
   107     ] ifFalse:[
       
   108         self selectName:(builderView variableNameOf:sel)
       
   109     ]
       
   110 
       
   111 ! !
       
   112 
       
   113 !UIPainterTreeView methodsFor:'drawing'!
       
   114 
       
   115 showSelected:anObject
       
   116     "show an object as selected"
       
   117 
       
   118     |oldFg oldBg|
       
   119 
       
   120     oldFg := anObject foreground.
       
   121     oldBg := anObject background.
       
   122     anObject foreground:oldBg.
       
   123     anObject background:oldFg.
       
   124     anObject drawIn:self.
       
   125     anObject foreground:oldFg.
       
   126     anObject background:oldBg
       
   127 
       
   128     "Modified: 31.8.1995 / 13:52:02 / claus"
       
   129 ! !
       
   130 
       
   131 !UIPainterTreeView methodsFor:'generating the class-tree picture'!
       
   132 
       
   133 addToTree:name indent:indent
       
   134     |newObject|
       
   135 
       
   136     newObject := DrawText new.
       
   137     "newObject font:font.  "
       
   138     newObject text:name.
       
   139     newObject origin:((indent asInteger + margin) @ yPos).
       
   140     newObject foreground:Color black. "/ foreground.
       
   141     newObject background:Color white. "/background.
       
   142     newObject linePattern:1; fillPattern:1. "/ opaque
       
   143     yPos := yPos + newObject frame height.
       
   144     self add:newObject.
       
   145     maxX := maxX max:(newObject frame corner x).
       
   146 
       
   147     "Modified: 5.9.1995 / 23:54:26 / claus"
       
   148 !
       
   149 
       
   150 addViewsToTreeFrom:aView indent:currentIndent
       
   151     |name|
       
   152 
       
   153     name := builderView variableNameOf:aView.
       
   154     self addToTree:name indent:currentIndent.
       
   155 
       
   156     builderView subviewsOf:aView do:[:subview |
       
   157         self addViewsToTreeFrom:subview
       
   158                            indent:(currentIndent + indent)
       
   159     ]
       
   160 !
       
   161 
       
   162 updateTree
       
   163     self removeAll.
       
   164     maxX := 0.
       
   165     yPos := (self verticalPixelPerMillimeter:1) rounded asInteger.
       
   166     self addViewsToTreeFrom:builderView indent:(self horizontalPixelPerMillimeter:1).
       
   167     self contentsChanged
       
   168 
       
   169     "Modified: 5.9.1995 / 23:54:35 / claus"
       
   170 ! !
       
   171 
       
   172 !UIPainterTreeView methodsFor:'initialization'!
       
   173 
       
   174 initialize
       
   175     super initialize.
       
   176 
       
   177     maxX := 0.
       
   178     yPos := (self verticalPixelPerMillimeter:1) rounded asInteger.
       
   179     indent := (self horizontalPixelPerMillimeter:5) rounded asInteger.
       
   180     sorted := true.
       
   181     pressAction := [:aPoint | self click:aPoint].
       
   182     shiftPressAction := [:aPoint | self shiftClick:aPoint]
       
   183 
       
   184     "Modified: 6.9.1995 / 00:11:48 / claus"
       
   185 !
       
   186 
       
   187 initializeMiddleButtonMenu
       
   188     |labels|
       
   189 
       
   190     labels := resources array:#(
       
   191                         'inspect view'
       
   192                         'inspect properties'
       
   193                        ).
       
   194 
       
   195     self middleButtonMenu:(PopUpMenu
       
   196                                 labels:labels
       
   197                              selectors:#(
       
   198                                          inspectView
       
   199                                          inspectProps
       
   200                                         )
       
   201                                 receiver:self
       
   202                                      for:self)
       
   203 ! !
       
   204 
       
   205 !UIPainterTreeView methodsFor:'private'!
       
   206 
       
   207 selectedName
       
   208     selection isNil ifTrue:[^ nil].
       
   209     ^ selection text asString withoutSeparators
       
   210 !
       
   211 
       
   212 withSelectedNameDo:aBlock
       
   213     |name|
       
   214 
       
   215     name := self selectedName.
       
   216     name notNil ifTrue:[aBlock value:name]
       
   217 ! !
       
   218 
       
   219 !UIPainterTreeView methodsFor:'queries'!
       
   220 
       
   221 heightOfContents
       
   222     ^ yPos  + (self verticalPixelPerMillimeter:1) rounded
       
   223 
       
   224     "Modified: 6.9.1995 / 12:56:24 / claus"
       
   225 !
       
   226 
       
   227 widthOfContents
       
   228     ^ maxX + (self horizontalPixelPerMillimeter:1) rounded
       
   229 
       
   230     "Modified: 6.9.1995 / 12:56:28 / claus"
       
   231 ! !
       
   232 
       
   233 !UIPainterTreeView methodsFor:'user interaction'!
       
   234 
       
   235 click:aPoint
       
   236     |anObject|
       
   237 
       
   238     anObject := self findObjectAtVisible:aPoint.
       
   239     (anObject ~~ selection) ifTrue:[
       
   240         self unselect.
       
   241         anObject notNil ifTrue:[
       
   242             self select:anObject.
       
   243             builderView selectName:(self selectedName)
       
   244         ] ifFalse:[
       
   245             builderView selectName:'self'
       
   246         ]
       
   247     ]
       
   248 
       
   249 
       
   250 
       
   251 
       
   252 !
       
   253 
       
   254 inspectProps
       
   255     builderView inspectAttributes
       
   256 !
       
   257 
       
   258 inspectView
       
   259     builderView inspectSelection
       
   260 !
       
   261 
       
   262 shiftClick:aPoint
       
   263     |anObject|
       
   264 
       
   265     anObject := self findObjectAtVisible:aPoint.
       
   266 
       
   267     anObject notNil ifTrue:[
       
   268         (self isSelected:anObject) ifTrue:[
       
   269             builderView removeNameFromSelection:anObject text asString withoutSeparators
       
   270         ] ifFalse:[
       
   271             builderView addNameToSelection:anObject text asString withoutSeparators
       
   272         ]
       
   273     ]
       
   274 
       
   275 
       
   276 
       
   277 
       
   278 
       
   279 
       
   280 ! !
       
   281 
       
   282 !UIPainterTreeView class methodsFor:'documentation'!
       
   283 
       
   284 version
       
   285     ^ '$Header$'
       
   286 ! !