UISelectionPanel.st
author ca
Thu, 05 Jun 1997 11:58:17 +0200
changeset 142 75f927b856f6
parent 139 dc64ad7c0267
child 143 9add9e2609d9
permissions -rw-r--r--
update specs; remove color and default values

"
 COPYRIGHT (c) 1997 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"


ApplicationModel subclass:#UISelectionPanel
	instanceVariableNames:'selection selectors receiver'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-UIPainter'
!

View subclass:#Canvas
	instanceVariableNames:'inputView selection specification lastClickPoint labelHolder
		nameHolder'
	classVariableNames:''
	poolDictionaries:''
	privateIn:UISelectionPanel
!

DropObject subclass:#DropSpecification
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	privateIn:UISelectionPanel::Canvas
!

!UISelectionPanel class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1997 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

!

documentation
"
    implements a selection panel, keeping widgets which could be placed
    into the UIPainter by drag & drop.

    [author:]
        Claus Atzkern

    [see also:]
        TabView
        UIPainter

    [start with:]
        UISelectionPanel open

"

! !

!UISelectionPanel class methodsFor:'instance creation'!

newDefault
    |appl|

    appl := self new.

    appl labels:#( 'Button & Toggle'
                   'Panel'
                   'Text'
                   'View'
                   'Menu & Combo'
                   'Slider'
                 )

      selectors:#( #buttonToggleSpec
                   #panelSpec
                   #textSpec
                   #viewsSpec
                   #menuComboSpec
                   #sliderSpec
                 )
       receiver:self.

  ^ appl.
!

open
    |appl|

    appl := self newDefault.
    appl open.
    ^ appl.
! !

!UISelectionPanel class methodsFor:'interface specs'!

buttonToggleSpec
    "this window spec was automatically generated by the ST/X UIPainter"

    "do not manually edit this - the painter/builder may not be able to
     handle the specification if its corrupted."

    "
     UIPainter new openOnClass:UISelectionPanel andSelector:#buttonToggleSpec
     UISelectionPanel new openInterface:#buttonToggleSpec
    "

    <resource: #canvas>

    ^

       #(#FullSpec
          #'window:' 
           #(#WindowSpec
              #'name:' 'uIPainterView'
              #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
              #'label:' 'unnamed'
              #'bounds:' #(#Rectangle 0 0 439 193)
          )
          #'component:' 
           #(#SpecCollection
              #'collection:' 
               #(
                 #(#ArrowButtonSpec
                    #'name:' 'ArrowButton up'
                    #'layout:' #(#LayoutFrame 237 0 20 0 259 0 42 0)
                    #'isTriggerOnDown:' true
                    #'direction:' #up
                )
                 #(#ActionButtonSpec
                    #'name:' 'Button'
                    #'layout:' #(#LayoutFrame 20 0 20 0 119 0 42 0)
                    #'label:' 'Button'
                    #'isTriggerOnDown:' false
                )
                 #(#RadioButtonSpec
                    #'name:' 'RadioButton'
                    #'layout:' #(#LayoutFrame 127 0.0 20 0 226 0 42 0)
                    #'label:' 'RadioButton'
                    #'isTriggerOnDown:' true
                    #'showLamp:' true
                    #'lampColor:' #(#Color 100.0 100.0 0.0)
                )
                 #(#ArrowButtonSpec
                    #'name:' 'ArrowButton down'
                    #'layout:' #(#LayoutFrame 238 0 51 0 260 0 73 0)
                    #'hasCharacterOrientedLabel:' false
                    #'isTriggerOnDown:' true
                    #'direction:' #down
                )
                 #(#ArrowButtonSpec
                    #'name:' 'ArrowButton left'
                    #'layout:' #(#LayoutFrame 238 0 82 0 260 0 104 0)
                    #'hasCharacterOrientedLabel:' false
                    #'isTriggerOnDown:' true
                    #'direction:' #left
                )
                 #(#ArrowButtonSpec
                    #'name:' 'ArrowButton right'
                    #'layout:' #(#LayoutFrame 238 0 113 0 260 0 135 0)
                    #'hasCharacterOrientedLabel:' false
                    #'isTriggerOnDown:' true
                    #'direction:' #right
                )
                 #(#CheckToggleSpec
                    #'name:' 'CheckToggle'
                    #'layout:' #(#LayoutFrame 297 0 82 0 317 0 102 0)
                    #'isTriggerOnDown:' true
                    #'showLamp:' false
                    #'lampColor:' #(#Color 100.0 100.0 0.0)
                )
                 #(#ToggleSpec
                    #'name:' 'Toggle'
                    #'layout:' #(#LayoutFrame 297 0 20 0 396 0 42 0)
                    #'label:' 'Toggle'
                    #'isTriggerOnDown:' true
                    #'showLamp:' true
                    #'lampColor:' #(#Color 100.0 100.0 0.0)
                )
                 #(#CheckBoxSpec
                    #'name:' 'CheckBox'
                    #'layout:' #(#LayoutFrame 295 0 51 0 396 0 73 0)
                    #'tabable:' false
                    #'label:' 'CheckBox'
                    #'translateLabel:' false
                )
                 #(#ActionButtonSpec
                    #'name:' 'ok'
                    #'layout:' #(#LayoutFrame 20 0 51 0 119 0 73 0)
                    #'label:' 'ok'
                    #'model:' #accept
                    #'isTriggerOnDown:' false
                )
                 #(#ActionButtonSpec
                    #'name:' 'cancel'
                    #'layout:' #(#LayoutFrame 20 0 82 0 119 0 104 0)
                    #'label:' 'cancel'
                    #'model:' #cancel
                    #'isTriggerOnDown:' false
                )
                 #(#ActionButtonSpec
                    #'name:' 'help'
                    #'layout:' #(#LayoutFrame 20 0 113 0 119 0 135 0)
                    #'label:' 'help'
                    #'model:' #help
                    #'isTriggerOnDown:' false
                )
              )
          )
      )


