public void mouseDragged(MouseEvent evt) {
    mx = evt.getX();
    my = evt.getY();
    // Check if this is a rectangle drawing drag
    if ((evt.getModifiers() & InputEvent.BUTTON2_MASK) != 0) {
      //      rectx2 = evt.getX();
      //      recty2 = evt.getY();
    } else {
      rotmat.setIdentity();

      rotmat.rotate((float) (my - omy), 'x');
      rotmat.rotate((float) (mx - omx), 'y');

      for (int i = 0; i < npoint; i++) {
        SequencePoint sp = (SequencePoint) points.elementAt(i);
        sp.coord[0] -= centre[0];
        sp.coord[1] -= centre[1];
        sp.coord[2] -= centre[2];

        // Now apply the rotation matrix
        sp.coord = rotmat.vectorMultiply(sp.coord);

        // Now translate back again
        sp.coord[0] += centre[0];
        sp.coord[1] += centre[1];
        sp.coord[2] += centre[2];
      }

      for (int i = 0; i < 3; i++) {
        axes[i] = rotmat.vectorMultiply(axes[i]);
      }
      omx = mx;
      omy = my;

      redrawneeded = true;
      paint(this.getGraphics());
    }

    return;
  }
  public RotatableCanvas(Object parent, AlignViewport av, Controller c, Vector points, int npoint) {
    this.parent = parent;
    this.points = points;
    this.npoint = npoint;
    this.controller = c;
    this.av = av;

    controller.addListener(this);

    prefsize = getPreferredSize();
    orig = new float[npoint][3];

    for (int i = 0; i < npoint; i++) {
      SequencePoint sp = (SequencePoint) points.elementAt(i);
      for (int j = 0; j < 3; j++) {
        orig[i][j] = sp.coord[j];
      }
    }
    // Initialize the matrices to identity

    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (i != j) {
          idmat.addElement(i, j, 0);
          objmat.addElement(i, j, 0);
          rotmat.addElement(i, j, 0);
        } else {
          idmat.addElement(i, j, 0);
          objmat.addElement(i, j, 0);
          rotmat.addElement(i, j, 0);
        }
      }
    }

    axes = new float[3][3];
    initAxes();

    findCentre();
    findWidth();

    scale = findScale();

    //    System.out.println("Scale factor = " + scale);

    addMouseListener(this);
    addKeyListener(this);
    if (getParent() != null) {
      getParent().addKeyListener(this);
    }
    addMouseMotionListener(this);

    // Add rubberband
    rubberband = new RubberbandRectangle(this);
    rubberband.setActive(true);
    rubberband.addListener(this);
  }