ilog.views.graphic
Class IlvSpline

java.lang.Object
  extended by ilog.views.IlvGraphic
      extended by ilog.views.graphic.IlvPolyPoints
          extended by ilog.views.graphic.IlvSpline
All Implemented Interfaces:
IlvPolyPointsInterface, IlvPersistentObject, Transferable, Serializable
Direct Known Subclasses:
IlvClosedSpline

public class IlvSpline
extends IlvPolyPoints

IlvSpline represents a line that displays a Bezier spline.

The default values for an IlvSpline instance are as follows:

Example

The following code example shows how to use IlvSpline in a simple Java application:

   IlvManager manager = new IlvManager();
       
   IlvPoint[] points = new IlvPoint[6];
   points[0] = new IlvPoint(40f, 40f);
   points[1] = new IlvPoint(50f, 20f);
   points[2] = new IlvPoint(90f, 40f);
   points[3] = new IlvPoint(70f, 70f);
   points[4] = new IlvPoint(90f, 90f);
   points[5] = new IlvPoint(40f, 90f);
       
   IlvSpline defaultSpline = new IlvSpline(points, true);
   IlvSpline customSpline = new IlvSpline(points, true);
       
   customSpline.setStrokeOn(true);
   customSpline.setForeground(Color.green);
   customSpline.setLineWidth(5);
   customSpline.setBackground(Color.red);
   customSpline.setFillOn(true);
   customSpline.setClosed(true);
   customSpline.setSmoothness(1f);
       
   customSpline.moveResize(new IlvRect(100,80,40,40));
   IlvPoint center = customSpline.getCenter(new IlvTransformer());
   customSpline.rotate(center, 130);
       
   manager.addObject(defaultSpline, true);
   manager.addObject(customSpline, true);
 

The following image shows the graphic objects created in the code example:

IlvPolyPoints

About Graphic Objects

IlvSpline is a custom graphic object, that is, a subclass of IlvGraphic. Graphic objects are controlled using an instance of IlvManager or one of its subclasses, and displayed using one or more IlvManagerView instances in a Java Swing application. For information about generic features for graphic objects, see IlvGraphic.

See Also:
IlvManager, IlvManagerView, IlvStroke, IlvGraphicUtil, Serialized Form

Constructor Summary
IlvSpline(IlvInputStream stream)
          Reads the object from an IlvInputStream.
IlvSpline(IlvPoint[] points)
          Creates a new spline.
IlvSpline(IlvPoint[] points, boolean copy)
          Creates a new IlvSpline.
IlvSpline(IlvPoint[] points, boolean copy, boolean closed)
          Creates a new IlvSpline.
IlvSpline(IlvSpline source)
          Creates a new spline by copying an existing one.
 
Method Summary
 IlvRect boundingBox(IlvTransformer t)
          Returns the bounding rectangle of the object.
protected  void computeBBox(IlvRect bbox)
          Recomputes the bounding rectangle of the object.
 boolean contains(IlvPoint p, IlvPoint tp, IlvTransformer t)
          Tests if a point lies within the outline of the object.
 IlvGraphic copy()
          Copies the object.
 void draw(Graphics dst, IlvTransformer t)
          Draws the object.
