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.
- It has bounds in terms of user (Cartesian) coordinates instead
of a size in terms of AWT coordinates. The package has a layout
manager that sets the AWT coordinates of each graphic element given
the user coordinates bounds of all the graphic elements and the
AWT bounds of the container that the graphic elements are in.
It must be able to draw itself at any screen pixel size.
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.
-
Graphic()
-
-
contains(int, int)
- Return if the specified AWT coordinates are inside the graphic
element.
-
getGraphics()
- Gets a Graphics context for this graphic element.
-
getHeight()
- Return the AWT bounds height value.
-
getParent()
- Return the GraphicPane that the element is in.
-
getWidth()
- Return the AWT bounds width value.
-
getX()
- Return the AWT bounds x value.
-
getX(double)
- Return the AWT X coordinate corresponding to a user X coordinate.
-
getY()
- Return the AWT bounds y value.
-
getY(double)
- Return the AWT Y coordinate corresponding to a user Y coordinate.
-
mouseClicked(MouseEvent)
- Invoked when the mouse has been clicked on a graphic element.
-
mousePressed(MouseEvent)
- Invoked when the mouse has been pressed on a graphic element.
-
mouseReleased(MouseEvent)
- Invoked when the mouse has been released on a graphic element.
-
obtainBounds(GraphicBoundsUC)
- Obtain the Cartesian coordinate bounds of a graphic element.
-
paint(Graphics, int, int)
- Paint the graphic element.
-
repaint()
- Repaint the whole graphic element as soon as possible.
-
repaint(int, int, int, int)
- Repaint part of the graphic element as soon as possible.
-
repaint(long)
- Repaint the whole graphic element within the given time.
-
repaint(long, int, int, int, int)
- Repaint part of the graphic element within the given time.
-
toString()
- Return the String representation of this graphic element's values.
Graphic
public Graphic()
getParent
public GraphicPane getParent()
- Return the GraphicPane that the element is in.
getX
public final int getX()
- Return the AWT bounds x value.
getY
public final int getY()
- Return the AWT bounds y value.
getWidth
public final int getWidth()
- Return the AWT bounds width value.
getHeight
public final int getHeight()
- Return the AWT bounds height value.
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.
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
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).
getX
public final int getX(double x)
- Return the AWT X coordinate corresponding to a user X coordinate.
getY
public final int getY(double y)
- Return the AWT Y coordinate corresponding to a user Y coordinate.
repaint
public void repaint()
- Repaint the whole graphic element as soon as possible.
repaint
public void repaint(long tm)
- Repaint the whole graphic element within the given time.
repaint
public void repaint(int x,
int y,
int width,
int height)
- Repaint part of the graphic element as soon as possible.
repaint
public void repaint(long tm,
int x,
int y,
int width,
int height)
- Repaint part of the graphic element within the given time.
mouseClicked
public void mouseClicked(MouseEvent e)
- Invoked when the mouse has been clicked on a graphic element.
The default implementation does nothing.
mousePressed
public void mousePressed(MouseEvent e)
- Invoked when the mouse has been pressed on a graphic element.
The default implementation does nothing.
mouseReleased
public void mouseReleased(MouseEvent e)
- Invoked when the mouse has been released on a graphic element.
The default implementation does nothing.
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.)
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