ColorEditDialog.st
changeset 2326 f23fac376621
parent 2279 f077161d5d57
child 2347 c37fb02785bc
equal deleted inserted replaced
2325:51599f6d8013 2326:f23fac376621
   464             )
   464             )
   465            (InputFieldSpec
   465            (InputFieldSpec
   466               name: 'ColorNameField'
   466               name: 'ColorNameField'
   467               layout: (LayoutFrame 108 0 176 0 -162 1 198 0)
   467               layout: (LayoutFrame 108 0 176 0 -162 1 198 0)
   468               model: colorNameHolder
   468               model: colorNameHolder
   469               immediateAccept: true
   469               immediateAccept: false
   470               acceptOnReturn: true
   470               acceptOnReturn: true
   471               acceptOnTab: true
   471               acceptOnTab: true
   472               acceptOnLostFocus: true
   472               acceptOnLostFocus: true
   473               acceptOnPointerLeave: false
   473               acceptOnPointerLeave: true
       
   474             )
       
   475            (LabelSpec
       
   476               label: 'HTML Color Name:'
       
   477               name: 'HTMLColorNameLabel'
       
   478               layout: (LayoutFrame 4 0 204 0 110 0 226 0)
       
   479               translateLabel: true
       
   480               adjust: right
       
   481             )
       
   482            (InputFieldSpec
       
   483               name: 'MLHTColorNameFieldField'
       
   484               layout: (LayoutFrame 108 0 204 0 -162 1 226 0)
       
   485               model: htmlColorNameHolder
       
   486               immediateAccept: false
       
   487               acceptOnReturn: true
       
   488               acceptOnTab: true
       
   489               acceptOnLostFocus: true
       
   490               acceptOnPointerLeave: true
       
   491             )
       
   492            (ActionButtonSpec
       
   493               label: 'Copy Color'
       
   494               name: 'CopyColor'
       
   495               layout: (LayoutFrame 12 0 236 0 100 0 258 0)
       
   496               activeHelpKey: hlsMixer
       
   497               translateLabel: true
       
   498               resizeForLabel: true
       
   499               tabable: true
       
   500               model: copyColor
       
   501             )
       
   502            (ActionButtonSpec
       
   503               label: 'Paste Color'
       
   504               name: 'PasteColor'
       
   505               layout: (LayoutFrame 108 0 236 0 196 0 258 0)
       
   506               translateLabel: true
       
   507               resizeForLabel: true
       
   508               tabable: true
       
   509               model: pasteColor
       
   510             )
       
   511            (ActionButtonSpec
       
   512               label: 'pickColorIcon'
       
   513               name: 'Button1'
       
   514               layout: (LayoutFrame 285 0 236 0 312 0 263 0)
       
   515               activeHelpKey: pickColor
       
   516               hasCharacterOrientedLabel: false
       
   517               translateLabel: true
       
   518               resizeForLabel: true
       
   519               tabable: true
       
   520               model: pickColor
   474             )
   521             )
   475            (HorizontalPanelViewSpec
   522            (HorizontalPanelViewSpec
   476               name: 'HorizontalPanel1'
   523               name: 'HorizontalPanel1'
   477               layout: (LayoutFrame 0 0.0 -32 1 0 1.0 0 1.0)
   524               layout: (LayoutFrame 0 0.0 -32 1 0 1.0 0 1.0)
   478               horizontalLayout: fitSpace
   525               horizontalLayout: fitSpace
   505                   )
   552                   )
   506                  )
   553                  )
   507                
   554                
   508               )
   555               )
   509             )
   556             )
   510            (LabelSpec
       
   511               label: 'HTML Color Name:'
       
   512               name: 'HTMLColorNameLabel'
       
   513               layout: (LayoutFrame 4 0 204 0 110 0 226 0)
       
   514               translateLabel: true
       
   515               adjust: right
       
   516             )
       
   517            (InputFieldSpec
       
   518               name: 'MLHTColorNameFieldField'
       
   519               layout: (LayoutFrame 108 0 204 0 -162 1 226 0)
       
   520               model: htmlColorNameHolder
       
   521               immediateAccept: true
       
   522               acceptOnReturn: true
       
   523               acceptOnTab: true
       
   524               acceptOnLostFocus: true
       
   525               acceptOnPointerLeave: false
       
   526             )
       
   527            (ActionButtonSpec
       
   528               label: 'Copy Color'
       
   529               name: 'CopyColor'
       
   530               layout: (LayoutFrame 12 0 236 0 100 0 258 0)
       
   531               activeHelpKey: hlsMixer
       
   532               translateLabel: true
       
   533               resizeForLabel: true
       
   534               tabable: true
       
   535               model: copyColor
       
   536             )
       
   537            (ActionButtonSpec
       
   538               label: 'Paste Color'
       
   539               name: 'PasteColor'
       
   540               layout: (LayoutFrame 108 0 236 0 196 0 258 0)
       
   541               translateLabel: true
       
   542               resizeForLabel: true
       
   543               tabable: true
       
   544               model: pasteColor
       
   545             )
       
   546            (ActionButtonSpec
       
   547               label: 'pickColorIcon'
       
   548               name: 'Button1'
       
   549               layout: (LayoutFrame 285 0 236 0 312 0 263 0)
       
   550               activeHelpKey: pickColor
       
   551               hasCharacterOrientedLabel: false
       
   552               translateLabel: true
       
   553               resizeForLabel: true
       
   554               tabable: true
       
   555               model: pickColor
       
   556             )
       
   557            )
   557            )
   558          
   558          
   559         )
   559         )
   560       )
   560       )
   561 ! !
   561 ! !
   565 color
   565 color
   566     |colorName|
   566     |colorName|
   567 
   567 
   568     colorName := self colorName.
   568     colorName := self colorName.
   569     colorName notEmptyOrNil ifTrue:[
   569     colorName notEmptyOrNil ifTrue:[
       
   570         "/ ^ Color name:(colorName asSymbol)
   570         ^ colorName asSymbol
   571         ^ colorName asSymbol
   571     ].
   572     ].
   572     ^Color redByte:(red value) greenByte:(green value) blueByte:(blue value)
   573     ^ Color redByte:(red value) greenByte:(green value) blueByte:(blue value)
   573 !
   574 !
   574 
   575 
   575 color:aColor
   576 color:aColor
   576     aColor isNil ifTrue:[
   577     aColor isNil ifTrue:[
   577         ^ self
   578         ^ self
   601 
   602 
   602     clr := self color.
   603     clr := self color.
   603     clr isColor ifTrue:[
   604     clr isColor ifTrue:[
   604         "not a symbol"
   605         "not a symbol"
   605         self setPreview:clr.
   606         self setPreview:clr.
   606         self htmlColorNameHolder value:(clr htmlPrintString).
   607         self htmlColorNameHolder value:(clr htmlPrintString) withoutNotifying:self.
   607     ].
   608     ].
       
   609 !
       
   610 
       
   611 colorChangedTo:clr
       
   612     "compute rgb and hls (if possible)"
       
   613 
       
   614     |h|
       
   615 
       
   616     self red   value:clr redByte withoutNotifying:self.
       
   617     self green value:clr greenByte withoutNotifying:self.
       
   618     self blue  value:clr blueByte withoutNotifying:self.
       
   619 
       
   620     h := clr hue.
       
   621     h notNil ifTrue:[
       
   622         self hue        value:(h rounded) withoutNotifying:self.
       
   623     ].
       
   624     self light      value:(clr light rounded) withoutNotifying:self.
       
   625     self saturation value:(clr saturation rounded) withoutNotifying:self.
       
   626 
       
   627     self colorChanged
   608 !
   628 !
   609 
   629 
   610 colorNameChanged
   630 colorNameChanged
   611     "compute rgb and hls (if possible)"
   631     "compute rgb and hls (if possible)"
   612 
   632 
   613     |clr h|
   633     |clr|
   614 
   634 
   615     clr := Color name:colorNameHolder value ifIllegal:nil.
   635     clr := Color name:colorNameHolder value ifIllegal:nil.
   616     clr isNil ifTrue:[
   636     clr isNil ifTrue:[
   617         ^ self
   637         ^ self
   618     ].
   638     ].
   619 
   639     self colorChangedTo:clr.
   620     self red   value:clr redByte withoutNotifying:self.
       
   621     self green value:clr greenByte withoutNotifying:self.
       
   622     self blue  value:clr blueByte withoutNotifying:self.
       
   623 
       
   624     h := clr hue.
       
   625     h notNil ifTrue:[
       
   626         self hue        value:(h rounded) withoutNotifying:self.
       
   627     ].
       
   628     self light      value:(clr light rounded) withoutNotifying:self.
       
   629     self saturation value:(clr saturation rounded) withoutNotifying:self.
       
   630 
       
   631     self colorChanged
       
   632 !
   640 !
   633 
   641 
   634 copyColor
   642 copyColor
   635     self window setClipboardObject:self color
   643     self window setClipboardObject:self color
   636 !
   644 !
   647         green  value:(g * 255 / 100) rounded withoutNotifying:self.
   655         green  value:(g * 255 / 100) rounded withoutNotifying:self.
   648         blue   value:(b * 255 / 100) rounded withoutNotifying:self.
   656         blue   value:(b * 255 / 100) rounded withoutNotifying:self.
   649     ].
   657     ].
   650     colorNameHolder value:'' withoutNotifying:self.
   658     colorNameHolder value:'' withoutNotifying:self.
   651     self colorChanged
   659     self colorChanged
       
   660 !
       
   661 
       
   662 htmlColorNameChanged
       
   663     "compute rgb and hls (if possible)"
       
   664 
       
   665     |clr|
       
   666 
       
   667     clr := Color rgbValue:(Integer 
       
   668                                 readFrom:(htmlColorNameHolder value copyFrom:2)
       
   669                                 radix:16
       
   670                                 onError:nil).
       
   671     clr isNil ifTrue:[
       
   672         ^ self
       
   673     ].
       
   674     self colorNameHolder value:'' withoutNotifying:self.
       
   675     self colorChangedTo:clr.
   652 !
   676 !
   653 
   677 
   654 pasteColor
   678 pasteColor
   655     |copyBufferColor|
   679     |copyBufferColor|
   656 
   680 
   729 !
   753 !
   730 
   754 
   731 htmlColorNameHolder
   755 htmlColorNameHolder
   732     htmlColorNameHolder isNil ifTrue:[
   756     htmlColorNameHolder isNil ifTrue:[
   733         htmlColorNameHolder := '' asValue.
   757         htmlColorNameHolder := '' asValue.
       
   758         htmlColorNameHolder addDependent:self.
   734     ].
   759     ].
   735     ^htmlColorNameHolder
   760     ^htmlColorNameHolder
   736 !
   761 !
   737 
   762 
   738 hue
   763 hue
   771 
   796 
   772 update:something with:aParameter from:changedObject
   797 update:something with:aParameter from:changedObject
   773     (changedObject == red
   798     (changedObject == red
   774     or:[changedObject == green
   799     or:[changedObject == green
   775     or:[changedObject == blue]]) ifTrue:[
   800     or:[changedObject == blue]]) ifTrue:[
   776         ^ self rgbSliderChanged
   801         self rgbSliderChanged.
       
   802         ^ self
   777     ].
   803     ].
   778 
   804 
   779     (changedObject == hue
   805     (changedObject == hue
   780     or:[changedObject == light
   806     or:[changedObject == light
   781     or:[changedObject == saturation]]) ifTrue:[
   807     or:[changedObject == saturation]]) ifTrue:[
   782         ^ self hlsSliderChanged
   808         self hlsSliderChanged.
       
   809         ^ self
   783     ].
   810     ].
   784 
   811 
   785     (changedObject == colorNameHolder) ifTrue:[
   812     (changedObject == colorNameHolder) ifTrue:[
   786         ^ self colorNameChanged
   813         self colorNameChanged.
   787     ].
   814         ^ self
   788 
   815     ].
   789     ^ super update:something with:aParameter from:changedObject
   816     (changedObject == htmlColorNameHolder) ifTrue:[
       
   817         self htmlColorNameChanged.
       
   818         ^ self
       
   819     ].
       
   820 
       
   821     super update:something with:aParameter from:changedObject
   790 ! !
   822 ! !
   791 
   823 
   792 !ColorEditDialog methodsFor:'startup & release'!
   824 !ColorEditDialog methodsFor:'startup & release'!
   793 
   825 
   794 postBuildPreviewBox:aView
   826 postBuildPreviewBox:aView