Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Fix to fill scalable polygon node with gradient background
Fix to fill scalable polygon node with gradient background [message #636301] Sat, 30 October 2010 14:42 Go to next message
Nigel is currently offline NigelFriend
Messages: 7
Registered: October 2010
Junior Member
Hi,

I've seen several questions on how to fill a scalable polygon with a
gradient background and have had a lot of trouble getting this to work
myself. It turns out that all of the time the code I used was working
but there must be a bug in GMF/GEF/Draw2D? that ignores the position of
the node. To work around the bug I used the code below. The code is
located in the ScalablePolygonNodeEditPart->ScalablePolygonNodeFigure class.

/**
* @generated NOT
*/
// MOD fillShape method added to fill with a gradient
@Override
protected void fillShape(Graphics graphics)
{
// Get the current rectangle to set the start and end locations of the
gradient
Rectangle r = getBounds().getCopy();
Point topLeft = r.getTopLeft();
Point bottomRight = r.getBottomRight();

// Create the gradient pattern and set it, I'm going from the
background colour to white
Pattern pattern = new Pattern(Display.getCurrent(), topLeft.x,
topLeft.y, bottomRight.x, bottomRight.y,
ColorConstants.white, THIS_BACK);
graphics.setBackgroundPattern(pattern);

// Now apply the location offset to the polygons point list
PointList pointList = this.getScaledPoints();
PointList positionList = new PointList();
Point location = this.getLocation();

for (int i=0;i<pointList.size();i++)
{
Point p = pointList.getPoint(i);
Point newP = new Point(p.x+location.x, p.y+location.y);
positionList.addPoint(newP);
}

// Fill the polygon and clean up
graphics.fillPolygon(positionList);
graphics.setBackgroundPattern(null);
pattern.dispose();
}

Enjoy :-)
Re: Fix to fill scalable polygon node with gradient background [message #638472 is a reply to message #636301] Thu, 11 November 2010 12:34 Go to previous messageGo to next message
Mostafa ElShafei is currently offline Mostafa ElShafeiFriend
Messages: 39
Registered: October 2010
Member
Dear Nigel,

Thanks so much for your code. I really appreciate your help Very Happy Smile

However, How to apply gradient on a Scalable Polygon when it is resized???

Is there a solution Nigel?

Thanks in advance.
Re: Fix to fill scalable polygon node with gradient background [message #652130 is a reply to message #638472] Wed, 02 February 2011 18:02 Go to previous message
Nigel Daniels is currently offline Nigel DanielsFriend
Messages: 66
Registered: July 2009
Member
Hi Mostafa,

Sorry for my late reply. I suspect that when the edit part is being used
to resize the Polygon the fill is not being called. I'd add a break
point in the fill method to see if it ever get's called. If it is not
then you may need to extend or alter the edit part.

Currently I'm not using the gradients as they produced poor visual
results when printed or projected.

I hope this helps you out.

Regards,

Nigel

On 11/11/2010 12:34, Mostafa ElShafei wrote:
> Dear Nigel,
>
> Thanks so much for your code. I really appreciate your help :d :)
>
> However, How to apply gradient on a Scalable Polygon when it is resized???
>
> Is there a solution Nigel?
>
> Thanks in advance.
Previous Topic:How to layout a diagram at initialisation?
Next Topic:GMF diagrams are not getting saved when used with SVN
Goto Forum:
  


Current Time: Thu Apr 25 23:40:51 GMT 2024

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

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

Back to the top