Chapter 7. Working with Diagrams

Table of Contents
The Diagram Pane
Viewing Diagrams
Creating New Diagrams
Creating New Elements
Editing Elements
Editing Diagrams
Undo/Redo

UML is a graphical language. Therefore, from a users perspective at least, the most important part of a UML tool is the graphical editor. This chapter introduces the general features of the diagram editor that are available for all or most of the diagram types, then takes a detailed look at the graphical editor and explains Poseidon's most important functionalities for editing diagrams.

The Diagram Pane

The graphical editor is embedded in the Diagram pane. This pane, as has been previously mentioned, is used to display and edit the diagrams of your model.

Diagram Pane Toolbar

Across the top of the Diagram pane, there is a toolbar that contains a number of tools you can use to create and modify your UML models. If you have already worked with a UML tool or a drawing tool capable of creating UML diagrams, you are probably familiar with the general idea. Each diagram type has a specialized set of tools in addition to the tools that are common to all diagram types. To display the name of each individual tool, position your mouse over it and wait a second or so, the name will appear in a box underneath.

In general, the Diagram pane toolbar changes according to the type of diagram currently displayed. There are, however, some tools which are available in all or nearly all of the diagrams:

Select

The first tool in the toolbar is called the 'select' tool, and is the default active tool. It is used to select, move, and scale diagram elements, as well as modify the element directly from the diagram. When an element has been selected and is now the current active element, it will appear with yellow circles (called 'handles') surrounding it.

A brief list of functions:

  • Select an element — Click on the desired element.

  • Move an element — Click and hold the mouse button inside the element, then drag the element to its new location.

  • Resize an element — Click and hold the mouse button on an element handle, then drag the handle.

  • Edit an element inline — Double-click on a text element to activate the text edit box.

Try it YourselfResize an Element

  1. Select the Client class from a diagram.

  2. Small round yellow handles appear on the corners of the element.

  3. Click and hold the mouse button on one of these handles and drag it around the diagram to resize the class.

Broom

The second tool is called the 'broom'. It arranges elements of a diagram into vertical and/or horizontal alignment.

To use the broom, you must first select the broom tool. This can be done by clicking the broom tool in the toolbar, or by pressing the CTRL key while clicking the mouse button. To get a very small broom, hold down the SHIFT key while creating the broom tool.

Next you must specify which edge of the elements will be aligned by moving the broom in that direction. For instance, moving the broom tool down first means it will align the tops of any elements it touches. Likewise, if the broom is moved upwards first, the bottoms of the elements will be aligned.

Now you can adjust the size of the broom. With the mouse button still depressed, moving the mouse in a perpendicular direction will expand the broom in that direction.

The broom will move any element it touches. The exception to this is associations — Poseidon attempts to maintain the shape and connection points of associations where possible. Thus, the broom will not straighten an association with a bendpoint, even if the broom comes into contact with the bendpoint. Figures 7–1 through 7–3 demonstrate how the broom interacts with associations.

Figure 7-1. Broom moves down without affecting bendpoint

Notice here how the broom has passed through the connection between Class_1 and Class_2, but the bendpoint is not affected in any way. The entire association is moved untouched.

Figure 7-2. Broom moves further without affecting connection point

In Figure 7–2, the broom has moved the elements further down. Note that the association between Class_2 and Class_3 has remained in exactly the same spot. The connection point on Class_2 has moved so that the association can remain the same.

Figure 7-3. Broom moves even further and must affect the association

Finally the association must move. Class_2 has moved too far down to maintain the size and shape of the connection. But the connection between Class_1 and Class_2 remains untouched.

The elements can be returned to their original positions, providing that the mouse button has not been released. As the broom tool is moved back to its original position, the elements it has moved are returned to their original positions. You can undo any alignment action until you release the mouse button.

The broom tool is also capable of automatically aligning elements. As before, the broom must be in contact with the elements to be aligned. The pressing the space bar toggles the alignment choices and moves the elements around.

Figure 7-4. Elements before they are aligned

The broom tool is touching all of the elements that will be moved, but the space bar has not been pressed yet. The classes are at no particular interval.

Figure 7-5. Elements spaced evenly

At this point, the space bar has been pressed once and the elements are now evenly spaced. Class_1 and Class_3 have not moved, but Class_2 has been positioned directly between them.

Figure 7-6. Elements packed tightly

Pressing the space bar again causes the elements to move very close together. The length of the broom or the original positions of the elements will not affect how close the elements are to each other.

Figure 7-7. Elements spread out

If the space bar is pressed one more time, the elements will be evenly spread out along the entire length of the broom tool. The broom tool in Figure 7–7 has been elongated to illustrate this.

Try it YourselfAlign Elements Vertically

  1. Open the deployment diagram 'componentOverview'.

  2. Select the broom tool from the diagram toolbar.

  3. Click and hold the mouse button on the far left side of the diagram pane.

  4. Move the mouse to the right slightly. The broom tool should now be a vertical line. Do not release the mouse button

  5. If necessary, move the mouse up or down to extend the broom so that it can touch both the 'ClientManagement' and 'ObjectManagement' components. Again, do not release the mouse button.

  6. Move the broom to the right to move the components. You can also move the broom back to the left to see the undo function in action.

Note

Sometimes a diagram requires a bit of extra explanation. This information is not a part of the final code, yet it helps the viewer better understand the diagram. This information can be included in a note element. Notes are extra comments that are included and displayed in a diagram. These notes can be added to any element including other notes, or they can stand alone in the diagram.

Notes are ignored by the code generator and are therefore never seen in the code output. They are likewise never seen in the navigation pane.

To add a note to a diagram, select the element that will have the note attached (or select the background of the diagram to add a freestanding note). Click the 'note' icon in the diagram toolbar. You can also create notes through the context menu of an element. The new note will now appear. You can either use the 'select' tool to make the note the current active element and then begin typing, or double-click to open the editable text field.

Figure 7-8. Adding a note through a context menu

Just as with any other element, notes can be resized with its handles and the color can be changed through the style panel of the details pane. This makes it easy to introduce a color-coding scheme to diagram notations.

Figure 7-9. A new note

Drawing Tools

The set of tools which appears at the end of the toolbar are for general drawing purposes. With these tools you can add other graphical elements, such as shapes and text, to your diagram. You should keep in mind that, although useful sometimes, these graphics are not part of UML and therefore they don't show up in the model tree in the Navigation pane.

The Drawing Tools:

  • Rectangle — Click in the diagram area and drag the mouse to create a rectangle.

  • Rounded Rectangle — Click in the diagram area and drag the mouse to create a rectangle with rounded corners.

  • Circle — Click in the diagram area and drag the mouse to create an ellipse.

  • Line — Click in the diagram area and drag the mouse to create a line.

  • Text — Click once to create a new text box and add text to a diagram.

  • Polygon — Click once everywhere the polygon is to have a corner. Double-click the last corner to close and render the polygon.

  • Spline — Use the same method as with the polygon to create an object with curved edges.

  • Ink — Hold the mouse button down and move the mouse around to create freehand shapes.

Diagram-specific Tools

The rest of the tools in the toolbar are specific to the current diagram type. They allow the creation of diagram elements and operate similar to a stamp. With a single click on the icon you get a handle to create one corresponding diagram element. If you double-click, the tool stays selected and you can create a number of diagram elements, one after the other. The cursor changes to a hair cross with which you can select the position of the new element. To disable this feature just click on the 'select' tool.

Some tools are only available in a certain context. In Class Diagrams, the tools to create a new attribute or a new operation are only available when a class is selected. Select the desired class and click on the appropriate button to create a new attribute or operation for your class.

The individual tools are covered in detail in Chapter 9 titled, 'A Walk Through the Diagrams'.