gmf_tutorial9 [GMF Samples And Tutorials]
 

Overview

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 :

  • Eclipse 3.5.1
  • Graphical Modeling Framework SDK 2.2.1
  • Eclipse Modeling Framework 2.5.0

Tutorial steps

  • Open the FolderEditPart.java file
  • Add the following methode to the body of the FolderFigure 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);
	}
  • Save the class

Running the diagram editor

At this point, when running the diagram editor, you should get this result :

Allowing to change the gradient color

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 :

  • you open the 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.
  • you simply remove the 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 :

Thank you

I hope that this material will be helpful for you. If you want to support it, your help is welcome :

Discussion

simon zutterman, 2012/12/18 22:32

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

 
gmf_tutorial9.txt · Last modified: 2011/08/08 20:07 by jfbraz
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki