Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 122219

Summary: ImageFigure not working correctly with border and local coordinates
Product: [Tools] GEF Reporter: Jason Grant <junk>
Component: GEF-Legacy Draw2dAssignee: Alexander Nyßen <nyssen>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: nyssen
Version: 3.2   
Target Milestone: 3.6.2 (Helios SR2)   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Jason Grant CLA 2005-12-28 02:21:59 EST
I have an ImageFigure subclass which returns true from
useLocalCoordinates().  I also set a border on this ImageFigure.

When the ImageFigure repaints, the image top-left corner is rendered at
(0, 0), and so the image is overlapped by the top & left borders, and
whitespace shows between the image and the bottom & right borders.

I posted the above in the GEF newsgroup on 23rd-Dec-2005 with the subject "ImageFigure with border and localCoordinates", and Randy responded with:

ImageFigure should work with a border. You've found a bug in that 
getClientArea should not be called from paintFigure(). Please open a bug 
report.

The fix is something like:
Rect area = getBounds().getCropped(getInsets());
Comment 1 Alexander Nyßen CLA 2010-11-30 17:43:19 EST
Changed that within paintFigure, bounds that are shrinked/cropped by insets are used rather than client area. 

Because Rectangle#getCropped() was deprecated in 3.7 (replaced by getShrinked(), which was introduced in 3.7), used different fixes in both versions.

In the 3.6 maintenance branch, changed calculation of area to:
Rectangle area = getBounds().getCropped(getInsets());

In the 3.7 (HEAD), changed calculation into: 
Rectangle area = getBounds().getShrinked(getInsets());

Reproduced the problem and verified the fix using the following snippet: 

public class Bug122219 {

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell();
		LightweightSystem lws = new LightweightSystem(shell);

		Figure panel = new Figure();
		panel.setLayoutManager(new FlowLayout());
		lws.setContents(panel);

		PaletteData paletteData = new PaletteData(new RGB[] {
				new RGB(255, 0, 0), new RGB(0, 255, 0) });
		ImageData imageData = new ImageData(48, 48, 1, paletteData);
		Image image = new Image(display, imageData);

		ImageFigure imageFigure = new ImageFigure(image) {
			protected boolean useLocalCoordinates() {
				return true;
			};
		};
		imageFigure.setBorder(new LineBorder(ColorConstants.black, 5));
		panel.add(imageFigure);

		shell.setSize(400, 300);
		shell.open();

		while (!shell.isDisposed())
			if (!display.readAndDispatch())
				display.sleep();
	}
}