!

menuComboSpec
    "this window spec was automatically generated by the ST/X UIPainter"

    "do not manually edit this - the painter/builder may not be able to
     handle the specification if its corrupted."

    "
     UIPainter new openOnClass:UISelectionPanel andSelector:#menuComboSpec
     UISelectionPanel new openInterface:#menuComboSpec
    "

    <resource: #canvas>

    ^
     
       #(#FullSpec
          #'window:' 
           #(#WindowSpec
              #'name:' 'uIPainterView'
              #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
              #'label:' 'unnamed'
              #'bounds:' #(#Rectangle 0 0 464 253)
          )
          #'component:' 
           #(#SpecCollection
              #'collection:' 
               #(
                 #(#ComboBoxSpec
                    #'name:' 'ComboBox'
                    #'layout:' #(#LayoutFrame 20 0 20 0 123 0 40 0)
                    #'immediateAccept:' true
                )
                 #(#ComboListSpec
                    #'name:' 'ComboList'
                    #'layout:' #(#LayoutFrame 20 0 51 0 123 0 71 0)
                    #'tabable:' false
                )
                 #(#PopUpListSpec
                    #'name:' 'PopUpList'
                    #'layout:' #(#LayoutFrame 147 0 20 0 250 0 42 0)
                    #'label:' 'PopUpList'
                )
                 #(#MenuPanelSpec
                    #'name:' 'MenuPanel'
                    #'layout:' #(#LayoutFrame 147 0 67 0 250 0 89 0)
                )
                 #(#TabViewSpec
                    #'name:' 'TabView'
                    #'layout:' #(#LayoutFrame 269 0 20 0 409 0 56 0)
                    #'tabWidget:' #Window
                    #'direction:' #top
                )
                 #(#NoteBookViewSpec
                    #'name:' 'noteBookView'
                    #'layout:' #(#LayoutFrame 269 0 66 0 409 0 182 0)
                    #'level:' 2
                )
                 #(#LabelSpec
                    #'name:' 'label1'
                    #'layout:' #(#LayoutFrame 147 0 51 0 250 0 67 0)
                    #'label:' 'MenuPanel'
                    #'canUIDrag:' false
                )
              )
          )
      )
