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 //We can still insert gaps if the selectionGroup
\r
887 //contains all the sequences
\r
888 sg.setEndRes(sg.getEndRes()+startres-lastres);
\r
889 fixedRight = av.alignment.getWidth()+startres-lastres;
\r
901 else if(!insertGap)
\r
903 /// Are we able to delete?
\r
904 // ie are all columns blank?
\r
906 for (int s = 0; s < sg.getSize(true); s++)
\r
908 seq = (SequenceI)sg.getSequences(true).elementAt(s);
\r
910 for (int j = startres; j < lastres; j++)
\r
912 if (seq.getSequence().length() <= j)
\r
917 if (!jalview.util.Comparison.isGap(
\r
918 seq.getSequence().charAt(j)))
\r
920 // Not a gap, block edit not valid
\r
929 for (int i = 0; i < sg.getSize(true); i++)
\r
931 seq = (SequenceI) sg.getSequences(true).elementAt(i);
\r
935 // dragging to the right
\r
936 for (int j = lastres; j < startres; j++)
\r
938 if (fixedColumns && fixedRight != -1)
\r
940 insertChar(j, seq, fixedRight);
\r
943 insertChar(j, seq);
\r
948 // dragging to the left
\r
949 for (int j = lastres; j > startres; j--)
\r
951 if (fixedColumns && fixedRight != -1)
\r
953 deleteChar(startres, seq, fixedRight);
\r
957 deleteChar(startres, seq);
\r
963 else /////Editing a single sequence///////////
\r
967 // dragging to the right
\r
968 for (int j = lastres; j < startres; j++)
\r
970 if (fixedColumns && fixedRight != -1)
\r
973 sg.getStartRes() == 0
\r
974 && sg.getEndRes() == fixedRight
\r
975 && !jalview.util.Comparison.isGap(seq.getCharAt(fixedRight)))
\r
977 System.out.println("still here");
\r
978 //Single sequence edit, whole sequence selected,
\r
979 //extend the selection group
\r
980 sg.setEndRes(av.alignment.getWidth() -1 + startres - lastres);
\r
981 fixedColumns = false;
\r
982 insertChar(j, seq);
\r
985 insertChar(j, seq, fixedRight);
\r
988 insertChar(j, seq);
\r
993 // dragging to the left
\r
994 for (int j = lastres; j > startres; j--)
\r
996 if (fixedColumns && fixedRight != -1)
\r
998 deleteChar(startres, seq, fixedRight);
\r
1002 deleteChar(startres, seq);
\r
1008 lastres = startres;
\r
1009 seqCanvas.repaint();
\r
1016 * @param j DOCUMENT ME!
\r
1017 * @param seq DOCUMENT ME!
\r
1019 void insertChar(int j, SequenceI seq)
\r
1021 seq.insertCharAt(j, av.getGapCharacter());
\r
1022 seqEditOccurred = true;
\r
1025 void insertChar(int j, SequenceI seq, int fixedColumn)
\r
1027 //Find the next gap before the end of the visible region boundary
\r
1028 //If lastCol > j, theres a boundary after the gap insertion
\r
1029 int blankColumn = fixedColumn;
\r
1030 for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)
\r
1032 if (jalview.util.Comparison.isGap(seq.getCharAt(blankColumn)))
\r
1034 //Theres a space, so break and insert the gap
\r
1039 if (blankColumn <= j)
\r
1045 if (!jalview.util.Comparison.isGap(seq.getCharAt(blankColumn)))
\r
1048 System.out.println("Tried removing residue (INSERT)"+seq.getCharAt(fixedColumn));
\r
1052 seq.deleteCharAt(blankColumn);
\r
1053 seq.insertCharAt(j, av.getGapCharacter());
\r
1054 seqEditOccurred = true;
\r
1057 void deleteChar(int j, SequenceI seq, int fixedColumn)
\r
1059 if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))
\r
1061 ap.alignFrame.statusBar.setText(
\r
1062 "End editing: Tried removing residue " + seq.getCharAt(j));
\r
1066 seq.deleteCharAt(j);
\r
1067 seq.insertCharAt(fixedColumn, av.getGapCharacter());
\r
1068 seqEditOccurred = true;
\r
1074 * @param j DOCUMENT ME!
\r
1075 * @param seq DOCUMENT ME!
\r
1077 void deleteChar(int j, SequenceI seq)
\r
1079 if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))
\r
1081 ap.alignFrame.statusBar.setText(
\r
1082 "End editing: Tried removing residue " + seq.getCharAt(j));
\r
1086 seq.deleteCharAt(j);
\r
1087 seqEditOccurred = true;
\r
1088 seqCanvas.repaint();
\r
1093 * @param e DOCUMENT ME!
\r
1095 public void mouseEntered(MouseEvent e)
\r
1100 if (scrollThread != null)
\r
1102 scrollThread.running = false;
\r
1103 scrollThread = null;
\r
1110 * @param e DOCUMENT ME!
\r
1112 public void mouseExited(MouseEvent e)
\r
1114 if (av.getWrapAlignment())
\r
1119 if (mouseDragging)
\r
1121 scrollThread = new ScrollThread();
\r
1125 public void mouseClicked(MouseEvent evt)
\r
1128 public void mouseWheelMoved(MouseWheelEvent e)
\r
1131 /* if (mouseWheelPressed)
\r
1133 Font font = av.getFont();
\r
1134 int fontSize = font.getSize();
\r
1135 if (e.getWheelRotation() > 0 && fontSize < 51)
\r
1137 else if (fontSize > 1)
\r
1142 av.setFont(new Font(font.getName(), font.getStyle(), fontSize));
\r
1148 if (e.getWheelRotation() > 0)
\r
1149 ap.scrollUp(false);
\r
1151 ap.scrollUp(true);
\r
1161 * @param i DOCUMENT ME!
\r
1163 void editOccurred()
\r
1165 if (!seqEditOccurred)
\r
1167 ap.alignFrame.historyList.pop();
\r
1168 ap.alignFrame.updateEditMenuBar();
\r
1173 av.firePropertyChange("alignment", null,av.getAlignment().getSequences());
\r
1180 * @param evt DOCUMENT ME!
\r
1182 public void doMousePressedDefineMode(MouseEvent evt)
\r
1184 int res = findRes(evt);
\r
1185 int seq = findSeq(evt);
\r
1188 startWrapBlock=wrappedBlock;
\r
1190 if(av.wrapAlignment && seq>av.alignment.getHeight())
\r
1192 JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
1193 "Cannot edit annotations in wrapped view.",
\r
1194 "Wrapped view - no edit",
\r
1195 JOptionPane.WARNING_MESSAGE);
\r
1199 if(seq<0 || res<0)
\r
1202 SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq);
\r
1204 if ((sequence == null) || (res > sequence.getLength()))
\r
1209 stretchGroup = av.getSelectionGroup();
\r
1211 if (stretchGroup == null)
\r
1213 stretchGroup = av.alignment.findGroup(sequence);
\r
1215 if ((stretchGroup != null) && (res > stretchGroup.getStartRes()) &&
\r
1216 (res < stretchGroup.getEndRes()))
\r
1218 av.setSelectionGroup(stretchGroup);
\r
1222 stretchGroup = null;
\r
1225 else if (!stretchGroup.getSequences(false).contains(sequence) ||
\r
1226 (stretchGroup.getStartRes() > res) ||
\r
1227 (stretchGroup.getEndRes() < res))
\r
1229 stretchGroup = null;
\r
1231 SequenceGroup[] allGroups = av.alignment.findAllGroups(sequence);
\r
1233 if (allGroups != null)
\r
1235 for (int i = 0; i < allGroups.length; i++)
\r
1237 if ((allGroups[i].getStartRes() <= res) &&
\r
1238 (allGroups[i].getEndRes() >= res))
\r
1240 stretchGroup = allGroups[i];
\r
1246 av.setSelectionGroup(stretchGroup);
\r
1250 if (av.cursorMode)
\r
1252 seqCanvas.cursorX = findRes(evt);
\r
1253 seqCanvas.cursorY = findSeq(evt);
\r
1254 seqCanvas.repaint();
\r
1259 if (javax.swing.SwingUtilities.isRightMouseButton(evt))
\r
1261 Vector allFeatures = getAllFeaturesAtRes(sequence.getDatasetSequence(),
\r
1262 sequence.findPosition(res));
\r
1263 Vector links = new Vector();
\r
1264 for (int i = 0; i < allFeatures.size(); i++)
\r
1266 SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(i);
\r
1267 if (sf.links != null)
\r
1269 for (int j = 0; j < sf.links.size(); j++)
\r
1271 links.addElement(sf.links.elementAt(j));
\r
1276 jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(ap, null, links);
\r
1277 pop.show(this, evt.getX(), evt.getY());
\r
1280 else if (stretchGroup == null)
\r
1282 //Only if left mouse button do we want to change group sizes
\r
1284 // define a new group here
\r
1285 SequenceGroup sg = new SequenceGroup();
\r
1286 sg.setStartRes(res);
\r
1287 sg.setEndRes(res);
\r
1288 sg.addSequence(sequence, false);
\r
1289 av.setSelectionGroup(sg);
\r
1290 stretchGroup = sg;
\r
1292 if (av.getConservationSelected())
\r
1294 SliderPanel.setConservationSlider(ap,
\r
1295 av.getGlobalColourScheme(),
\r
1299 if (av.getAbovePIDThreshold())
\r
1301 SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(),
\r
1304 if ( (stretchGroup != null) && (stretchGroup.getEndRes() == res))
\r
1306 // Edit end res position of selected group
\r
1307 changeEndRes = true;
\r
1309 else if ( (stretchGroup != null) &&
\r
1310 (stretchGroup.getStartRes() == res))
\r
1312 // Edit end res position of selected group
\r
1313 changeStartRes = true;
\r
1315 stretchGroup.getWidth();
\r
1318 seqCanvas.repaint();
\r
1324 * @param evt DOCUMENT ME!
\r
1326 public void doMouseReleasedDefineMode(MouseEvent evt)
\r
1328 if (stretchGroup == null)
\r
1334 if(stretchGroup.cs!=null)
\r
1336 if (stretchGroup.cs instanceof ClustalxColourScheme)
\r
1338 ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX(
\r
1339 stretchGroup.getSequences(true),
\r
1340 stretchGroup.getWidth());
\r
1343 if (stretchGroup.cs.conservationApplied())
\r
1345 SliderPanel.setConservationSlider(ap, stretchGroup.cs,
\r
1346 stretchGroup.getName());
\r
1347 stretchGroup.recalcConservation();
\r
1351 SliderPanel.setPIDSliderSource(ap, stretchGroup.cs,
\r
1352 stretchGroup.getName());
\r
1355 changeEndRes = false;
\r
1356 changeStartRes = false;
\r
1357 stretchGroup = null;
\r
1358 PaintRefresher.Refresh(av.alignment);
\r
1364 * @param evt DOCUMENT ME!
\r
1366 public void doMouseDraggedDefineMode(MouseEvent evt)
\r
1368 int res = findRes(evt);
\r
1369 int y = findSeq(evt);
\r
1371 if(wrappedBlock!=startWrapBlock)
\r
1374 if (stretchGroup == null)
\r
1380 if(y > av.alignment.getHeight())
\r
1382 y = av.alignment.getHeight() -1;
\r
1384 if(res> av.alignment.getWidth())
\r
1386 res = av.alignment.getWidth()-1;
\r
1389 if (stretchGroup.getEndRes() == res)
\r
1391 // Edit end res position of selected group
\r
1392 changeEndRes = true;
\r
1394 else if (stretchGroup.getStartRes() == res)
\r
1396 // Edit start res position of selected group
\r
1397 changeStartRes = true;
\r
1400 if (res < av.getStartRes())
\r
1402 res = av.getStartRes();
\r
1407 if (res > (stretchGroup.getStartRes() - 1))
\r
1409 stretchGroup.setEndRes(res);
\r
1412 else if (changeStartRes)
\r
1414 if (res < (stretchGroup.getEndRes() + 1))
\r
1416 stretchGroup.setStartRes(res);
\r
1420 int dragDirection = 0;
\r
1424 dragDirection = 1;
\r
1426 else if (y < oldSeq)
\r
1428 dragDirection = -1;
\r
1432 while ((y != oldSeq) && (oldSeq > -1) && (y < av.alignment.getHeight()))
\r
1434 // This routine ensures we don't skip any sequences, as the
\r
1435 // selection is quite slow.
\r
1436 Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
\r
1438 oldSeq += dragDirection;
\r
1443 Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);
\r
1445 if (stretchGroup.getSequences(false).contains(nextSeq))
\r
1447 stretchGroup.deleteSequence(seq, false);
\r
1453 stretchGroup.addSequence(seq, false);
\r
1456 stretchGroup.addSequence(nextSeq, false);
\r
1463 mouseDragging = true;
\r
1465 if (scrollThread != null)
\r
1467 scrollThread.setEvent(evt);
\r
1470 seqCanvas.repaint();
\r
1473 void scrollCanvas(MouseEvent evt)
\r
1477 if(scrollThread!=null)
\r
1479 scrollThread.running = false;
\r
1480 scrollThread = null;
\r
1482 mouseDragging = false;
\r
1486 if (scrollThread == null)
\r
1487 scrollThread = new ScrollThread();
\r
1489 mouseDragging = true;
\r
1490 scrollThread.setEvent(evt);
\r
1496 // this class allows scrolling off the bottom of the visible alignment
\r
1497 class ScrollThread extends Thread
\r
1500 boolean running = false;
\r
1502 public ScrollThread()
\r
1507 public void setEvent(MouseEvent e)
\r
1512 public void stopScrolling()
\r
1525 if (mouseDragging && (evt.getY() < 0) &&
\r
1526 (av.getStartSeq() > 0))
\r
1528 running = ap.scrollUp(true);
\r
1531 if (mouseDragging && (evt.getY() >= getHeight()) &&
\r
1532 (av.alignment.getHeight() > av.getEndSeq()))
\r
1534 running = ap.scrollUp(false);
\r
1537 if (mouseDragging && (evt.getX() < 0))
\r
1539 running = ap.scrollRight(false);
\r
1541 else if (mouseDragging && (evt.getX() >= getWidth()))
\r
1543 running = ap.scrollRight(true);
\r
1551 catch (Exception ex)
\r