Adding scrollbars for zooming and panning is pretty easy. The scaling is built into the widgets. All we need do is attach the scrollbars.
The complete source code is long. Here is the most relevant part:public class SimpleMap3 extends SimpleMap2 { Adjustable zoomer, scroller; public SimpleMap3() { zoomer = new JScrollBar(JScrollBar.VERTICAL); add("West", (Component)zoomer); map.setRangeZoomer(zoomer); scroller = new JScrollBar(JScrollBar.HORIZONTAL); add("South", (Component)scroller); map.setRangeScroller(scroller); } }
The API documentation uses the terms "pixel space" and "coordinate space". They are perhaps a bit inelegant. It's really fairly simple. "Pixel space" has a coordinate system that corresponds to pixels on your screen. "Coordinate space" has a coordinate system that corresponds to your model. Zooming will change the scale of your map. So as you zoom in more pixels are used to represent an area of "coordinate space".
For example, with sequences, the primary axis (in coordinate space) will correspond to residues of the sequence. Hence, coordinate 3 corresponds to the third residue (or fourth if you start at 0). The offset can be used to keep overlapping features from obscuring each other (although the packer also does this automatically). Or the offset can be used to indicate function. The idea is that you define biological features and other entities in "coordinate space".
You will want to put features on a map giving it coordinates that correspond to the model. The map and its zoomers will figure out how many pixels to use.