Java2d

 

Table of contents

Library Overview

Java provides powerful functionality for 2-dimensional graphics, usually summarized under the name "Java2D". Since Java2D works like a rendering pipeline (geometry, colors etc. are just sequentially handed to the rendering engine), it is too low level to be directly used for describing an interactive 2D-scene in an Oorange network. This is why Oorange, for the purpose of examples, ships with a class library java2d that offers a simple scenegraph api based on Java2D.

A java2d scene is a directed graph without directed cycles whose vertices implement the interface SceneNode. Scene nodes describe a geometric shape with all information like outline, transformation, color, textual annotation etc. Scene nodes can be added to appropriate viewer windows to display them (and all their descendents in the scene hierarchy). For more information we refer to the documentation of the java2d package.

Node Descriptions

Area

This node takes ajava2d.SceneNode and extracts its shape as a java.awt.geom.Area (an object that just describes a subset of the plane in a form suitable in computational geometry algorithms).

Ingredient ports:

  • sceneNode: Specify here the SceneNode to extract the shape from.

Disk

This node represents a java2d.SceneComponent with the circular unit disk as its shape.

Suggested modifications:

  • In the init section change the line
self.setPaint(new java.awt.Color(128,0,0,30));

to change the color of the disk. The four numbers specify the red, green, blue, alpha components of the color and should be integers in the range from 0 to 255. The alpha value specifies opacity, which means 0 gives a totally transparent disk while 255 yields a totally opaque one,

  • In the init section change the line
self.setShape(
  new java.awt.geom.Ellipse2D.Double(-1,-1,2,2)
);

to change the center and the radius of the disk. The first number specifies the minimal x-coordinates of the disk as a double precision floating point number, the second does the same for the y-direction. The last two numbers (they should be equal for a circular disk) specify the diameter of the disk.

There are numerous other properties one could specify in the init section, like for example the width and color of the disk's outline. See the documentation of the java2D package fo details.

SceneComponentForArea

This node takes an java.awt.geom.Area (an object that just describes a subset of the plane in a form suitable in computational geometry algorithms) and uses it as the shape of a java2d.SceneComponent. This adds graphical properties (color, outline etc.) to the area that are needed for drawing it using a Viewer2D.

Ingredient ports:

  • area: Specify here the Area to which display properties are to be added.

Viewer2D

This node represents an viewer widget for java2d scenes.

Ingredient ports:

  • sceneNode: Add here the sceneNodes that should be displayed. The order matters since the first nodes are drawn first, which means they might be occluded by the later ones.

Viewer2DWithGrid

This node represents an viewer widget for java2d scenes. In addition it displays in the background a coordinate grid for better orientation.

Ingredient ports:

  • sceneNode: Add here the sceneNodes that should be displayed. The order matters since the first nodes are drawn first, which means they might be occluded by the later ones.