Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Drawing 2 rectangle in a rectangle
Drawing 2 rectangle in a rectangle [message #1027589] Wed, 27 March 2013 06:38 Go to next message
Wok Show is currently offline Wok ShowFriend
Messages: 40
Registered: July 2009

I am new in Graphiti abd hope you can help me further. The first issue is I don't know how to set the color of the rectangle.
I get only the color by using StyleFactory to add a color to the rectangle. Are there anyway to do this?

			Rectangle rect = gaService.createRectangle(containerShape);
			Color value= StylesFactory.eINSTANCE.createColor();

If I try to draw two rectangle in a RoundedRectangle, only one Rectangle will shown, where is the another rectangle. The last added rectangle will shown in the hostRectangle. In this example the mainRectangle is visible in the hostRect.

	public PictogramElement add(IAddContext context) {
		Tab addedTab = getTabOfContext(context);
		IGaService gaService = Graphiti.getGaService();
		ContainerShape targetContainer= (ContainerShape) context.getTargetContainer();
		IPeCreateService peCreateService = Graphiti.getPeCreateService();
		ContainerShape containerShape =
				peCreateService.createContainerShape(targetContainer, true);

		RoundedRectangle hostRect; // need to access it later

			hostRect =
					targetContainer.getContainer().getGraphicsAlgorithm().getX()+5, targetContainer.getContainer().getGraphicsAlgorithm().getY()+5, targetContainer.getContainer().getGraphicsAlgorithm().getWidth(), 300);

			if (addedTab.eResource() == null) {
			// create link and wire it
			link(containerShape, addedTab);
			RoundedRectangle toolbarRectangle = gaService.createRoundedRectangle(containerShape, 3, 3);
			gaService.setLocationAndSize(toolbarRectangle,targetContainer.getContainer().getGraphicsAlgorithm().getX(), targetContainer.getContainer().getGraphicsAlgorithm().getY(), 100, 100);
			toolbarRectangle.setBackground(manageColor(new ColorConstant(224,224,0)));

			RoundedRectangle mainRectangle = gaService.createRoundedRectangle(containerShape, 3, 3);
			gaService.setLocationAndSize(mainRectangle,targetContainer.getContainer().getGraphicsAlgorithm().getX(), targetContainer.getContainer().getGraphicsAlgorithm().getY()+100, 100, 200);
			mainRectangle.setBackground(manageColor(new ColorConstant(237,237,237)));

		// add a chopbox anchor to the shape 

		// call the layout feature

		return containerShape;

Many thanks for help.

Greez d.chau
Re: Drawing 2 rectangle in a rectangle [message #1027777 is a reply to message #1027589] Wed, 27 March 2013 11:56 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1890
Registered: July 2009
Location: Walldorf, Germany
Senior Member

you should not create color instances yourself, because colors are managed
as resource objects inside diagrams (in features you can call manageColors
to get one). All graphics algorithms (like rectangle) have
setForegroundColor and setBackgroundColor methods to set their colors.

The coordinates of the inner rectangles are relative to the host rectangle.
Also maybe the size of the host rectangle may be too small to show both
inner ones. Try to increase the size of the outer rectangle or use smaller
offsets for the inner ones.

Previous Topic:Graphiti and GEF Layers
Next Topic:Select Shapes over the SelectTool
Goto Forum:

Current Time: Sat May 26 08:25:28 GMT 2018

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

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

Back to the top