templates.diagram
Class Entity

java.lang.Object
  extended by templates.diagram.DiagramElement
      extended by templates.diagram.Entity

public class Entity
extends DiagramElement

Class to maintain the graphical representation of TemplateComponents.

Author:
Lenko Grigorov

Nested Class Summary
protected  class Entity.LabelBox
          Class to maintain the graphical representation of the label of the entity.
 
Field Summary
protected  TemplateComponent component
          The TemplateComponent represented by the entity.
static java.lang.String FLAG_MARK
          Denotes if the FSA model for an entity has been modified after being assigned to the entity.
protected static int LABEL_SPACING
          Offset of the label box in pixels, to produce spacing around it.
protected  EntityLayout layout
          The layout information of the entity.
static int ON_ICON
          Constant to say mouse cursor is over the icon of the entity.
static int ON_LABEL
          Constant to say mouse cursor is over the label of the entity.
static int ON_NADA
          Constant to say mouse cursor is not over any part of the entity.
static int ON_PORT
          Constant to say mouse cursor is over one of the connector handles of the entity.
static int ON_SUP
          Constant to say mouse cursor is over the "supervisor computation" shortcut icon (possible only if the entity is a channel).
static int PORT_RADIUS
          The radius of the connector handles on the sides the entity, in pixels.
 
Fields inherited from class templates.diagram.DiagramElement
COLOR_INCONSIST, COLOR_NORM, COLOR_SELECT, COLOR_SELECT_INCONSIST, FAT_LINE_STROKE, globalFont, globalFontRenderer, highlight, inconsistent, LINE_STROKE, MARKER_STROKE, selected
 
Constructor Summary
Entity(TemplateComponent component)
          Construct an entity for the layout of the given TemplateComponent .
Entity(TemplateComponent component, EntityLayout layout)
          Construct an entity for the given TemplateComponent with the given EntityLayout.
 
Method Summary
protected  void computeBounds()
          Computes the bounds of the entity (smallest rectangle containing all elements of the entity) and caches the result.
 boolean contains(java.awt.Point p)
          Checks if the diagram element contains the given point.
 void draw(java.awt.Graphics2D g2d)
          Render the diagram element in the given graphical context, disregarding the inconsistency setting.
 void draw(java.awt.Graphics2D g2d, boolean showInconsistency)
          Render the diagram element in the given graphical context, according to the choice of differentiating or not inconsistent diagram elements.
 void drawPlain(java.awt.Graphics2D g2d)
          Renders only the icon and the label of the entity using the DiagramElement.COLOR_NORM color, in the given graphical context.
 java.awt.Rectangle getBounds()
          Retrieve the bounds of the diagram element.
 TemplateComponent getComponent()
          Retrieve the TemplateComponent represented by the entity.
 EntityIcon getIcon()
          Retrieve the icon of the entity.
 java.lang.String getLabel()
          Retrieve the label of the entity.
 java.awt.Point getLocation()
          Retrieve the location of the entity.
 java.awt.Point[] getPorts()
          Retrieve the center points of the connector handles.
 boolean intersects(java.awt.Rectangle r)
          Checks if the given rectangle intersects the diagram element.
 void setIcon(EntityIcon icon)
          Set the icon of the entity.
 void setLabel(java.lang.String label)
          Set the label of the entity.
 void setLocation(java.awt.Point location)
          Set the location of the entity.
 void translate(java.awt.Point delta)
          NOTE: Do not use this method directly.
 void update()
          Updates the entity to reflect any changes to the icon, label, location, type of entity, etc.
 int whereisPoint(java.awt.Point p)
          Checks on which part of the entity a given point lies.
 
Methods inherited from class templates.diagram.DiagramElement
getGlobalFont, getGlobalFontMetrics, getGlobalFontRenderer, setGlobalFont, setGlobalFontRenderer, setHighlight, setInconsistent, setSelected
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FLAG_MARK

public static final java.lang.String FLAG_MARK
Denotes if the FSA model for an entity has been modified after being assigned to the entity.

See Also:
Constant Field Values

LABEL_SPACING

protected static final int LABEL_SPACING
Offset of the label box in pixels, to produce spacing around it.

See Also:
Constant Field Values

PORT_RADIUS

public static final int PORT_RADIUS
The radius of the connector handles on the sides the entity, in pixels.

See Also:
Constant Field Values

ON_NADA

public static final int ON_NADA
Constant to say mouse cursor is not over any part of the entity.

See Also:
whereisPoint(Point), Constant Field Values

ON_ICON

public static final int ON_ICON
Constant to say mouse cursor is over the icon of the entity.

See Also:
whereisPoint(Point), Constant Field Values

ON_LABEL

public static final int ON_LABEL
Constant to say mouse cursor is over the label of the entity.

See Also:
whereisPoint(Point), Constant Field Values

ON_PORT

public static final int ON_PORT
Constant to say mouse cursor is over one of the connector handles of the entity.

See Also:
whereisPoint(Point), Constant Field Values

ON_SUP

public static final int ON_SUP
Constant to say mouse cursor is over the "supervisor computation" shortcut icon (possible only if the entity is a channel).

See Also:
whereisPoint(Point), Constant Field Values

component

protected TemplateComponent component
The TemplateComponent represented by the entity.


layout

protected EntityLayout layout
The layout information of the entity.

