Handling diagrams and view elements with J

 

Model and representation

Objecteering, in accordance with the UML standard, separates the model (its semantics) from its representation.  The set of metaclasses presented up until now corresponded to the model (Package, Class, Operation, …).  Representation allows the construction of graphical views associated to the model.

 

The ViewElement metaclass is a representation of a model element.  A model element can be associated with several ViewElements.  For example, a Class can be represented in several different Diagrams in several forms (with its attributes), which present its tagged values, in color, …).  A Class will, therefore, have several ViewElements which represent it within several Diagrams (Figure 3).

 

Figure 3. Different representations (ViewElement) of a class (Model)

 

In UML, this distinction reflects the separation of ModelElement and ViewElement.

 

 

Graphic management

The graphic model is very general, and only presents the ViewBox and ViewLink generic classes.

 

Before carrying out any operations on diagrams in J, you must first open the diagram using the "open" command.  Once you have finished your operations on a diagram, it must then be closed using the "close" command.  These operations are mandatory when handling objects in diagrams, and must be carried out.

 

For further details on these two commands, please see "Diagram class".

 

The order of creation for a graphic element in J must always indicate the associated semantic element.  Objecteering, knowing the context of the diagram and of the presented model element, will then create the correct graphic form. For example, the introduction:

 

aBox = adiagram.createAddAndMoveViewBox

       (aClass1, 300,30,70,75);

 

will create in the "aDiagram" diagram a representation of the "aClass1" class, in the attached coordinates (see "Point" for a description of the system of coordinated graphics).

 

The three important notions to be dealt with are, therefore, the Diagram, the model element (Element) and the representation of the elements (ViewElement).

 

When a ViewElement is created, it is possible to modify its graphic resources in J (color, width, coordinates), by modifying the attributes provided by the ViewElement, Point, ViewBox and ViewLink classes.

 

For example, the instruction below will present the "aBox" box, with a red contour and a green background :

 

aBox.setbgGreen(255);

aBox.setbgRed(255);

 

 

Example

This is an example that can be used in a macro. It creates a Class named aClass1 and the associated graphic element. The macro has to be used in a diagram.

 

Class aClass1;

Diagram adiagram;

ModelElement modelElt ;

ViewBox aBox;

 

adiagram = this ;

//First we open the diagram

adiagram.open() ;

 

modelElt  = OriginModelElement ;

if (modelElt.ClassOf == Package)

{

aClass1 =  modelElt.createAndAddClass  ("aClass1");

aBox = adiagram.createAddAndMoveViewBox(aClass1, 300,30,70,75);

//green backgroung

aBox.setbgRed(153);

aBox.setbgGreen(200);

aBox.setbgBlue(153);

//blue foreground

aBox.setfgRed(83);

aBox.setfgGreen(92);

aBox.setfgBlue(167);

}

 

//Finally we close the diagram

adiagram.close() ;