protected  void finalize()
          Overrides the method to clean some resources.
 Color getBackground()
          Returns the color of the IlvSpline.
 int getEndCap()
          Returns the decoration applied at the end of the polyline.
 Color getForeground()
          Returns the foreground color of the spline.
 IlvPoint getIntersectionWithOutline(IlvPoint innerPoint, IlvPoint outerPoint, IlvTransformer t)
          Returns the intersection of the line segment from inner point to outer point with the shape of the graphic object.
 float[] getLineStyle()
          Returns the array representing the lengths of the dash segments.
 float getLineWidth()
          Returns the line width of the object.
 float getLineWidth(IlvTransformer t)
          Returns the line width that is displayed when the object is drawn with the specified transformer.
 float getMaximumLineWidth()
          Returns the maximum line width of the spline.
 float getSmoothness()
          Returns the smoothness of the spline.
 boolean isClosed()
          Returns true if the spline is closed.
 boolean isFillOn()
          Returns true if the inside of the spline will be filled.
 boolean isStrokeOn()
          Returns true if the spline is stroked.
 IlvSelection makeSelection()
          Creates the selection object for this class.
 boolean pointsInBBox()
          Returns false since all points are not contained inside the bounding rectangle of the object.
 void setBackground(Color color)
          Changes the background color of the IlvSpline.
 void setClosed(boolean set)
          When set to true, specifies that the spline is closed.
 void setEndCap(int endCap)
          Changes the decoration applied at the end of the polyline.
 void setFillOn(boolean set)
          If true, specifies that the inside of the spline will be filled.
 void setForeground(Color c)
          Changes the foreground color of the spline.
 void setLineStyle(float[] lineStyle)
          Changes the array representing the lengths of the dash segments.
 void setLineWidth(float lineWidth)
          Changes the line width of the object.
 void setMaximumLineWidth(float maximumLineWidth)
          Changes the maximum line width of the spline.
 void setSmoothness(float smoothness)
          Sets the smoothness of the spline.
 void setStrokeOn(boolean set)
          When set to true, specifies that the spline is stroked.
 void write(IlvOutputStream stream)
          Writes the object to an IlvOutputStream.
 
Methods inherited from class ilog.views.graphic.IlvPolyPoints
allowsPointInsertion, allowsPointMove, allowsPointRemoval, applyTransform, getPointAt, getPoints, getPointsCardinal, inBBox, insertPoint, intersects, movePoint, recomputeBBox, removePoint
 
Methods inherited from class ilog.views.IlvGraphic
addActionListener, addNamedPropertyListener, boundingBox, getAndAssociateObjectInteractor, getCenter, getDefaultInteractor, getGraphicBag, GetGraphicObject, getName, getNamedProperty, getObjectInteractor, getPopupMenu, getPopupMenu, getPopupMenuName, getProperty, getToolTipText, getToolTipText, getTopLevelGraphicBag, getTransferData, getTransferDataFlavors, hasProperty, inside, isDataFlavorSupported, isEditable, isInApplyToObject, isMovable, isPersistent, isSelectable, isVisible, move, move, moveResize, notifyObjectInteractorToManager, processActionEvent, reDraw, removeActionListener, removeNamedProperty, removeNamedPropertyListener, removeProperty, replaceProperty, resize, rotate, scale, setEditable, setGraphicBag, setInApplyToObject, setMovable, setName, setNamedProperty, setNameImpl, setObjectInteractor, setPopupMenu, setPopupMenuName, setProperty, setSelectable, setToolTipText, setVisible, toString, translate, zoomable
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IlvSpline

public IlvSpline(IlvPoint[] points)
Creates a new spline.

Parameters:
points - The control points of the spline. This array and the points will be copied by the constructor.

IlvSpline

public IlvSpline(IlvPoint[] points,
                 boolean copy)
Creates a new IlvSpline.

Parameters:
points - The array of points.
copy - If true, the array of points and its points of the first parameter will be copied. Otherwise this array will be used by the object and you must not use this array anymore.

IlvSpline

public IlvSpline(IlvPoint[] points,
                 boolean copy,
                 boolean closed)
Creates a new IlvSpline.

Parameters:
points - The array of points.
closed - true if the spline has to be closed.
copy - If true, the array of points and its points of the first parameter will be copied. Otherwise this array will be used by the object and you must not use this array anymore.
Since:
JViews 5.5

IlvSpline

public IlvSpline(IlvSpline source)
Creates a new spline by copying an existing one.


IlvSpline

public IlvSpline(IlvInputStream stream)
          throws IlvReadFileException
Reads the object from an IlvInputStream.

Parameters:
stream - The input stream.
Throws:
IlvReadFileException - if the format is not correct.
IlvReadFileException
Method Detail

copy

public IlvGraphic copy()
Copies the object. This method copies the object by calling the copy constructor.

Specified by:
copy in class IlvGraphic
Returns:
A copy of the object.
See Also:
IlvGraphic

computeBBox

protected void computeBBox(IlvRect bbox)
Recomputes the bounding rectangle of the object. This method is called when the points change. You normally do not have to call this method directly.

