Cpg-logo.jpg (4054 bytes)

Programming Tips

 

This section is divided in to a number of sections:

  1. Creating a CPG Map.
  2. Hooking-up Customisation Features.
  3. Magnification functions.
  4. Zoom Functions.
  5. Listening to CPG Map.

 

Creating a CPG Map

It is very easy to create a CPG Map once you have the data prepared or data access methods written. A default CPG Map object is created using the call

CPGMap theCPGMap = new CPGMap(); //creates a new CPG Map containing no data

Remember to import the CPGMap package! Once this is done you have to feed data in to the component. This is done using the public method, heresSomeData(boolean, Vector, String[]). The first parameter should be set to true if you're using double map data and false if you're using single map data. The second parameter is the data construct described in design and data preparation. The third parameter is a string array of the map names. If you were using the class FileParser to parse a CPG file this is how you'd do it:

FileParser FP = new FileParser(); //create a new instance of the class

Vector theData = FP.CPG_File(filename); /*this call creates the data structure- the string variable filename should be set to a URL or filepath pointing to the data file.*/

theCPGMap.heresSomeData(FP.getDoubleMapData(), theData, FP.getTitles());/*send the data to CPG Map- getDoubleMapData() returns a boolean value corresponding to whether it's double map data or not, getTitles() returns the map names.*/

String[] units = FP.getUnits();//gets a list of the units from FileParser

theCPGMap.setUnitsLHS(units[0]);//set the units on the LHS maps


if(units.length == 2)
    theCPGMap.setUnitsRHS(units[1]);//if it's double map data, set the units on the RHS.

Hooking-up Customisation Features

As mentioned in the functions section, there are many features that can be customised such as the background colour etc. It is very easy to hook these up to a variety of GUI elements such as choice boxes and buttons. A few examples are given below:

Change the background colour to red:

theCPGMap.setBackgroundColour(Colour.red);

Change the sausage width to 50 pixels:

theCPGMap.setSausageWidth(50);

Toggle between the CPG Map being click-sensitive and hover-sensitive:

theCPGMap.toggleMouseMotionSensitive();

Change the titles of the maps, (in this case assuming you have two maps):

String[] titles = new String[2];

titles[0] = "Map One";

titles[1] = "Map Too";

theCPGMap.setMapTitles(titles);

 

Magnification functions

As mentioned before, you can change the length of each of the sausages on the canvas (and change the two sausages of a double map independently of each other). To do this you have to get the user to input an integer for each of the sausages which then have to be assembled in to an integer array. This is easily done using a composite of GUI components like scrollbars. You could create the scrollbars dynamically (by finding out from CPG Map how many to make) and storing them in a vector. The code might look something like the following:

Vector scrollbars = new Vector();

int no_Of_Maps = theCPGMaps.getNoOfMaps(); //returns the number of double or single maps.

if(theCPGMap.isDoubleMapData())
    no_Of_Maps = no_Of_Maps * 2;    //if the program is showing double maps, multiply no_Of_Maps by 2.

for(int i = 0; i < no_Of_Maps; i++)
{       bar = new Scrollbar();
        scrollbars.addElement(bar);  //create the scrollbars and add them to the vector
}

Once the user has finished adjusting the scrollbars, you can collect the values from them by going through the vector and making an integer array out of them.

int[] values = new int[scrollbars.size()];//create an integer array
for(int i = 0; i < scrollbars.size(); i++)//go through the vector
{    Scrollbar bar = (Scrollbar)scrollbars.elementAt(i);//get the scrollbar
     values[i] = bar.getValue();//assign the value to the vector
}

That's the difficult bits over with. All you have to do now is send it to the method setMagnification(int[]).

theCPGMap.setMagnification(values);

That's one way of gathering data for setMagnification() but obviously there are many!

 

Zoom Functions

There are three zoom methods available to the programmer in the class CPGMap. They all adjust the sizes of the AWT components rather than 'blowing-up' the pixels.

zoomMapComponents(double)

This is the method to call when you want to zoom in or out of the map by a certain amount. It can accept values between -50.0 and 200.0, (representing percentage increase/decrease). Note that you can easily run out of virtual machine memory by zooming-in too far.

undoZoomToDefaults()

This restores the CPG Map to the default values.

undoLastZoom()

This method undoes the last zoom! What this means is if you have zoomed-in twice, it will restore the previous zoom rather than to the default values.

 

Listening to CPG Map

You can add a listener to CPG Map so that you are notified by the program every time a locus is highlighted. This is done by using the line

theCPGMap.addActionListener((ActionListener)this);

If a locus is highlighted your application will recieve the action event message "LOCUS_HIGHLIGHTED". You can then get the CPG_Locus object using the line

CPG_Locus selected = theCPGMap.getHighlightedLocus();

Now that you have the CPG_Locus object you can do what you want with it. For example you can print out it's name using the line

System.out.println("The selected locus is called :   " +  selected.getName());

The JavaDoc on CPG_Locus will tell you what methods are available.

 

To the JavaDoc.

 

©1998 Jeremy Dickson