Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » [DRAW2D] Scale child polygon to parent size
[DRAW2D] Scale child polygon to parent size [message #1768949] Tue, 25 July 2017 07:49 Go to next message
Thijs Franck is currently offline Thijs FranckFriend
Messages: 2
Registered: May 2017
Junior Member
Hi Everyone,

I'm working on a plugin for Archi, adding color views to models. You can read about the plugin on the Archi forum here.

To apply coloring, I want to add child shapes to every view object. The child should be transparent so the object below it can still be visible. The goal is to match the size of the parent shape exactly, so the overlay will fit perfectly on top of it. However, this is where I am running into some trouble. Below are two example screenshots of what is going wrong at the moment:


The first example shows how the overlay is supposed to work. The leftmost view object (rounded rectangle) is completely covered by the overlay object. I added a regular view object next to it for comparison. However, the arrow (a polygon shape) is not covered. A shape is drawn, but it is not the right size. Furthermore, as can be seen in example 2, the size of the arrow drawn is not always the same. In fact, it is different almost every time I try it.

Below is the code I use to add the overlay object (called 'container') to the parent (called 'owner'):
public void apply(IFigureDelegate delegate) {		
	if(colorViewColor != null && container == null){
		container = createColorViewFigure(delegate);
		Rectangle clientArea = owner.getClientArea();			
		container.setBackgroundColor(calculateColor(owner.getBackgroundColor(), colorViewColor, container.getAlpha()));

And this is the code I use to define my overlay shapes. Note that the 'delegate' parameter defines the shape of the parent. I use that same object to define the type and shape of my overlay object:

private Shape createColorViewFigure(IFigureDelegate delegate){
	Shape result = null;		
		ColorViewPolygon polygon = new ColorViewPolygon();
		PointList points = ((AbstractPolygonalFigureDelegate) delegate).getPoints();			
		result = polygon;
		ColorViewRoundedRectangle roundedRectangle = new ColorViewRoundedRectangle();
		roundedRectangle.setCornerDimensions(((RoundedRectangleFigureDelegate) delegate).getArc());
		result = roundedRectangle;
	else if(EllipseFigureDelegate.class.isAssignableFrom(delegate.getClass())){
		result = new ColorViewEllipse();
		result = new ColorViewRectangle();
	return result;

Finally, these are the definitions of my polygon and rounded rectangle objects:

private class ColorViewRoundedRectangle extends RoundedRectangle implements ColorViewShape{}
private class ColorViewPolygon extends ScalablePolygonShape implements ColorViewShape{}

I am at a loss why the polygon variants of my overlay objects are not scaling correctly. Do you have any suggestions? Any help is very much appreciated!

Best regards,
  • Attachment: example1.PNG
    (Size: 8.94KB, Downloaded 529 times)
  • Attachment: example2.PNG
    (Size: 6.09KB, Downloaded 537 times)

[Updated on: Wed, 26 July 2017 07:25]

Report message to a moderator

Re: [DRAW2D] Scale child polygon to parent size [message #1769394 is a reply to message #1768949] Mon, 31 July 2017 10:04 Go to previous message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 244
Registered: July 2009
Location: Lünen
Senior Member
You should check where the bounds of the ScalablePolygonShape are set. The ScalablePolygonShape will use the bounds and the points (from which template bounds are inferred) to determine what gets painted. The location is taken from the bounds. The scaling is inferred from scaling the template bounds against the bounds.
Previous Topic:Edit node and create new connections GEF/ZEST 5
Next Topic:Documentation about gef4/gef5
Goto Forum:

Current Time: Wed Jul 24 15:37:53 GMT 2024

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

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

Back to the top