Refreshing Images [message #188150] |
Tue, 19 July 2005 12:35 |
Eclipse User |
|
|
|
Originally posted by: jimMolk.none.ro
Hi
I have created a GUI with several editparts,models,etc...using draw2d and
GEF.
Each Editparts has its own figure
My problem is when i try to chande dynamically one selected figure by
changing its image (figure.getImage().setImage(Image)) , the image get
changed but it does not show at screen : to see the change i have to
select another figure : then the changed image appears.
i tried several methods like repaint,revalidate,etc...but no changes
any idea ?
thxs for help
|
|
|
Re: Refreshing Images [message #188199 is a reply to message #188150] |
Tue, 19 July 2005 15:17 |
Eclipse User |
|
|
|
Originally posted by: none.unknown.com
Figure.setImage() should invoke repaint() when the image is changed. That
should do it. Look at ImageFigure#setImage() for reference. It invokes
revalidate, but that is only because the image's size could be different and
the figure might have to be laid out again.
If this is not working for you, post some code or explanation about when
you're changing the figure's image.
"Jim Molk" <jimMolk@none.ro> wrote in message
news:e6af4b4ddc068338dbcd44f13592061c$1@www.eclipse.org...
> Hi
> I have created a GUI with several editparts,models,etc...using draw2d and
> GEF.
> Each Editparts has its own figure
> My problem is when i try to chande dynamically one selected figure by
> changing its image (figure.getImage().setImage(Image)) , the image get
> changed but it does not show at screen : to see the change i have to
> select another figure : then the changed image appears.
> i tried several methods like repaint,revalidate,etc...but no changes
> any idea ?
> thxs for help
>
|
|
|
Re: Refreshing Images [message #188260 is a reply to message #188199] |
Tue, 19 July 2005 15:58 |
Eclipse User |
|
|
|
Originally posted by: jimmolk.none.ro
Thxs but it doesn't work
here is my code :
I have several ComponentModels associated to their ComponentEditParts
*in class ComponentEditPart :
protected IFigure createFigure() {
ComponentModel model = (ComponentModel) getModel();
ComponentFigure figure = new ComponentFigure(model.getState());
model.setConstraint(new
Rectangle(figure.getLocation(),figure.getSize()));
return figure;
}
// called when a user made an action on the Component : State has changed
and Component's imageFigure has to change too
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(ComponentModel.P_STATE)) {
refreshFigure();
}
// call setImg of ComponentFigure
public void refreshFigure() {
((ComponentFigure) this.getFigure()).setImg(((ComponentModel)
getModel()).getState().getImage());
}
*Class componentFigure :
public class ComponentFigure extends Panel {
public final static int P_WIDTH = 62;
public final static int P_HEIGHT = 58;
private FixedSizeLabel label = new FixedSizeLabel(62);
private State state;
private ImageFigure imgfig;
private FlowLayout fl ;
public ComponentFigure(State state) {
this.state= state;
fl = new FlowLayout(false);
fl.setMinorAlignment(FlowLayout.ALIGN_CENTER);
fl.setMinorSpacing(0);
this.setLayoutManager(fl);
Image img = state.getImage();
imgfig = new ImageFigure();
imgfig.setImage(img);
this.setPreferredSize(P_WIDTH,P_HEIGHT);
this.setSize(P_WIDTH,P_HEIGHT);
this.add(imgfig);
this.add(label);
}
public void setName(String name) {
label.setText(label.getSubStringText(name));
label.setFont(new Font(null,"MS Sans Serif",8,0));
label.setToolTip(new Label(name));
}
//called when image has changed
public void setImg(Image arg) {
imgfig.setImage(arg);
}
}
So when i select a Component and make an action on it, there's no change
on screen though image has changed
i have to select another component,or for exemple minimize eclipse and
maximize it to make changes appear on screen...
Thxs for help !
|
|
|
Re: Refreshing Images [message #188284 is a reply to message #188260] |
Tue, 19 July 2005 17:31 |
Eclipse User |
|
|
|
Originally posted by: none.unknown.com
"Jim Molk" <jimmolk@none.ro> wrote in message
news:85e99629b92c55d1911b966ad0899950$1@www.eclipse.org...
> Thxs but it doesn't work
> here is my code :
> I have several ComponentModels associated to their ComponentEditParts
>
> *in class ComponentEditPart :
>
> protected IFigure createFigure() {
> ComponentModel model = (ComponentModel) getModel();
> ComponentFigure figure = new ComponentFigure(model.getState());
> model.setConstraint(new
> Rectangle(figure.getLocation(),figure.getSize()));
####
Shouldn't it be the other way around? The figure's size to be retrieved
from the model?
> return figure;
> }
>
> // called when a user made an action on the Component : State has changed
> and Component's imageFigure has to change too
> public void propertyChange(PropertyChangeEvent evt) {
> if (evt.getPropertyName().equals(ComponentModel.P_STATE)) {
> refreshFigure();
####
Any reason for not using refreshVisuals()?
> }
>
> // call setImg of ComponentFigure
> public void refreshFigure() {
> ((ComponentFigure) this.getFigure()).setImg(((ComponentModel)
> getModel()).getState().getImage());
> }
>
> *Class componentFigure :
>
> public class ComponentFigure extends Panel {
####
You probably should use figure rather than panel.
> public final static int P_WIDTH = 62;
> public final static int P_HEIGHT = 58;
> private FixedSizeLabel label = new FixedSizeLabel(62);
> private State state;
> private ImageFigure imgfig;
> private FlowLayout fl ;
>
> public ComponentFigure(State state) {
> this.state= state;
> fl = new FlowLayout(false);
> fl.setMinorAlignment(FlowLayout.ALIGN_CENTER);
> fl.setMinorSpacing(0);
> this.setLayoutManager(fl);
> Image img = state.getImage();
> imgfig = new ImageFigure();
> imgfig.setImage(img);
> this.setPreferredSize(P_WIDTH,P_HEIGHT);
> this.setSize(P_WIDTH,P_HEIGHT);
>
> this.add(imgfig);
> this.add(label);
> }
>
> public void setName(String name) {
> label.setText(label.getSubStringText(name));
> label.setFont(new Font(null,"MS Sans Serif",8,0));
####
Resource leak.
> label.setToolTip(new Label(name));
> }
>
> //called when image has changed
> public void setImg(Image arg) {
> imgfig.setImage(arg);
> }
>
> }
>
####
I'm not sure why this is not working for you. Try to see if
ImageFigure#paintFigure() is being called after you set the image.
>
> So when i select a Component and make an action on it, there's no change
> on screen though image has changed
> i have to select another component,or for exemple minimize eclipse and
> maximize it to make changes appear on screen...
> Thxs for help !
>
>
>
|
|
|
Re: Refreshing Images [message #188375 is a reply to message #188284] |
Wed, 20 July 2005 09:22 |
Eclipse User |
|
|
|
Originally posted by: jimmolk.none.ro
Thxs a lot ! i think i know where the problem is : it may be the device
parameter...why does a null parameter causes a memory leak in
label#setFont(); ?
I load my image like this : Image img = new Image(null,
MyEditor.class.getResourceAsStream(image))
in org.eclipse.swt.graphics.Image.java :
public Image (Device device, InputStream stream) {
if (device == null) device = Device.getDevice();
if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
init(device, new ImageData(stream));
if (device.tracking) device.new_Object(this);
}
I tried to catch exceptions for ImageFigure#setImg() :
try {
imgfig.setImage(arg);
} catch(Exception e) {
e.printStackTrace();
}
Then i got a NullPointerException:
java.lang.NullPointerException
at
org.eclipse.draw2d.DeferredUpdateManager.queueWork(DeferredU pdateManager.java:151)
at
org.eclipse.draw2d.DeferredUpdateManager.addInvalidFigure(De ferredUpdateManager.java:101)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1221)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1223)
at org.eclipse.draw2d.Figure.revalidate(Figure.java:1223)
...
in org.eclipse.draw2d.DeferredUpdateManager :
queueWork() {
if (!updateQueued) {
Display.getCurrent().asyncExec(new UpdateRequest());
updateQueued = true;
}
So what should i put instead of null parameter for device ?
thxs for your help
> "Jim Molk" <jimmolk@none.ro> wrote in message
> news:85e99629b92c55d1911b966ad0899950$1@www.eclipse.org...
>> Thxs but it doesn't work
>> here is my code :
>> I have several ComponentModels associated to their ComponentEditParts
>>
>> *in class ComponentEditPart :
>>
>> protected IFigure createFigure() {
>> ComponentModel model = (ComponentModel) getModel();
>> ComponentFigure figure = new ComponentFigure(model.getState());
>> model.setConstraint(new
>> Rectangle(figure.getLocation(),figure.getSize()));
> ####
> Shouldn't it be the other way around? The figure's size to be retrieved
> from the model?
->nevermind, this line had no use.
>> return figure;
>> }
>>
>> // called when a user made an action on the Component : State has changed
>> and Component's imageFigure has to change too
>> public void propertyChange(PropertyChangeEvent evt) {
>> if (evt.getPropertyName().equals(ComponentModel.P_STATE)) {
>> refreshFigure();
> ####
> Any reason for not using refreshVisuals()?
-> i used refreshVisuals but that didn't work
>> }
>>
>> // call setImg of ComponentFigure
>> public void refreshFigure() {
>> ((ComponentFigure) this.getFigure()).setImg(((ComponentModel)
>> getModel()).getState().getImage());
>> }
>>
>> *Class componentFigure :
>>
>> public class ComponentFigure extends Panel {
> ####
> You probably should use figure rather than panel.
->i tried , no changes
|
|
|
Re: Refreshing Images [message #188859 is a reply to message #188375] |
Fri, 22 July 2005 19:26 |
Eclipse User |
|
|
|
Originally posted by: none.unknown.com
It's not the null parameter that is the resource leak. It's the font that
you're creating and not disposing.
That, however, is not what's causing this problem. From your stack trace,
it seems you're setting the new image for the figure from outside the UI
thread. That's not allowed. Use Display.a/syncExec().
"Jim Molk" <jimmolk@none.ro> wrote in message
news:fade893b4998b9f342ef0d71a4a883ba$1@www.eclipse.org...
> Thxs a lot ! i think i know where the problem is : it may be the device
> parameter...why does a null parameter causes a memory leak in
> label#setFont(); ?
> I load my image like this : Image img = new Image(null,
> MyEditor.class.getResourceAsStream(image))
>
> in org.eclipse.swt.graphics.Image.java :
>
> public Image (Device device, InputStream stream) {
> if (device == null) device = Device.getDevice();
> if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
> init(device, new ImageData(stream));
> if (device.tracking) device.new_Object(this);
> }
>
>
> I tried to catch exceptions for ImageFigure#setImg() :
> try {
> imgfig.setImage(arg);
> } catch(Exception e) {
> e.printStackTrace();
> }
>
>
> Then i got a NullPointerException:
> java.lang.NullPointerException
> at
>
org.eclipse.draw2d.DeferredUpdateManager.queueWork(DeferredU pdateManager.jav
a:151)
> at
>
org.eclipse.draw2d.DeferredUpdateManager.addInvalidFigure(De ferredUpdateMana
ger.java:101)
> at org.eclipse.draw2d.Figure.revalidate(Figure.java:1221)
> at org.eclipse.draw2d.Figure.revalidate(Figure.java:1223)
> at org.eclipse.draw2d.Figure.revalidate(Figure.java:1223)
> ...
>
> in org.eclipse.draw2d.DeferredUpdateManager :
> queueWork() {
> if (!updateQueued) {
> Display.getCurrent().asyncExec(new UpdateRequest());
> updateQueued = true;
> }
>
> So what should i put instead of null parameter for device ?
> thxs for your help
>
> > "Jim Molk" <jimmolk@none.ro> wrote in message
> > news:85e99629b92c55d1911b966ad0899950$1@www.eclipse.org...
> >> Thxs but it doesn't work
> >> here is my code :
> >> I have several ComponentModels associated to their ComponentEditParts
> >>
> >> *in class ComponentEditPart :
> >>
> >> protected IFigure createFigure() {
> >> ComponentModel model = (ComponentModel) getModel();
> >> ComponentFigure figure = new ComponentFigure(model.getState());
> >> model.setConstraint(new
> >> Rectangle(figure.getLocation(),figure.getSize()));
>
> > ####
> > Shouldn't it be the other way around? The figure's size to be retrieved
> > from the model?
> ->nevermind, this line had no use.
>
> >> return figure;
> >> }
> >>
> >> // called when a user made an action on the Component : State has
changed
> >> and Component's imageFigure has to change too
> >> public void propertyChange(PropertyChangeEvent evt) {
> >> if (evt.getPropertyName().equals(ComponentModel.P_STATE)) {
> >> refreshFigure();
>
> > ####
> > Any reason for not using refreshVisuals()?
> -> i used refreshVisuals but that didn't work
>
> >> }
> >>
> >> // call setImg of ComponentFigure
> >> public void refreshFigure() {
> >> ((ComponentFigure) this.getFigure()).setImg(((ComponentModel)
> >> getModel()).getState().getImage());
> >> }
> >>
> >> *Class componentFigure :
> >>
> >> public class ComponentFigure extends Panel {
>
> > ####
> > You probably should use figure rather than panel.
> ->i tried , no changes
>
|
|
|
Powered by
FUDForum. Page generated in 0.03738 seconds