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
427 if(av.hasHiddenColumns)
\r
428 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
434 int findSeq(MouseEvent evt)
\r
438 int y = evt.getY();
\r
440 if (av.wrapAlignment)
\r
442 int hgap = av.charHeight;
\r
443 if (av.scaleAboveWrapped)
\r
444 hgap += av.charHeight;
\r
446 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
447 + hgap + seqCanvas.getAnnotationHeight();
\r
451 seq = Math.min( (y % cHeight) / av.getCharHeight(),
\r
452 av.alignment.getHeight() -1);
\r
458 seq = Math.min( (y / av.getCharHeight()) + av.getStartSeq(),
\r
459 av.alignment.getHeight() -1);
\r
468 public void doMousePressed(MouseEvent evt)
\r
470 ap.alignFrame.addHistoryItem(new HistoryItem(
\r
471 "Edit Sequence", av.alignment, HistoryItem.EDIT));
\r
473 int seq = findSeq(evt);
\r
474 int res = findRes(evt);
\r
476 if (seq < av.getAlignment().getHeight() &&
\r
477 res < av.getAlignment().getSequenceAt(seq).getLength())
\r
479 //char resstr = align.getSequenceAt(seq).getSequence().charAt(res);
\r
480 // Find the residue's position in the sequence (res is the position
\r
481 // in the alignment
\r
495 public void mouseMoved(MouseEvent evt)
\r
497 int res = findRes(evt);
\r
498 int seq = findSeq(evt);
\r
500 if (seq >= av.getAlignment().getHeight() || seq<0 || res<0)
\r
505 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
\r
506 if (res > sequence.getLength())
\r
511 StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " +
\r
512 sequence.getName());
\r
515 if (av.alignment.isNucleotide())
\r
517 obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) +
\r
520 text.append(" Nucleotide: ");
\r
524 obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
\r
526 text.append(" Residue: ");
\r
533 text.append(obj + " (" + sequence.findPosition(res) + ")");
\r
537 if(seqCanvas.pdbCanvas!=null && sequence==seqCanvas.pdbCanvas.sequence)
\r
539 seqCanvas.pdbCanvas.highlightRes(sequence.findPosition(res));
\r
542 ap.alignFrame.statusBar.setText(text.toString());
\r
545 // use aa to see if the mouse pointer is on a
\r
546 if (av.showSequenceFeatures
\r
547 && sequence.getSequenceFeatures()!=null
\r
548 && av.featuresDisplayed!=null)
\r
550 StringBuffer featureText = new StringBuffer();
\r
551 Vector allFeatures = getAllFeaturesAtRes(sequence, sequence.findPosition(res));
\r
554 while (index < allFeatures.size())
\r
556 SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(index);
\r
558 featureText.append(sf.getType()+" "+sf.begin+":"+sf.end);
\r
560 if (sf.getDescription() != null)
\r
561 featureText.append(" " + sf.getDescription());
\r
563 if (sf.getValue("status") != null )
\r
565 featureText.append(" (" + sf.getValue("status") + ")");
\r
567 featureText.append("\n");
\r
573 if (tooltip == null)
\r
574 tooltip = new Tooltip(featureText.toString(), seqCanvas);
\r
576 tooltip.setTip(featureText.toString());
\r
583 Vector getAllFeaturesAtRes(SequenceI seq, int res)
\r
585 Vector allFeatures = new Vector();
\r
587 if(seq.getSequenceFeatures()!=null)
\r
589 while (index < seq.getSequenceFeatures().length)
\r
591 SequenceFeature sf = seq.getSequenceFeatures()[index];
\r
592 if (sf.getBegin() <= res &&
\r
593 sf.getEnd() >= res)
\r
595 if (av.featuresDisplayed.containsKey(sf.getType()))
\r
597 allFeatures.addElement(sf);
\r
603 return allFeatures;
\r
608 public void mouseDragged(MouseEvent evt)
\r
610 if (mouseWheelPressed)
\r
612 int oldWidth = av.charWidth;
\r
614 //Which is bigger, left-right or up-down?
\r
615 if (Math.abs(evt.getY() - lastMousePress.y)
\r
616 > Math.abs(evt.getX() - lastMousePress.x))
\r
618 int fontSize = av.font.getSize();
\r
620 if (evt.getY() < lastMousePress.y && av.charHeight > 1)
\r
624 else if (evt.getY() > lastMousePress.y)
\r
633 av.setFont(new Font(av.font.getName(), av.font.getStyle(), fontSize));
\r
634 av.charWidth = oldWidth;
\r
638 if (evt.getX() < lastMousePress.x && av.charWidth > 1)
\r
642 else if (evt.getX() > lastMousePress.x)
\r
655 FontMetrics fm = getFontMetrics(av.getFont());
\r
656 av.validCharWidth = fm.charWidth('M') <= av.charWidth;
\r
658 lastMousePress = evt.getPoint();
\r
661 ap.annotationPanel.image = null;
\r
667 doMouseDraggedDefineMode(evt);
\r
671 int res = findRes(evt);
\r
678 if ((lastres == -1) || (lastres == res))
\r
683 if ( (res < av.getAlignment().getWidth()) && (res < lastres))
\r
685 // dragLeft, delete gap
\r
686 editSequence(false, res);
\r
689 editSequence(true, res);
\r
691 mouseDragging = true;
\r
692 if(scrollThread!=null)
\r
693 scrollThread.setEvent(evt);
\r
697 synchronized void editSequence(boolean insertGap, int startres)
\r
699 int fixedLeft = -1;
\r
700 int fixedRight = -1;
\r
701 boolean fixedColumns = false;
\r
702 SequenceGroup sg = av.getSelectionGroup();
\r
705 if (!groupEditing && av.hasHiddenRows)
\r
707 if (av.alignment.getSequenceAt(startseq).getHiddenSequences() != null)
\r
709 groupEditing = true;
\r
713 //No group, but the sequence may represent a group
\r
716 && av.alignment.getSequenceAt(startseq).getHiddenSequences() == null)
\r
718 groupEditing = false;
\r
721 SequenceI seq = av.alignment.getSequenceAt(startseq);
\r
722 StringBuffer message = new StringBuffer();
\r
724 message.append("Edit group:");
\r
726 message.append("Edit sequence: "+seq.getName());
\r
729 message.append(" insert ");
\r
731 message.append(" delete ");
\r
733 message.append(Math.abs(startres-lastres)+" gaps.");
\r
734 ap.alignFrame.statusBar.setText(message.toString());
\r
737 //Are we editing within a selection group?
\r
739 || (sg != null && sg.getSequences(true).contains(seq)))
\r
741 fixedColumns = true;
\r
743 //sg might be null as the user may only see 1 sequence,
\r
744 //but the sequence represents a group
\r
747 sg = new SequenceGroup(null, null, false, false, false, 0,
\r
748 av.alignment.getWidth()-1);
\r
749 sg.addSequence(av.alignment.getSequenceAt(startseq), false);
\r
752 fixedLeft = sg.getStartRes();
\r
753 fixedRight = sg.getEndRes();
\r
755 if ( (startres < fixedLeft && lastres >= fixedLeft)
\r
756 || (startres >= fixedLeft && lastres < fixedLeft)
\r
757 || (startres > fixedRight && lastres <=fixedRight)
\r
758 || (startres <= fixedRight && lastres > fixedRight))
\r
764 if (fixedLeft > startres)
\r
766 fixedRight = fixedLeft - 1;
\r
769 else if (fixedRight < startres)
\r
771 fixedLeft = fixedRight;
\r
777 if(av.hasHiddenColumns )
\r
779 fixedColumns = true;
\r
780 int y1 = av.getColumnSelection().getHiddenBoundaryLeft(startres);
\r
781 int y2 = av.getColumnSelection().getHiddenBoundaryRight(startres);
\r
783 if ( (insertGap && startres > y1 && lastres < y1)
\r
784 || (!insertGap && startres < y2 && lastres > y2))
\r
790 //System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
\r
791 //Selection spans a hidden region
\r
792 if(fixedLeft<y1 && (fixedRight>y2 || fixedRight==-1))
\r
800 fixedRight = y2 - 1;
\r
811 //If the user has selected the whole sequence, and is dragging to
\r
812 // the right, we can still extend the alignment and selectionGroup
\r
813 if( sg.getStartRes() == 0
\r
814 && sg.getEndRes() == fixedRight
\r
815 && sg.getEndRes() == av.alignment.getWidth()-1
\r
818 sg.setEndRes(av.alignment.getWidth() + startres - lastres);
\r
819 fixedRight = sg.getEndRes();
\r
822 // Is it valid with fixed columns??
\r
823 // Find the next gap before the end
\r
824 // of the visible region boundary
\r
825 boolean blank = false;
\r
826 for (fixedRight = fixedRight;
\r
827 fixedRight > lastres;
\r
831 for (int s = 0; s < sg.getSize(true); s++)
\r
833 seq = (SequenceI)sg.getSequences(true).elementAt(s);
\r
834 for (int j = 0; j < startres - lastres; j++)
\r
836 if (!jalview.util.Comparison.isGap(
\r
837 seq.getCharAt(fixedRight - j)))
\r
850 if(sg.getSize(false) == av.alignment.getHeight() )
\r
852 if((av.hasHiddenColumns
\r
853 && startres<av.getColumnSelection().getHiddenBoundaryRight(startres)))
\r
859 int alWidth = av.alignment.getWidth();
\r
860 if(av.hasHiddenRows)
\r
862 int hwidth = av.alignment.getHiddenSequences().getWidth();
\r
866 //We can still insert gaps if the selectionGroup
\r
867 //contains all the sequences
\r
868 sg.setEndRes(sg.getEndRes()+startres-lastres);
\r
869 fixedRight = alWidth+startres-lastres;
\r
881 else if(!insertGap)
\r
883 /// Are we able to delete?
\r
884 // ie are all columns blank?
\r
886 for (int s = 0; s < sg.getSize(true); s++)
\r
888 seq = (SequenceI)sg.getSequences(true).elementAt(s);
\r
890 for (int j = startres; j < lastres; j++)
\r
892 if (seq.getSequence().length() <= j)
\r
897 if (!jalview.util.Comparison.isGap(
\r
898 seq.getSequence().charAt(j)))
\r
900 // Not a gap, block edit not valid
\r
909 for (int i = 0; i < sg.getSize(true); i++)
\r
911 seq = (SequenceI) sg.getSequences(true).elementAt(i);
\r
915 // dragging to the right
\r
916 for (int j = lastres; j < startres; j++)
\r
918 if (fixedColumns && fixedRight != -1)
\r
920 insertChar(j, seq, fixedRight);
\r
923 insertChar(j, seq);
\r
928 // dragging to the left
\r
929 for (int j = lastres; j > startres; j--)
\r
931 if (fixedColumns && fixedRight != -1)
\r
933 deleteChar(startres, seq, fixedRight);
\r
937 deleteChar(startres, seq);
\r
943 else /////Editing a single sequence///////////
\r
947 // dragging to the right
\r
948 for (int j = lastres; j < startres; j++)
\r
950 if (fixedColumns && fixedRight != -1)
\r
952 insertChar(j, seq, fixedRight);
\r
955 insertChar(j, seq);
\r
960 // dragging to the left
\r
961 for (int j = lastres; j > startres; j--)
\r
963 if (fixedColumns && fixedRight != -1)
\r
965 deleteChar(startres, seq, fixedRight);
\r
969 deleteChar(startres, seq);
\r
975 lastres = startres;
\r
976 seqCanvas.repaint();
\r
983 * @param j DOCUMENT ME!
\r
984 * @param seq DOCUMENT ME!
\r
986 void insertChar(int j, SequenceI seq)
\r
988 seq.insertCharAt(j, av.getGapCharacter());
\r
989 seqEditOccurred = true;
\r
992 void insertChar(int j, SequenceI seq, int fixedColumn)
\r
994 //Find the next gap before the end of the visible region boundary
\r
995 //If lastCol > j, theres a boundary after the gap insertion
\r
996 int blankColumn = fixedColumn;
\r
997 for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
\r
999 if (jalview.util.Comparison.isGap(seq.getCharAt(blankColumn)))
\r
1001 //Theres a space, so break and insert the gap
\r
1006 if (blankColumn <= j)
\r
1012 if (!jalview.util.Comparison.isGap(seq.getCharAt(blankColumn)))
\r
1015 System.out.println("Tried removing residue (INSERT)"+seq.getCharAt(fixedColumn));
\r
1019 seq.deleteCharAt(blankColumn);
\r
1020 seq.insertCharAt(j, av.getGapCharacter());
\r
1021 seqEditOccurred = true;
\r
1024 void deleteChar(int j, SequenceI seq, int fixedColumn)
\r
1026 if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))
\r
1028 ap.alignFrame.statusBar.setText(
\r
1029 "End editing: Tried removing residue " + seq.getCharAt(j));
\r
1033 seq.deleteCharAt(j);
\r
1034 seq.insertCharAt(fixedColumn, av.getGapCharacter());
\r
1035 seqEditOccurred = true;
\r
1041 * @param j DOCUMENT ME!
\r
1042 * @param seq DOCUMENT ME!
\r
1044 void deleteChar(int j, SequenceI seq)
\r
1046 if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))
\r
1048 ap.alignFrame.statusBar.setText(
\r
1049 "End editing: Tried removing residue " + seq.getCharAt(j));
\r
1053 seq.deleteCharAt(j);
\r
1054 seqEditOccurred = true;
\r
1055 seqCanvas.repaint();
\r
1061 * @param i DOCUMENT ME!
\r
1063 void editOccurred()
\r
1065 if (!seqEditOccurred)
\r
1067 ap.alignFrame.historyList.pop();
\r
1068 ap.alignFrame.updateEditMenuBar();
\r
1073 av.firePropertyChange("alignment", null,av.getAlignment().getSequences());
\r
1077 //////////////////////////////////////////
\r
1078 /////Everything below this is for defining the boundary of the rubberband
\r
1079 //////////////////////////////////////////
\r
1080 public void doMousePressedDefineMode(MouseEvent evt)
\r
1084 if (scrollThread != null)
\r
1086 scrollThread.running = false;
\r
1087 scrollThread = null;
\r
1090 int res = findRes(evt);
\r
1091 int seq = findSeq(evt);
\r
1093 startWrapBlock=wrappedBlock;
\r
1098 SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq);
\r
1100 if (sequence == null || res > sequence.getLength())
\r
1105 stretchGroup = av.getSelectionGroup();
\r
1107 if (stretchGroup == null)
\r
1109 stretchGroup = av.alignment.findGroup(sequence);
\r
1110 if (stretchGroup != null && res > stretchGroup.getStartRes() &&
\r
1111 res < stretchGroup.getEndRes())
\r
1113 av.setSelectionGroup(stretchGroup);
\r
1117 stretchGroup = null;
\r
1121 else if (!stretchGroup.getSequences(false).contains(sequence)
\r
1122 || stretchGroup.getStartRes() > res
\r
1123 || stretchGroup.getEndRes() < res)
\r
1125 stretchGroup = null;
\r
1127 SequenceGroup[] allGroups = av.alignment.findAllGroups(sequence);
\r
1129 if (allGroups != null)
\r
1131 for (int i = 0; i < allGroups.length; i++)
\r
1133 if (allGroups[i].getStartRes() <= res &&
\r
1134 allGroups[i].getEndRes() >= res)
\r
1136 stretchGroup = allGroups[i];
\r
1141 av.setSelectionGroup(stretchGroup);
\r
1145 // DETECT RIGHT MOUSE BUTTON IN AWT
\r
1146 if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK) ==
\r
1147 InputEvent.BUTTON3_MASK)
\r
1149 Vector allFeatures = getAllFeaturesAtRes(sequence,
\r
1150 sequence.findPosition(res));
\r
1152 Vector links = null;
\r
1153 if(allFeatures!=null)
\r
1155 for (int i = 0; i < allFeatures.size(); i++)
\r
1157 SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(i);
\r
1158 if (sf.links != null)
\r
1160 links = new Vector();
\r
1161 for (int j = 0; j < sf.links.size(); j++)
\r
1163 links.addElement(sf.links.elementAt(j));
\r
1168 APopupMenu popup = new APopupMenu(ap, null, links);
\r
1170 popup.show(this, evt.getX(), evt.getY());
\r
1175 if (av.cursorMode)
\r
1177 seqCanvas.cursorX = findRes(evt);
\r
1178 seqCanvas.cursorY = findSeq(evt);
\r
1179 seqCanvas.repaint();
\r
1183 //Only if left mouse button do we want to change group sizes
\r
1185 if (stretchGroup == null)
\r
1187 // define a new group here
\r
1188 SequenceGroup sg = new SequenceGroup();
\r
1189 sg.setStartRes(res);
\r
1190 sg.setEndRes(res);
\r
1191 sg.addSequence(sequence, false);
\r
1192 av.setSelectionGroup(sg);
\r
1193 stretchGroup = sg;
\r
1195 if (av.getConservationSelected())
\r
1197 SliderPanel.setConservationSlider(ap, av.getGlobalColourScheme(),
\r
1200 if (av.getAbovePIDThreshold())
\r
1202 SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(),
\r
1209 public void doMouseReleasedDefineMode(MouseEvent evt)
\r
1211 if (stretchGroup == null)
\r
1216 if(stretchGroup.cs!=null)
\r
1218 if (stretchGroup.cs instanceof ClustalxColourScheme)
\r
1220 ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX(
\r
1221 stretchGroup.getSequences(true),
\r
1222 stretchGroup.getWidth());
\r
1225 if (stretchGroup.cs.conservationApplied())
\r
1227 SliderPanel.setConservationSlider(ap, stretchGroup.cs,
\r
1228 stretchGroup.getName());
\r
1229 stretchGroup.recalcConservation();
\r
1233 SliderPanel.setPIDSliderSource(ap, stretchGroup.cs,
\r
1234 stretchGroup.getName());
\r
1237 changeEndRes = false;
\r
1238 changeStartRes = false;
\r
1239 stretchGroup = null;
\r
1240 PaintRefresher.Refresh(av.alignment);
\r
1244 public void doMouseDraggedDefineMode(MouseEvent evt)
\r
1246 int res = findRes(evt);
\r
1247 int y = findSeq(evt);
\r
1249 if(wrappedBlock!=startWrapBlock)
\r
1252 if (stretchGroup == null)
\r
1257 mouseDragging = true;
\r
1260 if(y > av.alignment.getHeight())
\r
1262 y = av.alignment.getHeight() -1;
\r
1265 if(res>av.alignment.getWidth())
\r
1266 res = av.alignment.getWidth()-1;
\r
1268 if (stretchGroup.getEndRes() == res)
\r
1270 // Edit end res position of selected group
\r
1271 changeEndRes = true;
\r
1273 else if (stretchGroup.getStartRes() == res)
\r
1275 // Edit start res position of selected group
\r
1276 changeStartRes = true;
\r
1286 if (res > (stretchGroup.getStartRes() - 1))
\r
1288 stretchGroup.setEndRes(res);
\r
1291 else if (changeStartRes)
\r
1293 if (res < (stretchGroup.getEndRes() + 1))
\r
1295 stretchGroup.setStartRes(res);
\r
1299 int dragDirection = 0;
\r
1303 dragDirection = 1;
\r
1305 else if (y < oldSeq)
\r
1307 dragDirection = -1;
\r
1311 while ((y != oldSeq) && (oldSeq > -1) && (y < av.alignment.getHeight()))
\r
1313 // This routine ensures we don't skip any sequences, as the
\r
1314 // selection is quite slow.
\r
1315 Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
\r
1317 oldSeq += dragDirection;
\r
1322 Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
\r
1324 if (stretchGroup.getSequences(false).contains(nextSeq))
\r
1326 stretchGroup.deleteSequence(seq, false);
\r
1332 stretchGroup.addSequence(seq, false);
\r
1335 stretchGroup.addSequence(nextSeq, false);
\r
1343 if(res>av.endRes || res<av.startRes
\r
1344 || y<av.startSeq || y>av.endSeq)
\r
1349 if (scrollThread != null)
\r
1351 scrollThread.setEvent(evt);
\r
1354 seqCanvas.repaint();
\r
1357 public void mouseEntered(MouseEvent e)
\r
1362 if (scrollThread != null)
\r
1364 scrollThread.running = false;
\r
1365 scrollThread = null;
\r
1369 public void mouseExited(MouseEvent e)
\r
1371 if (av.getWrapAlignment())
\r
1376 if (mouseDragging && scrollThread==null)
\r
1378 scrollThread = new ScrollThread();
\r
1382 void scrollCanvas(MouseEvent evt)
\r
1386 if(scrollThread!=null)
\r
1388 scrollThread.running = false;
\r
1389 scrollThread = null;
\r
1391 mouseDragging = false;
\r
1395 if (scrollThread == null)
\r
1396 scrollThread = new ScrollThread();
\r
1398 mouseDragging = true;
\r
1399 scrollThread.setEvent(evt);
\r
1404 // this class allows scrolling off the bottom of the visible alignment
\r
1405 class ScrollThread
\r
1409 boolean running = false;
\r
1410 public ScrollThread()
\r
1415 public void setEvent(MouseEvent e)
\r
1420 public void stopScrolling()
\r
1434 if (mouseDragging && evt.getY() < 0 && av.getStartSeq() > 0)
\r
1436 running = ap.scrollUp(true);
\r
1439 if (mouseDragging && evt.getY() >= getSize().height &&
\r
1440 av.alignment.getHeight() > av.getEndSeq())
\r
1442 running = ap.scrollUp(false);
\r
1445 if (mouseDragging && evt.getX() < 0)
\r
1447 running = ap.scrollRight(false);
\r
1450 else if (mouseDragging && evt.getX() >= getSize().width)
\r
1452 running = ap.scrollRight(true);
\r
1460 catch (Exception ex)
\r