Bug 139368 - [Preferences] ColorSelector does not support null
Summary: [Preferences] ColorSelector does not support null
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
: 175958 178448 185608 190226 (view as bug list)
Depends on:
Blocks: 139344
  Show dependency tree
 
Reported: 2006-04-29 03:01 EDT by Yueqian Wang CLA
Modified: 2012-08-27 09:34 EDT (History)
8 users (show)

See Also:


Attachments
The source code of the dialog (1.80 KB, text/plain)
2006-04-29 03:09 EDT, Yueqian Wang CLA
no flags Details
The source code of the dialog luncher for the first case (402 bytes, text/plain)
2006-04-29 03:11 EDT, Yueqian Wang CLA
no flags Details
The source code of the dialog luncher of the first case (402 bytes, text/plain)
2006-04-29 03:11 EDT, Yueqian Wang CLA
no flags Details
The source code of the dialog luncher of the second case (464 bytes, text/plain)
2006-04-29 03:19 EDT, Yueqian Wang CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Yueqian Wang CLA 2006-04-29 03:01:18 EDT
Step to reproduce:
1. Create a ColorSelector and a button in a dialog. 
2. Set the image of the ColorSelector to null and the one of the button to an image.
3. Open this dialog twice. You can see the image of the button is shown on the ColorSelector when it opens for the second time.

If I open the dialog only once or reverse the creation order of these two controls, this appearance doesn't exist.

But if I create a image before create the dialog, this appearance occurs even the first time.
Comment 1 Yueqian Wang CLA 2006-04-29 03:09:13 EDT
Created attachment 39872 [details]
The source code of the dialog
Comment 2 Yueqian Wang CLA 2006-04-29 03:11:07 EDT
Created attachment 39873 [details]
The source code of the dialog luncher for the first case
Comment 3 Yueqian Wang CLA 2006-04-29 03:11:27 EDT
Created attachment 39874 [details]
The source code of the dialog luncher of the first case
Comment 4 Yueqian Wang CLA 2006-04-29 03:17:11 EDT
Comment on attachment 39873 [details]
The source code of the dialog luncher for the first case

Duplicated submitting
Comment 5 Yueqian Wang CLA 2006-04-29 03:19:00 EDT
Created attachment 39875 [details]
The source code of the dialog luncher of the second case
Comment 6 Yueqian Wang CLA 2006-04-29 03:22:15 EDT
This appearace exsits only in 3.2RC1.
Comment 7 Wang Qiangsheng CLA 2007-02-28 19:38:24 EST
*** Bug 175958 has been marked as a duplicate of this bug. ***
Comment 8 Eric Moffatt CLA 2007-03-05 11:27:34 EST
(In reply to comment #6)
> This appearace exsits only in 3.2RC1.
> 

Do you mean that it's no longer a problem (i.e. is it still an issue in the actual 3.2 release) ?
Comment 9 Wang Qiangsheng CLA 2007-03-05 18:10:13 EST
At that stage when the bug reported, it's in 3.2RC1.
Looks it is still a problem by reporting of item 175958.
Thanks

(In reply to comment #8)
> (In reply to comment #6)
> > This appearace exsits only in 3.2RC1.
> > 
> 
> Do you mean that it's no longer a problem (i.e. is it still an issue in the
> actual 3.2 release) ?
> 

Comment 10 Wang Qiangsheng CLA 2007-03-20 18:37:54 EDT
*** Bug 178448 has been marked as a duplicate of this bug. ***
Comment 11 Wang Qiangsheng CLA 2007-05-07 21:13:08 EDT
*** Bug 185608 has been marked as a duplicate of this bug. ***
Comment 12 Wang Qiangsheng CLA 2007-05-31 17:41:32 EDT
*** Bug 190226 has been marked as a duplicate of this bug. ***
Comment 13 Tod Creasey CLA 2007-06-19 09:13:30 EDT
ColorSelector is designed to simply draw a color rectangle in a GC and is not designed to support text.

Text is actually quite hard to show because you need to make sure the color of the text is readable with the color of the background which constantly changes.

We currently are not planning to add support for this but should you wish to add a patch that adds this support we would be happy to review it.
Comment 14 Zhiqiang Qian CLA 2007-08-06 23:23:21 EDT
I'm reopening this. Actually this bug is not requesting for supporting text drawing in ColorSelector (the title may misleading), we just want it to support the 'null' value setting, e.g. ColorSelector.setColorValue(null). When the value is null, we expect the button has the same visual effect as it is first created, e.g. just button background, no black rectangle line. Currently when you set null value to ColorSelector, exception will thrown out.

I think this just needs a few lines of change in method updateColorImage(). Our current workaround is to use ColorSelector.getButtion().setImage(null), this causes the problem, while this could also be an SWT or Windows bug. Of course we can do something elase to work around this, like copy and modify the whole ColorSelector source, but it's better if this can be fixed internally.
Comment 15 Patrik Dufresne CLA 2012-08-24 15:27:09 EDT
This bug is open since 2006, and the fix is very simple.

--- ColorSelector.java	2012-08-24 15:21:05.677278682 -0400
+++ ColorSelector.java	2012-08-24 15:24:17.781276846 -0400
@@ -198,8 +198,12 @@
         if (fColor != null) {
 			fColor.dispose();
 		}
-        fColor = new Color(display, fColorValue);
-        gc.setBackground(fColor);
+        if(fColorValue!=null) {
+            fColor = new Color(display, fColorValue);
+            gc.setBackground(fColor);
+        } else {
+            gc.setBackground(fButton.getBackground());
+        }
         gc.fillRectangle(1, 3, fExtent.x - 2, fExtent.y - 5);
         gc.dispose();
         fButton.setImage(fImage);