org.openbp.cockpit.modeler.figures.spline
Class PolySplineFigure

java.lang.Object
  extended by CH.ifa.draw.standard.AbstractFigure
      extended by org.openbp.cockpit.modeler.figures.spline.PolySplineFigure
All Implemented Interfaces:
CH.ifa.draw.framework.Figure, CH.ifa.draw.util.Storable, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
PolySplineConnection

public class PolySplineFigure
extends CH.ifa.draw.standard.AbstractFigure

A poly spline figure is a line figure consisting of an arbitary number of cubic Bezier curves. It has handles for all waypoints as well as for each control point. A waypoint can have three different states:
A corner means that both control points are completely independent of each other.
A curve means that both control points are on opposite angles but may have a different distance.
An even curve means that one control point is the direct mirror of its counterpart.

Author:
Stephan Moritz
See Also:
Serialized Form

Field Summary
protected  boolean drawDecorations
          Only draw decorations if this is true
static int LEFT_CONTROLPOINT
           
static int RIGHT_CONTROLPOINT
           
protected  java.util.List segments
          Contains the actual curve segements (contains CubicCurve2D objects)
 
Fields inherited from interface CH.ifa.draw.framework.Figure
POPUP_MENU
 
Constructor Summary
PolySplineFigure()
          Constructor.
 
Method Summary
protected  void adjustOpposite(int index, int side)
           
 void basicDisplayBox(java.awt.Point origin, java.awt.Point corner)
           
protected  void basicMoveBy(int dx, int dy)
           
protected  void basicSetCtrlPoint(int index, int side, java.awt.geom.Point2D target)
           
 boolean canConnect()
          Spline figures cannot be connected and return false.
protected  void clearShapeCache()
          Clears the shape cache used for hit detection.
 CH.ifa.draw.framework.Connector connectorAt(int x, int y)
           
protected  java.awt.geom.Point2D constrainCtrlPoint(int index, int side, java.awt.geom.Point2D target)
           
 boolean containsPoint(int x, int y)
          Returns true if the given point is near to the spline.
 java.awt.Rectangle displayBox()
          The display box equals the bounds of the spline enlarged by 30 pixels vertically and horizontally.
 void draw(java.awt.Graphics g)
           
protected  void drawDecorations(java.awt.Graphics g)
          Draws the start and end decorations of the spline.
protected  void drawSpline(java.awt.Graphics2D g2)
          Draws the spline itself.
 int findSegment(int x, int y)
          Gets the segment of the polyline that is hit by the given point.
 CH.ifa.draw.figures.LineDecoration getAnimationDecoration()
          Gets the decoration for the spline animation.
 java.lang.Object getAttribute(java.lang.String name)
          Gets the attribute with the given name.
 java.awt.geom.Point2D getCtrlPointAt(int i, int side)
           
 CH.ifa.draw.figures.LineDecoration getEndDecoration()
          Gets the decoration for the end point of the spline.
 java.awt.Color getFrameColor()
          Gets the color of the spline.
 java.awt.geom.Point2D getPointAt(int i)
           
protected  java.awt.geom.Point2D getPointOnCurve(double position)
          Determines a point on the spline, specified by a ratio.
 java.awt.Rectangle getSplineBounds()
          Gets the display box of the spline's segments.
 CH.ifa.draw.figures.LineDecoration getStartDecoration()
          Gets the decoration for the start point of the spline.
 java.awt.Stroke getStroke()
          Gets the stroke.
 java.util.Vector handles()
           
 boolean isEmpty()
           
 boolean joinSegments(int x, int y)
          Joins to segments into one if the given point hits a node of the polyline.
 java.awt.Point pointAt(int i)
           
 int pointCount()
           
 void read(CH.ifa.draw.util.StorableInput dr)
           
protected  void rebuildShapeCache()
          Rebuilds the shape cache used for hit detection.
 void removePoint(int i)
           
 java.awt.geom.CubicCurve2D segmentAt(int i)
          Gets the segment at the given index.
 void setAnimationDecoration(CH.ifa.draw.figures.LineDecoration animationDecoration)
          Sets the decoration for the spline animation.
 void setAttribute(java.lang.String name, java.lang.Object value)
          Sets the attribute with the given name.
 void setCtrlPointAt(int index, int side, java.awt.geom.Point2D target)
           
 void setDrawDecorations(boolean drawDecorations)
          Sets the flag if decorations should be drawn.
 void setEndDecoration(CH.ifa.draw.figures.LineDecoration endDecoration)
          Sets the decoration for the end point of the spline.
 void setFrameColor(java.awt.Color frameColor)
          Sets the color of the spline.
 void setPointAt(int index, java.awt.geom.Point2D target)
           
 void setStartDecoration(CH.ifa.draw.figures.LineDecoration startDecoration)
          Sets the decoration for the start point of the spline.
 void setStroke(java.awt.Stroke stroke)
          Sets the stroke.
 int splitSegment(int x, int y)
          Splits the segment at the given point if a segment was hit.
 void write(CH.ifa.draw.util.StorableOutput dw)
           
 
