Inner and outer cicle, but not centered [message #1623782] |
Thu, 19 February 2015 10:16 |
Frank Benoit 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:
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 |
Frank Benoit 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;
}
}
-
Attachment: Test.png
(Size: 9.38KB, Downloaded 314 times)
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02526 seconds