Coordinating Two Widgets

Now we coordinate the NeoMap and the NeoSeq so that they work together a little better. We listen for events from each widget. When the NeoSeq is scrolled the center of scaling (zooming) of the NeoMap is set to the first residue visible in the NeoSeq.

Notice that clicking the map does not just scroll the NeoSeq. It also causes the zoom center to change. This is because the NeoSeq will generate a NeoEvent whenever it is scrolled, be it by the user using the scrollbar or by our program.

/*
**  © Copyright 2000, Neomorphic, Inc.
**  © Copyright 2001 - 2005, Affymetrix, Inc.
**  All Rights Reserved
**
**  This file is part of the GenoViz SDK
**
*/

package tutorial;

import com.affymetrix.genoviz.event.NeoRangeEvent;
import com.affymetrix.genoviz.event.NeoRangeListener;
import com.affymetrix.genoviz.event.NeoMouseEvent;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class SequenceMap1 extends SequenceMap0 implements NeoRangeListener {

  protected MouseListener mouser = new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
      if (e instanceof NeoMouseEvent) {
        neoMouseClicked((NeoMouseEvent)e);
      }
    }
  };

  public void neoMouseClicked(NeoMouseEvent theEvent) {
      showStatus(""); // Clear status line.
      // Let's see if we can scroll that NeoSeq.
      this.seq.scrollSequence((int)theEvent.getCoordX());
      this.seq.updateWidget();
    }

  public SequenceMap1() {
    super();
    this.seq.addRangeListener(this);
    this.map.addMouseListener(this.mouser);
  }

  public String getAppletInfo() {
    return "Simple Sequence Map.";
  }

  public void rangeChanged(NeoRangeEvent theEvent) {
    int sbeg = (int)theEvent.getVisibleStart();
    // Center zooming at the beginning of the range.
    this.map.setZoomBehavior(
      this.map.X,
      this.map.CONSTRAIN_COORD,
      sbeg
    );
  }

}
        

Exercises

  1. Turn on the map's default selection behavior.
  2. When an item is selected in the map, add it as an annotation to the NeoSeq.

Next: Displaying a Multiseq Alignment