ColorEditDialog.st
changeset 2224 6ec083adc6bf
parent 1846 65558eb9f4d3
child 2228 6736186fc553
equal deleted inserted replaced
2223:7cddff46d0ad 2224:6ec083adc6bf
     7  inclusion of the above copyright notice.   This software may not
     7  inclusion of the above copyright notice.   This software may not
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
       
    13 "{ Package: 'stx:libtool2' }"
    12 "{ Package: 'stx:libtool2' }"
    14 
    13 
    15 SimpleDialog subclass:#ColorEditDialog
    14 SimpleDialog subclass:#ColorEditDialog
    16 	instanceVariableNames:'red green blue hue light saturation colorNameHolder'
    15 	instanceVariableNames:'red green blue hue light saturation colorNameHolder
       
    16 		htmlColorNameHolder'
    17 	classVariableNames:''
    17 	classVariableNames:''
    18 	poolDictionaries:''
    18 	poolDictionaries:''
    19 	category:'Interface-UIPainter'
    19 	category:'Interface-UIPainter'
    20 !
    20 !
    21 
    21 
    64 
    64 
    65     "Do not manually edit this!! If it is corrupted,
    65     "Do not manually edit this!! If it is corrupted,
    66      the UIPainter may not be able to read the specification."
    66      the UIPainter may not be able to read the specification."
    67 
    67 
    68     "
    68     "
    69      UIPainter new openOnClass:ColorEditor andSelector:#windowSpec
    69      UIPainter new openOnClass:ColorEditDialog andSelector:#windowSpec
    70      ColorEditor new openInterface:#windowSpec
    70      ColorEditDialog new openInterface:#windowSpec
    71      ColorEditor open
    71      ColorEditDialog open
    72     "
    72     "
    73 
    73 
    74     <resource: #canvas>
    74     <resource: #canvas>
    75 
    75 
    76     ^ 
    76     ^ 
    78         name: windowSpec
    78         name: windowSpec
    79         window: 
    79         window: 
    80        (WindowSpec
    80        (WindowSpec
    81           label: 'Define Color'
    81           label: 'Define Color'
    82           name: 'Define Color'
    82           name: 'Define Color'
    83           min: (Point 340 260)
    83           min: (Point 440 300)
    84           max: (Point nil 260)
    84           max: (Point 440 300)
    85           bounds: (Rectangle 0 0 453 260)
    85           bounds: (Rectangle 0 0 436 300)
    86         )
    86         )
    87         component: 
    87         component: 
    88        (SpecCollection
    88        (SpecCollection
    89           collection: (
    89           collection: (
    90            (VerticalPanelViewSpec
    90            (VerticalPanelViewSpec
   122                
   122                
   123               )
   123               )
   124             )
   124             )
   125            (VerticalPanelViewSpec
   125            (VerticalPanelViewSpec
   126               name: 'RGBSliderPanel'
   126               name: 'RGBSliderPanel'
   127               layout: (LayoutFrame 62 0 0 0 -166 1 76 0)
   127               layout: (LayoutFrame 62 0 0 0 -177 1 76 0)
   128               horizontalLayout: fit
   128               horizontalLayout: fit
   129               verticalLayout: spreadSpace
   129               verticalLayout: spreadSpace
   130               horizontalSpace: 3
   130               horizontalSpace: 3
   131               verticalSpace: 3
   131               verticalSpace: 3
   132               component: 
   132               component: 
   138                     model: red
   138                     model: red
   139                     orientation: horizontal
   139                     orientation: horizontal
   140                     stop: 255
   140                     stop: 255
   141                     step: 1
   141                     step: 1
   142                     backgroundColor: (Color 100.0 0.0 0.0)
   142                     backgroundColor: (Color 100.0 0.0 0.0)
   143                     extent: (Point 225 16)
   143                     extent: (Point 197 16)
   144                   )
   144                   )
   145                  (SliderSpec
   145                  (SliderSpec
   146                     name: 'GreenSlider'
   146                     name: 'GreenSlider'
   147                     tabable: false
   147                     tabable: false
   148                     model: green
   148                     model: green
   149                     orientation: horizontal
   149                     orientation: horizontal
   150                     stop: 255
   150                     stop: 255
   151                     step: 1
   151                     step: 1
   152                     backgroundColor: (Color 0.0 100.0 0.0)
   152                     backgroundColor: (Color 0.0 100.0 0.0)
   153                     extent: (Point 225 16)
   153                     extent: (Point 197 16)
   154                   )
   154                   )
   155                  (SliderSpec
   155                  (SliderSpec
   156                     name: 'BlueSlider'
   156                     name: 'BlueSlider'
   157                     tabable: false
   157                     tabable: false
   158                     model: blue
   158                     model: blue
   159                     orientation: horizontal
   159                     orientation: horizontal
   160                     stop: 255
   160                     stop: 255
   161                     step: 1
   161                     step: 1
   162                     backgroundColor: (Color 0.0 0.0 100.0)
   162                     backgroundColor: (Color 0.0 0.0 100.0)
   163                     extent: (Point 225 16)
   163                     extent: (Point 197 16)
   164                   )
   164                   )
   165                  )
   165                  )
   166                
   166                
   167               )
   167               )
   168             )
   168             )
   169            (VerticalPanelViewSpec
   169            (VerticalPanelViewSpec
   170               name: 'RGBFieldPanel'
   170               name: 'RGBFieldPanel'
   171               layout: (LayoutFrame -161 1 0 0 -123 1 76 0)
   171               layout: (LayoutFrame -173 1 0 0 -143 1 76 0)
   172               horizontalLayout: fit
   172               horizontalLayout: fit
   173               verticalLayout: spreadSpace
   173               verticalLayout: spreadSpace
   174               horizontalSpace: 3
   174               horizontalSpace: 3
   175               verticalSpace: 3
   175               verticalSpace: 3
   176               component: 
   176               component: 
   182                     type: numberInRange
   182                     type: numberInRange
   183                     numChars: 3
   183                     numChars: 3
   184                     minValue: 0
   184                     minValue: 0
   185                     maxValue: 255
   185                     maxValue: 255
   186                     acceptOnPointerLeave: false
   186                     acceptOnPointerLeave: false
   187                     extent: (Point 38 20)
   187                     extent: (Point 30 20)
   188                   )
   188                   )
   189                  (InputFieldSpec
   189                  (InputFieldSpec
   190                     name: 'GreenField'
   190                     name: 'GreenField'
   191                     model: green
   191                     model: green
   192                     type: numberInRange
   192                     type: numberInRange
   193                     numChars: 3
   193                     numChars: 3
   194                     minValue: 0
   194                     minValue: 0
   195                     maxValue: 255
   195                     maxValue: 255
   196                     acceptOnPointerLeave: false
   196                     acceptOnPointerLeave: false
   197                     extent: (Point 38 20)
   197                     extent: (Point 30 20)
   198                   )
   198                   )
   199                  (InputFieldSpec
   199                  (InputFieldSpec
   200                     name: 'BlueField'
   200                     name: 'BlueField'
   201                     model: blue
   201                     model: blue
   202                     type: numberInRange
   202                     type: numberInRange
   203                     numChars: 3
   203                     numChars: 3
   204                     minValue: 0
   204                     minValue: 0
   205                     maxValue: 255
   205                     maxValue: 255
   206                     acceptOnPointerLeave: false
   206                     acceptOnPointerLeave: false
   207                     extent: (Point 38 20)
   207                     extent: (Point 30 20)
       
   208                   )
       
   209                  )
       
   210                
       
   211               )
       
   212             )
       
   213            (VerticalPanelViewSpec
       
   214               name: 'RGBFieldPanelHex'
       
   215               layout: (LayoutFrame -141 1 0 0 -121 1 76 0)
       
   216               horizontalLayout: fit
       
   217               verticalLayout: spreadSpace
       
   218               horizontalSpace: 3
       
   219               verticalSpace: 3
       
   220               component: 
       
   221              (SpecCollection
       
   222                 collection: (
       
   223                  (InputFieldSpec
       
   224                     name: 'EntryField4'
       
   225                     model: red
       
   226                     type: hexIntegerInRange
       
   227                     numChars: 3
       
   228                     minValue: 0
       
   229                     maxValue: 255
       
   230                     acceptOnPointerLeave: false
       
   231                     extent: (Point 20 20)
       
   232                   )
       
   233                  (InputFieldSpec
       
   234                     name: 'EntryField5'
       
   235                     model: green
       
   236                     type: hexIntegerInRange
       
   237                     numChars: 3
       
   238                     minValue: 0
       
   239                     maxValue: 255
       
   240                     acceptOnPointerLeave: false
       
   241                     extent: (Point 20 20)
       
   242                   )
       
   243                  (InputFieldSpec
       
   244                     name: 'EntryField6'
       
   245                     model: blue
       
   246                     type: hexIntegerInRange
       
   247                     numChars: 3
       
   248                     minValue: 0
       
   249                     maxValue: 255
       
   250                     acceptOnPointerLeave: false
       
   251                     extent: (Point 20 20)
   208                   )
   252                   )
   209                  )
   253                  )
   210                
   254                
   211               )
   255               )
   212             )
   256             )
   245                
   289                
   246               )
   290               )
   247             )
   291             )
   248            (VerticalPanelViewSpec
   292            (VerticalPanelViewSpec
   249               name: 'HLSSliderPanel'
   293               name: 'HLSSliderPanel'
   250               layout: (LayoutFrame 62 0 86 0 -166 1 163 0)
   294               layout: (LayoutFrame 62 0 86 0 -177 1 163 0)
   251               horizontalLayout: fit
   295               horizontalLayout: fit
   252               verticalLayout: spreadSpace
   296               verticalLayout: spreadSpace
   253               horizontalSpace: 3
   297               horizontalSpace: 3
   254               verticalSpace: 3
   298               verticalSpace: 3
   255               component: 
   299               component: 
   261                     model: hue
   305                     model: hue
   262                     orientation: horizontal
   306                     orientation: horizontal
   263                     stop: 359
   307                     stop: 359
   264                     step: 1
   308                     step: 1
   265                     keyboardStep: 1
   309                     keyboardStep: 1
   266                     extent: (Point 225 16)
   310                     extent: (Point 197 16)
   267                   )
   311                   )
   268                  (SliderSpec
   312                  (SliderSpec
   269                     name: 'Slider2'
   313                     name: 'Slider2'
   270                     tabable: false
   314                     tabable: false
   271                     model: light
   315                     model: light
   272                     orientation: horizontal
   316                     orientation: horizontal
   273                     step: 1
   317                     step: 1
   274                     backgroundColor: (Color 66.9993 66.9993 66.9993)
   318                     backgroundColor: (Color 66.999313344015 66.999313344015 66.999313344015)
   275                     keyboardStep: 1
   319                     keyboardStep: 1
   276                     extent: (Point 225 16)
   320                     extent: (Point 197 16)
   277                   )
   321                   )
   278                  (SliderSpec
   322                  (SliderSpec
   279                     name: 'Slider3'
   323                     name: 'Slider3'
   280                     tabable: false
   324                     tabable: false
   281                     model: saturation
   325                     model: saturation
   282                     orientation: horizontal
   326                     orientation: horizontal
   283                     step: 1
   327                     step: 1
   284                     backgroundColor: (Color 66.9993 66.9993 66.9993)
   328                     backgroundColor: (Color 66.999313344015 66.999313344015 66.999313344015)
   285                     keyboardStep: 1
   329                     keyboardStep: 1
   286                     extent: (Point 225 16)
   330                     extent: (Point 197 16)
   287                   )
   331                   )
   288                  )
   332                  )
   289                
   333                
   290               )
   334               )
   291             )
   335             )
   292            (VerticalPanelViewSpec
   336            (VerticalPanelViewSpec
   293               name: 'HLSFieldPanel'
   337               name: 'HLSFieldPanel'
   294               layout: (LayoutFrame -161 1 86 0 -123 1 163 0)
   338               layout: (LayoutFrame -173 1 86 0 -143 1 163 0)
   295               horizontalLayout: fit
   339               horizontalLayout: fit
   296               verticalLayout: spreadSpace
   340               verticalLayout: spreadSpace
   297               horizontalSpace: 3
   341               horizontalSpace: 3
   298               verticalSpace: 3
   342               verticalSpace: 3
   299               component: 
   343               component: 
   305                     type: numberInRange
   349                     type: numberInRange
   306                     numChars: 3
   350                     numChars: 3
   307                     minValue: 0
   351                     minValue: 0
   308                     maxValue: 359
   352                     maxValue: 359
   309                     acceptOnPointerLeave: false
   353                     acceptOnPointerLeave: false
   310                     extent: (Point 38 20)
   354                     extent: (Point 30 20)
   311                   )
   355                   )
   312                  (InputFieldSpec
   356                  (InputFieldSpec
   313                     name: 'EntryField2'
   357                     name: 'EntryField2'
   314                     model: light
   358                     model: light
   315                     type: numberInRange
   359                     type: numberInRange
   316                     numChars: 3
   360                     numChars: 3
   317                     minValue: 0
   361                     minValue: 0
   318                     maxValue: 100
   362                     maxValue: 100
   319                     acceptOnPointerLeave: false
   363                     acceptOnPointerLeave: false
   320                     extent: (Point 38 20)
   364                     extent: (Point 30 20)
   321                   )
   365                   )
   322                  (InputFieldSpec
   366                  (InputFieldSpec
   323                     name: 'EntryField3'
   367                     name: 'EntryField3'
   324                     model: saturation
   368                     model: saturation
   325                     type: numberInRange
   369                     type: numberInRange
   326                     numChars: 3
   370                     numChars: 3
   327                     minValue: 0
   371                     minValue: 0
   328                     maxValue: 100
   372                     maxValue: 100
   329                     acceptOnPointerLeave: false
   373                     acceptOnPointerLeave: false
   330                     extent: (Point 38 20)
   374                     extent: (Point 30 20)
   331                   )
   375                   )
   332                  )
   376                  )
   333                
   377                
   334               )
   378               )
   335             )
   379             )
   352               )
   396               )
   353             )
   397             )
   354            (LabelSpec
   398            (LabelSpec
   355               label: 'Color Name:'
   399               label: 'Color Name:'
   356               name: 'ColorNameLabel'
   400               name: 'ColorNameLabel'
   357               layout: (LayoutFrame 0 0 190 0 106 0 212 0)
   401               layout: (LayoutFrame 0 0 176 0 106 0 198 0)
   358               translateLabel: true
   402               translateLabel: true
   359               adjust: right
   403               adjust: right
   360             )
   404             )
   361            (InputFieldSpec
   405            (InputFieldSpec
   362               name: 'ColorNameField'
   406               name: 'ColorNameField'
   363               layout: (LayoutFrame 110 0 190 0 -123 1 212 0)
   407               layout: (LayoutFrame 108 0 176 0 -162 1 198 0)
   364               model: colorNameHolder
   408               model: colorNameHolder
   365               immediateAccept: true
   409               immediateAccept: true
   366               acceptOnReturn: true
   410               acceptOnReturn: true
   367               acceptOnTab: true
   411               acceptOnTab: true
   368               acceptOnLostFocus: true
   412               acceptOnLostFocus: true
   401                   )
   445                   )
   402                  )
   446                  )
   403                
   447                
   404               )
   448               )
   405             )
   449             )
       
   450            (LabelSpec
       
   451               label: 'HTML Color Name:'
       
   452               name: 'HTMLColorNameLabel'
       
   453               layout: (LayoutFrame 4 0 204 0 110 0 226 0)
       
   454               translateLabel: true
       
   455               adjust: right
       
   456             )
       
   457            (InputFieldSpec
       
   458               name: 'MLHTColorNameFieldField'
       
   459               layout: (LayoutFrame 108 0 204 0 -162 1 226 0)
       
   460               model: htmlColorNameHolder
       
   461               immediateAccept: true
       
   462               acceptOnReturn: true
       
   463               acceptOnTab: true
       
   464               acceptOnLostFocus: true
       
   465               acceptOnPointerLeave: false
       
   466             )
       
   467            (ActionButtonSpec
       
   468               label: 'Copy Color'
       
   469               name: 'CopyColor'
       
   470               layout: (LayoutFrame 12 0 236 0 100 0 258 0)
       
   471               translateLabel: true
       
   472               resizeForLabel: true
       
   473               tabable: true
       
   474               model: copyColor
       
   475             )
       
   476            (ActionButtonSpec
       
   477               label: 'Paste Color'
       
   478               name: 'PasteColor'
       
   479               layout: (LayoutFrame 108 0 236 0 196 0 258 0)
       
   480               translateLabel: true
       
   481               resizeForLabel: true
       
   482               tabable: true
       
   483               model: pasteColor
       
   484             )
   406            )
   485            )
   407          
   486          
   408         )
   487         )
   409       )
   488       )
   410 ! !
   489 ! !
   423     ]
   502     ]
   424 !
   503 !
   425 
   504 
   426 colorName
   505 colorName
   427     ^ colorNameHolder value
   506     ^ colorNameHolder value
       
   507 !
       
   508 
       
   509 htmlColorName
       
   510     ^ htmlColorNameHolder value
   428 ! !
   511 ! !
   429 
   512 
   430 !ColorEditDialog methodsFor:'actions'!
   513 !ColorEditDialog methodsFor:'actions'!
   431 
   514 
   432 colorChanged
   515 colorChanged
   438     clr := self color.
   521     clr := self color.
   439     box backgroundColor:clr.
   522     box backgroundColor:clr.
   440     box foregroundColor:(clr brightness < 0.5 
   523     box foregroundColor:(clr brightness < 0.5 
   441                             ifTrue:[Color white] 
   524                             ifTrue:[Color white] 
   442                             ifFalse:[Color black]).
   525                             ifFalse:[Color black]).
       
   526 
       
   527     self htmlColorNameHolder value:('#',clr hex).
   443 !
   528 !
   444 
   529 
   445 colorNameChanged
   530 colorNameChanged
   446     "compute rgb and hls (if possible)"
   531     "compute rgb and hls (if possible)"
   447 
   532 
   462     ].
   547     ].
   463     light      value:(clr light rounded) withoutNotifying:self.
   548     light      value:(clr light rounded) withoutNotifying:self.
   464     saturation value:(clr saturation rounded) withoutNotifying:self.
   549     saturation value:(clr saturation rounded) withoutNotifying:self.
   465 
   550 
   466     self colorChanged
   551     self colorChanged
       
   552 !
       
   553 
       
   554 copyColor
       
   555     self window setClipboardObject:self color
       
   556 !
       
   557 
       
   558 copyColorName
       
   559     self window setClipboardText:self htmlColorName
   467 !
   560 !
   468 
   561 
   469 hlsSliderChanged
   562 hlsSliderChanged
   470     "compute rgb"
   563     "compute rgb"
   471 
   564 
   474         green  value:(g * 255 / 100) rounded withoutNotifying:self.
   567         green  value:(g * 255 / 100) rounded withoutNotifying:self.
   475         blue   value:(b * 255 / 100) rounded withoutNotifying:self.
   568         blue   value:(b * 255 / 100) rounded withoutNotifying:self.
   476     ].
   569     ].
   477     colorNameHolder value:'' withoutNotifying:self.
   570     colorNameHolder value:'' withoutNotifying:self.
   478     self colorChanged
   571     self colorChanged
       
   572 !
       
   573 
       
   574 pasteColor
       
   575     |copyBufferColor|
       
   576 
       
   577     copyBufferColor := self window getClipboardObject.
       
   578     copyBufferColor isColor ifFalse:[
       
   579         self window beep.
       
   580         ^ self
       
   581     ].
       
   582     self color:copyBufferColor
   479 !
   583 !
   480 
   584 
   481 rgbSliderChanged
   585 rgbSliderChanged
   482     "compute hls"
   586     "compute hls"
   483 
   587 
   524         green addDependent:self.
   628         green addDependent:self.
   525     ].
   629     ].
   526     ^green
   630     ^green
   527 !
   631 !
   528 
   632 
       
   633 htmlColorNameHolder
       
   634     htmlColorNameHolder isNil ifTrue:[
       
   635         htmlColorNameHolder := '' asValue.
       
   636     ].
       
   637     ^htmlColorNameHolder
       
   638 !
       
   639 
   529 hue
   640 hue
   530     hue isNil ifTrue:[
   641     hue isNil ifTrue:[
   531         hue := 0 asValue.
   642         hue := 0 asValue.
   532         hue addDependent:self.
   643         hue addDependent:self.
   533     ].
   644     ].