ColorEditDialog.st
author Claus Gittinger <cg@exept.de>
Sat, 21 Jul 2012 18:58:03 +0200
changeset 2898 c7f6c498df6a
parent 2831 3dbef5687ae6
child 2904 bd6cacbab203
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 SimpleDialog subclass:#ColorEditDialog
    15 	instanceVariableNames:'red green blue hue light saturation colorNameHolder
    16 		htmlColorNameHolder colorDefinitionStringHolder previewBox
    17 		brightnessStringHolder'
    18 	classVariableNames:''
    19 	poolDictionaries:''
    20 	category:'Interface-UIPainter'
    21 !
    22 
    23 !ColorEditDialog class methodsFor:'documentation'!
    24 
    25 copyright
    26 "
    27  COPYRIGHT (c) 1995 by eXept Software AG
    28               All Rights Reserved
    29 
    30  This software is furnished under a license and may be used
    31  only in accordance with the terms of that license and with the
    32  inclusion of the above copyright notice.   This software may not
    33  be provided or otherwise made available to, or used by, any
    34  other person.  No title to or ownership of the software is
    35  hereby transferred.
    36 "
    37 !
    38 
    39 documentation
    40 "
    41     An edit-dialog for colors.
    42 "
    43 !
    44 
    45 examples
    46 "
    47                                                                                 [exBegin]                                      
    48     |editor color|
    49 
    50     editor := ColorEditDialog new.
    51     editor color:(Color green).
    52     editor open.
    53     editor accepted ifTrue:[
    54         editor color inspect.
    55     ]
    56                                                                                 [exEnd]
    57 "
    58 ! !
    59 
    60 !ColorEditDialog class methodsFor:'help specs'!
    61 
    62 flyByHelpSpec
    63     "This resource specification was automatically generated
    64      by the UIHelpTool of ST/X."
    65 
    66     "Do not manually edit this!! If it is corrupted,
    67      the UIHelpTool may not be able to read the specification."
    68 
    69     "
    70      UIHelpTool openOnClass:ColorEditDialog    
    71     "
    72 
    73     <resource: #help>
    74 
    75     ^ super flyByHelpSpec addPairsFrom:#(
    76 
    77 #pickColor
    78 'Pick a Color from the Screen'
    79 
    80 )
    81 !
    82 
    83 helpSpec
    84     "This resource specification was automatically generated
    85      by the UIHelpTool of ST/X."
    86 
    87     "Do not manually edit this!! If it is corrupted,
    88      the UIHelpTool may not be able to read the specification."
    89 
    90     "
    91      UIHelpTool openOnClass:ColorEditDialog    
    92     "
    93 
    94     <resource: #help>
    95 
    96     ^ super helpSpec addPairsFrom:#(
    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 
   107 #copyToClipboard
   108 'Copy the color to the clipboard'
   109 
   110 #hlsMixer
   111 'Mix color from hls (hue-light-saturation) components'
   112 
   113 #htmlColorName
   114 'The color as used in an HTML page.'
   115 
   116 #pasteFromClipboard
   117 'Paste color from the Clipboard'
   118 
   119 #rgbMixer
   120 'Mix color from rgb (red-green-blue) components'
   121 
   122 )
   123 ! !
   124 
   125 !ColorEditDialog class methodsFor:'image specs'!
   126 
   127 pickColorIcon
   128     ^ ToolbarIconLibrary pipette16x16Icon
   129 ! !
   130 
   131 !ColorEditDialog class methodsFor:'interface specs'!
   132 
   133 windowSpec
   134     "This resource specification was automatically generated
   135      by the UIPainter of ST/X."
   136 
   137     "Do not manually edit this!! If it is corrupted,
   138      the UIPainter may not be able to read the specification."
   139 
   140     "
   141      UIPainter new openOnClass:ColorEditDialog andSelector:#windowSpec
   142      ColorEditDialog new openInterface:#windowSpec
   143      ColorEditDialog open
   144     "
   145 
   146     <resource: #canvas>
   147 
   148     ^ 
   149      #(FullSpec
   150         name: windowSpec
   151         window: 
   152        (WindowSpec
   153           label: 'Define Color'
   154           name: 'Define Color'
   155           min: (Point 440 360)
   156           max: (Point 440 360)
   157           bounds: (Rectangle 0 0 440 360)
   158         )
   159         component: 
   160        (SpecCollection
   161           collection: (
   162            (VerticalPanelViewSpec
   163               name: 'RGBLabelPanel'
   164               layout: (LayoutFrame 0 0 0 0 70 0 76 0)
   165               horizontalLayout: fit
   166               verticalLayout: spreadSpace
   167               horizontalSpace: 3
   168               verticalSpace: 3
   169               component: 
   170              (SpecCollection
   171                 collection: (
   172                  (LabelSpec
   173                     label: 'Red:'
   174                     name: 'RedLabel'
   175                     translateLabel: true
   176                     adjust: right
   177                     useDefaultExtent: true
   178                   )
   179                  (LabelSpec
   180                     label: 'Green:'
   181                     name: 'GreenLabel'
   182                     translateLabel: true
   183                     adjust: right
   184                     useDefaultExtent: true
   185                   )
   186                  (LabelSpec
   187                     label: 'Blue:'
   188                     name: 'BlueLabel'
   189                     translateLabel: true
   190                     adjust: right
   191                     useDefaultExtent: true
   192                   )
   193                  )
   194                
   195               )
   196             )
   197            (VerticalPanelViewSpec
   198               name: 'RGBSliderPanel'
   199               layout: (LayoutFrame 70 0 0 0 -177 1 76 0)
   200               horizontalLayout: fit
   201               verticalLayout: spreadSpace
   202               horizontalSpace: 3
   203               verticalSpace: 3
   204               component: 
   205              (SpecCollection
   206                 collection: (
   207                  (SliderSpec
   208                     name: 'RedSlider'
   209                     tabable: false
   210                     model: red
   211                     orientation: horizontal
   212                     stop: 255
   213                     step: 1
   214                     backgroundColor: (Color 100.0 0.0 0.0)
   215                     extent: (Point 193 16)
   216                   )
   217                  (SliderSpec
   218                     name: 'GreenSlider'
   219                     tabable: false
   220                     model: green
   221                     orientation: horizontal
   222                     stop: 255
   223                     step: 1
   224                     backgroundColor: (Color 0.0 100.0 0.0)
   225                     extent: (Point 193 16)
   226                   )
   227                  (SliderSpec
   228                     name: 'BlueSlider'
   229                     tabable: false
   230                     model: blue
   231                     orientation: horizontal
   232                     stop: 255
   233                     step: 1
   234                     backgroundColor: (Color 0.0 0.0 100.0)
   235                     extent: (Point 193 16)
   236                   )
   237                  )
   238                
   239               )
   240             )
   241            (VerticalPanelViewSpec
   242               name: 'RGBFieldPanel'
   243               layout: (LayoutFrame -173 1 0 0 -143 1 76 0)
   244               horizontalLayout: fit
   245               verticalLayout: spreadSpace
   246               horizontalSpace: 3
   247               verticalSpace: 3
   248               component: 
   249              (SpecCollection
   250                 collection: (
   251                  (InputFieldSpec
   252                     name: 'RedField'
   253                     model: red
   254                     type: numberInRange
   255                     numChars: 3
   256                     minValue: 0
   257                     maxValue: 255
   258                     acceptOnPointerLeave: false
   259                     extent: (Point 28 20)
   260                   )
   261                  (InputFieldSpec
   262                     name: 'GreenField'
   263                     model: green
   264                     type: numberInRange
   265                     numChars: 3
   266                     minValue: 0
   267                     maxValue: 255
   268                     acceptOnPointerLeave: false
   269                     extent: (Point 28 20)
   270                   )
   271                  (InputFieldSpec
   272                     name: 'BlueField'
   273                     model: blue
   274                     type: numberInRange
   275                     numChars: 3
   276                     minValue: 0
   277                     maxValue: 255
   278                     acceptOnPointerLeave: false
   279                     extent: (Point 28 20)
   280                   )
   281                  )
   282                
   283               )
   284             )
   285            (VerticalPanelViewSpec
   286               name: 'RGBFieldPanelHex'
   287               layout: (LayoutFrame -141 1 0 0 -119 1 76 0)
   288               horizontalLayout: fit
   289               verticalLayout: spreadSpace
   290               horizontalSpace: 3
   291               verticalSpace: 3
   292               component: 
   293              (SpecCollection
   294                 collection: (
   295                  (InputFieldSpec
   296                     name: 'EntryField4'
   297                     model: red
   298                     type: hexIntegerInRange
   299                     numChars: 3
   300                     minValue: 0
   301                     maxValue: 255
   302                     acceptOnPointerLeave: false
   303                     extent: (Point 20 20)
   304                   )
   305                  (InputFieldSpec
   306                     name: 'EntryField5'
   307                     model: green
   308                     type: hexIntegerInRange
   309                     numChars: 3
   310                     minValue: 0
   311                     maxValue: 255
   312                     acceptOnPointerLeave: false
   313                     extent: (Point 20 20)
   314                   )
   315                  (InputFieldSpec
   316                     name: 'EntryField6'
   317                     model: blue
   318                     type: hexIntegerInRange
   319                     numChars: 3
   320                     minValue: 0
   321                     maxValue: 255
   322                     acceptOnPointerLeave: false
   323                     extent: (Point 20 20)
   324                   )
   325                  )
   326                
   327               )
   328             )
   329            (VerticalPanelViewSpec
   330               name: 'HLSLabelPanel'
   331               layout: (LayoutFrame 0 0 86 0 70 0 163 0)
   332               horizontalLayout: fit
   333               verticalLayout: spreadSpace
   334               horizontalSpace: 3
   335               verticalSpace: 3
   336               component: 
   337              (SpecCollection
   338                 collection: (
   339                  (LabelSpec
   340                     label: 'Hue:'
   341                     name: 'Label1'
   342                     translateLabel: true
   343                     adjust: right
   344                     useDefaultExtent: true
   345                   )
   346                  (LabelSpec
   347                     label: 'Light:'
   348                     name: 'Label2'
   349                     translateLabel: true
   350                     adjust: right
   351                     useDefaultExtent: true
   352                   )
   353                  (LabelSpec
   354                     label: 'Saturation:'
   355                     name: 'Label3'
   356                     translateLabel: true
   357                     adjust: right
   358                     useDefaultExtent: true
   359                   )
   360                  )
   361                
   362               )
   363             )
   364            (VerticalPanelViewSpec
   365               name: 'HLSSliderPanel'
   366               layout: (LayoutFrame 70 0 86 0 -177 1 163 0)
   367               horizontalLayout: fit
   368               verticalLayout: spreadSpace
   369               horizontalSpace: 3
   370               verticalSpace: 3
   371               component: 
   372              (SpecCollection
   373                 collection: (
   374                  (SliderSpec
   375                     name: 'Slider1'
   376                     tabable: false
   377                     model: hue
   378                     orientation: horizontal
   379                     stop: 359
   380                     step: 1
   381                     keyboardStep: 1
   382                     extent: (Point 193 16)
   383                   )
   384                  (SliderSpec
   385                     name: 'Slider2'
   386                     tabable: false
   387                     model: light
   388                     orientation: horizontal
   389                     step: 1
   390                     backgroundColor: (Color 66.9993133440146 66.9993133440146 66.9993133440146)
   391                     keyboardStep: 1
   392                     extent: (Point 193 16)
   393                   )
   394                  (SliderSpec
   395                     name: 'Slider3'
   396                     tabable: false
   397                     model: saturation
   398                     orientation: horizontal
   399                     step: 1
   400                     backgroundColor: (Color 66.9993133440146 66.9993133440146 66.9993133440146)
   401                     keyboardStep: 1
   402                     extent: (Point 193 16)
   403                   )
   404                  )
   405                
   406               )
   407             )
   408            (VerticalPanelViewSpec
   409               name: 'HLSFieldPanel'
   410               layout: (LayoutFrame -173 1 86 0 -143 1 163 0)
   411               horizontalLayout: fit
   412               verticalLayout: spreadSpace
   413               horizontalSpace: 3
   414               verticalSpace: 3
   415               component: 
   416              (SpecCollection
   417                 collection: (
   418                  (InputFieldSpec
   419                     name: 'EntryField1'
   420                     model: hue
   421                     type: numberInRange
   422                     numChars: 3
   423                     minValue: 0
   424                     maxValue: 359
   425                     acceptOnPointerLeave: false
   426                     extent: (Point 28 20)
   427                   )
   428                  (InputFieldSpec
   429                     name: 'EntryField2'
   430                     model: light
   431                     type: numberInRange
   432                     numChars: 3
   433                     minValue: 0
   434                     maxValue: 100
   435                     acceptOnPointerLeave: false
   436                     extent: (Point 28 20)
   437                   )
   438                  (InputFieldSpec
   439                     name: 'EntryField3'
   440                     model: saturation
   441                     type: numberInRange
   442                     numChars: 3
   443                     minValue: 0
   444                     maxValue: 100
   445                     acceptOnPointerLeave: false
   446                     extent: (Point 28 20)
   447                   )
   448                  )
   449                
   450               )
   451             )
   452            (ViewSpec
   453               name: 'PreviewBoxFrame'
   454               layout: (LayoutFrame -117 1 4 0.0 -3 1.0 -39 1.0)
   455               level: 1
   456               component: 
   457              (SpecCollection
   458                 collection: (
   459                  (LabelSpec
   460                     label: 'Preview'
   461                     name: 'PreviewBox'
   462                     layout: (LayoutFrame 2 0.0 2 0.0 -2 1.0 -2 1.0)
   463                     level: -1
   464                     translateLabel: true
   465                     postBuildCallback: postBuildPreviewBox:
   466                   )
   467                  )
   468                
   469               )
   470             )
   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
   492               label: 'Color Name:'
   493               name: 'ColorNameLabel'
   494               layout: (LayoutFrame 2 0 214 0 115 0 236 0)
   495               activeHelpKey: colorName
   496               translateLabel: true
   497               adjust: right
   498             )
   499            (InputFieldSpec
   500               name: 'ColorNameField'
   501               layout: (LayoutFrame 117 0 214 0 -122 1 236 0)
   502               activeHelpKey: colorName
   503               model: colorNameHolder
   504               immediateAccept: false
   505               acceptOnReturn: true
   506               acceptOnTab: true
   507               acceptOnLostFocus: true
   508               acceptOnPointerLeave: true
   509             )
   510            (LabelSpec
   511               label: 'HTML Color Name:'
   512               name: 'HTMLColorNameLabel'
   513               layout: (LayoutFrame 2 0 240 0 115 0 262 0)
   514               activeHelpKey: htmlColorName
   515               translateLabel: true
   516               adjust: right
   517             )
   518            (InputFieldSpec
   519               name: 'MLHTColorNameFieldField'
   520               layout: (LayoutFrame 117 0 240 0 -122 1 262 0)
   521               activeHelpKey: htmlColorName
   522               model: htmlColorNameHolder
   523               immediateAccept: false
   524               acceptOnReturn: true
   525               acceptOnTab: true
   526               acceptOnLostFocus: true
   527               acceptOnPointerLeave: true
   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             )
   549            (ActionButtonSpec
   550               label: 'Copy Color'
   551               name: 'CopyColor'
   552               layout: (LayoutFrame 12 0 298 0 100 0 320 0)
   553               activeHelpKey: hlsMixer
   554               translateLabel: true
   555               resizeForLabel: true
   556               tabable: true
   557               model: copyColor
   558             )
   559            (ActionButtonSpec
   560               label: 'Paste Color'
   561               name: 'PasteColor'
   562               layout: (LayoutFrame 108 0 298 0 196 0 320 0)
   563               translateLabel: true
   564               resizeForLabel: true
   565               tabable: true
   566               model: pasteColor
   567             )
   568            (ActionButtonSpec
   569               label: 'pickColorIcon'
   570               name: 'Button1'
   571               layout: (LayoutFrame 285 0 298 0 312 0 325 0)
   572               activeHelpKey: pickColor
   573               hasCharacterOrientedLabel: false
   574               translateLabel: true
   575               resizeForLabel: true
   576               tabable: true
   577               model: pickColor
   578             )
   579            (HorizontalPanelViewSpec
   580               name: 'HorizontalPanel1'
   581               layout: (LayoutFrame 0 0.0 -32 1 0 1.0 0 1.0)
   582               horizontalLayout: fitSpace
   583               verticalLayout: centerMax
   584               horizontalSpace: 3
   585               verticalSpace: 3
   586               reverseOrderIfOKAtLeft: true
   587               component: 
   588              (SpecCollection
   589                 collection: (
   590                  (ActionButtonSpec
   591                     label: 'Cancel'
   592                     name: 'CancelButton'
   593                     translateLabel: true
   594                     resizeForLabel: false
   595                     tabable: true
   596                     model: cancel
   597                     useDefaultExtent: true
   598                   )
   599                  (ActionButtonSpec
   600                     label: 'OK'
   601                     name: 'OKButton'
   602                     translateLabel: true
   603                     resizeForLabel: false
   604                     tabable: true
   605                     model: accept
   606                     isDefault: true
   607                     defaultable: true
   608                     useDefaultExtent: true
   609                   )
   610                  )
   611                
   612               )
   613             )
   614            )
   615          
   616         )
   617       )
   618 ! !
   619 
   620 !ColorEditDialog class methodsFor:'startup'!
   621 
   622 openOn:aColor
   623     ^ self new
   624         color:aColor;
   625         open;
   626         yourself
   627 
   628     "
   629      self openOn:Color red
   630     "
   631 ! !
   632 
   633 !ColorEditDialog methodsFor:'accessing'!
   634 
   635 color
   636     |colorName|
   637 
   638     colorName := self colorName.
   639     colorName notEmptyOrNil ifTrue:[
   640         ^ Color name:(colorName asSymbol)
   641     ].
   642     ^ Color redByte:(red value) greenByte:(green value) blueByte:(blue value)
   643 !
   644 
   645 color:aColor
   646     aColor isNil ifTrue:[
   647         ^ self
   648     ].
   649 
   650     aColor isSymbol ifTrue:[
   651         self colorNameHolder value:aColor
   652     ] ifFalse:[
   653         self red value:aColor redByte.
   654         self green value:aColor greenByte.
   655         self blue value:aColor blueByte.
   656     ]
   657 !
   658 
   659 colorName
   660     ^ colorNameHolder value
   661 !
   662 
   663 colorNameOrColor
   664     |colorName|
   665 
   666     colorName := self colorName.
   667     colorName notEmptyOrNil ifTrue:[
   668         "/ ^ Color name:(colorName asSymbol)
   669         ^ colorName asSymbol
   670     ].
   671     ^ Color redByte:(red value) greenByte:(green value) blueByte:(blue value)
   672 !
   673 
   674 htmlColorName
   675     ^ htmlColorNameHolder value
   676 ! !
   677 
   678 !ColorEditDialog methodsFor:'actions'!
   679 
   680 colorChanged
   681     |clr nm|
   682 
   683     clr := self colorNameOrColor.
   684     clr isColor ifTrue:[
   685         "not a symbol"
   686         self setPreview:clr.
   687         self htmlColorNameHolder value:(clr htmlPrintString) withoutNotifying:self.
   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"
   699 !
   700 
   701 colorChangedTo:clr
   702     "compute rgb and hls (if possible)"
   703 
   704     |h|
   705 
   706     self red   value:clr redByte withoutNotifying:self.
   707     self green value:clr greenByte withoutNotifying:self.
   708     self blue  value:clr blueByte withoutNotifying:self.
   709 
   710     h := clr hue.
   711     h notNil ifTrue:[
   712         self hue        value:(h rounded) withoutNotifying:self.
   713     ].
   714     self light      value:(clr light rounded) withoutNotifying:self.
   715     self saturation value:(clr saturation rounded) withoutNotifying:self.
   716 
   717     self colorChanged
   718 
   719     "Modified: / 27-01-2011 / 12:48:28 / cg"
   720 !
   721 
   722 colorNameChanged
   723     "compute rgb and hls (if possible)"
   724 
   725     |clr|
   726 
   727     clr := Color name:colorNameHolder value ifIllegal:nil.
   728     clr isNil ifTrue:[
   729         ^ self
   730     ].
   731     self colorChangedTo:clr.
   732 !
   733 
   734 copyColor
   735     self window setClipboardObject:self color
   736 !
   737 
   738 copyColorName
   739     self window setClipboardText:self htmlColorName
   740 !
   741 
   742 hlsSliderChanged
   743     "compute rgb"
   744 
   745     Color withRGBFromHue:hue value light:light value saturation:saturation value do:[:r :g :b |
   746         red    value:(r * 255 / 100) rounded withoutNotifying:self.
   747         green  value:(g * 255 / 100) rounded withoutNotifying:self.
   748         blue   value:(b * 255 / 100) rounded withoutNotifying:self.
   749     ].
   750     colorNameHolder value:'' withoutNotifying:self.
   751     self colorChanged
   752 !
   753 
   754 htmlColorNameChanged
   755     "compute rgb and hls (if possible)"
   756 
   757     |clr|
   758 
   759     htmlColorNameHolder value isEmptyOrNil ifTrue:[
   760         ^ self.
   761     ].
   762 
   763     clr := Color rgbValue:(Integer 
   764                                 readFrom:(htmlColorNameHolder value copyFrom:2)
   765                                 radix:16
   766                                 onError:nil).
   767     clr isNil ifTrue:[
   768         ^ self
   769     ].
   770     self colorNameHolder value:'' withoutNotifying:self.
   771     self colorChangedTo:clr.
   772 !
   773 
   774 pasteColor
   775     |copyBufferColor|
   776 
   777     copyBufferColor := self window getClipboardObject.
   778     copyBufferColor isColor ifFalse:[
   779         UserPreferences current beepInEditor ifTrue:[                
   780             self window beep.
   781         ].
   782         ^ self
   783     ].
   784     self color:copyBufferColor
   785 !
   786 
   787 pickColor
   788     |color|
   789 
   790     color := Color fromUserWithFeedBack:[:clr | self setPreview:clr].
   791     color notNil ifTrue:[
   792         self color:color.
   793     ]
   794 !
   795 
   796 rgbSliderChanged
   797     "compute hls"
   798 
   799     |r g b|
   800 
   801     r := self red value.
   802     g := self green value.
   803     b := self blue value.
   804 
   805     Color withHLSFromRed:(r * 100 / 255) green:(g * 100 / 255) blue:(b * 100 / 255) do:[:h :l :s |
   806         h isNil ifTrue:[
   807             "/ achromatic
   808         ] ifFalse:[
   809             self hue    value:(h rounded) withoutNotifying:self.
   810         ].
   811         self light      value:(l rounded) withoutNotifying:self.
   812         self saturation value:(s rounded) withoutNotifying:self.
   813     ].
   814     self colorNameHolder value:'' withoutNotifying:self.
   815     self colorChanged
   816 !
   817 
   818 setPreview:color
   819     previewBox isNil ifTrue:[^ self "called before setup"].
   820 
   821     previewBox backgroundColor:color.
   822     previewBox foregroundColor:(color brightness < 0.5 
   823                             ifTrue:[Color white] 
   824                             ifFalse:[Color black]).
   825 ! !
   826 
   827 !ColorEditDialog methodsFor:'aspects'!
   828 
   829 blue
   830     blue isNil ifTrue:[
   831         blue := 0 asValue.
   832         blue addDependent:self.
   833     ].
   834     ^blue
   835 !
   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 
   857 colorNameHolder
   858     colorNameHolder isNil ifTrue:[
   859         colorNameHolder := '' asValue.
   860         colorNameHolder addDependent:self.
   861     ].
   862     ^colorNameHolder
   863 !
   864 
   865 green
   866     green isNil ifTrue:[
   867         green := 0 asValue.
   868         green addDependent:self.
   869     ].
   870     ^green
   871 !
   872 
   873 htmlColorNameHolder
   874     htmlColorNameHolder isNil ifTrue:[
   875         htmlColorNameHolder := '' asValue.
   876         htmlColorNameHolder addDependent:self.
   877     ].
   878     ^htmlColorNameHolder
   879 !
   880 
   881 hue
   882     hue isNil ifTrue:[
   883         hue := 0 asValue.
   884         hue addDependent:self.
   885     ].
   886     ^hue
   887 !
   888 
   889 light
   890     light isNil ifTrue:[
   891         light := 0 asValue.
   892         light addDependent:self.
   893     ].
   894     ^light
   895 !
   896 
   897 red
   898     red isNil ifTrue:[
   899         red := 0 asValue.
   900         red addDependent:self.
   901     ].
   902     ^red
   903 !
   904 
   905 saturation
   906     saturation isNil ifTrue:[
   907         saturation := 0 asValue.
   908         saturation addDependent:self.
   909     ].
   910     ^saturation
   911 ! !
   912 
   913 !ColorEditDialog methodsFor:'change & update'!
   914 
   915 update:something with:aParameter from:changedObject
   916     (changedObject == red
   917     or:[changedObject == green
   918     or:[changedObject == blue]]) ifTrue:[
   919         self rgbSliderChanged.
   920         ^ self
   921     ].
   922 
   923     (changedObject == hue
   924     or:[changedObject == light
   925     or:[changedObject == saturation]]) ifTrue:[
   926         self hlsSliderChanged.
   927         ^ self
   928     ].
   929 
   930     (changedObject == colorNameHolder) ifTrue:[
   931         self colorNameChanged.
   932         ^ self
   933     ].
   934     (changedObject == htmlColorNameHolder) ifTrue:[
   935         self htmlColorNameChanged.
   936         ^ self
   937     ].
   938 
   939     super update:something with:aParameter from:changedObject
   940 ! !
   941 
   942 !ColorEditDialog methodsFor:'startup & release'!
   943 
   944 postBuildPreviewBox:aView
   945     previewBox := aView
   946 !
   947 
   948 postBuildWith:aBuilder
   949     super postBuildWith:aBuilder.
   950     self colorChanged.
   951 
   952     "Modified: / 6.9.1998 / 22:55:25 / cg"
   953 ! !
   954 
   955 !ColorEditDialog class methodsFor:'documentation'!
   956 
   957 version
   958     ^ '$Header$'
   959 !
   960 
   961 version_CVS
   962     ^ '$Header$'
   963 ! !