class definition
authorClaus Gittinger <cg@exept.de>
Thu, 27 Jan 2011 12:54:20 +0100
changeset 2831 3dbef5687ae6
parent 2830 aec9b9fd5c17
child 2832 c1e7c5d29577
class definition added: #brightness #brightnessStringHolder #colorDefinitionStringHolder comment/format in: #colorChangedTo: changed: #colorChanged #helpSpec #windowSpec
ColorEditDialog.st
--- a/ColorEditDialog.st	Mon Jan 24 11:27:07 2011 +0100
+++ b/ColorEditDialog.st	Thu Jan 27 12:54:20 2011 +0100
@@ -13,7 +13,8 @@
 
 SimpleDialog subclass:#ColorEditDialog
 	instanceVariableNames:'red green blue hue light saturation colorNameHolder
-		htmlColorNameHolder previewBox'
+		htmlColorNameHolder colorDefinitionStringHolder previewBox
+		brightnessStringHolder'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Interface-UIPainter'
@@ -94,12 +95,24 @@
 
     ^ super helpSpec addPairsFrom:#(
 
+#brightness
+'The Color''s brightness value (0..1)'
+
+#colorDefinitionString
+'A Smalltalk expression to construct the color.'
+
+#colorName
+'The standard colorname (as used in the X-Window System), if known'
+
 #copyToClipboard
 'Copy the color to the clipboard'
 
 #hlsMixer
 'Mix color from hls (hue-light-saturation) components'
 
+#htmlColorName
+'The color as used in an HTML page.'
+
 #pasteFromClipboard
 'Paste color from the Clipboard'
 
@@ -139,9 +152,9 @@
        (WindowSpec
           label: 'Define Color'
           name: 'Define Color'
-          min: (Point 440 300)
-          max: (Point 440 300)
-          bounds: (Rectangle 0 0 440 300)
+          min: (Point 440 360)
+          max: (Point 440 360)
+          bounds: (Rectangle 0 0 440 360)
         )
         component: 
        (SpecCollection
@@ -243,7 +256,7 @@
                     minValue: 0
                     maxValue: 255
                     acceptOnPointerLeave: false
-                    extent: (Point 30 20)
+                    extent: (Point 28 20)
                   )
                  (InputFieldSpec
                     name: 'GreenField'
@@ -253,7 +266,7 @@
                     minValue: 0
                     maxValue: 255
                     acceptOnPointerLeave: false
-                    extent: (Point 30 20)
+                    extent: (Point 28 20)
                   )
                  (InputFieldSpec
                     name: 'BlueField'
@@ -263,7 +276,7 @@
                     minValue: 0
                     maxValue: 255
                     acceptOnPointerLeave: false
-                    extent: (Point 30 20)
+                    extent: (Point 28 20)
                   )
                  )
                
@@ -287,7 +300,7 @@
                     minValue: 0
                     maxValue: 255
                     acceptOnPointerLeave: false
-                    extent: (Point 22 20)
+                    extent: (Point 20 20)
                   )
                  (InputFieldSpec
                     name: 'EntryField5'
@@ -297,7 +310,7 @@
                     minValue: 0
                     maxValue: 255
                     acceptOnPointerLeave: false
-                    extent: (Point 22 20)
+                    extent: (Point 20 20)
                   )
                  (InputFieldSpec
                     name: 'EntryField6'
@@ -307,7 +320,7 @@
                     minValue: 0
                     maxValue: 255
                     acceptOnPointerLeave: false
-                    extent: (Point 22 20)
+                    extent: (Point 20 20)
                   )
                  )
                
@@ -374,7 +387,7 @@
                     model: light
                     orientation: horizontal
                     step: 1
-                    backgroundColor: (Color 66.999313344015 66.999313344015 66.999313344015)
+                    backgroundColor: (Color 66.9993133440146 66.9993133440146 66.9993133440146)
                     keyboardStep: 1
                     extent: (Point 193 16)
                   )
@@ -384,7 +397,7 @@
                     model: saturation
                     orientation: horizontal
                     step: 1
-                    backgroundColor: (Color 66.999313344015 66.999313344015 66.999313344015)
+                    backgroundColor: (Color 66.9993133440146 66.9993133440146 66.9993133440146)
                     keyboardStep: 1
                     extent: (Point 193 16)
                   )
@@ -410,7 +423,7 @@
                     minValue: 0
                     maxValue: 359
                     acceptOnPointerLeave: false
-                    extent: (Point 30 20)
+                    extent: (Point 28 20)
                   )
                  (InputFieldSpec
                     name: 'EntryField2'
@@ -420,7 +433,7 @@
                     minValue: 0
                     maxValue: 100
                     acceptOnPointerLeave: false
-                    extent: (Point 30 20)
+                    extent: (Point 28 20)
                   )
                  (InputFieldSpec
                     name: 'EntryField3'
@@ -430,7 +443,7 @@
                     minValue: 0
                     maxValue: 100
                     acceptOnPointerLeave: false
-                    extent: (Point 30 20)
+                    extent: (Point 28 20)
                   )
                  )
                
