templates.diagram
Class DiagramElement

java.lang.Object
  extended by templates.diagram.DiagramElement
Direct Known Subclasses:
Connector, Entity

public abstract class DiagramElement
extends java.lang.Object

Common functionality of graphical representations of TemplateModel elements.

Author:
Lenko Grigorov

Field Summary
static java.awt.Color COLOR_INCONSIST
          Color for rendering inconsistent diagram elements.
static java.awt.Color COLOR_NORM
          Default color for rendering diagram elements.
static java.awt.Color COLOR_SELECT
          Color for rendering selected diagram elements.
static java.awt.Color COLOR_SELECT_INCONSIST
          Color for rendering selected inconsistent diagram elements.
protected static java.awt.Stroke FAT_LINE_STROKE
          Stroke for rendering thicker lines.
protected static java.awt.Font globalFont
          A pointer to the font to be used to render text on the display.
protected static java.awt.Graphics globalFontRenderer
          A pointer to the graphical context which will provide font rendering metrics.
protected  boolean highlight
          Specifies if the diagram element is highlighted.
protected  boolean inconsistent
          Specifies if the diagram element is inconsistent.
protected static java.awt.Stroke LINE_STROKE
          Default stroke style for rendering diagram elements.
protected static java.awt.Stroke MARKER_STROKE
          Stroke for rendering selection marquees.
protected  boolean selected
          Specifies if the diagram element is selected.
 
Constructor Summary
DiagramElement()
           
 
Method Summary
abstract  boolean contains(java.awt.Point p)
          Checks if the diagram element contains the given point.
abstract  void draw(java.awt.Graphics2D g2d)
          Render the diagram element in the given graphical context, disregarding the inconsistency setting.
abstract  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.
abstract  java.awt.Rectangle getBounds()
          Retrieve the bounds of the diagram element.
static java.awt.Font getGlobalFont()
          Retrieve the font to be used to render text on the display.
static java.awt.FontMetrics getGlobalFontMetrics()
          Retrieve the font metrics for rendering text on the display.
static java.awt.Graphics getGlobalFontRenderer()
          Retrieve the graphical context which provides font rendering metrics.
abstract  boolean intersects(java.awt.Rectangle r)
          Checks if the given rectangle intersects the diagram element.
static void setGlobalFont(java.awt.Font f)
          Set the font to be used to render text on the display.
static void setGlobalFontRenderer(java.awt.Graphics g)
          Set the graphical context which will provide font rendering metrics.
 void setHighlight(boolean b)
          Set if the diagram element should be rendered as highlighted or not.
 void setInconsistent(boolean b)
          Set if the diagram element should be rendered as inconsistent or not.
 void setSelected(boolean b)
          Set if the diagram element should be rendered as selected or not.
abstract  void translate(java.awt.Point delta)
          Translate the diagram element by the given displacement in the x and y direction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

globalFontRenderer

protected static java.awt.Graphics globalFontRenderer
A pointer to the graphical context which will provide font rendering metrics.

Needs to be set before creating TemplateDiagrams.


globalFont

protected static java.awt.Font globalFont
A pointer to the font to be used to render text on the display.

Needs to be set before creating TemplateDiagrams.


COLOR_NORM

public static final java.awt.Color COLOR_NORM
Default color for rendering diagram elements.


COLOR_INCONSIST

public static final java.awt.Color COLOR_INCONSIST
Color for rendering inconsistent diagram elements.


COLOR_SELECT

public static final java.awt.Color COLOR_SELECT
Color for rendering selected diagram elements.


COLOR_SELECT_INCONSIST

public static final java.awt.Color COLOR_SELECT_INCONSIST
Color for rendering selected inconsistent diagram elements.


LINE_STROKE

protected static final java.awt.Stroke LINE_STROKE
Default stroke style for rendering diagram elements.


FAT_LINE_STROKE

protected static final java.awt.Stroke FAT_LINE_STROKE
Stroke for rendering thicker lines.


MARKER_STROKE

protected static final java.awt.Stroke MARKER_STROKE
Stroke for rendering selection marquees.


highlight

protected boolean highlight
Specifies if the diagram element is highlighted.


selected

protected boolean selected
Specifies if the diagram element is selected.


inconsistent

protected boolean inconsistent
Specifies if the diagram element is inconsistent.

Constructor Detail

DiagramElement

public DiagramElement()
Method Detail

setGlobalFontRenderer

public static void setGlobalFontRenderer(java.awt.Graphics g)
Set the graphical context which will provide font rendering metrics.

Needs to be set before creating TemplateDiagrams.

Parameters:
g - the graphical context which will provide font rendering metrics

getGlobalFontRenderer

public static java.awt.Graphics getGlobalFontRenderer()
Retrieve the graphical context which provides font rendering metrics.

Returns:
the graphical context which provides font rendering metrics

getGlobalFontMetrics

public static java.awt.FontMetrics getGlobalFontMetrics()
Retrieve the font metrics for rendering text on the display.

Returns:
the font metrics for rendering text on the display if both globalFontRenderer and globalFont are set; null otherwise

setGlobalFont

public static void setGlobalFont(java.awt.Font f)
Set the font to be used to render text on the display.

Needs to be set before creating TemplateDiagrams.

Parameters:
f - the font to be used to render text on the display

getGlobalFont

public static java.awt.Font getGlobalFont()
Retrieve the font to be used to render text on the display.

Returns:
the font to be used to render text on the display

translate

public abstract void translate(java.awt.Point delta)
Translate the diagram element by the given displacement in the x and y direction.

Parameters:
delta - the displacement in the x and y direction

setHighlight

public void setHighlight(boolean b)
Set if the diagram element should be rendered as highlighted or not.

Parameters:
b - true if the diagram element should be rendered as highlighted; false otherwise

setSelected

public void setSelected(boolean b)
Set if the diagram element should be rendered as selected or not.

Parameters:
b - true if the diagram element should be rendered as seelcted; false otherwise

setInconsistent

public void setInconsistent(boolean b)
Set if the diagram element should be rendered as inconsistent or not.

Parameters:
b - true if the diagram element should be rendered as inconsistent; false otherwise

getBounds

public abstract java.awt.Rectangle getBounds()
Retrieve the bounds of the diagram element.

Returns:
the smallest rectangle containing all parts of the diagram element

draw

public abstract void draw(java.awt.Graphics2D g2d)
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.

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

draw

public abstract 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.

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

contains

public abstract boolean contains(java.awt.Point p)
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.

Parameters:
p - the point to be checked
Returns:
true if the diagram element contains the point; false otherwise

intersects

public abstract boolean intersects(java.awt.Rectangle r)
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.

Parameters:
r - the rectangle to be checked
Returns:
true if the rectangle intersects the diagram element; false otherwise