Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Overview window Thumbnail.run() infinite loop problem
Overview window Thumbnail.run() infinite loop problem [message #225585] Tue, 31 October 2006 17:41 Go to next message
Mark Robinson is currently offline Mark RobinsonFriend
Messages: 37
Registered: July 2009
Member
I've hit a problem with the overview window I've implemented. When the
overview window is open the application was running a lot slower and you
could sometimes see the overview window constantly flickering. This only
occured when I put a certain figure onto my editor. The offending figure
uses an Image that I scale.

If I comment out the overview window code, start the application, add this
figure to the editor and pause the main thread in the debugger, I find the
code is in the eventLoopIdle function. When I put the overview code back
in, start the application, add this figure and pause the main thread, the
code is stuck in an infinite loop in Thumbnail.run (). Tumbnail.run is
repeatedly called, eventually sets isDirty (false) but instead of hitting
stop() the next time it is called, the loop starts from the initial
condition again? So, this only happens with this figure and when the
overview window is open.

So it seems to be a problem with the Overview window? (Other figures I add
that are not images don't cause this problem in the overview window).

The figure uses the following paintFigure method:

@Override
protected void paintFigure (Graphics graphics)
{
// Center the image around the label.

disposeImages ();

List children = getChildren ();
// Image is child 1.
// label is child 2.

// Get the size of the label.
Figure text = (Figure) children.get (1);
Dimension textSize = text.getSize ();
Rectangle textBounds = text.getBounds ();

// Use the size of the label to scale the image
int scale = textSize.width + textSize.width/3;
Image scaledImage = new Image (null, m_partitionImage.getImageData
().scaledTo (scale, scale));
org.eclipse.swt.graphics.Rectangle scaledImageBounds =
scaledImage.getBounds ();

m_imageFigure.setLocation (m_lblName.getLocation ());
m_imageFigure.setImage (scaledImage);
m_imageFigure.setSize (scaledImageBounds.width,
scaledImageBounds.height);

// Move the label to the correct place within the scaled image.
int x = text.getLocation ().x + scaledImageBounds.width/2 -
textBounds.width/2;
int y = text.getLocation ().y + scaledImageBounds.height/2 -
textBounds.height/2;

m_lblName.setLocation (new Point (x, y));
}

If I comment out the overview window
Re: Overview window Thumbnail.run() infinite loop problem [message #225604 is a reply to message #225585] Tue, 31 October 2006 18:52 Go to previous messageGo to next message
Xiang Qinxian is currently offline Xiang QinxianFriend
Messages: 119
Registered: July 2009
Senior Member
Mark Robinson 写道:
> I've hit a problem with the overview window I've implemented. When the
> overview window is open the application was running a lot slower and you
> could sometimes see the overview window constantly flickering. This only
> occured when I put a certain figure onto my editor. The offending figure
> uses an Image that I scale.
>
> If I comment out the overview window code, start the application, add
> this figure to the editor and pause the main thread in the debugger, I
> find the code is in the eventLoopIdle function. When I put the overview
> code back in, start the application, add this figure and pause the main
> thread, the code is stuck in an infinite loop in Thumbnail.run ().
> Tumbnail.run is repeatedly called, eventually sets isDirty (false) but
> instead of hitting stop() the next time it is called, the loop starts
> from the initial condition again? So, this only happens with this figure
> and when the overview window is open.
> So it seems to be a problem with the Overview window? (Other figures I
> add that are not images don't cause this problem in the overview window).
>
> The figure uses the following paintFigure method:
>
> @Override
> protected void paintFigure (Graphics graphics)
> {
> // Center the image around the label.
> disposeImages ();
> List children = getChildren ();
> // Image is child 1.
> // label is child 2.
> // Get the size of the label.
> Figure text = (Figure) children.get (1);
> Dimension textSize = text.getSize ();
> Rectangle textBounds = text.getBounds ();
> // Use the size of the label to scale the image
> int scale = textSize.width + textSize.width/3;
> Image scaledImage = new Image (null, m_partitionImage.getImageData
> ().scaledTo (scale, scale));
> org.eclipse.swt.graphics.Rectangle scaledImageBounds =
> scaledImage.getBounds ();
> m_imageFigure.setLocation (m_lblName.getLocation ());
> m_imageFigure.setImage (scaledImage);
> m_imageFigure.setSize (scaledImageBounds.width,
> scaledImageBounds.height);
> // Move the label to the correct place within the scaled image.
> int x = text.getLocation ().x + scaledImageBounds.width/2 -
> textBounds.width/2;
> int y = text.getLocation ().y + scaledImageBounds.height/2 -
> textBounds.height/2;
> m_lblName.setLocation (new Point (x, y));
> }
> If I comment out the overview window
>
>
Hi,

There are problems:
Image resource don't be dispose in time.
Invocation of paint method in Figure is not frequency.

From code, there is layout like layout. maybe could try stack layout.
And if other code trigger layout method, deep in cycle, because layout
will call paint method indirectly.

In the paint method above, not using graphics, show that it's not proper.

Regards,

Qinxian.
Re: Overview window Thumbnail.run() infinite loop problem [message #225886 is a reply to message #225585] Fri, 03 November 2006 07:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dstamkokeng.gmail.com

Mark Robinson wrote:

> I've hit a problem with the overview window I've implemented. When the
> overview window is open the application was running a lot slower and you
> could sometimes see the overview window constantly flickering. This only
> occured when I put a certain figure onto my editor. The offending figure
> uses an Image that I scale.

> If I comment out the overview window code, start the application, add this
> figure to the editor and pause the main thread in the debugger, I find the
> code is in the eventLoopIdle function. When I put the overview code back
> in, start the application, add this figure and pause the main thread, the
> code is stuck in an infinite loop in Thumbnail.run (). Tumbnail.run is
> repeatedly called, eventually sets isDirty (false) but instead of hitting
> stop() the next time it is called, the loop starts from the initial
> condition again? So, this only happens with this figure and when the
> overview window is open.

> So it seems to be a problem with the Overview window? (Other figures I add
> that are not images don't cause this problem in the overview window).

> The figure uses the following paintFigure method:

> @Override
> protected void paintFigure (Graphics graphics)
> {
> // Center the image around the label.

> disposeImages ();

> List children = getChildren ();
> // Image is child 1.
> // label is child 2.

> // Get the size of the label.
> Figure text = (Figure) children.get (1);
> Dimension textSize = text.getSize ();
> Rectangle textBounds = text.getBounds ();

> // Use the size of the label to scale the image
> int scale = textSize.width + textSize.width/3;
> Image scaledImage = new Image (null, m_partitionImage.getImageData
> ().scaledTo (scale, scale));
> org.eclipse.swt.graphics.Rectangle scaledImageBounds =
> scaledImage.getBounds ();

> m_imageFigure.setLocation (m_lblName.getLocation ());
> m_imageFigure.setImage (scaledImage);
> m_imageFigure.setSize (scaledImageBounds.width,
> scaledImageBounds.height);

> // Move the label to the correct place within the scaled image.
> int x = text.getLocation ().x + scaledImageBounds.width/2 -
> textBounds.width/2;
> int y = text.getLocation ().y + scaledImageBounds.height/2 -
> textBounds.height/2;

> m_lblName.setLocation (new Point (x, y));
> }

> If I comment out the overview window
Hi,

I am currently trying to implement a thumbnail view for my program. May I
know how I go about doing it? Sorry for posting in this thread, as I
cannot find others who are also implementing an overview.
Re: Overview window Thumbnail.run() infinite loop problem [message #225892 is a reply to message #225886] Fri, 03 November 2006 14:48 Go to previous messageGo to next message
Alex Boyko is currently offline Alex BoykoFriend
Messages: 200
Registered: July 2009
Senior Member
Hi,

The thumbnail view you're trying to create is the one from the outline
view in logic example, where you have 2 buttons for viewing diagram as a
tree and just the whole "fit-all" diagram? If yes, please look at the
LogicEditor class from the logic example, it has an inner private class
OutlinePage. This is the class that creates tree and outline view for the
editor. Check it out let me know if there are any problems.

Cheers,
Alex
Re: Overview window Thumbnail.run() infinite loop problem [message #225899 is a reply to message #225585] Fri, 03 November 2006 15:35 Go to previous messageGo to next message
Alex Boyko is currently offline Alex BoykoFriend
Messages: 200
Registered: July 2009
Senior Member
Hi Mark,

If you switch to tree mode in the outline view and then create the edit
part that has your figure with an image, does it paint ok on the main
diagram surface?

Alex
Re: Overview window Thumbnail.run() infinite loop problem [message #225907 is a reply to message #225899] Fri, 03 November 2006 17:25 Go to previous messageGo to next message
Mark Robinson is currently offline Mark RobinsonFriend
Messages: 37
Registered: July 2009
Member
Alex Boyko wrote:

> Hi Mark,

> If you switch to tree mode in the outline view and then create the edit
> part that has your figure with an image, does it paint ok on the main
> diagram surface?

> Alex

I haven't implemented the tree mode in the outline view.

The problem was my paintFigure function. Xiang pointed me in this
direction by pointing out I wasn't actually using the graphics context in
the paintFigure method. When I commented out paintFigure and used a
StackLayout to add the label then the image, the inifinite loop problem
vanished.

However, I now cannot figure out where I should resize the image. The
problem is that the label can be any size. The label needs to be placed in
the center of the image and the image needs to be resized to be bigger
than the label? paintFigure seemed the logical place to do this; now I
have no idea where to do this?

Here is how I'm now laying out the figure.

public PartitionFigure ()
{
// TODO(mr) This works but will not allow image to be scaled.

m_imageFigure = new ImageFigure (new Image (null,
m_partitionImage.getImageData ()));
setLayoutManager (new StackLayout ());
setOpaque (false);
add (m_imageFigure);
m_lblName = new Label ();
add (m_lblName);
}

I also tried not adding the image to the layout (so only the label is
added in the constructor), but tried drawing it in the paintFigure method
using the graphics context instead. However I couldn't work out where to
change the bounds of the figure to accomodate the image?

Thanks.
Re: Overview window Thumbnail.run() infinite loop problem [message #225974 is a reply to message #225907] Fri, 03 November 2006 20:44 Go to previous messageGo to next message
Alex Boyko is currently offline Alex BoykoFriend
Messages: 200
Registered: July 2009
Senior Member
Hi Mark,

1. For the label to be placed at the centre of the container (instaed of
on top of the image as it is right now I'm guessing) try to use
FreeformLayout instead of StackLayout and give your label figure a
location point such that it's aligned at the centre of the container.

2. For the image to be scalable try to extend ImageFigure as following.
This is merely an example. I've tried to use this figure instead of
CircuitFigure for the CircuitEditPart in logic example. Seems to be
working.

package org.eclipse.gef.examples.logicdesigner.figures;

import java.io.FileInputStream;

import org.eclipse.swt.graphics.Image;

import org.eclipse.ui.PlatformUI;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.ImageFigure;
import org.eclipse.draw2d.geometry.Rectangle;


public class MyFig
extends ImageFigure {


public MyFig(String location) {
super();
try {
setImage(new Image(PlatformUI.getWorkbench().getDisplay(), new
FileInputStream(location)));
} catch (Exception e) {
setImage(null);
}
}

protected void paintFigure(Graphics graphics) {
Rectangle targetRect = getClientArea().getCopy();
org.eclipse.swt.graphics.Rectangle imgBox = getImage().getBounds();
graphics.drawImage(getImage(), 0, 0, imgBox.width, imgBox.height,
targetRect.x, targetRect.y, targetRect.width, targetRect.height);
}

}


For more information you can take a look at GMF open source project (built
on top of GEF and EMF). Check ScalableImageFigure in GMF.

Cheers,
Alex
Re: Overview window Thumbnail.run() infinite loop problem [message #226003 is a reply to message #225907] Sat, 04 November 2006 01:18 Go to previous messageGo to next message
Alex Boyko is currently offline Alex BoykoFriend
Messages: 200
Registered: July 2009
Senior Member
Hi Mark,

I just figured that I didn't answer your main question about setting
bounds of the image figure. From the previous comment code snippet instead
of getting client area for the image figure, you could get parent's client
area and I think that should do it.
However, you could get rid of the container figure holding image figure
and label inside and have your image figure containing the label figure.
User should be able to resize this figure as he likes by dragging-dropping
resize handles - the image will cover the entire figure bounds. On the
image figure you'd have to set up ToolbarLayout manager for now to place
the label. However to place the label in the geometric centre of the image
figure you'd have to extend this layout manager. Later on you can take a
look at the ConstrainedToolBarLayout manager from GMF, I think it would
resize the container with respect to the size of the label inside.

Here is an example of the code you could use for your figure:

package org.eclipse.gef.examples.logicdesigner.figures;

import java.io.FileInputStream;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;

import org.eclipse.ui.PlatformUI;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.ImageFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Rectangle;


public class MyFig
extends ImageFigure {

public MyFig(String location) {
super();
ToolbarLayout layout = new ToolbarLayout();
layout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
setLayoutManager(layout);

try {
setImage(new Image(PlatformUI.getWorkbench().getDisplay(), new
FileInputStream(location)));
setPreferredSize(getImage().getBounds().width,
getImage().getBounds().height);
} catch (Exception e) {
System.out.println(e);
setImage(null);
}
Label label = new Label("LABEL");
label.setFont(new Font(PlatformUI.getWorkbench().getDisplay(),
"Verdana", 10, SWT.BOLD));
add(label);
}

protected void paintFigure(Graphics graphics) {
Rectangle targetRect = getClientArea().getCopy();
org.eclipse.swt.graphics.Rectangle imgBox = getImage().getBounds();
graphics.drawImage(getImage(), 0, 0, imgBox.width, imgBox.height,
targetRect.x, targetRect.y, targetRect.width, targetRect.height);
}



}


Again, I've tried this figure with the logic example by returning an
instance of MyFig in CircuitEditPaer#createFigure(). The string that
should be passed in the constructor is the path to the image file you'd
like to use. (don't try SVG in GEF). To properly try this figure with
logic example comment out 2 methods from CircuitEditPart: getContentPane()
and createEditPolicies()

Let me know if this helps at all.

Cheers,
Alex
Re: Overview window Thumbnail.run() infinite loop problem [message #226157 is a reply to message #226003] Mon, 06 November 2006 15:23 Go to previous message
Mark Robinson is currently offline Mark RobinsonFriend
Messages: 37
Registered: July 2009
Member
Alex Boyko wrote:

> Hi Mark,

> I just figured that I didn't answer your main question about setting
> bounds of the image figure. From the previous comment code snippet instead
> of getting client area for the image figure, you could get parent's client
> area and I think that should do it.
> However, you could get rid of the container figure holding image figure
> and label inside and have your image figure containing the label figure.
> User should be able to resize this figure as he likes by dragging-dropping
> resize handles - the image will cover the entire figure bounds. On the
> image figure you'd have to set up ToolbarLayout manager for now to place
> the label. However to place the label in the geometric centre of the image
> figure you'd have to extend this layout manager. Later on you can take a
> look at the ConstrainedToolBarLayout manager from GMF, I think it would
> resize the container with respect to the size of the label inside.

> Here is an example of the code you could use for your figure:

> package org.eclipse.gef.examples.logicdesigner.figures;

> import java.io.FileInputStream;

> import org.eclipse.swt.SWT;
> import org.eclipse.swt.graphics.Font;
> import org.eclipse.swt.graphics.Image;

> import org.eclipse.ui.PlatformUI;

> import org.eclipse.draw2d.Graphics;
> import org.eclipse.draw2d.ImageFigure;
> import org.eclipse.draw2d.Label;
> import org.eclipse.draw2d.ToolbarLayout;
> import org.eclipse.draw2d.geometry.Rectangle;


> public class MyFig
> extends ImageFigure {

> public MyFig(String location) {
> super();
> ToolbarLayout layout = new ToolbarLayout();
> layout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
> setLayoutManager(layout);

> try {
> setImage(new Image(PlatformUI.getWorkbench().getDisplay(), new
> FileInputStream(location)));
> setPreferredSize(getImage().getBounds().width,
> getImage().getBounds().height);
> } catch (Exception e) {
> System.out.println(e);
> setImage(null);
> }
> Label label = new Label("LABEL");
> label.setFont(new Font(PlatformUI.getWorkbench().getDisplay(),
> "Verdana", 10, SWT.BOLD));
> add(label);
> }

> protected void paintFigure(Graphics graphics) {
> Rectangle targetRect = getClientArea().getCopy();
> org.eclipse.swt.graphics.Rectangle imgBox = getImage().getBounds();
> graphics.drawImage(getImage(), 0, 0, imgBox.width, imgBox.height,
> targetRect.x, targetRect.y, targetRect.width, targetRect.height);
> }



> }


> Again, I've tried this figure with the logic example by returning an
> instance of MyFig in CircuitEditPaer#createFigure(). The string that
> should be passed in the constructor is the path to the image file you'd
> like to use. (don't try SVG in GEF). To properly try this figure with
> logic example comment out 2 methods from CircuitEditPart: getContentPane()
> and createEditPolicies()

> Let me know if this helps at all.

> Cheers,
> Alex


Thanks Alex,

This did indeed work when I did as you suggested and placed this in the
logic example.

Many thanks.
Previous Topic:Context Menu Provider
Next Topic:Wavy line under Label
Goto Forum:
  


Current Time: Fri Mar 29 09:00:32 GMT 2024

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

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

Back to the top