The Essential JViews Framework > Graphic Objects > Creating a New Graphic Object Class

This section explains how to create a new graphic object class, ShadowEllipse, which inherits from IlvGraphic. The ShadowEllipse object is an ellipse object with a drop shadow, as seen below:

images/shadowEclipse.png

Figure 4.4 A ShadowEllipse

You can design such an object from scratch by implementing a subclass of the IlvGraphic class. IlvGraphic is an abstract class. Therefore, some of its methods must be redefined in derived classes. This is the case for the following:

 public abstract void draw(Graphics dst, IlvTransformer t) 
 public abstract IlvRect boundingBox(IlvTransformer t) 
 public abstract void applyTransform(IlvTransformer t)  
 public abstract IlvGraphic copy() 

Other methods, such as move, resize, rotate, and contains, have a default implementation in the IlvGraphic implementation. These methods, as well as any other method that modifies the bounding box, are implemented by means of a call to the applyTransform function. If the new class has a parent that defines some of these methods, you simply inherit the functions from this parent class.

The ShadowEllipse class defines the draw, contains, and boundingBox methods. In addition, it defines a write method that is necessary to write the object to a stream and a constructor that takes an IlvInputStream as a parameter to read the object from a stream. For details, see The write Method and The read Constructor. These methods have no default implementation. You must provide a version of them for each subclass of the IlvGraphic class. If you do not intend to write additional information to the stream, you do not need to implement the write method, but you always need to define a constructor with an IlvInputStream parameter. Otherwise, you will not be able to read the object from a stream.

In the following subsections you learn the most commonly used procedures. We show you how to define methods that deal with geometric properties and drawing, and how to make this object persistent. The complete source code of the example is available at:

<installdir>/jviews-framework81/codefragments/shadow-ellipse/src/ShadowEllipse.java

This section is divided as follows: