Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 

G 2D Graphics Library and Rendering Engine for Java › Click to download › Updated Info


Download Java Tools from JavaFAQ.nu » Graphics » G 2D Graphics Library and Rendering Engine for Java


Main Page | Details | Download Now | History | Statistics | Promote | Tell a Friend

Category Graphics
Submitted by
admin
Published
Mon Nov 06, 2006 6:31 am

Description

G is a generic graphics library built on top of Java 2D. Client applications can use at high level, make scene graph oriented 2D graphics.



G Graphics Library (Java) Features

  • Layered graphics with visibility support
  • Object oriented hierarchical scene graphs
  • World and device coordinate support
  • Flexible 3D space world extents
  • Powerful rendering style support
  • Powerful object detection functions
  • Smart annotations
  • Extensible
  • Interaction support
  • Raster image support
  • Embedded Swing component support
  • Utilities for geometry generation and transformations
  • Image export and printing support
  • Many Java versions: JDK 1.2, 1.3, 1.4 and 1.5 compatible
  • Light weight (~80kB), self contained, simple to use
  • Free, open source (LGPL), OSI certified

Create a GWindow as top level graphics node and link to a Swing panel. Add a GScene which defines viewport and world extents. Build the graphics hierarchy by GObjects and add to the scene. GObjects consists of GSegments (polylines) and other GObjects. Rendering information is supplied by GStyle objects added to any level of the graphics. Annotations (GText), raster images (GImage) and AWT/Swing components (GComponent) are added to segments with specified position hints. Interactions are implemented through the GInteraction interface.

The graphics is double buffered to keep rendering smooth. The implementation makes heavy use of regions to keep track of objects and damage area in order to keep the rendering pipeline as efficient as possible.

G 2D Graphics Library and Rendering Engine for Java can downloaded from G library home page.

Here is one simple code example:

Code:


/*
 * (C) 2004 - Geotechnical Software Services
 *
 * This code is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free
 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 * MA  02111-1307, USA.
 */
import java.awt.*;

import javax.swing.*;

import no.geosoft.cc.geometry.Geometry;
import no.geosoft.cc.graphics.*;



/**
 * G demo program. Demonstrates:
 *
 * <ul>
 *   <li> Basic graphic window and scene setup
 *   <li> Setting canvas background color
 *   <li> Basic scene composition
 *   <li> The use of style
 *   <li> Example geometry generation
 *   <li> Simple annotation with positioning
 * </ul>
 *
 * @author <a href="mailto:jacob.dreyer@geosoft.no">Jacob Dreyer</a>
 */   
public class Demo1 extends JFrame
{
  public Demo1()
  {
    super ("G Graphics Library - Demo 1");   
    setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
   
    // Create the graphic canvas
    GWindow window = new GWindow(new Color (210, 235, 255));
    getContentPane().add (window.getCanvas());
   
    // Create scene with default viewport and world extent settings
    GScene scene = new GScene (window);

    // Create the graphics object and add to the scene
    GObject helloWorld = new HelloWorld();
    scene.add (helloWorld);

    pack();
    setSize (new Dimension (500, 500));
    setVisible (true);
  }


 
  /**
   * Defines the geometry and presentation for the sample
   * graphic object.
   */   
  public class HelloWorld extends GObject
  {
    private GSegment star_;
   
   
    public HelloWorld()
    {
      star_ = new GSegment();
      GStyle starStyle = new GStyle();
      starStyle.setForegroundColor (new Color (255, 0, 0));
      starStyle.setBackgroundColor (new Color (255, 255, 0));
      starStyle.setLineWidth (3);
      setStyle (starStyle);
      addSegment (star_);
     
      GText text = new GText ("HelloWorld", GPosition.MIDDLE);
      GStyle textStyle = new GStyle();
      textStyle.setForegroundColor (new Color (100, 100, 150));
      textStyle.setBackgroundColor (null);
      textStyle.setFont (new Font ("Dialog", Font.BOLD, 48));
      text.setStyle (textStyle);
      star_.setText (text);
    }
   

 
    /**
     * This method is called whenever the canvas needs to redraw this
     * object. For efficiency, prepare as much of the graphic object
     * up front (such as sub object, segment and style setup) and
     * set geometry only in this method.
     */
    public void draw()
    {
      star_.setGeometry (Geometry.createStar (220, 220, 200, 80, 15));
    }
  }
 


  public static void main (String[] args)
  {
    new Demo1();
  }
}

View all screenshots

Rating Not Rated
Votes 0

Popularity 5/5: Very Popular
Downloads 153
Page Views 9655

Download Now!


Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy