Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Simple gradient(How to create a simple gradient with two colors for a shape?)
Simple gradient [message #1073134] Wed, 24 July 2013 03:43 Go to next message
John Cole is currently offline John Cole
Messages: 26
Registered: June 2013
Junior Member
Hello everyone,

I am using a multitude of different looking shapes in my graphiti editor, which are created automaticly based on descriptions I imported to the editor.

So far so good, but some of the shapes don't simply use a foreground color but gradients. So instead of just using the method setBackground I want to create a gradient, like seen in the picture.

The colors of the gradient are also different from case to case and are readed out from the descriptions I mentioned above. So I can't use final class variables for that.

Here's a short example:
// shape, that will  get the gradient color
Rectangle rectangleShape;

// two colors for the gradient
Color color1 = gaService.manageColor(targetDiagram, 120, 120, 120);
Color color2 = gaService.manageColor(targetDiagram, 5, 5, 5);

// set the gradient
rectangleShape.setGradient(color1, color2);


Of course there is no method setGradient, but that's just what I thought about.

Is there such a simple solution for my problem?

Thanking you in anticipation!
  • Attachment: gradient.png
    (Size: 1.12KB, Downloaded 39 times)

[Updated on: Wed, 24 July 2013 03:44]

Report message to a moderator

Re: Simple gradient [message #1073333 is a reply to message #1073134] Wed, 24 July 2013 10:35 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1574
Registered: July 2009
Location: Walldorf, Germany
Senior Member
John,

have you seen
http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.graphiti.doc%2Fresources%2Fdocu%2Fgfw%2Fcolor-schemas.htm&cp=25_1_8
?

The page describes how to set gradients in Graphiti.

Michael
Re: Simple gradient [message #1073698 is a reply to message #1073333] Thu, 25 July 2013 06:32 Go to previous messageGo to next message
John Cole is currently offline John Cole
Messages: 26
Registered: June 2013
Junior Member
Hello Michael,

many thanks for the answer.
Tried it out and it works so far. I have only one problem now. I tried to implement a gradient from black to white, like this:

		
		addGradientColoredArea(
				gcas,
				"000000",
				0,
				LocationType.LOCATION_TYPE_ABSOLUTE_START, 
				"FFFFFF", 
				0,
				LocationType.LOCATION_TYPE_ABSOLUTE_END);


It works, but the problem is, that until now I am only able to define a gradient with two colors.

What I'm trying to do is to define a gradient from one color to another and from the middle again to the first one (as you can see in the picture of my first post).
In the example of my first post it would be from black to gray and then again from grey to black, up from the middle.

Is that possible? What should I do?

Many thanks id advance!
Re: Simple gradient [message #1075338 is a reply to message #1073698] Mon, 29 July 2013 05:00 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1574
Registered: July 2009
Location: Walldorf, Germany
Senior Member
John,

that should be possible by adding several GradientColoredArea into one
GradientColoredAreas object defining those transitions. At the bottom of the
page is an example that shows the usage of several entries.

Michael
Re: Simple gradient [message #1080746 is a reply to message #1075338] Tue, 06 August 2013 06:35 Go to previous message
John Cole is currently offline John Cole
Messages: 26
Registered: June 2013
Junior Member
Thank you very much Michael! It worked perfectly!

Here's the code, if somebody comes across the same problem:

		// gradient from pixel 0 from absolute start to height / 2
		addGradientColoredArea(
				gcas,
				color1,
				0,
				LocationType.LOCATION_TYPE_ABSOLUTE_START, 
				color2, 
				height / 2,
				LocationType.LOCATION_TYPE_RELATIVE);
		// gradient from height / 2 to pixel 0 from absolute end
		addGradientColoredArea(
				gcas,
				color2,
				height / 2,
				LocationType.LOCATION_TYPE_RELATIVE, 
				color1, 
				0,
				LocationType.LOCATION_TYPE_ABSOLUTE_END);

Previous Topic:Navigation in graphiti
Next Topic:Creating a new Diagram
Goto Forum:
  


Current Time: Sat Jul 26 09:25:10 EDT 2014

Powered by FUDForum. Page generated in 0.02009 seconds