2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 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
23 import java.awt.event.*;
\r
25 import jalview.datamodel.*;
\r
26 import jalview.schemes.*;
\r
28 import java.util.Vector;
\r
30 public class SeqPanel
\r
31 extends Panel implements MouseMotionListener, MouseListener
\r
34 public SeqCanvas seqCanvas;
\r
35 public AlignmentPanel ap;
\r
37 protected int lastres;
\r
38 protected int startseq;
\r
40 protected AlignViewport av;
\r
42 // if character is inserted or deleted, we will need to recalculate the conservation
\r
43 boolean seqEditOccurred = false;
\r
45 ScrollThread scrollThread = null;
\r
46 boolean mouseDragging = false;
\r
47 boolean editingSeqs = false;
\r
48 boolean groupEditing = false;
\r
51 boolean changeEndSeq = false;
\r
52 boolean changeStartSeq = false;
\r
53 boolean changeEndRes = false;
\r
54 boolean changeStartRes = false;
\r
55 SequenceGroup stretchGroup = null;
\r
57 StringBuffer keyboardNo1;
\r
58 StringBuffer keyboardNo2;
\r
60 boolean mouseWheelPressed = false;
\r
61 Point lastMousePress;
\r
63 public SeqPanel(AlignViewport avp, AlignmentPanel p)
\r
67 seqCanvas = new SeqCanvas(avp);
\r
68 setLayout(new BorderLayout());
\r
73 seqCanvas.addMouseMotionListener(this);
\r
74 seqCanvas.addMouseListener(this);
\r
76 seqCanvas.repaint();
\r
83 seqEditOccurred = false;
\r
84 editingSeqs = false;
\r
85 groupEditing = false;
\r
92 seqCanvas.cursorY = getKeyboardNo(keyboardNo1)-1;
\r
96 void setCursorColumn()
\r
98 seqCanvas.cursorX = getKeyboardNo(keyboardNo1)-1;
\r
102 void setCursorRowAndColumn()
\r
104 if(keyboardNo2==null)
\r
106 keyboardNo2 = new StringBuffer();
\r
110 seqCanvas.cursorX = getKeyboardNo(keyboardNo1) - 1;
\r
111 seqCanvas.cursorY = getKeyboardNo(keyboardNo2) - 1;
\r
116 void setCursorPosition()
\r
118 SequenceI sequence =
\r
119 (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);
\r
121 seqCanvas.cursorX = sequence.findIndex(
\r
122 getKeyboardNo(keyboardNo1)-1
\r
127 void moveCursor(int dx, int dy)
\r
129 seqCanvas.cursorX += dx;
\r
130 seqCanvas.cursorY += dy;
\r
134 void scrollToVisible()
\r
136 if (seqCanvas.cursorX < 0)
\r
137 seqCanvas.cursorX = 0;
\r
138 else if (seqCanvas.cursorX > av.alignment.getWidth() - 1)
\r
139 seqCanvas.cursorX = av.alignment.getWidth() - 1;
\r
141 if (seqCanvas.cursorY < 0)
\r
142 seqCanvas.cursorY = 0;
\r
143 else if (seqCanvas.cursorY > av.alignment.getHeight() - 1)
\r
144 seqCanvas.cursorY = av.alignment.getHeight() - 1;
\r
148 if (av.wrapAlignment)
\r
150 ap.scrollToWrappedVisible(seqCanvas.cursorX);
\r
154 while (seqCanvas.cursorY < av.startSeq)
\r
158 while (seqCanvas.cursorY + 1 > av.endSeq)
\r
160 ap.scrollUp(false);
\r
162 while (seqCanvas.cursorX < av.startRes)
\r
165 if (!ap.scrollRight(false))
\r
168 while (seqCanvas.cursorX > av.endRes)
\r
170 if (!ap.scrollRight(true))
\r
174 setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY),
\r
175 seqCanvas.cursorX, seqCanvas.cursorY);
\r
177 seqCanvas.repaint();
\r
180 void setSelectionAreaAtCursor(boolean topLeft)
\r
182 SequenceI sequence =
\r
183 (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);
\r
185 if(av.getSelectionGroup()!=null)
\r
187 SequenceGroup sg = av.selectionGroup;
\r
188 //Find the top and bottom of this group
\r
189 int min = av.alignment.getHeight(), max = 0;
\r
190 for(int i=0; i<sg.getSize(false); i++)
\r
192 int index = av.alignment.findIndex( sg.getSequenceAt(i) );
\r
203 sg.setStartRes(seqCanvas.cursorX);
\r
204 if(sg.getEndRes()<seqCanvas.cursorX)
\r
205 sg.setEndRes(seqCanvas.cursorX);
\r
207 min = seqCanvas.cursorY;
\r
211 sg.setEndRes(seqCanvas.cursorX);
\r
212 if(sg.getStartRes()>seqCanvas.cursorX)
\r
213 sg.setStartRes(seqCanvas.cursorX);
\r
215 max = seqCanvas.cursorY+1;
\r
220 // Only the user can do this
\r
221 av.setSelectionGroup(null);
\r
225 // Now add any sequences between min and max
\r
226 sg.getSequences(false).removeAllElements();
\r
227 for (int i = min; i < max; i++)
\r
229 sg.addSequence(av.alignment.getSequenceAt(i), false);
\r
234 if (av.getSelectionGroup() == null)
\r
236 SequenceGroup sg = new SequenceGroup();
\r
237 sg.setStartRes(seqCanvas.cursorX);
\r
238 sg.setEndRes(seqCanvas.cursorX);
\r
239 sg.addSequence(sequence, false);
\r
240 av.setSelectionGroup(sg);
\r
247 void insertGapAtCursor(boolean group)
\r
249 ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence",
\r
250 av.alignment, HistoryItem.EDIT));
\r
251 groupEditing = group;
\r
252 startseq = seqCanvas.cursorY;
\r
253 lastres = seqCanvas.cursorX;
\r
254 editSequence(true, seqCanvas.cursorX+getKeyboardNo(keyboardNo1));
\r
258 void deleteGapAtCursor(boolean group)
\r
260 ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence",
\r
261 av.alignment, HistoryItem.EDIT));
\r
262 groupEditing = group;
\r
263 startseq = seqCanvas.cursorY;
\r
264 lastres = seqCanvas.cursorX+getKeyboardNo(keyboardNo1);
\r
265 editSequence(false, seqCanvas.cursorX);
\r
269 void numberPressed(char value)
\r
271 if(keyboardNo1==null)
\r
272 keyboardNo1 = new StringBuffer();
\r
274 if(keyboardNo2!=null)
\r
275 keyboardNo2.append(value);
\r
277 keyboardNo1.append(value);
\r
280 int getKeyboardNo(StringBuffer kb)
\r
285 return Integer.parseInt(kb.toString());
\r
288 void setStatusMessage(SequenceI sequence, int res, int seq)
\r
290 StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " +
\r
291 sequence.getName());
\r
294 if (av.alignment.isNucleotide())
\r
296 obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) +
\r
299 text.append(" Nucleotide: ");
\r
303 obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
\r
305 text.append(" Residue: ");
\r
313 text.append(obj + " (" + sequence.findPosition(res) +
\r
318 ap.alignFrame.statusBar.setText(text.toString());
\r
321 public void mousePressed(MouseEvent evt)
\r
323 lastMousePress = evt.getPoint();
\r
325 if ( (evt.getModifiers() & InputEvent.BUTTON2_MASK) ==
\r
326 InputEvent.BUTTON2_MASK)
\r
328 mouseWheelPressed = true;
\r
332 if (evt.isShiftDown() || evt.isAltDown() ||
\r
333 evt.isControlDown())
\r
335 if (evt.isAltDown() || evt.isControlDown())
\r
337 groupEditing = true;
\r
339 editingSeqs = true;
\r
343 doMousePressedDefineMode(evt);
\r
348 int seq = findSeq(evt);
\r
349 int res = findRes(evt);
\r
354 ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence",
\r
355 av.alignment, HistoryItem.EDIT));
\r
357 if ((seq < av.getAlignment().getHeight()) &&
\r
358 (res < av.getAlignment().getSequenceAt(seq).getLength()))
\r
372 public void mouseClicked(MouseEvent evt){}
\r
375 public void mouseReleased(MouseEvent evt)
\r
377 mouseDragging = false;
\r
378 mouseWheelPressed = false;
\r
382 doMouseReleasedDefineMode(evt);
\r
392 int startWrapBlock=-1;
\r
393 int wrappedBlock=-1;
\r
394 int findRes(MouseEvent evt)
\r
397 int x = evt.getX();
\r
399 if (av.wrapAlignment)
\r
402 int hgap = av.charHeight;
\r
403 if (av.scaleAboveWrapped)
\r
404 hgap += av.charHeight;
\r
406 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
407 + hgap + seqCanvas.getAnnotationHeight();
\r
409 int y = evt.getY();
\r
411 x -= seqCanvas.LABEL_WEST;
\r
414 int cwidth = seqCanvas.getWrappedCanvasWidth(getSize().width);
\r
416 wrappedBlock = y / cHeight;
\r
417 wrappedBlock += av.getStartRes() / cwidth;
\r
419 res = wrappedBlock * cwidth + x / av.getCharWidth();
\r
424 res = (x / av.getCharWidth()) + av.getStartRes();
\r
431 int findSeq(MouseEvent evt)
\r
435 int y = evt.getY();
\r
437 if (av.wrapAlignment)
\r
439 int hgap = av.charHeight;
\r
440 if (av.scaleAboveWrapped)
\r
441 hgap += av.charHeight;
\r
443 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
444 + hgap + seqCanvas.getAnnotationHeight();
\r
448 seq = ( (y % cHeight) / av.getCharHeight());
\r
452 seq = (y / av.getCharHeight()) + av.getStartSeq();
\r
459 public void doMousePressed(MouseEvent evt)
\r
461 ap.alignFrame.addHistoryItem(new HistoryItem(
\r
462 "Edit Sequence", av.alignment, HistoryItem.EDIT));
\r
464 int seq = findSeq(evt);
\r
465 int res = findRes(evt);
\r
467 if (seq < av.getAlignment().getHeight() &&
\r
468 res < av.getAlignment().getSequenceAt(seq).getLength())
\r
470 //char resstr = align.getSequenceAt(seq).getSequence().charAt(res);
\r
471 // Find the residue's position in the sequence (res is the position
\r
472 // in the alignment
\r
486 public void mouseMoved(MouseEvent evt)
\r
488 int res = findRes(evt);
\r
489 int seq = findSeq(evt);
\r
491 if (seq >= av.getAlignment().getHeight() || seq<0 || res<0)
\r
496 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
\r
497 if (res > sequence.getLength())
\r
502 StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " +
\r
503 sequence.getName());
\r
506 if (av.alignment.isNucleotide())
\r
508 obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) +
\r
511 text.append(" Nucleotide: ");
\r
515 obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
\r
517 text.append(" Residue: ");
\r
525 text.append(obj + " (" +
\r
526 av.getAlignment().getSequenceAt(seq).findPosition(res) + ")");
\r
530 if(seqCanvas.pdbCanvas!=null && sequence==seqCanvas.pdbCanvas.sequence)
\r
532 seqCanvas.pdbCanvas.highlightRes(sequence.findPosition(res));
\r
536 // use aa to see if the mouse pointer is on a
\r
537 if (av.showSequenceFeatures
\r
538 && sequence.getSequenceFeatures()!=null
\r
539 && av.featuresDisplayed!=null)
\r
541 StringBuffer featureText = new StringBuffer();
\r
542 Vector allFeatures = getAllFeaturesAtRes(sequence, sequence.findPosition(res));
\r
545 while (index < allFeatures.size())
\r
547 SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(index);
\r
549 featureText.append(sf.getType()+" "+sf.begin+":"+sf.end);
\r
551 if (sf.getDescription() != null)
\r
552 featureText.append(" " + sf.getDescription());
\r
554 if (sf.getValue("status") != null )
\r
556 featureText.append(" (" + sf.getValue("status") + ")");
\r
558 featureText.append("\n");
\r
564 if (tooltip == null)
\r
565 tooltip = new Tooltip(featureText.toString(), seqCanvas);
\r
567 tooltip.setTip(featureText.toString());
\r
571 // text.append(" Sequence Feature:");
\r
572 // text.append(featureText);
\r
577 ap.alignFrame.statusBar.setText(text.toString());
\r
581 Vector getAllFeaturesAtRes(SequenceI seq, int res)
\r
583 Vector allFeatures = new Vector();
\r
585 if(seq.getSequenceFeatures()!=null)
\r
587 while (index < seq.getSequenceFeatures().length)
\r
589 SequenceFeature sf = seq.getSequenceFeatures()[index];
\r
590 if (sf.getBegin() <= res &&
\r
591 sf.getEnd() >= res)
\r
593 if (av.featuresDisplayed.containsKey(sf.getType()))
\r
595 allFeatures.addElement(sf);
\r
601 return allFeatures;
\r
606 public void mouseDragged(MouseEvent evt)
\r
608 if (mouseWheelPressed)
\r
610 int oldWidth = av.charWidth;
\r
612 //Which is bigger, left-right or up-down?
\r
613 if (Math.abs(evt.getY() - lastMousePress.y)
\r
614 > Math.abs(evt.getX() - lastMousePress.x))
\r
616 int fontSize = av.font.getSize();
\r
618 if (evt.getY() < lastMousePress.y && av.charHeight > 1)
\r
622 else if (evt.getY() > lastMousePress.y)
\r
631 av.setFont(new Font(av.font.getName(), av.font.getStyle(), fontSize));
\r
632 av.charWidth = oldWidth;
\r
636 if (evt.getX() < lastMousePress.x && av.charWidth > 1)
\r
640 else if (evt.getX() > lastMousePress.x)
\r
653 FontMetrics fm = getFontMetrics(av.getFont());
\r
654 av.validCharWidth = fm.charWidth('M') <= av.charWidth;
\r
656 lastMousePress = evt.getPoint();
\r
659 ap.annotationPanel.image = null;
\r
665 doMouseDraggedDefineMode(evt);
\r
669 int res = findRes(evt);
\r
676 if ((lastres == -1) || (lastres == res))
\r
681 if ( (res < av.getAlignment().getWidth()) && (res < lastres))
\r
683 // dragLeft, delete gap
\r
684 editSequence(false, res);
\r
687 editSequence(true, res);
\r
689 mouseDragging = true;
\r
690 if(scrollThread!=null)
\r
691 scrollThread.setEvent(evt);
\r
695 synchronized void editSequence(boolean insertGap, int startres)
\r
697 int fixedLeft = -1;
\r
698 int fixedRight = -1;
\r
699 boolean fixedColumns = false;
\r
700 SequenceGroup sg = av.getSelectionGroup();
\r
702 if(groupEditing && sg==null)
\r
705 SequenceI seq = av.alignment.getSequenceAt(startseq);
\r
706 StringBuffer message = new StringBuffer();
\r
708 message.append("Edit group:");
\r
710 message.append("Edit sequence: "+seq.getName());
\r
713 message.append(" insert ");
\r
715 message.append(" delete ");
\r
717 message.append(Math.abs(startres-lastres)+" gaps.");
\r
718 ap.alignFrame.statusBar.setText(message.toString());
\r
721 //Are we editing within a selection group?
\r
723 || (sg != null && sg.getSequences(false).contains(seq)))
\r
725 fixedColumns = true;
\r
727 fixedLeft = sg.getStartRes();
\r
728 fixedRight = sg.getEndRes();
\r
730 if ( (startres < fixedLeft && lastres >= fixedLeft)
\r
731 || (startres >= fixedLeft && lastres < fixedLeft)
\r
732 || (startres > fixedRight && lastres <=fixedRight)
\r
733 || (startres <= fixedRight && lastres > fixedRight))
\r
739 if (fixedLeft > startres)
\r
741 fixedRight = fixedLeft - 1;
\r
744 else if (fixedRight < startres)
\r
746 fixedLeft = fixedRight;
\r
757 //If the user has selected the whole sequence, and is dragging to
\r
758 // the right, we can still extend the alignment and selectionGroup
\r
759 if(sg.getStartRes() == 0 && sg.getEndRes() + 1 == av.alignment.getWidth())
\r
761 sg.setEndRes(av.alignment.getWidth() + startres - lastres);
\r
762 fixedRight = sg.getEndRes();
\r
765 // Is it valid with fixed columns??
\r
766 // Find the next gap before the end
\r
767 // of the visible region boundary
\r
768 boolean blank = false;
\r
769 for (fixedRight = fixedRight;
\r
770 fixedRight > lastres;
\r
774 for (int s = 0; s < sg.getSize(false); s++)
\r
776 seq = sg.getSequenceAt(s);
\r
777 for (int j = 0; j < startres - lastres; j++)
\r
779 if (!jalview.util.Comparison.isGap(
\r
780 seq.getCharAt(fixedRight - j)))
\r
793 if(sg.getSize(false) == av.alignment.getHeight())
\r
795 //We can still insert gaps if the selectionGroup
\r
796 //contains all the sequences
\r
797 sg.setEndRes(sg.getEndRes()+startres-lastres);
\r
798 fixedRight = av.alignment.getWidth()+startres-lastres;
\r
810 else if(!insertGap)
\r
812 /// Are we able to delete?
\r
813 // ie are all columns blank?
\r
815 for (int s = 0; s < sg.getSize(false); s++)
\r
817 seq = sg.getSequenceAt(s);
\r
819 for (int j = startres; j < lastres; j++)
\r
821 if (seq.getSequence().length() <= j)
\r
826 if (!jalview.util.Comparison.isGap(
\r
827 seq.getSequence().charAt(j)))
\r
829 // Not a gap, block edit not valid
\r
838 for (int i = 0; i < sg.getSize(false); i++)
\r
840 seq = sg.getSequenceAt(i);
\r
844 // dragging to the right
\r
845 for (int j = lastres; j < startres; j++)
\r
847 if (fixedColumns && fixedRight != -1)
\r
849 insertChar(j, seq, fixedRight);
\r
852 insertChar(j, seq);
\r
857 // dragging to the left
\r
858 for (int j = lastres; j > startres; j--)
\r
860 if (fixedColumns && fixedRight != -1)
\r
862 deleteChar(startres, seq, fixedRight);
\r
866 deleteChar(startres, seq);
\r
872 else /////Editing a single sequence///////////
\r
876 // dragging to the right
\r
877 for (int j = lastres; j < startres; j++)
\r
879 if (fixedColumns && fixedRight != -1)
\r
881 if (sg.getStartRes() == 0
\r
882 && sg.getEndRes() + 1 == av.alignment.getWidth()
\r
883 && !jalview.util.Comparison.isGap(seq.getCharAt(fixedRight)))
\r
885 //Single sequence edit, whole sequence selected,
\r
886 //extend the selection group
\r
887 sg.setEndRes(av.alignment.getWidth() -1 + startres - lastres);
\r
888 fixedColumns = false;
\r
889 insertChar(j, seq);
\r
892 insertChar(j, seq, fixedRight);
\r
895 insertChar(j, seq);
\r
900 // dragging to the left
\r
901 for (int j = lastres; j > startres; j--)
\r
903 if (fixedColumns && fixedRight != -1)
\r
905 deleteChar(startres, seq, fixedRight);
\r
909 deleteChar(startres, seq);
\r
915 lastres = startres;
\r
916 seqCanvas.repaint();
\r
923 * @param j DOCUMENT ME!
\r
924 * @param seq DOCUMENT ME!
\r
926 void insertChar(int j, SequenceI seq)
\r
928 seq.insertCharAt(j, av.getGapCharacter());
\r
929 seqEditOccurred = true;
\r
932 void insertChar(int j, SequenceI seq, int fixedColumn)
\r
934 //Find the next gap before the end of the visible region boundary
\r
935 //If lastCol > j, theres a boundary after the gap insertion
\r
936 int blankColumn = fixedColumn;
\r
937 for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
\r
939 if (jalview.util.Comparison.isGap(seq.getCharAt(blankColumn)))
\r
941 //Theres a space, so break and insert the gap
\r
946 if (blankColumn <= j)
\r
952 if (!jalview.util.Comparison.isGap(seq.getCharAt(blankColumn)))
\r
955 System.out.println("Tried removing residue (INSERT)"+seq.getCharAt(fixedColumn));
\r
959 seq.deleteCharAt(blankColumn);
\r
960 seq.insertCharAt(j, av.getGapCharacter());
\r
961 seqEditOccurred = true;
\r
964 void deleteChar(int j, SequenceI seq, int fixedColumn)
\r
966 if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))
\r
968 ap.alignFrame.statusBar.setText(
\r
969 "End editing: Tried removing residue " + seq.getCharAt(j));
\r
973 seq.deleteCharAt(j);
\r
974 seq.insertCharAt(fixedColumn, av.getGapCharacter());
\r
975 seqEditOccurred = true;
\r
981 * @param j DOCUMENT ME!
\r
982 * @param seq DOCUMENT ME!
\r
984 void deleteChar(int j, SequenceI seq)
\r
986 if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))
\r
988 ap.alignFrame.statusBar.setText(
\r
989 "End editing: Tried removing residue " + seq.getCharAt(j));
\r
993 seq.deleteCharAt(j);
\r
994 seqEditOccurred = true;
\r
995 seqCanvas.repaint();
\r
1001 * @param i DOCUMENT ME!
\r
1003 void editOccurred()
\r
1005 if (!seqEditOccurred)
\r
1007 ap.alignFrame.historyList.pop();
\r
1008 ap.alignFrame.updateEditMenuBar();
\r
1013 av.firePropertyChange("alignment", null,av.getAlignment().getSequences());
\r
1017 //////////////////////////////////////////
\r
1018 /////Everything below this is for defining the boundary of the rubberband
\r
1019 //////////////////////////////////////////
\r
1020 public void doMousePressedDefineMode(MouseEvent evt)
\r
1024 if (scrollThread != null)
\r
1026 scrollThread.running = false;
\r
1027 scrollThread = null;
\r
1030 int res = findRes(evt);
\r
1031 int seq = findSeq(evt);
\r
1033 startWrapBlock=wrappedBlock;
\r
1038 SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq);
\r
1040 if (sequence == null || res > sequence.getLength())
\r
1045 stretchGroup = av.getSelectionGroup();
\r
1047 if (stretchGroup == null)
\r
1049 stretchGroup = av.alignment.findGroup(sequence);
\r
1050 if (stretchGroup != null && res > stretchGroup.getStartRes() &&
\r
1051 res < stretchGroup.getEndRes())
\r
1053 av.setSelectionGroup(stretchGroup);
\r
1057 stretchGroup = null;
\r
1061 else if (!stretchGroup.getSequences(false).contains(sequence)
\r
1062 || stretchGroup.getStartRes() > res
\r
1063 || stretchGroup.getEndRes() < res)
\r
1065 stretchGroup = null;
\r
1067 SequenceGroup[] allGroups = av.alignment.findAllGroups(sequence);
\r
1069 if (allGroups != null)
\r
1071 for (int i = 0; i < allGroups.length; i++)
\r
1073 if (allGroups[i].getStartRes() <= res &&
\r
1074 allGroups[i].getEndRes() >= res)
\r
1076 stretchGroup = allGroups[i];
\r
1081 av.setSelectionGroup(stretchGroup);
\r
1084 if (av.cursorMode)
\r
1086 seqCanvas.cursorX = findRes(evt);
\r
1087 seqCanvas.cursorY = findSeq(evt);
\r
1088 seqCanvas.repaint();
\r
1094 // DETECT RIGHT MOUSE BUTTON IN AWT
\r
1095 if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK) ==
\r
1096 InputEvent.BUTTON3_MASK)
\r
1098 Vector allFeatures = getAllFeaturesAtRes(sequence,
\r
1099 sequence.findPosition(res));
\r
1101 Vector links = null;
\r
1102 if(allFeatures!=null)
\r
1104 for (int i = 0; i < allFeatures.size(); i++)
\r
1106 SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(i);
\r
1107 if (sf.links != null)
\r
1109 links = new Vector();
\r
1110 for (int j = 0; j < sf.links.size(); j++)
\r
1112 links.addElement(sf.links.elementAt(j));
\r
1117 APopupMenu popup = new APopupMenu(ap, null, links);
\r
1119 popup.show(this, evt.getX(), evt.getY());
\r
1124 //Only if left mouse button do we want to change group sizes
\r
1126 if (stretchGroup == null)
\r
1128 // define a new group here
\r
1129 SequenceGroup sg = new SequenceGroup();
\r
1130 sg.setStartRes(res);
\r
1131 sg.setEndRes(res);
\r
1132 sg.addSequence(sequence, false);
\r
1133 av.setSelectionGroup(sg);
\r
1134 stretchGroup = sg;
\r
1136 if (av.getConservationSelected())
\r
1138 SliderPanel.setConservationSlider(ap, av.getGlobalColourScheme(),
\r
1141 if (av.getAbovePIDThreshold())
\r
1143 SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(),
\r
1149 if (stretchGroup != null && stretchGroup.getEndRes() == res)
\r
1151 // Edit end res position of selected group
\r
1152 changeEndRes = true;
\r
1155 else if (stretchGroup != null && stretchGroup.getStartRes() == res)
\r
1157 // Edit end res position of selected group
\r
1158 changeStartRes = true;
\r
1163 public void doMouseReleasedDefineMode(MouseEvent evt)
\r
1165 if (stretchGroup == null)
\r
1170 if(stretchGroup.cs!=null)
\r
1172 if (stretchGroup.cs instanceof ClustalxColourScheme)
\r
1174 ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX(
\r
1175 stretchGroup.getSequences(true),
\r
1176 stretchGroup.getWidth());
\r
1179 if (stretchGroup.cs.conservationApplied())
\r
1181 SliderPanel.setConservationSlider(ap, stretchGroup.cs,
\r
1182 stretchGroup.getName());
\r
1183 stretchGroup.recalcConservation();
\r
1187 SliderPanel.setPIDSliderSource(ap, stretchGroup.cs,
\r
1188 stretchGroup.getName());
\r
1191 changeEndRes = false;
\r
1192 changeStartRes = false;
\r
1193 stretchGroup = null;
\r
1194 PaintRefresher.Refresh(av.alignment);
\r
1198 public void doMouseDraggedDefineMode(MouseEvent evt)
\r
1200 int res = findRes(evt);
\r
1201 int y = findSeq(evt);
\r
1203 if(wrappedBlock!=startWrapBlock)
\r
1206 if (stretchGroup == null)
\r
1211 mouseDragging = true;
\r
1214 if(y > av.alignment.getHeight())
\r
1216 y = av.alignment.getHeight() -1;
\r
1219 if(res>av.alignment.getWidth())
\r
1220 res = av.alignment.getWidth()-1;
\r
1222 if (stretchGroup.getEndRes() == res)
\r
1224 // Edit end res position of selected group
\r
1225 changeEndRes = true;
\r
1227 else if (stretchGroup.getStartRes() == res)
\r
1229 // Edit start res position of selected group
\r
1230 changeStartRes = true;
\r
1240 if (res > (stretchGroup.getStartRes() - 1))
\r
1242 stretchGroup.setEndRes(res);
\r
1245 else if (changeStartRes)
\r
1247 if (res < (stretchGroup.getEndRes() + 1))
\r
1249 stretchGroup.setStartRes(res);
\r
1253 int dragDirection = 0;
\r
1257 dragDirection = 1;
\r
1259 else if (y < oldSeq)
\r
1261 dragDirection = -1;
\r
1265 while ((y != oldSeq) && (oldSeq > -1) && (y < av.alignment.getHeight()))
\r
1267 // This routine ensures we don't skip any sequences, as the
\r
1268 // selection is quite slow.
\r
1269 Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
\r
1271 oldSeq += dragDirection;
\r
1276 Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
\r
1278 if (stretchGroup.getSequences(false).contains(nextSeq))
\r
1280 stretchGroup.deleteSequence(seq, false);
\r
1286 stretchGroup.addSequence(seq, false);
\r
1289 stretchGroup.addSequence(nextSeq, false);
\r
1297 if(res>av.endRes || res<av.startRes
\r
1298 || y<av.startSeq || y>av.endSeq)
\r
1303 if (scrollThread != null)
\r
1305 scrollThread.setEvent(evt);
\r
1308 seqCanvas.repaint();
\r
1311 public void mouseEntered(MouseEvent e)
\r
1316 if (scrollThread != null)
\r
1318 scrollThread.running = false;
\r
1319 scrollThread = null;
\r
1323 public void mouseExited(MouseEvent e)
\r
1325 if (av.getWrapAlignment())
\r
1330 if (mouseDragging && scrollThread==null)
\r
1332 scrollThread = new ScrollThread();
\r
1336 // this class allows scrolling off the bottom of the visible alignment
\r
1337 class ScrollThread
\r
1341 boolean running = false;
\r
1342 public ScrollThread()
\r
1347 public void setEvent(MouseEvent e)
\r
1352 public void stopScrolling()
\r
1366 if (mouseDragging && evt.getY() < 0 && av.getStartSeq() > 0)
\r
1368 running = ap.scrollUp(true);
\r
1371 if (mouseDragging && evt.getY() >= getSize().height &&
\r
1372 av.alignment.getHeight() > av.getEndSeq())
\r
1374 running = ap.scrollUp(false);
\r
1377 if (mouseDragging && evt.getX() < 0)
\r
1379 running = ap.scrollRight(true);
\r
1382 else if (mouseDragging && evt.getX() >= getSize().width)
\r
1384 running = ap.scrollRight(false);
\r
1392 catch (Exception ex)
\r