This tutorial shows how to fill a fiagram node with a gradient color.
It is based on the model built in the first GMF tutorial wich is availabale through :
This tutorial has been built with :
FolderEditPart.java
fileFolderFigure
inner class : /** * @generated NOT */ protected void fillShape(Graphics graphics) { // Backup the graphics colors Color bgColor = graphics.getBackgroundColor(); Color fgColor = graphics.getForegroundColor(); // Set the graphics color graphics.setBackgroundColor(ColorConstants.white); graphics.setForegroundColor(getBackgroundColor()); // Restore the original colors graphics.fillGradient(getBounds(), true); graphics.setBackgroundColor(bgColor); graphics.setForegroundColor(fgColor); }
As we had put a background color (light gray) in the gmfgraph file, GMF automatically disables the possibility to change it in the diagram editor (if you select a folder node and try to change teh background color in the properties view, you will see that it is disabled).
To fix it, there are two options :
filesystem.gmfgen
file, find the Inner Class Viewmap FolderFigure
node (which is under Gen Top Level Node FolderEditPart
). Open it, select the Style Attribute
child node, and in the properties view, set the Fixed Background
to false
.background
color defined in the gmfgraph
file for the folder node.If you re-generate your diagram editor, run it, and create a new diagram file you may now be able to change the background colors :
I hope that this material will be helpful for you. If you want to support it, your help is welcome :
Discussion
hi, i'm a beginner with GMF models, i am currently making a graphical editor and need to apply the gradient color method to my nodes. However, when i even try to apply this code in the filesystem example, i always get the error: the method BackgroundColor() is undefined for the type Color. same error applies to all other methods in the piece of code in this tutorial.
Can you please help?
regards