Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Inner and outer cicle, but not centered(why the +1?)
Inner and outer cicle, but not centered [message #1623782] Thu, 19 February 2015 10:16 Go to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
Hi

i want to draw a symbol for an activity diagram "Termination state".
Here is the code. (Perhaps you have something more elegant?)
			final int IN_SIZE = 20;
			final int OUT_SIZE = IN_SIZE+10;
			
			Point midPoint = new Point(50, 100);
			
			Ellipse e = new Ellipse();
			e.setBounds(Rectangle.SINGLETON.setBounds(midPoint.x-IN_SIZE/2, midPoint.y-IN_SIZE/2, IN_SIZE, IN_SIZE));
			e.setFill(true);
			e.setOutline(false);
			e.setBackgroundColor( ColorConstants.black );
			e.setAntialias( SWT.ON );
			
			Ellipse i = new Ellipse();
			i.setBounds(Rectangle.SINGLETON.setBounds(midPoint.x-OUT_SIZE/2, midPoint.y-OUT_SIZE/2, OUT_SIZE-1, OUT_SIZE-1)); // here the -1
			i.setFill(false);
			i.setOutline(true);
			i.setForegroundColor( ColorConstants.black );
			i.setAntialias( SWT.ON );
			i.add(e);


In the i.setBounds() line, if i do not -1 the w+h, the circles are not right centered. The -1 makes it look good, but it seems wrong to me. I don't understand where I am missing the point.

Attached images:
index.php/fa/20907/0/
index.php/fa/20908/0/

Can you explain?

cu
Frank

[Updated on: Thu, 19 February 2015 11:14]

Report message to a moderator

Re: Inner and outer cicle, but not centered [message #1624010 is a reply to message #1623782] Thu, 19 February 2015 13:40 Go to previous messageGo to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
a full standalone test app:

package castle.eclipsetool.permutation;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Ellipse;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Tester {

	public static void main(String[] args) {
		Shell shell = new Shell(new Display());
		shell.setSize(365, 280);
		shell.setText("Test");
		shell.setLayout(new GridLayout());

		Canvas canvas = createDiagram(shell);
		canvas.setLayoutData(new GridData(GridData.FILL_BOTH));

		Display display = shell.getDisplay();
		shell.open();
		while (!shell.isDisposed()) {
			while (!display.readAndDispatch()) {
				display.sleep();
			}
		}

	}

	private static Canvas createDiagram(Shell parent) {

		Figure root = new Figure();
		root.add(createSymbol(new Point(30, 30), false ));
		root.add(createSymbol(new Point(70, 30), true ));
		
		Canvas canvas = new Canvas(parent, SWT.DOUBLE_BUFFERED);
		canvas.setBackground(ColorConstants.white);
		LightweightSystem lws = new LightweightSystem(canvas);
		lws.setContents(root);
		return canvas;
	}

	private static Ellipse createSymbol(Point midPoint, boolean fix) {
		final int IN_SIZE = 20;
		final int OUT_SIZE = IN_SIZE+10;
		

		Ellipse e = new Ellipse();
		e.setBounds(Rectangle.SINGLETON.setBounds(midPoint.x-IN_SIZE/2, midPoint.y-IN_SIZE/2, IN_SIZE, IN_SIZE));
		e.setFill(true);
		e.setOutline(false);
		e.setBackgroundColor( ColorConstants.black );
		e.setAntialias( SWT.ON );
		
		Ellipse i = new Ellipse();
		i.setBounds(Rectangle.SINGLETON.setBounds(midPoint.x-OUT_SIZE/2, midPoint.y-OUT_SIZE/2, OUT_SIZE-( fix? 1 : 0), OUT_SIZE-( fix? 1 : 0))); // here the -1
		i.setFill(false);
		i.setOutline(true);
		i.setForegroundColor( ColorConstants.black );
		i.setAntialias( SWT.ON );
		i.add(e);
		return i;
	}

}

index.php/fa/20915/0/
  • Attachment: Test.png
    (Size: 9.38KB, Downloaded 314 times)
Re: Inner and outer cicle, but not centered [message #1625951 is a reply to message #1624010] Fri, 20 February 2015 18:48 Go to previous messageGo to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
Answering to myself.

The inner circle is centered correctly when the outline is enabled.
I don't know if this is a bug.
Re: Inner and outer cicle, but not centered [message #1671124 is a reply to message #1625951] Fri, 13 March 2015 13:22 Go to previous message
Matthias Wienand is currently offline Matthias WienandFriend
Messages: 230
Registered: March 2015
Senior Member
Hi Frank,

I do not think this is a bug as SWT defines fill operations to exclude the bottom and right edges of shapes. See [1] for details.

Best regards,
Matthias

[1] www.eclipse.org/articles/Article-SWT-graphics/SWT_graphics.html#Filling%20shapes

[Updated on: Fri, 13 March 2015 13:23]

Report message to a moderator

Previous Topic:Drag/Drop children in GridLayout
Next Topic:Asynchronous layouting of zest graph
Goto Forum:
  


Current Time: Tue Mar 19 08:24:32 GMT 2024

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

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

Back to the top