JWAVE

Java™ Graphic Components


Annotated example of a JWAVE component class

See the source code for existing JWAVE classes for templates for creating new JWAVE components, as there are a number of special cases like VRML plots, which require the class constructor to be overridden.

The basic components of a new class are explained in this annotated source for the WaveBar3D() class:


Make sure you include the following package:
   package VisualNumerics.wave;
The class definition must extend the WaveGraph class
   public class WaveBar3D extends WaveGraph
   {  
The class constructor usually just invokes the parent constructor
      public WaveBar3D( int x, int y, int xsize, int ysize )
      {  super( x, y, xsize, ysize );
      }
The plot() method is the only required method for a subclass of WaveGraph. It consists mainly of "add" methods, which are paired with the public "set" methods that are used to set attributes.

The "add" methods append the appropriate keywords and values to a string which will be sent to PV-WAVE. Including these "add" methods in the plot() method allows you to customize and control exactly what keywords and data will be sent to PV-WAVE for this plot type. If a user had called a set method not supported by this class, the keyword would not be sent to PV-WAVE because there is no corresponding "add" method here.

Most standard keyword parameters already have "set" and "add" methods in the WaveGraph class, so all you have to do is include the appropriate "add" method calls here. There may however be some unique methods, as is the case here, that we must include the source for both the "set" and "add" methods in this class.

   
      public void plot()
      {
You must always call addGraph() to define the name of the plot type. On the PV-WAVE server there must be a procedure with the same name. (More on this later).
         addGraph("WaveBar3D");
This will send the data to PV-WAVE in a binary format
         addZ();
These methods allow te PV-WAVE color palette to be changed
         addTEK_COLOR();
         addLOADCT();
Add unique keywords supported for this plot type. These are not included in the WaveGraph class, so the source code for both the public "set" methods, and the private "add" method shown here must be included in this class.
         addRowColors();
         addColumnColors();
Add all keywords supported for this plot type from WaveGraph
         addAx();
         addAz();
         addBackground();
         addColor();
         addRegion();
         addTitle();
         addXTitle();
         addYTitle();
         addZTitle();
Call the Wave graphic server. This is a required method and causes the PV-WAVE server to be called.
         callWave();
      }
Below are set methods unique to this class. They just copy the attributes to a protected variable.
      public void setRowColors(int[] color)
      {  rowcolors = color;
      }

      public void setColumnColors(int[] color)
      {  columncolors = color;
      }
If you have to write your own add methods, as is required here, you must create a string with the following form:
       TAGNAME  TYPE  Value1  Value2 ...ValueN 
where TYPE is I=integer, F=float, D=double, S=string

Note the special tests performed here for parameters that contain arrays. The variable can either contain data, or an array of length 0 (initial condition), or "null" (if the reset() method was called).

      protected void addRowColors()
      {  if (rowcolors != null) { 
            if (rowcolors.length >= 1) {
               tags = tags + "RowColors\tI";
               for (int i=0; i < rowcolors.length; i++)
                  tags = tags + "\t" + rowcolors[i];
               tags = tags + "\n";
            }
         } 
      }

      protected void addColumnColors()
      {  if (columncolors != null) { 
            if (columncolors.length >= 1) {
               tags = tags + "ColumnColors\tI";
               for (int i=0; i < columncolors.length; i++)
                  tags = tags + "\t" + columncolors[i];
               tags = tags + "\n";
            }
         } 
      }
The reset method sets all protected variables back to their initial setting. In the case of array variables they are set to null as is done here.
      public void reset()
      {
      super.reset();
      rowcolors     = null;
      columncolors  = null;
      }
Here are the two protected variables which are unique to this class:
      protected int[] rowcolors;
      protected int[] columncolors;
   }

Back
Copyright © 1996 - Visual Numerics, Inc.®