JAL-1683 replace year/version strings with tokens in source
[jalview.git] / src / jalview / appletgui / SeqPanel.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.appletgui;
22
23 import jalview.commands.EditCommand;
24 import jalview.commands.EditCommand.Action;
25 import jalview.datamodel.ColumnSelection;
26 import jalview.datamodel.SearchResults;
27 import jalview.datamodel.Sequence;
28 import jalview.datamodel.SequenceFeature;
29 import jalview.datamodel.SequenceGroup;
30 import jalview.datamodel.SequenceI;
31 import jalview.schemes.ResidueProperties;
32 import jalview.structure.SelectionSource;
33 import jalview.structure.SequenceListener;
34 import jalview.structure.StructureSelectionManager;
35 import jalview.util.MessageManager;
36
37 import java.awt.BorderLayout;
38 import java.awt.Font;
39 import java.awt.FontMetrics;
40 import java.awt.Panel;
41 import java.awt.Point;
42 import java.awt.event.InputEvent;
43 import java.awt.event.MouseEvent;
44 import java.awt.event.MouseListener;
45 import java.awt.event.MouseMotionListener;
46 import java.util.Vector;
47
48 public class SeqPanel extends Panel implements MouseMotionListener,
49         MouseListener, SequenceListener
50 {
51
52   public SeqCanvas seqCanvas;
53
54   public AlignmentPanel ap;
55
56   protected int lastres;
57
58   protected int startseq;
59
60   protected AlignViewport av;
61
62   // if character is inserted or deleted, we will need to recalculate the
63   // conservation
64   boolean seqEditOccurred = false;
65
66   ScrollThread scrollThread = null;
67
68   boolean mouseDragging = false;
69
70   boolean editingSeqs = false;
71
72   boolean groupEditing = false;
73
74   int oldSeq = -1;
75
76   boolean changeEndSeq = false;
77
78   boolean changeStartSeq = false;
79
80   boolean changeEndRes = false;
81
82   boolean changeStartRes = false;
83
84   SequenceGroup stretchGroup = null;
85
86   StringBuffer keyboardNo1;
87
88   StringBuffer keyboardNo2;
89
90   boolean mouseWheelPressed = false;
91
92   Point lastMousePress;
93
94   EditCommand editCommand;
95
96   StructureSelectionManager ssm;
97
98   public SeqPanel(AlignViewport avp, AlignmentPanel p)
99   {
100     this.av = avp;
101
102     seqCanvas = new SeqCanvas(avp);
103     setLayout(new BorderLayout());
104     add(seqCanvas);
105
106     ap = p;
107
108     seqCanvas.addMouseMotionListener(this);
109     seqCanvas.addMouseListener(this);
110     ssm = StructureSelectionManager.getStructureSelectionManager(av.applet);
111     ssm.addStructureViewerListener(this);
112
113     seqCanvas.repaint();
114   }
115
116   void endEditing()
117   {
118     if (editCommand != null && editCommand.getSize() > 0)
119     {
120       ap.alignFrame.addHistoryItem(editCommand);
121       av.firePropertyChange("alignment", null, av.getAlignment()
122               .getSequences());
123     }
124
125     startseq = -1;
126     lastres = -1;
127     editingSeqs = false;
128     groupEditing = false;
129     keyboardNo1 = null;
130     keyboardNo2 = null;
131     editCommand = null;
132   }
133
134   void setCursorRow()
135   {
136     seqCanvas.cursorY = getKeyboardNo1() - 1;
137     scrollToVisible();
138   }
139
140   void setCursorColumn()
141   {
142     seqCanvas.cursorX = getKeyboardNo1() - 1;
143     scrollToVisible();
144   }
145
146   void setCursorRowAndColumn()
147   {
148     if (keyboardNo2 == null)
149     {
150       keyboardNo2 = new StringBuffer();
151     }
152     else
153     {
154       seqCanvas.cursorX = getKeyboardNo1() - 1;
155       seqCanvas.cursorY = getKeyboardNo2() - 1;
156       scrollToVisible();
157     }
158   }
159
160   void setCursorPosition()
161   {
162     SequenceI sequence = av.getAlignment().getSequenceAt(
163             seqCanvas.cursorY);
164
165     seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1()) - 1;
166     scrollToVisible();
167   }
168
169   void moveCursor(int dx, int dy)
170   {
171     seqCanvas.cursorX += dx;
172     seqCanvas.cursorY += dy;
173     if (av.hasHiddenColumns()
174             && !av.getColumnSelection().isVisible(seqCanvas.cursorX))
175     {
176       int original = seqCanvas.cursorX - dx;
177       int maxWidth = av.getAlignment().getWidth();
178
179       while (!av.getColumnSelection().isVisible(seqCanvas.cursorX)
180               && seqCanvas.cursorX < maxWidth && seqCanvas.cursorX > 0)
181       {
182         seqCanvas.cursorX += dx;
183       }
184
185       if (seqCanvas.cursorX >= maxWidth
186               || !av.getColumnSelection().isVisible(seqCanvas.cursorX))
187       {
188         seqCanvas.cursorX = original;
189       }
190     }
191     scrollToVisible();
192   }
193
194   void scrollToVisible()
195   {
196     if (seqCanvas.cursorX < 0)
197     {
198       seqCanvas.cursorX = 0;
199     }
200     else if (seqCanvas.cursorX > av.getAlignment().getWidth() - 1)
201     {
202       seqCanvas.cursorX = av.getAlignment().getWidth() - 1;
203     }
204
205     if (seqCanvas.cursorY < 0)
206     {
207       seqCanvas.cursorY = 0;
208     }
209     else if (seqCanvas.cursorY > av.getAlignment().getHeight() - 1)
210     {
211       seqCanvas.cursorY = av.getAlignment().getHeight() - 1;
212     }
213
214     endEditing();
215     if (av.wrapAlignment)
216     {
217       ap.scrollToWrappedVisible(seqCanvas.cursorX);
218     }
219     else
220     {
221       while (seqCanvas.cursorY < av.startSeq)
222       {
223         ap.scrollUp(true);
224       }
225       while (seqCanvas.cursorY + 1 > av.endSeq)
226       {
227         ap.scrollUp(false);
228       }
229       while (seqCanvas.cursorX < av.getColumnSelection()
230               .adjustForHiddenColumns(av.startRes))
231       {
232
233         if (!ap.scrollRight(false))
234         {
235           break;
236         }
237       }
238       while (seqCanvas.cursorX > av.getColumnSelection()
239               .adjustForHiddenColumns(av.endRes))
240       {
241         if (!ap.scrollRight(true))
242         {
243           break;
244         }
245       }
246     }
247     setStatusMessage(av.getAlignment().getSequenceAt(seqCanvas.cursorY),
248             seqCanvas.cursorX, seqCanvas.cursorY);
249
250     seqCanvas.repaint();
251   }
252
253   void setSelectionAreaAtCursor(boolean topLeft)
254   {
255     SequenceI sequence = av.getAlignment().getSequenceAt(
256             seqCanvas.cursorY);
257
258     if (av.getSelectionGroup() != null)
259     {
260       SequenceGroup sg = av.getSelectionGroup();
261       // Find the top and bottom of this group
262       int min = av.getAlignment().getHeight(), max = 0;
263       for (int i = 0; i < sg.getSize(); i++)
264       {
265         int index = av.getAlignment().findIndex(sg.getSequenceAt(i));
266         if (index > max)
267         {
268           max = index;
269         }
270         if (index < min)
271         {
272           min = index;
273         }
274       }
275
276       max++;
277
278       if (topLeft)
279       {
280         sg.setStartRes(seqCanvas.cursorX);
281         if (sg.getEndRes() < seqCanvas.cursorX)
282         {
283           sg.setEndRes(seqCanvas.cursorX);
284         }
285
286         min = seqCanvas.cursorY;
287       }
288       else
289       {
290         sg.setEndRes(seqCanvas.cursorX);
291         if (sg.getStartRes() > seqCanvas.cursorX)
292         {
293           sg.setStartRes(seqCanvas.cursorX);
294         }
295
296         max = seqCanvas.cursorY + 1;
297       }
298
299       if (min > max)
300       {
301         // Only the user can do this
302         av.setSelectionGroup(null);
303       }
304       else
305       {
306         // Now add any sequences between min and max
307         sg.clear();
308         for (int i = min; i < max; i++)
309         {
310           sg.addSequence(av.getAlignment().getSequenceAt(i), false);
311         }
312       }
313     }
314
315     if (av.getSelectionGroup() == null)
316     {
317       SequenceGroup sg = new SequenceGroup();
318       sg.setStartRes(seqCanvas.cursorX);
319       sg.setEndRes(seqCanvas.cursorX);
320       sg.addSequence(sequence, false);
321       av.setSelectionGroup(sg);
322     }
323     ap.paintAlignment(false);
324     av.sendSelection();
325   }
326
327   void insertGapAtCursor(boolean group)
328   {
329     groupEditing = group;
330     startseq = seqCanvas.cursorY;
331     lastres = seqCanvas.cursorX;
332     editSequence(true, seqCanvas.cursorX + getKeyboardNo1());
333     endEditing();
334   }
335
336   void deleteGapAtCursor(boolean group)
337   {
338     groupEditing = group;
339     startseq = seqCanvas.cursorY;
340     lastres = seqCanvas.cursorX + getKeyboardNo1();
341     editSequence(false, seqCanvas.cursorX);
342     endEditing();
343   }
344
345   void numberPressed(char value)
346   {
347     if (keyboardNo1 == null)
348     {
349       keyboardNo1 = new StringBuffer();
350     }
351
352     if (keyboardNo2 != null)
353     {
354       keyboardNo2.append(value);
355     }
356     else
357     {
358       keyboardNo1.append(value);
359     }
360   }
361
362   int getKeyboardNo1()
363   {
364     try
365     {
366       if (keyboardNo1 != null)
367       {
368         int value = Integer.parseInt(keyboardNo1.toString());
369         keyboardNo1 = null;
370         return value;
371       }
372     } catch (Exception x)
373     {
374     }
375     keyboardNo1 = null;
376     return 1;
377   }
378
379   int getKeyboardNo2()
380   {
381     try
382     {
383       if (keyboardNo2 != null)
384       {
385         int value = Integer.parseInt(keyboardNo2.toString());
386         keyboardNo2 = null;
387         return value;
388       }
389     } catch (Exception x)
390     {
391     }
392     keyboardNo2 = null;
393     return 1;
394   }
395
396   void setStatusMessage(SequenceI sequence, int res, int seq)
397   {
398     StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: "
399             + sequence.getName());
400
401     Object obj = null;
402     if (av.getAlignment().isNucleotide())
403     {
404       obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res)
405               + "");
406       if (obj != null)
407       {
408         text.append(" Nucleotide: ");
409       }
410     }
411     else
412     {
413       obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
414       if (obj != null)
415       {
416         text.append("  Residue: ");
417       }
418     }
419
420     if (obj != null)
421     {
422
423       if (obj != "")
424       {
425         text.append(obj + " (" + sequence.findPosition(res) + ")");
426       }
427     }
428
429     ap.alignFrame.statusBar.setText(text.toString());
430
431   }
432
433   public void mousePressed(MouseEvent evt)
434   {
435     lastMousePress = evt.getPoint();
436
437     // For now, ignore the mouseWheel font resizing on Macs
438     // As the Button2_mask always seems to be true
439     if ((evt.getModifiers() & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK
440             && !av.MAC)
441     {
442       mouseWheelPressed = true;
443       return;
444     }
445
446     if (evt.isShiftDown() || evt.isControlDown() || evt.isAltDown())
447     {
448       if (evt.isControlDown() || evt.isAltDown())
449       {
450         groupEditing = true;
451       }
452       editingSeqs = true;
453     }
454     else
455     {
456       doMousePressedDefineMode(evt);
457       return;
458     }
459
460     int seq = findSeq(evt);
461     int res = findRes(evt);
462
463     if (seq < 0 || res < 0)
464     {
465       return;
466     }
467
468     if ((seq < av.getAlignment().getHeight())
469             && (res < av.getAlignment().getSequenceAt(seq).getLength()))
470     {
471       startseq = seq;
472       lastres = res;
473     }
474     else
475     {
476       startseq = -1;
477       lastres = -1;
478     }
479
480     return;
481   }
482
483   public void mouseClicked(MouseEvent evt)
484   {
485     SequenceI sequence = av.getAlignment().getSequenceAt(findSeq(evt));
486     if (evt.getClickCount() > 1)
487     {
488       if (av.getSelectionGroup() != null
489               && av.getSelectionGroup().getSize() == 1
490               && av.getSelectionGroup().getEndRes()
491                       - av.getSelectionGroup().getStartRes() < 2)
492       {
493         av.setSelectionGroup(null);
494       }
495
496       SequenceFeature[] features = findFeaturesAtRes(sequence,
497               sequence.findPosition(findRes(evt)));
498
499       if (features != null && features.length > 0)
500       {
501         SearchResults highlight = new SearchResults();
502         highlight.addResult(sequence, features[0].getBegin(),
503                 features[0].getEnd());
504         seqCanvas.highlightSearchResults(highlight);
505       }
506       if (features != null && features.length > 0)
507       {
508         seqCanvas.getFeatureRenderer().amendFeatures(new SequenceI[]
509         { sequence }, features, false, ap);
510
511         seqCanvas.highlightSearchResults(null);
512       }
513     }
514   }
515
516   public void mouseReleased(MouseEvent evt)
517   {
518     mouseDragging = false;
519     mouseWheelPressed = false;
520     ap.paintAlignment(true);
521
522     if (!editingSeqs)
523     {
524       doMouseReleasedDefineMode(evt);
525       return;
526     }
527
528     endEditing();
529
530   }
531
532   int startWrapBlock = -1;
533
534   int wrappedBlock = -1;
535
536   int findRes(MouseEvent evt)
537   {
538     int res = 0;
539     int x = evt.getX();
540
541     if (av.wrapAlignment)
542     {
543
544       int hgap = av.charHeight;
545       if (av.scaleAboveWrapped)
546       {
547         hgap += av.charHeight;
548       }
549
550       int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
551               + seqCanvas.getAnnotationHeight();
552
553       int y = evt.getY();
554       y -= hgap;
555       x -= seqCanvas.LABEL_WEST;
556
557       int cwidth = seqCanvas.getWrappedCanvasWidth(getSize().width);
558       if (cwidth < 1)
559       {
560         return 0;
561       }
562
563       wrappedBlock = y / cHeight;
564       wrappedBlock += av.getStartRes() / cwidth;
565
566       res = wrappedBlock * cwidth + x / av.getCharWidth();
567
568     }
569     else
570     {
571       res = (x / av.getCharWidth()) + av.getStartRes();
572     }
573
574     if (av.hasHiddenColumns())
575     {
576       res = av.getColumnSelection().adjustForHiddenColumns(res);
577     }
578
579     return res;
580
581   }
582
583   int findSeq(MouseEvent evt)
584   {
585     final int sqnum = findAlRow(evt);
586     return (sqnum < 0) ? 0 : sqnum;
587   }
588
589   /**
590    * 
591    * @param evt
592    * @return row in alignment that was selected (or -1 for column selection)
593    */
594   private int findAlRow(MouseEvent evt)
595   {
596     int seq = 0;
597     int y = evt.getY();
598
599     if (av.wrapAlignment)
600     {
601       int hgap = av.charHeight;
602       if (av.scaleAboveWrapped)
603       {
604         hgap += av.charHeight;
605       }
606
607       int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
608               + seqCanvas.getAnnotationHeight();
609
610       y -= hgap;
611
612       seq = Math.min((y % cHeight) / av.getCharHeight(), av.getAlignment()
613               .getHeight() - 1);
614       if (seq < 0)
615       {
616         seq = -1;
617       }
618     }
619     else
620     {
621       seq = Math.min((y / av.getCharHeight()) + av.getStartSeq(), av
622               .getAlignment().getHeight() - 1);
623       if (seq < 0)
624       {
625         seq = -1;
626       }
627     }
628
629     return seq;
630   }
631
632   public void doMousePressed(MouseEvent evt)
633   {
634
635     int seq = findSeq(evt);
636     int res = findRes(evt);
637
638     if (seq < av.getAlignment().getHeight()
639             && res < av.getAlignment().getSequenceAt(seq).getLength())
640     {
641       // char resstr = align.getSequenceAt(seq).getSequence().charAt(res);
642       // Find the residue's position in the sequence (res is the position
643       // in the alignment
644
645       startseq = seq;
646       lastres = res;
647     }
648     else
649     {
650       startseq = -1;
651       lastres = -1;
652     }
653
654     return;
655   }
656
657   String lastMessage;
658
659   public void mouseOverSequence(SequenceI sequence, int index, int pos)
660   {
661     String tmp = sequence.hashCode() + index + "";
662     if (lastMessage == null || !lastMessage.equals(tmp))
663     {
664       ssm.mouseOverSequence(sequence, index, pos, av);
665     }
666
667     lastMessage = tmp;
668   }
669
670   public void highlightSequence(SearchResults results)
671   {
672     if (av.followHighlight)
673     {
674       if (ap.scrollToPosition(results, true))
675       {
676         ap.alignFrame.repaint();
677       }
678     }
679     seqCanvas.highlightSearchResults(results);
680
681   }
682
683   public void updateColours(SequenceI seq, int index)
684   {
685     System.out.println("update the seqPanel colours");
686     // repaint();
687   }
688
689   public void mouseMoved(MouseEvent evt)
690   {
691     int res = findRes(evt);
692     int seq = findSeq(evt);
693
694     if (seq >= av.getAlignment().getHeight() || seq < 0 || res < 0)
695     {
696       if (tooltip != null)
697       {
698         tooltip.setTip("");
699       }
700       return;
701     }
702
703     SequenceI sequence = av.getAlignment().getSequenceAt(seq);
704     if (res > sequence.getLength())
705     {
706       if (tooltip != null)
707       {
708         tooltip.setTip("");
709       }
710       return;
711     }
712
713     int respos = sequence.findPosition(res);
714     if (ssm != null)
715     {
716       mouseOverSequence(sequence, res, respos);
717     }
718
719     StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: "
720             + sequence.getName());
721
722     Object obj = null;
723     if (av.getAlignment().isNucleotide())
724     {
725       obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res)
726               + "");
727       if (obj != null)
728       {
729         text.append(" Nucleotide: ");
730       }
731     }
732     else
733     {
734       obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
735       if (obj != null)
736       {
737         text.append("  Residue: ");
738       }
739     }
740
741     if (obj != null)
742     {
743       if (obj != "")
744       {
745         text.append(obj + " (" + respos + ")");
746       }
747     }
748
749     ap.alignFrame.statusBar.setText(text.toString());
750
751     StringBuffer tooltipText = new StringBuffer();
752     SequenceGroup[] groups = av.getAlignment().findAllGroups(sequence);
753     if (groups != null)
754     {
755       for (int g = 0; g < groups.length; g++)
756       {
757         if (groups[g].getStartRes() <= res && groups[g].getEndRes() >= res)
758         {
759           if (!groups[g].getName().startsWith("JTreeGroup")
760                   && !groups[g].getName().startsWith("JGroup"))
761           {
762             tooltipText.append(groups[g].getName() + " ");
763           }
764           if (groups[g].getDescription() != null)
765           {
766             tooltipText.append(groups[g].getDescription());
767           }
768           tooltipText.append("\n");
769         }
770       }
771     }
772
773     // use aa to see if the mouse pointer is on a
774     SequenceFeature[] allFeatures = findFeaturesAtRes(sequence,
775             sequence.findPosition(res));
776
777     int index = 0;
778     while (index < allFeatures.length)
779     {
780       SequenceFeature sf = allFeatures[index];
781
782       tooltipText.append(sf.getType() + " " + sf.begin + ":" + sf.end);
783
784       if (sf.getDescription() != null)
785       {
786         tooltipText.append(" " + sf.getDescription());
787       }
788
789       if (sf.getValue("status") != null)
790       {
791         String status = sf.getValue("status").toString();
792         if (status.length() > 0)
793         {
794           tooltipText.append(" (" + sf.getValue("status") + ")");
795         }
796       }
797       tooltipText.append("\n");
798
799       index++;
800     }
801
802     if (tooltip == null)
803     {
804       tooltip = new Tooltip(tooltipText.toString(), seqCanvas);
805     }
806     else
807     {
808       tooltip.setTip(tooltipText.toString());
809     }
810   }
811
812   SequenceFeature[] findFeaturesAtRes(SequenceI sequence, int res)
813   {
814     Vector tmp = new Vector();
815     SequenceFeature[] features = sequence.getSequenceFeatures();
816     if (features != null)
817     {
818       for (int i = 0; i < features.length; i++)
819       {
820         if (av.getFeaturesDisplayed() == null
821                 || !av.getFeaturesDisplayed().isVisible(features[i].getType()))
822         {
823           continue;
824         }
825
826         if (features[i].featureGroup != null
827                 && !seqCanvas.fr.checkGroupVisibility(features[i].featureGroup,false))
828         {
829           continue;
830         }
831
832         if ((features[i].getBegin() <= res)
833                 && (features[i].getEnd() >= res))
834         {
835           tmp.addElement(features[i]);
836         }
837       }
838     }
839
840     features = new SequenceFeature[tmp.size()];
841     tmp.copyInto(features);
842
843     return features;
844   }
845
846   Tooltip tooltip;
847
848   public void mouseDragged(MouseEvent evt)
849   {
850     if (mouseWheelPressed)
851     {
852       int oldWidth = av.charWidth;
853
854       // Which is bigger, left-right or up-down?
855       if (Math.abs(evt.getY() - lastMousePress.y) > Math.abs(evt.getX()
856               - lastMousePress.x))
857       {
858         int fontSize = av.font.getSize();
859
860         if (evt.getY() < lastMousePress.y && av.charHeight > 1)
861         {
862           fontSize--;
863         }
864         else if (evt.getY() > lastMousePress.y)
865         {
866           fontSize++;
867         }
868
869         if (fontSize < 1)
870         {
871           fontSize = 1;
872         }
873
874         av.setFont(new Font(av.font.getName(), av.font.getStyle(), fontSize));
875         av.charWidth = oldWidth;
876       }
877       else
878       {
879         if (evt.getX() < lastMousePress.x && av.charWidth > 1)
880         {
881           av.charWidth--;
882         }
883         else if (evt.getX() > lastMousePress.x)
884         {
885           av.charWidth++;
886         }
887
888         if (av.charWidth < 1)
889         {
890           av.charWidth = 1;
891         }
892       }
893
894       ap.fontChanged();
895
896       FontMetrics fm = getFontMetrics(av.getFont());
897       av.validCharWidth = fm.charWidth('M') <= av.charWidth;
898
899       lastMousePress = evt.getPoint();
900
901       ap.paintAlignment(false);
902       ap.annotationPanel.image = null;
903       return;
904     }
905
906     if (!editingSeqs)
907     {
908       doMouseDraggedDefineMode(evt);
909       return;
910     }
911
912     int res = findRes(evt);
913
914     if (res < 0)
915     {
916       res = 0;
917     }
918
919     if ((lastres == -1) || (lastres == res))
920     {
921       return;
922     }
923
924     if ((res < av.getAlignment().getWidth()) && (res < lastres))
925     {
926       // dragLeft, delete gap
927       editSequence(false, res);
928     }
929     else
930     {
931       editSequence(true, res);
932     }
933
934     mouseDragging = true;
935     if (scrollThread != null)
936     {
937       scrollThread.setEvent(evt);
938     }
939
940   }
941
942   synchronized void editSequence(boolean insertGap, int startres)
943   {
944     int fixedLeft = -1;
945     int fixedRight = -1;
946     boolean fixedColumns = false;
947     SequenceGroup sg = av.getSelectionGroup();
948
949     SequenceI seq = av.getAlignment().getSequenceAt(startseq);
950
951     if (!groupEditing && av.hasHiddenRows())
952     {
953       if (av.isHiddenRepSequence(seq))
954       {
955         sg = av.getRepresentedSequences(seq);
956         groupEditing = true;
957       }
958     }
959
960     StringBuffer message = new StringBuffer();
961     if (groupEditing)
962     {
963       message.append(MessageManager.getString("action.edit_group")).append(":");
964       if (editCommand == null)
965       {
966         editCommand = new EditCommand(MessageManager.getString("action.edit_group"));
967       }
968     }
969     else
970     {
971       message.append(MessageManager.getString("label.edit_sequence")).append(" " + seq.getName());
972       String label = seq.getName();
973       if (label.length() > 10)
974       {
975         label = label.substring(0, 10);
976       }
977       if (editCommand == null)
978       {
979         editCommand = new EditCommand(MessageManager.formatMessage("label.edit_params", new String[]{label}));
980       }
981     }
982
983     if (insertGap)
984     {
985       message.append(" insert ");
986     }
987     else
988     {
989       message.append(" delete ");
990     }
991
992     message.append(Math.abs(startres - lastres) + " gaps.");
993     ap.alignFrame.statusBar.setText(message.toString());
994
995     // Are we editing within a selection group?
996     if (groupEditing
997             || (sg != null && sg.getSequences(av.getHiddenRepSequences())
998                     .contains(seq)))
999     {
1000       fixedColumns = true;
1001
1002       // sg might be null as the user may only see 1 sequence,
1003       // but the sequence represents a group
1004       if (sg == null)
1005       {
1006         if (!av.isHiddenRepSequence(seq))
1007         {
1008           endEditing();
1009           return;
1010         }
1011
1012         sg = av.getRepresentedSequences(seq);
1013       }
1014
1015       fixedLeft = sg.getStartRes();
1016       fixedRight = sg.getEndRes();
1017
1018       if ((startres < fixedLeft && lastres >= fixedLeft)
1019               || (startres >= fixedLeft && lastres < fixedLeft)
1020               || (startres > fixedRight && lastres <= fixedRight)
1021               || (startres <= fixedRight && lastres > fixedRight))
1022       {
1023         endEditing();
1024         return;
1025       }
1026
1027       if (fixedLeft > startres)
1028       {
1029         fixedRight = fixedLeft - 1;
1030         fixedLeft = 0;
1031       }
1032       else if (fixedRight < startres)
1033       {
1034         fixedLeft = fixedRight;
1035         fixedRight = -1;
1036       }
1037     }
1038
1039     if (av.hasHiddenColumns())
1040     {
1041       fixedColumns = true;
1042       int y1 = av.getColumnSelection().getHiddenBoundaryLeft(startres);
1043       int y2 = av.getColumnSelection().getHiddenBoundaryRight(startres);
1044
1045       if ((insertGap && startres > y1 && lastres < y1)
1046               || (!insertGap && startres < y2 && lastres > y2))
1047       {
1048         endEditing();
1049         return;
1050       }
1051
1052       // System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
1053       // Selection spans a hidden region
1054       if (fixedLeft < y1 && (fixedRight > y2 || fixedRight == -1))
1055       {
1056         if (startres >= y2)
1057         {
1058           fixedLeft = y2;
1059         }
1060         else
1061         {
1062           fixedRight = y2 - 1;
1063         }
1064       }
1065     }
1066
1067     if (groupEditing)
1068     {
1069       SequenceI[] groupSeqs = sg.getSequences(av.getHiddenRepSequences())
1070               .toArray(new SequenceI[0]);
1071
1072       // drag to right
1073       if (insertGap)
1074       {
1075         // If the user has selected the whole sequence, and is dragging to
1076         // the right, we can still extend the alignment and selectionGroup
1077         if (sg.getStartRes() == 0 && sg.getEndRes() == fixedRight
1078                 && sg.getEndRes() == av.getAlignment().getWidth() - 1)
1079         {
1080           sg.setEndRes(av.getAlignment().getWidth() + startres - lastres);
1081           fixedRight = sg.getEndRes();
1082         }
1083
1084         // Is it valid with fixed columns??
1085         // Find the next gap before the end
1086         // of the visible region boundary
1087         boolean blank = false;
1088         for (fixedRight = fixedRight; fixedRight > lastres; fixedRight--)
1089         {
1090           blank = true;
1091
1092           for (SequenceI gs : groupSeqs)
1093           {
1094             for (int j = 0; j < startres - lastres; j++)
1095             {
1096               if (!jalview.util.Comparison.isGap(gs.getCharAt(fixedRight
1097                       - j)))
1098               {
1099                 blank = false;
1100                 break;
1101               }
1102             }
1103           }
1104           if (blank)
1105           {
1106             break;
1107           }
1108         }
1109
1110         if (!blank)
1111         {
1112           if (sg.getSize() == av.getAlignment().getHeight())
1113           {
1114             if ((av.hasHiddenColumns() && startres < av
1115                     .getColumnSelection().getHiddenBoundaryRight(startres)))
1116             {
1117               endEditing();
1118               return;
1119             }
1120
1121             int alWidth = av.getAlignment().getWidth();
1122             if (av.hasHiddenRows())
1123             {
1124               int hwidth = av.getAlignment().getHiddenSequences()
1125                       .getWidth();
1126               if (hwidth > alWidth)
1127               {
1128                 alWidth = hwidth;
1129               }
1130             }
1131             // We can still insert gaps if the selectionGroup
1132             // contains all the sequences
1133             sg.setEndRes(sg.getEndRes() + startres - lastres);
1134             fixedRight = alWidth + startres - lastres;
1135           }
1136           else
1137           {
1138             endEditing();
1139             return;
1140           }
1141         }
1142       }
1143
1144       // drag to left
1145       else if (!insertGap)
1146       {
1147         // / Are we able to delete?
1148         // ie are all columns blank?
1149
1150         for (SequenceI gs : groupSeqs)
1151         {
1152           for (int j = startres; j < lastres; j++)
1153           {
1154             if (gs.getLength() <= j)
1155             {
1156               continue;
1157             }
1158
1159             if (!jalview.util.Comparison.isGap(gs.getCharAt(j)))
1160             {
1161               // Not a gap, block edit not valid
1162               endEditing();
1163               return;
1164             }
1165           }
1166         }
1167       }
1168
1169       if (insertGap)
1170       {
1171         // dragging to the right
1172         if (fixedColumns && fixedRight != -1)
1173         {
1174           for (int j = lastres; j < startres; j++)
1175           {
1176             insertChar(j, groupSeqs, fixedRight);
1177           }
1178         }
1179         else
1180         {
1181           editCommand.appendEdit(Action.INSERT_GAP, groupSeqs,
1182                   startres, startres - lastres, av.getAlignment(), true);
1183         }
1184       }
1185       else
1186       {
1187         // dragging to the left
1188         if (fixedColumns && fixedRight != -1)
1189         {
1190           for (int j = lastres; j > startres; j--)
1191           {
1192             deleteChar(startres, groupSeqs, fixedRight);
1193           }
1194         }
1195         else
1196         {
1197           editCommand.appendEdit(Action.DELETE_GAP, groupSeqs,
1198                   startres, lastres - startres, av.getAlignment(), true);
1199         }
1200
1201       }
1202     }
1203     else
1204     // ///Editing a single sequence///////////
1205     {
1206       if (insertGap)
1207       {
1208         // dragging to the right
1209         if (fixedColumns && fixedRight != -1)
1210         {
1211           for (int j = lastres; j < startres; j++)
1212           {
1213             insertChar(j, new SequenceI[]
1214             { seq }, fixedRight);
1215           }
1216         }
1217         else
1218         {
1219           editCommand.appendEdit(Action.INSERT_GAP, new SequenceI[]
1220           { seq }, lastres, startres - lastres, av.getAlignment(), true);
1221         }
1222       }
1223       else
1224       {
1225         // dragging to the left
1226         if (fixedColumns && fixedRight != -1)
1227         {
1228           for (int j = lastres; j > startres; j--)
1229           {
1230             if (!jalview.util.Comparison.isGap(seq.getCharAt(startres)))
1231             {
1232               endEditing();
1233               break;
1234             }
1235             deleteChar(startres, new SequenceI[]
1236             { seq }, fixedRight);
1237           }
1238         }
1239         else
1240         {
1241           // could be a keyboard edit trying to delete none gaps
1242           int max = 0;
1243           for (int m = startres; m < lastres; m++)
1244           {
1245             if (!jalview.util.Comparison.isGap(seq.getCharAt(m)))
1246             {
1247               break;
1248             }
1249             max++;
1250           }
1251
1252           if (max > 0)
1253           {
1254             editCommand.appendEdit(Action.DELETE_GAP, new SequenceI[]
1255             { seq }, startres, max, av.getAlignment(), true);
1256           }
1257         }
1258       }
1259     }
1260
1261     lastres = startres;
1262     seqCanvas.repaint();
1263   }
1264
1265   void insertChar(int j, SequenceI[] seq, int fixedColumn)
1266   {
1267     int blankColumn = fixedColumn;
1268     for (int s = 0; s < seq.length; s++)
1269     {
1270       // Find the next gap before the end of the visible region boundary
1271       // If lastCol > j, theres a boundary after the gap insertion
1272
1273       for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
1274       {
1275         if (jalview.util.Comparison.isGap(seq[s].getCharAt(blankColumn)))
1276         {
1277           // Theres a space, so break and insert the gap
1278           break;
1279         }
1280       }
1281
1282       if (blankColumn <= j)
1283       {
1284         blankColumn = fixedColumn;
1285         endEditing();
1286         return;
1287       }
1288     }
1289
1290     editCommand.appendEdit(Action.DELETE_GAP, seq, blankColumn, 1,
1291             av.getAlignment(), true);
1292
1293     editCommand.appendEdit(Action.INSERT_GAP, seq, j, 1,
1294             av.getAlignment(), true);
1295
1296   }
1297
1298   void deleteChar(int j, SequenceI[] seq, int fixedColumn)
1299   {
1300
1301     editCommand.appendEdit(Action.DELETE_GAP, seq, j, 1,
1302             av.getAlignment(), true);
1303
1304     editCommand.appendEdit(Action.INSERT_GAP, seq, fixedColumn, 1,
1305             av.getAlignment(), true);
1306   }
1307
1308   // ////////////////////////////////////////
1309   // ///Everything below this is for defining the boundary of the rubberband
1310   // ////////////////////////////////////////
1311   public void doMousePressedDefineMode(MouseEvent evt)
1312   {
1313     if (scrollThread != null)
1314     {
1315       scrollThread.running = false;
1316       scrollThread = null;
1317     }
1318
1319     int res = findRes(evt);
1320     int seq = findSeq(evt);
1321     oldSeq = seq;
1322     startWrapBlock = wrappedBlock;
1323
1324     if (seq == -1)
1325     {
1326       return;
1327     }
1328
1329     SequenceI sequence = av.getAlignment().getSequenceAt(seq);
1330
1331     if (sequence == null || res > sequence.getLength())
1332     {
1333       return;
1334     }
1335
1336     stretchGroup = av.getSelectionGroup();
1337
1338     if (stretchGroup == null)
1339     {
1340       stretchGroup = av.getAlignment().findGroup(sequence);
1341       if (stretchGroup != null && res > stretchGroup.getStartRes()
1342               && res < stretchGroup.getEndRes())
1343       {
1344         av.setSelectionGroup(stretchGroup);
1345       }
1346       else
1347       {
1348         stretchGroup = null;
1349       }
1350     }
1351
1352     else if (!stretchGroup.getSequences(null).contains(sequence)
1353             || stretchGroup.getStartRes() > res
1354             || stretchGroup.getEndRes() < res)
1355     {
1356       stretchGroup = null;
1357
1358       SequenceGroup[] allGroups = av.getAlignment().findAllGroups(sequence);
1359
1360       if (allGroups != null)
1361       {
1362         for (int i = 0; i < allGroups.length; i++)
1363         {
1364           if (allGroups[i].getStartRes() <= res
1365                   && allGroups[i].getEndRes() >= res)
1366           {
1367             stretchGroup = allGroups[i];
1368             break;
1369           }
1370         }
1371       }
1372       av.setSelectionGroup(stretchGroup);
1373     }
1374
1375     // DETECT RIGHT MOUSE BUTTON IN AWT
1376     if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
1377     {
1378       SequenceFeature[] allFeatures = findFeaturesAtRes(sequence,
1379               sequence.findPosition(res));
1380
1381       Vector links = null;
1382       if (allFeatures != null)
1383       {
1384         for (int i = 0; i < allFeatures.length; i++)
1385         {
1386           if (allFeatures[i].links != null)
1387           {
1388             if (links == null)
1389             {
1390               links = new Vector();
1391             }
1392             for (int j = 0; j < allFeatures[i].links.size(); j++)
1393             {
1394               links.addElement(allFeatures[i].links.elementAt(j));
1395             }
1396           }
1397         }
1398       }
1399       APopupMenu popup = new APopupMenu(ap, null, links);
1400       this.add(popup);
1401       popup.show(this, evt.getX(), evt.getY());
1402       return;
1403     }
1404
1405     if (av.cursorMode)
1406     {
1407       seqCanvas.cursorX = findRes(evt);
1408       seqCanvas.cursorY = findSeq(evt);
1409       seqCanvas.repaint();
1410       return;
1411     }
1412
1413     // Only if left mouse button do we want to change group sizes
1414
1415     if (stretchGroup == null)
1416     {
1417       // define a new group here
1418       SequenceGroup sg = new SequenceGroup();
1419       sg.setStartRes(res);
1420       sg.setEndRes(res);
1421       sg.addSequence(sequence, false);
1422       av.setSelectionGroup(sg);
1423       stretchGroup = sg;
1424
1425       if (av.getConservationSelected())
1426       {
1427         SliderPanel.setConservationSlider(ap, av.getGlobalColourScheme(),
1428                 "Background");
1429       }
1430       if (av.getAbovePIDThreshold())
1431       {
1432         SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(),
1433                 "Background");
1434       }
1435
1436     }
1437   }
1438
1439   public void doMouseReleasedDefineMode(MouseEvent evt)
1440   {
1441     if (stretchGroup == null)
1442     {
1443       return;
1444     }
1445
1446     stretchGroup.recalcConservation(); // always do this - annotation has own
1447                                        // state
1448     if (stretchGroup.cs != null)
1449     {
1450       stretchGroup.cs.alignmentChanged(stretchGroup,
1451               av.getHiddenRepSequences());
1452
1453       if (stretchGroup.cs.conservationApplied())
1454       {
1455         SliderPanel.setConservationSlider(ap, stretchGroup.cs,
1456                 stretchGroup.getName());
1457       }
1458       else
1459       {
1460         SliderPanel.setPIDSliderSource(ap, stretchGroup.cs,
1461                 stretchGroup.getName());
1462       }
1463     }
1464     changeEndRes = false;
1465     changeStartRes = false;
1466     stretchGroup = null;
1467     PaintRefresher.Refresh(ap, av.getSequenceSetId());
1468     ap.paintAlignment(true);
1469     av.sendSelection();
1470   }
1471
1472   public void doMouseDraggedDefineMode(MouseEvent evt)
1473   {
1474     int res = findRes(evt);
1475     int y = findSeq(evt);
1476
1477     if (wrappedBlock != startWrapBlock)
1478     {
1479       return;
1480     }
1481
1482     if (stretchGroup == null)
1483     {
1484       return;
1485     }
1486
1487     mouseDragging = true;
1488
1489     if (y > av.getAlignment().getHeight())
1490     {
1491       y = av.getAlignment().getHeight() - 1;
1492     }
1493
1494     if (res >= av.getAlignment().getWidth())
1495     {
1496       res = av.getAlignment().getWidth() - 1;
1497     }
1498
1499     if (stretchGroup.getEndRes() == res)
1500     {
1501       // Edit end res position of selected group
1502       changeEndRes = true;
1503     }
1504     else if (stretchGroup.getStartRes() == res)
1505     {
1506       // Edit start res position of selected group
1507       changeStartRes = true;
1508     }
1509
1510     if (res < 0)
1511     {
1512       res = 0;
1513     }
1514
1515     if (changeEndRes)
1516     {
1517       if (res > (stretchGroup.getStartRes() - 1))
1518       {
1519         stretchGroup.setEndRes(res);
1520       }
1521     }
1522     else if (changeStartRes)
1523     {
1524       if (res < (stretchGroup.getEndRes() + 1))
1525       {
1526         stretchGroup.setStartRes(res);
1527       }
1528     }
1529
1530     int dragDirection = 0;
1531
1532     if (y > oldSeq)
1533     {
1534       dragDirection = 1;
1535     }
1536     else if (y < oldSeq)
1537     {
1538       dragDirection = -1;
1539     }
1540
1541     while ((y != oldSeq) && (oldSeq > -1)
1542             && (y < av.getAlignment().getHeight()))
1543     {
1544       // This routine ensures we don't skip any sequences, as the
1545       // selection is quite slow.
1546       Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
1547
1548       oldSeq += dragDirection;
1549
1550       if (oldSeq < 0)
1551       {
1552         break;
1553       }
1554
1555       Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
1556
1557       if (stretchGroup.getSequences(null).contains(nextSeq))
1558       {
1559         stretchGroup.deleteSequence(seq, false);
1560       }
1561       else
1562       {
1563         if (seq != null)
1564         {
1565           stretchGroup.addSequence(seq, false);
1566         }
1567
1568         stretchGroup.addSequence(nextSeq, false);
1569       }
1570     }
1571
1572     if (oldSeq < 0)
1573     {
1574       oldSeq = -1;
1575     }
1576
1577     if (res > av.endRes || res < av.startRes || y < av.startSeq
1578             || y > av.endSeq)
1579     {
1580       mouseExited(evt);
1581     }
1582
1583     if (scrollThread != null)
1584     {
1585       scrollThread.setEvent(evt);
1586     }
1587
1588     seqCanvas.repaint();
1589   }
1590
1591   public void mouseEntered(MouseEvent e)
1592   {
1593     if (oldSeq < 0)
1594     {
1595       oldSeq = 0;
1596     }
1597
1598     if (scrollThread != null)
1599     {
1600       scrollThread.running = false;
1601       scrollThread = null;
1602     }
1603   }
1604
1605   public void mouseExited(MouseEvent e)
1606   {
1607     if (av.getWrapAlignment())
1608     {
1609       return;
1610     }
1611
1612     if (mouseDragging && scrollThread == null)
1613     {
1614       scrollThread = new ScrollThread();
1615     }
1616   }
1617
1618   void scrollCanvas(MouseEvent evt)
1619   {
1620     if (evt == null)
1621     {
1622       if (scrollThread != null)
1623       {
1624         scrollThread.running = false;
1625         scrollThread = null;
1626       }
1627       mouseDragging = false;
1628     }
1629     else
1630     {
1631       if (scrollThread == null)
1632       {
1633         scrollThread = new ScrollThread();
1634       }
1635
1636       mouseDragging = true;
1637       scrollThread.setEvent(evt);
1638     }
1639
1640   }
1641
1642   // this class allows scrolling off the bottom of the visible alignment
1643   class ScrollThread extends Thread
1644   {
1645     MouseEvent evt;
1646
1647     boolean running = false;
1648
1649     public ScrollThread()
1650     {
1651       start();
1652     }
1653
1654     public void setEvent(MouseEvent e)
1655     {
1656       evt = e;
1657     }
1658
1659     public void stopScrolling()
1660     {
1661       running = false;
1662     }
1663
1664     public void run()
1665     {
1666       running = true;
1667       while (running)
1668       {
1669
1670         if (evt != null)
1671         {
1672
1673           if (mouseDragging && evt.getY() < 0 && av.getStartSeq() > 0)
1674           {
1675             running = ap.scrollUp(true);
1676           }
1677
1678           if (mouseDragging && evt.getY() >= getSize().height
1679                   && av.getAlignment().getHeight() > av.getEndSeq())
1680           {
1681             running = ap.scrollUp(false);
1682           }
1683
1684           if (mouseDragging && evt.getX() < 0)
1685           {
1686             running = ap.scrollRight(false);
1687           }
1688
1689           else if (mouseDragging && evt.getX() >= getSize().width)
1690           {
1691             running = ap.scrollRight(true);
1692           }
1693         }
1694
1695         try
1696         {
1697           Thread.sleep(75);
1698         } catch (Exception ex)
1699         {
1700         }
1701       }
1702     }
1703   }
1704
1705   /**
1706    * modify current selection according to a received message.
1707    */
1708   public void selection(SequenceGroup seqsel, ColumnSelection colsel,
1709           SelectionSource source)
1710   {
1711     // TODO: fix this hack - source of messages is align viewport, but SeqPanel
1712     // handles selection messages...
1713     // TODO: extend config options to allow user to control if selections may be
1714     // shared between viewports.
1715     if (av != null
1716             && (av == source || !av.followSelection || (source instanceof AlignViewport && ((AlignViewport) source)
1717                     .getSequenceSetId().equals(av.getSequenceSetId()))))
1718     {
1719       return;
1720     }
1721     // do we want to thread this ? (contention with seqsel and colsel locks, I
1722     // suspect)
1723     // rules are: colsel is copied if there is a real intersection between
1724     // sequence selection
1725     boolean repaint = false, copycolsel = true;
1726     if (av.getSelectionGroup() == null || !av.isSelectionGroupChanged(true))
1727     {
1728       SequenceGroup sgroup = null;
1729       if (seqsel != null && seqsel.getSize() > 0)
1730       {
1731         if (av.getAlignment() == null)
1732         {
1733           System.out
1734                   .println("Selection message: alignviewport av SeqSetId="
1735                           + av.getSequenceSetId() + " ViewId="
1736                           + av.getViewId()
1737                           + " 's alignment is NULL! returning immediatly.");
1738           return;
1739         }
1740         sgroup = seqsel.intersect(av.getAlignment(),
1741                 (av.hasHiddenRows()) ? av.getHiddenRepSequences() : null);
1742         if ((sgroup == null || sgroup.getSize() == 0)
1743                 && (colsel == null || colsel.size() == 0))
1744         {
1745           // don't copy columns if the region didn't intersect.
1746           copycolsel = false;
1747         }
1748       }
1749       if (sgroup != null && sgroup.getSize() > 0)
1750       {
1751         av.setSelectionGroup(sgroup);
1752       }
1753       else
1754       {
1755         av.setSelectionGroup(null);
1756       }
1757       repaint = av.isSelectionGroupChanged(true);
1758     }
1759     if (copycolsel
1760             && (av.getColumnSelection() == null || !av
1761                     .isColSelChanged(true)))
1762     {
1763       // the current selection is unset or from a previous message
1764       // so import the new colsel.
1765       if (colsel == null || colsel.size() == 0)
1766       {
1767         if (av.getColumnSelection() != null)
1768         {
1769           av.getColumnSelection().clear();
1770         }
1771       }
1772       else
1773       {
1774         // TODO: shift colSel according to the intersecting sequences
1775         if (av.getColumnSelection() == null)
1776         {
1777           av.setColumnSelection(new ColumnSelection(colsel));
1778         }
1779         else
1780         {
1781           av.getColumnSelection().setElementsFrom(colsel);
1782         }
1783       }
1784       repaint |= av.isColSelChanged(true);
1785     }
1786     if (copycolsel
1787             && av.hasHiddenColumns()
1788             && (av.getColumnSelection() == null || av.getColumnSelection()
1789                     .getHiddenColumns() == null))
1790     {
1791       System.err.println("Bad things");
1792     }
1793     if (repaint)
1794     {
1795       ap.scalePanelHolder.repaint();
1796       ap.repaint();
1797     }
1798   }
1799
1800   /**
1801    * scroll to the given row/column - or nearest visible location
1802    * 
1803    * @param row
1804    * @param column
1805    */
1806   public void scrollTo(int row, int column)
1807   {
1808
1809     row = row < 0 ? ap.av.startSeq : row;
1810     column = column < 0 ? ap.av.startRes : column;
1811     ap.scrollTo(column, column, row, true, true);
1812   }
1813
1814   /**
1815    * scroll to the given row - or nearest visible location
1816    * 
1817    * @param row
1818    */
1819   public void scrollToRow(int row)
1820   {
1821
1822     row = row < 0 ? ap.av.startSeq : row;
1823     ap.scrollTo(ap.av.startRes, ap.av.startRes, row, true, true);
1824   }
1825
1826   /**
1827    * scroll to the given column - or nearest visible location
1828    * 
1829    * @param column
1830    */
1831   public void scrollToColumn(int column)
1832   {
1833
1834     column = column < 0 ? ap.av.startRes : column;
1835     ap.scrollTo(column, column, ap.av.startSeq, true, true);
1836   }
1837
1838 }