2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
19 package jalview.gui;
\r
21 import jalview.datamodel.*;
\r
22 import jalview.commands.EditCommand;
\r
23 import jalview.schemes.*;
\r
26 import java.awt.event.*;
\r
27 import javax.swing.*;
\r
28 import java.util.Vector;
\r
35 * @version $Revision$
\r
37 public class SeqPanel extends JPanel implements MouseListener,
\r
38 MouseMotionListener, MouseWheelListener
\r
41 /** DOCUMENT ME!! */
\r
42 public SeqCanvas seqCanvas;
\r
44 /** DOCUMENT ME!! */
\r
45 public AlignmentPanel ap;
\r
46 protected int lastres;
\r
47 protected int startseq;
\r
48 protected AlignViewport av;
\r
50 ScrollThread scrollThread = null;
\r
51 boolean mouseDragging = false;
\r
52 boolean editingSeqs = false;
\r
53 boolean groupEditing = false;
\r
55 //////////////////////////////////////////
\r
56 /////Everything below this is for defining the boundary of the rubberband
\r
57 //////////////////////////////////////////
\r
59 boolean changeEndSeq = false;
\r
60 boolean changeStartSeq = false;
\r
61 boolean changeEndRes = false;
\r
62 boolean changeStartRes = false;
\r
63 SequenceGroup stretchGroup = null;
\r
64 boolean remove = false;
\r
66 Point lastMousePress;
\r
67 boolean mouseWheelPressed = false;
\r
68 StringBuffer keyboardNo1;
\r
69 StringBuffer keyboardNo2;
\r
71 java.net.URL linkImageURL;
\r
73 StringBuffer tooltipText = new StringBuffer("<html>");
\r
76 EditCommand editCommand;
\r
79 * Creates a new SeqPanel object.
\r
81 * @param avp DOCUMENT ME!
\r
82 * @param p DOCUMENT ME!
\r
84 public SeqPanel(AlignViewport avp, AlignmentPanel p)
\r
86 linkImageURL = getClass().getResource("/images/link.gif");
\r
87 ToolTipManager.sharedInstance().registerComponent(this);
\r
88 ToolTipManager.sharedInstance().setInitialDelay(0);
\r
89 ToolTipManager.sharedInstance().setDismissDelay(10000);
\r
91 setBackground(Color.white);
\r
93 seqCanvas = new SeqCanvas(avp);
\r
94 setLayout(new BorderLayout());
\r
95 add(seqCanvas, BorderLayout.CENTER);
\r
99 if (!av.isDataset())
\r
101 addMouseMotionListener(this);
\r
102 addMouseListener(this);
\r
103 addMouseWheelListener(this);
\r
107 int startWrapBlock = -1;
\r
108 int wrappedBlock = -1;
\r
109 int findRes(MouseEvent evt)
\r
112 int x = evt.getX();
\r
114 if (av.wrapAlignment)
\r
117 int hgap = av.charHeight;
\r
118 if (av.scaleAboveWrapped)
\r
119 hgap += av.charHeight;
\r
121 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
122 + hgap + seqCanvas.getAnnotationHeight();
\r
124 int y = evt.getY();
\r
126 x -= seqCanvas.LABEL_WEST;
\r
128 int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());
\r
132 wrappedBlock = y / cHeight;
\r
133 wrappedBlock += av.getStartRes() / cwidth;
\r
135 res = wrappedBlock * cwidth + x / av.getCharWidth();
\r
140 res = (x / av.getCharWidth()) + av.getStartRes();
\r
143 if (av.hasHiddenColumns)
\r
144 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
150 int findSeq(MouseEvent evt)
\r
153 int y = evt.getY();
\r
155 if (av.wrapAlignment)
\r
157 int hgap = av.charHeight;
\r
158 if (av.scaleAboveWrapped)
\r
159 hgap += av.charHeight;
\r
161 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
162 + hgap + seqCanvas.getAnnotationHeight();
\r
166 seq = Math.min( (y % cHeight) / av.getCharHeight(),
\r
167 av.alignment.getHeight() - 1);
\r
171 seq = Math.min( (y / av.getCharHeight()) + av.getStartSeq(),
\r
172 av.alignment.getHeight() - 1);
\r
178 SequenceFeature[] findFeaturesAtRes(SequenceI sequence, int res)
\r
180 Vector tmp = new Vector();
\r
181 SequenceFeature[] features = sequence.getSequenceFeatures();
\r
182 if (features != null)
\r
184 for (int i = 0; i < features.length; i++)
\r
186 if (av.featuresDisplayed == null
\r
187 || !av.featuresDisplayed.containsKey(features[i].getType()))
\r
190 if ( (features[i].getBegin() <= res) &&
\r
191 (features[i].getEnd() >= res))
\r
193 tmp.addElement(features[i]);
\r
198 features = new SequenceFeature[tmp.size()];
\r
199 for(int i=0; i<tmp.size(); i++)
\r
201 features[i] = (SequenceFeature)tmp.elementAt(i);
\r
207 Vector getAllFeaturesAtRes(SequenceI seq, int res)
\r
209 Vector allFeatures = new Vector();
\r
211 if(seq.getSequenceFeatures()!=null && av.featuresDisplayed!=null)
\r
213 while (index < seq.getSequenceFeatures().length)
\r
215 SequenceFeature sf = seq.getSequenceFeatures()[index];
\r
216 if (sf.getBegin() <= res &&
\r
217 sf.getEnd() >= res)
\r
219 if (av.featuresDisplayed.containsKey(sf.getType()))
\r
221 allFeatures.addElement(sf);
\r
227 return allFeatures;
\r
232 if (editCommand!=null && editCommand.getSize() > 0)
\r
234 ap.alignFrame.addHistoryItem(editCommand);
\r
235 av.firePropertyChange("alignment", null,
\r
236 av.getAlignment().getSequences());
\r
241 editingSeqs = false;
\r
242 groupEditing = false;
\r
243 keyboardNo1 = null;
\r
244 keyboardNo2 = null;
\r
245 editCommand = null;
\r
248 void setCursorRow()
\r
250 seqCanvas.cursorY = getKeyboardNo(keyboardNo1)-1;
\r
254 void setCursorColumn()
\r
256 seqCanvas.cursorX = getKeyboardNo(keyboardNo1)-1;
\r
260 void setCursorRowAndColumn()
\r
262 if(keyboardNo2==null)
\r
264 keyboardNo2 = new StringBuffer();
\r
268 seqCanvas.cursorX = getKeyboardNo(keyboardNo1) - 1;
\r
269 seqCanvas.cursorY = getKeyboardNo(keyboardNo2) - 1;
\r
274 void setCursorPosition()
\r
276 SequenceI sequence =
\r
277 (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);
\r
279 seqCanvas.cursorX = sequence.findIndex(
\r
280 getKeyboardNo(keyboardNo1)-1
\r
285 void moveCursor(int dx, int dy)
\r
287 seqCanvas.cursorX += dx;
\r
288 seqCanvas.cursorY += dy;
\r
289 if (av.hasHiddenColumns && !av.colSel.isVisible(seqCanvas.cursorX))
\r
291 int original = seqCanvas.cursorX - dx;
\r
292 int maxWidth = av.alignment.getWidth();
\r
294 while(!av.colSel.isVisible(seqCanvas.cursorX)
\r
295 && seqCanvas.cursorX<maxWidth
\r
296 && seqCanvas.cursorX>0)
\r
298 seqCanvas.cursorX += dx;
\r
301 if(seqCanvas.cursorX>=maxWidth
\r
302 || !av.colSel.isVisible(seqCanvas.cursorX) )
\r
304 seqCanvas.cursorX = original;
\r
311 void scrollToVisible()
\r
313 if (seqCanvas.cursorX < 0)
\r
314 seqCanvas.cursorX = 0;
\r
315 else if (seqCanvas.cursorX > av.alignment.getWidth() - 1)
\r
316 seqCanvas.cursorX = av.alignment.getWidth() - 1;
\r
318 if (seqCanvas.cursorY < 0)
\r
319 seqCanvas.cursorY = 0;
\r
320 else if (seqCanvas.cursorY > av.alignment.getHeight() - 1)
\r
321 seqCanvas.cursorY = av.alignment.getHeight() - 1;
\r
325 if(av.wrapAlignment)
\r
327 ap.scrollToWrappedVisible(seqCanvas.cursorX);
\r
331 while (seqCanvas.cursorY < av.startSeq)
\r
335 while (seqCanvas.cursorY + 1 > av.endSeq)
\r
337 ap.scrollUp(false);
\r
339 if (!av.wrapAlignment)
\r
341 while (seqCanvas.cursorX < av.colSel.adjustForHiddenColumns(av.startRes))
\r
343 if (!ap.scrollRight(false))
\r
346 while (seqCanvas.cursorX > av.colSel.adjustForHiddenColumns(av.endRes))
\r
348 if (!ap.scrollRight(true))
\r
353 setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY),
\r
354 seqCanvas.cursorX, seqCanvas.cursorY);
\r
356 seqCanvas.repaint();
\r
359 void setSelectionAreaAtCursor(boolean topLeft)
\r
361 SequenceI sequence =
\r
362 (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);
\r
364 if(av.getSelectionGroup()!=null)
\r
366 SequenceGroup sg = av.selectionGroup;
\r
367 //Find the top and bottom of this group
\r
368 int min = av.alignment.getHeight(), max = 0;
\r
369 for(int i=0; i<sg.getSize(false); i++)
\r
371 int index = av.alignment.findIndex( sg.getSequenceAt(i) );
\r
382 sg.setStartRes(seqCanvas.cursorX);
\r
383 if(sg.getEndRes()<seqCanvas.cursorX)
\r
384 sg.setEndRes(seqCanvas.cursorX);
\r
386 min = seqCanvas.cursorY;
\r
390 sg.setEndRes(seqCanvas.cursorX);
\r
391 if(sg.getStartRes()>seqCanvas.cursorX)
\r
392 sg.setStartRes(seqCanvas.cursorX);
\r
394 max = seqCanvas.cursorY+1;
\r
399 // Only the user can do this
\r
400 av.setSelectionGroup(null);
\r
404 // Now add any sequences between min and max
\r
405 sg.getSequences(false).clear();
\r
406 for (int i = min; i < max; i++)
\r
408 sg.addSequence(av.alignment.getSequenceAt(i), false);
\r
413 if (av.getSelectionGroup() == null)
\r
415 SequenceGroup sg = new SequenceGroup();
\r
416 sg.setStartRes(seqCanvas.cursorX);
\r
417 sg.setEndRes(seqCanvas.cursorX);
\r
418 sg.addSequence(sequence, false);
\r
419 av.setSelectionGroup(sg);
\r
426 void insertGapAtCursor(boolean group)
\r
428 groupEditing = group;
\r
429 startseq = seqCanvas.cursorY;
\r
430 lastres = seqCanvas.cursorX;
\r
431 editSequence(true, seqCanvas.cursorX+getKeyboardNo(keyboardNo1));
\r
435 void deleteGapAtCursor(boolean group)
\r
437 groupEditing = group;
\r
438 startseq = seqCanvas.cursorY;
\r
439 lastres = seqCanvas.cursorX+getKeyboardNo(keyboardNo1);
\r
440 editSequence(false, seqCanvas.cursorX);
\r
444 void numberPressed(char value)
\r
446 if(keyboardNo1==null)
\r
447 keyboardNo1 = new StringBuffer();
\r
449 if(keyboardNo2!=null)
\r
450 keyboardNo2.append(value);
\r
452 keyboardNo1.append(value);
\r
455 int getKeyboardNo(StringBuffer kb)
\r
460 return Integer.parseInt(kb.toString());
\r
467 * @param evt DOCUMENT ME!
\r
469 public void mouseReleased(MouseEvent evt)
\r
471 mouseDragging = false;
\r
472 mouseWheelPressed = false;
\r
476 doMouseReleasedDefineMode(evt);
\r
490 * @param evt DOCUMENT ME!
\r
492 public void mousePressed(MouseEvent evt)
\r
494 lastMousePress = evt.getPoint();
\r
496 if (javax.swing.SwingUtilities.isMiddleMouseButton(evt))
\r
498 mouseWheelPressed = true;
\r
502 if (evt.isShiftDown() || evt.isAltDown() ||
\r
503 evt.isControlDown())
\r
505 if (evt.isAltDown() || evt.isControlDown())
\r
507 groupEditing = true;
\r
509 editingSeqs = true;
\r
513 doMousePressedDefineMode(evt);
\r
517 int seq = findSeq(evt);
\r
518 int res = findRes(evt);
\r
523 if ((seq < av.getAlignment().getHeight()) &&
\r
524 (res < av.getAlignment().getSequenceAt(seq).getLength()))
\r
541 * @param evt DOCUMENT ME!
\r
543 public void mouseMoved(MouseEvent evt)
\r
547 // This is because MacOSX creates a mouseMoved
\r
548 // If control is down, other platforms will not.
\r
552 int res = findRes(evt);
\r
553 int seq = findSeq(evt);
\r
556 if(res<0 || seq<0 || seq >= av.getAlignment().getHeight())
\r
559 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
\r
561 if (res > sequence.getLength())
\r
566 if(seqCanvas.pdbCanvas!=null && sequence==seqCanvas.pdbCanvas.sequence)
\r
568 seqCanvas.pdbCanvas.highlightRes(sequence.findPosition(res));
\r
571 setStatusMessage(sequence, res, seq);
\r
573 // use aa to see if the mouse pointer is on a
\r
574 if (av.showSequenceFeatures)
\r
576 tooltipText.setLength(6); // Cuts the buffer back to <html>
\r
578 SequenceFeature[] features = findFeaturesAtRes(
\r
579 sequence.getDatasetSequence(), sequence.findPosition(res));
\r
583 for (int i = 0; i < features.length; i++)
\r
585 if (features[i].getType().equals("disulfide bond"))
\r
587 if (features[i].getBegin() == sequence.findPosition(res)
\r
588 || features[i].getEnd() == sequence.findPosition(res))
\r
590 if (tooltipText.length() > 6)
\r
591 tooltipText.append("<br>");
\r
592 tooltipText.append("disulfide bond " + features[i].getBegin() + ":" +
\r
593 features[i].getEnd());
\r
594 if (features[i].links != null)
\r
595 tooltipText.append(" <img src=\"" + linkImageURL + "\">");
\r
600 if (tooltipText.length() > 6)
\r
601 tooltipText.append("<br>");
\r
603 tooltipText.append(features[i].getType() + " " +
\r
604 features[i].begin);
\r
605 if (features[i].begin != features[i].end)
\r
606 tooltipText.append(" " + features[i].end);
\r
608 if (features[i].getDescription() != null
\r
609 && !features[i].description.equals(features[i].getType()))
\r
611 tmpString = features[i].getDescription();
\r
612 int startTag=tmpString.toUpperCase().indexOf("<HTML>");
\r
615 tmpString = tmpString.substring(startTag + 6);
\r
617 int endTag=tmpString.toUpperCase().indexOf("</BODY>");
\r
620 tmpString = tmpString.substring(0, endTag);
\r
622 endTag = tmpString.toUpperCase().indexOf("</HTML>");
\r
625 tmpString = tmpString.substring(0, endTag);
\r
630 tooltipText.append("; " + tmpString);
\r
634 if (tmpString.indexOf("<") > -1 || tmpString.indexOf(">") > -1)
\r
636 //The description does not specify html is to
\r
637 //be used, so we must remove < > symbols
\r
638 tmpString = tmpString.replaceAll("<", "<");
\r
639 tmpString = tmpString.replaceAll(">", ">");
\r
641 tooltipText.append("; ");
\r
642 tooltipText.append(tmpString);
\r
646 tooltipText.append("; "+tmpString);
\r
649 if (features[i].getValue("status") != null )
\r
651 String status = features[i].getValue("status").toString();
\r
652 if(status.length()>0)
\r
653 tooltipText.append("; (" + features[i].getValue("status") + ")");
\r
656 if (features[i].links != null)
\r
657 tooltipText.append(" <img src=\"" + linkImageURL + "\">");
\r
661 // else if(features[i].begin==0 && features[i].end==0)
\r
663 // seqSpecific.append(features[i].featureGroup+": "
\r
664 // + features[i].getType()+" "
\r
665 // +features[i].getDescription()+"<br>");
\r
670 if(tooltipText.length()==6) // <html></html>
\r
672 setToolTipText(null);
\r
676 tooltipText.append("</html>");
\r
677 setToolTipText(tooltipText.toString());
\r
681 setToolTipText(null);
\r
685 void setStatusMessage(SequenceI sequence, int res, int seq)
\r
687 StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " +
\r
688 sequence.getName());
\r
691 if (av.alignment.isNucleotide())
\r
693 obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) +
\r
696 text.append(" Nucleotide: ");
\r
700 obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
\r
702 text.append(" Residue: ");
\r
710 text.append(obj + " (" + sequence.findPosition(res) +
\r
714 ap.alignFrame.statusBar.setText(text.toString());
\r
721 * @param evt DOCUMENT ME!
\r
723 public void mouseDragged(MouseEvent evt)
\r
725 if (mouseWheelPressed)
\r
727 int oldWidth = av.charWidth;
\r
729 //Which is bigger, left-right or up-down?
\r
730 if (Math.abs(evt.getY() - lastMousePress.getY())
\r
731 > Math.abs(evt.getX() - lastMousePress.getX()))
\r
733 int fontSize = av.font.getSize();
\r
735 if (evt.getY() < lastMousePress.getY())
\r
739 else if (evt.getY() > lastMousePress.getY())
\r
747 av.setFont(new Font(av.font.getName(), av.font.getStyle(), fontSize));
\r
748 av.charWidth = oldWidth;
\r
753 if (evt.getX() < lastMousePress.getX() && av.charWidth > 1)
\r
757 else if (evt.getX() > lastMousePress.getX())
\r
765 FontMetrics fm = getFontMetrics(av.getFont());
\r
766 av.validCharWidth = fm.charWidth('M') <= av.charWidth;
\r
768 lastMousePress = evt.getPoint();
\r
775 doMouseDraggedDefineMode(evt);
\r
779 int res = findRes(evt);
\r
786 if ((lastres == -1) || (lastres == res))
\r
791 if ( (res < av.getAlignment().getWidth()) && (res < lastres))
\r
793 // dragLeft, delete gap
\r
794 editSequence(false, res);
\r
797 editSequence(true, res);
\r
799 mouseDragging = true;
\r
800 if(scrollThread!=null)
\r
801 scrollThread.setEvent(evt);
\r
805 synchronized void editSequence(boolean insertGap, int startres)
\r
807 int fixedLeft = -1;
\r
808 int fixedRight = -1;
\r
809 boolean fixedColumns = false;
\r
810 SequenceGroup sg = av.getSelectionGroup();
\r
813 if (!groupEditing && av.hasHiddenRows)
\r
815 if (av.alignment.getSequenceAt(startseq).getHiddenSequences() != null)
\r
817 groupEditing = true;
\r
821 //No group, but the sequence may represent a group
\r
824 && av.alignment.getSequenceAt(startseq).getHiddenSequences() == null)
\r
826 groupEditing = false;
\r
829 SequenceI seq = av.alignment.getSequenceAt(startseq);
\r
830 StringBuffer message = new StringBuffer();
\r
833 message.append("Edit group:");
\r
834 if (editCommand == null)
\r
835 editCommand = new EditCommand("Edit Group");
\r
839 message.append("Edit sequence: " + seq.getName());
\r
840 String label = seq.getName();
\r
841 if(label.length()>10)
\r
842 label = label.substring(0,10);
\r
843 if(editCommand==null)
\r
844 editCommand = new EditCommand("Edit "+label);
\r
848 message.append(" insert ");
\r
850 message.append(" delete ");
\r
852 message.append(Math.abs(startres-lastres)+" gaps.");
\r
853 ap.alignFrame.statusBar.setText(message.toString());
\r
856 //Are we editing within a selection group?
\r
858 || (sg != null && sg.getSequences(true).contains(seq)))
\r
860 fixedColumns = true;
\r
862 //sg might be null as the user may only see 1 sequence,
\r
863 //but the sequence represents a group
\r
866 sg = new SequenceGroup(null, null, false, false, false, 0,
\r
867 av.alignment.getWidth()-1);
\r
868 sg.addSequence(av.alignment.getSequenceAt(startseq), false);
\r
871 fixedLeft = sg.getStartRes();
\r
872 fixedRight = sg.getEndRes();
\r
874 if ( (startres < fixedLeft && lastres >= fixedLeft)
\r
875 || (startres >= fixedLeft && lastres < fixedLeft)
\r
876 || (startres > fixedRight && lastres <=fixedRight)
\r
877 || (startres <= fixedRight && lastres > fixedRight))
\r
883 if (fixedLeft > startres)
\r
885 fixedRight = fixedLeft - 1;
\r
888 else if (fixedRight < startres)
\r
890 fixedLeft = fixedRight;
\r
896 if(av.hasHiddenColumns )
\r
898 fixedColumns = true;
\r
899 int y1 = av.getColumnSelection().getHiddenBoundaryLeft(startres);
\r
900 int y2 = av.getColumnSelection().getHiddenBoundaryRight(startres);
\r
902 if ( (insertGap && startres > y1 && lastres < y1)
\r
903 || (!insertGap && startres < y2 && lastres > y2))
\r
909 //System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
\r
910 //Selection spans a hidden region
\r
911 if(fixedLeft<y1 && (fixedRight>y2 || fixedRight==-1))
\r
919 fixedRight = y2 - 1;
\r
927 Vector vseqs = sg.getSequences(true);
\r
928 int g, groupSize = vseqs.size();
\r
929 SequenceI[] groupSeqs = new SequenceI[groupSize];
\r
930 for (g = 0; g < groupSeqs.length; g++)
\r
931 groupSeqs[g] = (SequenceI) vseqs.elementAt(g);
\r
936 //If the user has selected the whole sequence, and is dragging to
\r
937 // the right, we can still extend the alignment and selectionGroup
\r
938 if( sg.getStartRes() == 0
\r
939 && sg.getEndRes() == fixedRight
\r
940 && sg.getEndRes() == av.alignment.getWidth()-1
\r
943 sg.setEndRes(av.alignment.getWidth() + startres - lastres);
\r
944 fixedRight = sg.getEndRes();
\r
947 // Is it valid with fixed columns??
\r
948 // Find the next gap before the end
\r
949 // of the visible region boundary
\r
950 boolean blank = false;
\r
951 for (fixedRight = fixedRight;
\r
952 fixedRight > lastres;
\r
957 for (g = 0; g < groupSize; g++)
\r
959 for (int j = 0; j < startres - lastres; j++)
\r
961 if (!jalview.util.Comparison.isGap(
\r
962 groupSeqs[g].getCharAt(fixedRight - j)))
\r
975 if(sg.getSize(false) == av.alignment.getHeight() )
\r
977 if((av.hasHiddenColumns
\r
978 && startres<av.getColumnSelection().getHiddenBoundaryRight(startres)))
\r
984 int alWidth = av.alignment.getWidth();
\r
985 if(av.hasHiddenRows)
\r
987 int hwidth = av.alignment.getHiddenSequences().getWidth();
\r
991 //We can still insert gaps if the selectionGroup
\r
992 //contains all the sequences
\r
993 sg.setEndRes(sg.getEndRes()+startres-lastres);
\r
994 fixedRight = alWidth+startres-lastres;
\r
1006 else if(!insertGap)
\r
1008 /// Are we able to delete?
\r
1009 // ie are all columns blank?
\r
1011 for (g = 0; g < groupSize; g++)
\r
1013 for (int j = startres; j < lastres; j++)
\r
1015 if (groupSeqs[g].getLength() <= j)
\r
1020 if (!jalview.util.Comparison.isGap(
\r
1021 groupSeqs[g].getCharAt(j)))
\r
1023 // Not a gap, block edit not valid
\r
1033 // dragging to the right
\r
1034 if (fixedColumns && fixedRight != -1)
\r
1036 for (int j = lastres; j < startres; j++)
\r
1038 insertChar(j, groupSeqs, fixedRight);
\r
1043 editCommand.appendEdit(EditCommand.INSERT_GAP,
\r
1045 startres, startres-lastres,
\r
1046 av.getGapCharacter(),
\r
1052 // dragging to the left
\r
1053 if (fixedColumns && fixedRight != -1)
\r
1055 for (int j = lastres; j > startres; j--)
\r
1057 deleteChar(startres, groupSeqs, fixedRight);
\r
1061 editCommand.appendEdit(EditCommand.DELETE_GAP,
\r
1063 startres, lastres - startres,
\r
1064 av.getGapCharacter(),
\r
1069 else /////Editing a single sequence///////////
\r
1073 // dragging to the right
\r
1074 if (fixedColumns && fixedRight != -1)
\r
1076 for (int j = lastres; j < startres; j++)
\r
1078 insertChar(j, new SequenceI[]{seq}, fixedRight);
\r
1083 editCommand.appendEdit(EditCommand.INSERT_GAP,
\r
1086 lastres, startres-lastres,
\r
1087 av.getGapCharacter(),
\r
1093 // dragging to the left
\r
1094 if (fixedColumns && fixedRight != -1)
\r
1096 for (int j = lastres; j > startres; j--)
\r
1098 if (!jalview.util.Comparison.isGap(seq.getCharAt(startres)))
\r
1103 deleteChar(startres, new SequenceI[]{seq}, fixedRight);
\r
1108 //could be a keyboard edit trying to delete none gaps
\r
1110 for(int m = startres; m<lastres; m++)
\r
1112 if(!jalview.util.Comparison.isGap(seq.getCharAt(m)))
\r
1119 editCommand.appendEdit(EditCommand.DELETE_GAP,
\r
1123 av.getGapCharacter(),
\r
1130 lastres = startres;
\r
1131 seqCanvas.repaint();
\r
1136 void insertChar(int j, SequenceI [] seq, int fixedColumn)
\r
1138 int blankColumn = fixedColumn;
\r
1139 for(int s=0; s<seq.length; s++)
\r
1141 //Find the next gap before the end of the visible region boundary
\r
1142 //If lastCol > j, theres a boundary after the gap insertion
\r
1144 for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
\r
1146 if (jalview.util.Comparison.isGap(seq[s].getCharAt(blankColumn)))
\r
1148 //Theres a space, so break and insert the gap
\r
1153 if (blankColumn <= j)
\r
1155 blankColumn = fixedColumn;
\r
1161 editCommand.appendEdit(EditCommand.DELETE_GAP,
\r
1163 blankColumn, 1, av.getGapCharacter(), true);
\r
1165 editCommand.appendEdit(EditCommand.INSERT_GAP,
\r
1167 j, 1, av.getGapCharacter(),
\r
1172 void deleteChar(int j, SequenceI [] seq, int fixedColumn)
\r
1175 editCommand.appendEdit(EditCommand.DELETE_GAP,
\r
1177 j, 1, av.getGapCharacter(), true);
\r
1179 editCommand.appendEdit(EditCommand.INSERT_GAP,
\r
1181 fixedColumn, 1, av.getGapCharacter(), true);
\r
1187 * @param e DOCUMENT ME!
\r
1189 public void mouseEntered(MouseEvent e)
\r
1194 if (scrollThread != null)
\r
1196 scrollThread.running = false;
\r
1197 scrollThread = null;
\r
1204 * @param e DOCUMENT ME!
\r
1206 public void mouseExited(MouseEvent e)
\r
1208 if (av.getWrapAlignment())
\r
1213 if (mouseDragging)
\r
1215 scrollThread = new ScrollThread();
\r
1219 public void mouseClicked(MouseEvent evt)
\r
1221 SequenceI sequence = av.alignment.getSequenceAt( findSeq(evt) );
\r
1222 if(evt.getClickCount()>1)
\r
1224 if (av.getSelectionGroup().getSize(false) == 1
\r
1225 && av.getSelectionGroup().getEndRes()
\r
1226 - av.getSelectionGroup().getStartRes() < 2)
\r
1227 av.setSelectionGroup(null);
\r
1229 SequenceFeature[] features = findFeaturesAtRes(
\r
1230 sequence.getDatasetSequence(),
\r
1231 sequence.findPosition( findRes(evt) )
\r
1234 if(features!=null && features.length>0)
\r
1236 SearchResults highlight = new SearchResults();
\r
1237 highlight.addResult(sequence,
\r
1238 features[0].getBegin(),
\r
1239 features[0].getEnd());
\r
1240 seqCanvas.highlightSearchResults(highlight);
\r
1242 if(features!=null && features.length>0)
\r
1244 seqCanvas.getFeatureRenderer().amendFeatures(
\r
1246 {sequence}, features, false, ap);
\r
1248 seqCanvas.highlightSearchResults(null);
\r
1253 public void mouseWheelMoved(MouseWheelEvent e)
\r
1256 /* if (mouseWheelPressed)
\r
1258 Font font = av.getFont();
\r
1259 int fontSize = font.getSize();
\r
1260 if (e.getWheelRotation() > 0 && fontSize < 51)
\r
1262 else if (fontSize > 1)
\r
1267 av.setFont(new Font(font.getName(), font.getStyle(), fontSize));
\r
1273 if (e.getWheelRotation() > 0)
\r
1274 ap.scrollUp(false);
\r
1276 ap.scrollUp(true);
\r
1285 * @param evt DOCUMENT ME!
\r
1287 public void doMousePressedDefineMode(MouseEvent evt)
\r
1289 int res = findRes(evt);
\r
1290 int seq = findSeq(evt);
\r
1293 startWrapBlock=wrappedBlock;
\r
1295 if(av.wrapAlignment && seq>av.alignment.getHeight())
\r
1297 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
1298 "Cannot edit annotations in wrapped view.",
\r
1299 "Wrapped view - no edit",
\r
1300 JOptionPane.WARNING_MESSAGE);
\r
1304 if(seq<0 || res<0)
\r
1307 SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq);
\r
1309 if ((sequence == null) || (res > sequence.getLength()))
\r
1314 stretchGroup = av.getSelectionGroup();
\r
1316 if (stretchGroup == null)
\r
1318 stretchGroup = av.alignment.findGroup(sequence);
\r
1320 if ((stretchGroup != null) && (res > stretchGroup.getStartRes()) &&
\r
1321 (res < stretchGroup.getEndRes()))
\r
1323 av.setSelectionGroup(stretchGroup);
\r
1327 stretchGroup = null;
\r
1330 else if (!stretchGroup.getSequences(false).contains(sequence) ||
\r
1331 (stretchGroup.getStartRes() > res) ||
\r
1332 (stretchGroup.getEndRes() < res))
\r
1334 stretchGroup = null;
\r
1336 SequenceGroup[] allGroups = av.alignment.findAllGroups(sequence);
\r
1338 if (allGroups != null)
\r
1340 for (int i = 0; i < allGroups.length; i++)
\r
1342 if ((allGroups[i].getStartRes() <= res) &&
\r
1343 (allGroups[i].getEndRes() >= res))
\r
1345 stretchGroup = allGroups[i];
\r
1351 av.setSelectionGroup(stretchGroup);
\r
1356 if (javax.swing.SwingUtilities.isRightMouseButton(evt))
\r
1358 Vector allFeatures = getAllFeaturesAtRes(sequence.getDatasetSequence(),
\r
1359 sequence.findPosition(res));
\r
1360 Vector links = new Vector();
\r
1361 for (int i = 0; i < allFeatures.size(); i++)
\r
1363 SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(i);
\r
1364 if (sf.links != null)
\r
1366 for (int j = 0; j < sf.links.size(); j++)
\r
1368 links.addElement(sf.links.elementAt(j));
\r
1373 jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(ap, null, links);
\r
1374 pop.show(this, evt.getX(), evt.getY());
\r
1378 if (av.cursorMode)
\r
1380 seqCanvas.cursorX = findRes(evt);
\r
1381 seqCanvas.cursorY = findSeq(evt);
\r
1382 seqCanvas.repaint();
\r
1386 if (stretchGroup == null)
\r
1388 //Only if left mouse button do we want to change group sizes
\r
1390 // define a new group here
\r
1391 SequenceGroup sg = new SequenceGroup();
\r
1392 sg.setStartRes(res);
\r
1393 sg.setEndRes(res);
\r
1394 sg.addSequence(sequence, false);
\r
1395 av.setSelectionGroup(sg);
\r
1396 stretchGroup = sg;
\r
1398 if (av.getConservationSelected())
\r
1400 SliderPanel.setConservationSlider(ap,
\r
1401 av.getGlobalColourScheme(),
\r
1405 if (av.getAbovePIDThreshold())
\r
1407 SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(),
\r
1410 if ( (stretchGroup != null) && (stretchGroup.getEndRes() == res))
\r
1412 // Edit end res position of selected group
\r
1413 changeEndRes = true;
\r
1415 else if ( (stretchGroup != null) &&
\r
1416 (stretchGroup.getStartRes() == res))
\r
1418 // Edit end res position of selected group
\r
1419 changeStartRes = true;
\r
1421 stretchGroup.getWidth();
\r
1424 seqCanvas.repaint();
\r
1430 * @param evt DOCUMENT ME!
\r
1432 public void doMouseReleasedDefineMode(MouseEvent evt)
\r
1434 if (stretchGroup == null)
\r
1440 if(stretchGroup.cs!=null)
\r
1442 if (stretchGroup.cs instanceof ClustalxColourScheme)
\r
1444 ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX(
\r
1445 stretchGroup.getSequences(true),
\r
1446 stretchGroup.getWidth());
\r
1449 if (stretchGroup.cs instanceof Blosum62ColourScheme
\r
1450 || stretchGroup.cs instanceof PIDColourScheme
\r
1451 || stretchGroup.cs.conservationApplied()
\r
1452 || stretchGroup.cs.getThreshold()>0)
\r
1453 stretchGroup.recalcConservation();
\r
1455 if (stretchGroup.cs.conservationApplied())
\r
1457 SliderPanel.setConservationSlider(ap, stretchGroup.cs,
\r
1458 stretchGroup.getName());
\r
1462 SliderPanel.setPIDSliderSource(ap, stretchGroup.cs,
\r
1463 stretchGroup.getName());
\r
1466 changeEndRes = false;
\r
1467 changeStartRes = false;
\r
1468 stretchGroup = null;
\r
1470 PaintRefresher.Refresh(this, av.getSequenceSetId());
\r
1476 * @param evt DOCUMENT ME!
\r
1478 public void doMouseDraggedDefineMode(MouseEvent evt)
\r
1480 int res = findRes(evt);
\r
1481 int y = findSeq(evt);
\r
1483 if(wrappedBlock!=startWrapBlock)
\r
1486 if (stretchGroup == null)
\r
1491 if(res>= av.alignment.getWidth())
\r
1493 res = av.alignment.getWidth()-1;
\r
1496 if (stretchGroup.getEndRes() == res)
\r
1498 // Edit end res position of selected group
\r
1499 changeEndRes = true;
\r
1501 else if (stretchGroup.getStartRes() == res)
\r
1503 // Edit start res position of selected group
\r
1504 changeStartRes = true;
\r
1507 if (res < av.getStartRes())
\r
1509 res = av.getStartRes();
\r
1514 if (res > (stretchGroup.getStartRes() - 1))
\r
1516 stretchGroup.setEndRes(res);
\r
1519 else if (changeStartRes)
\r
1521 if (res < (stretchGroup.getEndRes() + 1))
\r
1523 stretchGroup.setStartRes(res);
\r
1527 int dragDirection = 0;
\r
1531 dragDirection = 1;
\r
1533 else if (y < oldSeq)
\r
1535 dragDirection = -1;
\r
1539 while ((y != oldSeq) && (oldSeq > -1) && (y < av.alignment.getHeight()))
\r
1541 // This routine ensures we don't skip any sequences, as the
\r
1542 // selection is quite slow.
\r
1543 Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
\r
1545 oldSeq += dragDirection;
\r
1550 Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
\r
1552 if (stretchGroup.getSequences(false).contains(nextSeq))
\r
1554 stretchGroup.deleteSequence(seq, false);
\r
1560 stretchGroup.addSequence(seq, false);
\r
1563 stretchGroup.addSequence(nextSeq, false);
\r
1570 mouseDragging = true;
\r
1572 if (scrollThread != null)
\r
1574 scrollThread.setEvent(evt);
\r
1577 seqCanvas.repaint();
\r
1580 void scrollCanvas(MouseEvent evt)
\r
1584 if(scrollThread!=null)
\r
1586 scrollThread.running = false;
\r
1587 scrollThread = null;
\r
1589 mouseDragging = false;
\r
1593 if (scrollThread == null)
\r
1594 scrollThread = new ScrollThread();
\r
1596 mouseDragging = true;
\r
1597 scrollThread.setEvent(evt);
\r
1603 // this class allows scrolling off the bottom of the visible alignment
\r
1604 class ScrollThread extends Thread
\r
1607 boolean running = false;
\r
1609 public ScrollThread()
\r
1614 public void setEvent(MouseEvent e)
\r
1619 public void stopScrolling()
\r
1632 if (mouseDragging && (evt.getY() < 0) &&
\r
1633 (av.getStartSeq() > 0))
\r
1635 running = ap.scrollUp(true);
\r
1638 if (mouseDragging && (evt.getY() >= getHeight()) &&
\r
1639 (av.alignment.getHeight() > av.getEndSeq()))
\r
1641 running = ap.scrollUp(false);
\r
1644 if (mouseDragging && (evt.getX() < 0))
\r
1646 running = ap.scrollRight(false);
\r
1648 else if (mouseDragging && (evt.getX() >= getWidth()))
\r
1650 running = ap.scrollRight(true);
\r
1658 catch (Exception ex)
\r