Friday, November 23, 2007

WWJ renderable objects

Although it seems a very big change, here I present a WWJ hack to convert more object into Renderable object, that is, objects that implements the Renderable interface.
I have made only three things to achieve this:


  1. Add the next methods to the Renderable interface:

    public boolean isEnabled();
    public void setEnabled(boolean enabled);
    public String getName();
    public void setName(String name);
    public double getOpacity();
    public void setOpacity(double opacity);

    The idea is that a any Renderable object can has a enable/disable state, an opacity value and optionally a name.



  2. Add a default implementation for this method in all affected classes and interfaces. The default implementation doesn't alter the normal behavior of this elements.

    /**
    * Default Renderable implementation.
    */
    public boolean isEnabled()
    {
    return true;
    }

    public void setEnabled(boolean enabled)
    {
    // Do nothing.
    }

    public String getName()
    {
    return null;
    }

    public void setName(String name)
    {
    // Do nothing.
    }

    public double getOpacity()
    {
    return 1;
    }

    public void setOpacity(double opacity)
    {
    // Do nothing.
    }




  3. Added a new class RenderableListLayer, similar to LayerList that can contain any "new" Renderable object, that is, Layers, Icons, Images, etc.
    Here are a peace of code using this class:

    LayerList ll = new LayerList();
    RenderableListLayer main = new RenderableListLayer();

    main.add(new BMNGSurfaceLayer());
    main.add(new LandsatI3());
    main.add(new ScalebarLayer());

    RenderableListLayer rll = new RenderableListLayer();
    rll.add(si1);
    rll.add(si2);
    rll.add(si3);
    rll.add(new CompassLayer());
    rll.add(new WorldMapLayer());

    main.add(rll);
    main.setPickEnabled(false);

    ll.add(main);




Source code can be found here.

Finally it must be necessary to implement the appropriate mechanism to render images, nodes and other Renderable object taking into account its opacity and enable values.

No comments: