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