2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.appletgui;
23 import java.awt.event.*;
25 import jalview.commands.*;
26 import jalview.datamodel.*;
27 import jalview.schemes.*;
28 import jalview.structure.SequenceListener;
29 import jalview.structure.StructureSelectionManager;
31 public class SeqPanel extends Panel implements MouseMotionListener,
32 MouseListener, SequenceListener
35 public SeqCanvas seqCanvas;
37 public AlignmentPanel ap;
39 protected int lastres;
41 protected int startseq;
43 protected AlignViewport av;
45 // if character is inserted or deleted, we will need to recalculate the
47 boolean seqEditOccurred = false;
49 ScrollThread scrollThread = null;
51 boolean mouseDragging = false;
53 boolean editingSeqs = false;
55 boolean groupEditing = false;
59 boolean changeEndSeq = false;
61 boolean changeStartSeq = false;
63 boolean changeEndRes = false;
65 boolean changeStartRes = false;
67 SequenceGroup stretchGroup = null;
69 StringBuffer keyboardNo1;
71 StringBuffer keyboardNo2;
73 boolean mouseWheelPressed = false;
77 EditCommand editCommand;
79 StructureSelectionManager ssm;
81 public SeqPanel(AlignViewport avp, AlignmentPanel p)
85 seqCanvas = new SeqCanvas(avp);
86 setLayout(new BorderLayout());
91 seqCanvas.addMouseMotionListener(this);
92 seqCanvas.addMouseListener(this);
93 ssm = StructureSelectionManager.getStructureSelectionManager();
94 ssm.addStructureViewerListener(this);
101 if (editCommand != null && editCommand.getSize() > 0)
103 ap.alignFrame.addHistoryItem(editCommand);
104 av.firePropertyChange("alignment", null, av.getAlignment()
111 groupEditing = false;
119 seqCanvas.cursorY = getKeyboardNo1() - 1;
123 void setCursorColumn()
125 seqCanvas.cursorX = getKeyboardNo1() - 1;
129 void setCursorRowAndColumn()
131 if (keyboardNo2 == null)
133 keyboardNo2 = new StringBuffer();
137 seqCanvas.cursorX = getKeyboardNo1() - 1;
138 seqCanvas.cursorY = getKeyboardNo2() - 1;
143 void setCursorPosition()
145 SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(
148 seqCanvas.cursorX = sequence.findIndex(getKeyboardNo1() - 1);
152 void moveCursor(int dx, int dy)
154 seqCanvas.cursorX += dx;
155 seqCanvas.cursorY += dy;
156 if (av.hasHiddenColumns && !av.colSel.isVisible(seqCanvas.cursorX))
158 int original = seqCanvas.cursorX - dx;
159 int maxWidth = av.alignment.getWidth();
161 while (!av.colSel.isVisible(seqCanvas.cursorX)
162 && seqCanvas.cursorX < maxWidth && seqCanvas.cursorX > 0)
164 seqCanvas.cursorX += dx;
167 if (seqCanvas.cursorX >= maxWidth
168 || !av.colSel.isVisible(seqCanvas.cursorX))
170 seqCanvas.cursorX = original;
176 void scrollToVisible()
178 if (seqCanvas.cursorX < 0)
180 seqCanvas.cursorX = 0;
182 else if (seqCanvas.cursorX > av.alignment.getWidth() - 1)
184 seqCanvas.cursorX = av.alignment.getWidth() - 1;
187 if (seqCanvas.cursorY < 0)
189 seqCanvas.cursorY = 0;
191 else if (seqCanvas.cursorY > av.alignment.getHeight() - 1)
193 seqCanvas.cursorY = av.alignment.getHeight() - 1;
197 if (av.wrapAlignment)
199 ap.scrollToWrappedVisible(seqCanvas.cursorX);
203 while (seqCanvas.cursorY < av.startSeq)
207 while (seqCanvas.cursorY + 1 > av.endSeq)
211 while (seqCanvas.cursorX < av.colSel
212 .adjustForHiddenColumns(av.startRes))
215 if (!ap.scrollRight(false))
220 while (seqCanvas.cursorX > av.colSel
221 .adjustForHiddenColumns(av.endRes))
223 if (!ap.scrollRight(true))
229 setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY),
230 seqCanvas.cursorX, seqCanvas.cursorY);
235 void setSelectionAreaAtCursor(boolean topLeft)
237 SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(
240 if (av.getSelectionGroup() != null)
242 SequenceGroup sg = av.selectionGroup;
243 // Find the top and bottom of this group
244 int min = av.alignment.getHeight(), max = 0;
245 for (int i = 0; i < sg.getSize(); i++)
247 int index = av.alignment.findIndex(sg.getSequenceAt(i));
262 sg.setStartRes(seqCanvas.cursorX);
263 if (sg.getEndRes() < seqCanvas.cursorX)
265 sg.setEndRes(seqCanvas.cursorX);
268 min = seqCanvas.cursorY;
272 sg.setEndRes(seqCanvas.cursorX);
273 if (sg.getStartRes() > seqCanvas.cursorX)
275 sg.setStartRes(seqCanvas.cursorX);
278 max = seqCanvas.cursorY + 1;
283 // Only the user can do this
284 av.setSelectionGroup(null);
288 // Now add any sequences between min and max
289 sg.getSequences(null).removeAllElements();
290 for (int i = min; i < max; i++)
292 sg.addSequence(av.alignment.getSequenceAt(i), false);
297 if (av.getSelectionGroup() == null)
299 SequenceGroup sg = new SequenceGroup();
300 sg.setStartRes(seqCanvas.cursorX);
301 sg.setEndRes(seqCanvas.cursorX);
302 sg.addSequence(sequence, false);
303 av.setSelectionGroup(sg);
306 ap.paintAlignment(false);
309 void insertGapAtCursor(boolean group)
311 groupEditing = group;
312 startseq = seqCanvas.cursorY;
313 lastres = seqCanvas.cursorX;
314 editSequence(true, seqCanvas.cursorX + getKeyboardNo1());
318 void deleteGapAtCursor(boolean group)
320 groupEditing = group;
321 startseq = seqCanvas.cursorY;
322 lastres = seqCanvas.cursorX + getKeyboardNo1();
323 editSequence(false, seqCanvas.cursorX);
327 void numberPressed(char value)
329 if (keyboardNo1 == null)
331 keyboardNo1 = new StringBuffer();
334 if (keyboardNo2 != null)
336 keyboardNo2.append(value);
340 keyboardNo1.append(value);
346 if (keyboardNo1 == null)
350 int value = Integer.parseInt(keyboardNo1.toString());
358 if (keyboardNo2 == null)
362 int value = Integer.parseInt(keyboardNo2.toString());
368 void setStatusMessage(SequenceI sequence, int res, int seq)
370 StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: "
371 + sequence.getName());
374 if (av.alignment.isNucleotide())
376 obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res)
380 text.append(" Nucleotide: ");
385 obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
388 text.append(" Residue: ");
397 text.append(obj + " (" + sequence.findPosition(res) + ")");
401 ap.alignFrame.statusBar.setText(text.toString());
405 public void mousePressed(MouseEvent evt)
407 lastMousePress = evt.getPoint();
409 // For now, ignore the mouseWheel font resizing on Macs
410 // As the Button2_mask always seems to be true
411 if ((evt.getModifiers() & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK
414 mouseWheelPressed = true;
418 if (evt.isShiftDown() || evt.isControlDown() || evt.isAltDown())
420 if (evt.isControlDown() || evt.isAltDown())
428 doMousePressedDefineMode(evt);
432 int seq = findSeq(evt);
433 int res = findRes(evt);
435 if (seq < 0 || res < 0)
440 if ((seq < av.getAlignment().getHeight())
441 && (res < av.getAlignment().getSequenceAt(seq).getLength()))
455 public void mouseClicked(MouseEvent evt)
457 SequenceI sequence = av.alignment.getSequenceAt(findSeq(evt));
458 if (evt.getClickCount() > 1)
460 if (av.getSelectionGroup().getSize() == 1
461 && av.getSelectionGroup().getEndRes()
462 - av.getSelectionGroup().getStartRes() < 2)
464 av.setSelectionGroup(null);
467 SequenceFeature[] features = findFeaturesAtRes(sequence,
468 sequence.findPosition(findRes(evt)));
470 if (features != null && features.length > 0)
472 SearchResults highlight = new SearchResults();
473 highlight.addResult(sequence, features[0].getBegin(),
474 features[0].getEnd());
475 seqCanvas.highlightSearchResults(highlight);
477 if (features != null && features.length > 0)
479 seqCanvas.getFeatureRenderer().amendFeatures(new SequenceI[]
480 { sequence }, features, false, ap);
482 seqCanvas.highlightSearchResults(null);
487 public void mouseReleased(MouseEvent evt)
489 mouseDragging = false;
490 mouseWheelPressed = false;
491 ap.paintAlignment(true);
495 doMouseReleasedDefineMode(evt);
503 int startWrapBlock = -1;
505 int wrappedBlock = -1;
507 int findRes(MouseEvent evt)
512 if (av.wrapAlignment)
515 int hgap = av.charHeight;
516 if (av.scaleAboveWrapped)
518 hgap += av.charHeight;
521 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
522 + seqCanvas.getAnnotationHeight();
526 x -= seqCanvas.LABEL_WEST;
528 int cwidth = seqCanvas.getWrappedCanvasWidth(getSize().width);
534 wrappedBlock = y / cHeight;
535 wrappedBlock += av.getStartRes() / cwidth;
537 res = wrappedBlock * cwidth + x / av.getCharWidth();
542 res = (x / av.getCharWidth()) + av.getStartRes();
545 if (av.hasHiddenColumns)
547 res = av.getColumnSelection().adjustForHiddenColumns(res);
554 int findSeq(MouseEvent evt)
556 final int sqnum = findAlRow(evt);
557 return (sqnum < 0) ? 0 : sqnum;
563 * @return row in alignment that was selected (or -1 for column selection)
565 private int findAlRow(MouseEvent evt)
570 if (av.wrapAlignment)
572 int hgap = av.charHeight;
573 if (av.scaleAboveWrapped)
575 hgap += av.charHeight;
578 int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap
579 + seqCanvas.getAnnotationHeight();
583 seq = Math.min((y % cHeight) / av.getCharHeight(),
584 av.alignment.getHeight() - 1);
592 seq = Math.min((y / av.getCharHeight()) + av.getStartSeq(),
593 av.alignment.getHeight() - 1);
603 public void doMousePressed(MouseEvent evt)
606 int seq = findSeq(evt);
607 int res = findRes(evt);
609 if (seq < av.getAlignment().getHeight()
610 && res < av.getAlignment().getSequenceAt(seq).getLength())
612 // char resstr = align.getSequenceAt(seq).getSequence().charAt(res);
613 // Find the residue's position in the sequence (res is the position
630 public void mouseOverSequence(SequenceI sequence, int index, int pos)
632 String tmp = sequence.hashCode() + index + "";
633 if (lastMessage == null || !lastMessage.equals(tmp))
634 ssm.mouseOverSequence(sequence, index, pos);
639 public void highlightSequence(SearchResults results)
641 seqCanvas.highlightSearchResults(results);
642 if (av.followHighlight)
644 ap.scrollToPosition(results);
648 public void updateColours(SequenceI seq, int index)
650 System.out.println("update the seqPanel colours");
654 public void mouseMoved(MouseEvent evt)
656 int res = findRes(evt);
657 int seq = findSeq(evt);
659 if (seq >= av.getAlignment().getHeight() || seq < 0 || res < 0)
668 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
669 if (res > sequence.getLength())
678 int respos = sequence.findPosition(res);
680 mouseOverSequence(sequence, res, respos);
682 StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: "
683 + sequence.getName());
686 if (av.alignment.isNucleotide())
688 obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res)
692 text.append(" Nucleotide: ");
697 obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
700 text.append(" Residue: ");
708 text.append(obj + " (" + respos + ")");
712 ap.alignFrame.statusBar.setText(text.toString());
714 StringBuffer tooltipText = new StringBuffer();
715 SequenceGroup[] groups = av.alignment.findAllGroups(sequence);
718 for (int g = 0; g < groups.length; g++)
720 if (groups[g].getStartRes() <= res && groups[g].getEndRes() >= res)
722 if (!groups[g].getName().startsWith("JTreeGroup")
723 && !groups[g].getName().startsWith("JGroup"))
725 tooltipText.append(groups[g].getName() + " ");
727 if (groups[g].getDescription() != null)
729 tooltipText.append(groups[g].getDescription());
731 tooltipText.append("\n");
736 // use aa to see if the mouse pointer is on a
737 SequenceFeature[] allFeatures = findFeaturesAtRes(sequence,
738 sequence.findPosition(res));
741 while (index < allFeatures.length)
743 SequenceFeature sf = allFeatures[index];
745 tooltipText.append(sf.getType() + " " + sf.begin + ":" + sf.end);
747 if (sf.getDescription() != null)
749 tooltipText.append(" " + sf.getDescription());
752 if (sf.getValue("status") != null)
754 String status = sf.getValue("status").toString();
755 if (status.length() > 0)
757 tooltipText.append(" (" + sf.getValue("status") + ")");
760 tooltipText.append("\n");
767 tooltip = new Tooltip(tooltipText.toString(), seqCanvas);
771 tooltip.setTip(tooltipText.toString());
775 SequenceFeature[] findFeaturesAtRes(SequenceI sequence, int res)
777 Vector tmp = new Vector();
778 SequenceFeature[] features = sequence.getSequenceFeatures();
779 if (features != null)
781 for (int i = 0; i < features.length; i++)
783 if (av.featuresDisplayed == null
784 || !av.featuresDisplayed.containsKey(features[i].getType()))
789 if (features[i].featureGroup != null
790 && seqCanvas.fr.featureGroups != null
791 && seqCanvas.fr.featureGroups
792 .containsKey(features[i].featureGroup)
793 && !((Boolean) seqCanvas.fr.featureGroups
794 .get(features[i].featureGroup)).booleanValue())
797 if ((features[i].getBegin() <= res)
798 && (features[i].getEnd() >= res))
800 tmp.addElement(features[i]);
805 features = new SequenceFeature[tmp.size()];
806 tmp.copyInto(features);
813 public void mouseDragged(MouseEvent evt)
815 if (mouseWheelPressed)
817 int oldWidth = av.charWidth;
819 // Which is bigger, left-right or up-down?
820 if (Math.abs(evt.getY() - lastMousePress.y) > Math.abs(evt.getX()
823 int fontSize = av.font.getSize();
825 if (evt.getY() < lastMousePress.y && av.charHeight > 1)
829 else if (evt.getY() > lastMousePress.y)
839 av.setFont(new Font(av.font.getName(), av.font.getStyle(), fontSize));
840 av.charWidth = oldWidth;
844 if (evt.getX() < lastMousePress.x && av.charWidth > 1)
848 else if (evt.getX() > lastMousePress.x)
853 if (av.charWidth < 1)
861 FontMetrics fm = getFontMetrics(av.getFont());
862 av.validCharWidth = fm.charWidth('M') <= av.charWidth;
864 lastMousePress = evt.getPoint();
866 ap.paintAlignment(false);
867 ap.annotationPanel.image = null;
873 doMouseDraggedDefineMode(evt);
877 int res = findRes(evt);
884 if ((lastres == -1) || (lastres == res))
889 if ((res < av.getAlignment().getWidth()) && (res < lastres))
891 // dragLeft, delete gap
892 editSequence(false, res);
896 editSequence(true, res);
899 mouseDragging = true;
900 if (scrollThread != null)
902 scrollThread.setEvent(evt);
907 synchronized void editSequence(boolean insertGap, int startres)
911 boolean fixedColumns = false;
912 SequenceGroup sg = av.getSelectionGroup();
914 SequenceI seq = av.alignment.getSequenceAt(startseq);
916 if (!groupEditing && av.hasHiddenRows)
918 if (av.hiddenRepSequences != null
919 && av.hiddenRepSequences.containsKey(seq))
921 sg = (SequenceGroup) av.hiddenRepSequences.get(seq);
926 StringBuffer message = new StringBuffer();
929 message.append("Edit group:");
930 if (editCommand == null)
932 editCommand = new EditCommand("Edit Group");
937 message.append("Edit sequence: " + seq.getName());
938 String label = seq.getName();
939 if (label.length() > 10)
941 label = label.substring(0, 10);
943 if (editCommand == null)
945 editCommand = new EditCommand("Edit " + label);
951 message.append(" insert ");
955 message.append(" delete ");
958 message.append(Math.abs(startres - lastres) + " gaps.");
959 ap.alignFrame.statusBar.setText(message.toString());
961 // Are we editing within a selection group?
963 || (sg != null && sg.getSequences(av.hiddenRepSequences)
968 // sg might be null as the user may only see 1 sequence,
969 // but the sequence represents a group
972 if (av.hiddenRepSequences == null
973 || !av.hiddenRepSequences.containsKey(seq))
979 sg = (SequenceGroup) av.hiddenRepSequences.get(seq);
982 fixedLeft = sg.getStartRes();
983 fixedRight = sg.getEndRes();
985 if ((startres < fixedLeft && lastres >= fixedLeft)
986 || (startres >= fixedLeft && lastres < fixedLeft)
987 || (startres > fixedRight && lastres <= fixedRight)
988 || (startres <= fixedRight && lastres > fixedRight))
994 if (fixedLeft > startres)
996 fixedRight = fixedLeft - 1;
999 else if (fixedRight < startres)
1001 fixedLeft = fixedRight;
1006 if (av.hasHiddenColumns)
1008 fixedColumns = true;
1009 int y1 = av.getColumnSelection().getHiddenBoundaryLeft(startres);
1010 int y2 = av.getColumnSelection().getHiddenBoundaryRight(startres);
1012 if ((insertGap && startres > y1 && lastres < y1)
1013 || (!insertGap && startres < y2 && lastres > y2))
1019 // System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
1020 // Selection spans a hidden region
1021 if (fixedLeft < y1 && (fixedRight > y2 || fixedRight == -1))
1029 fixedRight = y2 - 1;
1036 Vector vseqs = sg.getSequences(av.hiddenRepSequences);
1037 int g, groupSize = vseqs.size();
1038 SequenceI[] groupSeqs = new SequenceI[groupSize];
1039 for (g = 0; g < groupSeqs.length; g++)
1041 groupSeqs[g] = (SequenceI) vseqs.elementAt(g);
1047 // If the user has selected the whole sequence, and is dragging to
1048 // the right, we can still extend the alignment and selectionGroup
1049 if (sg.getStartRes() == 0 && sg.getEndRes() == fixedRight
1050 && sg.getEndRes() == av.alignment.getWidth() - 1)
1052 sg.setEndRes(av.alignment.getWidth() + startres - lastres);
1053 fixedRight = sg.getEndRes();
1056 // Is it valid with fixed columns??
1057 // Find the next gap before the end
1058 // of the visible region boundary
1059 boolean blank = false;
1060 for (fixedRight = fixedRight; fixedRight > lastres; fixedRight--)
1064 for (g = 0; g < groupSize; g++)
1066 for (int j = 0; j < startres - lastres; j++)
1068 if (!jalview.util.Comparison.isGap(groupSeqs[g]
1069 .getCharAt(fixedRight - j)))
1084 if (sg.getSize() == av.alignment.getHeight())
1086 if ((av.hasHiddenColumns && startres < av.getColumnSelection()
1087 .getHiddenBoundaryRight(startres)))
1093 int alWidth = av.alignment.getWidth();
1094 if (av.hasHiddenRows)
1096 int hwidth = av.alignment.getHiddenSequences().getWidth();
1097 if (hwidth > alWidth)
1102 // We can still insert gaps if the selectionGroup
1103 // contains all the sequences
1104 sg.setEndRes(sg.getEndRes() + startres - lastres);
1105 fixedRight = alWidth + startres - lastres;
1116 else if (!insertGap)
1118 // / Are we able to delete?
1119 // ie are all columns blank?
1121 for (g = 0; g < groupSize; g++)
1123 for (int j = startres; j < lastres; j++)
1125 if (groupSeqs[g].getLength() <= j)
1130 if (!jalview.util.Comparison.isGap(groupSeqs[g].getCharAt(j)))
1132 // Not a gap, block edit not valid
1142 // dragging to the right
1143 if (fixedColumns && fixedRight != -1)
1145 for (int j = lastres; j < startres; j++)
1147 insertChar(j, groupSeqs, fixedRight);
1152 editCommand.appendEdit(EditCommand.INSERT_GAP, groupSeqs,
1153 startres, startres - lastres, av.alignment, true);
1158 // dragging to the left
1159 if (fixedColumns && fixedRight != -1)
1161 for (int j = lastres; j > startres; j--)
1163 deleteChar(startres, groupSeqs, fixedRight);
1168 editCommand.appendEdit(EditCommand.DELETE_GAP, groupSeqs,
1169 startres, lastres - startres, av.alignment, true);
1175 // ///Editing a single sequence///////////
1179 // dragging to the right
1180 if (fixedColumns && fixedRight != -1)
1182 for (int j = lastres; j < startres; j++)
1184 insertChar(j, new SequenceI[]
1185 { seq }, fixedRight);
1190 editCommand.appendEdit(EditCommand.INSERT_GAP, new SequenceI[]
1191 { seq }, lastres, startres - lastres, av.alignment, true);
1196 // dragging to the left
1197 if (fixedColumns && fixedRight != -1)
1199 for (int j = lastres; j > startres; j--)
1201 if (!jalview.util.Comparison.isGap(seq.getCharAt(startres)))
1206 deleteChar(startres, new SequenceI[]
1207 { seq }, fixedRight);
1212 // could be a keyboard edit trying to delete none gaps
1214 for (int m = startres; m < lastres; m++)
1216 if (!jalview.util.Comparison.isGap(seq.getCharAt(m)))
1225 editCommand.appendEdit(EditCommand.DELETE_GAP, new SequenceI[]
1226 { seq }, startres, max, av.alignment, true);
1233 seqCanvas.repaint();
1236 void insertChar(int j, SequenceI[] seq, int fixedColumn)
1238 int blankColumn = fixedColumn;
1239 for (int s = 0; s < seq.length; s++)
1241 // Find the next gap before the end of the visible region boundary
1242 // If lastCol > j, theres a boundary after the gap insertion
1244 for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
1246 if (jalview.util.Comparison.isGap(seq[s].getCharAt(blankColumn)))
1248 // Theres a space, so break and insert the gap
1253 if (blankColumn <= j)
1255 blankColumn = fixedColumn;
1261 editCommand.appendEdit(EditCommand.DELETE_GAP, seq, blankColumn, 1,
1262 av.alignment, true);
1264 editCommand.appendEdit(EditCommand.INSERT_GAP, seq, j, 1, av.alignment,
1269 void deleteChar(int j, SequenceI[] seq, int fixedColumn)
1272 editCommand.appendEdit(EditCommand.DELETE_GAP, seq, j, 1, av.alignment,
1275 editCommand.appendEdit(EditCommand.INSERT_GAP, seq, fixedColumn, 1,
1276 av.alignment, true);
1279 // ////////////////////////////////////////
1280 // ///Everything below this is for defining the boundary of the rubberband
1281 // ////////////////////////////////////////
1282 public void doMousePressedDefineMode(MouseEvent evt)
1284 if (scrollThread != null)
1286 scrollThread.running = false;
1287 scrollThread = null;
1290 int res = findRes(evt);
1291 int seq = findSeq(evt);
1293 startWrapBlock = wrappedBlock;
1300 SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq);
1302 if (sequence == null || res > sequence.getLength())
1307 stretchGroup = av.getSelectionGroup();
1309 if (stretchGroup == null)
1311 stretchGroup = av.alignment.findGroup(sequence);
1312 if (stretchGroup != null && res > stretchGroup.getStartRes()
1313 && res < stretchGroup.getEndRes())
1315 av.setSelectionGroup(stretchGroup);
1319 stretchGroup = null;
1323 else if (!stretchGroup.getSequences(null).contains(sequence)
1324 || stretchGroup.getStartRes() > res
1325 || stretchGroup.getEndRes() < res)
1327 stretchGroup = null;
1329 SequenceGroup[] allGroups = av.alignment.findAllGroups(sequence);
1331 if (allGroups != null)
1333 for (int i = 0; i < allGroups.length; i++)
1335 if (allGroups[i].getStartRes() <= res
1336 && allGroups[i].getEndRes() >= res)
1338 stretchGroup = allGroups[i];
1343 av.setSelectionGroup(stretchGroup);
1346 // DETECT RIGHT MOUSE BUTTON IN AWT
1347 if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
1349 SequenceFeature[] allFeatures = findFeaturesAtRes(sequence,
1350 sequence.findPosition(res));
1352 Vector links = null;
1353 if (allFeatures != null)
1355 for (int i = 0; i < allFeatures.length; i++)
1357 if (allFeatures[i].links != null)
1361 links = new Vector();
1363 for (int j = 0; j < allFeatures[i].links.size(); j++)
1365 links.addElement(allFeatures[i].links.elementAt(j));
1370 APopupMenu popup = new APopupMenu(ap, null, links);
1372 popup.show(this, evt.getX(), evt.getY());
1378 seqCanvas.cursorX = findRes(evt);
1379 seqCanvas.cursorY = findSeq(evt);
1380 seqCanvas.repaint();
1384 // Only if left mouse button do we want to change group sizes
1386 if (stretchGroup == null)
1388 // define a new group here
1389 SequenceGroup sg = new SequenceGroup();
1390 sg.setStartRes(res);
1392 sg.addSequence(sequence, false);
1393 av.setSelectionGroup(sg);
1396 if (av.getConservationSelected())
1398 SliderPanel.setConservationSlider(ap, av.getGlobalColourScheme(),
1401 if (av.getAbovePIDThreshold())
1403 SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(),
1410 public void doMouseReleasedDefineMode(MouseEvent evt)
1412 if (stretchGroup == null)
1417 if (stretchGroup.cs != null)
1419 if (stretchGroup.cs instanceof ClustalxColourScheme)
1421 ((ClustalxColourScheme) stretchGroup.cs).resetClustalX(
1422 stretchGroup.getSequences(av.hiddenRepSequences),
1423 stretchGroup.getWidth());
1426 if (stretchGroup.cs instanceof Blosum62ColourScheme
1427 || stretchGroup.cs instanceof PIDColourScheme
1428 || stretchGroup.cs.conservationApplied()
1429 || stretchGroup.cs.getThreshold() > 0)
1431 stretchGroup.recalcConservation();
1434 if (stretchGroup.cs.conservationApplied())
1436 SliderPanel.setConservationSlider(ap, stretchGroup.cs,
1437 stretchGroup.getName());
1438 stretchGroup.recalcConservation();
1442 SliderPanel.setPIDSliderSource(ap, stretchGroup.cs,
1443 stretchGroup.getName());
1446 changeEndRes = false;
1447 changeStartRes = false;
1448 stretchGroup = null;
1449 PaintRefresher.Refresh(ap, av.getSequenceSetId());
1450 ap.paintAlignment(true);
1453 public void doMouseDraggedDefineMode(MouseEvent evt)
1455 int res = findRes(evt);
1456 int y = findSeq(evt);
1458 if (wrappedBlock != startWrapBlock)
1463 if (stretchGroup == null)
1468 mouseDragging = true;
1470 if (y > av.alignment.getHeight())
1472 y = av.alignment.getHeight() - 1;
1475 if (res >= av.alignment.getWidth())
1477 res = av.alignment.getWidth() - 1;
1480 if (stretchGroup.getEndRes() == res)
1482 // Edit end res position of selected group
1483 changeEndRes = true;
1485 else if (stretchGroup.getStartRes() == res)
1487 // Edit start res position of selected group
1488 changeStartRes = true;
1498 if (res > (stretchGroup.getStartRes() - 1))
1500 stretchGroup.setEndRes(res);
1503 else if (changeStartRes)
1505 if (res < (stretchGroup.getEndRes() + 1))
1507 stretchGroup.setStartRes(res);
1511 int dragDirection = 0;
1517 else if (y < oldSeq)
1522 while ((y != oldSeq) && (oldSeq > -1) && (y < av.alignment.getHeight()))
1524 // This routine ensures we don't skip any sequences, as the
1525 // selection is quite slow.
1526 Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
1528 oldSeq += dragDirection;
1535 Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
1537 if (stretchGroup.getSequences(null).contains(nextSeq))
1539 stretchGroup.deleteSequence(seq, false);
1545 stretchGroup.addSequence(seq, false);
1548 stretchGroup.addSequence(nextSeq, false);
1557 if (res > av.endRes || res < av.startRes || y < av.startSeq
1563 if (scrollThread != null)
1565 scrollThread.setEvent(evt);
1568 seqCanvas.repaint();
1571 public void mouseEntered(MouseEvent e)
1578 if (scrollThread != null)
1580 scrollThread.running = false;
1581 scrollThread = null;
1585 public void mouseExited(MouseEvent e)
1587 if (av.getWrapAlignment())
1592 if (mouseDragging && scrollThread == null)
1594 scrollThread = new ScrollThread();
1598 void scrollCanvas(MouseEvent evt)
1602 if (scrollThread != null)
1604 scrollThread.running = false;
1605 scrollThread = null;
1607 mouseDragging = false;
1611 if (scrollThread == null)
1613 scrollThread = new ScrollThread();
1616 mouseDragging = true;
1617 scrollThread.setEvent(evt);
1622 // this class allows scrolling off the bottom of the visible alignment
1623 class ScrollThread extends Thread
1627 boolean running = false;
1629 public ScrollThread()
1634 public void setEvent(MouseEvent e)
1639 public void stopScrolling()
1653 if (mouseDragging && evt.getY() < 0 && av.getStartSeq() > 0)
1655 running = ap.scrollUp(true);
1658 if (mouseDragging && evt.getY() >= getSize().height
1659 && av.alignment.getHeight() > av.getEndSeq())
1661 running = ap.scrollUp(false);
1664 if (mouseDragging && evt.getX() < 0)
1666 running = ap.scrollRight(false);
1669 else if (mouseDragging && evt.getX() >= getSize().width)
1671 running = ap.scrollRight(true);
1678 } catch (Exception ex)