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