!

panelSpec
    "this window spec was automatically generated by the ST/X UIPainter"

    "do not manually edit this - the painter/builder may not be able to
     handle the specification if its corrupted."

    "
     UIPainter new openOnClass:UISelectionPanel andSelector:#panelSpec
     UISelectionPanel new openInterface:#panelSpec
    "

    <resource: #canvas>

    ^

       #(#FullSpec
          #'window:' 
           #(#WindowSpec
              #'name:' 'uIPainterView'
              #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
              #'label:' 'unnamed'
              #'bounds:' #(#Rectangle 0 0 475 136)
          )
          #'component:' 
           #(#SpecCollection
              #'collection:' 
               #(
                 #(#HorizontalPanelViewSpec
                    #'name:' 'HorizontalPanelView'
                    #'layout:' #(#LayoutFrame 20 0 20 0 104 0 105 0)
                    #'component:' 
                     #(#SpecCollection
                        #'collection:' 
                         #(
                           #(#LabelSpec
                              #'name:' 'label1'
                              #'label:' 'A'
                              #'level:' 2
                              #'extent:' #(#Point 23 23)
                              #'canUIDrag:' false
                          )
                           #(#LabelSpec
                              #'name:' 'label2'
                              #'label:' 'B'
                              #'level:' 2
                              #'extent:' #(#Point 23 23)
                              #'canUIDrag:' false
                          )
                           #(#LabelSpec
                              #'name:' 'label3'
                              #'label:' 'C'
                              #'level:' 2
                              #'extent:' #(#Point 23 23)
                              #'canUIDrag:' false
                          )
                        )
                    )
                    #'horizontalLayout:' #center
                    #'verticalLayout:' #center
                    #'horizontalSpace:' 3
                    #'verticalSpace:' 3
                )
                 #(#VariableHorizontalPanelSpec
                    #'name:' 'VariableHorizontalPanel'
                    #'layout:' #(#LayoutFrame 249 0 20 0 337 0 105 0)
                    #'component:' 
                     #(#SpecCollection
                        #'collection:' 
                         #(
                           #(#LabelSpec
                              #'name:' 'label4'
                              #'label:' 'A'
                              #'level:' 2
                              #'canUIDrag:' false
                          )
                           #(#LabelSpec
                              #'name:' 'label5'
                              #'label:' 'B'
                              #'level:' 2
                              #'canUIDrag:' false
                          )
                        )
                    )
                )
                 #(#VerticalPanelViewSpec
                    #'name:' 'VerticalPanelView'
                    #'layout:' #(#LayoutFrame 110 0 20 0 168 0 105 0)
                    #'component:' 
                     #(#SpecCollection
                        #'collection:' 
                         #(
                           #(#LabelSpec
                              #'name:' 'label6'
                              #'label:' 'A'
                              #'level:' 2
                              #'extent:' #(#Point 23 23)
                              #'canUIDrag:' false
                          )
                           #(#LabelSpec
                              #'name:' 'label7'
                              #'label:' 'B'
                              #'level:' 2
                              #'extent:' #(#Point 23 23)
                              #'canUIDrag:' false
                          )
                           #(#LabelSpec
                              #'name:' 'label8'
                              #'label:' 'C'
                              #'level:' 2
                              #'extent:' #(#Point 23 23)
                              #'canUIDrag:' false
                          )
                        )
                    )
                    #'horizontalLayout:' #center
                    #'verticalLayout:' #center
                    #'horizontalSpace:' 3
                    #'verticalSpace:' 3
                )
                 #(#VariableVerticalPanelSpec
                    #'name:' 'VariableVerticalPanel'
                    #'layout:' #(#LayoutFrame 342 0 20 0 426 0 105 0)
                    #'component:' 
                     #(#SpecCollection
                        #'collection:' 
                         #(
                           #(#LabelSpec
                              #'name:' 'label9'
                              #'label:' 'A'
                              #'level:' 2
                              #'canUIDrag:' false
                          )
                           #(#LabelSpec
                              #'name:' 'label10'
                              #'label:' 'B'
                              #'level:' 2
                              #'canUIDrag:' false
                          )
                        )
                    )
                )
                 #(#PanelViewSpec
                    #'name:' 'PanelView'
                    #'layout:' #(#LayoutFrame 174 0 20 0 232 0 105 0)
                    #'component:' 
                     #(#SpecCollection
                        #'collection:' 
                         #(
                           #(#LabelSpec
                              #'name:' 'label11'
                              #'label:' 'A'
                              #'level:' 2
                              #'extent:' #(#Point 23 23)
                              #'canUIDrag:' false
                          )
                           #(#LabelSpec
                              #'name:' 'label12'
                              #'label:' 'B'
                              #'level:' 2
                              #'extent:' #(#Point 23 23)
                              #'canUIDrag:' false
                          )
                           #(#LabelSpec
                              #'name:' 'label13'
                              #'label:' 'C'
                              #'level:' 2
                              #'extent:' #(#Point 23 23)
                              #'canUIDrag:' false
                          )
                           #(#LabelSpec
                              #'name:' 'label14'
                              #'label:' 'D'
                              #'level:' 2
                              #'extent:' #(#Point 23 23)
                              #'canUIDrag:' false
                          )
                           #(#LabelSpec
                              #'name:' 'label15'
                              #'label:' 'E'
                              #'level:' 2
                              #'extent:' #(#Point 23 23)
                              #'canUIDrag:' false
                          )
                        )
                    )
                    #'horizontalLayout:' #fitSpace
                    #'verticalLayout:' #fitSpace
                    #'horizontalSpace:' 3
                    #'verticalSpace:' 3
                )
              )
          )
      )

