package jalview.gui;\r
\r
import jalview.datamodel.*;\r
-\r
+import jalview.commands.EditCommand;\r
import jalview.schemes.*;\r
\r
import java.awt.*;\r
import java.awt.event.*;\r
-\r
import javax.swing.*;\r
-\r
import java.util.Vector;\r
\r
\r
MouseMotionListener, MouseWheelListener\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
- StringBuffer tooltipText = new StringBuffer("<html>");\r
- String tmpString;\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
+ /** 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
+ /**\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
- 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
+ addMouseMotionListener(this);\r
+ addMouseListener(this);\r
+ addMouseWheelListener(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
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
- if(cwidth<1)\r
- return 0;\r
+ int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());\r
+ if (cwidth < 1)\r
+ return 0;\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
+ res = av.getColumnSelection().adjustForHiddenColumns(res);\r
\r
return res;\r
\r
- }\r
+ }\r
\r
- int findSeq(MouseEvent evt)\r
- {\r
- int seq = 0;\r
- int y = evt.getY();\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
- hgap += av.charHeight;\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
+ int cHeight = av.getAlignment().getHeight() * av.charHeight\r
+ + hgap + seqCanvas.getAnnotationHeight();\r
\r
- y -= hgap;\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
+ 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
+ return seq;\r
+ }\r
+\r
+ SequenceFeature[] findFeaturesAtRes(SequenceI sequence, int res)\r
+ {\r
+ Vector tmp = new Vector();\r
+ SequenceFeature[] features = sequence.getSequenceFeatures();\r
+\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
+ continue;\r
+\r
+ if ( (features[i].getBegin() <= sequence.findPosition(res)) &&\r
+ (features[i].getEnd() >= sequence.findPosition(res)))\r
+ {\r
+ tmp.addElement(features[i]);\r
+ }\r
+ }\r
+ }\r
+\r
+ features = new SequenceFeature[tmp.size()];\r
+ for(int i=0; i<tmp.size(); i++)\r
+ {\r
+ features[i] = (SequenceFeature)tmp.elementAt(i);\r
+ }\r
+\r
+ return features;\r
+ }\r
\r
Vector getAllFeaturesAtRes(SequenceI seq, int res)\r
{\r
\r
void endEditing()\r
{\r
+ if (editCommand!=null && editCommand.getSize() > 0)\r
+ {\r
+ ap.alignFrame.addHistoryItem(editCommand);\r
+ av.firePropertyChange("alignment", null,\r
+ av.getAlignment().getSequences());\r
+ }\r
+\r
startseq = -1;\r
lastres = -1;\r
- seqEditOccurred = false;\r
editingSeqs = false;\r
groupEditing = false;\r
keyboardNo1 = null;\r
keyboardNo2 = null;\r
+ editCommand = null;\r
}\r
\r
void setCursorRow()\r
\r
void insertGapAtCursor(boolean group)\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
+ endEditing();\r
}\r
\r
void deleteGapAtCursor(boolean group)\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
+ endEditing();\r
}\r
\r
void numberPressed(char value)\r
return;\r
}\r
\r
- editOccurred();\r
+ endEditing();\r
\r
ap.repaint();\r
}\r
return;\r
}\r
\r
-\r
-\r
int seq = findSeq(evt);\r
int res = findRes(evt);\r
\r
if(seq<0 || res<0)\r
return;\r
\r
- ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence",\r
- av.alignment, HistoryItem.EDIT));\r
-\r
if ((seq < av.getAlignment().getHeight()) &&\r
(res < av.getAlignment().getSequenceAt(seq).getLength()))\r
{\r
{\r
tooltipText.setLength(6); // Cuts the buffer back to <html>\r
\r
- SequenceFeature [] features = sequence.getDatasetSequence().getSequenceFeatures();\r
+ SequenceFeature[] features = findFeaturesAtRes(\r
+ sequence.getDatasetSequence(), res);\r
+\r
if(features!=null)\r
{\r
for (int i = 0; i < features.length; i++)\r
{\r
-\r
- if ( (features[i].getBegin() <= sequence.findPosition(res)) &&\r
- (features[i].getEnd() >= sequence.findPosition(res)))\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
tooltipText.append(" <img src=\"" + linkImageURL + "\">");\r
\r
}\r
- }\r
- else if(features[i].begin==0 && features[i].end==0)\r
+\r
+ // else if(features[i].begin==0 && features[i].end==0)\r
{\r
// seqSpecific.append(features[i].featureGroup+": "\r
// + features[i].getType()+" "\r
}\r
\r
\r
-\r
if(tooltipText.length()==6) // <html></html>\r
{\r
\r
SequenceI seq = av.alignment.getSequenceAt(startseq);\r
StringBuffer message = new StringBuffer();\r
if (groupEditing)\r
- message.append("Edit group:");\r
+ {\r
+ message.append("Edit group:");\r
+ if (editCommand == null)\r
+ editCommand = new EditCommand("Edit Group");\r
+ }\r
else\r
- message.append("Edit sequence: "+seq.getName());\r
+ {\r
+ message.append("Edit sequence: " + seq.getName());\r
+ String label = seq.getName();\r
+ if(label.length()>10)\r
+ label = label.substring(0,10);\r
+ if(editCommand==null)\r
+ editCommand = new EditCommand("Edit "+label);\r
+ }\r
\r
if(insertGap)\r
message.append(" insert ");\r
}\r
}\r
\r
-\r
- for (g = 0; g < groupSize; g++)\r
- {\r
if (insertGap)\r
{\r
// dragging to the right\r
- for (int j = lastres; j < startres; j++)\r
+ if (fixedColumns && fixedRight != -1)\r
{\r
- if (fixedColumns && fixedRight != -1)\r
+ for (int j = lastres; j < startres; j++)\r
{\r
- insertChar(j, groupSeqs[g], fixedRight);\r
+ insertChar(j, groupSeqs, fixedRight);\r
}\r
- else\r
- insertChar(j, groupSeqs[g]);\r
+ }\r
+ else\r
+ {\r
+ editCommand.appendEdit(EditCommand.INSERT_GAP,\r
+ groupSeqs,\r
+ startres, startres-lastres,\r
+ av.getGapCharacter(),\r
+ true);\r
}\r
}\r
else\r
{\r
// dragging to the left\r
- for (int j = lastres; j > startres; j--)\r
+ if (fixedColumns && fixedRight != -1)\r
{\r
- if (fixedColumns && fixedRight != -1)\r
+ for (int j = lastres; j > startres; j--)\r
{\r
- deleteChar(startres, groupSeqs[g], fixedRight);\r
- }\r
- else\r
- {\r
- deleteChar(startres, groupSeqs[g]);\r
+ deleteChar(startres, groupSeqs, fixedRight);\r
}\r
}\r
+ else\r
+ editCommand.appendEdit(EditCommand.DELETE_GAP,\r
+ groupSeqs,\r
+ startres, lastres - startres,\r
+ av.getGapCharacter(),\r
+ true);\r
+\r
}\r
- }\r
}\r
else /////Editing a single sequence///////////\r
{\r
if (insertGap)\r
{\r
// dragging to the right\r
- for (int j = lastres; j < startres; j++)\r
+ if (fixedColumns && fixedRight != -1)\r
{\r
- if (fixedColumns && fixedRight != -1)\r
+ for (int j = lastres; j < startres; j++)\r
{\r
- insertChar(j, seq, fixedRight);\r
+ insertChar(j, new SequenceI[]{seq}, fixedRight);\r
}\r
- else\r
- insertChar(j, seq);\r
+ }\r
+ else\r
+ {\r
+ editCommand.appendEdit(EditCommand.INSERT_GAP,\r
+ new SequenceI[]\r
+ {seq},\r
+ lastres, startres-lastres,\r
+ av.getGapCharacter(),\r
+ true);\r
}\r
}\r
else\r
{\r
// dragging to the left\r
- for (int j = lastres; j > startres; j--)\r
+ if (fixedColumns && fixedRight != -1)\r
{\r
- if (fixedColumns && fixedRight != -1)\r
+ for (int j = lastres; j > startres; j--)\r
{\r
- deleteChar(startres, seq, fixedRight);\r
+ if (!jalview.util.Comparison.isGap(seq.getCharAt(startres)))\r
+ {\r
+ endEditing();\r
+ break;\r
+ }\r
+ deleteChar(startres, new SequenceI[]{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
- deleteChar(startres, seq);\r
+ if(!jalview.util.Comparison.isGap(seq.getCharAt(m)))\r
+ break;\r
+ max++;\r
+ }\r
+\r
+ if (max>0)\r
+ {\r
+ editCommand.appendEdit(EditCommand.DELETE_GAP,\r
+ new SequenceI[]\r
+ {seq},\r
+ startres, max,\r
+ av.getGapCharacter(),\r
+ true);\r
}\r
}\r
}\r
}\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
- //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
- for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)\r
+ for(int s=0; s<seq.length; s++)\r
{\r
- if (jalview.util.Comparison.isGap(seq.getCharAt(blankColumn)))\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
+\r
+ for (blankColumn = fixedColumn; blankColumn > j; blankColumn--)\r
{\r
- //Theres a space, so break and insert the gap\r
- break;\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
}\r
- }\r
\r
- if (blankColumn <= j)\r
- {\r
- blankColumn = fixedColumn;\r
- endEditing();\r
- return;\r
- }\r
-\r
- if (!jalview.util.Comparison.isGap(seq.getCharAt(blankColumn)))\r
- {\r
- //Just Checking\r
- System.out.println("Tried removing residue (INSERT)"+seq.getCharAt(fixedColumn));\r
- return;\r
+ if (blankColumn <= j)\r
+ {\r
+ blankColumn = fixedColumn;\r
+ endEditing();\r
+ return;\r
+ }\r
}\r
\r
- seq.deleteCharAt(blankColumn);\r
- seq.insertCharAt(j, av.getGapCharacter());\r
- seqEditOccurred = true;\r
- }\r
+ editCommand.appendEdit(EditCommand.DELETE_GAP,\r
+ seq,\r
+ blankColumn, 1, av.getGapCharacter(), true);\r
\r
- void deleteChar(int j, SequenceI seq, int fixedColumn)\r
- {\r
- if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))\r
- {\r
- ap.alignFrame.statusBar.setText(\r
- "End editing: Tried removing residue " + seq.getCharAt(j));\r
- return;\r
- }\r
+ editCommand.appendEdit(EditCommand.INSERT_GAP,\r
+ seq,\r
+ j, 1, av.getGapCharacter(),\r
+ true);\r
\r
- seq.deleteCharAt(j);\r
- seq.insertCharAt(fixedColumn, av.getGapCharacter());\r
- seqEditOccurred = true;\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
+ void deleteChar(int j, SequenceI [] seq, int fixedColumn)\r
{\r
- if (!jalview.util.Comparison.isGap(seq.getCharAt(j)))\r
- {\r
- ap.alignFrame.statusBar.setText(\r
- "End editing: Tried removing residue " + seq.getCharAt(j));\r
- return;\r
- }\r
\r
- seq.deleteCharAt(j);\r
- seqEditOccurred = true;\r
- seqCanvas.repaint();\r
+ editCommand.appendEdit(EditCommand.DELETE_GAP,\r
+ seq,\r
+ j, 1, av.getGapCharacter(), true);\r
+\r
+ editCommand.appendEdit(EditCommand.INSERT_GAP,\r
+ seq,\r
+ fixedColumn, 1, av.getGapCharacter(), true);\r
}\r
+\r
/**\r
* DOCUMENT ME!\r
*\r
}\r
\r
public void mouseClicked(MouseEvent evt)\r
- {}\r
+ {\r
+ if(evt.getClickCount()>1)\r
+ {\r
+\r
+ SequenceFeature[] features = findFeaturesAtRes(\r
+ av.alignment.getSequenceAt( findSeq(evt) ).getDatasetSequence(),\r
+ findRes(evt)\r
+ );\r
+ for(int f=0; f<features.length; f++)\r
+ System.out.println("SELECT: "+features[f].getType()+" "\r
+ +features[f].getBegin()+" "+features[f].getEnd());\r
+\r
+ }\r
+ }\r
\r
public void mouseWheelMoved(MouseWheelEvent e)\r
{\r
}\r
\r
\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param i DOCUMENT ME!\r
- */\r
- void editOccurred()\r
- {\r
- if (!seqEditOccurred)\r
- {\r
- ap.alignFrame.historyList.pop();\r
- ap.alignFrame.updateEditMenuBar();\r
- }\r
-\r
- endEditing();\r
-\r
- av.firePropertyChange("alignment", null,av.getAlignment().getSequences());\r
-\r
- }\r
-\r
/**\r
* DOCUMENT ME!\r
*\r