ilog.views.graphic
Class IlvPolyPoints

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

public abstract class IlvPolyPoints
extends IlvGraphic
implements IlvPolyPointsInterface

IlvPolyPoints is an abstract class for all graphic objects that describe an object bound by several points.

In addition to the standard constructors, the following methods should be overridden to create a customized balloon:

Example

The following code example shows how to create a simple customized IlvPolyPoints class:

   class myPolygon extends IlvPolyPoints {
     
     private Color fill = Color.red;
   
     private Color stroke = Color.blue;
   
     public myPolygon(IlvPoint[] points)
     {
        super(points);
     }
    
     public myPolygon(IlvPoint points[], boolean copy)
     {
       super(points, copy);
     }
    
     public myPolygon(myPolygon source)
     {
       super(source);
     }
   
     public myPolygon(IlvInputStream stream) throws IlvReadFileException
     {
       super(stream);
     }
   
     public IlvGraphic copy()
     {
       return new myPolygon(this);
     }
   
     public void draw(Graphics dst, IlvTransformer t)
     {
       IlvGraphicUtil.FillOutlinedPolygon(dst, getPoints(), getPoints().length, 
                                         fill, stroke, t);
     }
   
     public boolean pointsInBBox()
     {
       return true;
     }
   }
 

The following code example shows how to use the customized IlvPolyPoints in a simple Java application:

   IlvManager manager = new IlvManager();
       
   IlvPoint[] points = new IlvPoint[7];
   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);
   points[6] = new IlvPoint(40f, 40f);
   
   myPolygon polygon = new myPolygon(points, true);
   manager.addObject(polygon, true);
 

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

IlvPolyPoints

About Graphic Objects

IlvPolyPoints 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, Serialized Form

Constructor Summary
IlvPolyPoints(IlvInputStream stream)
          Reads the object from an IlvInputStream.
IlvPolyPoints(IlvPoint[] points)
          Creates a new IlvPolyPoints.
IlvPolyPoints(IlvPoint[] points, boolean copy)
          Creates a new IlvPolyPoints.
IlvPolyPoints(IlvPolyPoints source)
          Creates a new IlvPolyPoints by copying an existing one.
 
Method Summary
 boolean allowsPointInsertion()
          Returns true if the interactors are allowed to add points, and false otherwise.
 boolean allowsPointMove(int index)
          Returns true if the interactors are allowed to move the point with the specified index, and false otherwise.
 boolean allowsPointRemoval()
          Returns true if the interactors are allowed to remove points, and false otherwise.
 void applyTransform(IlvTransformer t)
          Applies the given transformer to this IlvPolyPoints.
 IlvRect boundingBox(IlvTransformer t)
          Returns the bounding rectangle of the object.
protected  void computeBBox(IlvRect bbox)
          Recomputes the bounding rectangle of the object.
 IlvPoint getPointAt(int index, IlvTransformer t)
          Returns the point at the specified index.
protected  IlvPoint[] getPoints()
          Returns the internal array of points.
 int getPointsCardinal()
          Returns the number of points.
 boolean inBBox(IlvPoint p)
          Tests if a point lies inside the bounding box of the object.
 void insertPoint(int index, float x, float y, IlvTransformer t)
          Inserts a point at a specified index.
 boolean intersects(IlvRect rect, IlvRect trect, IlvTransformer t)
          Tests if a rectangle overlaps the object.
 IlvSelection makeSelection()
          Creates the selection object for this class.
 void movePoint(int index, float x, float y, IlvTransformer t)
          Changes the position of a point.
 void recomputeBBox()
          Recomputes the cached bounding rectangle of the object.
 void removePoint(int index, IlvTransformer t)
          Removes a point at a specified index.
 void write(IlvOutputStream stream)
          Writes the object to an IlvOutputStream.
 
Methods inherited from class ilog.views.IlvGraphic
addActionListener, addNamedPropertyListener, boundingBox, contains, copy, draw, getAndAssociateObjectInteractor, getCenter, getDefaultInteractor, getGraphicBag, GetGraphicObject, getIntersectionWithOutline, 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, setBackground, setEditable, setFillOn, setForeground, 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
 
Methods inherited from interface ilog.views.IlvPolyPointsInterface
pointsInBBox
 

Constructor Detail

IlvPolyPoints

public IlvPolyPoints(IlvPoint[] points)
Creates a new IlvPolyPoints. Note that this constructor will copy the array and the points in the array, so you can reuse the same array for other operations.

Parameters:
points - The array of points.

IlvPolyPoints

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

Parameters:
points - The array of points.
copy - If true then the array of points and the points of the first parameter will be copied; otherwise this array will be used by the object and you must not use this array further.

IlvPolyPoints

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

Parameters:
source - The source object.

IlvPolyPoints

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

Parameters:
stream - The input stream.
Throws:
IlvReadFileException - if the format is not correct.
See Also:
write(ilog.views.io.IlvOutputStream)
Method Detail

getPoints

protected IlvPoint[] getPoints()
Returns the internal array of points.


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.

Parameters:
bbox - The rectangle to store the resulting bounding box.

recomputeBBox

public void recomputeBBox()
Recomputes the cached bounding rectangle of the object. You normally do not have to call this method directly.


inBBox

public boolean inBBox(IlvPoint p)
Tests if a point lies inside the bounding box of the object.

Parameters:
p - The point to test.

write

public void write(IlvOutputStream stream)
           throws IOException
Writes the object to an IlvOutputStream. You should not call this method directly; instead, 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.

intersects

public boolean intersects(IlvRect rect,
                          IlvRect trect,
                          IlvTransformer t)
Tests if a rectangle overlaps the object.

Overrides:
intersects in class IlvGraphic
Parameters:
rect - The rectangle to be tested.
trect - The rectangle rect transformed by the transformer t.
t - The transformation that was applied to the object when it was drawn.
Returns:
true if the rectangle overlaps this graphic object.
See Also:
IlvGraphic

boundingBox

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

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

applyTransform

public void applyTransform(IlvTransformer t)
Applies the given transformer to this IlvPolyPoints.

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

getPointAt

public IlvPoint getPointAt(int index,
                           IlvTransformer t)
Returns the point at the specified index.

Specified by:
getPointAt in interface IlvPolyPointsInterface
Parameters:
index - The index of the point.
t - The transformer used to draw the object.
Returns:
The point in transformed coordinates.

getPointsCardinal

public int getPointsCardinal()
Returns the number of points.

Specified by:
getPointsCardinal in interface IlvPolyPointsInterface

allowsPointInsertion

public boolean allowsPointInsertion()
Returns true if the interactors are allowed to add points, and false otherwise.

The default implementation always returns true.

Specified by:
allowsPointInsertion in interface IlvPolyPointsInterface

allowsPointRemoval

public boolean allowsPointRemoval()
Returns true if the interactors are allowed to remove points, and false otherwise.

The default implementation returns true if the current number of points is larger than or equal to 2.

Specified by:
allowsPointRemoval in interface IlvPolyPointsInterface
See Also:
getPointsCardinal()

allowsPointMove

public boolean allowsPointMove(int index)
Returns true if the interactors are allowed to move the point with the specified index, and false otherwise.

The default implementation always returns true.

Specified by:
allowsPointMove in interface IlvPolyPointsInterface
Parameters:
index - The index of the point.
Since:
JViews 5.0

insertPoint

public void insertPoint(int index,
                        float x,
                        float y,
                        IlvTransformer t)
Inserts a point at a specified index. Elements with an index greater than or equal to the current index are shifted up.

Specified by:
insertPoint in interface IlvPolyPointsInterface
Parameters:
index - The index at which the new point will be inserted.
x - The x coordinate of the new point.
y - The y coordinate of the new point.
t - The transformer used to draw the object.

removePoint

public void removePoint(int index,
                        IlvTransformer t)
Removes a point at a specified index.

Specified by:
removePoint in interface IlvPolyPointsInterface
Parameters:
index - The index of the point to be removed.
t - The transformer used to draw the object.

movePoint

public void movePoint(int index,
                      float x,
                      float y,
                      IlvTransformer t)
Changes the position of a point.

Specified by:
movePoint in interface IlvPolyPointsInterface
Parameters:
index - The index of the point to be moved.
x - The new x position in untransformed coordinates.
y - The new y position in untransformed coordinates.
t - The transformer used to draw the object.

makeSelection

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

Overrides:
makeSelection in class IlvGraphic
See Also:
IlvPolyPointsSelection


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