!

sliderSpec
    "this window spec was automatically generated by the ST/X UIPainter"

    "do not manually edit this - the painter/builder may not be able to
     handle the specification if its corrupted."

    "
     UIPainter new openOnClass:UISelectionPanel andSelector:#sliderSpec
     UISelectionPanel new openInterface:#sliderSpec
    "

    <resource: #canvas>

    ^

       #(#FullSpec
          #'window:' 
           #(#WindowSpec
              #'name:' 'uIPainterView'
              #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
              #'label:' 'unnamed'
              #'bounds:' #(#Rectangle 0 0 445 162)
          )
          #'component:' 
           #(#SpecCollection
              #'collection:' 
               #(
                 #(#SliderSpec
                    #'name:' 'Vertical Slider'
                    #'layout:' #(#LayoutFrame 20 0 20 0 38 0 108 0)
                    #'orientation:' #vertical
                )
                 #(#ThumbWheelSpec
                    #'name:' 'Vertical ThumbWheel'
                    #'layout:' #(#LayoutFrame 48 0 20 0 63 0 108 0)
                    #'orientation:' #vertical
                    #'start:' 0
                    #'stop:' 360
                )
                 #(#ThumbWheelSpec
                    #'name:' 'Horizontal ThumbWheel'
                    #'layout:' #(#LayoutFrame 102 0 20 0 191 0 35 0)
                    #'orientation:' #horizontal
                    #'start:' 0
                    #'stop:' 360
                )
                 #(#SliderSpec
                    #'name:' 'Horizontal Slider'
                    #'layout:' #(#LayoutFrame 102 0 47 0 191 0 65 0)
                    #'orientation:' #horizontal
                    #'start:' 0
                    #'stop:' 100
                )
              )
          )
      )

!

