UISpecificationTool.st
author Claus Gittinger <cg@exept.de>
Sat, 21 Jul 2012 18:58:03 +0200
changeset 2898 c7f6c498df6a
parent 2830 aec9b9fd5c17
child 2902 2a7a9d68d16c
permissions -rw-r--r--
category of:15 methods
     1 "
     2  COPYRIGHT (c) 1995 by eXept Software AG
     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 "{ Package: 'stx:libtool2' }"
    13 
    14 ApplicationModel subclass:#UISpecificationTool
    15 	instanceVariableNames:'modifiedHolder aspects specification selection specChannel
    16 		buildInView listOfSpecViews'
    17 	classVariableNames:''
    18 	poolDictionaries:''
    19 	category:'Interface-UIPainter'
    20 !
    21 
    22 ViewScroller subclass:#BuildInView
    23 	instanceVariableNames:''
    24 	classVariableNames:''
    25 	poolDictionaries:''
    26 	privateIn:UISpecificationTool
    27 !
    28 
    29 !UISpecificationTool class methodsFor:'documentation'!
    30 
    31 copyright
    32 "
    33  COPYRIGHT (c) 1995 by eXept Software AG
    34               All Rights Reserved
    35 
    36  This software is furnished under a license and may be used
    37  only in accordance with the terms of that license and with the
    38  inclusion of the above copyright notice.   This software may not
    39  be provided or otherwise made available to, or used by, any
    40  other person.  No title to or ownership of the software is
    41  hereby transferred.
    42 "
    43 
    44 
    45 
    46 !
    47 
    48 documentation
    49 "
    50     used by the UIPainter to manipulate the specifications of the selected component
    51 
    52     [author:]
    53         Claus Atzkern
    54 
    55     [see also:]
    56         UIPainter
    57         UILayoutTool
    58         UIHelpTool
    59 "
    60 ! !
    61 
    62 !UISpecificationTool class methodsFor:'help specs'!
    63 
    64 helpSpec
    65     "This resource specification was automatically generated
    66      by the UIHelpTool of ST/X."
    67 
    68     "Do not manually edit this!! If it is corrupted,
    69      the UIHelpTool may not be able to read the specification."
    70 
    71     "
    72      UIHelpTool openOnClass:UISpecificationTool    
    73     "
    74 
    75     <resource: #help>
    76 
    77     ^ super helpSpec addPairsFrom:#(
    78 
    79 #allowNilColor
    80 'Add an option to allow a nil-Color to be choosen'
    81 
    82 #allowSymbolicColors
    83 'ColorMenu is allowed to return a symbolic color name'
    84 
    85 #allowSymbolicFonts
    86 'FontMenu is allowed to return a symbolic font name'
    87 
    88 #browseAction
    89 'Browse/Create the Action method.'
    90 
    91 #browseAspectMethod
    92 'Browse/Create the Aspect method.'
    93 
    94 #editListSpec
    95 'Edit the contents of the list (inline)'
    96 
    97 #labelsAreColored
    98 'Draw the labels in their color (otherwise, draw the background)'
    99 
   100 #showFrame
   101 'Show the frame'
   102 
   103 #showUseDefaultToggle
   104 'Add a toggle to choose the "default" color (resulting color will be nil)'
   105 
   106 )
   107 ! !
   108 
   109 !UISpecificationTool class methodsFor:'image specs'!
   110 
   111 browseActionImage
   112     ^ UIPainter browseActionImage
   113 !
   114 
   115 editTableIcon
   116     ^ UIPainter editTableIcon
   117 ! !
   118 
   119 !UISpecificationTool class methodsFor:'interface specs'!
   120 
   121 windowSpec
   122     "This resource specification was automatically generated
   123      by the UIPainter of ST/X."
   124 
   125     "Do not manually edit this!! If it is corrupted,
   126      the UIPainter may not be able to read the specification."
   127 
   128     "
   129      UIPainter new openOnClass:UISpecificationTool andSelector:#windowSpec
   130      UISpecificationTool new openInterface:#windowSpec
   131      UISpecificationTool open
   132     "
   133 
   134     <resource: #canvas>
   135 
   136     ^ 
   137      #(#FullSpec
   138         #name: #windowSpec
   139         #window: 
   140        #(#WindowSpec
   141           #label: 'unnamed canvas'
   142           #name: 'unnamed canvas'
   143           #bounds: #(#Rectangle 12 22 312 322)
   144         )
   145         #component: 
   146        #(#SpecCollection
   147           #collection: #(
   148            #(#ArbitraryComponentSpec
   149               #name: 'BuildInView'
   150               #layout: #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
   151               #hasVerticalScrollBar: true
   152               #miniScrollerVertical: true
   153               #autoHideScrollBars: true
   154               #hasBorder: false
   155               #component: #buildInView
   156             )
   157            )
   158          
   159         )
   160       )
   161 ! !
   162 
   163 !UISpecificationTool class methodsFor:'resources'!
   164 
   165 classResources
   166     "my translations are found in the UIPainter classes resources"
   167 
   168     ^ UIPainter classResources 
   169 ! !
   170 
   171 !UISpecificationTool methodsFor:'accessing-channels'!
   172 
   173 modifiedHolder:aValueHolder
   174     "set the value holder set to true in case of modifying attributes
   175     "
   176 
   177     modifiedHolder removeDependent:self.
   178 
   179     (modifiedHolder := aValueHolder) notNil ifTrue:[
   180         modifiedHolder addDependent:self.
   181     ].
   182 
   183 ! !
   184 
   185 !UISpecificationTool methodsFor:'accessing-specification'!
   186 
   187 listOfAspects
   188     ^ masterApplication listOfAspects
   189 
   190     "Created: / 12-01-2008 / 19:24:39 / cg"
   191 !
   192 
   193 listOfCallbacks
   194     ^ masterApplication listOfCallbacks
   195 
   196     "Created: / 12-01-2008 / 19:25:05 / cg"
   197 !
   198 
   199 specification
   200     "gets current edit specification
   201     "
   202     ^ specification
   203 
   204 
   205 !
   206 
   207 specification:aSpec
   208     "sets current edit specification
   209     "
   210     aSpec notNil ifTrue:[
   211         "/ same type of spec - simply change the spec;  no need to setup everything
   212         specification class == aSpec class ifTrue:[
   213             specification := aSpec.
   214             specChannel value:specification.
   215           ^ self
   216         ]
   217     ].
   218 
   219     "/ release resources
   220     specChannel release.
   221     aspects     release.
   222     selection := listOfSpecViews := nil.
   223     buildInView destroyAllClientViews.
   224 
   225     (specification := aSpec) isNil ifTrue:[
   226         aspects := specChannel := nil.
   227       ^ self
   228     ].
   229     
   230     "/ some tricky specs need the builder during the addBindings phase.
   231     "/ This is passed down in a special UIBindingsDictionary
   232     "/ (remain backward compatible)
   233 
   234     aspects := UISpecification newBindingsDictionary.
   235     aspects builder:builder.
   236     aspects at:#modifiedChannel put:modifiedHolder.
   237     aspects at:#acceptChannel   put:self acceptChannel.
   238 
   239     aspects at:#listOfAspects put:[self listOfAspects].
   240     aspects at:#listOfCallbacks put:[self listOfCallbacks].
   241 
   242     specChannel := specification asValue.
   243     specification class addBindingsTo:aspects for:specification channel:specChannel.
   244 
   245     "/ arrange for being notified, if any aspect changes
   246     aspects do:[:el| el addDependent:self ].
   247 
   248     "Modified: / 12-01-2008 / 19:28:47 / cg"
   249 ! !
   250 
   251 !UISpecificationTool methodsFor:'actions'!
   252 
   253 setMaxExtent
   254     "set the windows maxExtent from its current extent"
   255 
   256     |canvas currentExtent|
   257 
   258     canvas := self masterApplication canvas.
   259     currentExtent := canvas extent.
   260     (self aspectFor:#maxX) value:currentExtent x.
   261     (self aspectFor:#maxY) value:currentExtent y.
   262 
   263     "Modified: / 29.10.1997 / 18:29:17 / cg"
   264 !
   265 
   266 setMinExtent
   267     "set the windows minExtent from its current extent"
   268 
   269     |canvas currentExtent|
   270 
   271     canvas := self masterApplication canvas.
   272     currentExtent := canvas extent.
   273     (self aspectFor:#minX) value:currentExtent x.
   274     (self aspectFor:#minY) value:currentExtent y.
   275 
   276     "Created: / 29.10.1997 / 18:17:55 / cg"
   277     "Modified: / 29.10.1997 / 18:28:53 / cg"
   278 ! !
   279 
   280 !UISpecificationTool methodsFor:'bindings'!
   281 
   282 acceptChannel
   283     ^ masterApplication acceptChannel
   284 
   285     "Modified: / 12-01-2008 / 11:28:38 / cg"
   286 !
   287 
   288 aspectFor:aKey
   289     "returns the aspect for a key or nil"
   290 
   291     aspects notNil ifTrue:[
   292         ^ aspects at:aKey ifAbsent:nil
   293     ].
   294     ^ super aspectFor:aKey
   295 
   296     "Modified: / 12-01-2008 / 11:28:52 / cg"
   297 !
   298 
   299 buildInView
   300     ^ buildInView
   301 !
   302 
   303 specificationFor:aKey
   304     "this is called if our current specification contains 
   305      subspecifications or subcanvases.
   306      Get the subspecification from the current specification"
   307 
   308     specification notNil ifTrue:[
   309         ^ specification class perform:aKey ifNotUnderstood:nil
   310     ].
   311     ^ nil
   312 ! !
   313 
   314 !UISpecificationTool methodsFor:'change & update'!
   315 
   316 update
   317     "reload specification
   318     "
   319     specChannel notNil ifTrue:[
   320         specChannel value:specification.
   321     ]
   322 
   323 
   324 !
   325 
   326 update:something with:someArgument from:someone
   327     "any attribute changed its state in the current specification
   328     "
   329     someone ~~ modifiedHolder ifTrue:[
   330         "/ any in the spec has changed.
   331         "/ update my modified holders value
   332 
   333         modifiedHolder value:true
   334     ]
   335 
   336     "Modified: / 16.7.1998 / 19:25:59 / cg"
   337 ! !
   338 
   339 !UISpecificationTool methodsFor:'help'!
   340 
   341 basicFlyByHelpTextForKey:aKey
   342     "activeHelp interface: return some help text for a key.
   343      Redefined to ask the current components Spec first."
   344 
   345     |helpText|
   346 
   347     "/ first, ask the master (a hook for expecco, to provide different help texts)
   348     masterApplication notNil ifTrue:[
   349         helpText := masterApplication basicFlyByHelpTextForKey:aKey.
   350         helpText notNil ifTrue:[^ helpText ].
   351 
   352         "/ then, ask the master about the spec
   353         helpText := masterApplication basicHelpTextFromSpecification:specification forKey:aKey.
   354     ] ifFalse:[
   355         "/ then, ask the spec
   356         helpText := (specification helpSpec) at:aKey ifAbsent:nil.
   357     ].
   358     helpText notNil ifTrue:[^ helpText ].
   359 
   360     "/ finally, ask myself...
   361     ^ super basicFlyByHelpTextForKey:aKey.
   362 !
   363 
   364 basicHelpTextForKey:aKey
   365     "activeHelp interface: return some help text for a key.
   366      Redefined to ask the current components Spec first."
   367 
   368     |helpText|
   369 
   370     "/ first, ask the master (a hook for expecco, to provide different help texts)
   371     masterApplication notNil ifTrue:[
   372         helpText := masterApplication basicHelpTextForKey:aKey.
   373         helpText notNil ifTrue:[^ helpText ].
   374 
   375         "/ then, ask the master about the spec
   376         helpText := masterApplication basicHelpTextFromSpecification:specification forKey:aKey.
   377     ] ifFalse:[
   378         "/ then, ask the spec
   379         helpText := (specification helpSpec) at:aKey ifAbsent:nil.
   380     ].
   381     helpText notNil ifTrue:[^ helpText ].
   382 
   383     "/ finally, ask myself...
   384     ^ super basicHelpTextForKey:aKey.
   385 ! !
   386 
   387 !UISpecificationTool methodsFor:'initialization'!
   388 
   389 initialize
   390     super initialize.
   391     buildInView := BuildInView new.
   392     buildInView keepViews:true.
   393 ! !
   394 
   395 !UISpecificationTool methodsFor:'selection'!
   396 
   397 selection:something
   398     "selection changed"
   399 
   400     |slices index spec window|
   401 
   402     specification notNil ifTrue:[
   403         slices := specification class slices.
   404         index  := slices findFirst:[:aSlice| aSlice first = something ].
   405 
   406         index ~~ 0 ifTrue:[
   407             spec := specification class perform:((slices at:index) last)
   408         ]
   409     ].
   410 
   411     spec ~= selection ifTrue:[
   412         (selection := spec) notNil ifTrue:[
   413             listOfSpecViews isNil ifTrue:[
   414                 listOfSpecViews := Array new:(slices size).
   415             ] ifFalse:[
   416                 window := listOfSpecViews at:index
   417             ].
   418             window isNil ifTrue:[
   419                 builder buildFromSpec:spec in:(window := SimpleView new).
   420                 listOfSpecViews at:index put:window.
   421             ].
   422         ].
   423         buildInView scrolledView:window.
   424     ].
   425 ! !
   426 
   427 !UISpecificationTool::BuildInView methodsFor:'accessing'!
   428 
   429 mapped
   430     super mapped.
   431 
   432     scrolledView notNil ifTrue:[
   433         scrolledView beVisible.
   434         scrolledView raise.
   435     ].
   436 !
   437 
   438 scrolledView:aView
   439     "set the view to be scrolled"
   440     |wrapper y|
   441 
   442     scrolledView == aView ifTrue:[^ self].
   443 
   444     scrolledView notNil ifTrue:[
   445         scrolledView unmap.
   446     ].
   447     (scrolledView := aView) notNil ifTrue:[
   448         scrolledView superView ~~ frame ifTrue:[
   449             scrolledView borderWidth:0; level:0.
   450 
   451             frame addSubView:scrolledView.
   452 
   453             scrolledView subViews size == 1 ifTrue:[
   454                 wrapper := scrolledView subViews first.
   455                 wrapper isScrollWrapper ifTrue:[
   456                     "/ give it a full-relative size, and let it do
   457                     "/ the scrolling itself.
   458                     y := 1.0
   459                 ]
   460             ].
   461             y isNil ifTrue:[
   462                 y := scrolledView preferredHeight
   463             ].
   464             scrolledView origin:0@0 corner:1.0 @ y.
   465             scrolledView allViewBackground:(self viewBackground).
   466         ].
   467     ].    
   468     shown ifTrue:[
   469         scrolledView beVisible.
   470         scrolledView raise.
   471         self sizeChanged:nil.
   472     ].
   473     model value:scrolledView.
   474 ! !
   475 
   476 !UISpecificationTool::BuildInView methodsFor:'initialization'!
   477 
   478 level:aLevel
   479     super level:0
   480 !
   481 
   482 realize
   483 
   484     super realize.
   485     superView notNil ifTrue:[superView level:0].
   486 ! !
   487 
   488 !UISpecificationTool class methodsFor:'documentation'!
   489 
   490 version
   491     ^ '$Header$'
   492 !
   493 
   494 version_CVS
   495     ^ '$Header$'
   496 ! !