Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » About creating an Image
About creating an Image [message #162376] Tue, 21 December 2004 16:14 Go to next message
Eclipse UserFriend
Originally posted by: zhlmmc.hotmail.com

Why I have to create an Image in this way:
InputStream stream = MyPlugin.class.getResourceAsStream("shapes.gif");
Image image = new Image(null, stream);
try {
stream.close();
} catch (IOException ioe) {
}
If I write like this:
Image image = new Image(null,"shapes.gif");
will throw an exception?

thanks
Re: About creating an Image [message #162387 is a reply to message #162376] Tue, 21 December 2004 16:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Please post the exception and Image. Probably you should ask on SWT
newsgroup.
"zhlmmc" <zhlmmc@hotmail.com> wrote in message
news:cq9i5l$bnf$1@www.eclipse.org...
> Why I have to create an Image in this way:
> InputStream stream = MyPlugin.class.getResourceAsStream("shapes.gif");
> Image image = new Image(null, stream);
> try {
> stream.close();
> } catch (IOException ioe) {
> }
> If I write like this:
> Image image = new Image(null,"shapes.gif");
> will throw an exception?
>
> thanks
>
Re: About creating an Image [message #162456 is a reply to message #162387] Tue, 21 December 2004 23:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: zhlmmc.hotmail.com

i/o exception FileNotFound
I put the .class and the .shapes in the same directory and my jface
application window can show the gif correctly,but my gef plugin throw
the exception.

Randy Hudson wrote:

> Please post the exception and Image. Probably you should ask on SWT
> newsgroup.
> "zhlmmc" <zhlmmc@hotmail.com> wrote in message
> news:cq9i5l$bnf$1@www.eclipse.org...
>> Why I have to create an Image in this way:
>> InputStream stream = MyPlugin.class.getResourceAsStream("shapes.gif");
>> Image image = new Image(null, stream);
>> try {
>> stream.close();
>> } catch (IOException ioe) {
>> }
>> If I write like this:
>> Image image = new Image(null,"shapes.gif");
>> will throw an exception?
>>
>> thanks
>>
Re: About creating an Image [message #162478 is a reply to message #162456] Wed, 22 December 2004 02:03 Go to previous messageGo to next message
cloudor Mising name is currently offline cloudor Mising nameFriend
Messages: 34
Registered: July 2009
Member
Of course you should get that exception. When you omit the path of the
file name, it is assumed that your file is located in the directory your
jvm started up rather than the directory which contains both your
specified class and that image file.

zhlmmc wrote:
> i/o exception FileNotFound
> I put the .class and the .shapes in the same directory and my jface
> application window can show the gif correctly,but my gef plugin throw
> the exception.
>
> Randy Hudson wrote:
>
>> Please post the exception and Image. Probably you should ask on SWT
>> newsgroup.
>> "zhlmmc" <zhlmmc@hotmail.com> wrote in message
>> news:cq9i5l$bnf$1@www.eclipse.org...
>>
>>> Why I have to create an Image in this way:
>>> InputStream stream = MyPlugin.class.getResourceAsStream("shapes.gif");
>>> Image image = new Image(null, stream);
>>> try {
>>> stream.close();
>>> } catch (IOException ioe) {
>>> }
>>> If I write like this:
>>> Image image = new Image(null,"shapes.gif");
>>> will throw an exception?
>>>
>>> thanks
>>>
>
>
Re: About creating an Image [message #162494 is a reply to message #162478] Wed, 22 December 2004 03:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: zhlmmc.hotmail.com

I see...but could you tell me why my jface application can find the file?
I think I'm not clear about the mechanism of the plugin loader in Eclipse.

thanks :)
Cloudor Pu wrote:

> Of course you should get that exception. When you omit the path of the
> file name, it is assumed that your file is located in the directory your
> jvm started up rather than the directory which contains both your
> specified class and that image file.

> zhlmmc wrote:
>> i/o exception FileNotFound
>> I put the .class and the .shapes in the same directory and my jface
>> application window can show the gif correctly,but my gef plugin throw
>> the exception.
>>
>> Randy Hudson wrote:
>>
>>> Please post the exception and Image. Probably you should ask on SWT
>>> newsgroup.
>>> "zhlmmc" <zhlmmc@hotmail.com> wrote in message
>>> news:cq9i5l$bnf$1@www.eclipse.org...
>>>
>>>> Why I have to create an Image in this way:
>>>> InputStream stream = MyPlugin.class.getResourceAsStream("shapes.gif");
>>>> Image image = new Image(null, stream);
>>>> try {
>>>> stream.close();
>>>> } catch (IOException ioe) {
>>>> }
>>>> If I write like this:
>>>> Image image = new Image(null,"shapes.gif");
>>>> will throw an exception?
>>>>
>>>> thanks
>>>>
>>
>>
Re: About creating an Image [message #162502 is a reply to message #162494] Wed, 22 December 2004 04:56 Go to previous messageGo to next message
cloudor Mising name is currently offline cloudor Mising nameFriend
Messages: 34
Registered: July 2009
Member
I think it is because of your eclipse launcher set the working directory
for your jface application. However, calling new Image(null, filename)
is equivalent to calling new Image(null, new FileInputStream(
filename)). You might want to print the URLs constructed by
new File(".").toURL() in both applications to see the difference.

zhlmmc wrote:
> I see...but could you tell me why my jface application can find the file?
> I think I'm not clear about the mechanism of the plugin loader in Eclipse.
>
> thanks :)
> Cloudor Pu wrote:
>
>> Of course you should get that exception. When you omit the path of the
>> file name, it is assumed that your file is located in the directory
>> your jvm started up rather than the directory which contains both your
>> specified class and that image file.
>
>
>> zhlmmc wrote:
>>
>>> i/o exception FileNotFound
>>> I put the .class and the .shapes in the same directory and my jface
>>> application window can show the gif correctly,but my gef plugin throw
>>> the exception.
>>>
>>> Randy Hudson wrote:
>>>
>>>> Please post the exception and Image. Probably you should ask on SWT
>>>> newsgroup.
>>>> "zhlmmc" <zhlmmc@hotmail.com> wrote in message
>>>> news:cq9i5l$bnf$1@www.eclipse.org...
>>>>
>>>>> Why I have to create an Image in this way:
>>>>> InputStream stream = MyPlugin.class.getResourceAsStream("shapes.gif");
>>>>> Image image = new Image(null, stream);
>>>>> try {
>>>>> stream.close();
>>>>> } catch (IOException ioe) {
>>>>> }
>>>>> If I write like this:
>>>>> Image image = new Image(null,"shapes.gif");
>>>>> will throw an exception?
>>>>>
>>>>> thanks
>>>>>
>>>
>>>
>
>
Re: About creating an Image [message #162519 is a reply to message #162502] Wed, 22 December 2004 05:18 Go to previous message
Eclipse UserFriend
Originally posted by: zhlmmc.hotmail.com

file:/D:/Program
Files/eclipse-SDK-3.0.1-win32/eclipse/workspace/HelloWorld/. /
file:/D:/Program Files/eclipse-SDK-3.0.1-win32/eclipse/./

It's clear now :)
Thank you!

Cloudor Pu wrote:

> I think it is because of your eclipse launcher set the working directory
> for your jface application. However, calling new Image(null, filename)
> is equivalent to calling new Image(null, new FileInputStream(
> filename)). You might want to print the URLs constructed by
> new File(".").toURL() in both applications to see the difference.

> zhlmmc wrote:
>> I see...but could you tell me why my jface application can find the file?
>> I think I'm not clear about the mechanism of the plugin loader in Eclipse.
>>
>> thanks :)
>> Cloudor Pu wrote:
>>
>>> Of course you should get that exception. When you omit the path of the
>>> file name, it is assumed that your file is located in the directory
>>> your jvm started up rather than the directory which contains both your
>>> specified class and that image file.
>>
>>
>>> zhlmmc wrote:
>>>
>>>> i/o exception FileNotFound
>>>> I put the .class and the .shapes in the same directory and my jface
>>>> application window can show the gif correctly,but my gef plugin throw
>>>> the exception.
>>>>
>>>> Randy Hudson wrote:
>>>>
>>>>> Please post the exception and Image. Probably you should ask on SWT
>>>>> newsgroup.
>>>>> "zhlmmc" <zhlmmc@hotmail.com> wrote in message
>>>>> news:cq9i5l$bnf$1@www.eclipse.org...
>>>>>
>>>>>> Why I have to create an Image in this way:
>>>>>> InputStream stream = MyPlugin.class.getResourceAsStream("shapes.gif");
>>>>>> Image image = new Image(null, stream);
>>>>>> try {
>>>>>> stream.close();
>>>>>> } catch (IOException ioe) {
>>>>>> }
>>>>>> If I write like this:
>>>>>> Image image = new Image(null,"shapes.gif");
>>>>>> will throw an exception?
>>>>>>
>>>>>> thanks
>>>>>>
>>>>
>>>>
>>
>>
Previous Topic:How to add figures programmatically
Next Topic:What is GEF
Goto Forum:
  


Current Time: Thu Mar 28 08:25:46 GMT 2024

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

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

Back to the top