org.argouml.uml.diagram.use_case.ui
Class FigUseCase

java.lang.Object
  |
  +--FigNode
        |
        +--org.argouml.uml.diagram.ui.FigNodeModelElement
              |
              +--org.argouml.uml.diagram.use_case.ui.FigUseCase
All Implemented Interfaces:
ArgoEventListener, ArgoNotationEventListener, DelayedVChangeListener, java.util.EventListener, java.awt.event.KeyListener, java.awt.event.MouseListener, NotationContext, java.beans.PropertyChangeListener, java.beans.VetoableChangeListener

public class FigUseCase
extends FigNodeModelElement

A fig to display use cases on use case diagrams.

Realised as a solid oval containing the name of the use case. Optionally may be split into two compartments, with the lower compartment displaying the extension points for the use case.

Implements all interfaces through its superclasses.

There is some coordinate geometry to be done to fit rectangular text boxes inside an elipse. The rectangular text box contains the name and any extension points if shown, and is deemed to be of height 2h and width 2w. We allow a margin of p above the top and below the bottom of the box, so we know the height of the elipse, 2b = 2h + 2p.

The formula for an elipse of width 2a and height 2b, centred on the origin, is

x^2/a^2 + y^2/b^2 = 1.

We know that a corner of the rectangle is at coordinate (w,h), since the rectangle must also be centred on the origin to fit within the elipse. Subsituting these values for x and y in the formula above, we can compute a, half the width of the elipse, since we know b.

a = wb/sqrt(b^2 - h^2).

But b was defined in terms of the height of the rectangle plus agreed padding at the top, so we can write.

a = (wh + wb)/ sqrt(2hp + p^2)

Given we now know a and b, we can find the coordinates of any partition line required between use case name and extension points.

Finally we need to transform our coordinates, to recognise that the origin is at our top left corner, and the Y coordinates are reversed.

See Also:
Serialized Form

Nested Class Summary
 class FigUseCase.FigMyCircle
          FigMyCircle is a FigCircle with corrected connectionPoint method: this methods calculates where a connected edge ends.
 
Field Summary
protected  FigUseCase.FigMyCircle _bigPort
          UML use cases do not really have ports, so just define one big one so that users can drag edges to or from any point in the icon.
protected  FigUseCase.FigMyCircle _cover
          We don't use _bigPort for the actual graphics of the oval.
protected  FigRect _epBigPort
          The rectangle for the entire extension point box.
protected  FigLine _epSep
          The line separating name and extension points.
protected  FigGroup _epVec
          The vector of graphics for extension points (if any).
protected  CompartmentFigText _highlightedFigText
          Text highlighted by mouse actions on the diagram.
protected  int _MIN_VERT_PADDING
          The minimum padding allowed above and below the rectangle for the use case name and extension points to the top of the use case oval itself.
protected  int _SPACER
          Space above and below the line separating name from extension points.
private static Logger LOG
           
 
Fields inherited from class org.argouml.uml.diagram.ui.FigNodeModelElement
_enclosedFigs, _encloser, _name, _readyToEdit, _shadowSize, _stereo, BUNDLE, checkSize, ITALIC_LABEL_FONT, LABEL_FONT, MARGIN, POPUP_ADD_OFFSET, ROWHEIGHT, SHADOW_COLOR_ALPHA, SHADOW_COLOR_VALUE, STEREOHEIGHT, suppressCalcBounds
 
Constructor Summary
FigUseCase()
          Constructor for a new use case fig.
FigUseCase(GraphModel gm, java.lang.Object node)
          A version of the constructor used to associated the Fig with a particular NSUML object.
 
Method Summary
private  java.awt.Dimension _calcEllipse(java.awt.Dimension rectSize, int vertPadding)
          A private utility to calculate the bounding oval for the given rectangular text box.
private  double _calcX(double a, double b, double y)
          Private utility routine to work out the (positive) x coordinate of a point on an oval, given the radii and y coordinate.
private  java.awt.Dimension _getTextSize()
          A private utility routine to calculate the minimum size of the rectangle to hold the name and extension points (if displayed).
 java.lang.Object clone()
          Make a copy of the current fig.
protected  void createFeatureIn(FigGroup fg, java.awt.event.InputEvent ie)
          Create a new "feature" (extension point) in the use case fig.
 java.awt.Color getFillColor()
          Get the line colour for the use case oval.
 boolean getFilled()
          Get whether the use case oval is to be filled.
 java.util.Vector getGravityPoints()
          Makes sure that the edges stick to the elipse fig of the usecase.
 java.awt.Color getLineColor()
          Get the line colour for the use case oval.
 int getLineWidth()
          Get the line width for the use case oval.
 java.awt.Dimension getMinimumSize()
          Compute the minimum acceptable size of the use case.
