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 |
Mark Robinson 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 |
Xiang Qinxian 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 |
Eclipse User |
|
|
|
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 #225974 is a reply to message #225907] |
Fri, 03 November 2006 20:44 |
Alex Boyko 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 |
Alex Boyko 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 |
Mark Robinson 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.
|
|
|
Goto Forum:
Current Time: Tue Sep 24 12:17:25 GMT 2024
Powered by FUDForum. Page generated in 0.04160 seconds
|