Question & Answer
Question
How do you color class nodes in the diagrams using JAVA API in IBM Rational Rhapsody?
Cause
You would like to use Java Application Programming Interfaces [API] code to automate the manual task to be performed with in Rational Rhapsody.
Answer
In order to color the class nodes in a diagram in Rational Rhapsody you can use the API method setGraphicalProperty("BackgroundColor", "255,0,0") [The value 255,0,0 is for the color red]
Find below a code snippet for your reference:
All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
---|
Note: The below code scans through all the nodes in the different diagrams and colors it red if it is not a template.
IRPApplication myApp = RhapsodyAppServer.getActiveRhapsodyApplication();
IRPProject myProj = myApp.activeProject();
Iterator myIter = myProj.getNestedElementsRecursive().toList().iterator();
while (myIter.hasNext())
{
Object myObj = myIter.next();
if(myObj instanceof IRPDiagram)
{
IRPDiagram myDiag = (IRPDiagram) myObj;
Iterator myIter1 = myDiag.getGraphicalElements().toList().iterator();
while(myIter1.hasNext())
{
Object myObj1 = myIter1.next();
if(myObj1 instanceof IRPGraphNode)
{
IRPGraphNode myNode = (IRPGraphNode) myObj1;
if(myNode.getModelObject().isATemplate() == 0)
myNode.setGraphicalProperty("BackgroundColor", "255,0,0")
}
}
}
}
Product Synonym
Rational Rhapsody
Was this topic helpful?
Document Information
Modified date:
27 May 2022
UID
swg21585825