ca.sqlpower.architect.swingui
Class BasicRelationshipUI

java.lang.Object
  extended by ca.sqlpower.architect.swingui.RelationshipUI
      extended by ca.sqlpower.architect.swingui.BasicRelationshipUI
All Implemented Interfaces:
PlayPenComponentUI, java.beans.PropertyChangeListener, java.io.Serializable, java.util.EventListener
Direct Known Subclasses:
IERelationshipUI

public class BasicRelationshipUI
extends RelationshipUI
implements java.beans.PropertyChangeListener, java.io.Serializable

The BasicRelationshipUI is responsible for drawing the lines between tables. Subclasses decorate the ends of the lines.

See Also:
Serialized Form

Field Summary
protected  java.awt.Rectangle computedBounds
           
protected  java.awt.geom.GeneralPath containmentPath
          This is a closed path for use with contains() and intersects().
protected  java.awt.BasicStroke idStroke
           
protected  java.awt.BasicStroke nonIdStroke
           
protected  java.awt.geom.GeneralPath path
          This is the path that the relationship line follows.
protected  int radius
          Points within radius pixels of this relationship's visible path are considered to be contained within this component.
protected  Relationship relationship
           
protected  java.awt.Color selectedColor
           
protected  java.awt.Color unselectedColor
           
 
Fields inherited from class ca.sqlpower.architect.swingui.RelationshipUI
CHILD_FACES_BOTTOM, CHILD_FACES_LEFT, CHILD_FACES_RIGHT, CHILD_FACES_TOP, CHILD_MASK, fkConnectionPoint, NO_FACING_EDGES, orientation, PARENT_FACES_BOTTOM, PARENT_FACES_LEFT, PARENT_FACES_RIGHT, PARENT_FACES_TOP, PARENT_MASK, pkConnectionPoint, snapRadius, UI_CLASS_ID
 
Constructor Summary
BasicRelationshipUI()
           
 
Method Summary
 void bestConnectionPoints()
          Adjusts the UI's connection points to the default "best" position.
 java.awt.Point closestEdgePoint(boolean onPkTable, java.awt.Point p)
          Returns the closest point to p which is along an edge of either the PK table (onPkTable true) or the FK table (onPkTable false).
protected  java.awt.Rectangle computeBounds()
          Compute bounds should only be called by objects in this package or from regress.
 boolean contains(PlayPenComponent c, int x, int y)
           
 boolean contains(java.awt.Point p)
          Determines if the given point touches the visible part of this relationship.
static PlayPenComponentUI createUI(PlayPenComponent c)
           
 void fixConnectionPoints()
          Attempts to move the connection points if they collided with another relationship's connection points.
protected  int getFacingEdges(java.awt.Rectangle pktBounds, java.awt.Rectangle fktBounds)
           
