Uni-HH / CS. / TAMS / Java / jfig
 
spacer jfig
spacer News
spacer Gallery

spacer Editor
spacer Custom editors
spacer Viewer / Bean
spacer Applet
spacer Presentations
spacer Plotting

spacer Webstart
spacer Download
spacer Documentation
 

The jfig bean allows embedding a fully functional FIG file viewer into your own Java applications or websites. It consists of a main class, jfig.gui.JFigViewerBean, and includes all classes required to parse and display FIG files, packaged as one JAR archive file of approximately 250 KBytes (jfig-bean.jar).

The following screenshot (click on the thumbnail) shows the bean running as a standalone application:

jfig bean screenshot

The jfig bean can also be used as an applet via the jfig.gui.JFigViewerApplet class. Click here for an example.

Example: SimpleViewer

You can use the jfig bean in any Beans-compatible development environment (e.g. JBuilder or Netbeans), as well as in hand-written code. For example, the following code realizes a complete viewer for FIG files and URLs:
public class SimpleViewer {
  public static void main( String args[] ) throws Exception {
    // create the bean and parse the specified URL
    JFigViewerBean bean = new JFigViewerBean();
    bean.setURL( new URL( args[0] ));
    bean.setPreferredSize( new Dimension( 600, 600 ));

    // create and show a frame
    JFrame frame = new JFrame( "jfig bean demo" );
    frame.getContentPane().add( "Center", bean );
    frame.pack();
    frame.show();

    // set some bean attributes
    bean.setUnits( FigTrafo2D.UNITS_INCHES );
    bean.doZoom11(); // show data in original size (100%)

    // or use the following to do a 'zoom fit' into the specified
    // component dimension; this method can also be called before
    // the Swing GUI has been layouted...
    bean.doZoomFitAssumingDimension( new Dimension(600,600) );

    // add a popup-menu with a few generally useful actions
    bean.createDefaultPopupMenu();
  }
}

Bean properties

The jfig bean exports many different properties via the standard Java Beans design patterns:
  figURL          specify the URL to parse and display, e.g.
                  http://yourserver/path/file.fig
                  file:/tmp/welcome.fig
                  file:/c/temp/welcome.fig
                  getClass().getResource( "jfig/examples/house.fig" )

  preferredSize   specify the size of the viewer component

  antiAlias       whether to use Java2D anti-aliasing
  renderQuality   whether to use Java2D image filtering
  showRulers      whether to show the rulers on the canvas
  units           grid and rulers units:
                  e.g. jfig.canvas.FigTrafo2D.UNITS_INCHES
  zoomFactor      the zoom factor (1.0 means original size)

  figCanvas       use a custom canvas (e.g. to override grid modes)

If you simply want to load a file instead of an URL, use the following simple trick:
  JFigViewerBean bean = ...
  String filename = ...
  bean.setURL( new java.io.File(filename).toURL() );
  ...

Bean events

At the moment, jfig bean does not export any events via the standard design patterns. However, you can easily add your own event listeners directly. Caution: while it is possible to add listeners to the bean's (JPanel) component itself, this is not of great use. Instead, add your custom listeners to the embedded object canvas. For example:
  ...
  JFigViewerBean bean = new JFigViewerBean();
  JComponent   canvas = bean.getFigCanvas().getComponent();

  canvas.addMouseMotionListener( new YourMouseMotionListener() );
  canvas.addKeyListener( new YourKeyListener();
  ...
In some cases, the provided default listeners will be sufficient, so that no external code is required:
  ...
  JFigViewerBean bean = new JFigViewerBean();

  bean.createDefaultKeyHandler();    // useful shortcut keys
  bean.createDefaultPopupMenu();     // zoom, panning, options
  bean.createDefaultDragHandler();   // panning via mouse-drag
  bean.createPositionAndZoomPanel(); // show cursor position
  ...
The DefaultKeyListener supports the following actions:
   cursor keys
             left/right/up/down panning
             hold the shift-key down for faster panning

   a         toggle anti-aliasing
   b         toggle render-quality (bilinear filtering)
   g         toggle grid-mode      (off, course, medium, ...)
   r         toggle rulers         (show rulers, hide rulers)

   f         zoom fit              (fit drawing to canvas size)
   F         zoom 1:1              (100% size, restore origin)
   z         zoom out
   Z         zoom in

   F1        show help
   F5        redraw
   HOME      zoom 1:1
 
  29.01.2006   Impressum