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 02:38 Go to next message
Wok Show is currently offline Wok Show
Messages: 40
Registered: July 2009
Member
Hi,

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();
			value.getBlue();
			rect.setBackground(value);


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.

	@Override
	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 =
					gaService.createRoundedRectangle(containerShape,3,3);
			hostRect.setLineWidth(2);
			gaService.setLocationAndSize(hostRect,
					targetContainer.getContainer().getGraphicsAlgorithm().getX()+5, targetContainer.getContainer().getGraphicsAlgorithm().getY()+5, targetContainer.getContainer().getGraphicsAlgorithm().getWidth(), 300);

			if (addedTab.eResource() == null) {
				getDiagram().eResource().getContents().add(addedTab);
			}
			// 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 
		peCreateService.createChopboxAnchor(containerShape);

		// call the layout feature
		layoutPictogramElement(containerShape);

		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 07:56 Go to previous message
Michael Wenz is currently offline Michael Wenz
Messages: 1574
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Chau,

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.

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


Current Time: Fri Jul 25 11:23:59 EDT 2014

Powered by FUDForum. Page generated in 0.01369 seconds