@@ -456,15 +469,37 @@
               )
             )
            (LabelSpec
+              label: 'Brightness:'
+              name: 'Label5'
+              layout: (LayoutFrame 0 0 175 0 70 0 197 0)
+              activeHelpKey: brightness
+              translateLabel: true
+              adjust: right
+            )
+           (InputFieldSpec
+              name: 'EntryField8'
+              layout: (LayoutFrame 71 0 175 0 -296 1 197 0)
+              activeHelpKey: brightness
+              model: brightnessStringHolder
+              isReadOnly: true
+              immediateAccept: false
+              acceptOnReturn: true
+              acceptOnTab: true
+              acceptOnLostFocus: true
+              acceptOnPointerLeave: true
+            )
+           (LabelSpec
               label: 'Color Name:'
               name: 'ColorNameLabel'
-              layout: (LayoutFrame 0 0 176 0 106 0 198 0)
+              layout: (LayoutFrame 2 0 214 0 115 0 236 0)
+              activeHelpKey: colorName
               translateLabel: true
               adjust: right
             )
            (InputFieldSpec
               name: 'ColorNameField'
-              layout: (LayoutFrame 108 0 176 0 -162 1 198 0)
+              layout: (LayoutFrame 117 0 214 0 -122 1 236 0)
+              activeHelpKey: colorName
               model: colorNameHolder
               immediateAccept: false
               acceptOnReturn: true
@@ -475,13 +510,15 @@
            (LabelSpec
               label: 'HTML Color Name:'
               name: 'HTMLColorNameLabel'
-              layout: (LayoutFrame 4 0 204 0 110 0 226 0)
+              layout: (LayoutFrame 2 0 240 0 115 0 262 0)
+              activeHelpKey: htmlColorName
               translateLabel: true
               adjust: right
             )
            (InputFieldSpec
               name: 'MLHTColorNameFieldField'
-              layout: (LayoutFrame 108 0 204 0 -162 1 226 0)
+              layout: (LayoutFrame 117 0 240 0 -122 1 262 0)
+              activeHelpKey: htmlColorName
               model: htmlColorNameHolder
               immediateAccept: false
               acceptOnReturn: true
@@ -489,10 +526,30 @@
               acceptOnLostFocus: true
               acceptOnPointerLeave: true
             )
+           (LabelSpec
+              label: 'Color Definition:'
+              name: 'Label4'
+              layout: (LayoutFrame 2 0 266 0 115 0 288 0)
+              activeHelpKey: colorDefinitionString
+              translateLabel: true
+              adjust: right
+            )
+           (InputFieldSpec
+              name: 'EntryField7'
+              layout: (LayoutFrame 117 0 266 0 -122 1 288 0)
+              activeHelpKey: colorDefinitionString
+              model: colorDefinitionStringHolder
+              isReadOnly: true
+              immediateAccept: false
+              acceptOnReturn: true
+              acceptOnTab: true
+              acceptOnLostFocus: true
+              acceptOnPointerLeave: true
+            )
            (ActionButtonSpec
               label: 'Copy Color'
               name: 'CopyColor'
-              layout: (LayoutFrame 12 0 236 0 100 0 258 0)
+              layout: (LayoutFrame 12 0 298 0 100 0 320 0)
               activeHelpKey: hlsMixer
               translateLabel: true
               resizeForLabel: true
@@ -502,7 +559,7 @@
            (ActionButtonSpec
               label: 'Paste Color'
               name: 'PasteColor'
-              layout: (LayoutFrame 108 0 236 0 196 0 258 0)
+              layout: (LayoutFrame 108 0 298 0 196 0 320 0)
               translateLabel: true
               resizeForLabel: true
               tabable: true
@@ -511,7 +568,7 @@
            (ActionButtonSpec
               label: 'pickColorIcon'
               name: 'Button1'
-              layout: (LayoutFrame 285 0 236 0 312 0 263 0)
+              layout: (LayoutFrame 285 0 298 0 312 0 325 0)
               activeHelpKey: pickColor
               hasCharacterOrientedLabel: false
               translateLabel: true
@@ -621,14 +678,24 @@
 !ColorEditDialog methodsFor:'actions'!
 
 colorChanged
-    |clr|
+    |clr nm|
 
     clr := self colorNameOrColor.
     clr isColor ifTrue:[
         "not a symbol"
         self setPreview:clr.
         self htmlColorNameHolder value:(clr htmlPrintString) withoutNotifying:self.
+
+        nm := #(white red green blue black) detect:[:nm | clr = (Color perform:nm)] ifNone:nil.
+        nm notNil ifTrue:[
+            self colorDefinitionStringHolder value:('Color ',nm).
+        ] ifFalse:[
+            self colorDefinitionStringHolder value:('Color rgbValue:16r',(clr rgbValue hexPrintString leftPaddedTo:6 with:$0)).
+        ].
+        self brightnessStringHolder value:((clr brightness asFixedPoint:3) printString).
     ].
+
+    "Modified: / 27-01-2011 / 12:54:04 / cg"
 !
 
 colorChangedTo:clr
@@ -648,6 +715,8 @@
     self saturation value:(clr saturation rounded) withoutNotifying:self.
 
     self colorChanged
+
+    "Modified: / 27-01-2011 / 12:48:28 / cg"
 !
 
 colorNameChanged
@@ -765,6 +834,26 @@
     ^blue
 !
 
+brightnessStringHolder
+    brightnessStringHolder isNil ifTrue:[
+        brightnessStringHolder := 0 asValue.
+        "/ brightness addDependent:self.
+    ].
+    ^ brightnessStringHolder
+
+    "Created: / 27-01-2011 / 12:48:00 / cg"
+!
+
+colorDefinitionStringHolder
+    colorDefinitionStringHolder isNil ifTrue:[
+        colorDefinitionStringHolder := '' asValue.
+        "/ colorDefinitionStringHolder addDependent:self.
+    ].
+    ^colorDefinitionStringHolder
+
+    "Created: / 27-01-2011 / 12:38:12 / cg"
+!
+
 colorNameHolder
     colorNameHolder isNil ifTrue:[
         colorNameHolder := '' asValue.
@@ -867,4 +956,8 @@
 
 version
     ^ '$Header$'
+!
+
+version_CVS
+    ^ '$Header$'
 ! !