protected int startseq;\r
protected int padseq;\r
\r
- public boolean editFlag;\r
protected AlignViewport av;\r
\r
// if character is inserted or deleted, we will need to recalculate the conservation\r
\r
endres = res;\r
\r
- // This is to detect edits - we're at the end of an edit if mouse is up\r
- editFlag = false;\r
startseq = -1;\r
startres = -1;\r
lastres = -1;\r
res = x/av.getCharWidth() + av.getStartRes();\r
seq = y/av.getCharHeight() + av.getStartSeq();\r
\r
- if (seq < av.getAlignment().getHeight() && res < av.getAlignment().getSequenceAt(seq).getLength())\r
+ if (seq < av.getAlignment().getHeight() &&\r
+ res < av.getAlignment().getSequenceAt(seq).getLength())\r
{\r
//char resstr = align.getSequenceAt(seq).getSequence().charAt(res);\r
// Find the residue's position in the sequence (res is the position\r
\r
startseq = seq;\r
\r
- if (startseq == (av.getAlignment().getHeight()-1)) {\r
+ if (startseq == (av.getAlignment().getHeight() - 1))\r
padseq = 1;\r
- } else {\r
+ else\r
padseq = 1;\r
- }\r
\r
startres = res;\r
lastres = res;\r
\r
- } else {\r
+ }\r
+ else\r
+ {\r
startseq = -1;\r
startres = -1;\r
lastres = -1;\r
public void doMouseDragged(MouseEvent evt) {\r
// If we're dragging we're editing\r
\r
- editFlag = true;\r
int x = evt.getX();\r
\r
int res = x/av.getCharWidth() + av.getStartRes();\r
- if (res < 0) {res = 0;}\r
-\r
- if (res != lastres) {\r
- if (startseq != -1) {\r
+ if (res < 0)\r
+ res = 0;\r
\r
+ if (res != lastres)\r
+ {\r
// Group editing\r
- if (evt.isControlDown()) {\r
+ if (evt.isControlDown())\r
+ {\r
SequenceGroup sg = av.getAlignment().findGroup(startseq);\r
-\r
- if(sg!=null)\r
- if (res < av.getAlignment().getWidth() && res < lastres)\r
+ if (sg != null)\r
{\r
- boolean flag = false;\r
- for (int i= 0 ; i < sg.getSize(); i++)\r
+ boolean deleteAllowed = false;\r
+ if (res < av.getAlignment().getWidth() && res < lastres)\r
{\r
- SequenceI s = (SequenceI)sg.getSequenceAt(i);\r
- for (int j=lastres-1; j >= res; j--)\r
+ /// Are we able to delete?\r
+ boolean allGaps = true;\r
+ for (int i = 0; i < sg.getSize(); i++)\r
{\r
- if (!flag)\r
+ SequenceI s = sg.getSequenceAt(i);\r
+ for (int j = lastres-1; j >= res && allGaps; j--)\r
{\r
- if (s.getSequence().charAt(j)!=av.getAlignment().getGapCharacter() &&\r
- s.getSequence().charAt(j)==' ')\r
- {\r
- res = j+1;\r
- flag = true;\r
- }\r
- }\r
- }\r
- }\r
- }\r
+ if (!jalview.util.Comparison.isGap(s.getSequence().charAt(j)))\r
+ {\r
+ res = j + 1;\r
+ allGaps = false;\r
+ }\r
+ }\r
\r
- if(sg!=null)\r
- for (int i= 0 ; i < sg.getSize(); i++)\r
- {\r
- SequenceI s = (SequenceI)sg.getSequenceAt(i);\r
- boolean found = false;\r
- int sno = -1;\r
- for (int k = 0; k < av.getAlignment().getHeight(); k++)\r
- {\r
- if (av.getAlignment().getSequenceAt(k) == s)\r
- {\r
- found = true;\r
- sno = k;\r
- break;\r
- }\r
- }\r
- if (found && sno != -1) {\r
- if (res < av.getAlignment().getWidth() && res > lastres)\r
- {\r
- for (int j = lastres; j < res; j++)\r
- insertChar(j,sno);\r
+ if(!deleteAllowed && allGaps)\r
+ deleteAllowed = true;\r
\r
- int index = av.getAlignment().findIndex(s);\r
- if (index != -1)\r
- drawChars(index,index+1,lastres);\r
-\r
-\r
- } else if (res < av.getAlignment().getWidth() && res < lastres)\r
- {\r
- for (int j = res; j < lastres; j++)\r
- {\r
- deleteChar(j,res,sno);\r
- startres = res;\r
- }\r
- int index = av.getAlignment().findIndex(s);\r
- if (index != -1)\r
- drawChars(index,index+1,res);\r
+ }\r
+ }\r
\r
- }\r
- }\r
\r
- }\r
- lastres = res;\r
- } else {\r
+ for (int i = 0; i < sg.getSize(); i++)\r
+ {\r
+ SequenceI s = sg.getSequenceAt(i);\r
+ int k = av.alignment.findIndex(s);\r
\r
+ // drag to right\r
+ if (res < av.getAlignment().getWidth() && res > lastres)\r
+ for (int j = lastres; j < res; j++)\r
+ insertChar(j, k);\r
\r
- if (res < av.getAlignment().getWidth() && res > lastres) {\r
+ // drag to left\r
+ else if (deleteAllowed && res < av.getAlignment().getWidth() && res < lastres)\r
+ {\r
+ for (int j = res; j < lastres; j++)\r
+ {\r
+ deleteChar(j, k);\r
+ startres = res;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ else /////Editing a single sequence///////////\r
+ {\r
+ if (res < av.getAlignment().getWidth() && res > lastres)\r
+ {\r
// dragging to the right\r
- for (int j = lastres; j < res; j++)\r
- insertChar(j,startseq);\r
-\r
- drawChars(startseq,startseq+1,lastres);\r
-\r
- } else if (res < av.getAlignment().getWidth() && res < lastres)\r
+ for (int j = lastres; j < res; j++)\r
+ insertChar(j, startseq);\r
+ }\r
+ else if (res < av.getAlignment().getWidth() && res < lastres)\r
{\r
-\r
// dragging to the left\r
- for (int j = res; j < lastres; j++) {\r
- deleteChar(j,res,startseq);\r
- startres = res;\r
- }\r
- drawChars(startseq,startseq+1,res);\r
+ for (int j = res; j < lastres; j++)\r
+ {\r
+ deleteChar(j, startseq);\r
+ startres = res;\r
+ }\r
}\r
+\r
}\r
- }\r
- lastres = res;\r
+\r
}\r
\r
+ lastres = res;\r
repaint();\r
- return;\r
}\r
\r
public void drawChars(int seqstart, int seqend, int start) {\r
\r
public void insertChar(int j, int seq)\r
{\r
- av.getAlignment().getSequenceAt(seq).insertCharAt(j, av.getGapCharacter());\r
+ av.alignment.getSequenceAt(seq).insertCharAt(j, av.getGapCharacter());\r
seqEditOccurred=seq;\r
}\r
\r
- public void deleteChar(int j, int res, int seq)\r
+ public void deleteChar(int j, int seq)\r
{\r
\r
- if (av.getAlignment().getSequenceAt(seq).getSequence().charAt(j)=='.' ||\r
- av.getAlignment().getSequenceAt(seq).getSequence().charAt(j)=='-' ||\r
- av.getAlignment().getSequenceAt(seq).getSequence().charAt(j)==' ' )\r
- {\r
- av.getAlignment().getSequenceAt(seq).deleteCharAt(j);\r
- }\r
+ if ( jalview.util.Comparison.isGap( av.alignment.getSequenceAt(seq).getSequence().charAt(j)))\r
+ av.alignment.getSequenceAt(seq).deleteCharAt(j);\r
\r
- av.getAlignment().getWidth();\r
+ av.alignment.getWidth();\r
repaint();\r
seqEditOccurred=seq;\r
}\r
ccs.conserve = c;*/\r
}\r
\r
+//////////////////////////////////////////\r
+/////Everything below this is for defining the boundary of the rubberband\r
+//////////////////////////////////////////\r
int oldSeq = -1;\r
-\r
public void doMousePressedDefineMode(MouseEvent evt)\r
{\r
int res = evt.getX()/av.getCharWidth() + av.getStartRes();\r