private  CompartmentFigText getNextVisibleFeature(FigGroup fgVec, int i)
          Private method to find the next visible feature to highlight.
 java.util.Vector getPopUpActions(java.awt.event.MouseEvent me)
          Build a collection of menu items relevant for a right-click popup menu on a Use Case.
private  CompartmentFigText getPreviousVisibleFeature(FigGroup fgVec, int i)
          Private method to find the previous visible feature to highlight.
 boolean isExtensionPointVisible()
          Returns whether the extension points are currently displayed.
 void keyPressed(java.awt.event.KeyEvent ke)
          Deal with a key being pressed.
 Selection makeSelection()
          Creates a set of handles for dragging generalization/specializations or associations.
protected  void modelChanged(MElementEvent mee)
          Adjust the fig in the light of some change to the model.
 void mouseExited(java.awt.event.MouseEvent me)
          Deal with the mouse leaving the fig.
 void mousePressed(java.awt.event.MouseEvent me)
          React to a mouse key being pressed.
 java.lang.String placeString()
          The text string to be used as the default name of the new use case fig.
 void setBounds(int x, int y, int w, int h)
          Change the boundary of the use case.
 void setExtensionPointVisible(boolean isVisible)
          Set the visibility of the extension point compartment.
 void setFillColor(java.awt.Color col)
          Set the fill colour for the use case oval.
 void setFilled(boolean f)
          Set whether the use case oval is to be filled.
 void setLineColor(java.awt.Color col)
          Set the line colour for the use case oval.
 void setLineWidth(int w)
          Set the line width for the use case oval.
 void setOwner(java.lang.Object node)
          Associate this fig with a particular NSUML object.
protected  void textEdited(FigText ft)
          Invoked when text has been edited.
private  CompartmentFigText unhighlight()
          Private utility to unhighlight any currently selected extension point.
protected  void updateExtensionPoint()
          Updates the extensionpoints in the fig
protected  void updateNameText()
          Updates the text of the name FigText.
protected  void updateStereotypeText()
          Updates the text of the sterotype FigText.
 
Methods inherited from class org.argouml.uml.diagram.ui.FigNodeModelElement
addFig, calcBounds, damage, delayedVetoableChange, delete, dispose, elementOrdering, enableSizeChecking, finalize, getContextNotation, getEnclosedFigs, getEnclosingFig, getItemUID, getName, getNameFig, getShadowSize, getStereotype, getStereotypeFig, getTipString, getUpdatedSize, hit, hitClarifier, isPartlyOwner, isPartlyOwner, keyReleased, keyTyped, listRoleItemSet, mouseClicked, notationAdded, notationChanged, notationProviderAdded, notationProviderRemoved, notationRemoved, paint, paintClarifiers, postLoad, propertyChange, propertySet, recovered, removed, renderingChanged, roleAdded, roleRemoved, setEnclosingFig, setHandleBox, setItemUID, setName, setNameFig, setShadowSize, setStereotype, setStereotypeFig, superTranslate, updateBounds, updateListeners, vetoableChange
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.awt.event.MouseListener
mouseEntered, mouseReleased
 

Field Detail

LOG

private static final Logger LOG

_MIN_VERT_PADDING

protected final int _MIN_VERT_PADDING
The minimum padding allowed above and below the rectangle for the use case name and extension points to the top of the use case oval itself.

See Also:
Constant Field Values

_SPACER

protected final int _SPACER
Space above and below the line separating name from extension points. The line takes a further 1 pixel.

See Also:
Constant Field Values

_bigPort

protected FigUseCase.FigMyCircle _bigPort
UML use cases do not really have ports, so just define one big one so that users can drag edges to or from any point in the icon.


_cover

protected FigUseCase.FigMyCircle _cover
We don't use _bigPort for the actual graphics of the oval. We define an identical oval that sits on top of it.


_epSep

protected FigLine _epSep
The line separating name and extension points.


_epVec

protected FigGroup _epVec
The vector of graphics for extension points (if any). First one is the rectangle for the entire extension points box.


_epBigPort

protected FigRect _epBigPort
The rectangle for the entire extension point box.


_highlightedFigText

protected CompartmentFigText _highlightedFigText
Text highlighted by mouse actions on the diagram. Assumed to belong to the extension point compartment.

Constructor Detail

FigUseCase

public FigUseCase()
Constructor for a new use case fig. We work out the smallest oval that will fit round.

At creation the extension point box is not showing (for consistency with existing implementations). We can show it later.


FigUseCase

public FigUseCase(GraphModel gm,
                  java.lang.Object node)
