org.acm.seguin.uml.line
Class SegmentedLine

java.lang.Object
  extended by org.acm.seguin.uml.line.SegmentedLine
All Implemented Interfaces:
java.awt.event.ComponentListener, java.util.EventListener
Direct Known Subclasses:
AssociationRelationship, ImplementsRelationship, InheretenceRelationship

public class SegmentedLine
extends java.lang.Object
implements java.awt.event.ComponentListener

SegmentedLine.

For future builds, it may be worth considering caching the points above and below the line for an efficiency increase when there are lots of lines to paint.

Author:
Chris Seguin, Mike Atkinson

Field Summary
protected  double scalingFactor
          Description of the Field
protected  Vertex[] vertices
          The set of vertices on the line
protected  int[] Xs
          This array is used only during the paint method for drawing polylines
protected  int[] Ys
          This array is used only during the paint method for drawing polylines
 
Constructor Summary
SegmentedLine(EndPointPanel start, EndPointPanel end)
          Constructor for the SegmentedLine object
 
Method Summary
 void componentHidden(java.awt.event.ComponentEvent cevt)
          Description of the Method
 void componentMoved(java.awt.event.ComponentEvent cevt)
          Description of the Method
 void componentResized(java.awt.event.ComponentEvent cevt)
          Description of the Method
 void componentShown(java.awt.event.ComponentEvent cevt)
          Description of the Method
 void drag(java.awt.Point point)
          Drag the current vertex
protected  void drawArrow(java.awt.Graphics2D g)
          Draws the arrow and the last segment
 void drop()
          The point was dropped
protected  java.awt.Point getArrowPointAbove()
          Determine the point at which the last segment should stop
protected  java.awt.Point getArrowPointBelow()
          Determine the point at which the last segment should stop
protected  java.awt.Color getColor()
           
 EndPointPanel getEndPanel()
           
protected  java.awt.Point getShortPoint()
          Determine the point at which the last segment should stop
 EndPointPanel getStartPanel()
           
protected  java.awt.Stroke getStroke()
           
 boolean hit(java.awt.Point attempt)
          Description of the Method
 boolean isBothEndsSelected()
          Determines if both the start and end points are selected
 void load(java.lang.String buffer)
          Loads a segmented line from a buffer
 boolean match(EndPointPanel start, EndPointPanel end)
          Determines whether this panel matches the two desired end points
 void paint(java.awt.Graphics g)
          Draws the segmented line
 void save(java.io.PrintWriter output)
          Saves a segmented to the output stream
protected  void saveEndPanel(java.io.PrintWriter output)
          Saves the end panel
protected  void savePanel(java.io.PrintWriter output, EndPointPanel panel)
          Saves a panel
protected  void saveStartPanel(java.io.PrintWriter output)
          Saves the start panel
protected  void saveVertices(java.io.PrintWriter output)
          Saves the vertices
 void scale(double value)
          Scales the entire line
 void select(boolean way)
          Description of the Method
 void shift(int x, int y)
          Shifts the entire line
protected  void updateEnd()
          Updates the location of the end vertex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vertices

protected Vertex[] vertices
The set of vertices on the line


Xs

protected int[] Xs
This array is used only during the paint method for drawing polylines


Ys

protected int[] Ys
This array is used only during the paint method for drawing polylines


scalingFactor

protected double scalingFactor
Description of the Field

Constructor Detail

SegmentedLine

public SegmentedLine(EndPointPanel start,
                     EndPointPanel end)
Constructor for the SegmentedLine object

Parameters:
start - Panel that the segmented line starts at
end - End point of the panel
Method Detail

isBothEndsSelected

public boolean isBothEndsSelected()
Determines if both the start and end points are selected

Returns:
true when both are selected

getStartPanel

public EndPointPanel getStartPanel()

getEndPanel

public EndPointPanel getEndPanel()

paint

public void paint(java.awt.Graphics g)
Draws the segmented line

Parameters:
g - Description of Parameter

getStroke

protected java.awt.Stroke getStroke()

select

public void select(boolean way)
Description of the Method

Parameters:
way - Description of Parameter

hit

public boolean hit(java.awt.Point attempt)
Description of the Method

Parameters:
attempt - Description of Parameter
Returns:
Description of the Returned Value

drag

public void drag(java.awt.Point point)
Drag the current vertex

Parameters:
point - New location of the current vertex

drop

public void drop()
The point was dropped


componentHidden

public void componentHidden(java.awt.event.ComponentEvent cevt)
Description of the Method

Specified by:
componentHidden in interface java.awt.event.ComponentListener
Parameters:
cevt - Description of Parameter

componentMoved

public void componentMoved(java.awt.event.ComponentEvent cevt)
Description of the Method

Specified by:
componentMoved in interface java.awt.event.ComponentListener
Parameters:
cevt - Description of Parameter

componentResized

public void componentResized(java.awt.event.ComponentEvent cevt)
Description of the Method

Specified by:
componentResized in interface java.awt.event.ComponentListener
Parameters:
cevt - Description of Parameter

componentShown

public void componentShown(java.awt.event.ComponentEvent cevt)
Description of the Method

Specified by:
componentShown in interface java.awt.event.ComponentListener
Parameters:
cevt - Description of Parameter

save

public void save(java.io.PrintWriter output)
Saves a segmented to the output stream

Parameters:
output - the output stream

match

public boolean match(EndPointPanel start,
                     EndPointPanel end)
Determines whether this panel matches the two desired end points

Parameters:
start - the starting panel to be matched
end - the ending panel to be matched
Returns:
true if it matches

load

public void load(java.lang.String buffer)
Loads a segmented line from a buffer

Parameters:
buffer - the buffer containing the vertices

shift

public void shift(int x,
                  int y)
Shifts the entire line

Parameters:
x - the amount to shift in the x coordinate
y - the amount to shift in the y coordinate

scale

public void scale(double value)
Scales the entire line

Parameters:
value - the amount to scale

getShortPoint

protected java.awt.Point getShortPoint()
Determine the point at which the last segment should stop

Returns:
the point

getArrowPointAbove

protected java.awt.Point getArrowPointAbove()
Determine the point at which the last segment should stop

Returns:
the point

getArrowPointBelow

protected java.awt.Point getArrowPointBelow()
Determine the point at which the last segment should stop

Returns:
the point

updateEnd

protected void updateEnd()
Updates the location of the end vertex


getColor

protected java.awt.Color getColor()

drawArrow

protected void drawArrow(java.awt.Graphics2D g)
Draws the arrow and the last segment

Parameters:
g - the graphics object

saveStartPanel

protected void saveStartPanel(java.io.PrintWriter output)
Saves the start panel

Parameters:
output - the output stream

saveEndPanel

protected void saveEndPanel(java.io.PrintWriter output)
Saves the end panel

Parameters:
output - the output stream

savePanel

protected void savePanel(java.io.PrintWriter output,
                         EndPointPanel panel)
Saves a panel

Parameters:
output - the output stream
panel - the panel to be saved

saveVertices

protected void saveVertices(java.io.PrintWriter output)
Saves the vertices

Parameters:
output - the output stream