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