/*\r
* Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
*\r
* This program is free software; you can redistribute it and/or\r
* modify it under the terms of the GNU General Public License\r
*/\r
package jalview.gui;\r
\r
-import jalview.datamodel.*;\r
-\r
-import jalview.schemes.*;\r
+import java.util.*;\r
\r
import java.awt.*;\r
import java.awt.event.*;\r
-\r
import javax.swing.*;\r
\r
-import java.util.Vector;\r
-\r
+import jalview.commands.*;\r
+import jalview.datamodel.*;\r
+import jalview.schemes.*;\r
+import jalview.structure.*;\r
\r
/**\r
* DOCUMENT ME!\r
* @author $author$\r
* @version $Revision$\r
*/\r
-public class SeqPanel extends JPanel implements MouseListener,\r
- MouseMotionListener, MouseWheelListener\r
+public class SeqPanel\r
+ extends JPanel implements MouseListener,\r
+ MouseMotionListener, MouseWheelListener, SequenceListener\r
\r
{\r
- /** DOCUMENT ME!! */\r
- public SeqCanvas seqCanvas;\r
-\r
- /** DOCUMENT ME!! */\r
- public AlignmentPanel ap;\r
- protected int lastres;\r
- protected int startseq;\r
- protected AlignViewport av;\r
-\r
- // if character is inserted or deleted, we will need to recalculate the conservation\r
- boolean seqEditOccurred = false;\r
- ScrollThread scrollThread = null;\r
- boolean mouseDragging = false;\r
- boolean editingSeqs = false;\r
- boolean groupEditing = false;\r
-\r
- //////////////////////////////////////////\r
- /////Everything below this is for defining the boundary of the rubberband\r
- //////////////////////////////////////////\r
- int oldSeq = -1;\r
- boolean changeEndSeq = false;\r
- boolean changeStartSeq = false;\r
- boolean changeEndRes = false;\r
- boolean changeStartRes = false;\r
- SequenceGroup stretchGroup = null;\r
- boolean remove = false;\r
-\r
- Point lastMousePress;\r
- boolean mouseWheelPressed = false;\r
- StringBuffer keyboardNo1;\r
- StringBuffer keyboardNo2;\r
-\r
- java.net.URL linkImageURL;\r
-\r
- /**\r
- * Creates a new SeqPanel object.\r
- *\r
- * @param avp DOCUMENT ME!\r
- * @param p DOCUMENT ME!\r
- */\r
- public SeqPanel(AlignViewport avp, AlignmentPanel p)\r
- {\r
- linkImageURL = getClass().getResource("/images/link.gif");\r
- ToolTipManager.sharedInstance().registerComponent(this);\r
- ToolTipManager.sharedInstance().setInitialDelay(0);\r
- ToolTipManager.sharedInstance().setDismissDelay(10000);\r
- this.av = avp;\r
- setBackground(Color.white);\r
-\r
- seqCanvas = new SeqCanvas(avp);\r
- setLayout(new BorderLayout());\r
- add(seqCanvas, BorderLayout.CENTER);\r
-\r
- ap = p;\r
-\r
- if(!av.isDataset())\r
- {\r
- addMouseMotionListener(this);\r
- addMouseListener(this);\r
- addMouseWheelListener(this);\r
- }\r
+ /** DOCUMENT ME!! */\r
+ public SeqCanvas seqCanvas;\r
+\r
+ /** DOCUMENT ME!! */\r
+ public AlignmentPanel ap;\r
+ protected int lastres;\r
+ protected int startseq;\r
+ protected AlignViewport av;\r
+\r
+ ScrollThread scrollThread = null;\r
+ boolean mouseDragging = false;\r
+ boolean editingSeqs = false;\r
+ boolean groupEditing = false;\r
+\r
+ //////////////////////////////////////////\r
+ /////Everything below this is for defining the boundary of the rubberband\r
+ //////////////////////////////////////////\r
+ int oldSeq = -1;\r
+ boolean changeEndSeq = false;\r
+ boolean changeStartSeq = false;\r
+ boolean changeEndRes = false;\r
+ boolean changeStartRes = false;\r
+ SequenceGroup stretchGroup = null;\r
+ boolean remove = false;\r
+\r
+ Point lastMousePress;\r
+ boolean mouseWheelPressed = false;\r
+ StringBuffer keyboardNo1;\r
+ StringBuffer keyboardNo2;\r
+\r
+ java.net.URL linkImageURL;\r
+\r
+ StringBuffer tooltipText = new StringBuffer("<html>");\r
+ String tmpString;\r
+\r
+ EditCommand editCommand;\r
+\r
+ StructureSelectionManager ssm;\r
+\r
+\r
+ /**\r
+ * Creates a new SeqPanel object.\r
+ *\r
+ * @param avp DOCUMENT ME!\r
+ * @param p DOCUMENT ME!\r
+ */\r
+ public SeqPanel(AlignViewport av, AlignmentPanel ap)\r
+ {\r
+ linkImageURL = getClass().getResource("/images/link.gif");\r
+ ToolTipManager.sharedInstance().registerComponent(this);\r
+ ToolTipManager.sharedInstance().setInitialDelay(0);\r
+ ToolTipManager.sharedInstance().setDismissDelay(10000);\r
+ this.av = av;\r
+ setBackground(Color.white);\r
+\r
+ seqCanvas = new SeqCanvas(ap);\r
+ setLayout(new BorderLayout());\r
+ add(seqCanvas, BorderLayout.CENTER);\r
+\r
+ this.ap = ap;\r
+\r
+ if (!av.isDataset())\r
+ {\r
+ addMouseMotionListener(this);\r
+ addMouseListener(this);\r
+ addMouseWheelListener(this);\r
+ ssm = StructureSelectionManager.getStructureSelectionManager();\r
+ ssm.addStructureViewerListener(this);\r
}\r
+ }\r
\r
- int startWrapBlock=-1;\r
- int wrappedBlock=-1;\r
- int findRes(MouseEvent evt)\r
- {\r
- int res = 0;\r
- int x = evt.getX();\r
+ int startWrapBlock = -1;\r
+ int wrappedBlock = -1;\r
+ int findRes(MouseEvent evt)\r
+ {\r
+ int res = 0;\r
+ int x = evt.getX();\r
\r
if (av.wrapAlignment)\r
{\r
\r
int hgap = av.charHeight;\r
if (av.scaleAboveWrapped)\r
+ {\r
hgap += av.charHeight;\r
+ }\r
\r
int cHeight = av.getAlignment().getHeight() * av.charHeight\r
+ hgap + seqCanvas.getAnnotationHeight();\r
\r
- int y = evt.getY();\r
- y -= hgap;\r
- x -= seqCanvas.LABEL_WEST;\r
-\r
+ int y = evt.getY();\r
+ y -= hgap;\r
+ x -= seqCanvas.LABEL_WEST;\r
\r
- int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());\r
+ int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());\r
+ if (cwidth < 1)\r
+ {\r
+ return 0;\r
+ }\r
\r
- wrappedBlock = y / cHeight;\r
- wrappedBlock += av.getStartRes() / cwidth;\r
+ wrappedBlock = y / cHeight;\r
+ wrappedBlock += av.getStartRes() / cwidth;\r
\r
- res = wrappedBlock * cwidth + x / av.getCharWidth();\r
+ res = wrappedBlock * cwidth + x / av.getCharWidth();\r
\r
}\r
else\r
{\r
- res = (x / av.getCharWidth()) + av.getStartRes();\r
+ res = (x / av.getCharWidth()) + av.getStartRes();\r
}\r
\r
- if(av.hasHiddenColumns)\r
- res = av.getColumnSelection().adjustForHiddenColumns(res);\r
+ if (av.hasHiddenColumns)\r
+ {\r
+ res = av.getColumnSelection().adjustForHiddenColumns(res);\r
+ }\r
\r
return res;\r
\r
- }\r
-\r
- int findSeq(MouseEvent evt)\r
- {\r
-\r
- int seq = 0;\r
- int y = evt.getY();\r
-\r
- if (av.wrapAlignment)\r
- {\r
- int hgap = av.charHeight;\r
- if (av.scaleAboveWrapped)\r
- hgap += av.charHeight;\r
-\r
- int cHeight = av.getAlignment().getHeight() * av.charHeight\r
- + hgap + seqCanvas.getAnnotationHeight();\r
-\r
- y -= hgap;\r
-\r
- seq = ( (y % cHeight) / av.getCharHeight());\r
- }\r
- else\r
- {\r
- seq = (y / av.getCharHeight()) + av.getStartSeq();\r
- }\r
-\r
- return seq;\r
- }\r
-\r
- Vector getAllFeaturesAtRes(SequenceI seq, int res)\r
- {\r
- Vector allFeatures = new Vector();\r
- int index = 0;\r
- if(seq.getSequenceFeatures()!=null && av.featuresDisplayed!=null)\r
- {\r
- while (index < seq.getSequenceFeatures().length)\r
- {\r
- SequenceFeature sf = seq.getSequenceFeatures()[index];\r
- if (sf.getBegin() <= res &&\r
- sf.getEnd() >= res)\r
- {\r
- if (av.featuresDisplayed.containsKey(sf.getType()))\r
- {\r
- allFeatures.addElement(sf);\r
- }\r
- }\r
- index++;\r
- }\r
- }\r
- return allFeatures;\r
}\r
\r
- void endEditing()\r
- {\r
- startseq = -1;\r
- lastres = -1;\r
- seqEditOccurred = false;\r
- editingSeqs = false;\r
- groupEditing = false;\r
- keyboardNo1 = null;\r
- keyboardNo2 = null;\r
+ int findSeq(MouseEvent evt)\r
+ {\r
+ int seq = 0;\r
+ int y = evt.getY();\r
+\r
+ if (av.wrapAlignment)\r
+ {\r
+ int hgap = av.charHeight;\r
+ if (av.scaleAboveWrapped)\r
+ {\r
+ hgap += av.charHeight;\r
+ }\r
+\r
+ int cHeight = av.getAlignment().getHeight() * av.charHeight\r
+ + hgap + seqCanvas.getAnnotationHeight();\r
+\r
+ y -= hgap;\r
+\r
+ seq = Math.min( (y % cHeight) / av.getCharHeight(),\r
+ av.alignment.getHeight() - 1);\r
+ }\r
+ else\r
+ {\r
+ seq = Math.min( (y / av.getCharHeight()) + av.getStartSeq(),\r
+ av.alignment.getHeight() - 1);\r
+ }\r
+\r
+ return seq;\r
+ }\r
+\r
+ SequenceFeature[] findFeaturesAtRes(SequenceI sequence, int res)\r
+ {\r
+ Vector tmp = new Vector();\r
+ SequenceFeature[] features = sequence.getSequenceFeatures();\r
+ if (features != null)\r
+ {\r
+ for (int i = 0; i < features.length; i++)\r
+ {\r
+ if (av.featuresDisplayed == null\r
+ || !av.featuresDisplayed.containsKey(features[i].getType()))\r
+ {\r
+ continue;\r
+ }\r
+\r
+ if (features[i].featureGroup != null\r
+ && seqCanvas.fr.featureGroups!=null\r
+ && seqCanvas.fr.featureGroups.containsKey(features[i].featureGroup)\r
+ && !((Boolean)seqCanvas.fr.featureGroups.get(features[i].featureGroup)).booleanValue())\r
+ continue;\r
+\r
+\r
+ if ( (features[i].getBegin() <= res) &&\r
+ (features[i].getEnd() >= res))\r
+ {\r
+ tmp.addElement(features[i]);\r
+ }\r
+ }\r
}\r
\r
- void setCursorRow()\r
+ features = new SequenceFeature[tmp.size()];\r
+ tmp.copyInto(features);\r
+\r
+ return features;\r
+ }\r
+\r
+\r
+ void endEditing()\r
+ {\r
+ if (editCommand != null && editCommand.getSize() > 0)\r
{\r
- seqCanvas.cursorY = getKeyboardNo(keyboardNo1)-1;\r
- scrollToVisible();\r
+ ap.alignFrame.addHistoryItem(editCommand);\r
+ av.firePropertyChange("alignment", null,\r
+ av.getAlignment().getSequences());\r
}\r
\r
- void setCursorColumn()\r
+ startseq = -1;\r
+ lastres = -1;\r
+ editingSeqs = false;\r
+ groupEditing = false;\r
+ keyboardNo1 = null;\r
+ keyboardNo2 = null;\r
+ editCommand = null;\r
+ }\r
+\r
+ void setCursorRow()\r
+ {\r
+ seqCanvas.cursorY = getKeyboardNo1() - 1;\r
+ scrollToVisible();\r
+ }\r
+\r
+ void setCursorColumn()\r
+ {\r
+ seqCanvas.cursorX = getKeyboardNo1() - 1;\r
+ scrollToVisible();\r
+ }\r
+\r
+ void setCursorRowAndColumn()\r
+ {\r
+ if (keyboardNo2 == null)\r
+ {\r
+ keyboardNo2 = new StringBuffer();\r
+ }\r
+ else\r
{\r
- seqCanvas.cursorX = getKeyboardNo(keyboardNo1)-1;\r
+ seqCanvas.cursorX = getKeyboardNo1() - 1;\r
+ seqCanvas.cursorY = getKeyboardNo2() - 1;\r
scrollToVisible();\r
}\r
+ }\r
+\r
+ void setCursorPosition()\r
+ {\r
+ SequenceI sequence =\r
+ (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);\r
\r
- void setCursorRowAndColumn()\r
+ seqCanvas.cursorX = sequence.findIndex(\r
+ getKeyboardNo1() - 1\r
+ );\r
+ scrollToVisible();\r
+ }\r
+\r
+ void moveCursor(int dx, int dy)\r
+ {\r
+ seqCanvas.cursorX += dx;\r
+ seqCanvas.cursorY += dy;\r
+ if (av.hasHiddenColumns && !av.colSel.isVisible(seqCanvas.cursorX))\r
{\r
- if(keyboardNo2==null)\r
+ int original = seqCanvas.cursorX - dx;\r
+ int maxWidth = av.alignment.getWidth();\r
+\r
+ while (!av.colSel.isVisible(seqCanvas.cursorX)\r
+ && seqCanvas.cursorX < maxWidth\r
+ && seqCanvas.cursorX > 0)\r
{\r
- keyboardNo2 = new StringBuffer();\r
+ seqCanvas.cursorX += dx;\r
}\r
- else\r
+\r
+ if (seqCanvas.cursorX >= maxWidth\r
+ || !av.colSel.isVisible(seqCanvas.cursorX))\r
{\r
- seqCanvas.cursorX = getKeyboardNo(keyboardNo1) - 1;\r
- seqCanvas.cursorY = getKeyboardNo(keyboardNo2) - 1;\r
- scrollToVisible();\r
+ seqCanvas.cursorX = original;\r
}\r
}\r
\r
- void setCursorPosition()\r
- {\r
- SequenceI sequence =\r
- (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);\r
+ scrollToVisible();\r
+ }\r
\r
- seqCanvas.cursorX = sequence.findIndex(\r
- getKeyboardNo(keyboardNo1)-1\r
- );\r
- scrollToVisible();\r
+ void scrollToVisible()\r
+ {\r
+ if (seqCanvas.cursorX < 0)\r
+ {\r
+ seqCanvas.cursorX = 0;\r
}\r
-\r
- void moveCursor(int dx, int dy)\r
+ else if (seqCanvas.cursorX > av.alignment.getWidth() - 1)\r
{\r
- seqCanvas.cursorX += dx;\r
- seqCanvas.cursorY += dy;\r
- scrollToVisible();\r
+ seqCanvas.cursorX = av.alignment.getWidth() - 1;\r
}\r
\r
- void scrollToVisible()\r
+ if (seqCanvas.cursorY < 0)\r
{\r
- if (seqCanvas.cursorX < 0)\r
- seqCanvas.cursorX = 0;\r
- else if (seqCanvas.cursorX > av.alignment.getWidth() - 1)\r
- seqCanvas.cursorX = av.alignment.getWidth() - 1;\r
-\r
- if (seqCanvas.cursorY < 0)\r
- seqCanvas.cursorY = 0;\r
- else if (seqCanvas.cursorY > av.alignment.getHeight() - 1)\r
- seqCanvas.cursorY = av.alignment.getHeight() - 1;\r
-\r
+ seqCanvas.cursorY = 0;\r
+ }\r
+ else if (seqCanvas.cursorY > av.alignment.getHeight() - 1)\r
+ {\r
+ seqCanvas.cursorY = av.alignment.getHeight() - 1;\r
+ }\r
\r
- endEditing();\r
- if(av.wrapAlignment)\r
+ endEditing();\r
+ if (av.wrapAlignment)\r
+ {\r
+ ap.scrollToWrappedVisible(seqCanvas.cursorX);\r
+ }\r
+ else\r
+ {\r
+ while (seqCanvas.cursorY < av.startSeq)\r
{\r
- ap.scrollToWrappedVisible(seqCanvas.cursorX);\r
+ ap.scrollUp(true);\r
}\r
- else\r
+ while (seqCanvas.cursorY + 1 > av.endSeq)\r
{\r
- while (seqCanvas.cursorY < av.startSeq)\r
- {\r
- ap.scrollUp(true);\r
- }\r
- while (seqCanvas.cursorY + 1 > av.endSeq)\r
- {\r
- ap.scrollUp(false);\r
- }\r
- if (!av.wrapAlignment)\r
+ ap.scrollUp(false);\r
+ }\r
+ if (!av.wrapAlignment)\r
+ {\r
+ while (seqCanvas.cursorX < av.colSel.adjustForHiddenColumns(av.startRes))\r
{\r
- while (seqCanvas.cursorX < av.startRes)\r
+ if (!ap.scrollRight(false))\r
{\r
- if (!ap.scrollRight(false))\r
- break;\r
+ break;\r
}\r
- while (seqCanvas.cursorX > av.endRes)\r
+ }\r
+ while (seqCanvas.cursorX > av.colSel.adjustForHiddenColumns(av.endRes))\r
+ {\r
+ if (!ap.scrollRight(true))\r
{\r
- if (!ap.scrollRight(true))\r
- break;\r
+ break;\r
}\r
}\r
}\r
- setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY),\r
- seqCanvas.cursorX, seqCanvas.cursorY);\r
-\r
- seqCanvas.repaint();\r
}\r
+ setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY),\r
+ seqCanvas.cursorX, seqCanvas.cursorY);\r
\r
- void setSelectionAreaAtCursor(boolean topLeft)\r
- {\r
- SequenceI sequence =\r
- (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);\r
+ seqCanvas.repaint();\r
+ }\r
+\r
+ void setSelectionAreaAtCursor(boolean topLeft)\r
+ {\r
+ SequenceI sequence =\r
+ (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);\r
\r
- if(av.getSelectionGroup()!=null)\r
+ if (av.getSelectionGroup() != null)\r
+ {\r
+ SequenceGroup sg = av.selectionGroup;\r
+ //Find the top and bottom of this group\r
+ int min = av.alignment.getHeight(), max = 0;\r
+ for (int i = 0; i < sg.getSize(); i++)\r
{\r
- SequenceGroup sg = av.selectionGroup;\r
- //Find the top and bottom of this group\r
- int min = av.alignment.getHeight(), max = 0;\r
- for(int i=0; i<sg.getSize(false); i++)\r
+ int index = av.alignment.findIndex(sg.getSequenceAt(i));\r
+ if (index > max)\r
{\r
- int index = av.alignment.findIndex( sg.getSequenceAt(i) );\r
- if(index > max)\r
- max = index;\r
- if(index < min)\r
- min = index;\r
+ max = index;\r
}\r
-\r
- max ++;\r
-\r
- if(topLeft)\r
+ if (index < min)\r
{\r
- sg.setStartRes(seqCanvas.cursorX);\r
- if(sg.getEndRes()<seqCanvas.cursorX)\r
- sg.setEndRes(seqCanvas.cursorX);\r
-\r
- min = seqCanvas.cursorY;\r
+ min = index;\r
}\r
- else\r
- {\r
- sg.setEndRes(seqCanvas.cursorX);\r
- if(sg.getStartRes()>seqCanvas.cursorX)\r
- sg.setStartRes(seqCanvas.cursorX);\r
+ }\r
\r
- max = seqCanvas.cursorY+1;\r
- }\r
+ max++;\r
\r
- if(min>max)\r
+ if (topLeft)\r
+ {\r
+ sg.setStartRes(seqCanvas.cursorX);\r
+ if (sg.getEndRes() < seqCanvas.cursorX)\r
{\r
- // Only the user can do this\r
- av.setSelectionGroup(null);\r
+ sg.setEndRes(seqCanvas.cursorX);\r
}\r
- else\r
+\r
+ min = seqCanvas.cursorY;\r
+ }\r
+ else\r
+ {\r
+ sg.setEndRes(seqCanvas.cursorX);\r
+ if (sg.getStartRes() > seqCanvas.cursorX)\r
{\r
- // Now add any sequences between min and max\r
- sg.getSequences(false).clear();\r
- for (int i = min; i < max; i++)\r
- {\r
- sg.addSequence(av.alignment.getSequenceAt(i), false);\r
- }\r
+ sg.setStartRes(seqCanvas.cursorX);\r
}\r
+\r
+ max = seqCanvas.cursorY + 1;\r
}\r
\r
- if (av.getSelectionGroup() == null)\r
+ if (min > max)\r
{\r
- SequenceGroup sg = new SequenceGroup();\r
- sg.setStartRes(seqCanvas.cursorX);\r
- sg.setEndRes(seqCanvas.cursorX);\r
- sg.addSequence(sequence, false);\r
- av.setSelectionGroup(sg);\r
+ // Only the user can do this\r
+ av.setSelectionGroup(null);\r
}\r
+ else\r
+ {\r
+ // Now add any sequences between min and max\r
+ sg.getSequences(null).clear();\r
+ for (int i = min; i < max; i++)\r
+ {\r
+ sg.addSequence(av.alignment.getSequenceAt(i), false);\r
+ }\r
+ }\r
+ }\r
\r
-\r
- ap.repaint();\r
+ if (av.getSelectionGroup() == null)\r
+ {\r
+ SequenceGroup sg = new SequenceGroup();\r
+ sg.setStartRes(seqCanvas.cursorX);\r
+ sg.setEndRes(seqCanvas.cursorX);\r
+ sg.addSequence(sequence, false);\r
+ av.setSelectionGroup(sg);\r
}\r
\r
- void insertGapAtCursor(boolean group)\r
+ ap.paintAlignment(false);\r
+ }\r
+\r
+ void insertGapAtCursor(boolean group)\r
+ {\r
+ groupEditing = group;\r
+ startseq = seqCanvas.cursorY;\r
+ lastres = seqCanvas.cursorX;\r
+ editSequence(true, seqCanvas.cursorX + getKeyboardNo1());\r
+ endEditing();\r
+ }\r
+\r
+ void deleteGapAtCursor(boolean group)\r
+ {\r
+ groupEditing = group;\r
+ startseq = seqCanvas.cursorY;\r
+ lastres = seqCanvas.cursorX + getKeyboardNo1();\r
+ editSequence(false, seqCanvas.cursorX);\r
+ endEditing();\r
+ }\r
+\r
+ void numberPressed(char value)\r
+ {\r
+ if (keyboardNo1 == null)\r
{\r
- ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence",\r
- av.alignment, HistoryItem.EDIT));\r
- groupEditing = group;\r
- startseq = seqCanvas.cursorY;\r
- lastres = seqCanvas.cursorX;\r
- editSequence(true, seqCanvas.cursorX+getKeyboardNo(keyboardNo1));\r
- editOccurred();\r
+ keyboardNo1 = new StringBuffer();\r
}\r
\r
- void deleteGapAtCursor(boolean group)\r
+ if (keyboardNo2 != null)\r
+ {\r
+ keyboardNo2.append(value);\r
+ }\r
+ else\r
{\r
- ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence",\r
- av.alignment, HistoryItem.EDIT));\r
- groupEditing = group;\r
- startseq = seqCanvas.cursorY;\r
- lastres = seqCanvas.cursorX+getKeyboardNo(keyboardNo1);\r
- editSequence(false, seqCanvas.cursorX);\r
- editOccurred();\r
+ keyboardNo1.append(value);\r
}\r
+ }\r
\r
- void numberPressed(char value)\r
+ int getKeyboardNo1()\r
+ {\r
+ if (keyboardNo1 == null)\r
+ return 1;\r
+ else\r
{\r
- if(keyboardNo1==null)\r
- keyboardNo1 = new StringBuffer();\r
+ int value = Integer.parseInt(keyboardNo1.toString());\r
+ keyboardNo1 = null;\r
+ return value;\r
+ }\r
+ }\r
\r
- if(keyboardNo2!=null)\r
- keyboardNo2.append(value);\r
- else\r
- keyboardNo1.append(value);\r
+ int getKeyboardNo2()\r
+ {\r
+ if (keyboardNo2 == null)\r
+ return 1;\r
+ else\r
+ {\r
+ int value = Integer.parseInt(keyboardNo2.toString());\r
+ keyboardNo2 = null;\r
+ return value;\r
}\r
+ }\r
\r
- int getKeyboardNo(StringBuffer kb)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param evt DOCUMENT ME!\r
+ */\r
+ public void mouseReleased(MouseEvent evt)\r
+ {\r
+ mouseDragging = false;\r
+ mouseWheelPressed = false;\r
+\r
+ if (!editingSeqs)\r
{\r
- if(kb==null)\r
- return 1;\r
- else\r
- return Integer.parseInt(kb.toString());\r
+ doMouseReleasedDefineMode(evt);\r
+ return;\r
}\r
\r
+ endEditing();\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param evt DOCUMENT ME!\r
+ */\r
+ public void mousePressed(MouseEvent evt)\r
+ {\r
+ lastMousePress = evt.getPoint();\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param evt DOCUMENT ME!\r
- */\r
- public void mouseReleased(MouseEvent evt)\r
+ if (javax.swing.SwingUtilities.isMiddleMouseButton(evt))\r
{\r
- mouseDragging = false;\r
- mouseWheelPressed = false;\r
+ mouseWheelPressed = true;\r
+ return;\r
+ }\r
\r
- if (!editingSeqs)\r
+ if (evt.isShiftDown() || evt.isAltDown() ||\r
+ evt.isControlDown())\r
+ {\r
+ if (evt.isAltDown() || evt.isControlDown())\r
{\r
- doMouseReleasedDefineMode(evt);\r
- return;\r
+ groupEditing = true;\r
}\r
-\r
- editOccurred();\r
-\r
- ap.repaint();\r
+ editingSeqs = true;\r
+ }\r
+ else\r
+ {\r
+ doMousePressedDefineMode(evt);\r
+ return;\r
}\r
\r
+ int seq = findSeq(evt);\r
+ int res = findRes(evt);\r
\r
+ if (seq < 0 || res < 0)\r
+ {\r
+ return;\r
+ }\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param evt DOCUMENT ME!\r
- */\r
- public void mousePressed(MouseEvent evt)\r
+ if ( (seq < av.getAlignment().getHeight()) &&\r
+ (res < av.getAlignment().getSequenceAt(seq).getLength()))\r
{\r
- lastMousePress = evt.getPoint();\r
+ startseq = seq;\r
+ lastres = res;\r
+ }\r
+ else\r
+ {\r
+ startseq = -1;\r
+ lastres = -1;\r
+ }\r
\r
- if (javax.swing.SwingUtilities.isMiddleMouseButton(evt))\r
- {\r
- mouseWheelPressed = true;\r
- return;\r
- }\r
+ return;\r
+ }\r
\r
- if (evt.isShiftDown() || evt.isAltDown() ||\r
- evt.isControlDown())\r
- {\r
- if (evt.isAltDown() || evt.isControlDown())\r
- {\r
- groupEditing = true;\r
- }\r
- editingSeqs = true;\r
- }\r
- else\r
- {\r
- doMousePressedDefineMode(evt);\r
- return;\r
- }\r
+ String lastMessage;\r
+ public void mouseOverSequence(SequenceI sequence, int index)\r
+ {\r
+ String tmp = sequence.hashCode()+index+"";\r
+ if (lastMessage == null || !lastMessage.equals(tmp))\r
+ ssm.mouseOverSequence(sequence, index);\r
\r
+ lastMessage = tmp;\r
+ }\r
\r
\r
- int seq = findSeq(evt);\r
- int res = findRes(evt);\r
+ public void highlightSequence(jalview.datamodel.SequenceI seq, int index)\r
+ {\r
+ if(av.alignment.findIndex(seq)>-1)\r
+ {\r
+ SearchResults highlight = new SearchResults();\r
+ highlight.addResult(seq,index,index);\r
+ seqCanvas.highlightSearchResults(highlight);\r
+ }\r
+ }\r
\r
- if(seq<0 || res<0)\r
- return;\r
+ public void updateColours(SequenceI seq, int index)\r
+ {\r
+ System.out.println("update the seqPanel colours");\r
+ //repaint();\r
+ }\r
\r
- ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence",\r
- av.alignment, HistoryItem.EDIT));\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param evt DOCUMENT ME!\r
+ */\r
+ public void mouseMoved(MouseEvent evt)\r
+ {\r
+ if (editingSeqs)\r
+ {\r
+ // This is because MacOSX creates a mouseMoved\r
+ // If control is down, other platforms will not.\r
+ mouseDragged(evt);\r
+ }\r
\r
- if ((seq < av.getAlignment().getHeight()) &&\r
- (res < av.getAlignment().getSequenceAt(seq).getLength()))\r
- {\r
- startseq = seq;\r
- lastres = res;\r
- }\r
- else\r
- {\r
- startseq = -1;\r
- lastres = -1;\r
- }\r
+ int res = findRes(evt);\r
+ int seq = findSeq(evt);\r
\r
- return;\r
+ if (res < 0 || seq < 0 || seq >= av.getAlignment().getHeight())\r
+ {\r
+ return;\r
}\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param evt DOCUMENT ME!\r
- */\r
- public void mouseMoved(MouseEvent evt)\r
- {\r
- if (editingSeqs)\r
- {\r
- // This is because MacOSX creates a mouseMoved\r
- // If control is down, other platforms will not.\r
- mouseDragged(evt);\r
- }\r
+ SequenceI sequence = av.getAlignment().getSequenceAt(seq);\r
\r
- int res = findRes(evt);\r
- int seq = findSeq(evt);\r
+ if (res > sequence.getLength())\r
+ {\r
+ return;\r
+ }\r
\r
+ if (ssm != null)\r
+ mouseOverSequence(sequence, sequence.findPosition(res));\r
\r
- if(res<0 || seq<0 || seq >= av.getAlignment().getHeight())\r
- return;\r
+ setStatusMessage(sequence, res, seq);\r
\r
- SequenceI sequence = av.getAlignment().getSequenceAt(seq);\r
+ tooltipText.setLength(6); // Cuts the buffer back to <html>\r
\r
- if (res > sequence.getLength())\r
+ SequenceGroup[] groups = av.alignment.findAllGroups(sequence);\r
+ if (groups != null)\r
+ {\r
+ for (int g = 0; g < groups.length; g++)\r
{\r
- return;\r
- }\r
+ if (groups[g].getStartRes() <= res && groups[g].getEndRes() >= res)\r
+ {\r
+ if (tooltipText.length() > 6)\r
+ {\r
+ tooltipText.append("<br>");\r
+ }\r
\r
- if(seqCanvas.pdbCanvas!=null && sequence==seqCanvas.pdbCanvas.sequence)\r
- {\r
- seqCanvas.pdbCanvas.highlightRes(sequence.findPosition(res));\r
+ if (!groups[g].getName().startsWith("JTreeGroup") &&\r
+ !groups[g].getName().startsWith("JGroup"))\r
+ {\r
+ tooltipText.append(groups[g].getName());\r
+ }\r
+\r
+ if (groups[g].getDescription() != null)\r
+ {\r
+ tooltipText.append(": " + groups[g].getDescription());\r
+ }\r
+ }\r
}\r
+ }\r
\r
- setStatusMessage(sequence, res, seq);\r
+ // use aa to see if the mouse pointer is on a\r
+ if (av.showSequenceFeatures)\r
+ {\r
+ SequenceFeature[] features = findFeaturesAtRes(\r
+ sequence.getDatasetSequence(), sequence.findPosition(res));\r
\r
- // use aa to see if the mouse pointer is on a\r
- if (av.showSequenceFeatures)\r
+ if (features != null)\r
+ {\r
+ for (int i = 0; i < features.length; i++)\r
{\r
- SequenceFeature [] features = sequence.getDatasetSequence().getSequenceFeatures();\r
- if(features!=null)\r
+ if (features[i].getType().equals("disulfide bond"))\r
+ {\r
+ if (features[i].getBegin() == sequence.findPosition(res)\r
+ || features[i].getEnd() == sequence.findPosition(res))\r
+ {\r
+ if (tooltipText.length() > 6)\r
+ {\r
+ tooltipText.append("<br>");\r
+ }\r
+ tooltipText.append("disulfide bond " + features[i].getBegin() +\r
+ ":" +\r
+ features[i].getEnd());\r
+ if (features[i].links != null)\r
+ {\r
+ tooltipText.append(" <img src=\"" + linkImageURL + "\">");\r
+ }\r
+ }\r
+ }\r
+ else\r
+ {\r
+ if (tooltipText.length() > 6)\r
+ {\r
+ tooltipText.append("<br>");\r
+ }\r
+\r
+ tooltipText.append(features[i].getType() + " " +\r
+ features[i].begin);\r
+ if (features[i].begin != features[i].end)\r
{\r
- StringBuffer sbuffer = new StringBuffer("<html>");\r
- StringBuffer seqSpecific = new StringBuffer();\r
+ tooltipText.append(" " + features[i].end);\r
+ }\r
\r
- for (int i = 0; i < features.length; i++)\r
+ if (features[i].getDescription() != null\r
+ && !features[i].description.equals(features[i].getType()))\r
+ {\r
+ tmpString = features[i].getDescription();\r
+ int startTag = tmpString.toUpperCase().indexOf("<HTML>");\r
+ if (startTag > -1)\r
+ {\r
+ tmpString = tmpString.substring(startTag + 6);\r
+ }\r
+ int endTag = tmpString.toUpperCase().indexOf("</BODY>");\r
+ if (endTag > -1)\r
{\r
+ tmpString = tmpString.substring(0, endTag);\r
+ }\r
+ endTag = tmpString.toUpperCase().indexOf("</HTML>");\r
+ if (endTag > -1)\r
+ {\r
+ tmpString = tmpString.substring(0, endTag);\r
+ }\r
\r
- if ( (features[i].getBegin() <= sequence.findPosition(res)) &&\r
- (features[i].getEnd() >= sequence.findPosition(res)))\r
+ if (startTag > -1)\r
+ {\r
+ tooltipText.append("; " + tmpString);\r
+ }\r
+ else\r
+ {\r
+ if (tmpString.indexOf("<") > -1 || tmpString.indexOf(">") > -1)\r
{\r
- if(av.featuresDisplayed==null\r
- || !av.featuresDisplayed.containsKey(features[i].getType()))\r
- continue;\r
-\r
-\r
- if (features[i].getType().equals("disulfide bond"))\r
- {\r
- if (features[i].getBegin() == sequence.findPosition(res)\r
- || features[i].getEnd() == sequence.findPosition(res))\r
- {\r
- if (sbuffer.length() > 6)\r
- sbuffer.append("<br>");\r
- sbuffer.append("disulfide bond " + features[i].getBegin() + ":" +\r
- features[i].getEnd());\r
- if (features[i].links != null)\r
- sbuffer.append(" <img src=\"" + linkImageURL + "\">");\r
- }\r
- }\r
- else\r
- {\r
- if (sbuffer.length() > 6)\r
- sbuffer.append("<br>");\r
-\r
- sbuffer.append(features[i].getType() + " " +\r
- features[i].begin);\r
- if (features[i].begin != features[i].end)\r
- sbuffer.append(" " + features[i].end);\r
-\r
- if (features[i].getDescription() != null\r
- && !features[i].description.equals(features[i].getType()))\r
- sbuffer.append("; " + features[i].getDescription());\r
-\r
- if (features[i].getValue("status") != null)\r
- {\r
- sbuffer.append("; (" + features[i].getValue("status") + ")");\r
- }\r
- if (features[i].links != null)\r
- sbuffer.append(" <img src=\"" + linkImageURL + "\">");\r
-\r
- }\r
+ //The description does not specify html is to\r
+ //be used, so we must remove < > symbols\r
+ tmpString = tmpString.replaceAll("<", "<");\r
+ tmpString = tmpString.replaceAll(">", ">");\r
+\r
+ tooltipText.append("; ");\r
+ tooltipText.append(tmpString);\r
+\r
}\r
- else if(features[i].begin==0 && features[i].end==0)\r
+ else\r
{\r
- // seqSpecific.append(features[i].featureGroup+": "\r
- // + features[i].getType()+" "\r
- // +features[i].getDescription()+"<br>");\r
-\r
+ tooltipText.append("; " + tmpString);\r
}\r
}\r
-\r
- if(seqSpecific.length()>0)\r
- seqSpecific.setLength(seqSpecific.length()-4);\r
-\r
- sbuffer.append(seqSpecific);\r
- sbuffer.append("</html>");\r
- if(sbuffer.length()==13) // <html></html>\r
- setToolTipText("");\r
- else\r
- setToolTipText(sbuffer.toString());\r
}\r
- else\r
- setToolTipText("");\r
- }\r
- }\r
+ if (features[i].getValue("status") != null)\r
+ {\r
+ String status = features[i].getValue("status").toString();\r
+ if (status.length() > 0)\r
+ {\r
+ tooltipText.append("; (" + features[i].getValue("status") + ")");\r
+ }\r
+ }\r
\r
- void setStatusMessage(SequenceI sequence, int res, int seq)\r
+ if (features[i].links != null)\r
+ {\r
+ tooltipText.append(" <img src=\"" + linkImageURL + "\">");\r
+ }\r
+\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ if (tooltipText.length() == 6) // <html></html>\r
+ {\r
+ setToolTipText(null);\r
+ }\r
+ else\r
{\r
- StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " +\r
- sequence.getName());\r
+ tooltipText.append("</html>");\r
+ setToolTipText(tooltipText.toString());\r
+ }\r
+ // else\r
+ // setToolTipText(null);\r
+ }\r
+\r
+ void setStatusMessage(SequenceI sequence, int res, int seq)\r
+ {\r
+ StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " +\r
+ sequence.getName());\r
\r
- Object obj = null;\r
- if (av.alignment.isNucleotide())\r
+ Object obj = null;\r
+ if (av.alignment.isNucleotide())\r
+ {\r
+ obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) +\r
+ "");\r
+ if (obj != null)\r
{\r
- obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) +\r
- "");\r
- if (obj != null)\r
- text.append(" Nucleotide: ");\r
+ text.append(" Nucleotide: ");\r
}\r
- else\r
+ }\r
+ else\r
+ {\r
+ obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");\r
+ if (obj != null)\r
{\r
- obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");\r
- if (obj != null)\r
- text.append(" Residue: ");\r
+ text.append(" Residue: ");\r
}\r
+ }\r
\r
- if (obj != null)\r
+ if (obj != null)\r
+ {\r
+\r
+ if (obj != "")\r
+ {\r
+ text.append(obj + " (" + sequence.findPosition(res) +\r
+ ")");\r
+ }\r
+ }\r
+ ap.alignFrame.statusBar.setText(text.toString());\r
+\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param evt DOCUMENT ME!\r
+ */\r
+ public void mouseDragged(MouseEvent evt)\r
+ {\r
+ if (mouseWheelPressed)\r
+ {\r
+ int oldWidth = av.charWidth;\r
+\r
+ //Which is bigger, left-right or up-down?\r
+ if (Math.abs(evt.getY() - lastMousePress.getY())\r
+ > Math.abs(evt.getX() - lastMousePress.getX()))\r
{\r
+ int fontSize = av.font.getSize();\r
+\r
+ if (evt.getY() < lastMousePress.getY())\r
+ {\r
+ fontSize--;\r
+ }\r
+ else if (evt.getY() > lastMousePress.getY())\r
+ {\r
+ fontSize++;\r
+ }\r
\r
- if (obj != "")\r
+ if (fontSize < 1)\r
+ {\r
+ fontSize = 1;\r
+ }\r
+\r
+ av.setFont(new Font(av.font.getName(), av.font.getStyle(), fontSize));\r
+ av.charWidth = oldWidth;\r
+ ap.fontChanged();\r
+ }\r
+ else\r
+ {\r
+ if (evt.getX() < lastMousePress.getX() && av.charWidth > 1)\r
{\r
- text.append(obj + " (" + sequence.findPosition(res) +\r
- ")");\r
+ av.charWidth--;\r
}\r
+ else if (evt.getX() > lastMousePress.getX())\r
+ {\r
+ av.charWidth++;\r
+ }\r
+\r
+ ap.paintAlignment(false);\r
}\r
- ap.alignFrame.statusBar.setText(text.toString());\r
\r
+ FontMetrics fm = getFontMetrics(av.getFont());\r
+ av.validCharWidth = fm.charWidth('M') <= av.charWidth;\r
+\r
+ lastMousePress = evt.getPoint();\r
+\r
+ return;\r
}\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param evt DOCUMENT ME!\r
- */\r
- public void mouseDragged(MouseEvent evt)\r
+ if (!editingSeqs)\r
{\r
- if (mouseWheelPressed)\r
- {\r
- int oldWidth = av.charWidth;\r
+ doMouseDraggedDefineMode(evt);\r
+ return;\r
+ }\r
\r
- //Which is bigger, left-right or up-down?\r
- if (Math.abs(evt.getY() - lastMousePress.getY())\r
- > Math.abs(evt.getX() - lastMousePress.getX()))\r
- {\r
- int fontSize = av.font.getSize();\r
+ int res = findRes(evt);\r
\r
- if (evt.getY() < lastMousePress.getY())\r
- {\r
- fontSize--;\r
- }\r
- else if (evt.getY() > lastMousePress.getY())\r
- {\r
- fontSize++;\r
- }\r
+ if (res < 0)\r
+ {\r
+ res = 0;\r
+ }\r
\r
- if(fontSize<1)\r
- fontSize = 1;\r
+ if ( (lastres == -1) || (lastres == res))\r
+ {\r
+ return;\r
+ }\r
\r
- av.setFont(new Font(av.font.getName(), av.font.getStyle(), fontSize));\r
- av.charWidth = oldWidth;\r
- ap.fontChanged();\r
- }\r
- else\r
- {\r
- if (evt.getX() < lastMousePress.getX() && av.charWidth > 1)\r
- {\r
- av.charWidth--;\r
- }\r
- else if (evt.getX() > lastMousePress.getX())\r
- {\r
- av.charWidth++;\r
- }\r
+ if ( (res < av.getAlignment().getWidth()) && (res < lastres))\r
+ {\r
+ // dragLeft, delete gap\r
+ editSequence(false, res);\r
+ }\r
+ else\r
+ {\r
+ editSequence(true, res);\r
+ }\r
\r
- ap.repaint();\r
- }\r
+ mouseDragging = true;\r
+ if (scrollThread != null)\r
+ {\r
+ scrollThread.setEvent(evt);\r
+ }\r
+ }\r
\r
- FontMetrics fm = getFontMetrics(av.getFont());\r
- av.validCharWidth = fm.charWidth('M') <= av.charWidth;\r
\r
- lastMousePress = evt.getPoint();\r
\r
- return;\r
+ synchronized void editSequence(boolean insertGap, int startres)\r
+ {\r
+ int fixedLeft = -1;\r
+ int fixedRight = -1;\r
+ boolean fixedColumns = false;\r
+ SequenceGroup sg = av.getSelectionGroup();\r
+\r
+ SequenceI seq = av.alignment.getSequenceAt(startseq);\r
+\r
+ //No group, but the sequence may represent a group\r
+ if (!groupEditing && av.hasHiddenRows)\r
+ {\r
+ if (av.hiddenRepSequences != null\r
+ && av.hiddenRepSequences.containsKey(seq))\r
+ {\r
+ sg = (SequenceGroup) av.hiddenRepSequences.get(seq);\r
+ groupEditing = true;\r
}\r
+ }\r
\r
- if (!editingSeqs)\r
+ StringBuffer message = new StringBuffer();\r
+ if (groupEditing)\r
+ {\r
+ message.append("Edit group:");\r
+ if (editCommand == null)\r
{\r
- doMouseDraggedDefineMode(evt);\r
- return;\r
+ editCommand = new EditCommand("Edit Group");\r
+ }\r
+ }\r
+ else\r
+ {\r
+ message.append("Edit sequence: " + seq.getName());\r
+ String label = seq.getName();\r
+ if (label.length() > 10)\r
+ {\r
+ label = label.substring(0, 10);\r
+ }\r
+ if (editCommand == null)\r
+ {\r
+ editCommand = new EditCommand("Edit " + label);\r
}\r
+ }\r
\r
- int res = findRes(evt);\r
+ if (insertGap)\r
+ {\r
+ message.append(" insert ");\r
+ }\r
+ else\r
+ {\r
+ message.append(" delete ");\r
+ }\r
\r
- if (res < 0)\r
- {\r
- res = 0;\r
- }\r
+ message.append(Math.abs(startres - lastres) + " gaps.");\r
+ ap.alignFrame.statusBar.setText(message.toString());\r
\r
- if ((lastres == -1) || (lastres == res))\r
- {\r
- return;\r
- }\r
+ //Are we editing within a selection group?\r
+ if (groupEditing\r
+ || (sg != null && sg.getSequences(av.hiddenRepSequences).contains(seq)))\r
+ {\r
+ fixedColumns = true;\r
\r
- if ( (res < av.getAlignment().getWidth()) && (res < lastres))\r
+ //sg might be null as the user may only see 1 sequence,\r
+ //but the sequence represents a group\r
+ if (sg == null)\r
+ {\r
+ if (av.hiddenRepSequences == null\r
+ || !av.hiddenRepSequences.containsKey(seq))\r
{\r
- // dragLeft, delete gap\r
- editSequence(false, res);\r
+ endEditing();\r
+ return;\r
}\r
- else\r
- editSequence(true, res);\r
+ sg = (SequenceGroup) av.hiddenRepSequences.get(seq);\r
+ }\r
\r
- mouseDragging = true;\r
- if(scrollThread!=null)\r
- scrollThread.setEvent(evt);\r
+ fixedLeft = sg.getStartRes();\r
+ fixedRight = sg.getEndRes();\r
\r
+ if ( (startres < fixedLeft && lastres >= fixedLeft)\r
+ || (startres >= fixedLeft && lastres < fixedLeft)\r
+ || (startres > fixedRight && lastres <= fixedRight)\r
+ || (startres <= fixedRight && lastres > fixedRight))\r
+ {\r
+ endEditing();\r
+ return;\r
+ }\r
+\r
+ if (fixedLeft > startres)\r
+ {\r
+ fixedRight = fixedLeft - 1;\r
+ fixedLeft = 0;\r
+ }\r
+ else if (fixedRight < startres)\r
+ {\r
+ fixedLeft = fixedRight;\r
+ fixedRight = -1;\r
+ }\r
}\r
\r
- synchronized void editSequence(boolean insertGap, int startres)\r
+ if (av.hasHiddenColumns)\r
{\r
- int fixedLeft = -1;\r
- int fixedRight = -1;\r
- boolean fixedColumns = false;\r
- SequenceGroup sg = av.getSelectionGroup();\r
+ fixedColumns = true;\r
+ int y1 = av.getColumnSelection().getHiddenBoundaryLeft(startres);\r
+ int y2 = av.getColumnSelection().getHiddenBoundaryRight(startres);\r
\r
+ if ( (insertGap && startres > y1 && lastres < y1)\r
+ || (!insertGap && startres < y2 && lastres > y2))\r
+ {\r
+ endEditing();\r
+ return;\r
+ }\r
\r
- if (!groupEditing && av.hasHiddenRows)\r
+ //System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");\r
+ //Selection spans a hidden region\r
+ if (fixedLeft < y1 && (fixedRight > y2 || fixedRight == -1))\r
+ {\r
+ if (startres >= y2)\r
{\r
- if (av.alignment.getSequenceAt(startseq).getHiddenSequences() != null)\r
- {\r
- groupEditing = true;\r
- }\r
+ fixedLeft = y2;\r
}\r
-\r
- //No group, but the sequence may represent a group\r
- if (groupEditing\r
- && sg == null\r
- && av.alignment.getSequenceAt(startseq).getHiddenSequences() == null)\r
+ else\r
{\r
- groupEditing = false;\r
+ fixedRight = y2 - 1;\r
}\r
+ }\r
+ }\r
\r
- SequenceI seq = av.alignment.getSequenceAt(startseq);\r
- StringBuffer message = new StringBuffer();\r
- if (groupEditing)\r
- message.append("Edit group:");\r
- else\r
- message.append("Edit sequence: "+seq.getName());\r
-\r
- if(insertGap)\r
- message.append(" insert ");\r
- else\r
- message.append(" delete ");\r
-\r
- message.append(Math.abs(startres-lastres)+" gaps.");\r
- ap.alignFrame.statusBar.setText(message.toString());\r
-\r
+ if (groupEditing)\r
+ {\r
+ Vector vseqs = sg.getSequences(av.hiddenRepSequences);\r
+ int g, groupSize = vseqs.size();\r
+ SequenceI[] groupSeqs = new SequenceI[groupSize];\r
+ for (g = 0; g < groupSeqs.length; g++)\r
+ {\r
+ groupSeqs[g] = (SequenceI) vseqs.elementAt(g);\r
+ }\r
\r
- //Are we editing within a selection group?\r
- if (groupEditing\r
- || (sg != null && sg.getSequences(true).contains(seq)))\r
+ // drag to right\r
+ if (insertGap)\r
+ {\r
+ //If the user has selected the whole sequence, and is dragging to\r
+ // the right, we can still extend the alignment and selectionGroup\r
+ if (sg.getStartRes() == 0\r
+ && sg.getEndRes() == fixedRight\r
+ && sg.getEndRes() == av.alignment.getWidth() - 1\r
+ )\r
{\r
- fixedColumns = true;\r
-\r
- //sg might be null as the user may only see 1 sequence,\r
- //but the sequence represents a group\r
- if (sg == null)\r
- {\r
- sg = new SequenceGroup(null, null, false, false, false, 0,\r
- av.alignment.getWidth()-1);\r
- sg.addSequence(av.alignment.getSequenceAt(startseq), false);\r
- }\r
-\r
- fixedLeft = sg.getStartRes();\r
+ sg.setEndRes(av.alignment.getWidth() + startres - lastres);\r
fixedRight = sg.getEndRes();\r
+ }\r
\r
- if ( (startres < fixedLeft && lastres >= fixedLeft)\r
- || (startres >= fixedLeft && lastres < fixedLeft)\r
- || (startres > fixedRight && lastres <=fixedRight)\r
- || (startres <= fixedRight && lastres > fixedRight))\r
- {\r
- endEditing();\r
- return;\r
- }\r
+ // Is it valid with fixed columns??\r
+ // Find the next gap before the end\r
+ // of the visible region boundary\r
+ boolean blank = false;\r
+ for (fixedRight = fixedRight;\r
+ fixedRight > lastres;\r
+ fixedRight--)\r
+ {\r
+ blank = true;\r
\r
- if (fixedLeft > startres)\r
+ for (g = 0; g < groupSize; g++)\r
{\r
- fixedRight = fixedLeft - 1;\r
- fixedLeft = 0;\r
+ for (int j = 0; j < startres - lastres; j++)\r
+ {\r
+ if (!jalview.util.Comparison.isGap(\r
+ groupSeqs[g].getCharAt(fixedRight - j)))\r
+ {\r
+ blank = false;\r
+ break;\r
+ }\r
+ }\r
}\r
- else if (fixedRight < startres)\r
+ if (blank)\r
{\r
- fixedLeft = fixedRight;\r
- fixedRight = -1;\r
+ break;\r
}\r
}\r
\r
-\r
- if(av.hasHiddenColumns )\r
+ if (!blank)\r
{\r
- fixedColumns = true;\r
- int y1 = av.getColumnSelection().getHiddenBoundaryLeft(startres);\r
- int y2 = av.getColumnSelection().getHiddenBoundaryRight(startres);\r
-\r
- if ( (insertGap && startres > y1 && lastres < y1)\r
- || (!insertGap && startres < y2 && lastres > y2))\r
+ if (sg.getSize() == av.alignment.getHeight())\r
+ {\r
+ if ( (av.hasHiddenColumns\r
+ &&\r
+ startres < av.getColumnSelection().getHiddenBoundaryRight(startres)))\r
{\r
endEditing();\r
return;\r
}\r
\r
- //System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~");\r
- //Selection spans a hidden region\r
- if(fixedLeft<y1 && (fixedRight>y2 || fixedRight==-1))\r
+ int alWidth = av.alignment.getWidth();\r
+ if (av.hasHiddenRows)\r
{\r
- if(startres>=y2)\r
+ int hwidth = av.alignment.getHiddenSequences().getWidth();\r
+ if (hwidth > alWidth)\r
{\r
- System.out.println("left of line");\r
- fixedLeft = y2;\r
+ alWidth = hwidth;\r
}\r
- else\r
- {\r
- System.out.println("right of line");\r
- fixedRight = y2 - 1;\r
- }\r
}\r
+ //We can still insert gaps if the selectionGroup\r
+ //contains all the sequences\r
+ sg.setEndRes(sg.getEndRes() + startres - lastres);\r
+ fixedRight = alWidth + startres - lastres;\r
+ }\r
+ else\r
+ {\r
+ endEditing();\r
+ return;\r
+ }\r
}\r
+ }\r
\r
+ // drag to left\r
+ else if (!insertGap)\r
+ {\r
+ /// Are we able to delete?\r
+ // ie are all columns blank?\r
\r
- if (groupEditing)\r
+ for (g = 0; g < groupSize; g++)\r
{\r
- // drag to right\r
- if (insertGap)\r
+ for (int j = startres; j < lastres; j++)\r
{\r
- //If the user has selected the whole sequence, and is dragging to\r
- // the right, we can still extend the alignment and selectionGroup\r
- if( sg.getStartRes() == 0\r
- && sg.getEndRes() == fixedRight\r
- && sg.getEndRes() == av.alignment.getWidth()-1\r
- )\r
- {\r
- sg.setEndRes(av.alignment.getWidth() + startres - lastres);\r
- fixedRight = sg.getEndRes();\r
- }\r
-\r
- // Is it valid with fixed columns??\r
- // Find the next gap before the end\r
- // of the visible region boundary\r
- boolean blank = false;\r
- for (fixedRight = fixedRight;\r
- fixedRight > lastres;\r
- fixedRight--)\r
+ if (groupSeqs[g].getLength() <= j)\r
{\r
- blank = true;\r
- for (int s = 0; s < sg.getSize(true); s++)\r
- {\r
- seq = (SequenceI)sg.getSequences(true).elementAt(s);\r
- for (int j = 0; j < startres - lastres; j++)\r
- {\r
- if (!jalview.util.Comparison.isGap(\r
- seq.getCharAt(fixedRight - j)))\r
- {\r
- blank = false;\r
- break;\r
- }\r
- }\r
- }\r
- if (blank)\r
- break;\r
+ continue;\r
}\r
\r
- if (!blank)\r
+ if (!jalview.util.Comparison.isGap(\r
+ groupSeqs[g].getCharAt(j)))\r
{\r
- if(sg.getSize(false) == av.alignment.getHeight())\r
- {\r
- //We can still insert gaps if the selectionGroup\r
- //contains all the sequences\r
- sg.setEndRes(sg.getEndRes()+startres-lastres);\r
- fixedRight = av.alignment.getWidth()+startres-lastres;\r
- }\r
- else\r
- {\r
- endEditing();\r
- return;\r
- }\r
+ // Not a gap, block edit not valid\r
+ endEditing();\r
+ return;\r
}\r
}\r
+ }\r
+ }\r
\r
-\r
- // drag to left\r
- else if(!insertGap)\r
+ if (insertGap)\r
+ {\r
+ // dragging to the right\r
+ if (fixedColumns && fixedRight != -1)\r
+ {\r
+ for (int j = lastres; j < startres; j++)\r
{\r
- /// Are we able to delete?\r
- // ie are all columns blank?\r
-\r
- for (int s = 0; s < sg.getSize(true); s++)\r
- {\r
- seq = (SequenceI)sg.getSequences(true).elementAt(s);\r
-\r
- for (int j = startres; j < lastres; j++)\r
- {\r
- if (seq.getSequence().length() <= j)\r
- {\r
- continue;\r
- }\r
-\r
- if (!jalview.util.Comparison.isGap(\r
- seq.getSequence().charAt(j)))\r
- {\r
- // Not a gap, block edit not valid\r
- endEditing();\r
- return;\r
- }\r
- }\r
- }\r
+ insertChar(j, groupSeqs, fixedRight);\r
}\r
-\r
-\r
- for (int i = 0; i < sg.getSize(true); i++)\r
+ }\r
+ else\r
+ {\r
+ editCommand.appendEdit(EditCommand.INSERT_GAP,\r
+ groupSeqs,\r
+ startres, startres - lastres,\r
+ av.alignment,\r
+ true);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ // dragging to the left\r
+ if (fixedColumns && fixedRight != -1)\r
+ {\r
+ for (int j = lastres; j > startres; j--)\r
{\r
- seq = (SequenceI) sg.getSequences(true).elementAt(i);\r
+ deleteChar(startres, groupSeqs, fixedRight);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ editCommand.appendEdit(EditCommand.DELETE_GAP,\r
+ groupSeqs,\r
+ startres, lastres - startres,\r
+ av.alignment,\r
+ true);\r
+ }\r
\r
- if (insertGap)\r
- {\r
- // dragging to the right\r
- for (int j = lastres; j < startres; j++)\r
- {\r
- if (fixedColumns && fixedRight != -1)\r
- {\r
- insertChar(j, seq, fixedRight);\r
- }\r
- else\r
- insertChar(j, seq);\r
- }\r
- }\r
- else\r
- {\r
- // dragging to the left\r
- for (int j = lastres; j > startres; j--)\r
- {\r
- if (fixedColumns && fixedRight != -1)\r
- {\r
- deleteChar(startres, seq, fixedRight);\r
- }\r
- else\r
- {\r
- deleteChar(startres, seq);\r
- }\r
- }\r
- }\r
+ }\r
+ }\r
+ else /////Editing a single sequence///////////\r
+ {\r
+ if (insertGap)\r
+ {\r
+ // dragging to the right\r
+ if (fixedColumns && fixedRight != -1)\r
+ {\r
+ for (int j = lastres; j < startres; j++)\r
+ {\r
+ insertChar(j, new SequenceI[]\r
+ {seq}, fixedRight);\r
}\r
}\r
- else /////Editing a single sequence///////////\r
+ else\r
{\r
- if (insertGap)\r
+ editCommand.appendEdit(EditCommand.INSERT_GAP,\r
+ new SequenceI[]\r
+ {seq},\r
+ lastres, startres - lastres,\r
+ av.alignment,\r
+ true);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ // dragging to the left\r
+ if (fixedColumns && fixedRight != -1)\r
+ {\r
+ for (int j = lastres; j > startres; j--)\r
{\r
- // dragging to the right\r
- for (int j = lastres; j < startres; j++)\r
+ if (!jalview.util.Comparison.isGap(seq.getCharAt(startres)))\r
{\r
- if (fixedColumns && fixedRight != -1)\r
- {\r
- /*if (sg!=null &&\r
- sg.getStartRes() == 0\r
- && sg.getEndRes() == fixedRight\r
- && !jalview.util.Comparison.isGap(seq.getCharAt(fixedRight)))\r
- {\r
- System.out.println("still here");\r
- //Single sequence edit, whole sequence selected,\r
- //extend the selection group\r
- sg.setEndRes(av.alignment.getWidth() -1 + startres - lastres);\r
- fixedColumns = false;\r
- insertChar(j, seq);\r
- }\r
- else*/\r
- insertChar(j, seq, fixedRight);\r
- }\r
- else\r
- insertChar(j, seq);\r
+ endEditing();\r
+ break;\r
}\r
+ deleteChar(startres, new SequenceI[]\r
+ {seq}, fixedRight);\r
}\r
- else\r
+ }\r
+ else\r
+ {\r
+ //could be a keyboard edit trying to delete none gaps\r
+ int max = 0;\r
+ for (int m = startres; m < lastres; m++)\r
{\r
- // dragging to the left\r
- for (int j = lastres; j > startres; j--)\r
+ if (!jalview.util.Comparison.isGap(seq.getCharAt(m)))\r
{\r
- if (fixedColumns && fixedRight != -1)\r
- {\r
- deleteChar(startres, seq, fixedRight);\r
- }\r
- else\r
- {\r
- deleteChar(startres, seq);\r
- }\r
+ break;\r
}\r
+ max++;\r
}\r
- }\r
\r
- lastres = startres;\r
- seqCanvas.repaint();\r
+ if (max > 0)\r
+ {\r
+ editCommand.appendEdit(EditCommand.DELETE_GAP,\r
+ new SequenceI[]\r
+ {seq},\r
+ startres, max,\r
+ av.alignment,\r
+ true);\r
+ }\r
+ }\r
+ }\r
}\r
\r
+ lastres = startres;\r
+ seqCanvas.repaint();\r
+ }\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param j DOCUMENT ME!\r
- * @param seq DOCUMENT ME!\r
- */\r
- void insertChar(int j, SequenceI seq)\r
- {\r
- seq.insertCharAt(j, av.getGapCharacter());\r
- seqEditOccurred = true;\r
- }\r
-\r
- void insertChar(int j, SequenceI seq, int fixedColumn)\r
+ void insertChar(int j, SequenceI[] seq, int fixedColumn)\r
+ {\r
+ int blankColumn = fixedColumn;\r
+ for (int s = 0; s < seq.length; s++)\r
{\r
//Find the next gap before the end of the visible region boundary\r
//If lastCol > j, theres a boundary after the gap insertion\r
- int blankColumn = fixedColumn;\r
+\r
for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)\r
{\r
- if (jalview.util.Comparison.isGap(seq.getCharAt(blankColumn)))\r
+ if (jalview.util.Comparison.isGap(seq[s].getCharAt(blankColumn)))\r
{\r
//Theres a space, so break and insert the gap\r
break;\r
\r
if (blankColumn <= j)\r
{\r
+ blankColumn = fixedColumn;\r
endEditing();\r
return;\r
}\r
+ }\r
+\r
+ editCommand.appendEdit(EditCommand.DELETE_GAP,\r
+ seq,\r
+ blankColumn, 1, av.alignment, true);\r
+\r
+ editCommand.appendEdit(EditCommand.INSERT_GAP,\r
+ seq,\r
+ j, 1, av.alignment,\r
+ true);\r
+\r
+ }\r
+\r
+ void deleteChar(int j, SequenceI[] seq, int fixedColumn)\r
+ {\r
+\r
+ editCommand.appendEdit(EditCommand.DELETE_GAP,\r
+ seq,\r
+ j, 1, av.alignment, true);\r
+\r
+ editCommand.appendEdit(EditCommand.INSERT_GAP,\r
+ seq,\r
+ fixedColumn, 1, av.alignment, true);\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void mouseEntered(MouseEvent e)\r
+ {\r
+ if (oldSeq < 0)\r
+ {\r
+ oldSeq = 0;\r
+ }\r
+\r
+ if (scrollThread != null)\r
+ {\r
+ scrollThread.running = false;\r
+ scrollThread = null;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void mouseExited(MouseEvent e)\r
+ {\r
+ if (av.getWrapAlignment())\r
+ {\r
+ return;\r
+ }\r
+\r
+ if (mouseDragging)\r
+ {\r
+ scrollThread = new ScrollThread();\r
+ }\r
+ }\r
\r
- if (!jalview.util.Comparison.isGap(seq.getCharAt(blankColumn)))\r
+ public void mouseClicked(MouseEvent evt)\r
+ {\r
+ SequenceI sequence = av.alignment.getSequenceAt(findSeq(evt));\r
+ if (evt.getClickCount() > 1)\r
+ {\r
+ if (av.getSelectionGroup().getSize() == 1\r
+ && av.getSelectionGroup().getEndRes()\r
+ - av.getSelectionGroup().getStartRes() < 2)\r
{\r
- //Just Checking\r
- System.out.println("Tried removing residue (INSERT)"+seq.getCharAt(fixedColumn));\r
- return;\r
+ av.setSelectionGroup(null);\r
}\r
\r
- seq.deleteCharAt(blankColumn);\r
- seq.insertCharAt(j, av.getGapCharacter());\r
- seqEditOccurred = true;\r
- }\r
+ SequenceFeature[] features = findFeaturesAtRes(\r
+ sequence.getDatasetSequence(),\r
+ sequence.findPosition(findRes(evt))\r
+ );\r
\r
- void deleteChar(int j, SequenceI seq, int fixedColumn)\r
- {\r
- if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))\r
+ if (features != null && features.length > 0)\r
{\r
- ap.alignFrame.statusBar.setText(\r
- "End editing: Tried removing residue " + seq.getCharAt(j));\r
- return;\r
+ SearchResults highlight = new SearchResults();\r
+ highlight.addResult(sequence,\r
+ features[0].getBegin(),\r
+ features[0].getEnd());\r
+ seqCanvas.highlightSearchResults(highlight);\r
}\r
+ if (features != null && features.length > 0)\r
+ {\r
+ seqCanvas.getFeatureRenderer().amendFeatures(\r
+ new SequenceI[]\r
+ {sequence}, features, false, ap);\r
\r
- seq.deleteCharAt(j);\r
- seq.insertCharAt(fixedColumn, av.getGapCharacter());\r
- seqEditOccurred = true;\r
+ seqCanvas.highlightSearchResults(null);\r
+ }\r
}\r
+ }\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param j DOCUMENT ME!\r
- * @param seq DOCUMENT ME!\r
- */\r
- void deleteChar(int j, SequenceI seq)\r
- {\r
- if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))\r
+ public void mouseWheelMoved(MouseWheelEvent e)\r
+ {\r
+ e.consume();\r
+ if (e.getWheelRotation() > 0)\r
{\r
- ap.alignFrame.statusBar.setText(\r
- "End editing: Tried removing residue " + seq.getCharAt(j));\r
- return;\r
+ ap.scrollUp(false);\r
+ }\r
+ else\r
+ {\r
+ ap.scrollUp(true);\r
}\r
+ }\r
\r
- seq.deleteCharAt(j);\r
- seqEditOccurred = true;\r
- seqCanvas.repaint();\r
- }\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void mouseEntered(MouseEvent e)\r
- {\r
- if(oldSeq < 0)\r
- oldSeq = 0;\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param evt DOCUMENT ME!\r
+ */\r
+ public void doMousePressedDefineMode(MouseEvent evt)\r
+ {\r
+ int res = findRes(evt);\r
+ int seq = findSeq(evt);\r
+ oldSeq = seq;\r
\r
- if (scrollThread != null)\r
- {\r
- scrollThread.running = false;\r
- scrollThread = null;\r
- }\r
- }\r
+ startWrapBlock = wrappedBlock;\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void mouseExited(MouseEvent e)\r
+ if (av.wrapAlignment && seq > av.alignment.getHeight())\r
{\r
- if (av.getWrapAlignment())\r
- {\r
- return;\r
- }\r
+ JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+ "Cannot edit annotations in wrapped view.",\r
+ "Wrapped view - no edit",\r
+ JOptionPane.WARNING_MESSAGE);\r
+ return;\r
+ }\r
\r
- if (mouseDragging)\r
- {\r
- scrollThread = new ScrollThread();\r
- }\r
+ if (seq < 0 || res < 0)\r
+ {\r
+ return;\r
}\r
\r
- public void mouseClicked(MouseEvent evt)\r
- {}\r
+ SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq);\r
\r
- public void mouseWheelMoved(MouseWheelEvent e)\r
+ if ( (sequence == null) || (res > sequence.getLength()))\r
{\r
- e.consume();\r
- /* if (mouseWheelPressed)\r
- {\r
- Font font = av.getFont();\r
- int fontSize = font.getSize();\r
- if (e.getWheelRotation() > 0 && fontSize < 51)\r
- fontSize++;\r
- else if (fontSize > 1)\r
- fontSize--;\r
-\r
+ return;\r
+ }\r
\r
+ stretchGroup = av.getSelectionGroup();\r
\r
- av.setFont(new Font(font.getName(), font.getStyle(), fontSize));\r
+ if (stretchGroup == null)\r
+ {\r
+ stretchGroup = av.alignment.findGroup(sequence);\r
\r
- ap.fontChanged();\r
+ if ( (stretchGroup != null) && (res > stretchGroup.getStartRes()) &&\r
+ (res < stretchGroup.getEndRes()))\r
+ {\r
+ av.setSelectionGroup(stretchGroup);\r
}\r
- else*/\r
+ else\r
{\r
- if (e.getWheelRotation() > 0)\r
- ap.scrollUp(false);\r
- else\r
- ap.scrollUp(true);\r
+ stretchGroup = null;\r
}\r
-\r
}\r
+ else if (!stretchGroup.getSequences(null).contains(sequence) ||\r
+ (stretchGroup.getStartRes() > res) ||\r
+ (stretchGroup.getEndRes() < res))\r
+ {\r
+ stretchGroup = null;\r
\r
+ SequenceGroup[] allGroups = av.alignment.findAllGroups(sequence);\r
\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param i DOCUMENT ME!\r
- */\r
- void editOccurred()\r
- {\r
- if (!seqEditOccurred)\r
+ if (allGroups != null)\r
{\r
- ap.alignFrame.historyList.pop();\r
- ap.alignFrame.updateEditMenuBar();\r
+ for (int i = 0; i < allGroups.length; i++)\r
+ {\r
+ if ( (allGroups[i].getStartRes() <= res) &&\r
+ (allGroups[i].getEndRes() >= res))\r
+ {\r
+ stretchGroup = allGroups[i];\r
+ break;\r
+ }\r
+ }\r
}\r
\r
- endEditing();\r
-\r
- av.firePropertyChange("alignment", null,av.getAlignment().getSequences());\r
+ av.setSelectionGroup(stretchGroup);\r
\r
}\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param evt DOCUMENT ME!\r
- */\r
- public void doMousePressedDefineMode(MouseEvent evt)\r
+ if (javax.swing.SwingUtilities.isRightMouseButton(evt))\r
{\r
- int res = findRes(evt);\r
- int seq = findSeq(evt);\r
- oldSeq = seq;\r
-\r
- startWrapBlock=wrappedBlock;\r
-\r
- if(av.wrapAlignment && seq>av.alignment.getHeight())\r
+ SequenceFeature [] allFeatures = findFeaturesAtRes(sequence.getDatasetSequence(),\r
+ sequence.findPosition(res));\r
+ Vector links = new Vector();\r
+ for (int i = 0; i < allFeatures.length; i++)\r
{\r
- JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
- "Cannot edit annotations in wrapped view.",\r
- "Wrapped view - no edit",\r
- JOptionPane.WARNING_MESSAGE);\r
- return;\r
- }\r
-\r
- if(seq<0 || res<0)\r
- return;\r
-\r
- SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq);\r
-\r
- if ((sequence == null) || (res > sequence.getLength()))\r
+ if (allFeatures[i].links != null)\r
{\r
- return;\r
+ for (int j = 0; j < allFeatures[i].links.size(); j++)\r
+ {\r
+ links.addElement(allFeatures[i].links.elementAt(j));\r
+ }\r
}\r
+ }\r
\r
- stretchGroup = av.getSelectionGroup();\r
-\r
- if (stretchGroup == null)\r
- {\r
- stretchGroup = av.alignment.findGroup(sequence);\r
-\r
- if ((stretchGroup != null) && (res > stretchGroup.getStartRes()) &&\r
- (res < stretchGroup.getEndRes()))\r
- {\r
- av.setSelectionGroup(stretchGroup);\r
- }\r
- else\r
- {\r
- stretchGroup = null;\r
- }\r
- }\r
- else if (!stretchGroup.getSequences(false).contains(sequence) ||\r
- (stretchGroup.getStartRes() > res) ||\r
- (stretchGroup.getEndRes() < res))\r
- {\r
- stretchGroup = null;\r
+ jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(ap, null, links);\r
+ pop.show(this, evt.getX(), evt.getY());\r
+ return;\r
+ }\r
\r
- SequenceGroup[] allGroups = av.alignment.findAllGroups(sequence);\r
+ if (av.cursorMode)\r
+ {\r
+ seqCanvas.cursorX = findRes(evt);\r
+ seqCanvas.cursorY = findSeq(evt);\r
+ seqCanvas.repaint();\r
+ return;\r
+ }\r
\r
- if (allGroups != null)\r
- {\r
- for (int i = 0; i < allGroups.length; i++)\r
- {\r
- if ((allGroups[i].getStartRes() <= res) &&\r
- (allGroups[i].getEndRes() >= res))\r
- {\r
- stretchGroup = allGroups[i];\r
- break;\r
- }\r
- }\r
- }\r
+ if (stretchGroup == null)\r
+ {\r
+ //Only if left mouse button do we want to change group sizes\r
\r
- av.setSelectionGroup(stretchGroup);\r
+ // define a new group here\r
+ SequenceGroup sg = new SequenceGroup();\r
+ sg.setStartRes(res);\r
+ sg.setEndRes(res);\r
+ sg.addSequence(sequence, false);\r
+ av.setSelectionGroup(sg);\r
+ stretchGroup = sg;\r
\r
- }\r
+ if (av.getConservationSelected())\r
+ {\r
+ SliderPanel.setConservationSlider(ap,\r
+ av.getGlobalColourScheme(),\r
+ "Background");\r
+ }\r
\r
- if (av.cursorMode)\r
- {\r
- seqCanvas.cursorX = findRes(evt);\r
- seqCanvas.cursorY = findSeq(evt);\r
- seqCanvas.repaint();\r
- return;\r
- }\r
+ if (av.getAbovePIDThreshold())\r
+ {\r
+ SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(),\r
+ "Background");\r
+ }\r
+ if ( (stretchGroup != null) && (stretchGroup.getEndRes() == res))\r
+ {\r
+ // Edit end res position of selected group\r
+ changeEndRes = true;\r
+ }\r
+ else if ( (stretchGroup != null) &&\r
+ (stretchGroup.getStartRes() == res))\r
+ {\r
+ // Edit end res position of selected group\r
+ changeStartRes = true;\r
+ }\r
+ stretchGroup.getWidth();\r
+ }\r
\r
+ seqCanvas.repaint();\r
+ }\r
\r
- if (javax.swing.SwingUtilities.isRightMouseButton(evt))\r
- {\r
- Vector allFeatures = getAllFeaturesAtRes(sequence.getDatasetSequence(),\r
- sequence.findPosition(res));\r
- Vector links = new Vector();\r
- for (int i = 0; i < allFeatures.size(); i++)\r
- {\r
- SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(i);\r
- if (sf.links != null)\r
- {\r
- for (int j = 0; j < sf.links.size(); j++)\r
- {\r
- links.addElement(sf.links.elementAt(j));\r
- }\r
- }\r
- }\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param evt DOCUMENT ME!\r
+ */\r
+ public void doMouseReleasedDefineMode(MouseEvent evt)\r
+ {\r
+ if (stretchGroup == null)\r
+ {\r
+ return;\r
+ }\r
\r
- jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(ap, null, links);\r
- pop.show(this, evt.getX(), evt.getY());\r
+ if (stretchGroup.cs != null)\r
+ {\r
+ if (stretchGroup.cs instanceof ClustalxColourScheme)\r
+ {\r
+ ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX(\r
+ stretchGroup.getSequences(av.hiddenRepSequences),\r
+ stretchGroup.getWidth());\r
+ }\r
\r
- }\r
- else if (stretchGroup == null)\r
- {\r
- //Only if left mouse button do we want to change group sizes\r
+ if (stretchGroup.cs instanceof Blosum62ColourScheme\r
+ || stretchGroup.cs instanceof PIDColourScheme\r
+ || stretchGroup.cs.conservationApplied()\r
+ || stretchGroup.cs.getThreshold() > 0)\r
+ {\r
+ stretchGroup.recalcConservation();\r
+ }\r
\r
- // define a new group here\r
- SequenceGroup sg = new SequenceGroup();\r
- sg.setStartRes(res);\r
- sg.setEndRes(res);\r
- sg.addSequence(sequence, false);\r
- av.setSelectionGroup(sg);\r
- stretchGroup = sg;\r
+ if (stretchGroup.cs.conservationApplied())\r
+ {\r
+ SliderPanel.setConservationSlider(ap, stretchGroup.cs,\r
+ stretchGroup.getName());\r
+ }\r
+ else\r
+ {\r
+ SliderPanel.setPIDSliderSource(ap, stretchGroup.cs,\r
+ stretchGroup.getName());\r
+ }\r
+ PaintRefresher.Refresh(this, av.getSequenceSetId());\r
+ ap.paintAlignment(true);\r
+ }\r
\r
- if (av.getConservationSelected())\r
- {\r
- SliderPanel.setConservationSlider(ap,\r
- av.getGlobalColourScheme(),\r
- "Background");\r
- }\r
+ changeEndRes = false;\r
+ changeStartRes = false;\r
+ stretchGroup = null;\r
\r
- if (av.getAbovePIDThreshold())\r
- {\r
- SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(),\r
- "Background");\r
- }\r
- if ( (stretchGroup != null) && (stretchGroup.getEndRes() == res))\r
- {\r
- // Edit end res position of selected group\r
- changeEndRes = true;\r
- }\r
- else if ( (stretchGroup != null) &&\r
- (stretchGroup.getStartRes() == res))\r
- {\r
- // Edit end res position of selected group\r
- changeStartRes = true;\r
- }\r
- stretchGroup.getWidth();\r
- }\r
+ }\r
\r
- seqCanvas.repaint();\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param evt DOCUMENT ME!\r
+ */\r
+ public void doMouseDraggedDefineMode(MouseEvent evt)\r
+ {\r
+ int res = findRes(evt);\r
+ int y = findSeq(evt);\r
+\r
+ if (wrappedBlock != startWrapBlock)\r
+ {\r
+ return;\r
}\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param evt DOCUMENT ME!\r
- */\r
- public void doMouseReleasedDefineMode(MouseEvent evt)\r
+ if (stretchGroup == null)\r
{\r
- if (stretchGroup == null)\r
- {\r
- return;\r
- }\r
-\r
-\r
- if(stretchGroup.cs!=null)\r
- {\r
- if (stretchGroup.cs instanceof ClustalxColourScheme)\r
- {\r
- ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX(\r
- stretchGroup.getSequences(true),\r
- stretchGroup.getWidth());\r
- }\r
+ return;\r
+ }\r
\r
- if (stretchGroup.cs.conservationApplied())\r
- {\r
- SliderPanel.setConservationSlider(ap, stretchGroup.cs,\r
- stretchGroup.getName());\r
- stretchGroup.recalcConservation();\r
- }\r
- else\r
- {\r
- SliderPanel.setPIDSliderSource(ap, stretchGroup.cs,\r
- stretchGroup.getName());\r
- }\r
- }\r
- changeEndRes = false;\r
- changeStartRes = false;\r
- stretchGroup = null;\r
- PaintRefresher.Refresh(av.alignment);\r
+ if (res >= av.alignment.getWidth())\r
+ {\r
+ res = av.alignment.getWidth() - 1;\r
}\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param evt DOCUMENT ME!\r
- */\r
- public void doMouseDraggedDefineMode(MouseEvent evt)\r
+ if (stretchGroup.getEndRes() == res)\r
+ {\r
+ // Edit end res position of selected group\r
+ changeEndRes = true;\r
+ }\r
+ else if (stretchGroup.getStartRes() == res)\r
{\r
- int res = findRes(evt);\r
- int y = findSeq(evt);\r
+ // Edit start res position of selected group\r
+ changeStartRes = true;\r
+ }\r
\r
- if(wrappedBlock!=startWrapBlock)\r
- return;\r
+ if (res < av.getStartRes())\r
+ {\r
+ res = av.getStartRes();\r
+ }\r
\r
- if (stretchGroup == null)\r
- {\r
- return;\r
- }\r
+ if (changeEndRes)\r
+ {\r
+ if (res > (stretchGroup.getStartRes() - 1))\r
+ {\r
+ stretchGroup.setEndRes(res);\r
+ }\r
+ }\r
+ else if (changeStartRes)\r
+ {\r
+ if (res < (stretchGroup.getEndRes() + 1))\r
+ {\r
+ stretchGroup.setStartRes(res);\r
+ }\r
+ }\r
\r
+ int dragDirection = 0;\r
\r
- if(y > av.alignment.getHeight())\r
- {\r
- y = av.alignment.getHeight() -1;\r
- }\r
- if(res> av.alignment.getWidth())\r
- {\r
- res = av.alignment.getWidth()-1;\r
- }\r
+ if (y > oldSeq)\r
+ {\r
+ dragDirection = 1;\r
+ }\r
+ else if (y < oldSeq)\r
+ {\r
+ dragDirection = -1;\r
+ }\r
\r
- if (stretchGroup.getEndRes() == res)\r
- {\r
- // Edit end res position of selected group\r
- changeEndRes = true;\r
- }\r
- else if (stretchGroup.getStartRes() == res)\r
- {\r
- // Edit start res position of selected group\r
- changeStartRes = true;\r
- }\r
+ while ( (y != oldSeq) && (oldSeq > -1) && (y < av.alignment.getHeight()))\r
+ {\r
+ // This routine ensures we don't skip any sequences, as the\r
+ // selection is quite slow.\r
+ Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);\r
\r
- if (res < av.getStartRes())\r
- {\r
- res = av.getStartRes();\r
- }\r
+ oldSeq += dragDirection;\r
\r
- if (changeEndRes)\r
- {\r
- if (res > (stretchGroup.getStartRes() - 1))\r
- {\r
- stretchGroup.setEndRes(res);\r
- }\r
- }\r
- else if (changeStartRes)\r
- {\r
- if (res < (stretchGroup.getEndRes() + 1))\r
- {\r
- stretchGroup.setStartRes(res);\r
- }\r
- }\r
+ if (oldSeq < 0)\r
+ {\r
+ break;\r
+ }\r
\r
- int dragDirection = 0;\r
+ Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);\r
\r
- if (y > oldSeq)\r
- {\r
- dragDirection = 1;\r
- }\r
- else if (y < oldSeq)\r
+ if (stretchGroup.getSequences(null).contains(nextSeq))\r
+ {\r
+ stretchGroup.deleteSequence(seq, false);\r
+ }\r
+ else\r
+ {\r
+ if (seq != null)\r
{\r
- dragDirection = -1;\r
+ stretchGroup.addSequence(seq, false);\r
}\r
\r
+ stretchGroup.addSequence(nextSeq, false);\r
+ }\r
+ }\r
\r
- while ((y != oldSeq) && (oldSeq > -1) && (y < av.alignment.getHeight()))\r
- {\r
- // This routine ensures we don't skip any sequences, as the\r
- // selection is quite slow.\r
- Sequence seq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);\r
-\r
- oldSeq += dragDirection;\r
+ if (oldSeq < 0)\r
+ {\r
+ oldSeq = -1;\r
+ }\r
\r
- if(oldSeq<0)\r
- break;\r
+ mouseDragging = true;\r
\r
- Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);\r
+ if (scrollThread != null)\r
+ {\r
+ scrollThread.setEvent(evt);\r
+ }\r
\r
- if (stretchGroup.getSequences(false).contains(nextSeq))\r
- {\r
- stretchGroup.deleteSequence(seq, false);\r
- }\r
- else\r
- {\r
- if (seq != null)\r
- {\r
- stretchGroup.addSequence(seq, false);\r
- }\r
+ seqCanvas.repaint();\r
+ }\r
\r
- stretchGroup.addSequence(nextSeq, false);\r
- }\r
- }\r
+ void scrollCanvas(MouseEvent evt)\r
+ {\r
+ if (evt == null)\r
+ {\r
+ if (scrollThread != null)\r
+ {\r
+ scrollThread.running = false;\r
+ scrollThread = null;\r
+ }\r
+ mouseDragging = false;\r
+ }\r
+ else\r
+ {\r
+ if (scrollThread == null)\r
+ {\r
+ scrollThread = new ScrollThread();\r
+ }\r
\r
- if(oldSeq < 0)\r
- oldSeq = -1;\r
+ mouseDragging = true;\r
+ scrollThread.setEvent(evt);\r
+ }\r
\r
- mouseDragging = true;\r
+ }\r
\r
- if (scrollThread != null)\r
- {\r
- scrollThread.setEvent(evt);\r
- }\r
+ // this class allows scrolling off the bottom of the visible alignment\r
+ class ScrollThread\r
+ extends Thread\r
+ {\r
+ MouseEvent evt;\r
+ boolean running = false;\r
\r
- seqCanvas.repaint();\r
+ public ScrollThread()\r
+ {\r
+ start();\r
}\r
\r
- void scrollCanvas(MouseEvent evt)\r
+ public void setEvent(MouseEvent e)\r
{\r
- if(evt==null)\r
- {\r
- if(scrollThread!=null)\r
- {\r
- scrollThread.running = false;\r
- scrollThread = null;\r
- }\r
- mouseDragging = false;\r
- }\r
- else\r
- {\r
- if (scrollThread == null)\r
- scrollThread = new ScrollThread();\r
-\r
- mouseDragging = true;\r
- scrollThread.setEvent(evt);\r
- }\r
-\r
+ evt = e;\r
}\r
\r
+ public void stopScrolling()\r
+ {\r
+ running = false;\r
+ }\r
\r
- // this class allows scrolling off the bottom of the visible alignment\r
- class ScrollThread extends Thread\r
+ public void run()\r
{\r
- MouseEvent evt;\r
- boolean running = false;\r
+ running = true;\r
\r
- public ScrollThread()\r
+ while (running)\r
+ {\r
+ if (evt != null)\r
{\r
- start();\r
- }\r
+ if (mouseDragging && (evt.getY() < 0) &&\r
+ (av.getStartSeq() > 0))\r
+ {\r
+ running = ap.scrollUp(true);\r
+ }\r
\r
- public void setEvent(MouseEvent e)\r
- {\r
- evt = e;\r
+ if (mouseDragging && (evt.getY() >= getHeight()) &&\r
+ (av.alignment.getHeight() > av.getEndSeq()))\r
+ {\r
+ running = ap.scrollUp(false);\r
+ }\r
+\r
+ if (mouseDragging && (evt.getX() < 0))\r
+ {\r
+ running = ap.scrollRight(false);\r
+ }\r
+ else if (mouseDragging && (evt.getX() >= getWidth()))\r
+ {\r
+ running = ap.scrollRight(true);\r
+ }\r
}\r
\r
- public void stopScrolling()\r
+ try\r
{\r
- running = false;\r
+ Thread.sleep(20);\r
}\r
-\r
- public void run()\r
+ catch (Exception ex)\r
{\r
- running = true;\r
-\r
- while (running)\r
- {\r
- if (evt != null)\r
- {\r
- if (mouseDragging && (evt.getY() < 0) &&\r
- (av.getStartSeq() > 0))\r
- {\r
- running = ap.scrollUp(true);\r
- }\r
-\r
- if (mouseDragging && (evt.getY() >= getHeight()) &&\r
- (av.alignment.getHeight() > av.getEndSeq()))\r
- {\r
- running = ap.scrollUp(false);\r
- }\r
-\r
- if (mouseDragging && (evt.getX() < 0))\r
- {\r
- running = ap.scrollRight(false);\r
- }\r
- else if (mouseDragging && (evt.getX() >= getWidth()))\r
- {\r
- running = ap.scrollRight(true);\r
- }\r
- }\r
-\r
- try\r
- {\r
- Thread.sleep(20);\r
- }\r
- catch (Exception ex)\r
- {\r
- }\r
- }\r
}\r
+ }\r
}\r
+ }\r
}\r