ColorEditDialog.st
changeset 2831 3dbef5687ae6
parent 2574 ae2448675efb
child 2904 bd6cacbab203
equal deleted inserted replaced
2830:aec9b9fd5c17 2831:3dbef5687ae6
    11 "
    11 "
    12 "{ Package: 'stx:libtool2' }"
    12 "{ Package: 'stx:libtool2' }"
    13 
    13 
    14 SimpleDialog subclass:#ColorEditDialog
    14 SimpleDialog subclass:#ColorEditDialog
    15 	instanceVariableNames:'red green blue hue light saturation colorNameHolder
    15 	instanceVariableNames:'red green blue hue light saturation colorNameHolder
    16 		htmlColorNameHolder previewBox'
    16 		htmlColorNameHolder colorDefinitionStringHolder previewBox
       
    17 		brightnessStringHolder'
    17 	classVariableNames:''
    18 	classVariableNames:''
    18 	poolDictionaries:''
    19 	poolDictionaries:''
    19 	category:'Interface-UIPainter'
    20 	category:'Interface-UIPainter'
    20 !
    21 !
    21 
    22 
    92 
    93 
    93     <resource: #help>
    94     <resource: #help>
    94 
    95 
    95     ^ super helpSpec addPairsFrom:#(
    96     ^ super helpSpec addPairsFrom:#(
    96 
    97 
       
    98 #brightness
       
    99 'The Color''s brightness value (0..1)'
       
   100 
       
   101 #colorDefinitionString
       
   102 'A Smalltalk expression to construct the color.'
       
   103 
       
   104 #colorName
       
   105 'The standard colorname (as used in the X-Window System), if known'
       
   106 
    97 #copyToClipboard
   107 #copyToClipboard
    98 'Copy the color to the clipboard'
   108 'Copy the color to the clipboard'
    99 
   109 
   100 #hlsMixer
   110 #hlsMixer
   101 'Mix color from hls (hue-light-saturation) components'
   111 'Mix color from hls (hue-light-saturation) components'
       
   112 
       
   113 #htmlColorName
       
   114 'The color as used in an HTML page.'
   102 
   115 
   103 #pasteFromClipboard
   116 #pasteFromClipboard
   104 'Paste color from the Clipboard'
   117 'Paste color from the Clipboard'
   105 
   118 
   106 #rgbMixer
   119 #rgbMixer
   137         name: windowSpec
   150         name: windowSpec
   138         window: 
   151         window: 
   139        (WindowSpec
   152        (WindowSpec
   140           label: 'Define Color'
   153           label: 'Define Color'
   141           name: 'Define Color'
   154           name: 'Define Color'
   142           min: (Point 440 300)
   155           min: (Point 440 360)
   143           max: (Point 440 300)
   156           max: (Point 440 360)
   144           bounds: (Rectangle 0 0 440 300)
   157           bounds: (Rectangle 0 0 440 360)
   145         )
   158         )
   146         component: 
   159         component: 
   147        (SpecCollection
   160        (SpecCollection
   148           collection: (
   161           collection: (
   149            (VerticalPanelViewSpec
   162            (VerticalPanelViewSpec
   241                     type: numberInRange
   254                     type: numberInRange
   242                     numChars: 3
   255                     numChars: 3
   243                     minValue: 0
   256                     minValue: 0
   244                     maxValue: 255
   257                     maxValue: 255
   245                     acceptOnPointerLeave: false
   258                     acceptOnPointerLeave: false
   246                     extent: (Point 30 20)
   259                     extent: (Point 28 20)
   247                   )
   260                   )
   248                  (InputFieldSpec
   261                  (InputFieldSpec
   249                     name: 'GreenField'
   262                     name: 'GreenField'
   250                     model: green
   263                     model: green
   251                     type: numberInRange
   264                     type: numberInRange
   252                     numChars: 3
   265                     numChars: 3
   253                     minValue: 0
   266                     minValue: 0
   254                     maxValue: 255
   267                     maxValue: 255
   255                     acceptOnPointerLeave: false
   268                     acceptOnPointerLeave: false
   256                     extent: (Point 30 20)
   269                     extent: (Point 28 20)
   257                   )
   270                   )
   258                  (InputFieldSpec
   271                  (InputFieldSpec
   259                     name: 'BlueField'
   272                     name: 'BlueField'
   260                     model: blue
   273                     model: blue
   261                     type: numberInRange
   274                     type: numberInRange
   262                     numChars: 3
   275                     numChars: 3
   263                     minValue: 0
   276                     minValue: 0
   264                     maxValue: 255
   277                     maxValue: 255
   265                     acceptOnPointerLeave: false
   278                     acceptOnPointerLeave: false
   266                     extent: (Point 30 20)
   279                     extent: (Point 28 20)
   267                   )
   280                   )
   268                  )
   281                  )
   269                
   282                
   270               )
   283               )
   271             )
   284             )
   285                     type: hexIntegerInRange
   298                     type: hexIntegerInRange
   286                     numChars: 3
   299                     numChars: 3
   287                     minValue: 0
   300                     minValue: 0
   288                     maxValue: 255
   301                     maxValue: 255
   289                     acceptOnPointerLeave: false
   302                     acceptOnPointerLeave: false
   290                     extent: (Point 22 20)
   303                     extent: (Point 20 20)
   291                   )
   304                   )
   292                  (InputFieldSpec
   305                  (InputFieldSpec
   293                     name: 'EntryField5'
   306                     name: 'EntryField5'
   294                     model: green
   307                     model: green
   295                     type: hexIntegerInRange
   308                     type: hexIntegerInRange
   296                     numChars: 3
   309                     numChars: 3
   297                     minValue: 0
   310                     minValue: 0
   298                     maxValue: 255
   311                     maxValue: 255
   299                     acceptOnPointerLeave: false
   312                     acceptOnPointerLeave: false
   300                     extent: (Point 22 20)
   313                     extent: (Point 20 20)
   301                   )
   314                   )
   302                  (InputFieldSpec
   315                  (InputFieldSpec
   303                     name: 'EntryField6'
   316                     name: 'EntryField6'
   304                     model: blue
   317                     model: blue
   305                     type: hexIntegerInRange
   318                     type: hexIntegerInRange
   306                     numChars: 3
   319                     numChars: 3
   307                     minValue: 0
   320                     minValue: 0
   308                     maxValue: 255
   321                     maxValue: 255
   309                     acceptOnPointerLeave: false
   322                     acceptOnPointerLeave: false
   310                     extent: (Point 22 20)
   323                     extent: (Point 20 20)
   311                   )
   324                   )
   312                  )
   325                  )
   313                
   326                
   314               )
   327               )
   315             )
   328             )
   372                     name: 'Slider2'
   385                     name: 'Slider2'
   373                     tabable: false
   386                     tabable: false
   374                     model: light
   387                     model: light
   375                     orientation: horizontal
   388                     orientation: horizontal
   376                     step: 1
   389                     step: 1
   377                     backgroundColor: (Color 66.999313344015 66.999313344015 66.999313344015)
   390                     backgroundColor: (Color 66.9993133440146 66.9993133440146 66.9993133440146)
   378                     keyboardStep: 1
   391                     keyboardStep: 1
   379                     extent: (Point 193 16)
   392                     extent: (Point 193 16)
   380                   )
   393                   )
   381                  (SliderSpec
   394                  (SliderSpec
   382                     name: 'Slider3'
   395                     name: 'Slider3'
   383                     tabable: false
   396                     tabable: false
   384                     model: saturation
   397                     model: saturation
   385                     orientation: horizontal
   398                     orientation: horizontal
   386                     step: 1
   399                     step: 1
   387                     backgroundColor: (Color 66.999313344015 66.999313344015 66.999313344015)
   400                     backgroundColor: (Color 66.9993133440146 66.9993133440146 66.9993133440146)
   388                     keyboardStep: 1
   401                     keyboardStep: 1
   389                     extent: (Point 193 16)
   402                     extent: (Point 193 16)
   390                   )
   403                   )
   391                  )
   404                  )
   392                
   405                
   408                     type: numberInRange
   421                     type: numberInRange
   409                     numChars: 3
   422                     numChars: 3
   410                     minValue: 0
   423                     minValue: 0
   411                     maxValue: 359
   424                     maxValue: 359
   412                     acceptOnPointerLeave: false
   425                     acceptOnPointerLeave: false
   413                     extent: (Point 30 20)
   426                     extent: (Point 28 20)
   414                   )
   427                   )
   415                  (InputFieldSpec
   428                  (InputFieldSpec
   416                     name: 'EntryField2'
   429                     name: 'EntryField2'
   417                     model: light
   430                     model: light
   418                     type: numberInRange
   431                     type: numberInRange
   419                     numChars: 3
   432                     numChars: 3
   420                     minValue: 0
   433                     minValue: 0
   421                     maxValue: 100
   434                     maxValue: 100
   422                     acceptOnPointerLeave: false
   435                     acceptOnPointerLeave: false
   423                     extent: (Point 30 20)
   436                     extent: (Point 28 20)
   424                   )
   437                   )
   425                  (InputFieldSpec
   438                  (InputFieldSpec
   426                     name: 'EntryField3'
   439                     name: 'EntryField3'
   427                     model: saturation
   440                     model: saturation
   428                     type: numberInRange
   441                     type: numberInRange
   429                     numChars: 3
   442                     numChars: 3
   430                     minValue: 0
   443                     minValue: 0
   431                     maxValue: 100
   444                     maxValue: 100
   432                     acceptOnPointerLeave: false
   445                     acceptOnPointerLeave: false
   433                     extent: (Point 30 20)
   446                     extent: (Point 28 20)
   434                   )
   447                   )
   435                  )
   448                  )
   436                
   449                
   437               )
   450               )
   438             )
   451             )
   454                  )
   467                  )
   455                
   468                
   456               )
   469               )
   457             )
   470             )
   458            (LabelSpec
   471            (LabelSpec
       
   472               label: 'Brightness:'
       
   473               name: 'Label5'
       
   474               layout: (LayoutFrame 0 0 175 0 70 0 197 0)
       
   475               activeHelpKey: brightness
       
   476               translateLabel: true
       
   477               adjust: right
       
   478             )
       
   479            (InputFieldSpec
       
   480               name: 'EntryField8'
       
   481               layout: (LayoutFrame 71 0 175 0 -296 1 197 0)
       
   482               activeHelpKey: brightness
       
   483               model: brightnessStringHolder
       
   484               isReadOnly: true
       
   485               immediateAccept: false
       
   486               acceptOnReturn: true
       
   487               acceptOnTab: true
       
   488               acceptOnLostFocus: true
       
   489               acceptOnPointerLeave: true
       
   490             )
       
   491            (LabelSpec
   459               label: 'Color Name:'
   492               label: 'Color Name:'
   460               name: 'ColorNameLabel'
   493               name: 'ColorNameLabel'
   461               layout: (LayoutFrame 0 0 176 0 106 0 198 0)
   494               layout: (LayoutFrame 2 0 214 0 115 0 236 0)
       
   495               activeHelpKey: colorName
   462               translateLabel: true
   496               translateLabel: true
   463               adjust: right
   497               adjust: right
   464             )
   498             )
   465            (InputFieldSpec
   499            (InputFieldSpec
   466               name: 'ColorNameField'
   500               name: 'ColorNameField'
   467               layout: (LayoutFrame 108 0 176 0 -162 1 198 0)
   501               layout: (LayoutFrame 117 0 214 0 -122 1 236 0)
       
   502               activeHelpKey: colorName
   468               model: colorNameHolder
   503               model: colorNameHolder
   469               immediateAccept: false
   504               immediateAccept: false
   470               acceptOnReturn: true
   505               acceptOnReturn: true
   471               acceptOnTab: true
   506               acceptOnTab: true
   472               acceptOnLostFocus: true
   507               acceptOnLostFocus: true
   473               acceptOnPointerLeave: true
   508               acceptOnPointerLeave: true
   474             )
   509             )
   475            (LabelSpec
   510            (LabelSpec
   476               label: 'HTML Color Name:'
   511               label: 'HTML Color Name:'
   477               name: 'HTMLColorNameLabel'
   512               name: 'HTMLColorNameLabel'
   478               layout: (LayoutFrame 4 0 204 0 110 0 226 0)
   513               layout: (LayoutFrame 2 0 240 0 115 0 262 0)
       
   514               activeHelpKey: htmlColorName
   479               translateLabel: true
   515               translateLabel: true
   480               adjust: right
   516               adjust: right
   481             )
   517             )
   482            (InputFieldSpec
   518            (InputFieldSpec
   483               name: 'MLHTColorNameFieldField'
   519               name: 'MLHTColorNameFieldField'
   484               layout: (LayoutFrame 108 0 204 0 -162 1 226 0)
   520               layout: (LayoutFrame 117 0 240 0 -122 1 262 0)
       
   521               activeHelpKey: htmlColorName
   485               model: htmlColorNameHolder
   522               model: htmlColorNameHolder
   486               immediateAccept: false
   523               immediateAccept: false
   487               acceptOnReturn: true
   524               acceptOnReturn: true
   488               acceptOnTab: true
   525               acceptOnTab: true
   489               acceptOnLostFocus: true
   526               acceptOnLostFocus: true
   490               acceptOnPointerLeave: true
   527               acceptOnPointerLeave: true
   491             )
   528             )
       
   529            (LabelSpec
       
   530               label: 'Color Definition:'
       
   531               name: 'Label4'
       
   532               layout: (LayoutFrame 2 0 266 0 115 0 288 0)
       
   533               activeHelpKey: colorDefinitionString
       
   534               translateLabel: true
       
   535               adjust: right
       
   536             )
       
   537            (InputFieldSpec
       
   538               name: 'EntryField7'
       
   539               layout: (LayoutFrame 117 0 266 0 -122 1 288 0)
       
   540               activeHelpKey: colorDefinitionString
       
   541               model: colorDefinitionStringHolder
       
   542               isReadOnly: true
       
   543               immediateAccept: false
       
   544               acceptOnReturn: true
       
   545               acceptOnTab: true
       
   546               acceptOnLostFocus: true
       
   547               acceptOnPointerLeave: true
       
   548             )
   492            (ActionButtonSpec
   549            (ActionButtonSpec
   493               label: 'Copy Color'
   550               label: 'Copy Color'
   494               name: 'CopyColor'
   551               name: 'CopyColor'
   495               layout: (LayoutFrame 12 0 236 0 100 0 258 0)
   552               layout: (LayoutFrame 12 0 298 0 100 0 320 0)
   496               activeHelpKey: hlsMixer
   553               activeHelpKey: hlsMixer
   497               translateLabel: true
   554               translateLabel: true
   498               resizeForLabel: true
   555               resizeForLabel: true
   499               tabable: true
   556               tabable: true
   500               model: copyColor
   557               model: copyColor
   501             )
   558             )
   502            (ActionButtonSpec
   559            (ActionButtonSpec
   503               label: 'Paste Color'
   560               label: 'Paste Color'
   504               name: 'PasteColor'
   561               name: 'PasteColor'
   505               layout: (LayoutFrame 108 0 236 0 196 0 258 0)
   562               layout: (LayoutFrame 108 0 298 0 196 0 320 0)
   506               translateLabel: true
   563               translateLabel: true
   507               resizeForLabel: true
   564               resizeForLabel: true
   508               tabable: true
   565               tabable: true
   509               model: pasteColor
   566               model: pasteColor
   510             )
   567             )
   511            (ActionButtonSpec
   568            (ActionButtonSpec
   512               label: 'pickColorIcon'
   569               label: 'pickColorIcon'
   513               name: 'Button1'
   570               name: 'Button1'
   514               layout: (LayoutFrame 285 0 236 0 312 0 263 0)
   571               layout: (LayoutFrame 285 0 298 0 312 0 325 0)
   515               activeHelpKey: pickColor
   572               activeHelpKey: pickColor
   516               hasCharacterOrientedLabel: false
   573               hasCharacterOrientedLabel: false
   517               translateLabel: true
   574               translateLabel: true
   518               resizeForLabel: true
   575               resizeForLabel: true
   519               tabable: true
   576               tabable: true
   619 ! !
   676 ! !
   620 
   677 
   621 !ColorEditDialog methodsFor:'actions'!
   678 !ColorEditDialog methodsFor:'actions'!
   622 
   679 
   623 colorChanged
   680 colorChanged
   624     |clr|
   681     |clr nm|
   625 
   682 
   626     clr := self colorNameOrColor.
   683     clr := self colorNameOrColor.
   627     clr isColor ifTrue:[
   684     clr isColor ifTrue:[
   628         "not a symbol"
   685         "not a symbol"
   629         self setPreview:clr.
   686         self setPreview:clr.
   630         self htmlColorNameHolder value:(clr htmlPrintString) withoutNotifying:self.
   687         self htmlColorNameHolder value:(clr htmlPrintString) withoutNotifying:self.
   631     ].
   688 
       
   689         nm := #(white red green blue black) detect:[:nm | clr = (Color perform:nm)] ifNone:nil.
       
   690         nm notNil ifTrue:[
       
   691             self colorDefinitionStringHolder value:('Color ',nm).
       
   692         ] ifFalse:[
       
   693             self colorDefinitionStringHolder value:('Color rgbValue:16r',(clr rgbValue hexPrintString leftPaddedTo:6 with:$0)).
       
   694         ].
       
   695         self brightnessStringHolder value:((clr brightness asFixedPoint:3) printString).
       
   696     ].
       
   697 
       
   698     "Modified: / 27-01-2011 / 12:54:04 / cg"
   632 !
   699 !
   633 
   700 
   634 colorChangedTo:clr
   701 colorChangedTo:clr
   635     "compute rgb and hls (if possible)"
   702     "compute rgb and hls (if possible)"
   636 
   703 
   646     ].
   713     ].
   647     self light      value:(clr light rounded) withoutNotifying:self.
   714     self light      value:(clr light rounded) withoutNotifying:self.
   648     self saturation value:(clr saturation rounded) withoutNotifying:self.
   715     self saturation value:(clr saturation rounded) withoutNotifying:self.
   649 
   716 
   650     self colorChanged
   717     self colorChanged
       
   718 
       
   719     "Modified: / 27-01-2011 / 12:48:28 / cg"
   651 !
   720 !
   652 
   721 
   653 colorNameChanged
   722 colorNameChanged
   654     "compute rgb and hls (if possible)"
   723     "compute rgb and hls (if possible)"
   655 
   724 
   763         blue addDependent:self.
   832         blue addDependent:self.
   764     ].
   833     ].
   765     ^blue
   834     ^blue
   766 !
   835 !
   767 
   836 
       
   837 brightnessStringHolder
       
   838     brightnessStringHolder isNil ifTrue:[
       
   839         brightnessStringHolder := 0 asValue.
       
   840         "/ brightness addDependent:self.
       
   841     ].
       
   842     ^ brightnessStringHolder
       
   843 
       
   844     "Created: / 27-01-2011 / 12:48:00 / cg"
       
   845 !
       
   846 
       
   847 colorDefinitionStringHolder
       
   848     colorDefinitionStringHolder isNil ifTrue:[
       
   849         colorDefinitionStringHolder := '' asValue.
       
   850         "/ colorDefinitionStringHolder addDependent:self.
       
   851     ].
       
   852     ^colorDefinitionStringHolder
       
   853 
       
   854     "Created: / 27-01-2011 / 12:38:12 / cg"
       
   855 !
       
   856 
   768 colorNameHolder
   857 colorNameHolder
   769     colorNameHolder isNil ifTrue:[
   858     colorNameHolder isNil ifTrue:[
   770         colorNameHolder := '' asValue.
   859         colorNameHolder := '' asValue.
   771         colorNameHolder addDependent:self.
   860         colorNameHolder addDependent:self.
   772     ].
   861     ].
   865 
   954 
   866 !ColorEditDialog class methodsFor:'documentation'!
   955 !ColorEditDialog class methodsFor:'documentation'!
   867 
   956 
   868 version
   957 version
   869     ^ '$Header$'
   958     ^ '$Header$'
   870 ! !
   959 !
       
   960 
       
   961 version_CVS
       
   962     ^ '$Header$'
       
   963 ! !