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
24 import java.awt.event.*;
27 import jalview.commands.*;
28 import jalview.datamodel.*;
29 import jalview.schemes.*;
30 import jalview.structure.*;
39 extends JPanel implements MouseListener,
40 MouseMotionListener, MouseWheelListener, SequenceListener
44 public SeqCanvas seqCanvas;
47 public AlignmentPanel ap;
48 protected int lastres;
49 protected int startseq;
50 protected AlignViewport av;
52 ScrollThread scrollThread = null;
53 boolean mouseDragging = false;
54 boolean editingSeqs = false;
55 boolean groupEditing = false;
57 //////////////////////////////////////////
58 /////Everything below this is for defining the boundary of the rubberband
59 //////////////////////////////////////////
61 boolean changeEndSeq = false;
62 boolean changeStartSeq = false;
63 boolean changeEndRes = false;
64 boolean changeStartRes = false;
65 SequenceGroup stretchGroup = null;
66 boolean remove = false;
69 boolean mouseWheelPressed = false;
70 StringBuffer keyboardNo1;
71 StringBuffer keyboardNo2;
73 java.net.URL linkImageURL;
75 StringBuffer tooltipText = new StringBuffer("<html>");
78 EditCommand editCommand;
80 StructureSelectionManager ssm;
84 * Creates a new SeqPanel object.
86 * @param avp DOCUMENT ME!
87 * @param p DOCUMENT ME!
89 public SeqPanel(AlignViewport av, AlignmentPanel ap)
91 linkImageURL = getClass().getResource("/images/link.gif");
92 ToolTipManager.sharedInstance().registerComponent(this);
93 ToolTipManager.sharedInstance().setInitialDelay(0);
94 ToolTipManager.sharedInstance().setDismissDelay(10000);
96 setBackground(Color.white);
98 seqCanvas = new SeqCanvas(ap);
99 setLayout(new BorderLayout());
100 add(seqCanvas, BorderLayout.CENTER);
106 addMouseMotionListener(this);
107 addMouseListener(this);
108 addMouseWheelListener(this);
109 ssm = StructureSelectionManager.getStructureSelectionManager();
110 ssm.addStructureViewerListener(this);
114 int startWrapBlock = -1;
115 int wrappedBlock = -1;
116 int findRes(MouseEvent evt)
121 if (av.wrapAlignment)
124 int hgap = av.charHeight;
125 if (av.scaleAboveWrapped)
127 hgap += av.charHeight;
130 int cHeight = av.getAlignment().getHeight() * av.charHeight
131 + hgap + seqCanvas.getAnnotationHeight();
135 x -= seqCanvas.LABEL_WEST;
137 int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());
143 wrappedBlock = y / cHeight;
144 wrappedBlock += av.getStartRes() / cwidth;
146 res = wrappedBlock * cwidth + x / av.getCharWidth();
151 res = (x / av.getCharWidth()) + av.getStartRes();
154 if (av.hasHiddenColumns)
156 res = av.getColumnSelection().adjustForHiddenColumns(res);
163 int findSeq(MouseEvent evt)
168 if (av.wrapAlignment)
170 int hgap = av.charHeight;
171 if (av.scaleAboveWrapped)
173 hgap += av.charHeight;
176 int cHeight = av.getAlignment().getHeight() * av.charHeight
177 + hgap + seqCanvas.getAnnotationHeight();
181 seq = Math.min( (y % cHeight) / av.getCharHeight(),
182 av.alignment.getHeight() - 1);
186 seq = Math.min( (y / av.getCharHeight()) + av.getStartSeq(),
187 av.alignment.getHeight() - 1);
193 SequenceFeature[] findFeaturesAtRes(SequenceI sequence, int res)
195 Vector tmp = new Vector();
196 SequenceFeature[] features = sequence.getSequenceFeatures();
197 if (features != null)
199 for (int i = 0; i < features.length; i++)
201 if (av.featuresDisplayed == null
202 || !av.featuresDisplayed.containsKey(features[i].getType()))
207 if (features[i].featureGroup != null
208 && seqCanvas.fr.featureGroups!=null
209 && seqCanvas.fr.featureGroups.containsKey(features[i].featureGroup)
210 && !((Boolean)seqCanvas.fr.featureGroups.get(features[i].featureGroup)).booleanValue())
214 if ( (features[i].getBegin() <= res) &&
215 (features[i].getEnd() >= res))
217 tmp.addElement(features[i]);
222 features = new SequenceFeature[tmp.size()];
223 tmp.copyInto(features);
231 if (editCommand != null && editCommand.getSize() > 0)
233 ap.alignFrame.addHistoryItem(editCommand);
234 av.firePropertyChange("alignment", null,
235 av.getAlignment().getSequences());
241 groupEditing = false;
249 seqCanvas.cursorY = getKeyboardNo1() - 1;
253 void setCursorColumn()
255 seqCanvas.cursorX = getKeyboardNo1() - 1;
259 void setCursorRowAndColumn()
261 if (keyboardNo2 == null)
263 keyboardNo2 = new StringBuffer();
267 seqCanvas.cursorX = getKeyboardNo1() - 1;
268 seqCanvas.cursorY = getKeyboardNo2() - 1;
273 void setCursorPosition()
276 (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);
278 seqCanvas.cursorX = sequence.findIndex(
284 void moveCursor(int dx, int dy)
286 seqCanvas.cursorX += dx;
287 seqCanvas.cursorY += dy;
288 if (av.hasHiddenColumns && !av.colSel.isVisible(seqCanvas.cursorX))
290 int original = seqCanvas.cursorX - dx;
291 int maxWidth = av.alignment.getWidth();
293 while (!av.colSel.isVisible(seqCanvas.cursorX)
294 && seqCanvas.cursorX < maxWidth
295 && seqCanvas.cursorX > 0)
297 seqCanvas.cursorX += dx;
300 if (seqCanvas.cursorX >= maxWidth
301 || !av.colSel.isVisible(seqCanvas.cursorX))
303 seqCanvas.cursorX = original;
310 void scrollToVisible()
312 if (seqCanvas.cursorX < 0)
314 seqCanvas.cursorX = 0;
316 else if (seqCanvas.cursorX > av.alignment.getWidth() - 1)
318 seqCanvas.cursorX = av.alignment.getWidth() - 1;
321 if (seqCanvas.cursorY < 0)
323 seqCanvas.cursorY = 0;
325 else if (seqCanvas.cursorY > av.alignment.getHeight() - 1)
327 seqCanvas.cursorY = av.alignment.getHeight() - 1;
331 if (av.wrapAlignment)
333 ap.scrollToWrappedVisible(seqCanvas.cursorX);
337 while (seqCanvas.cursorY < av.startSeq)
341 while (seqCanvas.cursorY + 1 > av.endSeq)
345 if (!av.wrapAlignment)
347 while (seqCanvas.cursorX < av.colSel.adjustForHiddenColumns(av.startRes))
349 if (!ap.scrollRight(false))
354 while (seqCanvas.cursorX > av.colSel.adjustForHiddenColumns(av.endRes))
356 if (!ap.scrollRight(true))
363 setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY),
364 seqCanvas.cursorX, seqCanvas.cursorY);
369 void setSelectionAreaAtCursor(boolean topLeft)
372 (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);
374 if (av.getSelectionGroup() != null)
376 SequenceGroup sg = av.selectionGroup;
377 //Find the top and bottom of this group
378 int min = av.alignment.getHeight(), max = 0;
379 for (int i = 0; i < sg.getSize(); i++)
381 int index = av.alignment.findIndex(sg.getSequenceAt(i));
396 sg.setStartRes(seqCanvas.cursorX);
397 if (sg.getEndRes() < seqCanvas.cursorX)
399 sg.setEndRes(seqCanvas.cursorX);
402 min = seqCanvas.cursorY;
406 sg.setEndRes(seqCanvas.cursorX);
407 if (sg.getStartRes() > seqCanvas.cursorX)
409 sg.setStartRes(seqCanvas.cursorX);
412 max = seqCanvas.cursorY + 1;
417 // Only the user can do this
418 av.setSelectionGroup(null);
422 // Now add any sequences between min and max
423 sg.getSequences(null).clear();
424 for (int i = min; i < max; i++)
426 sg.addSequence(av.alignment.getSequenceAt(i), false);
431 if (av.getSelectionGroup() == null)
433 SequenceGroup sg = new SequenceGroup();
434 sg.setStartRes(seqCanvas.cursorX);
435 sg.setEndRes(seqCanvas.cursorX);
436 sg.addSequence(sequence, false);
437 av.setSelectionGroup(sg);
440 ap.paintAlignment(false);
443 void insertGapAtCursor(boolean group)
445 groupEditing = group;
446 startseq = seqCanvas.cursorY;
447 lastres = seqCanvas.cursorX;
448 editSequence(true, seqCanvas.cursorX + getKeyboardNo1());
452 void deleteGapAtCursor(boolean group)
454 groupEditing = group;
455 startseq = seqCanvas.cursorY;
456 lastres = seqCanvas.cursorX + getKeyboardNo1();
457 editSequence(false, seqCanvas.cursorX);
461 void numberPressed(char value)
463 if (keyboardNo1 == null)
465 keyboardNo1 = new StringBuffer();
468 if (keyboardNo2 != null)
470 keyboardNo2.append(value);
474 keyboardNo1.append(value);
480 if (keyboardNo1 == null)
484 int value = Integer.parseInt(keyboardNo1.toString());
492 if (keyboardNo2 == null)
496 int value = Integer.parseInt(keyboardNo2.toString());
505 * @param evt DOCUMENT ME!
507 public void mouseReleased(MouseEvent evt)
509 mouseDragging = false;
510 mouseWheelPressed = false;
514 doMouseReleasedDefineMode(evt);
524 * @param evt DOCUMENT ME!
526 public void mousePressed(MouseEvent evt)
528 lastMousePress = evt.getPoint();
530 if (javax.swing.SwingUtilities.isMiddleMouseButton(evt))
532 mouseWheelPressed = true;
536 if (evt.isShiftDown() || evt.isAltDown() ||
539 if (evt.isAltDown() || evt.isControlDown())
547 doMousePressedDefineMode(evt);
551 int seq = findSeq(evt);
552 int res = findRes(evt);
554 if (seq < 0 || res < 0)
559 if ( (seq < av.getAlignment().getHeight()) &&
560 (res < av.getAlignment().getSequenceAt(seq).getLength()))
575 public void mouseOverSequence(SequenceI sequence, int index, int pos)
577 String tmp = sequence.hashCode()+" "+index+" "+pos;
579 if (lastMessage == null || !lastMessage.equals(tmp))
581 // System.err.println("mouseOver Sequence: "+tmp);
582 ssm.mouseOverSequence(sequence, index, pos);
588 public void highlightSequence(SearchResults results)
590 seqCanvas.highlightSearchResults(results);
593 public void updateColours(SequenceI seq, int index)
595 System.out.println("update the seqPanel colours");
602 * @param evt DOCUMENT ME!
604 public void mouseMoved(MouseEvent evt)
608 // This is because MacOSX creates a mouseMoved
609 // If control is down, other platforms will not.
613 int res = findRes(evt);
614 int seq = findSeq(evt);
616 if (res < 0 || seq < 0 || seq >= av.getAlignment().getHeight())
621 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
623 if (res >= sequence.getLength())
628 pos = setStatusMessage(sequence, res, seq);
629 if (ssm != null && pos>-1)
630 mouseOverSequence(sequence, res, pos);
633 tooltipText.setLength(6); // Cuts the buffer back to <html>
635 SequenceGroup[] groups = av.alignment.findAllGroups(sequence);
638 for (int g = 0; g < groups.length; g++)
640 if (groups[g].getStartRes() <= res && groups[g].getEndRes() >= res)
642 if (tooltipText.length() > 6)
644 tooltipText.append("<br>");
647 if (!groups[g].getName().startsWith("JTreeGroup") &&
648 !groups[g].getName().startsWith("JGroup"))
650 tooltipText.append(groups[g].getName());
653 if (groups[g].getDescription() != null)
655 tooltipText.append(": " + groups[g].getDescription());
661 // use aa to see if the mouse pointer is on a
662 if (av.showSequenceFeatures)
664 SequenceFeature[] features = findFeaturesAtRes(
665 sequence.getDatasetSequence(), sequence.findPosition(res));
667 if (features != null)
669 for (int i = 0; i < features.length; i++)
671 if (features[i].getType().equals("disulfide bond"))
673 if (features[i].getBegin() == sequence.findPosition(res)
674 || features[i].getEnd() == sequence.findPosition(res))
676 if (tooltipText.length() > 6)
678 tooltipText.append("<br>");
680 tooltipText.append("disulfide bond " + features[i].getBegin() +
682 features[i].getEnd());
683 if (features[i].links != null)
685 tooltipText.append(" <img src=\"" + linkImageURL + "\">");
691 if (tooltipText.length() > 6)
693 tooltipText.append("<br>");
696 tooltipText.append(features[i].getType() + " " +
698 if (features[i].begin != features[i].end)
700 tooltipText.append(" " + features[i].end);
703 if (features[i].getDescription() != null
704 && !features[i].description.equals(features[i].getType()))
706 tmpString = features[i].getDescription();
707 int startTag = tmpString.toUpperCase().indexOf("<HTML>");
710 tmpString = tmpString.substring(startTag + 6);
712 int endTag = tmpString.toUpperCase().indexOf("</BODY>");
715 tmpString = tmpString.substring(0, endTag);
717 endTag = tmpString.toUpperCase().indexOf("</HTML>");
720 tmpString = tmpString.substring(0, endTag);
725 tooltipText.append("; " + tmpString);
729 if (tmpString.indexOf("<") > -1 || tmpString.indexOf(">") > -1)
731 //The description does not specify html is to
732 //be used, so we must remove < > symbols
733 tmpString = tmpString.replaceAll("<", "<");
734 tmpString = tmpString.replaceAll(">", ">");
736 tooltipText.append("; ");
737 tooltipText.append(tmpString);
742 tooltipText.append("; " + tmpString);
746 if (features[i].getValue("status") != null)
748 String status = features[i].getValue("status").toString();
749 if (status.length() > 0)
751 tooltipText.append("; (" + features[i].getValue("status") + ")");
755 if (features[i].links != null)
757 tooltipText.append(" <img src=\"" + linkImageURL + "\">");
765 if (tooltipText.length() == 6) // <html></html>
767 setToolTipText(null);
771 tooltipText.append("</html>");
772 if (lastTooltip == null || !lastTooltip.equals(tooltipText.toString()))
773 setToolTipText(tooltipText.toString());
775 lastTooltip = tooltipText.toString();
782 * Set status message in alignment panel
783 * @param sequence aligned sequence object
784 * @param res alignment column
785 * @param seq index of sequence in alignment
786 * @return position of res in sequence
788 int setStatusMessage(SequenceI sequence, int res, int seq)
791 StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " +
795 if (av.alignment.isNucleotide())
797 obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) +
801 text.append(" Nucleotide: ");
806 obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
809 text.append(" Residue: ");
815 pos=sequence.findPosition(res);
818 text.append(obj + " (" + pos +
822 ap.alignFrame.statusBar.setText(text.toString());
829 * @param evt DOCUMENT ME!
831 public void mouseDragged(MouseEvent evt)
833 if (mouseWheelPressed)
835 int oldWidth = av.charWidth;
837 //Which is bigger, left-right or up-down?
838 if (Math.abs(evt.getY() - lastMousePress.getY())
839 > Math.abs(evt.getX() - lastMousePress.getX()))
841 int fontSize = av.font.getSize();
843 if (evt.getY() < lastMousePress.getY())
847 else if (evt.getY() > lastMousePress.getY())
857 av.setFont(new Font(av.font.getName(), av.font.getStyle(), fontSize));
858 av.charWidth = oldWidth;
863 if (evt.getX() < lastMousePress.getX() && av.charWidth > 1)
867 else if (evt.getX() > lastMousePress.getX())
872 ap.paintAlignment(false);
875 FontMetrics fm = getFontMetrics(av.getFont());
876 av.validCharWidth = fm.charWidth('M') <= av.charWidth;
878 lastMousePress = evt.getPoint();
885 doMouseDraggedDefineMode(evt);
889 int res = findRes(evt);
896 if ( (lastres == -1) || (lastres == res))
901 if ( (res < av.getAlignment().getWidth()) && (res < lastres))
903 // dragLeft, delete gap
904 editSequence(false, res);
908 editSequence(true, res);
911 mouseDragging = true;
912 if (scrollThread != null)
914 scrollThread.setEvent(evt);
920 synchronized void editSequence(boolean insertGap, int startres)
924 boolean fixedColumns = false;
925 SequenceGroup sg = av.getSelectionGroup();
927 SequenceI seq = av.alignment.getSequenceAt(startseq);
929 //No group, but the sequence may represent a group
930 if (!groupEditing && av.hasHiddenRows)
932 if (av.hiddenRepSequences != null
933 && av.hiddenRepSequences.containsKey(seq))
935 sg = (SequenceGroup) av.hiddenRepSequences.get(seq);
940 StringBuffer message = new StringBuffer();
943 message.append("Edit group:");
944 if (editCommand == null)
946 editCommand = new EditCommand("Edit Group");
951 message.append("Edit sequence: " + seq.getName());
952 String label = seq.getName();
953 if (label.length() > 10)
955 label = label.substring(0, 10);
957 if (editCommand == null)
959 editCommand = new EditCommand("Edit " + label);
965 message.append(" insert ");
969 message.append(" delete ");
972 message.append(Math.abs(startres - lastres) + " gaps.");
973 ap.alignFrame.statusBar.setText(message.toString());
975 //Are we editing within a selection group?
977 || (sg != null && sg.getSequences(av.hiddenRepSequences).contains(seq)))
981 //sg might be null as the user may only see 1 sequence,
982 //but the sequence represents a group
985 if (av.hiddenRepSequences == null
986 || !av.hiddenRepSequences.containsKey(seq))
991 sg = (SequenceGroup) av.hiddenRepSequences.get(seq);
994 fixedLeft = sg.getStartRes();
995 fixedRight = sg.getEndRes();
997 if ( (startres < fixedLeft && lastres >= fixedLeft)
998 || (startres >= fixedLeft && lastres < fixedLeft)
999 || (startres > fixedRight && lastres <= fixedRight)
1000 || (startres <= fixedRight && lastres > fixedRight))
1006 if (fixedLeft > startres)
1008 fixedRight = fixedLeft - 1;
1011 else if (fixedRight < startres)
1013 fixedLeft = fixedRight;
1018 if (av.hasHiddenColumns)
1020 fixedColumns = true;
1021 int y1 = av.getColumnSelection().getHiddenBoundaryLeft(startres);
1022 int y2 = av.getColumnSelection().getHiddenBoundaryRight(startres);
1024 if ( (insertGap && startres > y1 && lastres < y1)
1025 || (!insertGap && startres < y2 && lastres > y2))
1031 //System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
1032 //Selection spans a hidden region
1033 if (fixedLeft < y1 && (fixedRight > y2 || fixedRight == -1))
1041 fixedRight = y2 - 1;
1048 Vector vseqs = sg.getSequences(av.hiddenRepSequences);
1049 int g, groupSize = vseqs.size();
1050 SequenceI[] groupSeqs = new SequenceI[groupSize];
1051 for (g = 0; g < groupSeqs.length; g++)
1053 groupSeqs[g] = (SequenceI) vseqs.elementAt(g);
1059 //If the user has selected the whole sequence, and is dragging to
1060 // the right, we can still extend the alignment and selectionGroup
1061 if (sg.getStartRes() == 0
1062 && sg.getEndRes() == fixedRight
1063 && sg.getEndRes() == av.alignment.getWidth() - 1
1066 sg.setEndRes(av.alignment.getWidth() + startres - lastres);
1067 fixedRight = sg.getEndRes();
1070 // Is it valid with fixed columns??
1071 // Find the next gap before the end
1072 // of the visible region boundary
1073 boolean blank = false;
1074 for (fixedRight = fixedRight;
1075 fixedRight > lastres;
1080 for (g = 0; g < groupSize; g++)
1082 for (int j = 0; j < startres - lastres; j++)
1084 if (!jalview.util.Comparison.isGap(
1085 groupSeqs[g].getCharAt(fixedRight - j)))
1100 if (sg.getSize() == av.alignment.getHeight())
1102 if ( (av.hasHiddenColumns
1104 startres < av.getColumnSelection().getHiddenBoundaryRight(startres)))
1110 int alWidth = av.alignment.getWidth();
1111 if (av.hasHiddenRows)
1113 int hwidth = av.alignment.getHiddenSequences().getWidth();
1114 if (hwidth > alWidth)
1119 //We can still insert gaps if the selectionGroup
1120 //contains all the sequences
1121 sg.setEndRes(sg.getEndRes() + startres - lastres);
1122 fixedRight = alWidth + startres - lastres;
1133 else if (!insertGap)
1135 /// Are we able to delete?
1136 // ie are all columns blank?
1138 for (g = 0; g < groupSize; g++)
1140 for (int j = startres; j < lastres; j++)
1142 if (groupSeqs[g].getLength() <= j)
1147 if (!jalview.util.Comparison.isGap(
1148 groupSeqs[g].getCharAt(j)))
1150 // Not a gap, block edit not valid
1160 // dragging to the right
1161 if (fixedColumns && fixedRight != -1)
1163 for (int j = lastres; j < startres; j++)
1165 insertChar(j, groupSeqs, fixedRight);
1170 editCommand.appendEdit(EditCommand.INSERT_GAP,
1172 startres, startres - lastres,
1179 // dragging to the left
1180 if (fixedColumns && fixedRight != -1)
1182 for (int j = lastres; j > startres; j--)
1184 deleteChar(startres, groupSeqs, fixedRight);
1189 editCommand.appendEdit(EditCommand.DELETE_GAP,
1191 startres, lastres - startres,
1198 else /////Editing a single sequence///////////
1202 // dragging to the right
1203 if (fixedColumns && fixedRight != -1)
1205 for (int j = lastres; j < startres; j++)
1207 insertChar(j, new SequenceI[]
1213 editCommand.appendEdit(EditCommand.INSERT_GAP,
1216 lastres, startres - lastres,
1223 // dragging to the left
1224 if (fixedColumns && fixedRight != -1)
1226 for (int j = lastres; j > startres; j--)
1228 if (!jalview.util.Comparison.isGap(seq.getCharAt(startres)))
1233 deleteChar(startres, new SequenceI[]
1239 //could be a keyboard edit trying to delete none gaps
1241 for (int m = startres; m < lastres; m++)
1243 if (!jalview.util.Comparison.isGap(seq.getCharAt(m)))
1252 editCommand.appendEdit(EditCommand.DELETE_GAP,
1264 seqCanvas.repaint();
1267 void insertChar(int j, SequenceI[] seq, int fixedColumn)
1269 int blankColumn = fixedColumn;
1270 for (int s = 0; s < seq.length; s++)
1272 //Find the next gap before the end of the visible region boundary
1273 //If lastCol > j, theres a boundary after the gap insertion
1275 for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
1277 if (jalview.util.Comparison.isGap(seq[s].getCharAt(blankColumn)))
1279 //Theres a space, so break and insert the gap
1284 if (blankColumn <= j)
1286 blankColumn = fixedColumn;
1292 editCommand.appendEdit(EditCommand.DELETE_GAP,
1294 blankColumn, 1, av.alignment, true);
1296 editCommand.appendEdit(EditCommand.INSERT_GAP,
1303 void deleteChar(int j, SequenceI[] seq, int fixedColumn)
1306 editCommand.appendEdit(EditCommand.DELETE_GAP,
1308 j, 1, av.alignment, true);
1310 editCommand.appendEdit(EditCommand.INSERT_GAP,
1312 fixedColumn, 1, av.alignment, true);
1318 * @param e DOCUMENT ME!
1320 public void mouseEntered(MouseEvent e)
1327 if (scrollThread != null)
1329 scrollThread.running = false;
1330 scrollThread = null;
1337 * @param e DOCUMENT ME!
1339 public void mouseExited(MouseEvent e)
1341 if (av.getWrapAlignment())
1348 scrollThread = new ScrollThread();
1352 public void mouseClicked(MouseEvent evt)
1354 SequenceI sequence = av.alignment.getSequenceAt(findSeq(evt));
1355 if (evt.getClickCount() > 1)
1357 if (av.getSelectionGroup().getSize() == 1
1358 && av.getSelectionGroup().getEndRes()
1359 - av.getSelectionGroup().getStartRes() < 2)
1361 av.setSelectionGroup(null);
1364 SequenceFeature[] features = findFeaturesAtRes(
1365 sequence.getDatasetSequence(),
1366 sequence.findPosition(findRes(evt))
1369 if (features != null && features.length > 0)
1371 SearchResults highlight = new SearchResults();
1372 highlight.addResult(sequence,
1373 features[0].getBegin(),
1374 features[0].getEnd());
1375 seqCanvas.highlightSearchResults(highlight);
1377 if (features != null && features.length > 0)
1379 seqCanvas.getFeatureRenderer().amendFeatures(
1381 {sequence}, features, false, ap);
1383 seqCanvas.highlightSearchResults(null);
1388 public void mouseWheelMoved(MouseWheelEvent e)
1391 if (e.getWheelRotation() > 0)
1404 * @param evt DOCUMENT ME!
1406 public void doMousePressedDefineMode(MouseEvent evt)
1408 int res = findRes(evt);
1409 int seq = findSeq(evt);
1412 startWrapBlock = wrappedBlock;
1414 if (av.wrapAlignment && seq > av.alignment.getHeight())
1416 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1417 "Cannot edit annotations in wrapped view.",
1418 "Wrapped view - no edit",
1419 JOptionPane.WARNING_MESSAGE);
1423 if (seq < 0 || res < 0)
1428 SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq);
1430 if ( (sequence == null) || (res > sequence.getLength()))
1435 stretchGroup = av.getSelectionGroup();
1437 if (stretchGroup == null)
1439 stretchGroup = av.alignment.findGroup(sequence);
1441 if ( (stretchGroup != null) && (res > stretchGroup.getStartRes()) &&
1442 (res < stretchGroup.getEndRes()))
1444 av.setSelectionGroup(stretchGroup);
1448 stretchGroup = null;
1451 else if (!stretchGroup.getSequences(null).contains(sequence) ||
1452 (stretchGroup.getStartRes() > res) ||
1453 (stretchGroup.getEndRes() < res))
1455 stretchGroup = null;
1457 SequenceGroup[] allGroups = av.alignment.findAllGroups(sequence);
1459 if (allGroups != null)
1461 for (int i = 0; i < allGroups.length; i++)
1463 if ( (allGroups[i].getStartRes() <= res) &&
1464 (allGroups[i].getEndRes() >= res))
1466 stretchGroup = allGroups[i];
1472 av.setSelectionGroup(stretchGroup);
1476 if (javax.swing.SwingUtilities.isRightMouseButton(evt))
1478 SequenceFeature [] allFeatures = findFeaturesAtRes(sequence.getDatasetSequence(),
1479 sequence.findPosition(res));
1480 Vector links = new Vector();
1481 for (int i = 0; i < allFeatures.length; i++)
1483 if (allFeatures[i].links != null)
1485 for (int j = 0; j < allFeatures[i].links.size(); j++)
1487 links.addElement(allFeatures[i].links.elementAt(j));
1492 jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(ap, null, links);
1493 pop.show(this, evt.getX(), evt.getY());
1499 seqCanvas.cursorX = findRes(evt);
1500 seqCanvas.cursorY = findSeq(evt);
1501 seqCanvas.repaint();
1505 if (stretchGroup == null)
1507 //Only if left mouse button do we want to change group sizes
1509 // define a new group here
1510 SequenceGroup sg = new SequenceGroup();
1511 sg.setStartRes(res);
1513 sg.addSequence(sequence, false);
1514 av.setSelectionGroup(sg);
1517 if (av.getConservationSelected())
1519 SliderPanel.setConservationSlider(ap,
1520 av.getGlobalColourScheme(),
1524 if (av.getAbovePIDThreshold())
1526 SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(),
1529 if ( (stretchGroup != null) && (stretchGroup.getEndRes() == res))
1531 // Edit end res position of selected group
1532 changeEndRes = true;
1534 else if ( (stretchGroup != null) &&
1535 (stretchGroup.getStartRes() == res))
1537 // Edit end res position of selected group
1538 changeStartRes = true;
1540 stretchGroup.getWidth();
1543 seqCanvas.repaint();
1549 * @param evt DOCUMENT ME!
1551 public void doMouseReleasedDefineMode(MouseEvent evt)
1553 if (stretchGroup == null)
1558 if (stretchGroup.cs != null)
1560 if (stretchGroup.cs instanceof ClustalxColourScheme)
1562 ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX(
1563 stretchGroup.getSequences(av.hiddenRepSequences),
1564 stretchGroup.getWidth());
1567 if (stretchGroup.cs instanceof Blosum62ColourScheme
1568 || stretchGroup.cs instanceof PIDColourScheme
1569 || stretchGroup.cs.conservationApplied()
1570 || stretchGroup.cs.getThreshold() > 0)
1572 stretchGroup.recalcConservation();
1575 if (stretchGroup.cs.conservationApplied())
1577 SliderPanel.setConservationSlider(ap, stretchGroup.cs,
1578 stretchGroup.getName());
1582 SliderPanel.setPIDSliderSource(ap, stretchGroup.cs,
1583 stretchGroup.getName());
1585 PaintRefresher.Refresh(this, av.getSequenceSetId());
1586 ap.paintAlignment(true);
1589 changeEndRes = false;
1590 changeStartRes = false;
1591 stretchGroup = null;
1598 * @param evt DOCUMENT ME!
1600 public void doMouseDraggedDefineMode(MouseEvent evt)
1602 int res = findRes(evt);
1603 int y = findSeq(evt);
1605 if (wrappedBlock != startWrapBlock)
1610 if (stretchGroup == null)
1615 if (res >= av.alignment.getWidth())
1617 res = av.alignment.getWidth() - 1;
1620 if (stretchGroup.getEndRes() == res)
1622 // Edit end res position of selected group
1623 changeEndRes = true;
1625 else if (stretchGroup.getStartRes() == res)
1627 // Edit start res position of selected group
1628 changeStartRes = true;
1631 if (res < av.getStartRes())
1633 res = av.getStartRes();
1638 if (res > (stretchGroup.getStartRes() - 1))
1640 stretchGroup.setEndRes(res);
1643 else if (changeStartRes)
1645 if (res < (stretchGroup.getEndRes() + 1))
1647 stretchGroup.setStartRes(res);
1651 int dragDirection = 0;
1657 else if (y < oldSeq)
1662 while ( (y != oldSeq) && (oldSeq > -1) && (y < av.alignment.getHeight()))
1664 // This routine ensures we don't skip any sequences, as the
1665 // selection is quite slow.
1666 Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
1668 oldSeq += dragDirection;
1675 Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
1677 if (stretchGroup.getSequences(null).contains(nextSeq))
1679 stretchGroup.deleteSequence(seq, false);
1685 stretchGroup.addSequence(seq, false);
1688 stretchGroup.addSequence(nextSeq, false);
1697 mouseDragging = true;
1699 if (scrollThread != null)
1701 scrollThread.setEvent(evt);
1704 seqCanvas.repaint();
1707 void scrollCanvas(MouseEvent evt)
1711 if (scrollThread != null)
1713 scrollThread.running = false;
1714 scrollThread = null;
1716 mouseDragging = false;
1720 if (scrollThread == null)
1722 scrollThread = new ScrollThread();
1725 mouseDragging = true;
1726 scrollThread.setEvent(evt);
1731 // this class allows scrolling off the bottom of the visible alignment
1736 boolean running = false;
1738 public ScrollThread()
1743 public void setEvent(MouseEvent e)
1748 public void stopScrolling()
1761 if (mouseDragging && (evt.getY() < 0) &&
1762 (av.getStartSeq() > 0))
1764 running = ap.scrollUp(true);
1767 if (mouseDragging && (evt.getY() >= getHeight()) &&
1768 (av.alignment.getHeight() > av.getEndSeq()))
1770 running = ap.scrollUp(false);
1773 if (mouseDragging && (evt.getX() < 0))
1775 running = ap.scrollRight(false);
1777 else if (mouseDragging && (evt.getX() >= getWidth()))
1779 running = ap.scrollRight(true);
1787 catch (Exception ex)