Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Really could use some help on this Image/TreeItem problem
Really could use some help on this Image/TreeItem problem [message #452849] Fri, 25 March 2005 05:14 Go to next message
Eclipse UserFriend
Originally posted by: bob.objfac.com

It's been about a week so I don't mind re-asking. (I even included a
snippet. ;-) Following is my original post. Thanks.

In the snippet below, note the difference in appearance between the icon
shown in the Label vs. TreeItem. The latter has a black artifact on the
right side. How do I fix this? Thanks.

public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
Label label = new Label (shell, SWT.NONE);
label.setText ("Can't find icon for .txt");
Image image = null;
Program p = Program.findProgram (".txt");
if (p != null) {
ImageData data = p.getImageData ();
if (data != null) {
image = new Image (display, data);
label.setImage (image);
}
}
Color white = new Color(display, 255,255,255);
Tree tree = new Tree(shell, SWT.NONE);
tree.setBackground(white);
if (image != null) {
TreeItem item = new TreeItem(tree, SWT.NONE);
item.setBackground(white);
item.setImage(image);
item.setText("?");
}
label.setBackground(white);
label.pack ();
tree.pack();
shell.pack ();
shell.open ();
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) display.sleep ();
}
white.dispose();
if (image != null) image.dispose ();
display.dispose ();
}