A version of the constructor used to associated the Fig with a particular NSUML object.

Not clear that this is ever used. The load routines use the main constructor and call setOwner directly.

Parameters:
gm - The graph model to associate with this Fig. Ignored in this implementation.
node - The NSUML object to associate with this Fig.
Method Detail

placeString

public java.lang.String placeString()
The text string to be used as the default name of the new use case fig. However this seems in general to be immediately overwritten - presumably somewhere in the creation code for the object, which choses to define a name.

Note. Good UML would probably prefer a name starting with a capital and no spaces!

Overrides:
placeString in class FigNodeModelElement
Returns:
The desired text of the default name.

clone

public java.lang.Object clone()
Make a copy of the current fig.

Uses the generic superclass clone which gives a vector of all the figs. Then initialize our instance variables from this vector.

Returns:
A new copy of the the current fig.

getPopUpActions

public java.util.Vector getPopUpActions(java.awt.event.MouseEvent me)
Build a collection of menu items relevant for a right-click popup menu on a Use Case.

Adds to the generic pop up items from the parent.

Overrides:
getPopUpActions in class FigNodeModelElement
Parameters:
me - The mouse event that generated this popup.
Returns:
A collection of menu items

isExtensionPointVisible

public boolean isExtensionPointVisible()
Returns whether the extension points are currently displayed.

Returns:
true if the attributes are visible, false otherwise.

setExtensionPointVisible

public void setExtensionPointVisible(boolean isVisible)
Set the visibility of the extension point compartment. This is called from outside this class when the user sets visibility explicitly through the style panel or the context sensitive pop-up menu.

We don't change the size of the use case, so we just have to mark the extension point elements' visibility. setBounds(int, int, int, int) will do the relayout (with name in the middle) for us.

Parameters:
isVisible - true if the compartment should be shown, false otherwise.

makeSelection

public Selection makeSelection()
Creates a set of handles for dragging generalization/specializations or associations.

Overrides:
makeSelection in class FigNodeModelElement
Returns:
The new selection object (a GEF entity).

setOwner

public void setOwner(java.lang.Object node)
Associate this fig with a particular NSUML object.

Associates the node with the "bigPort" that is the whole of this object.

Must be public, since called directly, e.g. by the load routines.

Overrides:
setOwner in class FigNodeModelElement
Parameters:
node - The NSUML object to associate with this fig.

getMinimumSize

public java.awt.Dimension getMinimumSize()
Compute the minimum acceptable size of the use case.

We work out the minimum size of the text box, and from that the radii of the enclosing ellipse.

Returns:
The dimensions of the smallest size bounding box of the use case.

_getTextSize

private java.awt.Dimension _getTextSize()
A private utility routine to calculate the minimum size of the rectangle to hold the name and extension points (if displayed).

Returns:
The dimensions of the rectangle

_calcEllipse

private java.awt.Dimension _calcEllipse(java.awt.Dimension rectSize,
                                        int vertPadding)
A private utility to calculate the bounding oval for the given rectangular text box.

To sufficiently constrain the problem, we define that there is a gap given by the parameter vertPadding above the top of the box to the top of the oval.

All computations are done in double, and then converted to integer at the end.

Parameters:
rectSize - The dimensions of the rectangle to be bounded
vertPadding - The padding between the top of the box and the top of the ellipse.
Returns:
The dimensions of the required oval

setBounds

public void setBounds(int x,
                      int y,
                      int w,
                      int h)
Change the boundary of the use case.

If we are called with less than the minimum size, we impose the minimum size.

We place the name and extension points at the centre of the rectangle.

Set the bounds of all components of the Fig.

Parameters:
x - X coordinate of upper left corner
y - Y coordinate of upper left corner
w - width of bounding box
h - height of bounding box

_calcX

private double _calcX(double a,
                      double b,
                      double y)
Private utility routine to work out the (positive) x coordinate of a point on an oval, given the radii and y coordinate.

Parameters:
a - radius in X direction
b - radius in Y direction
y - Y coordinate
Returns:
Positive X coordinate for the given Y coordinate

setLineColor

public void setLineColor(java.awt.Color col)
Set the line colour for the use case oval.

This involves setting the _cover oval, not the bigPort.

Parameters:
col - The colour desired.

getLineColor

public java.awt.Color getLineColor()
Get the line colour for the use case oval.

This involves getting the _cover oval colour, not the bigPort.

Returns:
The colour in use.

setFillColor

public void setFillColor(java.awt.Color col)
Set the fill colour for the use case oval.

This involves setting the _cover oval, not the bigPort.

Parameters:
col - The colour desired.

getFillColor

public java.awt.Color getFillColor()
Get the line colour for the use case oval.