textSpec
    "this window spec was automatically generated by the ST/X UIPainter"

    "do not manually edit this - the painter/builder may not be able to
     handle the specification if its corrupted."

    "
     UIPainter new openOnClass:UISelectionPanel andSelector:#textSpec
     UISelectionPanel new openInterface:#textSpec
    "

    <resource: #canvas>

    ^
     
       #(#FullSpec
          #'window:' 
           #(#WindowSpec
              #'name:' 'uIPainterView'
              #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
              #'label:' 'unnamed'
              #'bounds:' #(#Rectangle 0 0 467 207)
          )
          #'component:' 
           #(#SpecCollection
              #'collection:' 
               #(
                 #(#InputFieldSpec
                    #'name:' 'EditField'
                    #'layout:' #(#LayoutFrame 222 0 109 0 401 0 131 0)
                    #'immediateAccept:' true
                )
                 #(#LabelSpec
                    #'name:' 'Text Label'
                    #'layout:' #(#LayoutFrame 222 0 138 0 401 0 160 0)
                    #'label:' 'Text Label'
                )
                 #(#TextEditorSpec
                    #'name:' 'EditTextView'
                    #'layout:' #(#LayoutFrame 20 0 13 0 199 0 92 0)
                    #'hasHorizontalScrollBar:' true
                    #'hasVerticalScrollBar:' true
                )
                 #(#SequenceViewSpec
                    #'name:' 'SelectionInListView'
                    #'layout:' #(#LayoutFrame 222 0 12 0 401 0 91 0)
                    #'tabable:' false
                    #'hasHorizontalScrollBar:' true
                    #'hasVerticalScrollBar:' true
                )
                 #(#HTMLViewSpec
                    #'name:' 'HTMLView'
                    #'layout:' #(#LayoutFrame 23 0 109 0 202 0 188 0)
                    #'hasHorizontalScrollBar:' true
                    #'hasVerticalScrollBar:' true
                )
                 #(#LabelSpec
                    #'name:' 'HTMLViewLabel'
                    #'layout:' #(#LayoutFrame 99 0 169 0 164 0 183 0)
                    #'label:' 'HTMLView'
                    #'canUIDrag:' false
                )
                 #(#LabelSpec
                    #'name:' 'label1'
                    #'layout:' #(#LayoutFrame 91 0 73 0 153 0 87 0)
                    #'label:' 'EditText'
                    #'canUIDrag:' false
                )
                 #(#LabelSpec
                    #'name:' 'label2'
                    #'layout:' #(#LayoutFrame 297 0 73 0 384 0 87 0)
                    #'label:' 'SelectionInList'
                    #'canUIDrag:' false
                )
              )
          )
      )
!

viewsSpec
    "this window spec was automatically generated by the ST/X UIPainter"

    "do not manually edit this - the painter/builder may not be able to
     handle the specification if its corrupted."

    "
     UIPainter new openOnClass:UISelectionPanel andSelector:#viewsSpec
     UISelectionPanel new openInterface:#viewsSpec
    "

    <resource: #canvas>

    ^
     
       #(#FullSpec
          #'window:' 
           #(#WindowSpec
              #'name:' 'uIPainterView'
              #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
              #'label:' 'unnamed'
              #'bounds:' #(#Rectangle 0 0 485 245)
          )
          #'component:' 
           #(#SpecCollection
              #'collection:' 
               #(
                 #(#FramedBoxSpec
                    #'name:' 'FramedBox'
                    #'layout:' #(#LayoutFrame 8 0 20 0 110 0 85 0)
                    #'label:' 'FramedBox'
                    #'labelPosition:' #topCenter
                )
                 #(#ViewSpec
                    #'name:' 'View'
                    #'layout:' #(#LayoutFrame 124 0 20 0 206 0 85 0)
                )
                 #(#SubCanvasSpec
                    #'name:' 'SubCanvas'
                    #'layout:' #(#LayoutFrame 218 0 20 0 311 0 85 0)
                )
                 #(#LabelSpec
                    #'name:' 'subCanvasLabel'
                    #'layout:' #(#LayoutFrame 230 0 25 0 301 0 42 0)
                    #'label:' 'SubCanvas'
                    #'canUIDrag:' false
                )
                 #(#DividerSpec
                    #'name:' 'Horizontal Seperator'
                    #'layout:' #(#LayoutFrame 8 0 93 0 110 0 110 0)
                    #'orientation:' #horizontal
                )
                 #(#DividerSpec
                    #'name:' 'Vertical Seperator'
                    #'layout:' #(#LayoutFrame 124 0 93 0 143 0 171 0)
                    #'orientation:' #vertical
                )
                 #(#LabelSpec
                    #'name:' 'viewLabel'
                    #'layout:' #(#LayoutFrame 138 0 25 0 189 0 42 0)
                    #'label:' 'View'
                    #'canUIDrag:' false
                )
              )
          )
      )