Bob Foster
Re: Really could use some help on this Image/TreeItem problem [message #452857 is a reply to message #452849] Fri, 25 March 2005 06:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: doug-list.threepenny.net

I tried the snippet and got the same result, so that's some confirmation
for you.

Since it's only a problem for the ".txt" icon I think you need to ask
the question--how is this icon different? I'd suggest digging around in
the Windows DLLs to find the original icon and looking at it to see how
it's different from a normal icon. Presumably it's either color depth
or the way the transparency is handled.

Then you can maybe backtrack to understanding why it's drawn incorrectly
inside the tree.

Personally, I'm pretty new to SWT and I don't know how to do custom
drawing for a tree control, but presumably that's the only way to fix this.

Doug

Bob Foster wrote:

> It's been about a week so I don't mind re-asking. (I even included a
> snippet. ;-) Following is my original post. Thanks.
>
> In the snippet below, note the difference in appearance between the icon
> shown in the Label vs. TreeItem. The latter has a black artifact on the
> right side. How do I fix this? Thanks.
>
> public static void main (String [] args) {
> Display display = new Display ();
> Shell shell = new Shell (display);
> Label label = new Label (shell, SWT.NONE);
> label.setText ("Can't find icon for .txt");
> Image image = null;
> Program p = Program.findProgram (".txt");
> if (p != null) {
> ImageData data = p.getImageData ();
> if (data != null) {
> image = new Image (display, data);
> label.setImage (image);
> }
> }
> Color white = new Color(display, 255,255,255);
> Tree tree = new Tree(shell, SWT.NONE);
> tree.setBackground(white);
> if (image != null) {
> TreeItem item = new TreeItem(tree, SWT.NONE);
> item.setBackground(white);
> item.setImage(image);
> item.setText("?");
> }
> label.setBackground(white);
> label.pack ();
> tree.pack();
> shell.pack ();
> shell.open ();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> white.dispose();
> if (image != null) image.dispose ();
> display.dispose ();
> }
>
> Bob Foster
Re: Really could use some help on this Image/TreeItem problem [message #452860 is a reply to message #452849] Fri, 25 March 2005 10:10 Go to previous messageGo to next message
h1055071 is currently offline h1055071Friend
Messages: 335
Registered: July 2009
Senior Member
Bob,

I get this too in my trees. The icon sure has been hit with the ugly stick.
It looks to me like it's the Window "Notepad" icon with a black smudge. I
notice that even in the Eclipse IDE in the package explorer tree that the
default "file" icon is used for .txt files rather than the ugly one.

I can't tell you how to get rid of the black smudge or why it shows up. I
have a static utility method that returns the program's icon or returns the
default "file" icon if not found or if the extension is "txt":


private static Hashtable _imageCache = new Hashtable();

public Image getFileExtensionImage(File file) {
Image image = null;
Path path = new Path(file.getAbsolutePath());
String ext = path.getFileExtension();

if(ext != null && !ext.toLowerCase().equals("txt")) { // txt icons are
ugly
ext = "." + ext;
image = (Image)_imageCache.get(ext); // cached?
if(image == null) {
Program p = Program.findProgram(ext);
if(p != null) {
ImageData data = p.getImageData();
if(data != null) {
image = new Image(Display.getDefault(), data);
if(image != null) {
_imageCache.put(ext, image); // cache it
}
}
}
}
}

else {
image =
PlatformUI.getWorkbench().getSharedImages().getImage(IShared Images.IMG_OBJ_FILE);
}

return image;
}


Phil



"Bob Foster" <bob@objfac.com> wrote in message
news:d20bi6$h5t$1@news.eclipse.org...
> It's been about a week so I don't mind re-asking. (I even included a
> snippet. ;-) Following is my original post. Thanks.
>
> In the snippet below, note the difference in appearance between the icon
> shown in the Label vs. TreeItem. The latter has a black artifact on the
> right side. How do I fix this? Thanks.
>
> public static void main (String [] args) {
> Display display = new Display ();
> Shell shell = new Shell (display);
> Label label = new Label (shell, SWT.NONE);
> label.setText ("Can't find icon for .txt");
> Image image = null;
> Program p = Program.findProgram (".txt");
> if (p != null) {
> ImageData data = p.getImageData ();
> if (data != null) {
> image = new Image (display, data);
> label.setImage (image);
> }
> }
> Color white = new Color(display, 255,255,255);
> Tree tree = new Tree(shell, SWT.NONE);
> tree.setBackground(white);
> if (image != null) {
> TreeItem item = new TreeItem(tree, SWT.NONE);
> item.setBackground(white);
> item.setImage(image);
> item.setText("?");
> }
> label.setBackground(white);
> label.pack ();
> tree.pack();
> shell.pack ();
> shell.open ();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> white.dispose();
> if (image != null) image.dispose ();
> display.dispose ();
> }
>
> Bob Foster
Re: Really could use some help on this Image/TreeItem problem [message #452866 is a reply to message #452849] Fri, 25 March 2005 18:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bob.objfac.com

Thanks Doug and Philip for confirming I'm not the only one that sees
this. It's not just the .txt icon; others have the same problem. It's
pretty unacceptable in one's GUI.

Plus, the icons are rendered correctly in Label. What's the diff?

Bob

Bob Foster wrote:
> It's been about a week so I don't mind re-asking. (I even included a
> snippet. ;-) Following is my original post. Thanks.
>
> In the snippet below, note the difference in appearance between the icon
> shown in the Label vs. TreeItem. The latter has a black artifact on the
> right side. How do I fix this? Thanks.
>
> public static void main (String [] args) {
> Display display = new Display ();
> Shell shell = new Shell (display);
> Label label = new Label (shell, SWT.NONE);
> label.setText ("Can't find icon for .txt");
> Image image = null;
> Program p = Program.findProgram (".txt");
> if (p != null) {
> ImageData data = p.getImageData ();
> if (data != null) {
> image = new Image (display, data);
> label.setImage (image);
> }
> }
> Color white = new Color(display, 255,255,255);
> Tree tree = new Tree(shell, SWT.NONE);
> tree.setBackground(white);
> if (image != null) {
> TreeItem item = new TreeItem(tree, SWT.NONE);
> item.setBackground(white);
> item.setImage(image);
> item.setText("?");
> }
> label.setBackground(white);
> label.pack ();
> tree.pack();
> shell.pack ();
> shell.open ();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> white.dispose();
> if (image != null) image.dispose ();
> display.dispose ();
> }
>
> Bob Foster
Re: Really could use some help on this Image/TreeItem problem [message #452868 is a reply to message #452849] Fri, 25 March 2005 18:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bob.objfac.com

https://bugs.eclipse.org/bugs/show_bug.cgi?id=89116

Phillip and Doug (and anyone else) would appreciate your votes on this
one. I can't ship something that looks like this.

Thanks.

Bob

Bob Foster wrote:
> It's been about a week so I don't mind re-asking. (I even included a
> snippet. ;-) Following is my original post. Thanks.
>
> In the snippet below, note the difference in appearance between the icon
> shown in the Label vs. TreeItem. The latter has a black artifact on the
> right side. How do I fix this? Thanks.
>
> public static void main (String [] args) {
> Display display = new Display ();
> Shell shell = new Shell (display);
> Label label = new Label (shell, SWT.NONE);
> label.setText ("Can't find icon for .txt");
> Image image = null;
> Program p = Program.findProgram (".txt");
> if (p != null) {
> ImageData data = p.getImageData ();
> if (data != null) {
> image = new Image (display, data);
> label.setImage (image);
> }
> }
> Color white = new Color(display, 255,255,255);
> Tree tree = new Tree(shell, SWT.NONE);
> tree.setBackground(white);
> if (image != null) {
> TreeItem item = new TreeItem(tree, SWT.NONE);
> item.setBackground(white);
> item.setImage(image);
> item.setText("?");
> }
> label.setBackground(white);
> label.pack ();
> tree.pack();
> shell.pack ();
> shell.open ();
> while (!shell.isDisposed()) {
> if (!display.readAndDispatch ()) display.sleep ();
> }
> white.dispose();
> if (image != null) image.dispose ();
> display.dispose ();
> }
>
> Bob Foster
Re: Really could use some help on this Image/TreeItem problem [message #452871 is a reply to message #452868] Fri, 25 March 2005 18:44 Go to previous messageGo to next message
h1055071 is currently offline h1055071Friend
Messages: 335
Registered: July 2009
Senior Member
Voted on and confirmed.

What's different between TreeItem and Label rendering, I wonder?

Phil


"Bob Foster" <bob@objfac.com> wrote in message
news:d21ps3$78b$2@news.eclipse.org...
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=89116
>
> Phillip and Doug (and anyone else) would appreciate your votes on this
> one. I can't ship something that looks like this.
>
> Thanks.
>
> Bob
>
> Bob Foster wrote:
>> It's been about a week so I don't mind re-asking. (I even included a
>> snippet. ;-) Following is my original post. Thanks.
>>
>> In the snippet below, note the difference in appearance between the icon
>> shown in the Label vs. TreeItem. The latter has a black artifact on the
>> right side. How do I fix this? Thanks.
>>
>> public static void main (String [] args) {
>> Display display = new Display ();
>> Shell shell = new Shell (display);
>> Label label = new Label (shell, SWT.NONE);
>> label.setText ("Can't find icon for .txt");
>> Image image = null;
>> Program p = Program.findProgram (".txt");
>> if (p != null) {
>> ImageData data = p.getImageData ();
>> if (data != null) {
>> image = new Image (display, data);
>> label.setImage (image);
>> }
>> }
>> Color white = new Color(display, 255,255,255);
>> Tree tree = new Tree(shell, SWT.NONE);
>> tree.setBackground(white);
>> if (image != null) {
>> TreeItem item = new TreeItem(tree, SWT.NONE);
>> item.setBackground(white);
>> item.setImage(image);
>> item.setText("?");
>> }
>> label.setBackground(white);
>> label.pack ();
>> tree.pack();
>> shell.pack ();
>> shell.open ();
>> while (!shell.isDisposed()) {
>> if (!display.readAndDispatch ()) display.sleep ();
>> }
>> white.dispose();
>> if (image != null) image.dispose ();
>> display.dispose ();
>> }
>>
>> Bob Foster
Re: Really could use some help on this Image/TreeItem problem [message #452873 is a reply to message #452866] Fri, 25 March 2005 19:03 Go to previous messageGo to next message
h1055071 is currently offline h1055071Friend
Messages: 335
Registered: July 2009
Senior Member
You can also see it in the Eclipse IDE Navigator and Package Explorer trees
if you copy a file of type .mp3 to a folder there.

Phil


"Bob Foster" <bob@objfac.com> wrote in message
news:d21pce$6nh$1@news.eclipse.org...
> Thanks Doug and Philip for confirming I'm not the only one that sees this.
> It's not just the .txt icon; others have the same problem. It's pretty
> unacceptable in one's GUI.
>
> Plus, the icons are rendered correctly in Label. What's the diff?
>
> Bob
>
> Bob Foster wrote:
>> It's been about a week so I don't mind re-asking. (I even included a
>> snippet. ;-) Following is my original post. Thanks.
>>
>> In the snippet below, note the difference in appearance between the icon
>> shown in the Label vs. TreeItem. The latter has a black artifact on the
>> right side. How do I fix this? Thanks.
>>
>> public static void main (String [] args) {
>> Display display = new Display ();
>> Shell shell = new Shell (display);
>> Label label = new Label (shell, SWT.NONE);
>> label.setText ("Can't find icon for .txt");
>> Image image = null;
>> Program p = Program.findProgram (".txt");
>> if (p != null) {
>> ImageData data = p.getImageData ();
>> if (data != null) {
>> image = new Image (display, data);
>> label.setImage (image);
>> }
>> }
>> Color white = new Color(display, 255,255,255);
>> Tree tree = new Tree(shell, SWT.NONE);
>> tree.setBackground(white);
>> if (image != null) {
>> TreeItem item = new TreeItem(tree, SWT.NONE);
>> item.setBackground(white);
>> item.setImage(image);
>> item.setText("?");
>> }
>> label.setBackground(white);
>> label.pack ();
>> tree.pack();
>> shell.pack ();
>> shell.open ();
>> while (!shell.isDisposed()) {
>> if (!display.readAndDispatch ()) display.sleep ();
>> }
>> white.dispose();
>> if (image != null) image.dispose ();
>> display.dispose ();
>> }
>>
>> Bob Foster
>
Re: Really could use some help on this Image/TreeItem problem [message #452877 is a reply to message #452868] Fri, 25 March 2005 21:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: doug-list.threepenny.net

I've also added my vote to this as it's a pretty natural use of the tree
control.

BTW, I tried copying the image with SWT.IMAGE_DISABLE and SWT.IMAGE_GRAY
and in both cases the copy exhibits the same border in both Label and
the Tree. So perhaps the tree is using a gray scale image?

In that case the real issue is with the gray scale conversion.

Doug

Bob Foster wrote:

> https://bugs.eclipse.org/bugs/show_bug.cgi?id=89116
>
> Phillip and Doug (and anyone else) would appreciate your votes on this
> one. I can't ship something that looks like this.
>
> Thanks.
>
> Bob
>
> Bob Foster wrote:
>
>> It's been about a week so I don't mind re-asking. (I even included a
>> snippet. ;-) Following is my original post. Thanks.
>>
>> In the snippet below, note the difference in appearance between the
>> icon shown in the Label vs. TreeItem. The latter has a black artifact
>> on the right side. How do I fix this? Thanks.
>>
>> public static void main (String [] args) {
>> Display display = new Display ();
>> Shell shell = new Shell (display);
>> Label label = new Label (shell, SWT.NONE);
>> label.setText ("Can't find icon for .txt");
>> Image image = null;
>> Program p = Program.findProgram (".txt");
>> if (p != null) {
>> ImageData data = p.getImageData ();
>> if (data != null) {
>> image = new Image (display, data);
>> label.setImage (image);
>> }
>> }
>> Color white = new Color(display, 255,255,255);
>> Tree tree = new Tree(shell, SWT.NONE);
>> tree.setBackground(white);
>> if (image != null) {
>> TreeItem item = new TreeItem(tree, SWT.NONE);
>> item.setBackground(white);
>> item.setImage(image);
>> item.setText("?");
>> }
>> label.setBackground(white);
>> label.pack ();
>> tree.pack();
>> shell.pack ();
>> shell.open ();
>> while (!shell.isDisposed()) {
>> if (!display.readAndDispatch ()) display.sleep ();
>> }
>> white.dispose();
>> if (image != null) image.dispose ();
>> display.dispose ();
>> }
>>
>> Bob Foster
Re: Really could use some help on this Image/TreeItem problem [message #453029 is a reply to message #452871] Wed, 30 March 2005 00:48 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
Well ... we don't render it, Windows does. Thanks for the bug report.

"Phillip Beauvoir" <p.beauvoir@bolton.ac.uk> wrote in message
news:d21qus$91m$1@news.eclipse.org...
> Voted on and confirmed.
>
> What's different between TreeItem and Label rendering, I wonder?
>
> Phil
>
>
> "Bob Foster" <bob@objfac.com> wrote in message
> news:d21ps3$78b$2@news.eclipse.org...
> > https://bugs.eclipse.org/bugs/show_bug.cgi?id=89116
> >
> > Phillip and Doug (and anyone else) would appreciate your votes on this
> > one. I can't ship something that looks like this.
> >
> > Thanks.
> >
> > Bob
> >
> > Bob Foster wrote:
> >> It's been about a week so I don't mind re-asking. (I even included a
> >> snippet. ;-) Following is my original post. Thanks.
> >>
> >> In the snippet below, note the difference in appearance between the
icon
> >> shown in the Label vs. TreeItem. The latter has a black artifact on the
> >> right side. How do I fix this? Thanks.
> >>
> >> public static void main (String [] args) {
> >> Display display = new Display ();
> >> Shell shell = new Shell (display);
> >> Label label = new Label (shell, SWT.NONE);
> >> label.setText ("Can't find icon for .txt");
> >> Image image = null;
> >> Program p = Program.findProgram (".txt");
> >> if (p != null) {
> >> ImageData data = p.getImageData ();
> >> if (data != null) {
> >> image = new Image (display, data);
> >> label.setImage (image);
> >> }
> >> }
> >> Color white = new Color(display, 255,255,255);
> >> Tree tree = new Tree(shell, SWT.NONE);
> >> tree.setBackground(white);
> >> if (image != null) {
> >> TreeItem item = new TreeItem(tree, SWT.NONE);
> >> item.setBackground(white);
> >> item.setImage(image);
> >> item.setText("?");
> >> }
> >> label.setBackground(white);
> >> label.pack ();
> >> tree.pack();
> >> shell.pack ();
> >> shell.open ();
> >> while (!shell.isDisposed()) {
> >> if (!display.readAndDispatch ()) display.sleep ();
> >> }
> >> white.dispose();
> >> if (image != null) image.dispose ();
> >> display.dispose ();
> >> }
> >>
> >> Bob Foster
>
>
Re: Really could use some help on this Image/TreeItem problem [message #453040 is a reply to message #453029] Wed, 30 March 2005 02:16 Go to previous message
Eclipse UserFriend
Originally posted by: bob.objfac.com

Don't suppose there's some way to stick a label in a tree?

Bob

Steve Northover wrote:
> Well ... we don't render it, Windows does. Thanks for the bug report.
>
> "Phillip Beauvoir" <p.beauvoir@bolton.ac.uk> wrote in message
> news:d21qus$91m$1@news.eclipse.org...
>
>>Voted on and confirmed.
>>
>>What's different between TreeItem and Label rendering, I wonder?
>>
>>Phil
>>
>>
>>"Bob Foster" <bob@objfac.com> wrote in message
>>news:d21ps3$78b$2@news.eclipse.org...
>>
>>>https://bugs.eclipse.org/bugs/show_bug.cgi?id=89116
>>>
>>>Phillip and Doug (and anyone else) would appreciate your votes on this
>>>one. I can't ship something that looks like this.
>>>
>>>Thanks.
>>>
>>>Bob
>>>
>>>Bob Foster wrote:
>>>
>>>>It's been about a week so I don't mind re-asking. (I even included a
>>>>snippet. ;-) Following is my original post. Thanks.
>>>>
>>>>In the snippet below, note the difference in appearance between the
>
> icon
>
>>>>shown in the Label vs. TreeItem. The latter has a black artifact on the
>>>>right side. How do I fix this? Thanks.
>>>>
>>>>public static void main (String [] args) {
>>>> Display display = new Display ();
>>>> Shell shell = new Shell (display);
>>>> Label label = new Label (shell, SWT.NONE);
>>>> label.setText ("Can't find icon for .txt");
>>>> Image image = null;
>>>> Program p = Program.findProgram (".txt");
>>>> if (p != null) {
>>>> ImageData data = p.getImageData ();
>>>> if (data != null) {
>>>> image = new Image (display, data);
>>>> label.setImage (image);
>>>> }
>>>> }
>>>> Color white = new Color(display, 255,255,255);
>>>> Tree tree = new Tree(shell, SWT.NONE);
>>>> tree.setBackground(white);
>>>> if (image != null) {
>>>> TreeItem item = new TreeItem(tree, SWT.NONE);
>>>> item.setBackground(white);
>>>> item.setImage(image);
>>>> item.setText("?");
>>>> }
>>>> label.setBackground(white);
>>>> label.pack ();
>>>> tree.pack();
>>>> shell.pack ();
>>>> shell.open ();
>>>> while (!shell.isDisposed()) {
>>>> if (!display.readAndDispatch ()) display.sleep ();
>>>> }
>>>> white.dispose();
>>>> if (image != null) image.dispose ();
>>>> display.dispose ();
>>>>}
>>>>
>>>>Bob Foster
>>
>>
>
>
Previous Topic:shell.close() disposes the Shell instance
Next Topic:Linking button to help plugin !!
Goto Forum:
  


Current Time: Sun Aug 18 11:45:10 GMT 2019

Powered by FUDForum. Page generated in 0.01636 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top