Methods inherited from class CH.ifa.draw.standard.AbstractFigure
addFigureChangeListener, addToContainer, center, changed, clone, connectedTextLocator, connectionInsets, connectorVisibility, decompose, displayBox, displayBox, figures, findFigureInside, getZValue, includes, invalidate, listener, moveBy, release, removeFigureChangeListener, removeFromContainer, setZValue, size, willChange
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEFT_CONTROLPOINT

public static final int LEFT_CONTROLPOINT
See Also:
Constant Field Values

RIGHT_CONTROLPOINT

public static final int RIGHT_CONTROLPOINT
See Also:
Constant Field Values

segments

protected java.util.List segments
Contains the actual curve segements (contains CubicCurve2D objects)


drawDecorations

protected boolean drawDecorations
Only draw decorations if this is true

Constructor Detail

PolySplineFigure

public PolySplineFigure()
Constructor.

Method Detail

displayBox

public java.awt.Rectangle displayBox()
The display box equals the bounds of the spline enlarged by 30 pixels vertically and horizontally.

Specified by:
displayBox in interface CH.ifa.draw.framework.Figure
Specified by:
displayBox in class CH.ifa.draw.standard.AbstractFigure
See Also:
AbstractFigure.displayBox()

basicDisplayBox

public void basicDisplayBox(java.awt.Point origin,
                            java.awt.Point corner)
Specified by:
basicDisplayBox in interface CH.ifa.draw.framework.Figure
Specified by:
basicDisplayBox in class CH.ifa.draw.standard.AbstractFigure
See Also:
AbstractFigure.basicDisplayBox(Point origin, Point corner)

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface CH.ifa.draw.framework.Figure
Overrides:
isEmpty in class CH.ifa.draw.standard.AbstractFigure
See Also:
AbstractFigure.isEmpty()

handles

public java.util.Vector handles()
Specified by:
handles in interface CH.ifa.draw.framework.Figure
Specified by:
handles in class CH.ifa.draw.standard.AbstractFigure
See Also:
AbstractFigure.handles()

containsPoint

public boolean containsPoint(int x,
                             int y)
Returns true if the given point is near to the spline.

Specified by:
containsPoint in interface CH.ifa.draw.framework.Figure
Overrides:
containsPoint in class CH.ifa.draw.standard.AbstractFigure
See Also:
AbstractFigure.containsPoint(int x, int y)

canConnect

public boolean canConnect()
Spline figures cannot be connected and return false.

Specified by:
canConnect in interface CH.ifa.draw.framework.Figure
Overrides:
canConnect in class CH.ifa.draw.standard.AbstractFigure
See Also:
AbstractFigure.canConnect()

connectorAt

public CH.ifa.draw.framework.Connector connectorAt(int x,
                                                   int y)
Specified by:
connectorAt in interface CH.ifa.draw.framework.Figure
Overrides:
connectorAt in class CH.ifa.draw.standard.AbstractFigure
See Also:
AbstractFigure.connectorAt(int x, int y)

basicMoveBy

protected void basicMoveBy(int dx,
                           int dy)
Specified by:
basicMoveBy in class CH.ifa.draw.standard.AbstractFigure
See Also:
AbstractFigure.basicMoveBy(int dx, int dy)

draw

public void draw(java.awt.Graphics g)
Specified by:
draw in interface CH.ifa.draw.framework.Figure
Specified by:
draw in class CH.ifa.draw.standard.AbstractFigure
See Also:
AbstractFigure.draw(Graphics g)

drawSpline

protected void drawSpline(java.awt.Graphics2D g2)
Draws the spline itself.

Parameters:
g2 - Graphics to draw to

getSplineBounds

public java.awt.Rectangle getSplineBounds()
Gets the display box of the spline's segments.


adjustOpposite

protected void adjustOpposite(int index,
                              int side)

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Gets the attribute with the given name. Maps the "ArrowMode" attribute to a line decoration.

Specified by:
getAttribute in interface CH.ifa.draw.framework.Figure
Overrides:
getAttribute in class CH.ifa.draw.standard.AbstractFigure

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Sets the attribute with the given name. Interprets the "ArrowMode" attribute to set the line decoration.