!

windowSpec
    "this window spec was automatically generated by the ST/X UIPainter"

    "do not manually edit this - the painter/builder may not be able to
     handle the specification if its corrupted."

    "
     UIPainter new openOnClass:UISelectionPanel andSelector:#windowSpec
     UISelectionPanel new openInterface:#windowSpec
    "
    "UISelectionPanel open"

    <resource: #canvas>

    ^
     
       #(#FullSpec
          #'window:' 
           #(#WindowSpec
              #'name:' 'uIPainterView'
              #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
              #'label:' 'Component Gallery'
              #'bounds:' #(#Rectangle 0 0 480 260)
          )
          #'component:' 
           #(#SpecCollection
              #'collection:' 
               #(
                 #(#LabelSpec
                    #'name:' 'label1'
                    #'layout:' #(#LayoutFrame 0 0.0 -20 1.0 0 1.0 0 1.0)
                    #'label:' 'selection'
                    #'labelChannel:' #nameOfObject
                    #'level:' 2
                    #'hasCharacterOrientedLabel:' false
                )
                 #(#NoteBookViewSpec
                    #'name:' 'noteBookView1'
                    #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 -21 1.0)
                    #'menu:' #tabList
                    #'model:' #tabModel
                    #'tabWidget:' #Window
                    #'useIndex:' true
                    #'level:' 2
                    #'canvas:' #canvas
                )
              )
          )
      )
! !

!UISelectionPanel methodsFor:'accessing'!

labels:loLabels selectors:loSelectors receiver:aReceiver
    selectors := loSelectors.
    receiver := aReceiver.
    (self tabList) value:loLabels.

! !

!UISelectionPanel methodsFor:'aspects'!

canvas
    |holder|

    (holder := builder bindingAt:#canvas) isNil ifTrue:[
        builder aspectAt:#canvas put:(holder := Canvas new)
    ].
    ^ holder
!

nameOfObject
    |holder canvas|

    (holder := builder bindingAt:#nameOfObject) isNil ifTrue:[
        builder aspectAt:#nameOfObject put:(holder := ValueHolder new).
        canvas := self canvas.
        canvas nameHolder:holder.
    ].
    ^ holder
!

tabList
    "returns list of tab-labels
    "
    |holder|

    (holder := builder bindingAt:#tabList) isNil ifTrue:[
        builder aspectAt:#tabList put:(holder := ValueHolder new).
    ].
    ^ holder
!

tabModel
    "returns my model; catching select notifications
    "
    |holder|

    (holder := builder bindingAt:#tabModel) isNil ifTrue:[
        holder := AspectAdaptor new subject:self; forAspect:#selection.
        builder aspectAt:#tabModel put:holder.
    ].
    ^ holder

! !

!UISelectionPanel methodsFor:'selection'!

selection
    ^ selection
!

