2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 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
25 import java.awt.event.*;
\r
27 import jalview.commands.*;
\r
28 import jalview.datamodel.*;
\r
29 import jalview.schemes.*;
\r
30 import jalview.structure.SequenceListener;
\r
31 import jalview.structure.StructureSelectionManager;
\r
33 public class SeqPanel
\r
34 extends Panel implements MouseMotionListener, MouseListener, SequenceListener
\r
37 public SeqCanvas seqCanvas;
\r
38 public AlignmentPanel ap;
\r
40 protected int lastres;
\r
41 protected int startseq;
\r
43 protected AlignViewport av;
\r
45 // if character is inserted or deleted, we will need to recalculate the conservation
\r
46 boolean seqEditOccurred = false;
\r
48 ScrollThread scrollThread = null;
\r
49 boolean mouseDragging = false;
\r
50 boolean editingSeqs = false;
\r
51 boolean groupEditing = false;
\r
54 boolean changeEndSeq = false;
\r
55 boolean changeStartSeq = false;
\r
56 boolean changeEndRes = false;
\r
57 boolean changeStartRes = false;
\r
58 SequenceGroup stretchGroup = null;
\r
60 StringBuffer keyboardNo1;
\r
61 StringBuffer keyboardNo2;
\r
63 boolean mouseWheelPressed = false;
\r
64 Point lastMousePress;
\r
66 EditCommand editCommand;
\r
68 StructureSelectionManager ssm;
\r
71 public SeqPanel(AlignViewport avp, AlignmentPanel p)
\r
75 seqCanvas = new SeqCanvas(avp);
\r
76 setLayout(new BorderLayout());
\r
81 seqCanvas.addMouseMotionListener(this);
\r
82 seqCanvas.addMouseListener(this);
\r
83 ssm = StructureSelectionManager.getStructureSelectionManager();
\r
84 ssm.addStructureViewerListener(this);
\r
86 seqCanvas.repaint();
\r
91 if (editCommand != null && editCommand.getSize() > 0)
\r
93 ap.alignFrame.addHistoryItem(editCommand);
\r
94 av.firePropertyChange("alignment", null,
\r
95 av.getAlignment().getSequences());
\r
100 editingSeqs = false;
\r
101 groupEditing = false;
\r
102 keyboardNo1 = null;
\r
103 keyboardNo2 = null;
\r
104 editCommand = null;
\r
107 void setCursorRow()
\r
109 seqCanvas.cursorY = getKeyboardNo1() - 1;
\r
113 void setCursorColumn()
\r
115 seqCanvas.cursorX = getKeyboardNo1() - 1;
\r
119 void setCursorRowAndColumn()
\r
121 if (keyboardNo2 == null)
\r
123 keyboardNo2 = new StringBuffer();
\r
127 seqCanvas.cursorX = getKeyboardNo1() - 1;
\r
128 seqCanvas.cursorY = getKeyboardNo2() - 1;
\r
133 void setCursorPosition()
\r
135 SequenceI sequence =
\r
136 (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);
\r
138 seqCanvas.cursorX = sequence.findIndex(
\r
139 getKeyboardNo1() - 1
\r
144 void moveCursor(int dx, int dy)
\r
146 seqCanvas.cursorX += dx;
\r
147 seqCanvas.cursorY += dy;
\r
148 if (av.hasHiddenColumns && !av.colSel.isVisible(seqCanvas.cursorX))
\r
150 int original = seqCanvas.cursorX - dx;
\r
151 int maxWidth = av.alignment.getWidth();
\r
153 while (!av.colSel.isVisible(seqCanvas.cursorX)
\r
154 && seqCanvas.cursorX < maxWidth
\r
155 && seqCanvas.cursorX > 0)
\r
157 seqCanvas.cursorX += dx;
\r
160 if (seqCanvas.cursorX >= maxWidth
\r
161 || !av.colSel.isVisible(seqCanvas.cursorX))
\r
163 seqCanvas.cursorX = original;
\r
169 void scrollToVisible()
\r
171 if (seqCanvas.cursorX < 0)
\r
173 seqCanvas.cursorX = 0;
\r
175 else if (seqCanvas.cursorX > av.alignment.getWidth() - 1)
\r
177 seqCanvas.cursorX = av.alignment.getWidth() - 1;
\r
180 if (seqCanvas.cursorY < 0)
\r
182 seqCanvas.cursorY = 0;
\r
184 else if (seqCanvas.cursorY > av.alignment.getHeight() - 1)
\r
186 seqCanvas.cursorY = av.alignment.getHeight() - 1;
\r
190 if (av.wrapAlignment)
\r
192 ap.scrollToWrappedVisible(seqCanvas.cursorX);
\r
196 while (seqCanvas.cursorY < av.startSeq)
\r
200 while (seqCanvas.cursorY + 1 > av.endSeq)
\r
202 ap.scrollUp(false);
\r
204 while (seqCanvas.cursorX < av.colSel.adjustForHiddenColumns(av.startRes))
\r
207 if (!ap.scrollRight(false))
\r
212 while (seqCanvas.cursorX > av.colSel.adjustForHiddenColumns(av.endRes))
\r
214 if (!ap.scrollRight(true))
\r
220 setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY),
\r
221 seqCanvas.cursorX, seqCanvas.cursorY);
\r
223 seqCanvas.repaint();
\r
226 void setSelectionAreaAtCursor(boolean topLeft)
\r
228 SequenceI sequence =
\r
229 (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);
\r
231 if (av.getSelectionGroup() != null)
\r
233 SequenceGroup sg = av.selectionGroup;
\r
234 //Find the top and bottom of this group
\r
235 int min = av.alignment.getHeight(), max = 0;
\r
236 for (int i = 0; i < sg.getSize(); i++)
\r
238 int index = av.alignment.findIndex(sg.getSequenceAt(i));
\r
253 sg.setStartRes(seqCanvas.cursorX);
\r
254 if (sg.getEndRes() < seqCanvas.cursorX)
\r
256 sg.setEndRes(seqCanvas.cursorX);
\r
259 min = seqCanvas.cursorY;
\r
263 sg.setEndRes(seqCanvas.cursorX);
\r
264 if (sg.getStartRes() > seqCanvas.cursorX)
\r
266 sg.setStartRes(seqCanvas.cursorX);
\r
269 max = seqCanvas.cursorY + 1;
\r
274 // Only the user can do this
\r
275 av.setSelectionGroup(null);
\r
279 // Now add any sequences between min and max
\r
280 sg.getSequences(null).removeAllElements();
\r
281 for (int i = min; i < max; i++)
\r
283 sg.addSequence(av.alignment.getSequenceAt(i), false);
\r
288 if (av.getSelectionGroup() == null)
\r
290 SequenceGroup sg = new SequenceGroup();
\r
291 sg.setStartRes(seqCanvas.cursorX);
\r
292 sg.setEndRes(seqCanvas.cursorX);
\r
293 sg.addSequence(sequence, false);
\r
294 av.setSelectionGroup(sg);
\r
297 ap.paintAlignment(false);
\r
300 void insertGapAtCursor(boolean group)
\r
302 groupEditing = group;
\r
303 startseq = seqCanvas.cursorY;
\r
304 lastres = seqCanvas.cursorX;
\r
305 editSequence(true, seqCanvas.cursorX + getKeyboardNo1());
\r
309 void deleteGapAtCursor(boolean group)
\r
311 groupEditing = group;
\r
312 startseq = seqCanvas.cursorY;
\r
313 lastres = seqCanvas.cursorX + getKeyboardNo1();
\r
314 editSequence(false, seqCanvas.cursorX);
\r
318 void numberPressed(char value)
\r
320 if (keyboardNo1 == null)
\r
322 keyboardNo1 = new StringBuffer();
\r
325 if (keyboardNo2 != null)
\r
327 keyboardNo2.append(value);
\r
331 keyboardNo1.append(value);
\r
335 int getKeyboardNo1()
\r
337 if (keyboardNo1 == null)
\r
341 int value = Integer.parseInt(keyboardNo1.toString());
\r
342 keyboardNo1 = null;
\r
347 int getKeyboardNo2()
\r
349 if (keyboardNo2 == null)
\r
353 int value = Integer.parseInt(keyboardNo2.toString());
\r
354 keyboardNo2 = null;
\r
360 void setStatusMessage(SequenceI sequence, int res, int seq)
\r
362 StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " +
\r
363 sequence.getName());
\r
366 if (av.alignment.isNucleotide())
\r
368 obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) +
\r
372 text.append(" Nucleotide: ");
\r
377 obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
\r
380 text.append(" Residue: ");
\r
389 text.append(obj + " (" + sequence.findPosition(res) +
\r
394 ap.alignFrame.statusBar.setText(text.toString());
\r
398 public void mousePressed(MouseEvent evt)
\r
400 lastMousePress = evt.getPoint();
\r
402 //For now, ignore the mouseWheel font resizing on Macs
\r
403 //As the Button2_mask always seems to be true
\r
404 if ( (evt.getModifiers() & InputEvent.BUTTON2_MASK) ==
\r
405 InputEvent.BUTTON2_MASK && !av.MAC)
\r
407 mouseWheelPressed = true;
\r
411 if (evt.isShiftDown()
\r
412 || evt.isControlDown()
\r
413 || evt.isAltDown())
\r
415 if (evt.isControlDown() || evt.isAltDown())
\r
417 groupEditing = true;
\r
419 editingSeqs = true;
\r
423 doMousePressedDefineMode(evt);
\r
427 int seq = findSeq(evt);
\r
428 int res = findRes(evt);
\r
430 if (seq < 0 || res < 0)
\r
435 if ( (seq < av.getAlignment().getHeight()) &&
\r
436 (res < av.getAlignment().getSequenceAt(seq).getLength()))
\r
450 public void mouseClicked(MouseEvent evt)
\r
453 public void mouseReleased(MouseEvent evt)
\r
455 mouseDragging = false;
\r
456 mouseWheelPressed = false;
\r
457 ap.paintAlignment(true);
\r
461 doMouseReleasedDefineMode(evt);
\r
469 int startWrapBlock = -1;
\r
470 int wrappedBlock = -1;
\r
471 int findRes(MouseEvent evt)
\r
474 int x = evt.getX();
\r
476 if (av.wrapAlignment)
\r
479 int hgap = av.charHeight;
\r
480 if (av.scaleAboveWrapped)
\r
482 hgap += av.charHeight;
\r
485 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
486 + hgap + seqCanvas.getAnnotationHeight();
\r
488 int y = evt.getY();
\r
490 x -= seqCanvas.LABEL_WEST;
\r
492 int cwidth = seqCanvas.getWrappedCanvasWidth(getSize().width);
\r
498 wrappedBlock = y / cHeight;
\r
499 wrappedBlock += av.getStartRes() / cwidth;
\r
501 res = wrappedBlock * cwidth + x / av.getCharWidth();
\r
506 res = (x / av.getCharWidth()) + av.getStartRes();
\r
509 if (av.hasHiddenColumns)
\r
511 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
518 int findSeq(MouseEvent evt)
\r
522 int y = evt.getY();
\r
524 if (av.wrapAlignment)
\r
526 int hgap = av.charHeight;
\r
527 if (av.scaleAboveWrapped)
\r
529 hgap += av.charHeight;
\r
532 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
533 + hgap + seqCanvas.getAnnotationHeight();
\r
537 seq = Math.min( (y % cHeight) / av.getCharHeight(),
\r
538 av.alignment.getHeight() - 1);
\r
546 seq = Math.min( (y / av.getCharHeight()) + av.getStartSeq(),
\r
547 av.alignment.getHeight() - 1);
\r
557 public void doMousePressed(MouseEvent evt)
\r
560 int seq = findSeq(evt);
\r
561 int res = findRes(evt);
\r
563 if (seq < av.getAlignment().getHeight() &&
\r
564 res < av.getAlignment().getSequenceAt(seq).getLength())
\r
566 //char resstr = align.getSequenceAt(seq).getSequence().charAt(res);
\r
567 // Find the residue's position in the sequence (res is the position
\r
568 // in the alignment
\r
583 String lastMessage;
\r
584 public void mouseOverSequence(SequenceI sequence, int index)
\r
586 String tmp = sequence.hashCode()+index+"";
\r
587 if (lastMessage == null || !lastMessage.equals(tmp))
\r
588 ssm.mouseOverSequence(sequence, index);
\r
594 public void highlightSequence(jalview.datamodel.SequenceI seq, int index)
\r
596 if(av.alignment.findIndex(seq)>-1)
\r
598 SearchResults highlight = new SearchResults();
\r
599 highlight.addResult(seq,index,index);
\r
600 seqCanvas.highlightSearchResults(highlight);
\r
604 public void updateColours(SequenceI seq, int index)
\r
606 System.out.println("update the seqPanel colours");
\r
610 public void mouseMoved(MouseEvent evt)
\r
612 int res = findRes(evt);
\r
613 int seq = findSeq(evt);
\r
615 if (seq >= av.getAlignment().getHeight() || seq < 0 || res < 0)
\r
617 if (tooltip != null)
\r
619 tooltip.setTip("");
\r
624 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
\r
625 if (res > sequence.getLength())
\r
627 if (tooltip != null)
\r
629 tooltip.setTip("");
\r
636 mouseOverSequence(sequence, sequence.findPosition(res));
\r
639 StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " +
\r
640 sequence.getName());
\r
643 if (av.alignment.isNucleotide())
\r
645 obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) +
\r
649 text.append(" Nucleotide: ");
\r
654 obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
\r
657 text.append(" Residue: ");
\r
665 text.append(obj + " (" + sequence.findPosition(res) + ")");
\r
669 ap.alignFrame.statusBar.setText(text.toString());
\r
671 StringBuffer tooltipText = new StringBuffer();
\r
672 SequenceGroup[] groups = av.alignment.findAllGroups(sequence);
\r
673 if (groups != null)
\r
675 for (int g = 0; g < groups.length; g++)
\r
677 if (groups[g].getStartRes() <= res && groups[g].getEndRes() >= res)
\r
679 if (!groups[g].getName().startsWith("JTreeGroup") &&
\r
680 !groups[g].getName().startsWith("JGroup"))
\r
682 tooltipText.append(groups[g].getName() + " ");
\r
684 if (groups[g].getDescription() != null)
\r
686 tooltipText.append(groups[g].getDescription());
\r
688 tooltipText.append("\n");
\r
693 // use aa to see if the mouse pointer is on a
\r
694 if (av.showSequenceFeatures
\r
695 && sequence.getSequenceFeatures() != null
\r
696 && av.featuresDisplayed != null)
\r
699 Vector allFeatures = getAllFeaturesAtRes(sequence,
\r
700 sequence.findPosition(res));
\r
703 while (index < allFeatures.size())
\r
705 SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(index);
\r
707 tooltipText.append(sf.getType() + " " + sf.begin + ":" + sf.end);
\r
709 if (sf.getDescription() != null)
\r
711 tooltipText.append(" " + sf.getDescription());
\r
714 if (sf.getValue("status") != null)
\r
716 String status = sf.getValue("status").toString();
\r
717 if (status.length() > 0)
\r
719 tooltipText.append(" (" + sf.getValue("status") + ")");
\r
722 tooltipText.append("\n");
\r
728 if (tooltip == null)
\r
730 tooltip = new Tooltip(tooltipText.toString(), seqCanvas);
\r
734 tooltip.setTip(tooltipText.toString());
\r
738 Vector getAllFeaturesAtRes(SequenceI seq, int res)
\r
740 Vector allFeatures = new Vector();
\r
742 if (seq.getSequenceFeatures() != null)
\r
744 while (index < seq.getSequenceFeatures().length)
\r
746 SequenceFeature sf = seq.getSequenceFeatures()[index];
\r
747 if (sf.getBegin() <= res &&
\r
748 sf.getEnd() >= res)
\r
750 if (av.featuresDisplayed.containsKey(sf.getType()))
\r
752 allFeatures.addElement(sf);
\r
758 return allFeatures;
\r
763 public void mouseDragged(MouseEvent evt)
\r
765 if (mouseWheelPressed)
\r
767 int oldWidth = av.charWidth;
\r
769 //Which is bigger, left-right or up-down?
\r
770 if (Math.abs(evt.getY() - lastMousePress.y)
\r
771 > Math.abs(evt.getX() - lastMousePress.x))
\r
773 int fontSize = av.font.getSize();
\r
775 if (evt.getY() < lastMousePress.y && av.charHeight > 1)
\r
779 else if (evt.getY() > lastMousePress.y)
\r
789 av.setFont(new Font(av.font.getName(), av.font.getStyle(), fontSize));
\r
790 av.charWidth = oldWidth;
\r
794 if (evt.getX() < lastMousePress.x && av.charWidth > 1)
\r
798 else if (evt.getX() > lastMousePress.x)
\r
803 if (av.charWidth < 1)
\r
811 FontMetrics fm = getFontMetrics(av.getFont());
\r
812 av.validCharWidth = fm.charWidth('M') <= av.charWidth;
\r
814 lastMousePress = evt.getPoint();
\r
816 ap.paintAlignment(false);
\r
817 ap.annotationPanel.image = null;
\r
823 doMouseDraggedDefineMode(evt);
\r
827 int res = findRes(evt);
\r
834 if ( (lastres == -1) || (lastres == res))
\r
839 if ( (res < av.getAlignment().getWidth()) && (res < lastres))
\r
841 // dragLeft, delete gap
\r
842 editSequence(false, res);
\r
846 editSequence(true, res);
\r
849 mouseDragging = true;
\r
850 if (scrollThread != null)
\r
852 scrollThread.setEvent(evt);
\r
857 synchronized void editSequence(boolean insertGap, int startres)
\r
859 int fixedLeft = -1;
\r
860 int fixedRight = -1;
\r
861 boolean fixedColumns = false;
\r
862 SequenceGroup sg = av.getSelectionGroup();
\r
864 SequenceI seq = av.alignment.getSequenceAt(startseq);
\r
866 if (!groupEditing && av.hasHiddenRows)
\r
868 if (av.hiddenRepSequences != null
\r
869 && av.hiddenRepSequences.containsKey(seq))
\r
871 sg = (SequenceGroup) av.hiddenRepSequences.get(seq);
\r
872 groupEditing = true;
\r
876 StringBuffer message = new StringBuffer();
\r
879 message.append("Edit group:");
\r
880 if (editCommand == null)
\r
882 editCommand = new EditCommand("Edit Group");
\r
887 message.append("Edit sequence: " + seq.getName());
\r
888 String label = seq.getName();
\r
889 if (label.length() > 10)
\r
891 label = label.substring(0, 10);
\r
893 if (editCommand == null)
\r
895 editCommand = new EditCommand("Edit " + label);
\r
901 message.append(" insert ");
\r
905 message.append(" delete ");
\r
908 message.append(Math.abs(startres - lastres) + " gaps.");
\r
909 ap.alignFrame.statusBar.setText(message.toString());
\r
911 //Are we editing within a selection group?
\r
913 || (sg != null && sg.getSequences(av.hiddenRepSequences).contains(seq)))
\r
915 fixedColumns = true;
\r
917 //sg might be null as the user may only see 1 sequence,
\r
918 //but the sequence represents a group
\r
921 if (av.hiddenRepSequences == null
\r
922 || !av.hiddenRepSequences.containsKey(seq))
\r
928 sg = (SequenceGroup) av.hiddenRepSequences.get(seq);
\r
931 fixedLeft = sg.getStartRes();
\r
932 fixedRight = sg.getEndRes();
\r
934 if ( (startres < fixedLeft && lastres >= fixedLeft)
\r
935 || (startres >= fixedLeft && lastres < fixedLeft)
\r
936 || (startres > fixedRight && lastres <= fixedRight)
\r
937 || (startres <= fixedRight && lastres > fixedRight))
\r
943 if (fixedLeft > startres)
\r
945 fixedRight = fixedLeft - 1;
\r
948 else if (fixedRight < startres)
\r
950 fixedLeft = fixedRight;
\r
955 if (av.hasHiddenColumns)
\r
957 fixedColumns = true;
\r
958 int y1 = av.getColumnSelection().getHiddenBoundaryLeft(startres);
\r
959 int y2 = av.getColumnSelection().getHiddenBoundaryRight(startres);
\r
961 if ( (insertGap && startres > y1 && lastres < y1)
\r
962 || (!insertGap && startres < y2 && lastres > y2))
\r
968 //System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
\r
969 //Selection spans a hidden region
\r
970 if (fixedLeft < y1 && (fixedRight > y2 || fixedRight == -1))
\r
972 if (startres >= y2)
\r
978 fixedRight = y2 - 1;
\r
985 Vector vseqs = sg.getSequences(av.hiddenRepSequences);
\r
986 int g, groupSize = vseqs.size();
\r
987 SequenceI[] groupSeqs = new SequenceI[groupSize];
\r
988 for (g = 0; g < groupSeqs.length; g++)
\r
990 groupSeqs[g] = (SequenceI) vseqs.elementAt(g);
\r
996 //If the user has selected the whole sequence, and is dragging to
\r
997 // the right, we can still extend the alignment and selectionGroup
\r
998 if (sg.getStartRes() == 0
\r
999 && sg.getEndRes() == fixedRight
\r
1000 && sg.getEndRes() == av.alignment.getWidth() - 1
\r
1003 sg.setEndRes(av.alignment.getWidth() + startres - lastres);
\r
1004 fixedRight = sg.getEndRes();
\r
1007 // Is it valid with fixed columns??
\r
1008 // Find the next gap before the end
\r
1009 // of the visible region boundary
\r
1010 boolean blank = false;
\r
1011 for (fixedRight = fixedRight;
\r
1012 fixedRight > lastres;
\r
1017 for (g = 0; g < groupSize; g++)
\r
1019 for (int j = 0; j < startres - lastres; j++)
\r
1021 if (!jalview.util.Comparison.isGap(
\r
1022 groupSeqs[g].getCharAt(fixedRight - j)))
\r
1037 if (sg.getSize() == av.alignment.getHeight())
\r
1039 if ( (av.hasHiddenColumns
\r
1041 startres < av.getColumnSelection().getHiddenBoundaryRight(startres)))
\r
1047 int alWidth = av.alignment.getWidth();
\r
1048 if (av.hasHiddenRows)
\r
1050 int hwidth = av.alignment.getHiddenSequences().getWidth();
\r
1051 if (hwidth > alWidth)
\r
1056 //We can still insert gaps if the selectionGroup
\r
1057 //contains all the sequences
\r
1058 sg.setEndRes(sg.getEndRes() + startres - lastres);
\r
1059 fixedRight = alWidth + startres - lastres;
\r
1070 else if (!insertGap)
\r
1072 /// Are we able to delete?
\r
1073 // ie are all columns blank?
\r
1075 for (g = 0; g < groupSize; g++)
\r
1077 for (int j = startres; j < lastres; j++)
\r
1079 if (groupSeqs[g].getLength() <= j)
\r
1084 if (!jalview.util.Comparison.isGap(
\r
1085 groupSeqs[g].getCharAt(j)))
\r
1087 // Not a gap, block edit not valid
\r
1097 // dragging to the right
\r
1098 if (fixedColumns && fixedRight != -1)
\r
1100 for (int j = lastres; j < startres; j++)
\r
1102 insertChar(j, groupSeqs, fixedRight);
\r
1107 editCommand.appendEdit(EditCommand.INSERT_GAP,
\r
1109 startres, startres - lastres,
\r
1116 // dragging to the left
\r
1117 if (fixedColumns && fixedRight != -1)
\r
1119 for (int j = lastres; j > startres; j--)
\r
1121 deleteChar(startres, groupSeqs, fixedRight);
\r
1126 editCommand.appendEdit(EditCommand.DELETE_GAP,
\r
1128 startres, lastres - startres,
\r
1135 else /////Editing a single sequence///////////
\r
1139 // dragging to the right
\r
1140 if (fixedColumns && fixedRight != -1)
\r
1142 for (int j = lastres; j < startres; j++)
\r
1144 insertChar(j, new SequenceI[]
\r
1145 {seq}, fixedRight);
\r
1150 editCommand.appendEdit(EditCommand.INSERT_GAP,
\r
1153 lastres, startres - lastres,
\r
1160 // dragging to the left
\r
1161 if (fixedColumns && fixedRight != -1)
\r
1163 for (int j = lastres; j > startres; j--)
\r
1165 if (!jalview.util.Comparison.isGap(seq.getCharAt(startres)))
\r
1170 deleteChar(startres, new SequenceI[]
\r
1171 {seq}, fixedRight);
\r
1176 //could be a keyboard edit trying to delete none gaps
\r
1178 for (int m = startres; m < lastres; m++)
\r
1180 if (!jalview.util.Comparison.isGap(seq.getCharAt(m)))
\r
1189 editCommand.appendEdit(EditCommand.DELETE_GAP,
\r
1200 lastres = startres;
\r
1201 seqCanvas.repaint();
\r
1204 void insertChar(int j, SequenceI[] seq, int fixedColumn)
\r
1206 int blankColumn = fixedColumn;
\r
1207 for (int s = 0; s < seq.length; s++)
\r
1209 //Find the next gap before the end of the visible region boundary
\r
1210 //If lastCol > j, theres a boundary after the gap insertion
\r
1212 for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
\r
1214 if (jalview.util.Comparison.isGap(seq[s].getCharAt(blankColumn)))
\r
1216 //Theres a space, so break and insert the gap
\r
1221 if (blankColumn <= j)
\r
1223 blankColumn = fixedColumn;
\r
1229 editCommand.appendEdit(EditCommand.DELETE_GAP,
\r
1231 blankColumn, 1, av.alignment, true);
\r
1233 editCommand.appendEdit(EditCommand.INSERT_GAP,
\r
1235 j, 1, av.alignment,
\r
1240 void deleteChar(int j, SequenceI[] seq, int fixedColumn)
\r
1243 editCommand.appendEdit(EditCommand.DELETE_GAP,
\r
1245 j, 1, av.alignment, true);
\r
1247 editCommand.appendEdit(EditCommand.INSERT_GAP,
\r
1249 fixedColumn, 1, av.alignment, true);
\r
1252 //////////////////////////////////////////
\r
1253 /////Everything below this is for defining the boundary of the rubberband
\r
1254 //////////////////////////////////////////
\r
1255 public void doMousePressedDefineMode(MouseEvent evt)
\r
1257 if (scrollThread != null)
\r
1259 scrollThread.running = false;
\r
1260 scrollThread = null;
\r
1263 int res = findRes(evt);
\r
1264 int seq = findSeq(evt);
\r
1266 startWrapBlock = wrappedBlock;
\r
1273 SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq);
\r
1275 if (sequence == null || res > sequence.getLength())
\r
1280 stretchGroup = av.getSelectionGroup();
\r
1282 if (stretchGroup == null)
\r
1284 stretchGroup = av.alignment.findGroup(sequence);
\r
1285 if (stretchGroup != null && res > stretchGroup.getStartRes() &&
\r
1286 res < stretchGroup.getEndRes())
\r
1288 av.setSelectionGroup(stretchGroup);
\r
1292 stretchGroup = null;
\r
1296 else if (!stretchGroup.getSequences(null).contains(sequence)
\r
1297 || stretchGroup.getStartRes() > res
\r
1298 || stretchGroup.getEndRes() < res)
\r
1300 stretchGroup = null;
\r
1302 SequenceGroup[] allGroups = av.alignment.findAllGroups(sequence);
\r
1304 if (allGroups != null)
\r
1306 for (int i = 0; i < allGroups.length; i++)
\r
1308 if (allGroups[i].getStartRes() <= res &&
\r
1309 allGroups[i].getEndRes() >= res)
\r
1311 stretchGroup = allGroups[i];
\r
1316 av.setSelectionGroup(stretchGroup);
\r
1319 // DETECT RIGHT MOUSE BUTTON IN AWT
\r
1320 if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK) ==
\r
1321 InputEvent.BUTTON3_MASK)
\r
1323 Vector allFeatures = getAllFeaturesAtRes(sequence,
\r
1324 sequence.findPosition(res));
\r
1326 Vector links = null;
\r
1327 if (allFeatures != null)
\r
1329 for (int i = 0; i < allFeatures.size(); i++)
\r
1331 SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(i);
\r
1332 if (sf.links != null)
\r
1334 links = new Vector();
\r
1335 for (int j = 0; j < sf.links.size(); j++)
\r
1337 links.addElement(sf.links.elementAt(j));
\r
1342 APopupMenu popup = new APopupMenu(ap, null, links);
\r
1344 popup.show(this, evt.getX(), evt.getY());
\r
1348 if (av.cursorMode)
\r
1350 seqCanvas.cursorX = findRes(evt);
\r
1351 seqCanvas.cursorY = findSeq(evt);
\r
1352 seqCanvas.repaint();
\r
1356 //Only if left mouse button do we want to change group sizes
\r
1358 if (stretchGroup == null)
\r
1360 // define a new group here
\r
1361 SequenceGroup sg = new SequenceGroup();
\r
1362 sg.setStartRes(res);
\r
1363 sg.setEndRes(res);
\r
1364 sg.addSequence(sequence, false);
\r
1365 av.setSelectionGroup(sg);
\r
1366 stretchGroup = sg;
\r
1368 if (av.getConservationSelected())
\r
1370 SliderPanel.setConservationSlider(ap, av.getGlobalColourScheme(),
\r
1373 if (av.getAbovePIDThreshold())
\r
1375 SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(),
\r
1382 public void doMouseReleasedDefineMode(MouseEvent evt)
\r
1384 if (stretchGroup == null)
\r
1389 if (stretchGroup.cs != null)
\r
1391 if (stretchGroup.cs instanceof ClustalxColourScheme)
\r
1393 ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX(
\r
1394 stretchGroup.getSequences(av.hiddenRepSequences),
\r
1395 stretchGroup.getWidth());
\r
1398 if (stretchGroup.cs instanceof Blosum62ColourScheme
\r
1399 || stretchGroup.cs instanceof PIDColourScheme
\r
1400 || stretchGroup.cs.conservationApplied()
\r
1401 || stretchGroup.cs.getThreshold() > 0)
\r
1403 stretchGroup.recalcConservation();
\r
1406 if (stretchGroup.cs.conservationApplied())
\r
1408 SliderPanel.setConservationSlider(ap, stretchGroup.cs,
\r
1409 stretchGroup.getName());
\r
1410 stretchGroup.recalcConservation();
\r
1414 SliderPanel.setPIDSliderSource(ap, stretchGroup.cs,
\r
1415 stretchGroup.getName());
\r
1418 changeEndRes = false;
\r
1419 changeStartRes = false;
\r
1420 stretchGroup = null;
\r
1421 PaintRefresher.Refresh(ap, av.getSequenceSetId());
\r
1422 ap.paintAlignment(true);
\r
1425 public void doMouseDraggedDefineMode(MouseEvent evt)
\r
1427 int res = findRes(evt);
\r
1428 int y = findSeq(evt);
\r
1430 if (wrappedBlock != startWrapBlock)
\r
1435 if (stretchGroup == null)
\r
1440 mouseDragging = true;
\r
1442 if (y > av.alignment.getHeight())
\r
1444 y = av.alignment.getHeight() - 1;
\r
1447 if (res >= av.alignment.getWidth())
\r
1449 res = av.alignment.getWidth() - 1;
\r
1452 if (stretchGroup.getEndRes() == res)
\r
1454 // Edit end res position of selected group
\r
1455 changeEndRes = true;
\r
1457 else if (stretchGroup.getStartRes() == res)
\r
1459 // Edit start res position of selected group
\r
1460 changeStartRes = true;
\r
1470 if (res > (stretchGroup.getStartRes() - 1))
\r
1472 stretchGroup.setEndRes(res);
\r
1475 else if (changeStartRes)
\r
1477 if (res < (stretchGroup.getEndRes() + 1))
\r
1479 stretchGroup.setStartRes(res);
\r
1483 int dragDirection = 0;
\r
1487 dragDirection = 1;
\r
1489 else if (y < oldSeq)
\r
1491 dragDirection = -1;
\r
1494 while ( (y != oldSeq) && (oldSeq > -1) && (y < av.alignment.getHeight()))
\r
1496 // This routine ensures we don't skip any sequences, as the
\r
1497 // selection is quite slow.
\r
1498 Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
\r
1500 oldSeq += dragDirection;
\r
1507 Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
\r
1509 if (stretchGroup.getSequences(null).contains(nextSeq))
\r
1511 stretchGroup.deleteSequence(seq, false);
\r
1517 stretchGroup.addSequence(seq, false);
\r
1520 stretchGroup.addSequence(nextSeq, false);
\r
1529 if (res > av.endRes || res < av.startRes
\r
1530 || y < av.startSeq || y > av.endSeq)
\r
1535 if (scrollThread != null)
\r
1537 scrollThread.setEvent(evt);
\r
1540 seqCanvas.repaint();
\r
1543 public void mouseEntered(MouseEvent e)
\r
1550 if (scrollThread != null)
\r
1552 scrollThread.running = false;
\r
1553 scrollThread = null;
\r
1557 public void mouseExited(MouseEvent e)
\r
1559 if (av.getWrapAlignment())
\r
1564 if (mouseDragging && scrollThread == null)
\r
1566 scrollThread = new ScrollThread();
\r
1570 void scrollCanvas(MouseEvent evt)
\r
1574 if (scrollThread != null)
\r
1576 scrollThread.running = false;
\r
1577 scrollThread = null;
\r
1579 mouseDragging = false;
\r
1583 if (scrollThread == null)
\r
1585 scrollThread = new ScrollThread();
\r
1588 mouseDragging = true;
\r
1589 scrollThread.setEvent(evt);
\r
1594 // this class allows scrolling off the bottom of the visible alignment
\r
1595 class ScrollThread
\r
1599 boolean running = false;
\r
1600 public ScrollThread()
\r
1605 public void setEvent(MouseEvent e)
\r
1610 public void stopScrolling()
\r
1624 if (mouseDragging && evt.getY() < 0 && av.getStartSeq() > 0)
\r
1626 running = ap.scrollUp(true);
\r
1629 if (mouseDragging && evt.getY() >= getSize().height &&
\r
1630 av.alignment.getHeight() > av.getEndSeq())
\r
1632 running = ap.scrollUp(false);
\r
1635 if (mouseDragging && evt.getX() < 0)
\r
1637 running = ap.scrollRight(false);
\r
1640 else if (mouseDragging && evt.getX() >= getSize().width)
\r
1642 running = ap.scrollRight(true);
\r
1650 catch (Exception ex)
\r