Overrides:
computeBBox in class IlvPolyPoints
Parameters:
bbox - The rectangle to store the resulting bounding box.

pointsInBBox

public boolean pointsInBBox()
Returns false since all points are not contained inside the bounding rectangle of the object.


boundingBox

public IlvRect boundingBox(IlvTransformer t)
Returns the bounding rectangle of the object.

Specified by:
boundingBox in interface IlvPolyPointsInterface
Overrides:
boundingBox in class IlvPolyPoints
Parameters:
t - The transformer used to draw the object.
Returns:
The bounding rectangle of the object in transformed coordinates.
See Also:
IlvGraphic.draw(java.awt.Graphics, ilog.views.IlvTransformer), IlvGraphic.zoomable(), IlvGraphic

contains

public boolean contains(IlvPoint p,
                        IlvPoint tp,
                        IlvTransformer t)
Tests if a point lies within the outline of the object.

Overrides:
contains in class IlvGraphic
Parameters:
p - The point to be tested.
tp - The point p transformed by the transformer t.
t - The transformation that was applied to the object when it was drawn.
Returns:
true if the point lies inside this graphic object.
See Also:
IlvGraphic

getIntersectionWithOutline

public IlvPoint getIntersectionWithOutline(IlvPoint innerPoint,
                                           IlvPoint outerPoint,
                                           IlvTransformer t)
Returns the intersection of the line segment from inner point to outer point with the shape of the graphic object. This method is used the clip links against the shape of the node. The implementation of this method must be robust with respect to the input points: Even if innerPoint is not inside the graphic object, or if outerPoint is not outside the graphic object, it must return a valid point. For instance, if there is no intersection, it can return the start point.

This implementation calculates the precise intersection if the spline smoothness is not IlvGraphicUtil.COMPATIBLE_SMOOTHNESS and the line width is small. If the line width is very large, rounding errors will become visible.

Overrides:
getIntersectionWithOutline in class IlvGraphic
Parameters:
innerPoint - A point usually inside the graphic object, given in manager view coordinates.
outerPoint - A point usually outside of the graphic object, given in manager view coordinates.
t - The transformation used to draw the object.
Since:
JViews 8.1
See Also:
IlvClippingLinkConnector

draw

public void draw(Graphics dst,
                 IlvTransformer t)
Draws the object.

Specified by:
draw in class IlvGraphic
Parameters:
dst - The destination Graphics.
t - The transformation used to draw the object.
See Also:
IlvGraphic.boundingBox(ilog.views.IlvTransformer), IlvGraphic.zoomable(), IlvGraphic

makeSelection

public IlvSelection makeSelection()
Creates the selection object for this class. The default implementation creates an instance of IlvSplineSelection.

Overrides:
makeSelection in class IlvPolyPoints
See Also:
IlvSplineSelection

setForeground

public void setForeground(Color c)
Changes the foreground color of the spline. It is the color used to draw the spline.

Overrides:
setForeground in class IlvGraphic
Parameters:
c - The new foreground color.
See Also:
IlvGraphic.draw(Graphics, IlvTransformer), IlvGraphic.setBackground(Color), IlvGraphic.setFillOn(boolean), IlvGraphic.setStrokeOn(boolean), IlvGraphic

getForeground

public Color getForeground()
Returns the foreground color of the spline. It is the color used to draw the spline.


setBackground

public void setBackground(Color color)
Changes the background color of the IlvSpline. It is the color used to fill the spline.

Overrides:
setBackground in class IlvGraphic
Parameters:
color - The new background color.
Since:
JViews 5.5
See Also:
IlvGraphic.draw(Graphics, IlvTransformer), IlvGraphic.setForeground(Color), IlvGraphic.setFillOn(boolean), IlvGraphic.setStrokeOn(boolean), IlvGraphic

getBackground

public Color getBackground()
Returns the color of the IlvSpline. It is the color used to fill the spline.

Since:
JViews 5.5

isFillOn

public boolean isFillOn()
Returns true if the inside of the spline will be filled.

Since:
JViews 5.5
See Also:
setFillOn(boolean)

setFillOn

public void setFillOn(boolean set)
If true, specifies that the inside of the spline will be filled.

Overrides:
setFillOn in class IlvGraphic
Parameters:
set - Set to true to enable the fill style for this graphic object.
Since:
JViews 5.5
See Also:
isFillOn()

isStrokeOn

public boolean isStrokeOn()
Returns true if the spline is stroked.

Since:
JViews 5.5
See Also:
setStrokeOn(boolean)

setStrokeOn

public void setStrokeOn(boolean set)
When set to true, specifies that the spline is stroked.

Overrides:
setStrokeOn in class IlvGraphic
Parameters:
set - Set to true to enable the stroke in your customized graphic object.
Since:
JViews 5.5
See Also:
isStrokeOn()

setClosed

public void setClosed(boolean set)
When set to true, specifies that the spline is closed.

Since:
JViews 5.5

isClosed

public boolean isClosed()
Returns true if the spline is closed.

Since:
JViews 5.5

getLineWidth

public float getLineWidth()
Returns the line width of the object. The default value is 0.


setLineWidth

public void setLineWidth(float lineWidth)
Changes the line width of the object.

Parameters:
lineWidth - The new line width.

getLineWidth

public float getLineWidth(IlvTransformer t)
Returns the line width that is displayed when the object is drawn with the specified transformer.

Parameters:
t - The transformer used to draw the object.

getEndCap

public int getEndCap()
Returns the decoration applied at the end of the polyline. The values are defined in the class IlvStroke. The default value is CAP_SQUARE.

See Also:
IlvStroke

setEndCap

public void setEndCap(int endCap)
Changes the decoration applied at the end of the polyline.

Parameters:
endCap - The new decoration style. The values are defined in the class IlvStroke. The default value is CAP_SQUARE.
See Also:
IlvStroke

getMaximumLineWidth

public float getMaximumLineWidth()
Returns the maximum line width of the spline. If the maximum line width is specified and not equal to zero, then the width of the spline will stop zooming when the maximum line width is reached.


setMaximumLineWidth

public void setMaximumLineWidth(float maximumLineWidth)
Changes the maximum line width of the spline. If the maximum line width is specified and not equal to zero, then the width of the spline will stop zooming when the maximum line width is reached. A value of zero means that there is no limit.


getLineStyle

public float[] getLineStyle()
Returns the array representing the lengths of the dash segments. Alternate entries in the array represent the user space lengths of the opaque and transparent segments of the dashes.


setLineStyle

public void setLineStyle(float[] lineStyle)
Changes the array representing the lengths of the dash segments. Alternate entries in the array represent the user space lengths of the opaque and transparent segments of the dashes.


setSmoothness

public void setSmoothness(float smoothness)
Sets the smoothness of the spline. The value range is between 0.0 (sharp bends) and 1.0 (smooth bends). A recommended value is 0.65.

A special value IlvGraphicUtil.AUTO_SMOOTHNESS can be set to use an algorithm that automatically detects an appropriate smoothness for each bend.

The default value is IlvGraphicUtil.COMPATIBLE_SMOOTHNESS. With this value, a spline looks exactly as in JViews 3.0, that is, a spline with more than two bends (four control points) will not look smooth.

Changing the smoothness influences the bounding box of the object. Therefore it should only be done using an IlvApplyObject passed to IlvManager.applyToObject(ilog.views.IlvGraphic, ilog.views.IlvApplyObject, java.lang.Object, boolean).

Parameters:
smoothness - The smoothness.
Since:
JViews 3.5
See Also:
getSmoothness()

getSmoothness

public float getSmoothness()
Returns the smoothness of the spline.

Since:
JViews 3.5
See Also:
setSmoothness(float)

write

public void write(IlvOutputStream stream)
           throws IOException
Writes the object to an IlvOutputStream. Note that even if this is a public method, you should not call it directly. You should use the write methods of the manager.

Specified by:
write in interface IlvPersistentObject
Overrides:
write in class IlvPolyPoints
Parameters:
stream - The output stream.
Throws:
IOException - thrown when an exception occurs during the write operation for this object.

finalize

protected void finalize()
                 throws Throwable
Overrides the method to clean some resources.

Overrides:
finalize in class Object
Throws:
Throwable


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.