protected  int getFacingEdges(java.awt.Rectangle pktBounds, java.awt.Rectangle fktBounds, java.awt.geom.Point2D.Double pkIntersectPt, java.awt.geom.Point2D.Double fkIntersectPt)
           
 java.awt.Stroke getIdentifyingStroke()
           
 java.awt.Stroke getNonIdentifyingStroke()
           
 java.awt.Point getPreferredLocation()
           
 java.awt.Dimension getPreferredSize()
           
 java.awt.Dimension getPreferredSize(PlayPenComponent c)
           
 Relationship getRelationship()
           
 java.awt.Shape getShape()
          Returns the actual path that this relationship ui draws.
 int getShapeLength()
           
 int getTerminationLength()
          The distance that the termination extends perpendicularly away from the table's edge.
 int getTerminationWidth()
          The distance that the termination extends parallel to the table's edge.
 void installUI(PlayPenComponent c)
           
 boolean intersects(java.awt.Rectangle region)
          Determines if the given rectangle is visibly touching this component.
 boolean intersectsShape(java.awt.Shape s)
          Returns true iff this relationship's visible line intersects any part of the given shape.
 boolean isOrientationLegal()
          Figures out if the current orientation is legal, given the current pkTable and fkTable positions.
 boolean isOverFkDecoration(java.awt.Point p)
          Determines if the given point (in this Relationship's co-ordinates) is in the region defined as the primary key decoration.
 boolean isOverPkDecoration(java.awt.Point p)
          Determines if the given point (in this Relationship's co-ordinates) is in the region defined as the primary key decoration.
 void paint(java.awt.Graphics2D g2)
           
 void paint(java.awt.Graphics g, PlayPenComponent c)
           
protected  void paintTerminations(java.awt.Graphics2D g2, java.awt.Point start, java.awt.Point end, int orientation)
          Paints red dots.
 void propertyChange(java.beans.PropertyChangeEvent e)
           
 void revalidate()
           
protected  void translatePoint(java.awt.Point modify, java.awt.Point noModify)
          Sums the X coordinates of the two arguments and saves the result in modify.x.
 void uninstallUI(PlayPenComponent c)
           
 
Methods inherited from class ca.sqlpower.architect.swingui.RelationshipUI
getFkConnectionPoint, getOrientation, getPkConnectionPoint, getSnapRadius, setFkConnectionPoint, setOrientation, setPkConnectionPoint, setSnapRadius
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

relationship

protected Relationship relationship

computedBounds

protected java.awt.Rectangle computedBounds

path

protected java.awt.geom.GeneralPath path
This is the path that the relationship line follows. Don't use it for contains() and intersects() becuase it is closed by a diagonal line from start to finish.

See Also:
containmentPath

containmentPath

protected java.awt.geom.GeneralPath containmentPath
This is a closed path for use with contains() and intersects().


selectedColor

protected java.awt.Color selectedColor

unselectedColor

protected java.awt.Color unselectedColor

nonIdStroke

protected java.awt.BasicStroke nonIdStroke

idStroke

protected java.awt.BasicStroke idStroke

radius

protected int radius
Points within radius pixels of this relationship's visible path are considered to be contained within this component.

See Also:
contains(java.awt.Point)
Constructor Detail

BasicRelationshipUI

public BasicRelationshipUI()
Method Detail

createUI

public static PlayPenComponentUI createUI(PlayPenComponent c)

installUI

public void installUI(PlayPenComponent c)
Specified by:
installUI in interface PlayPenComponentUI

uninstallUI

public void uninstallUI(PlayPenComponent c)
Specified by:
uninstallUI in interface PlayPenComponentUI

revalidate

public void revalidate()
Specified by:
revalidate in interface PlayPenComponentUI

paint

public void paint(java.awt.Graphics2D g2)
Specified by:
paint in interface PlayPenComponentUI

paint

public void paint(java.awt.Graphics g,
                  PlayPenComponent c)
Parameters:
g - The graphics to paint on. It should be in the coordinate space of the containing playpen.

contains

public boolean contains(java.awt.Point p)
Description copied from class: RelationshipUI
Determines if the given point touches the visible part of this relationship.

Specified by:
contains in interface PlayPenComponentUI
Specified by:
contains in class RelationshipUI

contains

public boolean contains(PlayPenComponent c,
                        int x,
                        int y)

intersects

public boolean intersects(java.awt.Rectangle region)
Description copied from class: RelationshipUI
Determines if the given rectangle is visibly touching this component.

Specified by:
intersects in class RelationshipUI
Parameters:
region - The region to test.
Returns:
Whether or not this Relationship visibly intersects the given region

paintTerminations

protected void paintTerminations(java.awt.Graphics2D g2,
                                 java.awt.Point start,
                                 java.awt.Point end,
                                 int orientation)
Paints red dots. Subclasses will implement real notation.


bestConnectionPoints

public void bestConnectionPoints()
Adjusts the UI's connection points to the default "best" position.

Specified by:
bestConnectionPoints in class RelationshipUI

closestEdgePoint

public java.awt.Point closestEdgePoint(boolean onPkTable,
                                       java.awt.Point p)
Returns the closest point to p which is along an edge of either the PK table (onPkTable true) or the FK table (onPkTable false). NOTE: The orientation of the relationship will now be changed by this method.

Specified by:
closestEdgePoint in class RelationshipUI

translatePoint

protected void translatePoint(java.awt.Point modify,
                              java.awt.Point noModify)
Sums the X coordinates of the two arguments and saves the result in modify.x. Does the same for the Y coordinates.

Note that this is similar to Point.translate(int,int) but it takes a second point as an argument rather than two integers.


getFacingEdges

protected int getFacingEdges(java.awt.Rectangle pktBounds,
                             java.awt.Rectangle fktBounds)

getFacingEdges

protected int getFacingEdges(java.awt.Rectangle pktBounds,
                             java.awt.Rectangle fktBounds,
                             java.awt.geom.Point2D.Double pkIntersectPt,
                             java.awt.geom.Point2D.Double fkIntersectPt)

getTerminationLength

public int getTerminationLength()
The distance that the termination extends perpendicularly away from the table's edge. If the parent and child terminations are different sizes, this returns the maximum of the two.


getTerminationWidth

public int getTerminationWidth()
The distance that the termination extends parallel to the table's edge. If the parent and child terminations are different sizes, this returns the maximum of the two.


getRelationship

public Relationship getRelationship()

getIdentifyingStroke

public java.awt.Stroke getIdentifyingStroke()

getNonIdentifyingStroke

public java.awt.Stroke getNonIdentifyingStroke()

isOrientationLegal

public boolean isOrientationLegal()
Figures out if the current orientation is legal, given the current pkTable and fkTable positions.

XXX: answers false sometimes when true would be more correct. A more sophisticated implementation is warranted when time allows.


fixConnectionPoints

public void fixConnectionPoints()
Attempts to move the connection points if they collided with another relationship's connection points. It depends on the points having a previous location point already, preferably the best connection point.

Guesses for new connection points in the following order: 7 5 3 1 origin 2 4 6 8


computeBounds

protected java.awt.Rectangle computeBounds()
Compute bounds should only be called by objects in this package or from regress.


getPreferredSize

public java.awt.Dimension getPreferredSize()
Specified by:
getPreferredSize in interface PlayPenComponentUI

getPreferredSize

public java.awt.Dimension getPreferredSize(PlayPenComponent c)

getPreferredLocation

public java.awt.Point getPreferredLocation()
Specified by:
getPreferredLocation in class RelationshipUI

isOverPkDecoration

public boolean isOverPkDecoration(java.awt.Point p)
Determines if the given point (in this Relationship's co-ordinates) is in the region defined as the primary key decoration. This is useful for determining the behaviour of clicks and drags.

Specified by:
isOverPkDecoration in class RelationshipUI

isOverFkDecoration

public boolean isOverFkDecoration(java.awt.Point p)
Determines if the given point (in this Relationship's co-ordinates) is in the region defined as the primary key decoration. This is useful for determining the behaviour of clicks and drags.

Specified by:
isOverFkDecoration in class RelationshipUI

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
Specified by:
propertyChange in interface java.beans.PropertyChangeListener

intersectsShape

public boolean intersectsShape(java.awt.Shape s)
Description copied from class: RelationshipUI
Returns true iff this relationship's visible line intersects any part of the given shape.

Specified by:
intersectsShape in class RelationshipUI
Parameters:
s - The shape to test for intersection with.
Returns:
Whether or not this relationship intersects s.

getShape

public java.awt.Shape getShape()
Returns the actual path that this relationship ui draws. It will get reset from time to time as this relationship (or its connected tables) gets moved by the user.

Specified by:
getShape in class RelationshipUI

getShapeLength

public int getShapeLength()
Specified by:
getShapeLength in class RelationshipUI


Copyright © 2003-2007 SQL Power Group Inc. www.sqlpower.ca