![]()

![]()
This section is divided in to a number of sections:
Creating a CPG MapIt 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
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:
| |
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:
| |
Change the sausage width to 50 pixels:
| |
Toggle between the CPG Map being click-sensitive and hover-sensitive:
| |
Change the titles of the maps, (in this case assuming you have two maps):
|
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.
![]()
![]()