All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class GraphicPlotter.Graphic

java.lang.Object
   |
   +----GraphicPlotter.Graphic

public abstract class Graphic
extends Object
Abstract class of the graphic elements that are drawn by the package. A graphic element can be considered to be a special purpose light-weight Java AWT Component. A Graphic element differs from a Component in the following major ways.

The graphic element class does not extend java.awt.Component to avoid duplicating fields that the package directly gets and puts (such as the bounds fields that are accessible only to classes in the java.awt package). However, the graphic element class does implement some of the methods of java.awt.Component. Only those methods of Component required by the package are implemented.

Because the graphic element class does not extend Component, graphic element do not use AWT event handling. However, the package supports graphic elements that implement the MouseListener methods: mouseClicked(MouseEvent e), mousePressed(MouseEvent e), and mouseReleased(MouseEvent e). Inside these methods the value of the source field of MouseEvent is meaningless.


Constructor Index

 o Graphic()

Method Index

 o contains(int, int)
Return if the specified AWT coordinates are inside the graphic element.
 o getGraphics()
Gets a Graphics context for this graphic element.
 o getHeight()
Return the AWT bounds height value.
 o getParent()
Return the GraphicPane that the element is in.
 o getWidth()
Return the AWT bounds width value.
 o getX()
Return the AWT bounds x value.
 o getX(double)
Return the AWT X coordinate corresponding to a user X coordinate.
 o getY()
Return the AWT bounds y value.
 o getY(double)
Return the AWT Y coordinate corresponding to a user Y coordinate.
 o mouseClicked(MouseEvent)
Invoked when the mouse has been clicked on a graphic element.
 o mousePressed(MouseEvent)
Invoked when the mouse has been pressed on a graphic element.
 o mouseReleased(MouseEvent)
Invoked when the mouse has been released on a graphic element.
 o obtainBounds(GraphicBoundsUC)
Obtain the Cartesian coordinate bounds of a graphic element.
 o paint(Graphics, int, int)
Paint the graphic element.
 o repaint()
Repaint the whole graphic element as soon as possible.
 o repaint(int, int, int, int)
Repaint part of the graphic element as soon as possible.
 o repaint(long)
Repaint the whole graphic element within the given time.
 o repaint(long, int, int, int, int)
Repaint part of the graphic element within the given time.
 o toString()
Return the String representation of this graphic element's values.

Constructors

 o Graphic
 public Graphic()

Methods

 o getParent
 public GraphicPane getParent()
Return the GraphicPane that the element is in.

 o getX
 public final int getX()
Return the AWT bounds x value.

 o getY
 public final int getY()
Return the AWT bounds y value.

 o getWidth
 public final int getWidth()
Return the AWT bounds width value.

 o getHeight
 public final int getHeight()
Return the AWT bounds height value.

 o contains
 public boolean contains(int x,
                         int y)
Return if the specified AWT coordinates are inside the graphic element. This method needs to be override by graphic elements that are scaled to indicate nesting.

 o obtainBounds
 public abstract GraphicBoundsUC obtainBounds(GraphicBoundsUC gb)
Obtain the Cartesian coordinate bounds of a graphic element. Because the package obtains the Cartesian coordinate bounds using a method (rather than defining bounds fields), each class that extends this one may store the bounds in a way most convenient for itself. For example, the coordinates may be stored as fields of type short to reduce the amount of storage that is used, if the range of values fit in the range of short.

This method is designed to reduce the frequency of garbage collection by reducing the number of short lived objects.

It is expected that there will be a large number of graphic elements. The package will loop over these graphic elements obtaining the bounds of each one, as in

    for (int i = 0; i < graphicElementCnt; i++) {
       Graphic e = getGraphicElement(i);
       GraphicBoundsUC b = e.getBounds();
       // operations depending on the bounds
    }
 

Because getBounds() would create a new bounds object for each invocation, there would be a large number of short lived objects. This would result in more frequent garbage collection. To reduce the frequency of garbage collection this method is defined so the loop may be written as

    Bounds b = new GraphicBoundsUC();
    for (int i = 0; i < graphicElementCnt; i++) {
       Graphic e = getGraphicElement(i);
       e.obtainBounds(b);
       // operations depending on the bounds
    }
 

The obtainBounds(GraphicBoundsUC) method assigns values to the public variables of GraphicBoundsUC. In this way only one object is created for all iterations of the loop as opposed to creating as many objects as there are iterations of the loop, each of which is referenced only during one iteration.

Returns:
the argument
See Also:
GraphicBoundsUC
 o paint
 public abstract void paint(Graphics g,
                            int depth,
                            int paintDepthMax)
Paint the graphic element. It takes additional parameters (as compared to java.awt.Component.paint) that gives the depth of the graphic and the depth of the deepest graphic element being painted.

The deepest painted depth is used by a graphic element that shows nesting by scaling what is painted. If a graphic element follows the convention that a negative depth indicates that a scaled version is to be painted, then a graphic element with a depth less than Math.min(0, depthMax) paints itself scaled by a factor proportional to its depth minus Math.min(0, paintDepthMax).

 o getX
 public final int getX(double x)
Return the AWT X coordinate corresponding to a user X coordinate.

 o getY
 public final int getY(double y)
Return the AWT Y coordinate corresponding to a user Y coordinate.

 o repaint
 public void repaint()
Repaint the whole graphic element as soon as possible.

 o repaint
 public void repaint(long tm)
Repaint the whole graphic element within the given time.

 o repaint
 public void repaint(int x,
                     int y,
                     int width,
                     int height)
Repaint part of the graphic element as soon as possible.

 o repaint
 public void repaint(long tm,
                     int x,
                     int y,
                     int width,
                     int height)
Repaint part of the graphic element within the given time.

 o mouseClicked
 public void mouseClicked(MouseEvent e)
Invoked when the mouse has been clicked on a graphic element. The default implementation does nothing.

 o mousePressed
 public void mousePressed(MouseEvent e)
Invoked when the mouse has been pressed on a graphic element. The default implementation does nothing.

 o mouseReleased
 public void mouseReleased(MouseEvent e)
Invoked when the mouse has been released on a graphic element. The default implementation does nothing.

 o getGraphics
 public Graphics getGraphics()
Gets a Graphics context for this graphic element. Note: this method returns a Graphics whose clipping bounds is the intersection of the bounds of the Graphic object and its enclosing container. (The Component.getGraphics() method returns a Graphics whose clipping bounds is the size of the Graphic object.)

 o toString
 public String toString()
Return the String representation of this graphic element's values.

Overrides:
toString in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index