ilog.views.graphic
Class IlvGraphicPath

java.lang.Object
  extended by ilog.views.IlvGraphic
      extended by ilog.views.graphic.IlvGraphicPath
All Implemented Interfaces:
IlvPersistentObject, Transferable, Serializable

public class IlvGraphicPath
extends IlvGraphic

An IlvGraphicPath object is a set of polypoints that can be drawn as a polyline or a polygon.

Overview

The way in which an IlvGraphicPath is presented depends on the DrawRule attribute. This attribute is set to one of the following properties:

The stroke color is set by calling setForeground, the fill color by calling setBackground.

The main differences between an IlvGraphicPath object and a set of IlvPolygon objects are that for IlvGraphicPath:

The default values for an IlvGraphicPath instance are as follows:

Example

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

  IlvPoint[] outer = new IlvPoint[5];
  outer[0] = new IlvPoint(5f, 5f);
  outer[1] = new IlvPoint(60f, 5f);
  outer[2] = new IlvPoint(60f, 60f);
  outer[3] = new IlvPoint(5f, 60f);
  outer[4] = new IlvPoint(5f, 5f);
  
  IlvPoint[] inner = new IlvPoint[5];
  inner[0] = new IlvPoint(10f, 10f);
  inner[1] = new IlvPoint(55f, 10f);
  inner[2] = new IlvPoint(55f, 55f);
  inner[3] = new IlvPoint(10f, 55f);
  inner[4] = new IlvPoint(10f, 10f);
  
  IlvPointArray[] squares = new IlvPointArray[2];
  squares[0] = new IlvPointArray(outer, true);
  squares[1] = new IlvPointArray(inner, true);
  
  IlvGraphicPath sketch = new IlvGraphicPath(squares, true);
  
  sketch.setFillOn(true);
  sketch.setBackground(Color.green);
  sketch.setForeground(Color.red);
  sketch.setDrawRule(IlvGraphicPath.STROKE_AND_FILL);
  
  // Add the graphic object to the manager.
  manager.addObject(sketch,true);
 

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

IlvGraphicPath

About Graphic Objects

IlvGraphicPath 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:
IlvPointArray, IlvPolygon, IlvPolyline, IlvManager, IlvManagerView, IlvRect, Serialized Form

Field Summary
static int FILL_ONLY
          Fill only drawing rule.
static int STROKE_AND_FILL
          Stroke and fill drawing rule.
static int STROKE_ONLY
          Stroke only drawing rule.
 
Constructor Summary
IlvGraphicPath(IlvGraphicPath source)
          Creates a new IlvGraphicPath by copying an existing one.
IlvGraphicPath(IlvInputStream stream)
          Reads the object from an IlvInputStream.
IlvGraphicPath(IlvPoint[] points, boolean copy)
          Creates an IlvGraphicPath containing only one polypoint.
IlvGraphicPath(IlvPointArray[] paths, boolean copy)
          Creates an IlvGraphicPath containing several polypoints.
 
Method Summary
 void applyTransform(IlvTransformer t)
          Applies a transformation to the shape of the object.
 IlvRect boundingBox(IlvTransformer t)
          Returns the bounding rectangle of the object.
 boolean contains(IlvPoint p, IlvPoint tp, IlvTransformer t)
          Tests if a point lies within the shape of the object.
 IlvGraphic copy()
          Copies the object.
 void draw(Graphics dst, IlvTransformer t)
          Draws the object.
 Color getBackground()
          Returns the background color of the object.
 int getDrawRule()
          Returns the DrawRule of the object.
 Color getForeground()
          Returns the foreground color of the object.
 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.
 int getNumPaths()
          Returns the number of IlvPointArray managed by this object.
 IlvPointArray[] getPaths()
          Returns the array of IlvPointArray managed by this object.
 void setBackground(Color c)
          Changes the background color of the object.
 void setDrawRule(int val)
          Changes the DrawRule of the object.
 void setForeground(Color c)
          Changes the foreground color of the object.
 void setPaths(IlvPoint[] points, boolean copy)
          Sets the paths.
 void setPaths(IlvPointArray[] paths, boolean copy)
          Sets the paths.
 void write(IlvOutputStream stream)
          Writes the object to an IlvOutputStream.
 
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, intersects, isDataFlavorSupported, isEditable, isInApplyToObject, isMovable, isPersistent, isSelectable, isVisible, makeSelection, move, move, moveResize, notifyObjectInteractorToManager, processActionEvent, reDraw, removeActionListener, removeNamedProperty, removeNamedPropertyListener, removeProperty, replaceProperty, resize, rotate, scale, setEditable, setFillOn, setGraphicBag, setInApplyToObject, setMovable, setName, setNamedProperty, setNameImpl, setObjectInteractor, setPopupMenu, setPopupMenuName, setProperty, setSelectable, setStrokeOn, setToolTipText, setVisible, toString, translate, zoomable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STROKE_ONLY