This involves getting the _cover oval colour, not the bigPort.

Returns:
The colour in use.

setFilled

public void setFilled(boolean f)
Set whether the use case oval is to be filled.

This involves setting the _cover oval, not the bigPort.

Parameters:
f - true if the oval is to be filled, false if not.

getFilled

public boolean getFilled()
Get whether the use case oval is to be filled.

This involves getting the _cover oval, not the bigPort.

Returns:
true if the oval is to be filled, false if not.

setLineWidth

public void setLineWidth(int w)
Set the line width for the use case oval.

This involves setting the _cover oval, not the bigPort.

Parameters:
w - The line width desired.

getLineWidth

public int getLineWidth()
Get the line width for the use case oval.

This involves getting the _cover oval colour, not the bigPort.

Returns:
The line width set.

mousePressed

public void mousePressed(java.awt.event.MouseEvent me)
React to a mouse key being pressed.

Parameters:
me - The mouse action that caused us to be invoked.

mouseExited

public void mouseExited(java.awt.event.MouseEvent me)
Deal with the mouse leaving the fig. Unhighlight the fig.

Parameters:
me - The mouse action that caused us to be invoked.

keyPressed

public void keyPressed(java.awt.event.KeyEvent ke)
Deal with a key being pressed.

We deal with UP and DOWN, and use these to move through the list of selected extension points. We deal with ENTER and use that to start the text editor.

Specified by:
keyPressed in interface java.awt.event.KeyListener
Overrides:
keyPressed in class FigNodeModelElement
Parameters:
ke - The key event that caused us to be invoked.

textEdited

protected void textEdited(FigText ft)
                   throws java.beans.PropertyVetoException
Invoked when text has been edited.

We check that it is one of the extension point compartments and then parse accordingly.

Overrides:
textEdited in class FigNodeModelElement
Parameters:
ft - The text that has been edited.
java.beans.PropertyVetoException

getPreviousVisibleFeature

private CompartmentFigText getPreviousVisibleFeature(FigGroup fgVec,
                                                     int i)
Private method to find the previous visible feature to highlight.

We're passed in a group (which will be the extension point vector) and the currently highlighted fig (a member of that vector).

Parameters:
fgVec - A fig group (invariably the extension point vector) in which to seek the previous visible feature.
i - The index of the currently selected entry in fgVec.
Returns:
The new fig to use.

getNextVisibleFeature

private CompartmentFigText getNextVisibleFeature(FigGroup fgVec,
                                                 int i)
Private method to find the next visible feature to highlight.

We're passed in a group (which will be the extension point vector) and the currently highlighted fig (a member of that vector).

Parameters:
fgVec - A fig group (invariably the extension point vector) in which to seek the next visible feature.
i - The index of the currently selected entry in fgVec.
Returns:
The new fig to use.

createFeatureIn

protected void createFeatureIn(FigGroup fg,
                               java.awt.event.InputEvent ie)
Create a new "feature" (extension point) in the use case fig.

Extension points are not strictly features, but that is a historical accident of naming. This creates a new entry in the extension point vector.

Overrides:
createFeatureIn in class FigNodeModelElement
Parameters:
fg - The fig group to which this applies (which must be the extension point vector).
ie - The input event that triggered us. In the current implementation a mouse double click.

unhighlight

private CompartmentFigText unhighlight()
Private utility to unhighlight any currently selected extension point.

Returns:
The extension point that was unhighlighted.

modelChanged

protected void modelChanged(MElementEvent mee)
Adjust the fig in the light of some change to the model.

Called both when there has been a change to notation, and when there has been an NSUML event.

Overrides:
modelChanged in class FigNodeModelElement

updateExtensionPoint

protected void updateExtensionPoint()
Updates the extensionpoints in the fig


updateNameText

protected void updateNameText()
Description copied from class: FigNodeModelElement
Updates the text of the name FigText.

Overrides:
updateNameText in class FigNodeModelElement
See Also:
FigNodeModelElement.updateNameText()

getGravityPoints

public java.util.Vector getGravityPoints()
Makes sure that the edges stick to the elipse fig of the usecase.

See Also:
org.tigris.gef.presentation.Fig#getGravityPoints()

updateStereotypeText

protected void updateStereotypeText()
Description copied from class: FigNodeModelElement
Updates the text of the sterotype FigText. Override in subclasses to get wanted behaviour. TODO: remove all 'misuses' of the stereotype figtexts (like in FigInterface)

Overrides:
updateStereotypeText in class FigNodeModelElement
See Also:
FigNodeModelElement.updateStereotypeText()


ArgoUML © 1996-2004 (20040306)ArgoUML HomepageArgoUML Developers' pageArgoUML Cookbook