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
183 if (features != null)
\r
185 for (int i = 0; i < features.length; i++)
\r
187 if (av.featuresDisplayed == null
\r
188 || !av.featuresDisplayed.containsKey(features[i].getType()))
\r
191 if ( (features[i].getBegin() <= sequence.findPosition(res)) &&
\r
192 (features[i].getEnd() >= sequence.findPosition(res)))
\r
194 tmp.addElement(features[i]);
\r
199 features = new SequenceFeature[tmp.size()];
\r
200 for(int i=0; i<tmp.size(); i++)
\r
202 features[i] = (SequenceFeature)tmp.elementAt(i);
\r
208 Vector getAllFeaturesAtRes(SequenceI seq, int res)
\r
210 Vector allFeatures = new Vector();
\r
212 if(seq.getSequenceFeatures()!=null && av.featuresDisplayed!=null)
\r
214 while (index < seq.getSequenceFeatures().length)
\r
216 SequenceFeature sf = seq.getSequenceFeatures()[index];
\r
217 if (sf.getBegin() <= res &&
\r
218 sf.getEnd() >= res)
\r
220 if (av.featuresDisplayed.containsKey(sf.getType()))
\r
222 allFeatures.addElement(sf);
\r
228 return allFeatures;
\r
233 if (editCommand!=null && editCommand.getSize() > 0)
\r
235 ap.alignFrame.addHistoryItem(editCommand);
\r
236 av.firePropertyChange("alignment", null,
\r
237 av.getAlignment().getSequences());
\r
242 editingSeqs = false;
\r
243 groupEditing = false;
\r
244 keyboardNo1 = null;
\r
245 keyboardNo2 = null;
\r
246 editCommand = null;
\r
249 void setCursorRow()
\r
251 seqCanvas.cursorY = getKeyboardNo(keyboardNo1)-1;
\r
255 void setCursorColumn()
\r
257 seqCanvas.cursorX = getKeyboardNo(keyboardNo1)-1;
\r
261 void setCursorRowAndColumn()
\r
263 if(keyboardNo2==null)
\r
265 keyboardNo2 = new StringBuffer();
\r
269 seqCanvas.cursorX = getKeyboardNo(keyboardNo1) - 1;
\r
270 seqCanvas.cursorY = getKeyboardNo(keyboardNo2) - 1;
\r
275 void setCursorPosition()
\r
277 SequenceI sequence =
\r
278 (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);
\r
280 seqCanvas.cursorX = sequence.findIndex(
\r
281 getKeyboardNo(keyboardNo1)-1
\r
286 void moveCursor(int dx, int dy)
\r
288 seqCanvas.cursorX += dx;
\r
289 seqCanvas.cursorY += dy;
\r
293 void scrollToVisible()
\r
295 if (seqCanvas.cursorX < 0)
\r
296 seqCanvas.cursorX = 0;
\r
297 else if (seqCanvas.cursorX > av.alignment.getWidth() - 1)
\r
298 seqCanvas.cursorX = av.alignment.getWidth() - 1;
\r
300 if (seqCanvas.cursorY < 0)
\r
301 seqCanvas.cursorY = 0;
\r
302 else if (seqCanvas.cursorY > av.alignment.getHeight() - 1)
\r
303 seqCanvas.cursorY = av.alignment.getHeight() - 1;
\r
307 if(av.wrapAlignment)
\r
309 ap.scrollToWrappedVisible(seqCanvas.cursorX);
\r
313 while (seqCanvas.cursorY < av.startSeq)
\r
317 while (seqCanvas.cursorY + 1 > av.endSeq)
\r
319 ap.scrollUp(false);
\r
321 if (!av.wrapAlignment)
\r
323 while (seqCanvas.cursorX < av.startRes)
\r
325 if (!ap.scrollRight(false))
\r
328 while (seqCanvas.cursorX > av.endRes)
\r
330 if (!ap.scrollRight(true))
\r
335 setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY),
\r
336 seqCanvas.cursorX, seqCanvas.cursorY);
\r
338 seqCanvas.repaint();
\r
341 void setSelectionAreaAtCursor(boolean topLeft)
\r
343 SequenceI sequence =
\r
344 (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);
\r
346 if(av.getSelectionGroup()!=null)
\r
348 SequenceGroup sg = av.selectionGroup;
\r
349 //Find the top and bottom of this group
\r
350 int min = av.alignment.getHeight(), max = 0;
\r
351 for(int i=0; i<sg.getSize(false); i++)
\r
353 int index = av.alignment.findIndex( sg.getSequenceAt(i) );
\r
364 sg.setStartRes(seqCanvas.cursorX);
\r
365 if(sg.getEndRes()<seqCanvas.cursorX)
\r
366 sg.setEndRes(seqCanvas.cursorX);
\r
368 min = seqCanvas.cursorY;
\r
372 sg.setEndRes(seqCanvas.cursorX);
\r
373 if(sg.getStartRes()>seqCanvas.cursorX)
\r
374 sg.setStartRes(seqCanvas.cursorX);
\r
376 max = seqCanvas.cursorY+1;
\r
381 // Only the user can do this
\r
382 av.setSelectionGroup(null);
\r
386 // Now add any sequences between min and max
\r
387 sg.getSequences(false).clear();
\r
388 for (int i = min; i < max; i++)
\r
390 sg.addSequence(av.alignment.getSequenceAt(i), false);
\r
395 if (av.getSelectionGroup() == null)
\r
397 SequenceGroup sg = new SequenceGroup();
\r
398 sg.setStartRes(seqCanvas.cursorX);
\r
399 sg.setEndRes(seqCanvas.cursorX);
\r
400 sg.addSequence(sequence, false);
\r
401 av.setSelectionGroup(sg);
\r
408 void insertGapAtCursor(boolean group)
\r
410 groupEditing = group;
\r
411 startseq = seqCanvas.cursorY;
\r
412 lastres = seqCanvas.cursorX;
\r
413 editSequence(true, seqCanvas.cursorX+getKeyboardNo(keyboardNo1));
\r
417 void deleteGapAtCursor(boolean group)
\r
419 groupEditing = group;
\r
420 startseq = seqCanvas.cursorY;
\r
421 lastres = seqCanvas.cursorX+getKeyboardNo(keyboardNo1);
\r
422 editSequence(false, seqCanvas.cursorX);
\r
426 void numberPressed(char value)
\r
428 if(keyboardNo1==null)
\r
429 keyboardNo1 = new StringBuffer();
\r
431 if(keyboardNo2!=null)
\r
432 keyboardNo2.append(value);
\r
434 keyboardNo1.append(value);
\r
437 int getKeyboardNo(StringBuffer kb)
\r
442 return Integer.parseInt(kb.toString());
\r
449 * @param evt DOCUMENT ME!
\r
451 public void mouseReleased(MouseEvent evt)
\r
453 mouseDragging = false;
\r
454 mouseWheelPressed = false;
\r
458 doMouseReleasedDefineMode(evt);
\r
472 * @param evt DOCUMENT ME!
\r
474 public void mousePressed(MouseEvent evt)
\r
476 lastMousePress = evt.getPoint();
\r
478 if (javax.swing.SwingUtilities.isMiddleMouseButton(evt))
\r
480 mouseWheelPressed = true;
\r
484 if (evt.isShiftDown() || evt.isAltDown() ||
\r
485 evt.isControlDown())
\r
487 if (evt.isAltDown() || evt.isControlDown())
\r
489 groupEditing = true;
\r
491 editingSeqs = true;
\r
495 doMousePressedDefineMode(evt);
\r
499 int seq = findSeq(evt);
\r
500 int res = findRes(evt);
\r
505 if ((seq < av.getAlignment().getHeight()) &&
\r
506 (res < av.getAlignment().getSequenceAt(seq).getLength()))
\r
523 * @param evt DOCUMENT ME!
\r
525 public void mouseMoved(MouseEvent evt)
\r
529 // This is because MacOSX creates a mouseMoved
\r
530 // If control is down, other platforms will not.
\r
534 int res = findRes(evt);
\r
535 int seq = findSeq(evt);
\r
538 if(res<0 || seq<0 || seq >= av.getAlignment().getHeight())
\r
541 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
\r
543 if (res > sequence.getLength())
\r
548 if(seqCanvas.pdbCanvas!=null && sequence==seqCanvas.pdbCanvas.sequence)
\r
550 seqCanvas.pdbCanvas.highlightRes(sequence.findPosition(res));
\r
553 setStatusMessage(sequence, res, seq);
\r
555 // use aa to see if the mouse pointer is on a
\r
556 if (av.showSequenceFeatures)
\r
558 tooltipText.setLength(6); // Cuts the buffer back to <html>
\r
560 SequenceFeature[] features = findFeaturesAtRes(
\r
561 sequence.getDatasetSequence(), res);
\r
565 for (int i = 0; i < features.length; i++)
\r
567 if (features[i].getType().equals("disulfide bond"))
\r
569 if (features[i].getBegin() == sequence.findPosition(res)
\r
570 || features[i].getEnd() == sequence.findPosition(res))
\r
572 if (tooltipText.length() > 6)
\r
573 tooltipText.append("<br>");
\r
574 tooltipText.append("disulfide bond " + features[i].getBegin() + ":" +
\r
575 features[i].getEnd());
\r
576 if (features[i].links != null)
\r
577 tooltipText.append(" <img src=\"" + linkImageURL + "\">");
\r
582 if (tooltipText.length() > 6)
\r
583 tooltipText.append("<br>");
\r
585 tooltipText.append(features[i].getType() + " " +
\r
586 features[i].begin);
\r
587 if (features[i].begin != features[i].end)
\r
588 tooltipText.append(" " + features[i].end);
\r
590 if (features[i].getDescription() != null
\r
591 && !features[i].description.equals(features[i].getType()))
\r
593 tmpString = features[i].getDescription();
\r
594 int startTag=tmpString.toUpperCase().indexOf("<HTML>");
\r
597 tmpString = tmpString.substring(startTag + 6);
\r
599 int endTag=tmpString.toUpperCase().indexOf("</BODY>");
\r
602 tmpString = tmpString.substring(0, endTag);
\r
604 endTag = tmpString.toUpperCase().indexOf("</HTML>");
\r
607 tmpString = tmpString.substring(0, endTag);
\r
612 tooltipText.append("; " + tmpString);
\r
616 if (tmpString.indexOf("<") > -1 || tmpString.indexOf(">") > -1)
\r
618 //The description does not specify html is to
\r
619 //be used, so we must remove < > symbols
\r
620 tmpString = tmpString.replaceAll("<", "<");
\r
621 tmpString = tmpString.replaceAll(">", ">");
\r
623 tooltipText.append("; ");
\r
624 tooltipText.append(tmpString);
\r
628 tooltipText.append("; "+tmpString);
\r
631 if (features[i].getValue("status") != null )
\r
633 String status = features[i].getValue("status").toString();
\r
634 if(status.length()>0)
\r
635 tooltipText.append("; (" + features[i].getValue("status") + ")");
\r
638 if (features[i].links != null)
\r
639 tooltipText.append(" <img src=\"" + linkImageURL + "\">");
\r
643 // else if(features[i].begin==0 && features[i].end==0)
\r
645 // seqSpecific.append(features[i].featureGroup+": "
\r
646 // + features[i].getType()+" "
\r
647 // +features[i].getDescription()+"<br>");
\r
653 if(tooltipText.length()==6) // <html></html>
\r
656 setToolTipText("");
\r
660 tooltipText.append("</html>");
\r
661 setToolTipText(tooltipText.toString());
\r
665 setToolTipText("");
\r
669 void setStatusMessage(SequenceI sequence, int res, int seq)
\r
671 StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " +
\r
672 sequence.getName());
\r
675 if (av.alignment.isNucleotide())
\r
677 obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) +
\r
680 text.append(" Nucleotide: ");
\r
684 obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
\r
686 text.append(" Residue: ");
\r
694 text.append(obj + " (" + sequence.findPosition(res) +
\r
698 ap.alignFrame.statusBar.setText(text.toString());
\r
705 * @param evt DOCUMENT ME!
\r
707 public void mouseDragged(MouseEvent evt)
\r
709 if (mouseWheelPressed)
\r
711 int oldWidth = av.charWidth;
\r
713 //Which is bigger, left-right or up-down?
\r
714 if (Math.abs(evt.getY() - lastMousePress.getY())
\r
715 > Math.abs(evt.getX() - lastMousePress.getX()))
\r
717 int fontSize = av.font.getSize();
\r
719 if (evt.getY() < lastMousePress.getY())
\r
723 else if (evt.getY() > lastMousePress.getY())
\r
731 av.setFont(new Font(av.font.getName(), av.font.getStyle(), fontSize));
\r
732 av.charWidth = oldWidth;
\r
737 if (evt.getX() < lastMousePress.getX() && av.charWidth > 1)
\r
741 else if (evt.getX() > lastMousePress.getX())
\r
749 FontMetrics fm = getFontMetrics(av.getFont());
\r
750 av.validCharWidth = fm.charWidth('M') <= av.charWidth;
\r
752 lastMousePress = evt.getPoint();
\r
759 doMouseDraggedDefineMode(evt);
\r
763 int res = findRes(evt);
\r
770 if ((lastres == -1) || (lastres == res))
\r
775 if ( (res < av.getAlignment().getWidth()) && (res < lastres))
\r
777 // dragLeft, delete gap
\r
778 editSequence(false, res);
\r
781 editSequence(true, res);
\r
783 mouseDragging = true;
\r
784 if(scrollThread!=null)
\r
785 scrollThread.setEvent(evt);
\r
789 synchronized void editSequence(boolean insertGap, int startres)
\r
791 int fixedLeft = -1;
\r
792 int fixedRight = -1;
\r
793 boolean fixedColumns = false;
\r
794 SequenceGroup sg = av.getSelectionGroup();
\r
797 if (!groupEditing && av.hasHiddenRows)
\r
799 if (av.alignment.getSequenceAt(startseq).getHiddenSequences() != null)
\r
801 groupEditing = true;
\r
805 //No group, but the sequence may represent a group
\r
808 && av.alignment.getSequenceAt(startseq).getHiddenSequences() == null)
\r
810 groupEditing = false;
\r
813 SequenceI seq = av.alignment.getSequenceAt(startseq);
\r
814 StringBuffer message = new StringBuffer();
\r
817 message.append("Edit group:");
\r
818 if (editCommand == null)
\r
819 editCommand = new EditCommand("Edit Group");
\r
823 message.append("Edit sequence: " + seq.getName());
\r
824 String label = seq.getName();
\r
825 if(label.length()>10)
\r
826 label = label.substring(0,10);
\r
827 if(editCommand==null)
\r
828 editCommand = new EditCommand("Edit "+label);
\r
832 message.append(" insert ");
\r
834 message.append(" delete ");
\r
836 message.append(Math.abs(startres-lastres)+" gaps.");
\r
837 ap.alignFrame.statusBar.setText(message.toString());
\r
840 //Are we editing within a selection group?
\r
842 || (sg != null && sg.getSequences(true).contains(seq)))
\r
844 fixedColumns = true;
\r
846 //sg might be null as the user may only see 1 sequence,
\r
847 //but the sequence represents a group
\r
850 sg = new SequenceGroup(null, null, false, false, false, 0,
\r
851 av.alignment.getWidth()-1);
\r
852 sg.addSequence(av.alignment.getSequenceAt(startseq), false);
\r
855 fixedLeft = sg.getStartRes();
\r
856 fixedRight = sg.getEndRes();
\r
858 if ( (startres < fixedLeft && lastres >= fixedLeft)
\r
859 || (startres >= fixedLeft && lastres < fixedLeft)
\r
860 || (startres > fixedRight && lastres <=fixedRight)
\r
861 || (startres <= fixedRight && lastres > fixedRight))
\r
867 if (fixedLeft > startres)
\r
869 fixedRight = fixedLeft - 1;
\r
872 else if (fixedRight < startres)
\r
874 fixedLeft = fixedRight;
\r
880 if(av.hasHiddenColumns )
\r
882 fixedColumns = true;
\r
883 int y1 = av.getColumnSelection().getHiddenBoundaryLeft(startres);
\r
884 int y2 = av.getColumnSelection().getHiddenBoundaryRight(startres);
\r
886 if ( (insertGap && startres > y1 && lastres < y1)
\r
887 || (!insertGap && startres < y2 && lastres > y2))
\r
893 //System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
\r
894 //Selection spans a hidden region
\r
895 if(fixedLeft<y1 && (fixedRight>y2 || fixedRight==-1))
\r
903 fixedRight = y2 - 1;
\r
911 Vector vseqs = sg.getSequences(true);
\r
912 int g, groupSize = vseqs.size();
\r
913 SequenceI[] groupSeqs = new SequenceI[groupSize];
\r
914 for (g = 0; g < groupSeqs.length; g++)
\r
915 groupSeqs[g] = (SequenceI) vseqs.elementAt(g);
\r
920 //If the user has selected the whole sequence, and is dragging to
\r
921 // the right, we can still extend the alignment and selectionGroup
\r
922 if( sg.getStartRes() == 0
\r
923 && sg.getEndRes() == fixedRight
\r
924 && sg.getEndRes() == av.alignment.getWidth()-1
\r
927 sg.setEndRes(av.alignment.getWidth() + startres - lastres);
\r
928 fixedRight = sg.getEndRes();
\r
931 // Is it valid with fixed columns??
\r
932 // Find the next gap before the end
\r
933 // of the visible region boundary
\r
934 boolean blank = false;
\r
935 for (fixedRight = fixedRight;
\r
936 fixedRight > lastres;
\r
941 for (g = 0; g < groupSize; g++)
\r
943 for (int j = 0; j < startres - lastres; j++)
\r
945 if (!jalview.util.Comparison.isGap(
\r
946 groupSeqs[g].getCharAt(fixedRight - j)))
\r
959 if(sg.getSize(false) == av.alignment.getHeight() )
\r
961 if((av.hasHiddenColumns
\r
962 && startres<av.getColumnSelection().getHiddenBoundaryRight(startres)))
\r
968 int alWidth = av.alignment.getWidth();
\r
969 if(av.hasHiddenRows)
\r
971 int hwidth = av.alignment.getHiddenSequences().getWidth();
\r
975 //We can still insert gaps if the selectionGroup
\r
976 //contains all the sequences
\r
977 sg.setEndRes(sg.getEndRes()+startres-lastres);
\r
978 fixedRight = alWidth+startres-lastres;
\r
990 else if(!insertGap)
\r
992 /// Are we able to delete?
\r
993 // ie are all columns blank?
\r
995 for (g = 0; g < groupSize; g++)
\r
997 for (int j = startres; j < lastres; j++)
\r
999 if (groupSeqs[g].getLength() <= j)
\r
1004 if (!jalview.util.Comparison.isGap(
\r
1005 groupSeqs[g].getCharAt(j)))
\r
1007 // Not a gap, block edit not valid
\r
1017 // dragging to the right
\r
1018 if (fixedColumns && fixedRight != -1)
\r
1020 for (int j = lastres; j < startres; j++)
\r
1022 insertChar(j, groupSeqs, fixedRight);
\r
1027 editCommand.appendEdit(EditCommand.INSERT_GAP,
\r
1029 startres, startres-lastres,
\r
1030 av.getGapCharacter(),
\r
1036 // dragging to the left
\r
1037 if (fixedColumns && fixedRight != -1)
\r
1039 for (int j = lastres; j > startres; j--)
\r
1041 deleteChar(startres, groupSeqs, fixedRight);
\r
1045 editCommand.appendEdit(EditCommand.DELETE_GAP,
\r
1047 startres, lastres - startres,
\r
1048 av.getGapCharacter(),
\r
1053 else /////Editing a single sequence///////////
\r
1057 // dragging to the right
\r
1058 if (fixedColumns && fixedRight != -1)
\r
1060 for (int j = lastres; j < startres; j++)
\r
1062 insertChar(j, new SequenceI[]{seq}, fixedRight);
\r
1067 editCommand.appendEdit(EditCommand.INSERT_GAP,
\r
1070 lastres, startres-lastres,
\r
1071 av.getGapCharacter(),
\r
1077 // dragging to the left
\r
1078 if (fixedColumns && fixedRight != -1)
\r
1080 for (int j = lastres; j > startres; j--)
\r
1082 if (!jalview.util.Comparison.isGap(seq.getCharAt(startres)))
\r
1087 deleteChar(startres, new SequenceI[]{seq}, fixedRight);
\r
1092 //could be a keyboard edit trying to delete none gaps
\r
1094 for(int m = startres; m<lastres; m++)
\r
1096 if(!jalview.util.Comparison.isGap(seq.getCharAt(m)))
\r
1103 editCommand.appendEdit(EditCommand.DELETE_GAP,
\r
1107 av.getGapCharacter(),
\r
1114 lastres = startres;
\r
1115 seqCanvas.repaint();
\r
1120 void insertChar(int j, SequenceI [] seq, int fixedColumn)
\r
1122 int blankColumn = fixedColumn;
\r
1123 for(int s=0; s<seq.length; s++)
\r
1125 //Find the next gap before the end of the visible region boundary
\r
1126 //If lastCol > j, theres a boundary after the gap insertion
\r
1128 for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
\r
1130 if (jalview.util.Comparison.isGap(seq[s].getCharAt(blankColumn)))
\r
1132 //Theres a space, so break and insert the gap
\r
1137 if (blankColumn <= j)
\r
1139 blankColumn = fixedColumn;
\r
1145 editCommand.appendEdit(EditCommand.DELETE_GAP,
\r
1147 blankColumn, 1, av.getGapCharacter(), true);
\r
1149 editCommand.appendEdit(EditCommand.INSERT_GAP,
\r
1151 j, 1, av.getGapCharacter(),
\r
1156 void deleteChar(int j, SequenceI [] seq, int fixedColumn)
\r
1159 editCommand.appendEdit(EditCommand.DELETE_GAP,
\r
1161 j, 1, av.getGapCharacter(), true);
\r
1163 editCommand.appendEdit(EditCommand.INSERT_GAP,
\r
1165 fixedColumn, 1, av.getGapCharacter(), true);
\r
1171 * @param e DOCUMENT ME!
\r
1173 public void mouseEntered(MouseEvent e)
\r
1178 if (scrollThread != null)
\r
1180 scrollThread.running = false;
\r
1181 scrollThread = null;
\r
1188 * @param e DOCUMENT ME!
\r
1190 public void mouseExited(MouseEvent e)
\r
1192 if (av.getWrapAlignment())
\r
1197 if (mouseDragging)
\r
1199 scrollThread = new ScrollThread();
\r
1203 public void mouseClicked(MouseEvent evt)
\r
1205 if(evt.getClickCount()>1)
\r
1208 SequenceFeature[] features = findFeaturesAtRes(
\r
1209 av.alignment.getSequenceAt( findSeq(evt) ).getDatasetSequence(),
\r
1212 for(int f=0; f<features.length; f++)
\r
1213 System.out.println("SELECT: "+features[f].getType()+" "
\r
1214 +features[f].getBegin()+" "+features[f].getEnd());
\r
1219 public void mouseWheelMoved(MouseWheelEvent e)
\r
1222 /* if (mouseWheelPressed)
\r
1224 Font font = av.getFont();
\r
1225 int fontSize = font.getSize();
\r
1226 if (e.getWheelRotation() > 0 && fontSize < 51)
\r
1228 else if (fontSize > 1)
\r
1233 av.setFont(new Font(font.getName(), font.getStyle(), fontSize));
\r
1239 if (e.getWheelRotation() > 0)
\r
1240 ap.scrollUp(false);
\r
1242 ap.scrollUp(true);
\r
1251 * @param evt DOCUMENT ME!
\r
1253 public void doMousePressedDefineMode(MouseEvent evt)
\r
1255 int res = findRes(evt);
\r
1256 int seq = findSeq(evt);
\r
1259 startWrapBlock=wrappedBlock;
\r
1261 if(av.wrapAlignment && seq>av.alignment.getHeight())
\r
1263 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
1264 "Cannot edit annotations in wrapped view.",
\r
1265 "Wrapped view - no edit",
\r
1266 JOptionPane.WARNING_MESSAGE);
\r
1270 if(seq<0 || res<0)
\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
1286 if ((stretchGroup != null) && (res > stretchGroup.getStartRes()) &&
\r
1287 (res < stretchGroup.getEndRes()))
\r
1289 av.setSelectionGroup(stretchGroup);
\r
1293 stretchGroup = null;
\r
1296 else if (!stretchGroup.getSequences(false).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
1317 av.setSelectionGroup(stretchGroup);
\r
1322 if (javax.swing.SwingUtilities.isRightMouseButton(evt))
\r
1324 Vector allFeatures = getAllFeaturesAtRes(sequence.getDatasetSequence(),
\r
1325 sequence.findPosition(res));
\r
1326 Vector links = new Vector();
\r
1327 for (int i = 0; i < allFeatures.size(); i++)
\r
1329 SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(i);
\r
1330 if (sf.links != null)
\r
1332 for (int j = 0; j < sf.links.size(); j++)
\r
1334 links.addElement(sf.links.elementAt(j));
\r
1339 jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(ap, null, links);
\r
1340 pop.show(this, evt.getX(), evt.getY());
\r
1344 if (av.cursorMode)
\r
1346 seqCanvas.cursorX = findRes(evt);
\r
1347 seqCanvas.cursorY = findSeq(evt);
\r
1348 seqCanvas.repaint();
\r
1352 if (stretchGroup == null)
\r
1354 //Only if left mouse button do we want to change group sizes
\r
1356 // define a new group here
\r
1357 SequenceGroup sg = new SequenceGroup();
\r
1358 sg.setStartRes(res);
\r
1359 sg.setEndRes(res);
\r
1360 sg.addSequence(sequence, false);
\r
1361 av.setSelectionGroup(sg);
\r
1362 stretchGroup = sg;
\r
1364 if (av.getConservationSelected())
\r
1366 SliderPanel.setConservationSlider(ap,
\r
1367 av.getGlobalColourScheme(),
\r
1371 if (av.getAbovePIDThreshold())
\r
1373 SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(),
\r
1376 if ( (stretchGroup != null) && (stretchGroup.getEndRes() == res))
\r
1378 // Edit end res position of selected group
\r
1379 changeEndRes = true;
\r
1381 else if ( (stretchGroup != null) &&
\r
1382 (stretchGroup.getStartRes() == res))
\r
1384 // Edit end res position of selected group
\r
1385 changeStartRes = true;
\r
1387 stretchGroup.getWidth();
\r
1390 seqCanvas.repaint();
\r
1396 * @param evt DOCUMENT ME!
\r
1398 public void doMouseReleasedDefineMode(MouseEvent evt)
\r
1400 if (stretchGroup == null)
\r
1406 if(stretchGroup.cs!=null)
\r
1408 if (stretchGroup.cs instanceof ClustalxColourScheme)
\r
1410 ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX(
\r
1411 stretchGroup.getSequences(true),
\r
1412 stretchGroup.getWidth());
\r
1415 if (stretchGroup.cs.conservationApplied())
\r
1417 SliderPanel.setConservationSlider(ap, stretchGroup.cs,
\r
1418 stretchGroup.getName());
\r
1419 stretchGroup.recalcConservation();
\r
1423 SliderPanel.setPIDSliderSource(ap, stretchGroup.cs,
\r
1424 stretchGroup.getName());
\r
1427 changeEndRes = false;
\r
1428 changeStartRes = false;
\r
1429 stretchGroup = null;
\r
1431 PaintRefresher.Refresh(this, av.getSequenceSetId());
\r
1437 * @param evt DOCUMENT ME!
\r
1439 public void doMouseDraggedDefineMode(MouseEvent evt)
\r
1441 int res = findRes(evt);
\r
1442 int y = findSeq(evt);
\r
1444 if(wrappedBlock!=startWrapBlock)
\r
1447 if (stretchGroup == null)
\r
1452 if(res> av.alignment.getWidth())
\r
1454 res = av.alignment.getWidth()-1;
\r
1457 if (stretchGroup.getEndRes() == res)
\r
1459 // Edit end res position of selected group
\r
1460 changeEndRes = true;
\r
1462 else if (stretchGroup.getStartRes() == res)
\r
1464 // Edit start res position of selected group
\r
1465 changeStartRes = true;
\r
1468 if (res < av.getStartRes())
\r
1470 res = av.getStartRes();
\r
1475 if (res > (stretchGroup.getStartRes() - 1))
\r
1477 stretchGroup.setEndRes(res);
\r
1480 else if (changeStartRes)
\r
1482 if (res < (stretchGroup.getEndRes() + 1))
\r
1484 stretchGroup.setStartRes(res);
\r
1488 int dragDirection = 0;
\r
1492 dragDirection = 1;
\r
1494 else if (y < oldSeq)
\r
1496 dragDirection = -1;
\r
1500 while ((y != oldSeq) && (oldSeq > -1) && (y < av.alignment.getHeight()))
\r
1502 // This routine ensures we don't skip any sequences, as the
\r
1503 // selection is quite slow.
\r
1504 Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
\r
1506 oldSeq += dragDirection;
\r
1511 Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
\r
1513 if (stretchGroup.getSequences(false).contains(nextSeq))
\r
1515 stretchGroup.deleteSequence(seq, false);
\r
1521 stretchGroup.addSequence(seq, false);
\r
1524 stretchGroup.addSequence(nextSeq, false);
\r
1531 mouseDragging = true;
\r
1533 if (scrollThread != null)
\r
1535 scrollThread.setEvent(evt);
\r
1538 seqCanvas.repaint();
\r
1541 void scrollCanvas(MouseEvent evt)
\r
1545 if(scrollThread!=null)
\r
1547 scrollThread.running = false;
\r
1548 scrollThread = null;
\r
1550 mouseDragging = false;
\r
1554 if (scrollThread == null)
\r
1555 scrollThread = new ScrollThread();
\r
1557 mouseDragging = true;
\r
1558 scrollThread.setEvent(evt);
\r
1564 // this class allows scrolling off the bottom of the visible alignment
\r
1565 class ScrollThread extends Thread
\r
1568 boolean running = false;
\r
1570 public ScrollThread()
\r
1575 public void setEvent(MouseEvent e)
\r
1580 public void stopScrolling()
\r
1593 if (mouseDragging && (evt.getY() < 0) &&
\r
1594 (av.getStartSeq() > 0))
\r
1596 running = ap.scrollUp(true);
\r
1599 if (mouseDragging && (evt.getY() >= getHeight()) &&
\r
1600 (av.alignment.getHeight() > av.getEndSeq()))
\r
1602 running = ap.scrollUp(false);
\r
1605 if (mouseDragging && (evt.getX() < 0))
\r
1607 running = ap.scrollRight(false);
\r
1609 else if (mouseDragging && (evt.getX() >= getWidth()))
\r
1611 running = ap.scrollRight(true);
\r
1619 catch (Exception ex)
\r