public static final int STROKE_ONLY
Stroke only drawing rule.

See Also:
Constant Field Values

FILL_ONLY

public static final int FILL_ONLY
Fill only drawing rule.

See Also:
Constant Field Values

STROKE_AND_FILL

public static final int STROKE_AND_FILL
Stroke and fill drawing rule.

See Also:
Constant Field Values
Constructor Detail

IlvGraphicPath

public IlvGraphicPath(IlvPoint[] points,
                      boolean copy)
Creates an IlvGraphicPath containing only one polypoint.

Parameters:
points - The array of points of the polypoint.
copy - If true, the array of points and the points are copied before being used by the class. If false, the array is internally stored in the object and you must not use the array anymore.

IlvGraphicPath

public IlvGraphicPath(IlvPointArray[] paths,
                      boolean copy)
Creates an IlvGraphicPath containing several polypoints.

Parameters:
paths - The array of polypoints.
copy - If true, the array of polypoints is copied before being used by the class. If false, the array is internally stored in the object and you must not use the array anymore.

IlvGraphicPath

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

Parameters:
source - The copied object.

IlvGraphicPath

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

Parameters:
stream - The input stream.
Throws:
IlvReadFileException - if the format is not correct.
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

setDrawRule

public void setDrawRule(int val)
Changes the DrawRule of the object.

Parameters:
val - Valid values for this parameter are :
  • STROKE_ONLY, where each polypoint is displayed as a polyline using the foreground color.
  • FILL_ONLY, where each polypoint is displayed as a filled polygon using the background color.
  • STROKE_AND_FILL, where each polypoint is displayed as a filled polygon with an outline polyline.
  • See Also:
    getDrawRule()

    getDrawRule

    public int getDrawRule()
    Returns the DrawRule of the object. The return value is one of STROKE_ONLY, FILL_ONLY or STROKE_AND_FILL.

    See Also:
    setDrawRule(int)

    getNumPaths

    public int getNumPaths()
    Returns the number of IlvPointArray managed by this object.


    setPaths

    public void setPaths(IlvPoint[] points,
                         boolean copy)
    Sets the paths.

    Note that changing the paths may change the bounding rectangle. For this reason, if the object is contained inside a manager you should modify the paths using the method IlvManager.applyToObject(IlvGraphic, IlvApplyObject, Object, boolean) of the manager containing the object.

    Parameters:
    points - The array of points of the polypoint.
    copy - If true, the array of points and the points are copied before being used by the class. If false, the array is internally stored in the object and you must not use the array anymore.
    Since:
    JViews 8.1
    See Also:
    setPaths(IlvPointArray[], boolean), getPaths()

    setPaths

    public void setPaths(IlvPointArray[] paths,
                         boolean copy)
    Sets the paths.

    Note that changing the paths may change the bounding rectangle. For this reason, if the object is contained inside a manager you should modify the paths using the method IlvManager.applyToObject(IlvGraphic, IlvApplyObject, Object, boolean) of the manager containing the object.

    Parameters:
    paths - The array of polypoints.
    copy - If true, the array of polypoints is copied before being used by the class. If false, the array is internally stored in the object and you must not use the array anymore.
    Since:
    JViews 8.1
    See Also:
    setPaths(IlvPoint[], boolean), getPaths()

    getPaths

    public IlvPointArray[] getPaths()
    Returns the array of IlvPointArray managed by this object. Note that this method returns the internal array managed by this object, so you should not modify the array.

    See Also:
    setPaths(IlvPoint[], boolean), setPaths(IlvPointArray[], boolean)

    contains

    public boolean contains(IlvPoint p,
                            IlvPoint tp,
                            IlvTransformer t)
    Tests if a point lies within the shape 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.

    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

    boundingBox

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

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

    applyTransform

    public void applyTransform(IlvTransformer t)
    Applies a transformation to the shape of the object.

    Specified by:
    applyTransform in class IlvGraphic
    Parameters:
    t - The transformer to be applied.
    See Also:
    IlvGraphic

    setForeground

    public void setForeground(Color c)
    Changes the foreground color of the object. This color is used to draw the outline of the polygon.

    Overrides:
    setForeground in class IlvGraphic
    Parameters:
    c - The new 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 object. This color is used to draw the outline of the polygon.

    Returns:
    the color of the object.

    setBackground

    public void setBackground(Color c)
    Changes the background color of the object. This color is used to fill the polygon.

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

    getBackground

    public Color getBackground()
    Returns the background color of the object. This color is used to fill the polygon.

    Returns:
    the color of the object.

    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 IlvGraphic
    Parameters:
    stream - The output stream.
    Throws:
    IOException - thrown when an exception occurs during the write operation for this object.


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