Specified by:
setAttribute in interface CH.ifa.draw.framework.Figure
Overrides:
setAttribute in class CH.ifa.draw.standard.AbstractFigure

pointCount

public int pointCount()

pointAt

public java.awt.Point pointAt(int i)

getPointAt

public java.awt.geom.Point2D getPointAt(int i)

getCtrlPointAt

public java.awt.geom.Point2D getCtrlPointAt(int i,
                                            int side)

setPointAt

public void setPointAt(int index,
                       java.awt.geom.Point2D target)

setCtrlPointAt

public void setCtrlPointAt(int index,
                           int side,
                           java.awt.geom.Point2D target)

basicSetCtrlPoint

protected void basicSetCtrlPoint(int index,
                                 int side,
                                 java.awt.geom.Point2D target)

removePoint

public void removePoint(int i)

constrainCtrlPoint

protected java.awt.geom.Point2D constrainCtrlPoint(int index,
                                                   int side,
                                                   java.awt.geom.Point2D target)

getPointOnCurve

protected java.awt.geom.Point2D getPointOnCurve(double position)
Determines a point on the spline, specified by a ratio.

Parameters:
position - Ratio that determines the postion on the spline, ranging from 0 (startpoint) to 1 (endpoint)
Returns:
The (modified) 'over' argument or a new point if null

segmentAt

public java.awt.geom.CubicCurve2D segmentAt(int i)
Gets the segment at the given index.

Parameters:
i - Index
Returns:
The segment

findSegment

public int findSegment(int x,
                       int y)
Gets the segment of the polyline that is hit by the given point.

Parameters:
x - Document coordinate
y - Document coordinate
Returns:
the index of the segment or -1 if no segment was hit

rebuildShapeCache

protected void rebuildShapeCache()
Rebuilds the shape cache used for hit detection.


clearShapeCache

protected void clearShapeCache()
Clears the shape cache used for hit detection.


splitSegment

public int splitSegment(int x,
                        int y)
Splits the segment at the given point if a segment was hit.

Parameters:
x - Document coordinate
y - Document coordinate
Returns:
Index of the segment or -1 if no segment was hit

joinSegments

public boolean joinSegments(int x,
                            int y)
Joins to segments into one if the given point hits a node of the polyline.

Parameters:
x - Document coordinate
y - Document coordinate
Returns:
true: If the two segments were joined
false: Otherwise

drawDecorations

protected void drawDecorations(java.awt.Graphics g)
Draws the start and end decorations of the spline.

Parameters:
g - Graphics to draw to

getStartDecoration

public CH.ifa.draw.figures.LineDecoration getStartDecoration()
Gets the decoration for the start point of the spline.


setStartDecoration

public void setStartDecoration(CH.ifa.draw.figures.LineDecoration startDecoration)
Sets the decoration for the start point of the spline.


getEndDecoration

public CH.ifa.draw.figures.LineDecoration getEndDecoration()
Gets the decoration for the end point of the spline.


setEndDecoration

public void setEndDecoration(CH.ifa.draw.figures.LineDecoration endDecoration)
Sets the decoration for the end point of the spline.


getAnimationDecoration

public CH.ifa.draw.figures.LineDecoration getAnimationDecoration()
Gets the decoration for the spline animation.


setAnimationDecoration

public void setAnimationDecoration(CH.ifa.draw.figures.LineDecoration animationDecoration)
Sets the decoration for the spline animation.


setDrawDecorations

public void setDrawDecorations(boolean drawDecorations)
Sets the flag if decorations should be drawn.


getFrameColor

public java.awt.Color getFrameColor()
Gets the color of the spline.


setFrameColor

public void setFrameColor(java.awt.Color frameColor)
Sets the color of the spline.


getStroke

public java.awt.Stroke getStroke()
Gets the stroke.


setStroke

public void setStroke(java.awt.Stroke stroke)
Sets the stroke.


write

public void write(CH.ifa.draw.util.StorableOutput dw)
Specified by:
write in interface CH.ifa.draw.util.Storable
Overrides:
write in class CH.ifa.draw.standard.AbstractFigure

read

public void read(CH.ifa.draw.util.StorableInput dr)
          throws java.io.IOException
Specified by:
read in interface CH.ifa.draw.util.Storable
Overrides:
read in class CH.ifa.draw.standard.AbstractFigure
Throws:
java.io.IOException
See Also:
AbstractFigure.read(StorableInput dr)


Copyright © 2011. All Rights Reserved.