Constructor Detail

Entity

public Entity(TemplateComponent component)
       throws MissingLayoutException
Construct an entity for the layout of the given TemplateComponent .

Parameters:
component - the TemplateComponent which the entity will represent
Throws:
MissingLayoutException - if the TemplateComponent has no annotation with an EntityLayout (under the Annotable.LAYOUT key)

Entity

public Entity(TemplateComponent component,
              EntityLayout layout)
Construct an entity for the given TemplateComponent with the given EntityLayout.

Parameters:
component - the TemplateComponent which the entity will represent
layout - the layout information for the entity
Method Detail

computeBounds

protected void computeBounds()
Computes the bounds of the entity (smallest rectangle containing all elements of the entity) and caches the result.

See Also:
bounds

getComponent

public TemplateComponent getComponent()
Retrieve the TemplateComponent represented by the entity.

Returns:
the TemplateComponent represented by the entity

draw

public void draw(java.awt.Graphics2D g2d)
Description copied from class: DiagramElement
Render the diagram element in the given graphical context, disregarding the inconsistency setting. I.e., inconsistent diagram elements should be rendered as if they were consistent.

Specified by:
draw in class DiagramElement
Parameters:
g2d - the graphical context where the diagram element has to be rendered

draw

public void draw(java.awt.Graphics2D g2d,
                 boolean showInconsistency)
Description copied from class: DiagramElement
Render the diagram element in the given graphical context, according to the choice of differentiating or not inconsistent diagram elements.

Specified by:
draw in class DiagramElement
Parameters:
g2d - the graphical context where the diagram element has to be rendered
showInconsistency - choice for rendering inconsistent diagram elements differently or not; if true, inconsistent diagram elements have to be rendered differently; iffalse, inconsistent diagram elements should be rendered as if they were consistent

drawPlain

public void drawPlain(java.awt.Graphics2D g2d)
Renders only the icon and the label of the entity using the DiagramElement.COLOR_NORM color, in the given graphical context. This method is to be used to render representations of the entity outside of the drawing canvas, e.g., in dialog boxes.

Parameters:
g2d - the graphical context where the entity has to be rendered

getLocation

public java.awt.Point getLocation()
Retrieve the location of the entity.

Returns:
the location of the entity

setLocation

public void setLocation(java.awt.Point location)
Set the location of the entity.

NOTE: Do not use this method directly. Use TemplateDiagram.translate(java.util.Collection, Point) instead.

Parameters:
location - the new location of the entity

translate

public void translate(java.awt.Point delta)
NOTE: Do not use this method directly. Use TemplateDiagram.translate(java.util.Collection, Point) instead.

Specified by:
translate in class DiagramElement
Parameters:
delta - the displacement in the x and y direction

update

public void update()
Updates the entity to reflect any changes to the icon, label, location, type of entity, etc. In essence, recomputes how the entity should be rendered.


getBounds

public java.awt.Rectangle getBounds()
Description copied from class: DiagramElement
Retrieve the bounds of the diagram element.

Specified by:
getBounds in class DiagramElement
Returns:
the smallest rectangle containing all parts of the diagram element

contains

public boolean contains(java.awt.Point p)
Description copied from class: DiagramElement
Checks if the diagram element contains the given point.

With non-rectangular diagram elements, this is different from checking if the point is contained within the bounds of the element. More specifically, a point may be contained within the bounds, but this method may still return false.

Specified by:
contains in class DiagramElement
Parameters:
p - the point to be checked
Returns:
true if the diagram element contains the point; false otherwise

intersects

public boolean intersects(java.awt.Rectangle r)
Description copied from class: DiagramElement
Checks if the given rectangle intersects the diagram element.

With non-rectangular diagram elements, this is different from checking if the rectangle intersects the bounds of the element. More specifically, a rectangle may intersect the bounds, but this method may still return false.

Specified by:
intersects in class DiagramElement
Parameters:
r - the rectangle to be checked
Returns:
true if the rectangle intersects the diagram element; false otherwise

whereisPoint

public int whereisPoint(java.awt.Point p)
Checks on which part of the entity a given point lies. The answer can be the icon, the label, one of the connector handles, the "supervisor computation" shortcut icon (possible only if the entity represents channel), or nothing (i.e., the point does not lie on the connector).

Parameters:
p - the point to be checked
Returns:
which part of the connector the point lies on (ON_ICON, ON_LABEL, ON_PORT, ON_SUP or ON_NADA)

getLabel

public java.lang.String getLabel()
Retrieve the label of the entity.

Returns:
the label of the entity

setLabel

public void setLabel(java.lang.String label)
Set the label of the entity.

NOTE: Do not use this method directly. Use TemplateDiagram.labelEntity(Entity, String) instead.

Parameters:
label - the new label of the entity

getPorts

public java.awt.Point[] getPorts()
Retrieve the center points of the connector handles.

Returns:
the center points of the connector handles
See Also:
ports

getIcon

public EntityIcon getIcon()
Retrieve the icon of the entity.

Returns:
the icon of the entity

setIcon

public void setIcon(EntityIcon icon)
Set the icon of the entity.

NOTE: Do not use this method directly. Use TemplateDiagram.setEntityIcon(Entity, EntityIcon) instead.

Parameters:
icon - the new icon of the entity