TU Berlin

java2d

This package provides a 2D scene graph api based on the rendering capabilities of java.awt.Graphics2D.

Scene graph

The basic element in the 2D scene is a SceneComponent that provides all ingredients necessary to draw it: a Shape that can be filled with a certain Paint, whose outline can be drawn using a certain Stroke etc.

A Stroke in Java2D provides a way to create a 2-dimensional shape (that can be filled with a paint) out of the (in principle infinitely thin) 1-dimensional outline of a shape, in order to make it visible. Thus, Java2D provides ways to render 2- and 1-dimensional objects. In technical or mathematical drawings often also 0-dimensional geometries (points) need graphical representation. Points can be added to a SceneComponent by adding them to the list returned by getPoints().

A SceneComponent also can have a textual Annotation which is a collection of strings to be drawn at certain positions.

In addition, a SceneComponent can have children, which allows for a scene that is a directed acyclic graph. Each scene node can have an affine transformation (java.awt.geom.AffineTransform) that describes its orientation with respect to its parents. All attributes like paint, stroke, font etc. can be null, which means that they are inherited from the scene hierarchy.

To support dynamic and interactive behavior, you can register three types of event listeners with a SceneComponent:

  • An AppearanceChangeEvent is passed along the hierarchy up to its root to inform viewers that some child SceneComponent has changed and therefore the scene needs repainting.
  • One can register for drag events, which means that the user is attempting to drag the component with some input device (usually the mouse).
  • One can register for mouse over events, which means that the the pointer of some input device (usually the mouse) has entered or left the shape of the component.

Viewer

The JComponent Viewer2d is provided to draw the java2d scene graph. One can register with a Viewer2d for the occurrence of a ViewportChangeEvent. This can be used to create viewport-dependent geometries like coordinate axes.

Zusatzinformationen / Extras

Links

Downloads

(release 2014-05-27_rev1801 )