WebÞing

HyperLens

HyperLens Extension Framework

HyperLens offers several interfaces for programmers to enhance or extend its functionality. Full documentation for these will be written as time permits.

Intro under construction

The Lens API: defining new Layers and Lenses

Each HyperLens lens is defined by a JAVA class. So to define a new lens, all you need to do is define a new class that extends the abstract base class gLens. You can then use your class to define a lens in the Editor, and it will be automatically loaded when the project is run. A HyperLens server may permit new classes to be contributed over the 'net.

Example

A lens that makes a greyscale of an RGB image, by taking the mean value of the R/G/B components for each pixel. For this example we will extend the class imgLens, which itself extends the base class gLens. By extending imgLens, we are saying that our lens displays a raster image, and that the transparency control is enabled for this lens.


public class GreyLens extends imgLens {
/* To get the grey, we can define an inner ImageFilter class */
  class GreyFilter extends RGBImageFilter {
    GreyFilter() {
	canFilterIndexColorModel = true ; 
    }
    public int filterRGB(int x, int y, int rgb) {
      return (0x10101 * avgRGB(rgb) ) | 0xff000000 ;
    }
    private int avgRGB(int rgb) {
        int r = ( rgb & 0xff0000 ) >> 16 ;
        int g = ( rgb & 0xff00 ) >> 8 ;
        int b = ( rgb & 0xff ) ;
	return (r + g + b) / 3 ;
    }
  }
/* Since GreyFilter is really just a function, let's have it instantiated
   once and for all.  Note the constructor (if any) must be public
*/
   GreyFilter filter ;
   public GreyLens() {
     filter = new GreyFilter() ;
   }
/* now all we need is a method that computes the greyscale image within
   the area of the lens.  This will be called whenever the lens is moved
   or resized.
*/
  public void newImage() {
    ImageFilter crop = new CropImageFilter(
	bounds.x,bounds.y,bounds.width,bounds.height);
    Image tmp = createImage(new FilteredImageSource(baseImage.getSource(),crop)) ;
    if (imgDisplay != null)
	imgDisplay.flush() ;
    imgDisplay = createImage(new FilteredImageSource(tmp.getSource(), filter)) ;
    tmp.flush() ; tmp = null ;
  }
}

That's all! You don't even need to ask the system administrator to add it to the system library - all you need to do is specify "GreyLens" in the editor!

In reality, the greyscale is just one of the options offered by the FilterLens class.

The Plugin API: interfacing to other software or adding non-lens-based functions

Override Plugin to install yourself in the Plugins menu - then do whatever you want when you are selected. Each plugin has its own Thread and a handle on the main display area.

The Projections API: adding a new projection or other metric

(override the Geo class methods to compute latlong, distances and areas, which is for the time being as far as geographical projection support goes).

Extension API

(unlimited extensions - e.g. the ObjectLens class defines a new API for object types it can display).

[About] [Tutorial] [Manual] [API] [Applet] [Download]