ilog.views.graphic
Class IlvRectangle

java.lang.Object
  extended by ilog.views.IlvGraphic
      extended by ilog.views.graphic.IlvRectangle
All Implemented Interfaces:
IlvPersistentObject, Transferable, Serializable
Direct Known Subclasses:
IlvFilledRectangle, IlvReliefRectangle, IlvRoundRectangle, IlvShadowRectangle

public class IlvRectangle
extends IlvGraphic

IlvRectangle represents a rectangle with customizable fill and stroke. You can set the corners to be rounded or square.

The default values for an IlvRectangle instance are as follows:

Example

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

   IlvManager manager = new IlvManager();
   IlvRectangle myDefaultRect = new IlvRectangle();
   IlvRectangle myCustomRect = new IlvRectangle(new IlvRect(120,100,80,20), true, true);
   myCustomRect.setForeground(Color.black);
   myCustomRect.setBackground(Color.green);
   int topCorners = IlvRectangle.TOP_LEFT|IlvRectangle.TOP_RIGHT;
   myCustomRect.setCorners(topCorners);
   
   manager.addObject( myDefaultRect, true);
   manager.addObject( myCustomRect, true);
 

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

IlvRectangle

About Graphic Objects

IlvRectangle is a custom graphic object, that is, a subclass of IlvGraphic. Graphic objects are controlled using an IlvManager instance 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:
IlvPoint, IlvManager, IlvManagerView, Serialized Form

Field Summary
static int BOTTOM_LEFT
          Defines the bottom left corner.
static int BOTTOM_RIGHT
          Defines the bottom right corner.
protected  IlvRect drawrect
          The definition rectangle of the object.
static int TOP_LEFT
          Defines the top left corner.
static int TOP_RIGHT
          Defines the top right corner.
 
Constructor Summary
IlvRectangle()
          Creates a new IlvRectangle with a definition rectangle of (0, 0, 100, 100)
IlvRectangle(IlvInputStream stream)
          Reads the object from an IlvInputStream.
IlvRectangle(IlvRect rect)
          Creates a new IlvRectangle.
IlvRectangle(IlvRectangle source)
          Creates a new IlvRectangle by copying an existing one.
IlvRectangle(IlvRect rect, boolean outlined, boolean filled)
          Creates a new IlvRectangle.
IlvRectangle(IlvRect rect, boolean outlined, boolean filled, int radius)
          Creates a new IlvRectangle with rounded corners.
 
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 outline 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 IlvRectangle.
 int getCorners()
          Returns which corners of the rectangle are rounded if getRadius() is not 0.
 IlvRect getDefinitionRect()
          Returns a copy of the definition rectangle.
 Color getForeground()
          Returns the foreground color of the IlvRectangle.
 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 getRadius()
          Returns the radius.
 boolean isCornersZoomable()
          Returns true if the radius of the rounded corners follows the zoom level.
 boolean isFillOn()
          Returns true if the inside of the rectangle will be filled.
 boolean isStrokeOn()
          Returns true if the rectangle is stroked.
 void moveResize(IlvRect size)
          Resizes the object.
 void setBackground(Color color)
          Changes the background color of the IlvRectangle.
 void setCorners(int corners)
          Sets which corners of the rectangle are rounded if getRadius() is not 0.
 void setCornersZoomable(boolean set)
          When set to true, specifies that the radius of the rounded corners follows the zoom level.
 void setDefinitionRect(IlvRect rect)
          Sets the definition rectangle.
 void setFillOn(boolean set)
          If true, specifies that the inside of the rectangle will be filled.
 void setForeground(Color color)
          Changes the foreground color of the IlvRectangle.
 void setRadius(int radius)
          Changes the radius.
 void setStrokeOn(boolean set)
          When set to true, specifies that the rectangle is stroked.
 void translate(float dx, float dy)
          Translates the object.
 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, 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, zoomable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TOP_LEFT

public static final int TOP_LEFT
Defines the top left corner.

Since:
JViews 6.0
See Also:
setCorners(int), Constant Field Values

BOTTOM_LEFT

public static final int BOTTOM_LEFT
Defines the bottom left corner.

Since:
JViews 6.0
See Also:
setCorners(int), Constant Field Values

TOP_RIGHT

public static final int TOP_RIGHT
Defines the top right corner.

Since:
JViews 6.0
See Also:
setCorners(int), Constant Field Values

BOTTOM_RIGHT

public static final int BOTTOM_RIGHT
Defines the bottom right corner.

Since:
JViews 6.0
See Also:
setCorners(int), Constant Field Values

drawrect

protected final IlvRect drawrect
The definition rectangle of the object.

Constructor Detail

IlvRectangle

public IlvRectangle()
Creates a new IlvRectangle with a definition rectangle of (0, 0, 100, 100)

Since:
JViews 6.0
See Also:
IlvRectangle(IlvRect)

IlvRectangle

public IlvRectangle(IlvRect rect)
Creates a new IlvRectangle. The IlvRectangle is outlined but not filled.

Parameters:
rect - The definition rectangle of the object.

IlvRectangle

public IlvRectangle(IlvRect rect,
                    boolean outlined,
                    boolean filled)
Creates a new IlvRectangle.

Parameters:
rect - The definition rectangle of the object.
outlined - true if the rectangle has to be stroked.
filled - true if the rectangle has to be filled.
Since:
JViews 5.5
See Also:
setStrokeOn(boolean), setFillOn(boolean)

IlvRectangle

public IlvRectangle(IlvRect rect,
                    boolean outlined,
                    boolean filled,
                    int radius)
Creates a new IlvRectangle with rounded corners.

Parameters:
rect - The definition rectangle of the object.
outlined - true if the rectangle has to be stroked.
filled - true if the rectangle has to be filled.
radius - The radius of the rectangle corners.
Since:
JViews 5.5
See Also:
setStrokeOn(boolean), setFillOn(boolean), setRadius(int)

IlvRectangle

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

Parameters:
source - The origin object for the copy.

IlvRectangle

public IlvRectangle(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

getDefinitionRect

public final IlvRect getDefinitionRect()
Returns a copy of the definition rectangle.

Returns:
definition rectangle

setDefinitionRect

public void setDefinitionRect(IlvRect rect)
Sets the definition rectangle. The definition rectangle defines the position and size of the object. The effect is similar to calling moveResize(ilog.views.IlvRect). This method is here to follow the Beaninfo naming standard.

Since:
JViews 8.0

moveResize

public void moveResize(IlvRect size)
Resizes the object. The method sets the bounding rectangle of the object to the IlvRect parameter. This method calls the setDefinitionRect method.

Overrides:
moveResize in class IlvGraphic
Parameters:
size - The new bounding rectangle of the object.
See Also:
IlvGraphic, IlvGraphic.applyTransform(IlvTransformer)

translate

public void translate(float dx,
                      float dy)
Translates the object. Translates the bounding rectangle of the object by the vector (dx, dy).

Overrides:
translate in class IlvGraphic
Parameters:
dx - The horizontal translation factor.
dy - The vertical translation factor.
See Also:
IlvGraphic, IlvGraphic.applyTransform(IlvTransformer)

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

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

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.

Note that the method must never be called with a null argument.

Specified by:
applyTransform in class IlvGraphic
Parameters:
t - The transformer to be applied.
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

setForeground

public void setForeground(Color color)
Changes the foreground color of the IlvRectangle. It is the color used to draw the outline of the rectangle.

Overrides:
setForeground in class IlvGraphic
Parameters:
color - 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 IlvRectangle. It is the color used to draw the outline of the rectangle.

Returns:
The foreground color.

setBackground

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

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 background color of the IlvRectangle. It is the color used to fill the rectangle.

Returns:
The background color.
Since:
JViews 5.5

setRadius

public void setRadius(int radius)
Changes the radius.

Parameters:
radius - The new radius.
Since:
JViews 5.5
See Also:
getRadius(), getCorners(), setCornersZoomable(boolean)

getRadius

public int getRadius()
Returns the radius.

Returns:
The radius.
Since:
JViews 5.5
See Also:
setRadius(int)

isFillOn

public boolean isFillOn()
Returns true if the inside of the rectangle 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 rectangle 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 rectangle is stroked.

Since:
JViews 5.5
See Also:
setStrokeOn(boolean)

setStrokeOn

public void setStrokeOn(boolean set)
When set to true, specifies that the rectangle 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()

getCorners

public int getCorners()
Returns which corners of the rectangle are rounded if getRadius() is not 0. The default value is all the corners, that is, a combination of all the possible values described below.

Returns:
A combination of the following values:
Since:
JViews 6.0
See Also:
setCorners(int)

setCorners

public void setCorners(int corners)
Sets which corners of the rectangle are rounded if getRadius() is not 0. The default value is all the corners, that is, a combination of all the possible values described below.

Parameters:
corners - A combination of the following values:
  • TOP_LEFT: top left corner.
  • TOP_RIGHT: top right corner.
  • BOTTOM_RIGHT: bottom right corner.
  • BOTTOM_LEFT: bottom left corner.
    Since:
    JViews 6.0
    See Also:
    getCorners(), setCornersZoomable(boolean), setRadius(int)

  • isCornersZoomable

    public boolean isCornersZoomable()
    Returns true if the radius of the rounded corners follows the zoom level.

    Since:
    JViews 8.0
    See Also:
    setCornersZoomable(boolean)

    setCornersZoomable

    public void setCornersZoomable(boolean set)
    When set to true, specifies that the radius of the rounded corners follows the zoom level. The option has only an effect if a non-zero radius is specified and some or all corners are rounded. By default, the radius of the corners does not follow the zoom level.

    Since:
    JViews 8.0
    See Also:
    isCornersZoomable(), setCorners(int), setRadius(int)

    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.


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