UIPainter.st
changeset 166 cd5699643975
parent 161 12a70f62f414
child 168 8a79add2260f
equal deleted inserted replaced
165:f7df2a53d042 166:cd5699643975
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 
    13 
    14 ApplicationModel subclass:#UIPainter
    14 ApplicationModel subclass:#UIPainter
    15 	instanceVariableNames:'activeHelpTool layoutTool objectList selectionPanel tabSelection
    15 	instanceVariableNames:'activeHelpTool layoutTool specTool objectList selectionPanel
    16 		lastSlice specView fileName specClass specSelector specSuperclass
    16 		tabSelection specClass specSelector specSuperclass aspects'
    17 		aspects'
       
    18 	classVariableNames:''
    17 	classVariableNames:''
    19 	poolDictionaries:''
    18 	poolDictionaries:''
    20 	category:'Interface-UIPainter'
    19 	category:'Interface-UIPainter'
    21 !
    20 !
    22 
    21 
    83 
    82 
    84 preferenceFor:aSymbol
    83 preferenceFor:aSymbol
    85     ^ false
    84     ^ false
    86 
    85 
    87 
    86 
       
    87 ! !
       
    88 
       
    89 !UIPainter class methodsFor:'help specs'!
       
    90 
       
    91 helpSpec
       
    92     "return a dictionary filled with helpKey -> helptext associations.
       
    93      These are used by the activeHelp tool."
       
    94 
       
    95     |dict|
       
    96 
       
    97     dict := super helpSpec.
       
    98     dict at:#maxChars put:'set the maximum number of
       
    99 characters that are allowed
       
   100 in the editfield.'.
       
   101     dict at:#id put:'enter the name of the field
       
   102 here. This ID can be used
       
   103 by the applicationModel
       
   104 to access components,
       
   105 using #componentAt:<key>'.
       
   106     ^ dict
    88 ! !
   107 ! !
    89 
   108 
    90 !UIPainter class methodsFor:'icons'!
   109 !UIPainter class methodsFor:'icons'!
    91 
   110 
    92 iconAlignB
   111 iconAlignB
   596 !UIPainter methodsFor:'actions'!
   615 !UIPainter methodsFor:'actions'!
   597 
   616 
   598 accept
   617 accept
   599     |layout|
   618     |layout|
   600 
   619 
   601     tabSelection = layoutTool label ifTrue:[
   620     objectList removeDependent:self.
       
   621 
       
   622     self isLayoutToolSelected ifTrue:[
   602         (layout := layoutTool layout) notNil ifTrue:[
   623         (layout := layoutTool layout) notNil ifTrue:[
   603             layoutTool layoutType == #Extent ifTrue:[
   624             layoutTool layoutType == #Extent ifTrue:[
   604                 self painter setExtent:layout
   625                 self painter setExtent:layout
   605             ] ifFalse:[
   626             ] ifFalse:[
   606                 self painter setLayout:layout
   627                 self painter setLayout:layout
   607             ]
   628             ]
   608         ]
   629         ]
   609     ] ifFalse:[
   630     ] ifFalse:[
   610         tabSelection = 'Help' ifTrue:[
   631         self isHelpToolSelected ifTrue:[
   611             activeHelpTool accept
   632             activeHelpTool accept
   612         ].
   633         ].
   613         self painter updateFromSpec:(specView specEdited)
   634         self painter updateFromSpec:(specTool specEdited).
   614     ].
   635     ].
   615     self cancel
   636     self modifiedChannel value:false.
   616 
   637     objectList addDependent:self.
   617     "Modified: 17.6.1997 / 12:50:59 / cg"
   638 
   618 !
   639 !
   619 
   640 
   620 cancel
   641 cancel
   621     "cancel all changes and read back attributes from current view
   642     "cancel all changes and read back attributes from current view
   622     "
   643     "
   623     specView specEdited:(self painter specForSelection).
   644     self modifiedChannel value ifTrue:[
   624     layoutTool update.
   645         specTool specEdited:(self painter specForSelection).
   625     self modifiedChannel value:false.
   646         layoutTool layoutView:(layoutTool layoutView).
       
   647         self modifiedChannel value:false.
       
   648     ]
   626 !
   649 !
   627 
   650 
   628 doubleClick
   651 doubleClick
   629     objectList selectGroup
   652     objectList selectGroup
   630 ! !
   653 ! !
   641             specClass isBehavior ifFalse:[
   664             specClass isBehavior ifFalse:[
   642                 cls := Smalltalk at:specClass asSymbol
   665                 cls := Smalltalk at:specClass asSymbol
   643             ] ifTrue:[
   666             ] ifTrue:[
   644                 cls := specClass
   667                 cls := specClass
   645             ].
   668             ].
   646 
   669             (cls isSubclassOf:UISpecification) ifTrue:[
   647             (cls respondsTo:#helpSpec) ifTrue:[
   670                 cls := self class
   648                 activeHelpTool dictionary:(cls helpSpec).
   671             ].
   649            ]
   672             activeHelpTool dictionary:(cls helpSpec).
   650         ].
   673         ].
   651     ].
   674     ].
   652     ^ activeHelpTool
   675     ^ activeHelpTool
   653 
   676 
   654     "Modified: 17.6.1997 / 12:51:15 / cg"
   677     "Modified: 17.6.1997 / 12:51:15 / cg"
   720 !
   743 !
   721 
   744 
   722 noteBookView
   745 noteBookView
   723     "automatically generated by UIPainter ..."
   746     "automatically generated by UIPainter ..."
   724 
   747 
   725     |noteBook channel|
   748     |noteBook channel n1 n2|
   726 
   749 
   727     (noteBook := builder bindingAt:#noteBookView) isNil ifTrue:[
   750     (noteBook := builder bindingAt:#noteBookView) isNil ifTrue:[
   728         noteBook   := View origin:0.0 @0.0 corner:1.0@1.0.
   751         noteBook   := View new.
   729         layoutTool := UIPropertyView for:#Dimension     in:noteBook.
   752         layoutTool := UILayoutTool new.
   730         specView   := UIPropertyView for:#Specification in:noteBook.
   753         specTool   := UISpecificationTool new.
   731         channel    := self modifiedChannel.
   754         channel    := self modifiedChannel.
       
   755 
   732         layoutTool masterApplication:self.
   756         layoutTool masterApplication:self.
   733         specView   masterApplication:self.
   757         specTool   masterApplication:self.
       
   758 
       
   759         n1 := SubCanvas origin:0.0@0.0 corner:1.0@1.0 in:noteBook.
       
   760         n2 := SubCanvas origin:0.0@0.0 corner:1.0@1.0 in:noteBook.
       
   761 
       
   762         n1 client:layoutTool.
       
   763         specTool builder:(n2 client:specTool).
       
   764 
       
   765         layoutTool masterApplication:self.
       
   766         specTool   masterApplication:self.
   734         layoutTool modifiedHolder:channel.
   767         layoutTool modifiedHolder:channel.
   735         specView   modifiedHolder:channel.
   768         specTool   modifiedHolder:channel.
   736         builder aspectAt:#noteBookView put:noteBook.
   769         builder aspectAt:#noteBookView put:noteBook.
   737     ].
   770     ].
   738     ^ noteBook
   771     ^ noteBook
   739 !
   772 !
   740 
   773 
   768     "automatically generated by UIPainter ..."
   801     "automatically generated by UIPainter ..."
   769 
   802 
   770     |holder|
   803     |holder|
   771 
   804 
   772     (holder := builder bindingAt:#tabModel) isNil ifTrue:[
   805     (holder := builder bindingAt:#tabModel) isNil ifTrue:[
   773         lastSlice := 'Basics'.
       
   774         holder := AspectAdaptor new subject:self; forAspect:#tabSelection.
   806         holder := AspectAdaptor new subject:self; forAspect:#tabSelection.
   775         builder aspectAt:#tabModel put:holder.
   807         builder aspectAt:#tabModel put:holder.
   776     ].
   808     ].
   777     ^ holder
   809     ^ holder
   778 ! !
   810 ! !
   794 
   826 
   795     (someObject == objectList and:[something ~~ #list]) ifTrue:[
   827     (someObject == objectList and:[something ~~ #list]) ifTrue:[
   796         something ~~ #layout ifTrue:[
   828         something ~~ #layout ifTrue:[
   797             self objectListChanged
   829             self objectListChanged
   798         ] ifFalse:[
   830         ] ifFalse:[
   799             (self modifiedChannel value) ifFalse:[
   831             self modifiedChannel value ifTrue:[
   800                 layoutTool update
   832                 ^ self
   801             ]
   833             ].
   802         ]
   834             layoutTool update
       
   835         ].
       
   836         self modifiedChannel value:false
   803     ]
   837     ]
   804 ! !
   838 ! !
   805 
   839 
   806 !UIPainter methodsFor:'event handling'!
   840 !UIPainter methodsFor:'event handling'!
   807 
   841 
   818 !
   852 !
   819 
   853 
   820 objectListChanged
   854 objectListChanged
   821     "something changed in the painter view
   855     "something changed in the painter view
   822     "
   856     "
   823     |setSel view slices list spec props size same|
   857     |oldSelection view slices list spec props size|
   824 
   858 
   825     props := objectList selectedProperty.
   859     props := objectList selectedProperty.
       
   860     oldSelection := tabSelection.
   826     tabSelection := nil.
   861     tabSelection := nil.
   827 
   862 
   828     props isNil ifFalse:[
   863     props isNil ifFalse:[
   829         view := props view.
   864         view := props view.
   830         spec := props spec copy.
   865         spec := props spec copy.
   831 
   866 
   832         layoutTool forView == view ifFalse:[
   867         layoutTool layoutView == view ifFalse:[
   833             slices := spec class slices.
   868             slices := spec class slices.
   834             size   := slices size + 1.
   869             size   := slices size + 1.
   835             list   := Array new:size.
   870             list   := Array new:size.
   836             slices keysAndValuesDo:[:i :s|list at:i put:(s first asString)].
   871             slices keysAndValuesDo:[:i :s|list at:i put:(s first asString)].
   837             list at:size put:(layoutTool label).
   872             list at:size put:(layoutTool class label).
   838             (self tabList) value:list.
   873             (self tabList) value:list.
   839         ] ifTrue:[
   874         ] ifTrue:[
   840             list := self tabList value
   875             list := self tabList value
   841         ].
   876         ].
   842         (list findFirst:[:aName| aName = lastSlice]) ~~ 0 ifTrue:[
   877         (list findFirst:[:n| n = oldSelection ]) ~~ 0 ifTrue:[
   843             setSel := lastSlice
   878             tabSelection := oldSelection
       
   879         ] ifFalse:[
       
   880             tabSelection := list first
   844         ]
   881         ]
   845     ].
   882     ].
   846     layoutTool forView:view.
   883     layoutTool layoutView:view.
   847     specView specEdited:spec.
   884     specTool   specEdited:spec.
   848     self tabModel value:setSel.
   885 
   849 ! !
   886     tabSelection notNil ifTrue:[
   850 
   887         self isLayoutToolSelected ifTrue:[
   851 !UIPainter methodsFor:'file access'!
   888             (self noteBookView subViews at:1) raise
   852 
   889         ] ifFalse:[
   853 openFile:aFileName
   890             specTool selection:tabSelection.
   854     |aStream |
   891             (self noteBookView subViews at:2) raise
   855 
   892         ]
   856     aStream := FileStream readonlyFileNamed:aFileName.
   893     ].
   857 
   894 
   858     aStream notNil ifTrue:[
   895     (builder componentAt:#noteBook) selection:tabSelection.
   859         self painter fileInContentsFrom:aStream.
   896     self modifiedChannel value:false.
   860         aStream close.
       
   861         fileName := aFileName
       
   862     ]
       
   863 
       
   864 
       
   865 !
       
   866 
       
   867 saveAs:aFileName
       
   868     |aStream|
       
   869 
       
   870     aStream := FileStream newFileNamed:aFileName.
       
   871 
       
   872     aStream notNil ifTrue:[
       
   873         self painter storeContentsOn:aStream.
       
   874         aStream close.
       
   875         fileName := aFileName
       
   876     ].
       
   877 
       
   878 ! !
   897 ! !
   879 
   898 
   880 !UIPainter methodsFor:'private'!
   899 !UIPainter methodsFor:'private'!
   881 
   900 
   882 painter
   901 painter
   883     ^ objectList painter
   902     ^ objectList painter
   884 ! !
   903 ! !
   885 
   904 
       
   905 !UIPainter methodsFor:'queries'!
       
   906 
       
   907 isHelpToolSelected
       
   908     ^ tabSelection = 'Help'
       
   909 !
       
   910 
       
   911 isLayoutToolSelected
       
   912     ^ tabSelection = layoutTool class label
       
   913 ! !
       
   914 
   886 !UIPainter methodsFor:'selection'!
   915 !UIPainter methodsFor:'selection'!
   887 
   916 
   888 tabSelection
   917 tabSelection
   889     ^ tabSelection
   918     ^ tabSelection
   890 !
   919 !
   891 
   920 
   892 tabSelection:something
   921 tabSelection:something
   893     |specEdited slices spec idx|
   922     |raiseViewIdx|
   894 
   923 
   895     something isNil ifTrue:[^ self].
   924     something notNil ifTrue:[
   896 
   925         raiseViewIdx := 1.
   897     tabSelection := something.
   926         tabSelection := something.
   898 
   927 
   899     (specEdited := specView specEdited) notNil ifTrue:[
   928         self isLayoutToolSelected ifFalse:[
   900         slices    := specEdited class slices.
   929             specTool selection:tabSelection.
   901         lastSlice := tabSelection.
   930             raiseViewIdx := 2
   902 
       
   903         idx:= slices findFirst:[:aSlice| aSlice first = tabSelection ].
       
   904         idx == 0 ifTrue:[
       
   905             layoutTool update.
       
   906           ^ layoutTool raise.
       
   907         ].
   931         ].
   908         spec := specEdited class perform:((slices at:idx) last).
   932         (self noteBookView subViews at:raiseViewIdx) raise.
   909     ].
   933         self cancel.
   910     specView raise.
       
   911 
       
   912     specEdited isNil ifTrue:[
       
   913         specView buildFromSpec:nil
       
   914     ] ifFalse:[
       
   915         specView buildFromSpec:spec
       
   916     ]
   934     ]
   917 ! !
   935 ! !
   918 
   936 
   919 !UIPainter methodsFor:'startup / release'!
   937 !UIPainter methodsFor:'startup / release'!
   920 
   938 
  1277 
  1295 
  1278     activeHelpTool isNil ifTrue:[
  1296     activeHelpTool isNil ifTrue:[
  1279         ^ self information:'no help text defined'
  1297         ^ self information:'no help text defined'
  1280     ].    
  1298     ].    
  1281     dict := activeHelpTool dictionary.
  1299     dict := activeHelpTool dictionary.
       
  1300     (cls isSubclassOf:UISpecification) ifTrue:[
       
  1301         cls := self class
       
  1302     ].
  1282 
  1303 
  1283     src := '' writeStream.
  1304     src := '' writeStream.
  1284     src nextPutAll:'helpSpec
  1305     src nextPutAll:'helpSpec
  1285     "return a dictionary filled with helpKey -> helptext associations.
  1306     "return a dictionary filled with helpKey -> helptext associations.
  1286      These are used by the activeHelp tool."
  1307      These are used by the activeHelp tool."
  1332     self removeAll
  1353     self removeAll
  1333 
  1354 
  1334     "Modified: 17.6.1997 / 12:33:31 / cg"
  1355     "Modified: 17.6.1997 / 12:33:31 / cg"
  1335 !
  1356 !
  1336 
  1357 
  1337 doOpen
       
  1338     |box|
       
  1339 
       
  1340     box := FileSelectionBox new.
       
  1341     box title:(resources string:'Which file ?').
       
  1342     box selectingDirectory:false.
       
  1343     box pattern:'*.*'.
       
  1344     box action:[:aFile| self openFile:aFile ].
       
  1345     box open
       
  1346 
       
  1347 !
       
  1348 
       
  1349 doPickAView
  1358 doPickAView
  1350     |painter view className methodName cls sel accepted spec s|
  1359     |painter view className methodName cls sel accepted spec s|
  1351 
  1360 
  1352     objectList painter isModified ifTrue:[
  1361     objectList painter isModified ifTrue:[
  1353         (self confirm:'pick another interface without saving your modifications ?') ifFalse:[
  1362         (self confirm:'pick another interface without saving your modifications ?') ifFalse:[
  1376         selectionPanel window raise
  1385         selectionPanel window raise
  1377     ]
  1386     ]
  1378 
  1387 
  1379 !
  1388 !
  1380 
  1389 
  1381 doSave
       
  1382     fileName notNil ifTrue:[
       
  1383         self saveAs:fileName
       
  1384     ] ifFalse:[
       
  1385         self doSaveAs
       
  1386     ]
       
  1387 
       
  1388 !
       
  1389 
       
  1390 doSaveAs
       
  1391     |box|
       
  1392 
       
  1393     box := FileSelectionBox new.
       
  1394     box title:(resources string:'Which file ?').
       
  1395     box selectingDirectory:false.
       
  1396     box pattern:'*.*'.
       
  1397     box action:[:aFile| self saveAs:aFile ].
       
  1398     box open
       
  1399 
       
  1400 !
       
  1401 
       
  1402 doStartApplication
  1390 doStartApplication
  1403     |cls|
  1391     |cls|
  1404 
  1392 
  1405     (specClass isNil or:[specSelector isNil]) ifTrue:[
  1393     (specClass isNil or:[specSelector isNil]) ifTrue:[
  1406         ^ self information:'no class or selector defined'.
  1394         ^ self information:'no class or selector defined'.