Refreshing Images [message #188150] |
Tue, 19 July 2005 08: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 #188859 is a reply to message #188375] |
Fri, 22 July 2005 15: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.04745 seconds