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
19 package jalview.gui;
\r
21 import jalview.datamodel.*;
\r
23 import jalview.schemes.*;
\r
26 import java.awt.event.*;
\r
28 import javax.swing.*;
\r
30 import java.util.Vector;
\r
37 * @version $Revision$
\r
39 public class SeqPanel extends JPanel implements MouseListener,
\r
40 MouseMotionListener, MouseWheelListener
\r
43 /** DOCUMENT ME!! */
\r
44 public SeqCanvas seqCanvas;
\r
46 /** DOCUMENT ME!! */
\r
47 public AlignmentPanel ap;
\r
48 protected int lastres;
\r
49 protected int startseq;
\r
50 protected AlignViewport av;
\r
52 // if character is inserted or deleted, we will need to recalculate the conservation
\r
53 boolean seqEditOccurred = false;
\r
54 ScrollThread scrollThread = null;
\r
55 boolean mouseDragging = false;
\r
56 boolean editingSeqs = false;
\r
57 boolean groupEditing = false;
\r
59 //////////////////////////////////////////
\r
60 /////Everything below this is for defining the boundary of the rubberband
\r
61 //////////////////////////////////////////
\r
63 boolean changeEndSeq = false;
\r
64 boolean changeStartSeq = false;
\r
65 boolean changeEndRes = false;
\r
66 boolean changeStartRes = false;
\r
67 SequenceGroup stretchGroup = null;
\r
68 boolean remove = false;
\r
70 Point lastMousePress;
\r
71 boolean mouseWheelPressed = false;
\r
72 StringBuffer keyboardNo1;
\r
73 StringBuffer keyboardNo2;
\r
75 java.net.URL linkImageURL;
\r
78 * Creates a new SeqPanel object.
\r
80 * @param avp DOCUMENT ME!
\r
81 * @param p DOCUMENT ME!
\r
83 public SeqPanel(AlignViewport avp, AlignmentPanel p)
\r
85 linkImageURL = getClass().getResource("/images/link.gif");
\r
86 ToolTipManager.sharedInstance().registerComponent(this);
\r
87 ToolTipManager.sharedInstance().setInitialDelay(0);
\r
88 ToolTipManager.sharedInstance().setDismissDelay(10000);
\r
90 setBackground(Color.white);
\r
92 seqCanvas = new SeqCanvas(avp);
\r
93 setLayout(new BorderLayout());
\r
94 add(seqCanvas, BorderLayout.CENTER);
\r
100 addMouseMotionListener(this);
\r
101 addMouseListener(this);
\r
102 addMouseWheelListener(this);
\r
106 int startWrapBlock=-1;
\r
107 int wrappedBlock=-1;
\r
108 int findRes(MouseEvent evt)
\r
111 int x = evt.getX();
\r
113 if (av.wrapAlignment)
\r
116 int hgap = av.charHeight;
\r
117 if (av.scaleAboveWrapped)
\r
118 hgap += av.charHeight;
\r
120 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
121 + hgap + seqCanvas.getAnnotationHeight();
\r
123 int y = evt.getY();
\r
125 x -= seqCanvas.LABEL_WEST;
\r
128 int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());
\r
130 wrappedBlock = y / cHeight;
\r
131 wrappedBlock += av.getStartRes() / cwidth;
\r
133 res = wrappedBlock * cwidth + x / av.getCharWidth();
\r
138 res = (x / av.getCharWidth()) + av.getStartRes();
\r
141 if(av.hasHiddenColumns)
\r
142 res = av.getColumnSelection().adjustForHiddenColumns(res);
\r
148 int findSeq(MouseEvent evt)
\r
152 int y = evt.getY();
\r
154 if (av.wrapAlignment)
\r
156 int hgap = av.charHeight;
\r
157 if (av.scaleAboveWrapped)
\r
158 hgap += av.charHeight;
\r
160 int cHeight = av.getAlignment().getHeight() * av.charHeight
\r
161 + hgap + seqCanvas.getAnnotationHeight();
\r
165 seq = ( (y % cHeight) / av.getCharHeight());
\r
169 seq = (y / av.getCharHeight()) + av.getStartSeq();
\r
175 Vector getAllFeaturesAtRes(SequenceI seq, int res)
\r
177 Vector allFeatures = new Vector();
\r
179 if(seq.getSequenceFeatures()!=null && av.featuresDisplayed!=null)
\r
181 while (index < seq.getSequenceFeatures().length)
\r
183 SequenceFeature sf = seq.getSequenceFeatures()[index];
\r
184 if (sf.getBegin() <= res &&
\r
185 sf.getEnd() >= res)
\r
187 if (av.featuresDisplayed.containsKey(sf.getType()))
\r
189 allFeatures.addElement(sf);
\r
195 return allFeatures;
\r
202 seqEditOccurred = false;
\r
203 editingSeqs = false;
\r
204 groupEditing = false;
\r
205 keyboardNo1 = null;
\r
206 keyboardNo2 = null;
\r
209 void setCursorRow()
\r
211 seqCanvas.cursorY = getKeyboardNo(keyboardNo1)-1;
\r
215 void setCursorColumn()
\r
217 seqCanvas.cursorX = getKeyboardNo(keyboardNo1)-1;
\r
221 void setCursorRowAndColumn()
\r
223 if(keyboardNo2==null)
\r
225 keyboardNo2 = new StringBuffer();
\r
229 seqCanvas.cursorX = getKeyboardNo(keyboardNo1) - 1;
\r
230 seqCanvas.cursorY = getKeyboardNo(keyboardNo2) - 1;
\r
235 void setCursorPosition()
\r
237 SequenceI sequence =
\r
238 (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);
\r
240 seqCanvas.cursorX = sequence.findIndex(
\r
241 getKeyboardNo(keyboardNo1)-1
\r
246 void moveCursor(int dx, int dy)
\r
248 seqCanvas.cursorX += dx;
\r
249 seqCanvas.cursorY += dy;
\r
253 void scrollToVisible()
\r
255 if (seqCanvas.cursorX < 0)
\r
256 seqCanvas.cursorX = 0;
\r
257 else if (seqCanvas.cursorX > av.alignment.getWidth() - 1)
\r
258 seqCanvas.cursorX = av.alignment.getWidth() - 1;
\r
260 if (seqCanvas.cursorY < 0)
\r
261 seqCanvas.cursorY = 0;
\r
262 else if (seqCanvas.cursorY > av.alignment.getHeight() - 1)
\r
263 seqCanvas.cursorY = av.alignment.getHeight() - 1;
\r
267 if(av.wrapAlignment)
\r
269 ap.scrollToWrappedVisible(seqCanvas.cursorX);
\r
273 while (seqCanvas.cursorY < av.startSeq)
\r
277 while (seqCanvas.cursorY + 1 > av.endSeq)
\r
279 ap.scrollUp(false);
\r
281 if (!av.wrapAlignment)
\r
283 while (seqCanvas.cursorX < av.startRes)
\r
285 if (!ap.scrollRight(false))
\r
288 while (seqCanvas.cursorX > av.endRes)
\r
290 if (!ap.scrollRight(true))
\r
295 setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY),
\r
296 seqCanvas.cursorX, seqCanvas.cursorY);
\r
298 seqCanvas.repaint();
\r
301 void setSelectionAreaAtCursor(boolean topLeft)
\r
303 SequenceI sequence =
\r
304 (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);
\r
306 if(av.getSelectionGroup()!=null)
\r
308 SequenceGroup sg = av.selectionGroup;
\r
309 //Find the top and bottom of this group
\r
310 int min = av.alignment.getHeight(), max = 0;
\r
311 for(int i=0; i<sg.getSize(false); i++)
\r
313 int index = av.alignment.findIndex( sg.getSequenceAt(i) );
\r
324 sg.setStartRes(seqCanvas.cursorX);
\r
325 if(sg.getEndRes()<seqCanvas.cursorX)
\r
326 sg.setEndRes(seqCanvas.cursorX);
\r
328 min = seqCanvas.cursorY;
\r
332 sg.setEndRes(seqCanvas.cursorX);
\r
333 if(sg.getStartRes()>seqCanvas.cursorX)
\r
334 sg.setStartRes(seqCanvas.cursorX);
\r
336 max = seqCanvas.cursorY+1;
\r
341 // Only the user can do this
\r
342 av.setSelectionGroup(null);
\r
346 // Now add any sequences between min and max
\r
347 sg.getSequences(false).clear();
\r
348 for (int i = min; i < max; i++)
\r
350 sg.addSequence(av.alignment.getSequenceAt(i), false);
\r
355 if (av.getSelectionGroup() == null)
\r
357 SequenceGroup sg = new SequenceGroup();
\r
358 sg.setStartRes(seqCanvas.cursorX);
\r
359 sg.setEndRes(seqCanvas.cursorX);
\r
360 sg.addSequence(sequence, false);
\r
361 av.setSelectionGroup(sg);
\r
368 void insertGapAtCursor(boolean group)
\r
370 ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence",
\r
371 av.alignment, HistoryItem.EDIT));
\r
372 groupEditing = group;
\r
373 startseq = seqCanvas.cursorY;
\r
374 lastres = seqCanvas.cursorX;
\r
375 editSequence(true, seqCanvas.cursorX+getKeyboardNo(keyboardNo1));
\r
379 void deleteGapAtCursor(boolean group)
\r
381 ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence",
\r
382 av.alignment, HistoryItem.EDIT));
\r
383 groupEditing = group;
\r
384 startseq = seqCanvas.cursorY;
\r
385 lastres = seqCanvas.cursorX+getKeyboardNo(keyboardNo1);
\r
386 editSequence(false, seqCanvas.cursorX);
\r
390 void numberPressed(char value)
\r
392 if(keyboardNo1==null)
\r
393 keyboardNo1 = new StringBuffer();
\r
395 if(keyboardNo2!=null)
\r
396 keyboardNo2.append(value);
\r
398 keyboardNo1.append(value);
\r
401 int getKeyboardNo(StringBuffer kb)
\r
406 return Integer.parseInt(kb.toString());
\r
413 * @param evt DOCUMENT ME!
\r
415 public void mouseReleased(MouseEvent evt)
\r
417 mouseDragging = false;
\r
418 mouseWheelPressed = false;
\r
422 doMouseReleasedDefineMode(evt);
\r
436 * @param evt DOCUMENT ME!
\r
438 public void mousePressed(MouseEvent evt)
\r
440 lastMousePress = evt.getPoint();
\r
442 if (javax.swing.SwingUtilities.isMiddleMouseButton(evt))
\r
444 mouseWheelPressed = true;
\r
448 if (evt.isShiftDown() || evt.isAltDown() ||
\r
449 evt.isControlDown())
\r
451 if (evt.isAltDown() || evt.isControlDown())
\r
453 groupEditing = true;
\r
455 editingSeqs = true;
\r
459 doMousePressedDefineMode(evt);
\r
465 int seq = findSeq(evt);
\r
466 int res = findRes(evt);
\r
471 ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence",
\r
472 av.alignment, HistoryItem.EDIT));
\r
474 if ((seq < av.getAlignment().getHeight()) &&
\r
475 (res < av.getAlignment().getSequenceAt(seq).getLength()))
\r
492 * @param evt DOCUMENT ME!
\r
494 public void mouseMoved(MouseEvent evt)
\r
498 // This is because MacOSX creates a mouseMoved
\r
499 // If control is down, other platforms will not.
\r
503 int res = findRes(evt);
\r
504 int seq = findSeq(evt);
\r
507 if(res<0 || seq<0 || seq >= av.getAlignment().getHeight())
\r
510 SequenceI sequence = av.getAlignment().getSequenceAt(seq);
\r
512 if (res > sequence.getLength())
\r
517 if(seqCanvas.pdbCanvas!=null && sequence==seqCanvas.pdbCanvas.sequence)
\r
519 seqCanvas.pdbCanvas.highlightRes(sequence.findPosition(res));
\r
522 setStatusMessage(sequence, res, seq);
\r
524 // use aa to see if the mouse pointer is on a
\r
525 if (av.showSequenceFeatures)
\r
527 SequenceFeature [] features = sequence.getDatasetSequence().getSequenceFeatures();
\r
530 StringBuffer sbuffer = new StringBuffer("<html>");
\r
531 StringBuffer seqSpecific = new StringBuffer();
\r
533 for (int i = 0; i < features.length; i++)
\r
536 if ( (features[i].getBegin() <= sequence.findPosition(res)) &&
\r
537 (features[i].getEnd() >= sequence.findPosition(res)))
\r
539 if(av.featuresDisplayed==null
\r
540 || !av.featuresDisplayed.containsKey(features[i].getType()))
\r
544 if (features[i].getType().equals("disulfide bond"))
\r
546 if (features[i].getBegin() == sequence.findPosition(res)
\r
547 || features[i].getEnd() == sequence.findPosition(res))
\r
549 if (sbuffer.length() > 6)
\r
550 sbuffer.append("<br>");
\r
551 sbuffer.append("disulfide bond " + features[i].getBegin() + ":" +
\r
552 features[i].getEnd());
\r
553 if (features[i].links != null)
\r
554 sbuffer.append(" <img src=\"" + linkImageURL + "\">");
\r
559 if (sbuffer.length() > 6)
\r
560 sbuffer.append("<br>");
\r
562 sbuffer.append(features[i].getType() + " " +
\r
563 features[i].begin);
\r
564 if (features[i].begin != features[i].end)
\r
565 sbuffer.append(" " + features[i].end);
\r
567 if (features[i].getDescription() != null
\r
568 && !features[i].description.equals(features[i].getType()))
\r
569 sbuffer.append("; " + features[i].getDescription());
\r
571 if (features[i].getValue("status") != null)
\r
573 sbuffer.append("; (" + features[i].getValue("status") + ")");
\r
575 if (features[i].links != null)
\r
576 sbuffer.append(" <img src=\"" + linkImageURL + "\">");
\r
580 else if(features[i].begin==0 && features[i].end==0)
\r
582 // seqSpecific.append(features[i].featureGroup+": "
\r
583 // + features[i].getType()+" "
\r
584 // +features[i].getDescription()+"<br>");
\r
589 if(seqSpecific.length()>0)
\r
590 seqSpecific.setLength(seqSpecific.length()-4);
\r
592 sbuffer.append(seqSpecific);
\r
593 sbuffer.append("</html>");
\r
594 if(sbuffer.length()==13) // <html></html>
\r
595 setToolTipText("");
\r
597 setToolTipText(sbuffer.toString());
\r
600 setToolTipText("");
\r
604 void setStatusMessage(SequenceI sequence, int res, int seq)
\r
606 StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " +
\r
607 sequence.getName());
\r
610 if (av.alignment.isNucleotide())
\r
612 obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) +
\r
615 text.append(" Nucleotide: ");
\r
619 obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");
\r
621 text.append(" Residue: ");
\r
629 text.append(obj + " (" + sequence.findPosition(res) +
\r
633 ap.alignFrame.statusBar.setText(text.toString());
\r
640 * @param evt DOCUMENT ME!
\r
642 public void mouseDragged(MouseEvent evt)
\r
644 if (mouseWheelPressed)
\r
646 int oldWidth = av.charWidth;
\r
648 //Which is bigger, left-right or up-down?
\r
649 if (Math.abs(evt.getY() - lastMousePress.getY())
\r
650 > Math.abs(evt.getX() - lastMousePress.getX()))
\r
652 int fontSize = av.font.getSize();
\r
654 if (evt.getY() < lastMousePress.getY())
\r
658 else if (evt.getY() > lastMousePress.getY())
\r
666 av.setFont(new Font(av.font.getName(), av.font.getStyle(), fontSize));
\r
667 av.charWidth = oldWidth;
\r
672 if (evt.getX() < lastMousePress.getX() && av.charWidth > 1)
\r
676 else if (evt.getX() > lastMousePress.getX())
\r
684 FontMetrics fm = getFontMetrics(av.getFont());
\r
685 av.validCharWidth = fm.charWidth('M') <= av.charWidth;
\r
687 lastMousePress = evt.getPoint();
\r
694 doMouseDraggedDefineMode(evt);
\r
698 int res = findRes(evt);
\r
705 if ((lastres == -1) || (lastres == res))
\r
710 if ( (res < av.getAlignment().getWidth()) && (res < lastres))
\r
712 // dragLeft, delete gap
\r
713 editSequence(false, res);
\r
716 editSequence(true, res);
\r
718 mouseDragging = true;
\r
719 if(scrollThread!=null)
\r
720 scrollThread.setEvent(evt);
\r
724 synchronized void editSequence(boolean insertGap, int startres)
\r
726 int fixedLeft = -1;
\r
727 int fixedRight = -1;
\r
728 boolean fixedColumns = false;
\r
729 SequenceGroup sg = av.getSelectionGroup();
\r
732 if (!groupEditing && av.hasHiddenRows)
\r
734 if (av.alignment.getSequenceAt(startseq).getHiddenSequences() != null)
\r
736 groupEditing = true;
\r
740 //No group, but the sequence may represent a group
\r
743 && av.alignment.getSequenceAt(startseq).getHiddenSequences() == null)
\r
745 groupEditing = false;
\r
748 SequenceI seq = av.alignment.getSequenceAt(startseq);
\r
749 StringBuffer message = new StringBuffer();
\r
751 message.append("Edit group:");
\r
753 message.append("Edit sequence: "+seq.getName());
\r
756 message.append(" insert ");
\r
758 message.append(" delete ");
\r
760 message.append(Math.abs(startres-lastres)+" gaps.");
\r
761 ap.alignFrame.statusBar.setText(message.toString());
\r
764 //Are we editing within a selection group?
\r
766 || (sg != null && sg.getSequences(true).contains(seq)))
\r
768 fixedColumns = true;
\r
770 //sg might be null as the user may only see 1 sequence,
\r
771 //but the sequence represents a group
\r
774 sg = new SequenceGroup(null, null, false, false, false, 0,
\r
775 av.alignment.getWidth()-1);
\r
776 sg.addSequence(av.alignment.getSequenceAt(startseq), false);
\r
779 fixedLeft = sg.getStartRes();
\r
780 fixedRight = sg.getEndRes();
\r
782 if ( (startres < fixedLeft && lastres >= fixedLeft)
\r
783 || (startres >= fixedLeft && lastres < fixedLeft)
\r
784 || (startres > fixedRight && lastres <=fixedRight)
\r
785 || (startres <= fixedRight && lastres > fixedRight))
\r
791 if (fixedLeft > startres)
\r
793 fixedRight = fixedLeft - 1;
\r
796 else if (fixedRight < startres)
\r
798 fixedLeft = fixedRight;
\r
804 if(av.hasHiddenColumns )
\r
806 fixedColumns = true;
\r
807 int y1 = av.getColumnSelection().getHiddenBoundaryLeft(startres);
\r
808 int y2 = av.getColumnSelection().getHiddenBoundaryRight(startres);
\r
810 if ( (insertGap && startres > y1 && lastres < y1)
\r
811 || (!insertGap && startres < y2 && lastres > y2))
\r
817 //System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");
\r
818 //Selection spans a hidden region
\r
819 if(fixedLeft<y1 && (fixedRight>y2 || fixedRight==-1))
\r
827 fixedRight = y2 - 1;
\r
838 //If the user has selected the whole sequence, and is dragging to
\r
839 // the right, we can still extend the alignment and selectionGroup
\r
840 if( sg.getStartRes() == 0
\r
841 && sg.getEndRes() == fixedRight
\r
842 && sg.getEndRes() == av.alignment.getWidth()-1
\r
845 sg.setEndRes(av.alignment.getWidth() + startres - lastres);
\r
846 fixedRight = sg.getEndRes();
\r
849 // Is it valid with fixed columns??
\r
850 // Find the next gap before the end
\r
851 // of the visible region boundary
\r
852 boolean blank = false;
\r
853 for (fixedRight = fixedRight;
\r
854 fixedRight > lastres;
\r
858 for (int s = 0; s < sg.getSize(true); s++)
\r
860 seq = (SequenceI)sg.getSequences(true).elementAt(s);
\r
861 for (int j = 0; j < startres - lastres; j++)
\r
863 if (!jalview.util.Comparison.isGap(
\r
864 seq.getCharAt(fixedRight - j)))
\r
877 if(sg.getSize(false) == av.alignment.getHeight() )
\r
879 if((av.hasHiddenColumns
\r
880 && startres<av.getColumnSelection().getHiddenBoundaryRight(startres)))
\r
886 int alWidth = av.alignment.getWidth();
\r
887 if(av.hasHiddenRows)
\r
889 int hwidth = av.alignment.getHiddenSequences().getWidth();
\r
893 //We can still insert gaps if the selectionGroup
\r
894 //contains all the sequences
\r
895 sg.setEndRes(sg.getEndRes()+startres-lastres);
\r
896 fixedRight = alWidth+startres-lastres;
\r
908 else if(!insertGap)
\r
910 /// Are we able to delete?
\r
911 // ie are all columns blank?
\r
913 for (int s = 0; s < sg.getSize(true); s++)
\r
915 seq = (SequenceI)sg.getSequences(true).elementAt(s);
\r
917 for (int j = startres; j < lastres; j++)
\r
919 if (seq.getSequence().length() <= j)
\r
924 if (!jalview.util.Comparison.isGap(
\r
925 seq.getSequence().charAt(j)))
\r
927 // Not a gap, block edit not valid
\r
936 for (int i = 0; i < sg.getSize(true); i++)
\r
938 seq = (SequenceI) sg.getSequences(true).elementAt(i);
\r
942 // dragging to the right
\r
943 for (int j = lastres; j < startres; j++)
\r
945 if (fixedColumns && fixedRight != -1)
\r
947 insertChar(j, seq, fixedRight);
\r
950 insertChar(j, seq);
\r
955 // dragging to the left
\r
956 for (int j = lastres; j > startres; j--)
\r
958 if (fixedColumns && fixedRight != -1)
\r
960 deleteChar(startres, seq, fixedRight);
\r
964 deleteChar(startres, seq);
\r
970 else /////Editing a single sequence///////////
\r
974 // dragging to the right
\r
975 for (int j = lastres; j < startres; j++)
\r
977 if (fixedColumns && fixedRight != -1)
\r
979 insertChar(j, seq, fixedRight);
\r
982 insertChar(j, seq);
\r
987 // dragging to the left
\r
988 for (int j = lastres; j > startres; j--)
\r
990 if (fixedColumns && fixedRight != -1)
\r
992 deleteChar(startres, seq, fixedRight);
\r
996 deleteChar(startres, seq);
\r
1002 lastres = startres;
\r
1003 seqCanvas.repaint();
\r
1010 * @param j DOCUMENT ME!
\r
1011 * @param seq DOCUMENT ME!
\r
1013 void insertChar(int j, SequenceI seq)
\r
1015 seq.insertCharAt(j, av.getGapCharacter());
\r
1016 seqEditOccurred = true;
\r
1019 void insertChar(int j, SequenceI seq, int fixedColumn)
\r
1021 //Find the next gap before the end of the visible region boundary
\r
1022 //If lastCol > j, theres a boundary after the gap insertion
\r
1023 int blankColumn = fixedColumn;
\r
1024 for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
\r
1026 if (jalview.util.Comparison.isGap(seq.getCharAt(blankColumn)))
\r
1028 //Theres a space, so break and insert the gap
\r
1033 if (blankColumn <= j)
\r
1035 System.out.println("END HERE "+seq.getName()+" "+seq.getLength()+" "+j+" "
\r
1036 +blankColumn+" "+fixedColumn);
\r
1037 blankColumn = fixedColumn;
\r
1042 if (!jalview.util.Comparison.isGap(seq.getCharAt(blankColumn)))
\r
1045 System.out.println("Tried removing residue (INSERT)"+seq.getCharAt(fixedColumn));
\r
1049 seq.deleteCharAt(blankColumn);
\r
1050 seq.insertCharAt(j, av.getGapCharacter());
\r
1051 seqEditOccurred = true;
\r
1054 void deleteChar(int j, SequenceI seq, int fixedColumn)
\r
1056 if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))
\r
1058 ap.alignFrame.statusBar.setText(
\r
1059 "End editing: Tried removing residue " + seq.getCharAt(j));
\r
1063 seq.deleteCharAt(j);
\r
1064 seq.insertCharAt(fixedColumn, av.getGapCharacter());
\r
1065 seqEditOccurred = true;
\r
1071 * @param j DOCUMENT ME!
\r
1072 * @param seq DOCUMENT ME!
\r
1074 void deleteChar(int j, SequenceI seq)
\r
1076 if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))
\r
1078 ap.alignFrame.statusBar.setText(
\r
1079 "End editing: Tried removing residue " + seq.getCharAt(j));
\r
1083 seq.deleteCharAt(j);
\r
1084 seqEditOccurred = true;
\r
1085 seqCanvas.repaint();
\r
1090 * @param e DOCUMENT ME!
\r
1092 public void mouseEntered(MouseEvent e)
\r
1097 if (scrollThread != null)
\r
1099 scrollThread.running = false;
\r
1100 scrollThread = null;
\r
1107 * @param e DOCUMENT ME!
\r
1109 public void mouseExited(MouseEvent e)
\r
1111 if (av.getWrapAlignment())
\r
1116 if (mouseDragging)
\r
1118 scrollThread = new ScrollThread();
\r
1122 public void mouseClicked(MouseEvent evt)
\r
1125 public void mouseWheelMoved(MouseWheelEvent e)
\r
1128 /* if (mouseWheelPressed)
\r
1130 Font font = av.getFont();
\r
1131 int fontSize = font.getSize();
\r
1132 if (e.getWheelRotation() > 0 && fontSize < 51)
\r
1134 else if (fontSize > 1)
\r
1139 av.setFont(new Font(font.getName(), font.getStyle(), fontSize));
\r
1145 if (e.getWheelRotation() > 0)
\r
1146 ap.scrollUp(false);
\r
1148 ap.scrollUp(true);
\r
1158 * @param i DOCUMENT ME!
\r
1160 void editOccurred()
\r
1162 if (!seqEditOccurred)
\r
1164 ap.alignFrame.historyList.pop();
\r
1165 ap.alignFrame.updateEditMenuBar();
\r
1170 av.firePropertyChange("alignment", null,av.getAlignment().getSequences());
\r
1177 * @param evt DOCUMENT ME!
\r
1179 public void doMousePressedDefineMode(MouseEvent evt)
\r
1181 int res = findRes(evt);
\r
1182 int seq = findSeq(evt);
\r
1185 startWrapBlock=wrappedBlock;
\r
1187 if(av.wrapAlignment && seq>av.alignment.getHeight())
\r
1189 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
1190 "Cannot edit annotations in wrapped view.",
\r
1191 "Wrapped view - no edit",
\r
1192 JOptionPane.WARNING_MESSAGE);
\r
1196 if(seq<0 || res<0)
\r
1199 SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq);
\r
1201 if ((sequence == null) || (res > sequence.getLength()))
\r
1206 stretchGroup = av.getSelectionGroup();
\r
1208 if (stretchGroup == null)
\r
1210 stretchGroup = av.alignment.findGroup(sequence);
\r
1212 if ((stretchGroup != null) && (res > stretchGroup.getStartRes()) &&
\r
1213 (res < stretchGroup.getEndRes()))
\r
1215 av.setSelectionGroup(stretchGroup);
\r
1219 stretchGroup = null;
\r
1222 else if (!stretchGroup.getSequences(false).contains(sequence) ||
\r
1223 (stretchGroup.getStartRes() > res) ||
\r
1224 (stretchGroup.getEndRes() < res))
\r
1226 stretchGroup = null;
\r
1228 SequenceGroup[] allGroups = av.alignment.findAllGroups(sequence);
\r
1230 if (allGroups != null)
\r
1232 for (int i = 0; i < allGroups.length; i++)
\r
1234 if ((allGroups[i].getStartRes() <= res) &&
\r
1235 (allGroups[i].getEndRes() >= res))
\r
1237 stretchGroup = allGroups[i];
\r
1243 av.setSelectionGroup(stretchGroup);
\r
1247 if (av.cursorMode)
\r
1249 seqCanvas.cursorX = findRes(evt);
\r
1250 seqCanvas.cursorY = findSeq(evt);
\r
1251 seqCanvas.repaint();
\r
1256 if (javax.swing.SwingUtilities.isRightMouseButton(evt))
\r
1258 Vector allFeatures = getAllFeaturesAtRes(sequence.getDatasetSequence(),
\r
1259 sequence.findPosition(res));
\r
1260 Vector links = new Vector();
\r
1261 for (int i = 0; i < allFeatures.size(); i++)
\r
1263 SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(i);
\r
1264 if (sf.links != null)
\r
1266 for (int j = 0; j < sf.links.size(); j++)
\r
1268 links.addElement(sf.links.elementAt(j));
\r
1273 jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(ap, null, links);
\r
1274 pop.show(this, evt.getX(), evt.getY());
\r
1277 else if (stretchGroup == null)
\r
1279 //Only if left mouse button do we want to change group sizes
\r
1281 // define a new group here
\r
1282 SequenceGroup sg = new SequenceGroup();
\r
1283 sg.setStartRes(res);
\r
1284 sg.setEndRes(res);
\r
1285 sg.addSequence(sequence, false);
\r
1286 av.setSelectionGroup(sg);
\r
1287 stretchGroup = sg;
\r
1289 if (av.getConservationSelected())
\r
1291 SliderPanel.setConservationSlider(ap,
\r
1292 av.getGlobalColourScheme(),
\r
1296 if (av.getAbovePIDThreshold())
\r
1298 SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(),
\r
1301 if ( (stretchGroup != null) && (stretchGroup.getEndRes() == res))
\r
1303 // Edit end res position of selected group
\r
1304 changeEndRes = true;
\r
1306 else if ( (stretchGroup != null) &&
\r
1307 (stretchGroup.getStartRes() == res))
\r
1309 // Edit end res position of selected group
\r
1310 changeStartRes = true;
\r
1312 stretchGroup.getWidth();
\r
1315 seqCanvas.repaint();
\r
1321 * @param evt DOCUMENT ME!
\r
1323 public void doMouseReleasedDefineMode(MouseEvent evt)
\r
1325 if (stretchGroup == null)
\r
1331 if(stretchGroup.cs!=null)
\r
1333 if (stretchGroup.cs instanceof ClustalxColourScheme)
\r
1335 ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX(
\r
1336 stretchGroup.getSequences(true),
\r
1337 stretchGroup.getWidth());
\r
1340 if (stretchGroup.cs.conservationApplied())
\r
1342 SliderPanel.setConservationSlider(ap, stretchGroup.cs,
\r
1343 stretchGroup.getName());
\r
1344 stretchGroup.recalcConservation();
\r
1348 SliderPanel.setPIDSliderSource(ap, stretchGroup.cs,
\r
1349 stretchGroup.getName());
\r
1352 changeEndRes = false;
\r
1353 changeStartRes = false;
\r
1354 stretchGroup = null;
\r
1355 PaintRefresher.Refresh(av.alignment);
\r
1361 * @param evt DOCUMENT ME!
\r
1363 public void doMouseDraggedDefineMode(MouseEvent evt)
\r
1365 int res = findRes(evt);
\r
1366 int y = findSeq(evt);
\r
1368 if(wrappedBlock!=startWrapBlock)
\r
1371 if (stretchGroup == null)
\r
1377 if(y > av.alignment.getHeight())
\r
1379 y = av.alignment.getHeight() -1;
\r
1381 if(res> av.alignment.getWidth())
\r
1383 res = av.alignment.getWidth()-1;
\r
1386 if (stretchGroup.getEndRes() == res)
\r
1388 // Edit end res position of selected group
\r
1389 changeEndRes = true;
\r
1391 else if (stretchGroup.getStartRes() == res)
\r
1393 // Edit start res position of selected group
\r
1394 changeStartRes = true;
\r
1397 if (res < av.getStartRes())
\r
1399 res = av.getStartRes();
\r
1404 if (res > (stretchGroup.getStartRes() - 1))
\r
1406 stretchGroup.setEndRes(res);
\r
1409 else if (changeStartRes)
\r
1411 if (res < (stretchGroup.getEndRes() + 1))
\r
1413 stretchGroup.setStartRes(res);
\r
1417 int dragDirection = 0;
\r
1421 dragDirection = 1;
\r
1423 else if (y < oldSeq)
\r
1425 dragDirection = -1;
\r
1429 while ((y != oldSeq) && (oldSeq > -1) && (y < av.alignment.getHeight()))
\r
1431 // This routine ensures we don't skip any sequences, as the
\r
1432 // selection is quite slow.
\r
1433 Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
\r
1435 oldSeq += dragDirection;
\r
1440 Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
\r
1442 if (stretchGroup.getSequences(false).contains(nextSeq))
\r
1444 stretchGroup.deleteSequence(seq, false);
\r
1450 stretchGroup.addSequence(seq, false);
\r
1453 stretchGroup.addSequence(nextSeq, false);
\r
1460 mouseDragging = true;
\r
1462 if (scrollThread != null)
\r
1464 scrollThread.setEvent(evt);
\r
1467 seqCanvas.repaint();
\r
1470 void scrollCanvas(MouseEvent evt)
\r
1474 if(scrollThread!=null)
\r
1476 scrollThread.running = false;
\r
1477 scrollThread = null;
\r
1479 mouseDragging = false;
\r
1483 if (scrollThread == null)
\r
1484 scrollThread = new ScrollThread();
\r
1486 mouseDragging = true;
\r
1487 scrollThread.setEvent(evt);
\r
1493 // this class allows scrolling off the bottom of the visible alignment
\r
1494 class ScrollThread extends Thread
\r
1497 boolean running = false;
\r
1499 public ScrollThread()
\r
1504 public void setEvent(MouseEvent e)
\r
1509 public void stopScrolling()
\r
1522 if (mouseDragging && (evt.getY() < 0) &&
\r
1523 (av.getStartSeq() > 0))
\r
1525 running = ap.scrollUp(true);
\r
1528 if (mouseDragging && (evt.getY() >= getHeight()) &&
\r
1529 (av.alignment.getHeight() > av.getEndSeq()))
\r
1531 running = ap.scrollUp(false);
\r
1534 if (mouseDragging && (evt.getX() < 0))
\r
1536 running = ap.scrollRight(false);
\r
1538 else if (mouseDragging && (evt.getX() >= getWidth()))
\r
1540 running = ap.scrollRight(true);
\r
1548 catch (Exception ex)
\r