Get automated, consistent color in your UML models by using the UML Coloring plug-in

Help others understand models easier by using this plug-in for Rational Software Modeler or Rational Software Architect

By using the UML Coloring plug-in, you can define rules to automatically color UML elements as they are placed on the diagram surface in either IBM® Rational® Software Modeler or IBM® Rational® Software Architect UML models. This helps you apply a consistent coloring scheme to model elements, based on element traits. Coloring models in a consistent way can be a significant aid to improving others' understanding of the model.


Steve Arnold (, Consulting IT Specialist, IBM

Photo of Steve ArnoldSteve is a senior technical consultant who works for IBM Rational in the U.K., where he has worked since 2000. His main areas of expertise are UML design and Model-Driven Architecture (MDA), plus he has a strong interest in Eclipse and product extensibility.

developerWorks Master author

18 February 2010

Also available in Chinese Spanish

UML Coloring plug-in overview

This plug-in provides a framework that helps you develop extensible coloring and apply a set of the most common rules, which are included. Initially, you create instances of the different rules (for example, all elements stereotyped as cold are to be colored blue). Then, when a model element that meets the criterion for that rule is added to a diagram surface, the plug-in automatically colors the element according to the rule. There are several different kinds of rules provided:

  1. Color by name (using a regular expression to define the name)
  2. Color by stereotype
  3. Color by keyword
  4. Color by stereotype attribute value
  5. Color by type (class, interface, and so forth)
  6. Color by relationship (all elements related by a specified relationship type to a class of a certain name)

This approach is far more effective and useful than manual application of color, because it is consistent. Most people think only of applying colors according to stereotypes, but this approach provides many different kinds of rules and the ability to create new rules. (The user interface and some of the code shown in this article use the British spelling of color, so you will see colour instead in some places.)

How to install the UML Coloring plug-in

The installation of the UML Coloring plug-in is straightforward:

  1. Download the RAS file that is included with this article to a location on your hard drive (see Downloads).
  2. Start IBM® Rational® Software Modeler (or IBM® Rational® Software Architect), and then select File > Import.
  3. Choose RAS > RAS Asset, and click Next.
  4. Browse to the downloaded RAS file, accept the warning about deployable plug-ins, and then click Next.
  5. Select the feature, accept the license agreement, and then click Finish.
  6. When prompted, restart the shell to enable the plug-in.
  7. Now switch to the Modeling perspective, and select Window > Preferences > Modeling, and you should see the Color Preferences page.

How to use the UML Coloring plug-in

This, too, is a straightforward, two-step process: define the rule, and then apply the rule.

Define the color rule

  1. To define a color rule, click Windows > Preferences > Modeling, and select Color Preferences, on the left, to open the Color Preferences pane that Figure 1 shows.
Figure 1. Preferences view with Color Preferences selected
L: Preferences menu, R: Color Preferences pane
  1. Click the Add Rule button, and choose a rule type (see Figure 2).
Figure 2. Choose Rule Type window
Shows Keyword Rule selected
  1. Click OK, and then define the rule in the rule dialog that is shown in Figure 3 (different rule types have different rule creation dialogs). To illustrate, we created a rule that makes keywords blue (see Figure 3):
    • Rule Name: BlueKeyword
    • Rule Colour: [light blue selected]
    • Keyword Name: Data
Figure 3. Create Rule window
Screen capture of selections described

You will now see your rule in the Preferences menu. This rule will be applied whenever an element is added to a diagram.

Apply the color rules

To apply the that rule you created earlier:

  1. First, create a class in the model explorer.
  2. Then, with the class selected, open the Properties tab, click the Stereotypes option, and, for this example, enter Data in the Keywords field. (See Figure 4.)
Figure 4. Class Properties tab open, Stereotypes view
Shows selections and entry as described
  1. Now drag the class from the Project Explorer to a UML diagram (Figure 5). It should be automatically colored according ot the color rule that you defined.
Figure 5. Applied rule
Diagram is light blue

If you want to reapply the color rules to an existing diagram, you can right-click on the diagram, or an element, and select Re-Apply Colour Rules, and this will apply the color rules to all elements on the diagram.

How to extend the UML Coloring plug-in

The coloring plug-in provides an extension point so that you can add your own kinds of color rules. Code Listing 1 shows how the extension point is defined.

Listing 1. Extension point XML schema
<element name="extension">
   <element ref="colour_rule_type"/> 
  <attribute name="point" type="string" use="required"> </attribute> 
  <attribute name="id"type="string"> </attribute> 
  <attribute name="name" type="string"> </attribute> 
<element name="colour_rule_type">
  <attribute name="class" type="string" use="required"> 
     <meta.attribute kind="java"

Listing 2 is an example of an extension point definition.

Listing 2. Extension point example

After you have defined your extension, you need to implement these three classes:

  1. IColourRuleType, an implementation of this interface to define the metadata for the kind of color rule
  2. IColourRule, an implementation of this interface to define an instance of a color rule
  3. RuleDialog, a subclass of RuleDialog that provides a dialog for creating and editing a rule

Listings 3 and 4 show the interfaces that must be implemented, and an example of the RuleDialog can be seen by downloading the code below.

Listing 3. IColourRuleType
public interface IColourRuleType 
  public IColourRule createRule() ; 
  public void editRule(IColourRule rule); 
  public String getName(); 
  public boolean understandsRuleString(String ruleString); 
  public IColourRule loadFromString(String ruleString); 
Listing 4. IColourRule
public interface IColourRule 
  public boolean matchesElement(ElementtheElement); 
  public void setViewColour(View view); 
  public String createPreferenceString();
  public String getName(); 
  public String getType(); 
  public RGB getRGBColor(); 
  public void setName(String name); 
  public void setRGBColour(RGB colour); 


Update site for RSA
Deloyable RAS for RSx 7.5.xcolourer_v1.0.0.zip63KB
Source code as an archived Eclipse projectelement_colourer_v1.0.0.zip136KB



  • Learn about other applications in the IBM Rational Software Delivery Platform, including collaboration tools for parallel development and geographically dispersed teams, plus specialized software for architecture management, asset management, change and release management, integrated requirements management, process and portfolio management, and quality management. You can find product manuals, installation guides, and other documentation in the IBM Rational Online Documentation Center.
  • Visit the Rational software area on developerWorks for technical resources and best practices for Rational Software Delivery Platform products.
  • Explore Rational computer-based, Web-based, and instructor-led online courses. Hone your skills and learn more about Rational tools with these courses, which range from introductory to advanced. The courses on this catalog are available for purchase through computer-based training or Web-based training. Additionally, some "Getting Started" courses are available free of charge.
  • Subscribe to the IBM developerWorks newsletter, a weekly update on the best of developerWorks tutorials, articles, downloads, community activities, webcasts and events.

Get products and technologies



developerWorks: Sign in

Required fields are indicated with an asterisk (*).

Need an IBM ID?
Forgot your IBM ID?

Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.


All information submitted is secure.

Dig deeper into Rational software on developerWorks

ArticleTitle=Get automated, consistent color in your UML models by using the UML Coloring plug-in