selection:aValue
    |spec|

    (aValue isNil or:[aValue == 0]) ifTrue:[
        ^ self
    ].
    selection ~~ aValue ifTrue:[
        (selection := aValue) notNil ifTrue:[
            selectors size >= aValue ifTrue:[
                spec := receiver perform:(selectors at:selection)
            ]
        ].
        (builder aspectAt:#canvas) specification:spec
    ].
! !

!UISelectionPanel::Canvas methodsFor:'accessing'!

nameHolder:aValueHolder
    "set value holder which keeps the name of the object
     under the cursor or selected
    "
    nameHolder := aValueHolder
!

specification:aSpecOrSpecArray
    "load a new specification
    "
    |builder|

    self selection:nil.

    self subViews copy do:[:aSubView|
        aSubView ~~ inputView ifTrue:[
            aSubView destroy
        ]
    ].

    aSpecOrSpecArray notNil ifTrue:[
        specification := UISpecification from:aSpecOrSpecArray.
        builder := UIBuilder new.
        specification buildViewFor:builder in:self.
        self realizeAllSubViews.
        inputView raise.
    ] ifFalse:[
        specification := nil
    ]

! !

!UISelectionPanel::Canvas methodsFor:'drag & drop'!

buildSpecFrom:aSpec
    "build spec out of spec
    "
    |spec comp coll|

    (aSpec notNil and:[aSpec canUIDrag]) ifFalse:[
        ^ nil
    ].

    spec := aSpec copy.

    (aSpec class supportsSubComponents and:[aSpec component notNil]) ifFalse:[
        ^ spec
    ].
    comp := aSpec component.
    spec component:nil.

    comp canUIDrag ifFalse:[
      ^ spec
    ].
    coll := OrderedCollection new.

    comp do:[:anEntry||spc|
        (spc := self buildSpecFrom:anEntry) notNil ifTrue:[
            coll add:spc
        ]
    ].
    coll isEmpty ifTrue:[
      ^ spec
    ].
    comp := comp copy.
    comp collection:coll.
    spec component:comp.
  ^ spec


!

startDrag
    "start drag of selection
    "
    |dragObj spec name|

    spec := self findSpecFor:selection.

    spec notNil ifTrue:[
        spec := self buildSpecFrom:spec.
        name := spec className asString.
        name := name copyFrom:1 to:(name size - ('Spec' size) + 1). 
        name at:1 put:(name at:1) asLowercase.
        name at:(name size) put:$1.
        spec name:name.

        self showUnselected.
        dragObj := DropSpecification for:selection specification:spec.
        self showSelected.
        DragAndDropManager startDrag:dragObj from:inputView.
    ]


! !

!UISelectionPanel::Canvas methodsFor:'event handling'!

buttonMotion:state x:x y:y
    "start a drag on selection
    "
    |obj sensor|

    (state ~~ 0 and:[selection notNil]) ifTrue:[
        sensor := self sensor.
        sensor anyButtonPressed ifTrue:[
            (lastClickPoint dist:(x@y)) > 10.0 ifTrue:[
                self startDrag
            ]
        ]
    ] ifFalse:[
        (nameHolder notNil and:[(obj := self findObjectAtX:x y:y) notNil]) ifTrue:[
            nameHolder value:(obj name)
        ]
    ]

!

buttonPress:button x:x y:y
    "change selection
    "
    lastClickPoint := Point x:x y:y.
    self selection:(self findObjectAtX:x y:y).


!

exposeX:x y:y width:w height:h
    "handle an expose event from device; redraw selection
    "
    super exposeX:x y:y width:w height:h.
    self showSelected.


! !

!UISelectionPanel::Canvas methodsFor:'initialization'!

initialize
    super initialize.

    inputView := InputView origin:0.0@0.0 extent:1.0@1.0 in:self.

    inputView eventReceiver:self.
    inputView enableButtonEvents.
    inputView enableButtonMotionEvents.
    inputView enableMotionEvents.

! !

!UISelectionPanel::Canvas methodsFor:'searching'!

findObjectAtX:x y:y
    "find the origin/corner of the currentWidget
    "
    |view viewId point|

    point   := Point x:x y:y.
    point   := device translatePoint:point from:(inputView id)
                                             to:(inputView device rootView id).
    inputView lower.
    viewId := device viewIdFromPoint:point in:(self id).
    view   := device viewFromId:viewId.
    inputView raise.

    (view ~~ self and:[view ~~ inputView]) ifTrue:[
        (self findSpecFor:view) notNil ifTrue:[
             ^ view
        ]
    ].
    ^ nil




!

findSpecFor:anObject
    "returns subspec assigned to instance or nil
    "
    |name components spec|

    anObject notNil ifTrue:[
        name := anObject name.

        specification do:[:aSpec|
            aSpec name = name ifTrue:[
                aSpec canUIDrag ifTrue:[^ aSpec]
                               ifFalse:[^ nil]
            ]
        ]
    ].
    ^ nil

! !

!UISelectionPanel::Canvas methodsFor:'selection'!

handlesOf:aComponent do:aOneArgBlock
    "evaluate the block on each handle; the argument to the block
     is a rectangle
    "
    aComponent notNil ifTrue:[
        aOneArgBlock value:(aComponent origin       - (4@4) extent:7@7).
        aOneArgBlock value:(aComponent corner       - (4@4) extent:7@7).
        aOneArgBlock value:(aComponent topRight     - (4@4) extent:7@7).
        aOneArgBlock value:(aComponent bottomLeft   - (4@4) extent:7@7).
        aOneArgBlock value:(aComponent leftCenter   - (4@4) extent:7@7).
        aOneArgBlock value:(aComponent rightCenter  - (4@4) extent:7@7).
        aOneArgBlock value:(aComponent topCenter    - (4@4) extent:7@7).
        aOneArgBlock value:(aComponent bottomCenter - (4@4) extent:7@7).
    ]

!

selection:anObject
    "selection changed
    "
    |name|

    selection ~~ anObject ifTrue:[
        self showUnselected.
        (self findSpecFor:anObject) notNil ifTrue:[
            selection := anObject.
            name := anObject name.
            self showSelected
        ] ifFalse:[
            selection := nil
        ].
        nameHolder notNil ifTrue:[nameHolder value:name]
    ]

!

showSelected
    "show selected
    "
    selection notNil ifTrue:[
        self clippedByChildren:false.

        self handlesOf:selection do:[:aRectangle|
            self fillRectangle:aRectangle
        ].
        self clippedByChildren:true.
    ].


!

showUnselected
    "show unselected
    "
    |r|

    selection isNil ifTrue:[
        ^ self
    ].

    self clippedByChildren:false.

    self handlesOf:selection do:[:aRectangle|
        self clearRectangle:aRectangle
    ].
    self clippedByChildren:true.

"must redraw all components which are affected b the handles
"
    r := (selection originRelativeTo:self) - (4@4) extent:(selection extent + (4@4)).

    self subViews do:[:aComponent |
        |absOrg absFrame|

        aComponent ~~ inputView ifTrue:[
            absOrg   := aComponent originRelativeTo:self.
            absFrame := absOrg extent:(aComponent extent).

            (absFrame intersects:r) ifTrue:[
                aComponent withAllSubViewsDo:[:aView|
                    aView clear.
                    aView exposeX:0 y:0 width:9999 height:9999.
                ]
            ]
        ]
    ]


! !

!UISelectionPanel::Canvas::DropSpecification class methodsFor:'instance creation'!

for:aView specification:aSpec
    "create drop object for a view derived from a specification
    "
    aView topView raise.
    aView device sync.
    aView invalidate.
    aView windowGroup processExposeEvents.
    DisplayObject := Image fromView:aView grab:false.

    DisplayObject extent ~= aView extent ifTrue:[
        DisplayObject := Form extent:(aView extent) depth:1.
        DisplayObject colorMap:(Array with:Color white with:Color black).
        DisplayObject fill:(Color colorId:0).
        DisplayObject paint:(Color colorId:1).
        DisplayObject displayRectangleX:0 y:0 width:aView extent x height:aView extent y.
    ].

    ^ self new theObject:aSpec


! !

!UISelectionPanel class methodsFor:'documentation'!

version
    ^ '$Header$'
! !