2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.appletgui;
\r
25 import java.awt.event.*;
\r
27 import jalview.commands.*;
\r
28 import jalview.datamodel.*;
\r
29 import jalview.schemes.*;
\r
30 import jalview.structure.SequenceListener;
\r
31 import jalview.structure.StructureSelectionManager;
\r
33 public class SeqPanel
\r
34 extends Panel implements MouseMotionListener, MouseListener, SequenceListener
\r
37 public SeqCanvas seqCanvas;
\r
38 public AlignmentPanel ap;
\r
40 protected int lastres;
\r
41 protected int startseq;
\r
43 protected AlignViewport av;
\r
45 // if character is inserted or deleted, we will need to recalculate the conservation
\r
46 boolean seqEditOccurred = false;
\r
48 ScrollThread scrollThread = null;
\r
49 boolean mouseDragging = false;
\r
50 boolean editingSeqs = false;
\r
51 boolean groupEditing = false;
\r
54 boolean changeEndSeq = false;
\r
55 boolean changeStartSeq = false;
\r
56 boolean changeEndRes = false;
\r
57 boolean changeStartRes = false;
\r
58 SequenceGroup stretchGroup = null;
\r
60 StringBuffer keyboardNo1;
\r
61 StringBuffer keyboardNo2;
\r
63 boolean mouseWheelPressed = false;
\r
64 Point lastMousePress;
\r
66 EditCommand editCommand;
\r
68 StructureSelectionManager ssm;
\r
71 public SeqPanel(AlignViewport avp, AlignmentPanel p)
\r
75 seqCanvas = new SeqCanvas(avp);
\r
76 setLayout(new BorderLayout());
\r
81 seqCanvas.addMouseMotionListener(this);
\r
82 seqCanvas.addMouseListener(this);
\r
83 ssm = StructureSelectionManager.getStructureSelectionManager();
\r
84 ssm.addStructureViewerListener(this);
\r
86 seqCanvas.repaint();
\r
91 if (editCommand != null && editCommand.getSize() > 0)
\r
93 ap.alignFrame.addHistoryItem(editCommand);
\r
94 av.firePropertyChange("alignment", null,
\r
95 av.getAlignment().getSequences());
\r
100 editingSeqs = false;
\r
101 groupEditing = false;
\r
102 keyboardNo1 = null;
\r
103 keyboardNo2 = null;
\r
104 editCommand = null;
\r
107 void setCursorRow()
\r
109 seqCanvas.cursorY = getKeyboardNo1() - 1;
\r
113 void setCursorColumn()
\r
115 seqCanvas.cursorX = getKeyboardNo1() - 1;
\r
119 void setCursorRowAndColumn()
\r
121 if (keyboardNo2 == null)
\r
123 keyboardNo2 = new StringBuffer();
\r
127 seqCanvas.cursorX = getKeyboardNo1() - 1;
\r
128 seqCanvas.cursorY = getKeyboardNo2() - 1;
\r
133 void setCursorPosition()
\r
135 SequenceI sequence =
\r
136 (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);
\r
138 seqCanvas.cursorX = sequence.findIndex(
\r
139 getKeyboardNo1() - 1
\r
144 void moveCursor(int dx, int dy)
\r
146 seqCanvas.cursorX += dx;
\r
147 seqCanvas.cursorY += dy;
\r
148 if (av.hasHiddenColumns && !av.colSel.isVisible(seqCanvas.cursorX))
\r
150 int original = seqCanvas.cursorX - dx;
\r
151 int maxWidth = av.alignment.getWidth();
\r
153 while (!av.colSel.isVisible(seqCanvas.cursorX)
\r
154 && seqCanvas.cursorX < maxWidth
\r
155 && seqCanvas.cursorX > 0)
\r
157 seqCanvas.cursorX += dx;
\r
160 if (seqCanvas.cursorX >= maxWidth
\r
161 || !av.colSel.isVisible(seqCanvas.cursorX))
\r
163 seqCanvas.cursorX = original;
\r
169 void scrollToVisible()
\r
171 if (seqCanvas.cursorX < 0)
\r
173 seqCanvas.cursorX = 0;
\r
175 else if (seqCanvas.cursorX > av.alignment.getWidth() - 1)
\r
177 seqCanvas.cursorX = av.alignment.getWidth() - 1;
\r
180 if (seqCanvas.cursorY < 0)
\r
182 seqCanvas.cursorY = 0;
\r
184 else if (seqCanvas.cursorY > av.alignment.getHeight() - 1)
\r
186 seqCanvas.cursorY = av.alignment.getHeight() - 1;
\r
190 if (av.wrapAlignment)
\r
192 ap.scrollToWrappedVisible(seqCanvas.cursorX);
\r
196 while (seqCanvas.cursorY < av.startSeq)
\r
200 while (seqCanvas.cursorY + 1 > av.endSeq)
\r
202 ap.scrollUp(false);
\r
204 while (seqCanvas.cursorX < av.colSel.adjustForHiddenColumns(av.startRes))
\r
207 if (!ap.scrollRight(false))
\r
212 while (seqCanvas.cursorX > av.colSel.adjustForHiddenColumns(av.endRes))
\r
214 if (!ap.scrollRight(true))
\r
220 setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY),
\r
221 seqCanvas.cursorX, seqCanvas.cursorY);
\r
223 seqCanvas.repaint();
\r
226 void setSelectionAreaAtCursor(boolean topLeft)
\r
228 SequenceI sequence =
\r
229 (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);
\r
231 if (av.getSelectionGroup() != null)
\r
233 SequenceGroup sg = av.selectionGroup;
\r
234 //Find the top and bottom of this group
\r
235 int min = av.alignment.getHeight(), max = 0;
\r
236 for (int i = 0; i < sg.getSize(); i++)
\r
238 int index = av.alignment.findIndex(sg.getSequenceAt(i));
\r
253 sg.setStartRes(seqCanvas.cursorX);
\r
254 if (sg.getEndRes() < seqCanvas.cursorX)
\r
256 sg.setEndRes(seqCanvas.cursorX);
\r
259 min = seqCanvas.cursorY;
\r
263 sg.setEndRes(seqCanvas.cursorX);
\r
264 if (sg.getStartRes() > seqCanvas.cursorX)
\r
266 sg.setStartRes(seqCanvas.cursorX);
\r
269 max = seqCanvas.cursorY + 1;
\r
274 // Only the user can do this
\r
275 av.setSelectionGroup(null);
\r
279 // Now add any sequences between min and max
\r
280 sg.getSequences(null).removeAllElements();
\r
281 for (int i = min; i < max; i++)
\r
283 sg.addSequence(av.alignment.getSequenceAt(i), false);
\r
288 if (av.getSelectionGroup() == null)
\r
290 SequenceGroup sg = new SequenceGroup();
\r
291 sg.setStartRes(seqCanvas.cursorX);
\r
292 sg.setEndRes(seqCanvas.cursorX);
\r
293 sg.addSequence(sequence, false);
\r
294 av.setSelectionGroup(sg);
\r
297 ap.paintAlignment(false);
\r
300 void insertGapAtCursor(boolean group)
\r
302 groupEditing = group;
\r
303 startseq = seqCanvas.cursorY;
\r
304 lastres = seqCanvas.cursorX;
\r
305 editSequence(true, seqCanvas.cursorX + getKeyboardNo1());
\r
309 void deleteGapAtCursor(boolean group)
\r
311 groupEditing = group;
\r
312 startseq = seqCanvas.cursorY;
\r
313 lastres = seqCanvas.cursorX + getKeyboardNo1();
\r
314 editSequence(false, seqCanvas.cursorX);
\r
318 void numberPressed(char value)
\r
320 if (keyboardNo1 == null)
\r
322 keyboardNo1 = new StringBuffer();
\r
325 if (keyboardNo2 != null)
\r
327 keyboardNo2.append(value);
\r
331 keyboardNo1.append(value);
\r
335 int getKeyboardNo1()
\r
337 if (keyboardNo1 == null)
\r
341 int value = Integer.parseInt(keyboardNo1.toString());
\r
342 keyboardNo1 = null;
\r
347 int getKeyboardNo2()
\r
349 if (keyboardNo2 == null)
\r
353 int value = Integer.parseInt(keyboardNo2.toString());
\r
354 keyboardNo2 = null;
\r
360 void setStatusMessage(SequenceI sequence, int res, int seq)
\r
362 StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " +
\r
363 sequence.getName());
\r
366 if (av.alignment.isNucleotide())
\r
368 obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) +
\r
372 text.append(" Nucleotide: ");
\r
377 obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
\r
380 text.append(" Residue: ");
\r
389 text.append(obj + " (" + sequence.findPosition(res) +
\r
394 ap.alignFrame.statusBar.setText(text.toString());
\r
398 public void mousePressed(MouseEvent evt)
\r
400 lastMousePress = evt.getPoint();
\r
402 //For now, ignore the mouseWheel font resizing on Macs
\r
403 //As the Button2_mask always seems to be true
\r
404 if ( (evt.getModifiers() & InputEvent.BUTTON2_MASK) ==
\r
405 InputEvent.BUTTON2_MASK && !av.MAC)
\r
407 mouseWheelPressed = true;
\r
411 if (evt.isShiftDown()
\r
412 || evt.isControlDown()
\r
413 || evt.isAltDown())
\r
415 if (evt.isControlDown() || evt.isAltDown())
\r
417 groupEditing = true;
\r
419 editingSeqs = true;
\r
423 doMousePressedDefineMode(evt);
\r
427 int seq = findSeq(evt);
\r
428 int res = findRes(evt);
\r
430 if (seq < 0 || res < 0)
\r
435 if ( (seq < av.getAlignment().getHeight()) &&
\r
436 (res < av.getAlignment().getSequenceAt(seq).getLength()))
\r
450 public void mouseClicked(MouseEvent evt)
\r
452 SequenceI sequence = av.alignment.getSequenceAt(findSeq(evt));
\r
453 if (evt.getClickCount() > 1)
\r
455 if (av.getSelectionGroup().getSize() == 1
\r
456 && av.getSelectionGroup().getEndRes()
\r
457 - av.getSelectionGroup().getStartRes() < 2)
\r
459 av.setSelectionGroup(null);
\r
462 SequenceFeature[] features = findFeaturesAtRes(
\r
464 sequence.findPosition(findRes(evt))
\r
467 if (features != null && features.length > 0)
\r
469 SearchResults highlight = new SearchResults();
\r
470 highlight.addResult(sequence,
\r
471 features[0].getBegin(),
\r
472 features[0].getEnd());
\r
473 seqCanvas.highlightSearchResults(highlight);
\r
475 if (features != null && features.length > 0)
\r
477 seqCanvas.getFeatureRenderer().amendFeatures(
\r
479 {sequence}, features, false, ap);
\r
481 seqCanvas.highlightSearchResults(null);
\r
486 public void mouseReleased(MouseEvent evt)
\r
488 mouseDragging = false;
\r
489 mouseWheelPressed = false;
\r
490 ap.paintAlignment(true);
\r
494 doMouseReleasedDefineMode(evt);
\r
502 int startWrapBlock = -1;
\r
503 int wrappedBlock = -1;
\r
504 int findRes(MouseEvent evt)
\r
507 int x = evt.getX();
\r
509 if (av.wrapAlignment)
\r
512 int hgap = av.charHeight;
\r
513 if (av.scaleAboveWrapped)
\r
515 hgap += av.charHeight;
\r
518 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
519 + hgap + seqCanvas.getAnnotationHeight();
\r
521 int y = evt.getY();
\r
523 x -= seqCanvas.LABEL_WEST;
\r
525 int cwidth = seqCanvas.getWrappedCanvasWidth(getSize().width);
\r
531 wrappedBlock = y / cHeight;
\r
532 wrappedBlock += av.getStartRes() / cwidth;
\r
534 res = wrappedBlock * cwidth + x / av.getCharWidth();
\r
539 res = (x / av.getCharWidth()) + av.getStartRes();
\r
542 if (av.hasHiddenColumns)
\r
544 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
551 int findSeq(MouseEvent evt)
\r
555 int y = evt.getY();
\r
557 if (av.wrapAlignment)
\r
559 int hgap = av.charHeight;
\r
560 if (av.scaleAboveWrapped)
\r
562 hgap += av.charHeight;
\r
565 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
566 + hgap + seqCanvas.getAnnotationHeight();
\r
570 seq = Math.min( (y % cHeight) / av.getCharHeight(),
\r
571 av.alignment.getHeight() - 1);
\r
579 seq = Math.min( (y / av.getCharHeight()) + av.getStartSeq(),
\r
580 av.alignment.getHeight() - 1);
\r
592 public void doMousePressed(MouseEvent evt)
\r
595 int seq = findSeq(evt);
\r
596 int res = findRes(evt);
\r
598 if (seq < av.getAlignment().getHeight() &&
\r
599 res < av.getAlignment().getSequenceAt(seq).getLength())
\r
601 //char resstr = align.getSequenceAt(seq).getSequence().charAt(res);
\r
602 // Find the residue's position in the sequence (res is the position
\r
603 // in the alignment
\r
618 String lastMessage;
\r
619 public void mouseOverSequence(SequenceI sequence, int index)
\r
621 String tmp = sequence.hashCode()+index+"";
\r
622 if (lastMessage == null || !lastMessage.equals(tmp))
\r
623 ssm.mouseOverSequence(sequence, index);
\r
629 public void highlightSequence(SearchResults results)
\r
631 seqCanvas.highlightSearchResults(results);
\r
634 public void updateColours(SequenceI seq, int index)
\r
636 System.out.println("update the seqPanel colours");
\r
640 public void mouseMoved(MouseEvent evt)
\r
642 int res = findRes(evt);
\r
643 int seq = findSeq(evt);
\r
645 if (seq >= av.getAlignment().getHeight() || seq < 0 || res < 0)
\r
647 if (tooltip != null)
\r
649 tooltip.setTip("");
\r
654 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
\r
655 if (res > sequence.getLength())
\r
657 if (tooltip != null)
\r
659 tooltip.setTip("");
\r
666 mouseOverSequence(sequence, sequence.findPosition(res));
\r
669 StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " +
\r
670 sequence.getName());
\r
673 if (av.alignment.isNucleotide())
\r
675 obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) +
\r
679 text.append(" Nucleotide: ");
\r
684 obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
\r
687 text.append(" Residue: ");
\r
695 text.append(obj + " (" + sequence.findPosition(res) + ")");
\r
699 ap.alignFrame.statusBar.setText(text.toString());
\r
701 StringBuffer tooltipText = new StringBuffer();
\r
702 SequenceGroup[] groups = av.alignment.findAllGroups(sequence);
\r
703 if (groups != null)
\r
705 for (int g = 0; g < groups.length; g++)
\r
707 if (groups[g].getStartRes() <= res && groups[g].getEndRes() >= res)
\r
709 if (!groups[g].getName().startsWith("JTreeGroup") &&
\r
710 !groups[g].getName().startsWith("JGroup"))
\r
712 tooltipText.append(groups[g].getName() + " ");
\r
714 if (groups[g].getDescription() != null)
\r
716 tooltipText.append(groups[g].getDescription());
\r
718 tooltipText.append("\n");
\r
723 // use aa to see if the mouse pointer is on a
\r
724 SequenceFeature [] allFeatures = findFeaturesAtRes(sequence,
\r
725 sequence.findPosition(res));
\r
728 while (index < allFeatures.length)
\r
730 SequenceFeature sf = allFeatures[index];
\r
732 tooltipText.append(sf.getType() + " " + sf.begin + ":" + sf.end);
\r
734 if (sf.getDescription() != null)
\r
736 tooltipText.append(" " + sf.getDescription());
\r
739 if (sf.getValue("status") != null)
\r
741 String status = sf.getValue("status").toString();
\r
742 if (status.length() > 0)
\r
744 tooltipText.append(" (" + sf.getValue("status") + ")");
\r
747 tooltipText.append("\n");
\r
752 if (tooltip == null)
\r
754 tooltip = new Tooltip(tooltipText.toString(), seqCanvas);
\r
758 tooltip.setTip(tooltipText.toString());
\r
762 SequenceFeature[] findFeaturesAtRes(SequenceI sequence, int res)
\r
764 Vector tmp = new Vector();
\r
765 SequenceFeature[] features = sequence.getSequenceFeatures();
\r
766 if (features != null)
\r
768 for (int i = 0; i < features.length; i++)
\r
770 if (av.featuresDisplayed == null
\r
771 || !av.featuresDisplayed.containsKey(features[i].getType()))
\r
778 if (features[i].featureGroup != null
\r
779 && seqCanvas.fr.featureGroups!=null
\r
780 && seqCanvas.fr.featureGroups.containsKey(features[i].featureGroup)
\r
781 && !((Boolean)seqCanvas.fr.featureGroups.get(features[i].featureGroup)).booleanValue())
\r
785 if ( (features[i].getBegin() <= res) &&
\r
786 (features[i].getEnd() >= res))
\r
788 tmp.addElement(features[i]);
\r
793 features = new SequenceFeature[tmp.size()];
\r
794 tmp.copyInto(features);
\r
802 public void mouseDragged(MouseEvent evt)
\r
804 if (mouseWheelPressed)
\r
806 int oldWidth = av.charWidth;
\r
808 //Which is bigger, left-right or up-down?
\r
809 if (Math.abs(evt.getY() - lastMousePress.y)
\r
810 > Math.abs(evt.getX() - lastMousePress.x))
\r
812 int fontSize = av.font.getSize();
\r
814 if (evt.getY() < lastMousePress.y && av.charHeight > 1)
\r
818 else if (evt.getY() > lastMousePress.y)
\r
828 av.setFont(new Font(av.font.getName(), av.font.getStyle(), fontSize));
\r
829 av.charWidth = oldWidth;
\r
833 if (evt.getX() < lastMousePress.x && av.charWidth > 1)
\r
837 else if (evt.getX() > lastMousePress.x)
\r
842 if (av.charWidth < 1)
\r
850 FontMetrics fm = getFontMetrics(av.getFont());
\r
851 av.validCharWidth = fm.charWidth('M') <= av.charWidth;
\r
853 lastMousePress = evt.getPoint();
\r
855 ap.paintAlignment(false);
\r
856 ap.annotationPanel.image = null;
\r
862 doMouseDraggedDefineMode(evt);
\r
866 int res = findRes(evt);
\r
873 if ( (lastres == -1) || (lastres == res))
\r
878 if ( (res < av.getAlignment().getWidth()) && (res < lastres))
\r
880 // dragLeft, delete gap
\r
881 editSequence(false, res);
\r
885 editSequence(true, res);
\r
888 mouseDragging = true;
\r
889 if (scrollThread != null)
\r
891 scrollThread.setEvent(evt);
\r
896 synchronized void editSequence(boolean insertGap, int startres)
\r
898 int fixedLeft = -1;
\r
899 int fixedRight = -1;
\r
900 boolean fixedColumns = false;
\r
901 SequenceGroup sg = av.getSelectionGroup();
\r
903 SequenceI seq = av.alignment.getSequenceAt(startseq);
\r
905 if (!groupEditing && av.hasHiddenRows)
\r
907 if (av.hiddenRepSequences != null
\r
908 && av.hiddenRepSequences.containsKey(seq))
\r
910 sg = (SequenceGroup) av.hiddenRepSequences.get(seq);
\r
911 groupEditing = true;
\r
915 StringBuffer message = new StringBuffer();
\r
918 message.append("Edit group:");
\r
919 if (editCommand == null)
\r
921 editCommand = new EditCommand("Edit Group");
\r
926 message.append("Edit sequence: " + seq.getName());
\r
927 String label = seq.getName();
\r
928 if (label.length() > 10)
\r
930 label = label.substring(0, 10);
\r
932 if (editCommand == null)
\r
934 editCommand = new EditCommand("Edit " + label);
\r
940 message.append(" insert ");
\r
944 message.append(" delete ");
\r
947 message.append(Math.abs(startres - lastres) + " gaps.");
\r
948 ap.alignFrame.statusBar.setText(message.toString());
\r
950 //Are we editing within a selection group?
\r
952 || (sg != null && sg.getSequences(av.hiddenRepSequences).contains(seq)))
\r
954 fixedColumns = true;
\r
956 //sg might be null as the user may only see 1 sequence,
\r
957 //but the sequence represents a group
\r
960 if (av.hiddenRepSequences == null
\r
961 || !av.hiddenRepSequences.containsKey(seq))
\r
967 sg = (SequenceGroup) av.hiddenRepSequences.get(seq);
\r
970 fixedLeft = sg.getStartRes();
\r
971 fixedRight = sg.getEndRes();
\r
973 if ( (startres < fixedLeft && lastres >= fixedLeft)
\r
974 || (startres >= fixedLeft && lastres < fixedLeft)
\r
975 || (startres > fixedRight && lastres <= fixedRight)
\r
976 || (startres <= fixedRight && lastres > fixedRight))
\r
982 if (fixedLeft > startres)
\r
984 fixedRight = fixedLeft - 1;
\r
987 else if (fixedRight < startres)
\r
989 fixedLeft = fixedRight;
\r
994 if (av.hasHiddenColumns)
\r
996 fixedColumns = true;
\r
997 int y1 = av.getColumnSelection().getHiddenBoundaryLeft(startres);
\r
998 int y2 = av.getColumnSelection().getHiddenBoundaryRight(startres);
\r
1000 if ( (insertGap && startres > y1 && lastres < y1)
\r
1001 || (!insertGap && startres < y2 && lastres > y2))
\r
1007 //System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
\r
1008 //Selection spans a hidden region
\r
1009 if (fixedLeft < y1 && (fixedRight > y2 || fixedRight == -1))
\r
1011 if (startres >= y2)
\r
1017 fixedRight = y2 - 1;
\r
1024 Vector vseqs = sg.getSequences(av.hiddenRepSequences);
\r
1025 int g, groupSize = vseqs.size();
\r
1026 SequenceI[] groupSeqs = new SequenceI[groupSize];
\r
1027 for (g = 0; g < groupSeqs.length; g++)
\r
1029 groupSeqs[g] = (SequenceI) vseqs.elementAt(g);
\r
1035 //If the user has selected the whole sequence, and is dragging to
\r
1036 // the right, we can still extend the alignment and selectionGroup
\r
1037 if (sg.getStartRes() == 0
\r
1038 && sg.getEndRes() == fixedRight
\r
1039 && sg.getEndRes() == av.alignment.getWidth() - 1
\r
1042 sg.setEndRes(av.alignment.getWidth() + startres - lastres);
\r
1043 fixedRight = sg.getEndRes();
\r
1046 // Is it valid with fixed columns??
\r
1047 // Find the next gap before the end
\r
1048 // of the visible region boundary
\r
1049 boolean blank = false;
\r
1050 for (fixedRight = fixedRight;
\r
1051 fixedRight > lastres;
\r
1056 for (g = 0; g < groupSize; g++)
\r
1058 for (int j = 0; j < startres - lastres; j++)
\r
1060 if (!jalview.util.Comparison.isGap(
\r
1061 groupSeqs[g].getCharAt(fixedRight - j)))
\r
1076 if (sg.getSize() == av.alignment.getHeight())
\r
1078 if ( (av.hasHiddenColumns
\r
1080 startres < av.getColumnSelection().getHiddenBoundaryRight(startres)))
\r
1086 int alWidth = av.alignment.getWidth();
\r
1087 if (av.hasHiddenRows)
\r
1089 int hwidth = av.alignment.getHiddenSequences().getWidth();
\r
1090 if (hwidth > alWidth)
\r
1095 //We can still insert gaps if the selectionGroup
\r
1096 //contains all the sequences
\r
1097 sg.setEndRes(sg.getEndRes() + startres - lastres);
\r
1098 fixedRight = alWidth + startres - lastres;
\r
1109 else if (!insertGap)
\r
1111 /// Are we able to delete?
\r
1112 // ie are all columns blank?
\r
1114 for (g = 0; g < groupSize; g++)
\r
1116 for (int j = startres; j < lastres; j++)
\r
1118 if (groupSeqs[g].getLength() <= j)
\r
1123 if (!jalview.util.Comparison.isGap(
\r
1124 groupSeqs[g].getCharAt(j)))
\r
1126 // Not a gap, block edit not valid
\r
1136 // dragging to the right
\r
1137 if (fixedColumns && fixedRight != -1)
\r
1139 for (int j = lastres; j < startres; j++)
\r
1141 insertChar(j, groupSeqs, fixedRight);
\r
1146 editCommand.appendEdit(EditCommand.INSERT_GAP,
\r
1148 startres, startres - lastres,
\r
1155 // dragging to the left
\r
1156 if (fixedColumns && fixedRight != -1)
\r
1158 for (int j = lastres; j > startres; j--)
\r
1160 deleteChar(startres, groupSeqs, fixedRight);
\r
1165 editCommand.appendEdit(EditCommand.DELETE_GAP,
\r
1167 startres, lastres - startres,
\r
1174 else /////Editing a single sequence///////////
\r
1178 // dragging to the right
\r
1179 if (fixedColumns && fixedRight != -1)
\r
1181 for (int j = lastres; j < startres; j++)
\r
1183 insertChar(j, new SequenceI[]
\r
1184 {seq}, fixedRight);
\r
1189 editCommand.appendEdit(EditCommand.INSERT_GAP,
\r
1192 lastres, startres - lastres,
\r
1199 // dragging to the left
\r
1200 if (fixedColumns && fixedRight != -1)
\r
1202 for (int j = lastres; j > startres; j--)
\r
1204 if (!jalview.util.Comparison.isGap(seq.getCharAt(startres)))
\r
1209 deleteChar(startres, new SequenceI[]
\r
1210 {seq}, fixedRight);
\r
1215 //could be a keyboard edit trying to delete none gaps
\r
1217 for (int m = startres; m < lastres; m++)
\r
1219 if (!jalview.util.Comparison.isGap(seq.getCharAt(m)))
\r
1228 editCommand.appendEdit(EditCommand.DELETE_GAP,
\r
1239 lastres = startres;
\r
1240 seqCanvas.repaint();
\r
1243 void insertChar(int j, SequenceI[] seq, int fixedColumn)
\r
1245 int blankColumn = fixedColumn;
\r
1246 for (int s = 0; s < seq.length; s++)
\r
1248 //Find the next gap before the end of the visible region boundary
\r
1249 //If lastCol > j, theres a boundary after the gap insertion
\r
1251 for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
\r
1253 if (jalview.util.Comparison.isGap(seq[s].getCharAt(blankColumn)))
\r
1255 //Theres a space, so break and insert the gap
\r
1260 if (blankColumn <= j)
\r
1262 blankColumn = fixedColumn;
\r
1268 editCommand.appendEdit(EditCommand.DELETE_GAP,
\r
1270 blankColumn, 1, av.alignment, true);
\r
1272 editCommand.appendEdit(EditCommand.INSERT_GAP,
\r
1274 j, 1, av.alignment,
\r
1279 void deleteChar(int j, SequenceI[] seq, int fixedColumn)
\r
1282 editCommand.appendEdit(EditCommand.DELETE_GAP,
\r
1284 j, 1, av.alignment, true);
\r
1286 editCommand.appendEdit(EditCommand.INSERT_GAP,
\r
1288 fixedColumn, 1, av.alignment, true);
\r
1291 //////////////////////////////////////////
\r
1292 /////Everything below this is for defining the boundary of the rubberband
\r
1293 //////////////////////////////////////////
\r
1294 public void doMousePressedDefineMode(MouseEvent evt)
\r
1296 if (scrollThread != null)
\r
1298 scrollThread.running = false;
\r
1299 scrollThread = null;
\r
1302 int res = findRes(evt);
\r
1303 int seq = findSeq(evt);
\r
1305 startWrapBlock = wrappedBlock;
\r
1312 SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq);
\r
1314 if (sequence == null || res > sequence.getLength())
\r
1319 stretchGroup = av.getSelectionGroup();
\r
1321 if (stretchGroup == null)
\r
1323 stretchGroup = av.alignment.findGroup(sequence);
\r
1324 if (stretchGroup != null && res > stretchGroup.getStartRes() &&
\r
1325 res < stretchGroup.getEndRes())
\r
1327 av.setSelectionGroup(stretchGroup);
\r
1331 stretchGroup = null;
\r
1335 else if (!stretchGroup.getSequences(null).contains(sequence)
\r
1336 || stretchGroup.getStartRes() > res
\r
1337 || stretchGroup.getEndRes() < res)
\r
1339 stretchGroup = null;
\r
1341 SequenceGroup[] allGroups = av.alignment.findAllGroups(sequence);
\r
1343 if (allGroups != null)
\r
1345 for (int i = 0; i < allGroups.length; i++)
\r
1347 if (allGroups[i].getStartRes() <= res &&
\r
1348 allGroups[i].getEndRes() >= res)
\r
1350 stretchGroup = allGroups[i];
\r
1355 av.setSelectionGroup(stretchGroup);
\r
1358 // DETECT RIGHT MOUSE BUTTON IN AWT
\r
1359 if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK) ==
\r
1360 InputEvent.BUTTON3_MASK)
\r
1362 SequenceFeature [] allFeatures = findFeaturesAtRes(sequence,
\r
1363 sequence.findPosition(res));
\r
1365 Vector links = null;
\r
1366 if (allFeatures != null)
\r
1368 for (int i = 0; i < allFeatures.length; i++)
\r
1370 if (allFeatures[i].links != null)
\r
1372 links = new Vector();
\r
1373 for (int j = 0; j < allFeatures[i].links.size(); j++)
\r
1375 links.addElement(allFeatures[i].links.elementAt(j));
\r
1380 APopupMenu popup = new APopupMenu(ap, null, links);
\r
1382 popup.show(this, evt.getX(), evt.getY());
\r
1386 if (av.cursorMode)
\r
1388 seqCanvas.cursorX = findRes(evt);
\r
1389 seqCanvas.cursorY = findSeq(evt);
\r
1390 seqCanvas.repaint();
\r
1394 //Only if left mouse button do we want to change group sizes
\r
1396 if (stretchGroup == null)
\r
1398 // define a new group here
\r
1399 SequenceGroup sg = new SequenceGroup();
\r
1400 sg.setStartRes(res);
\r
1401 sg.setEndRes(res);
\r
1402 sg.addSequence(sequence, false);
\r
1403 av.setSelectionGroup(sg);
\r
1404 stretchGroup = sg;
\r
1406 if (av.getConservationSelected())
\r
1408 SliderPanel.setConservationSlider(ap, av.getGlobalColourScheme(),
\r
1411 if (av.getAbovePIDThreshold())
\r
1413 SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(),
\r
1420 public void doMouseReleasedDefineMode(MouseEvent evt)
\r
1422 if (stretchGroup == null)
\r
1427 if (stretchGroup.cs != null)
\r
1429 if (stretchGroup.cs instanceof ClustalxColourScheme)
\r
1431 ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX(
\r
1432 stretchGroup.getSequences(av.hiddenRepSequences),
\r
1433 stretchGroup.getWidth());
\r
1436 if (stretchGroup.cs instanceof Blosum62ColourScheme
\r
1437 || stretchGroup.cs instanceof PIDColourScheme
\r
1438 || stretchGroup.cs.conservationApplied()
\r
1439 || stretchGroup.cs.getThreshold() > 0)
\r
1441 stretchGroup.recalcConservation();
\r
1444 if (stretchGroup.cs.conservationApplied())
\r
1446 SliderPanel.setConservationSlider(ap, stretchGroup.cs,
\r
1447 stretchGroup.getName());
\r
1448 stretchGroup.recalcConservation();
\r
1452 SliderPanel.setPIDSliderSource(ap, stretchGroup.cs,
\r
1453 stretchGroup.getName());
\r
1456 changeEndRes = false;
\r
1457 changeStartRes = false;
\r
1458 stretchGroup = null;
\r
1459 PaintRefresher.Refresh(ap, av.getSequenceSetId());
\r
1460 ap.paintAlignment(true);
\r
1463 public void doMouseDraggedDefineMode(MouseEvent evt)
\r
1465 int res = findRes(evt);
\r
1466 int y = findSeq(evt);
\r
1468 if (wrappedBlock != startWrapBlock)
\r
1473 if (stretchGroup == null)
\r
1478 mouseDragging = true;
\r
1480 if (y > av.alignment.getHeight())
\r
1482 y = av.alignment.getHeight() - 1;
\r
1485 if (res >= av.alignment.getWidth())
\r
1487 res = av.alignment.getWidth() - 1;
\r
1490 if (stretchGroup.getEndRes() == res)
\r
1492 // Edit end res position of selected group
\r
1493 changeEndRes = true;
\r
1495 else if (stretchGroup.getStartRes() == res)
\r
1497 // Edit start res position of selected group
\r
1498 changeStartRes = true;
\r
1508 if (res > (stretchGroup.getStartRes() - 1))
\r
1510 stretchGroup.setEndRes(res);
\r
1513 else if (changeStartRes)
\r
1515 if (res < (stretchGroup.getEndRes() + 1))
\r
1517 stretchGroup.setStartRes(res);
\r
1521 int dragDirection = 0;
\r
1525 dragDirection = 1;
\r
1527 else if (y < oldSeq)
\r
1529 dragDirection = -1;
\r
1532 while ( (y != oldSeq) && (oldSeq > -1) && (y < av.alignment.getHeight()))
\r
1534 // This routine ensures we don't skip any sequences, as the
\r
1535 // selection is quite slow.
\r
1536 Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
\r
1538 oldSeq += dragDirection;
\r
1545 Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
\r
1547 if (stretchGroup.getSequences(null).contains(nextSeq))
\r
1549 stretchGroup.deleteSequence(seq, false);
\r
1555 stretchGroup.addSequence(seq, false);
\r
1558 stretchGroup.addSequence(nextSeq, false);
\r
1567 if (res > av.endRes || res < av.startRes
\r
1568 || y < av.startSeq || y > av.endSeq)
\r
1573 if (scrollThread != null)
\r
1575 scrollThread.setEvent(evt);
\r
1578 seqCanvas.repaint();
\r
1581 public void mouseEntered(MouseEvent e)
\r
1588 if (scrollThread != null)
\r
1590 scrollThread.running = false;
\r
1591 scrollThread = null;
\r
1595 public void mouseExited(MouseEvent e)
\r
1597 if (av.getWrapAlignment())
\r
1602 if (mouseDragging && scrollThread == null)
\r
1604 scrollThread = new ScrollThread();
\r
1608 void scrollCanvas(MouseEvent evt)
\r
1612 if (scrollThread != null)
\r
1614 scrollThread.running = false;
\r
1615 scrollThread = null;
\r
1617 mouseDragging = false;
\r
1621 if (scrollThread == null)
\r
1623 scrollThread = new ScrollThread();
\r
1626 mouseDragging = true;
\r
1627 scrollThread.setEvent(evt);
\r
1632 // this class allows scrolling off the bottom of the visible alignment
\r
1633 class ScrollThread
\r
1637 boolean running = false;
\r
1638 public ScrollThread()
\r
1643 public void setEvent(MouseEvent e)
\r
1648 public void stopScrolling()
\r
1662 if (mouseDragging && evt.getY() < 0 && av.getStartSeq() > 0)
\r
1664 running = ap.scrollUp(true);
\r
1667 if (mouseDragging && evt.getY() >= getSize().height &&
\r
1668 av.alignment.getHeight() > av.getEndSeq())
\r
1670 running = ap.scrollUp(false);
\r
1673 if (mouseDragging && evt.getX() < 0)
\r
1675 running = ap.scrollRight(false);
\r
1678 else if (mouseDragging && evt.getX() >= getSize().width)
\r
1680 running = ap.scrollRight(true);
\r
1688 catch (Exception ex)
\r