*/\r
package jalview.gui;\r
\r
-import jalview.analysis.*;\r
-\r
import jalview.datamodel.*;\r
\r
import jalview.schemes.*;\r
import java.awt.*;\r
import java.awt.event.*;\r
\r
-import java.util.*;\r
-\r
import javax.swing.*;\r
\r
\r
* @author $author$\r
* @version $Revision$\r
*/\r
-public class SeqPanel extends JPanel\r
+public class SeqPanel extends JPanel implements MouseListener,\r
+ MouseMotionListener, MouseWheelListener\r
+\r
{\r
/** DOCUMENT ME!! */\r
public SeqCanvas seqCanvas;\r
public AlignmentPanel ap;\r
protected int lastres;\r
protected int startseq;\r
- int startEdit = -1;\r
- int endEdit = -1;\r
protected AlignViewport av;\r
\r
// if character is inserted or deleted, we will need to recalculate the conservation\r
- int seqEditOccurred = -1;\r
+ boolean seqEditOccurred = false;\r
ScrollThread scrollThread = null;\r
boolean mouseDragging = false;\r
boolean editingSeqs = false;\r
boolean remove = false;\r
\r
boolean mouseWheelPressed = false;\r
+ StringBuffer keyboardNo1;\r
+ StringBuffer keyboardNo2;\r
\r
/**\r
* Creates a new SeqPanel object.\r
\r
ap = p;\r
\r
- addMouseMotionListener(new MouseMotionAdapter()\r
- {\r
- public void mouseMoved(MouseEvent evt)\r
- {\r
- doMouseMoved(evt);\r
- }\r
-\r
- public void mouseDragged(MouseEvent evt)\r
- {\r
- if (editingSeqs)\r
- {\r
- doMouseDragged(evt);\r
- }\r
- else\r
- {\r
- doMouseDraggedDefineMode(evt);\r
- }\r
- }\r
- });\r
-\r
- addMouseWheelListener(new MouseWheelListener()\r
- {\r
- public void mouseWheelMoved(MouseWheelEvent e)\r
- {\r
-\r
- if (mouseWheelPressed)\r
- {\r
- Font font = av.getFont();\r
- int fontSize = font.getSize();\r
- if (e.getWheelRotation() > 0 && fontSize < 30)\r
- fontSize++;\r
- else if (fontSize > 1)\r
- fontSize--;\r
-\r
- av.setFont(new Font(font.getName(), font.getStyle(), fontSize));\r
- ap.fontChanged();\r
- }\r
- else\r
- {\r
- if (e.getWheelRotation() > 0)\r
- ap.scrollUp(false);\r
- else\r
- ap.scrollUp(true);\r
- }\r
-\r
- }\r
- });\r
-\r
-\r
- addMouseListener(new MouseAdapter()\r
- {\r
- public void mouseReleased(MouseEvent evt)\r
- {\r
- mouseWheelPressed = false;\r
-\r
- if (editingSeqs)\r
- {\r
- doMouseReleased(evt);\r
- }\r
- else\r
- {\r
- doMouseReleasedDefineMode(evt);\r
- }\r
- }\r
-\r
- public void mousePressed(MouseEvent evt)\r
- {\r
- if( javax.swing.SwingUtilities.isMiddleMouseButton(evt))\r
- {\r
- mouseWheelPressed = true;\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
-\r
- editingSeqs = true;\r
- doMousePressed(evt);\r
- }\r
- else\r
- {\r
- doMousePressedDefineMode(evt);\r
- }\r
- }\r
-\r
- public void mouseExited(MouseEvent evt)\r
- {\r
- if (editingSeqs)\r
- {\r
- return;\r
- }\r
-\r
- doMouseExitedDefineMode(evt);\r
- }\r
-\r
- public void mouseEntered(MouseEvent evt)\r
- {\r
- if (editingSeqs)\r
- {\r
- return;\r
- }\r
-\r
- doMouseEnteredDefineMode(evt);\r
- }\r
- });\r
+ if(!av.isDataset())\r
+ {\r
+ addMouseMotionListener(this);\r
+ addMouseListener(this);\r
+ addMouseWheelListener(this);\r
+ }\r
}\r
\r
int startWrapBlock=-1;\r
\r
if (av.wrapAlignment)\r
{\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
int y = evt.getY();\r
- y -= (2 * av.charHeight);\r
+ y -= hgap;\r
x -= seqCanvas.LABEL_WEST;\r
\r
- int chunkHeight = (av.getAlignment().getHeight() + 2) * av.charHeight;\r
+\r
int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth());\r
- wrappedBlock = y/chunkHeight;\r
- wrappedBlock += av.getStartRes()/cwidth;\r
\r
- res = wrappedBlock*cwidth + x / av.getCharWidth();\r
+ wrappedBlock = y / cHeight;\r
+ wrappedBlock += av.getStartRes() / cwidth;\r
+\r
+ res = wrappedBlock * cwidth + x / av.getCharWidth();\r
+\r
}\r
else\r
{\r
res = (x / av.getCharWidth()) + av.getStartRes();\r
}\r
\r
+ if(av.hasHiddenColumns)\r
+ res = av.getColumnSelection().adjustForHiddenColumns(res);\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
- y -= (2 * av.charHeight);\r
- int chunkHeight = (av.getAlignment().getHeight() + 2) * av.charHeight;\r
- seq = ( (y % chunkHeight) / av.getCharHeight());\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
return seq;\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
+ }\r
+\r
+ void setCursorRow()\r
+ {\r
+ seqCanvas.cursorY = getKeyboardNo(keyboardNo1)-1;\r
+ scrollToVisible();\r
+ }\r
+\r
+ void setCursorColumn()\r
+ {\r
+ seqCanvas.cursorX = getKeyboardNo(keyboardNo1)-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.cursorY = getKeyboardNo(keyboardNo2) - 1;\r
+ scrollToVisible();\r
+ }\r
+ }\r
+\r
+ void setCursorPosition()\r
+ {\r
+ SequenceI sequence =\r
+ (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY);\r
+\r
+ seqCanvas.cursorX = sequence.findIndex(\r
+ getKeyboardNo(keyboardNo1)-1\r
+ );\r
+ scrollToVisible();\r
+ }\r
+\r
+ void moveCursor(int dx, int dy)\r
+ {\r
+ seqCanvas.cursorX += dx;\r
+ seqCanvas.cursorY += dy;\r
+ scrollToVisible();\r
+ }\r
+\r
+ void scrollToVisible()\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
+\r
+ endEditing();\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
+ while (seqCanvas.cursorX < av.startRes)\r
+ {\r
+ if(!ap.scrollRight(false))\r
+ break;\r
+ }\r
+ while (seqCanvas.cursorX > av.endRes)\r
+ {\r
+ if(!ap.scrollRight(true))\r
+ break;\r
+ }\r
+\r
+ setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY),\r
+ seqCanvas.cursorX, seqCanvas.cursorY);\r
+\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
+ {\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
+ int index = av.alignment.findIndex( sg.getSequenceAt(i) );\r
+ if(index > max)\r
+ max = index;\r
+ if(index < min)\r
+ min = index;\r
+ }\r
+\r
+ max ++;\r
+\r
+ if(topLeft)\r
+ {\r
+ sg.setStartRes(seqCanvas.cursorX);\r
+ if(sg.getEndRes()<seqCanvas.cursorX)\r
+ sg.setEndRes(seqCanvas.cursorX);\r
+\r
+ min = seqCanvas.cursorY;\r
+ }\r
+ else\r
+ {\r
+ sg.setEndRes(seqCanvas.cursorX);\r
+ if(sg.getStartRes()>seqCanvas.cursorX)\r
+ sg.setStartRes(seqCanvas.cursorX);\r
+\r
+ max = seqCanvas.cursorY+1;\r
+ }\r
+\r
+ if(min>max)\r
+ {\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.sequences.clear();\r
+ for (int i = min; i < max; i++)\r
+ {\r
+ sg.addSequence(av.alignment.getSequenceAt(i), false);\r
+ }\r
+ }\r
+ }\r
+\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
+\r
+ ap.repaint();\r
+ }\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
+ }\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
+ }\r
+\r
+ void numberPressed(char value)\r
+ {\r
+ if(keyboardNo1==null)\r
+ keyboardNo1 = new StringBuffer();\r
+\r
+ if(keyboardNo2!=null)\r
+ keyboardNo2.append(value);\r
+ else\r
+ keyboardNo1.append(value);\r
+ }\r
+\r
+ int getKeyboardNo(StringBuffer kb)\r
+ {\r
+ if(kb==null)\r
+ return 1;\r
+ else\r
+ return Integer.parseInt(kb.toString());\r
+ }\r
+\r
\r
/**\r
* DOCUMENT ME!\r
*\r
* @param evt DOCUMENT ME!\r
*/\r
- public void doMouseReleased(MouseEvent evt)\r
+ public void mouseReleased(MouseEvent evt)\r
{\r
- if (seqEditOccurred > -1)\r
- {\r
- editOccurred(seqEditOccurred);\r
- }\r
+ mouseDragging = false;\r
+ mouseWheelPressed = false;\r
+\r
+ if (!editingSeqs)\r
+ {\r
+ doMouseReleasedDefineMode(evt);\r
+ return;\r
+ }\r
\r
- startseq = -1;\r
- lastres = -1;\r
- seqEditOccurred = -1;\r
- editingSeqs = false;\r
- groupEditing = false;\r
+ editOccurred();\r
\r
- ap.repaint();\r
+ endEditing();\r
+ ap.repaint();\r
}\r
\r
+\r
+\r
/**\r
* DOCUMENT ME!\r
*\r
* @param evt DOCUMENT ME!\r
*/\r
- public void doMousePressed(MouseEvent evt)\r
+ public void mousePressed(MouseEvent evt)\r
{\r
- ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence",\r
- av.alignment, HistoryItem.EDIT));\r
+ if (javax.swing.SwingUtilities.isMiddleMouseButton(evt))\r
+ {\r
+ mouseWheelPressed = true;\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
+\r
+\r
\r
int seq = findSeq(evt);\r
int res = findRes(evt);\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
lastres = -1;\r
}\r
\r
- startEdit = lastres;\r
- endEdit = lastres;\r
-\r
return;\r
}\r
\r
*\r
* @param evt DOCUMENT ME!\r
*/\r
- public void doMouseMoved(MouseEvent evt)\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
int res = findRes(evt);\r
int seq = findSeq(evt);\r
\r
+\r
if(res<0 || seq<0 || seq >= av.getAlignment().getHeight())\r
return;\r
\r
\r
if (res > sequence.getLength())\r
{\r
- return;\r
- }\r
-\r
- Object obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) +\r
- "");\r
- String aa = "";\r
-\r
- if (obj != null)\r
- {\r
- aa = obj.toString();\r
- }\r
-\r
- StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " +\r
- sequence.getName());\r
+ return;\r
+ }\r
\r
- if (aa != "")\r
- {\r
- text.append(" Residue: " + aa + " (" +\r
- av.getAlignment().getSequenceAt(seq).findPosition(res) + ")");\r
- }\r
+ if(seqCanvas.pdbCanvas!=null && sequence==seqCanvas.pdbCanvas.sequence)\r
+ {\r
+ seqCanvas.pdbCanvas.highlightRes(sequence.findPosition(res));\r
+ }\r
\r
- ap.alignFrame.statusBar.setText(text.toString());\r
+ setStatusMessage(sequence, res, seq);\r
\r
// use aa to see if the mouse pointer is on a\r
if (av.showSequenceFeatures)\r
{\r
- Vector features = sequence.getSequenceFeatures();\r
- Enumeration e = features.elements();\r
- StringBuffer sbuffer = new StringBuffer();\r
-\r
- while (e.hasMoreElements())\r
+ SequenceFeature [] features = sequence.getDatasetSequence().getSequenceFeatures();\r
+ if(features!=null)\r
{\r
- SequenceFeature sf = (SequenceFeature) e.nextElement();\r
+ StringBuffer sbuffer = new StringBuffer("<html>");\r
+\r
+ for (int i = 0; i < features.length; i++)\r
+ {\r
\r
- if ((sf.getStart() <= sequence.findPosition(res)) &&\r
- (sf.getEnd() >= sequence.findPosition(res)))\r
+ if ( (features[i].getBegin() <= sequence.findPosition(res)) &&\r
+ (features[i].getEnd() >= sequence.findPosition(res)))\r
{\r
- if (sbuffer.length() > 0)\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
- sbuffer.append("; ");\r
+ if (sbuffer.length() > 6)\r
+ sbuffer.append("<br>");\r
+ sbuffer.append("disulfide bond " + features[i].getBegin() + ":" +\r
+ features[i].getEnd());\r
}\r
+ }\r
+ else\r
+ {\r
+ if (sbuffer.length() > 6)\r
+ sbuffer.append("<br>");\r
+ if(features[i].featureGroup!=null)\r
+ sbuffer.append(features[i].featureGroup+";");\r
+\r
+ sbuffer.append(features[i].getType());\r
\r
- sbuffer.append(sf.getType() + " " + sf.getDescription());\r
+ if (features[i].getDescription() != null\r
+ && !features[i].description.equals(features[i].getType()))\r
+ sbuffer.append("; " + features[i].getDescription());\r
\r
- if (sf.getStatus().length() > 0)\r
+ if (features[i].getStatus() != null && features[i].getStatus().length()>0)\r
{\r
- sbuffer.append(" (" + sf.getStatus() + ")");\r
+ sbuffer.append("; (" + features[i].getStatus() + ")");\r
}\r
+ }\r
}\r
+\r
+ }\r
+\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
+\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
+ {\r
+ obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) +\r
+ "");\r
+ if (obj != null)\r
+ text.append(" Nucleotide: ");\r
+ }\r
+ else\r
+ {\r
+ obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + "");\r
+ if (obj != null)\r
+ text.append(" Residue: ");\r
+ }\r
\r
- this.setToolTipText(sbuffer.toString());\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
*\r
* @param evt DOCUMENT ME!\r
*/\r
- public void doMouseDragged(MouseEvent evt)\r
+ public void mouseDragged(MouseEvent evt)\r
{\r
- // If we're dragging we're editing\r
+ if (!editingSeqs)\r
+ {\r
+ doMouseDraggedDefineMode(evt);\r
+ return;\r
+ }\r
+\r
int res = findRes(evt);\r
\r
if (res < 0)\r
return;\r
}\r
\r
- boolean dragRight = true;\r
+ if ( (res < av.getAlignment().getWidth()) && (res < lastres))\r
+ {\r
+ // dragLeft, delete gap\r
+ editSequence(false, res);\r
+ }\r
+ else\r
+ editSequence(true, res);\r
+\r
+ mouseDragging = true;\r
+ if(scrollThread!=null)\r
+ scrollThread.setEvent(evt);\r
+\r
+ }\r
+\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
+ if(groupEditing && sg==null)\r
+ return;\r
+\r
+ if (!groupEditing && av.hasHiddenRows)\r
+ {\r
+ //This needs to check all the sequences in a group edit,m\r
+ // not just the startseq\r
+ if (av.alignment.getSequenceAt(startseq).getHiddenSequences() != null)\r
+ {\r
+ groupEditing = true;\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
+\r
+ //Are we editing within a selection group?\r
+ if (groupEditing\r
+ || (sg != null && sg.sequences.contains(seq)))\r
+ {\r
+ fixedColumns = true;\r
+\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
+\r
\r
- if ((res < av.getAlignment().getWidth()) && (res < lastres))\r
+ if(av.hasHiddenColumns)\r
{\r
- dragRight = false;\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(fixedRight<y2 && fixedRight==-1 && y2!=startres)\r
+ fixedRight = y2 -1;\r
+ if(y1>fixedLeft && fixedLeft==-1)\r
+ fixedLeft = y1;\r
}\r
\r
- if (res != lastres)\r
+ if (groupEditing)\r
{\r
- // Group editing\r
- if (groupEditing)\r
+\r
+ /*if (av.hasHiddenRows)\r
+ {\r
+ //sg might be null as the user may only see 1 sequence\r
+ if (sg == null)\r
{\r
- SequenceGroup sg = av.getSelectionGroup();\r
+ sg = new SequenceGroup();\r
+ sg.addSequence(av.alignment.getSequenceAt(startseq), false);\r
+ }\r
\r
- if (sg == null)\r
- {\r
- lastres = -1;\r
+ SequenceGroup tmp = new SequenceGroup();\r
\r
- return;\r
- }\r
+ //Do any of the sequences have hidden associates?\r
+ for (int s = 0; s < sg.getSize(); s++)\r
+ {\r
+ seq = sg.getSequenceAt(s);\r
+ tmp.addSequence(seq, false);\r
+ if (seq.getHiddenSequences() != null)\r
+ {\r
+ for (int h = 0; h < seq.getHiddenSequences().getSize(); h++)\r
+ tmp.addSequence(seq.getHiddenSequences().getSequenceAt(h),\r
+ false);\r
+ }\r
+ }\r
\r
- // drag to right\r
- if (dragRight)\r
+ sg = tmp;\r
+ }*/\r
+ // int blankColumn = -1;\r
+\r
+\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 && sg.getEndRes() + 1 == av.alignment.getWidth())\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
+ {\r
+ blank = true;\r
+ for (int s = 0; s < sg.getSize(); s++)\r
+ {\r
+ seq = sg.getSequenceAt(s);\r
+ for (int j = 0; j < startres - lastres; j++)\r
{\r
- sg.setEndRes(sg.getEndRes() + (res - lastres));\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
+ }\r
\r
- // drag to left\r
- else\r
- {\r
- /// Are we able to delete?\r
- // ie are all columns blank?\r
- boolean deleteAllowed = false;\r
+ if (!blank)\r
+ {\r
+ if(sg.getSize() == av.alignment.getHeight())\r
+ {\r
+ //We can still insert gaps if the selectionGroup\r
+ //contains all the sequences\r
+ sg.setEndRes(sg.getEndRes()+1+startres-lastres);\r
+ fixedRight = av.alignment.getWidth()+startres-lastres;\r
+ }\r
+ else\r
+ {\r
+ endEditing();\r
+ return;\r
+ }\r
+ }\r
+ }\r
\r
- for (int s = 0; s < sg.getSize(); s++)\r
- {\r
- SequenceI seq = sg.getSequenceAt(s);\r
-\r
- for (int j = res; 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
- res = j + 1;\r
- deleteAllowed = false;\r
-\r
- continue;\r
- }\r
-\r
- deleteAllowed = true;\r
- }\r
- }\r
\r
- if (!deleteAllowed)\r
- {\r
- lastres = -1;\r
+ // drag to left\r
+ else if(!insertGap)\r
+ {\r
+ /// Are we able to delete?\r
+ // ie are all columns blank?\r
\r
- return;\r
- }\r
+ for (int s = 0; s < sg.getSize(); s++)\r
+ {\r
+ seq = sg.getSequenceAt(s);\r
\r
- sg.setEndRes(sg.getEndRes() - (lastres - res));\r
+ for (int j = startres; j < lastres; j++)\r
+ {\r
+ if (seq.getSequence().length() <= j)\r
+ {\r
+ continue;\r
}\r
\r
- for (int i = 0; i < sg.getSize(); i++)\r
+ if (!jalview.util.Comparison.isGap(\r
+ seq.getSequence().charAt(j)))\r
{\r
- SequenceI s = sg.getSequenceAt(i);\r
- int k = av.alignment.findIndex(s);\r
+ // Not a gap, block edit not valid\r
+ endEditing();\r
+ return;\r
+ }\r
+ }\r
+ }\r
+ }\r
\r
- // drag to right\r
- if (dragRight)\r
- {\r
- for (int j = lastres; j < res; j++)\r
- {\r
- insertChar(j, k);\r
- }\r
- }\r
\r
- // drag to left\r
- else\r
- {\r
- for (int j = res; j < lastres; j++)\r
- {\r
- if (s.getLength() > j)\r
- {\r
- deleteChar(res, k);\r
- }\r
- }\r
- }\r
+ for (int i = 0; i < sg.getSize(); i++)\r
+ {\r
+ seq = sg.getSequenceAt(i);\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 /////Editing a single sequence///////////\r
+ else\r
{\r
- if ((res < av.getAlignment().getWidth()) && (res > lastres))\r
+ // dragging to the left\r
+ for (int j = lastres; j > startres; j--)\r
+ {\r
+ if (fixedColumns && fixedRight != -1)\r
{\r
- // dragging to the right\r
- for (int j = lastres; j < res; j++)\r
- {\r
- insertChar(j, startseq);\r
- }\r
+ deleteChar(startres, seq, fixedRight);\r
}\r
- else if ((res < av.getAlignment().getWidth()) &&\r
- (res < lastres))\r
+ else\r
{\r
- // dragging to the left\r
- for (int j = lastres; j > res; j--)\r
- {\r
- if (jalview.util.Comparison.isGap(\r
- av.alignment.getSequenceAt(startseq)\r
- .getSequence().charAt(res)))\r
- {\r
- deleteChar(res, startseq);\r
- }\r
- else\r
- {\r
- break;\r
- }\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
+ for (int j = lastres; j < startres; j++)\r
+ {\r
+ if (fixedColumns && fixedRight != -1)\r
+ {\r
+ if (sg.getStartRes() == 0\r
+ && sg.getEndRes() + 1 == av.alignment.getWidth()\r
+ && !jalview.util.Comparison.isGap(seq.getCharAt(fixedRight)))\r
+ {\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
+ }\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
- endEdit = res;\r
- lastres = res;\r
+ lastres = startres;\r
seqCanvas.repaint();\r
}\r
\r
+\r
/**\r
* DOCUMENT ME!\r
*\r
- * @param seqstart DOCUMENT ME!\r
- * @param seqend DOCUMENT ME!\r
- * @param start DOCUMENT ME!\r
+ * @param j DOCUMENT ME!\r
+ * @param seq DOCUMENT ME!\r
*/\r
- public void drawChars(int seqstart, int seqend, int start)\r
+ void insertChar(int j, SequenceI seq)\r
{\r
- seqCanvas.drawPanel(seqCanvas.gg, start, av.getEndRes(), seqstart,\r
- seqend, av.getStartRes(), av.getStartSeq(), 0);\r
- seqCanvas.repaint();\r
+ seq.insertCharAt(j, av.getGapCharacter());\r
+ seqEditOccurred = true;\r
+ }\r
+\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
+ {\r
+ if (jalview.util.Comparison.isGap(seq.getCharAt(blankColumn)))\r
+ {\r
+ //Theres a space, so break and insert the gap\r
+ break;\r
+ }\r
+ }\r
+\r
+ if (blankColumn <= j)\r
+ {\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
+ }\r
+\r
+ seq.deleteCharAt(blankColumn);\r
+ seq.insertCharAt(j, av.getGapCharacter());\r
+ seqEditOccurred = true;\r
+ }\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
+\r
+ seq.deleteCharAt(j);\r
+ seq.insertCharAt(fixedColumn, av.getGapCharacter());\r
+ seqEditOccurred = true;\r
}\r
\r
/**\r
* @param j DOCUMENT ME!\r
* @param seq DOCUMENT ME!\r
*/\r
- public void insertChar(int j, int seq)\r
+ void deleteChar(int j, SequenceI seq)\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
+ }\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void mouseEntered(MouseEvent e)\r
{\r
- av.alignment.getSequenceAt(seq).insertCharAt(j, av.getGapCharacter());\r
- seqEditOccurred = seq;\r
+ if(oldSeq < 0)\r
+ oldSeq = 0;\r
+\r
+ if (scrollThread != null)\r
+ {\r
+ scrollThread.running = false;\r
+ scrollThread = null;\r
+ }\r
}\r
\r
/**\r
* DOCUMENT ME!\r
*\r
- * @param j DOCUMENT ME!\r
- * @param seq DOCUMENT ME!\r
+ * @param e DOCUMENT ME!\r
*/\r
- public void deleteChar(int j, int seq)\r
+ public void mouseExited(MouseEvent e)\r
{\r
- av.alignment.getSequenceAt(seq).deleteCharAt(j);\r
- seqEditOccurred = seq;\r
+ if (av.getWrapAlignment())\r
+ {\r
+ return;\r
+ }\r
+\r
+ if (mouseDragging)\r
+ {\r
+ scrollThread = new ScrollThread();\r
+ }\r
+ }\r
+\r
+ public void mouseClicked(MouseEvent evt)\r
+ {}\r
+\r
+ public void mouseWheelMoved(MouseWheelEvent e)\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
+ av.setFont(new Font(font.getName(), font.getStyle(), fontSize));\r
+ ap.fontChanged();\r
+ }\r
+ else\r
+ {\r
+ if (e.getWheelRotation() > 0)\r
+ ap.scrollUp(false);\r
+ else\r
+ ap.scrollUp(true);\r
+ }\r
\r
- av.alignment.getWidth();\r
- seqCanvas.repaint();\r
}\r
\r
+\r
+\r
/**\r
* DOCUMENT ME!\r
*\r
* @param i DOCUMENT ME!\r
*/\r
- void editOccurred(int i)\r
+ void editOccurred()\r
{\r
- if (endEdit == startEdit)\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
startWrapBlock=wrappedBlock;\r
\r
- if(seq<0 || res<0)\r
+ if(av.wrapAlignment && seq>av.alignment.getHeight())\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
}\r
}\r
\r
+ if (av.cursorMode)\r
+ {\r
+ seqCanvas.cursorX = findRes(evt);\r
+ seqCanvas.cursorY = findSeq(evt);\r
+ seqCanvas.repaint();\r
+ return;\r
+ }\r
+\r
+\r
if (stretchGroup == null)\r
{\r
// define a new group here\r
*/\r
public void doMouseReleasedDefineMode(MouseEvent evt)\r
{\r
- if (mouseDragging)\r
- {\r
- stretchGroup.recalcConservation();\r
- mouseDragging = false;\r
- }\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
SliderPanel.setConservationSlider(ap, stretchGroup.cs,\r
stretchGroup.getName());\r
+ stretchGroup.recalcConservation();\r
}\r
else\r
{\r
if(wrappedBlock!=startWrapBlock)\r
return;\r
\r
- if (stretchGroup == null)\r
- {\r
+ if (stretchGroup == null)\r
+ {\r
return;\r
- }\r
+ }\r
\r
- if (res > av.alignment.getWidth())\r
+\r
+ if(y > av.alignment.getHeight())\r
{\r
- res = av.alignment.getWidth() - 1;\r
+ y = av.alignment.getHeight() -1;\r
+ }\r
+ if(res> av.alignment.getWidth())\r
+ {\r
+ res = av.alignment.getWidth()-1;\r
}\r
\r
if (stretchGroup.getEndRes() == res)\r
{\r
res = av.getStartRes();\r
}\r
- else if (res > av.getEndRes() && !av.getWrapAlignment())\r
- {\r
- res = av.getEndRes();\r
- }\r
\r
if (changeEndRes)\r
{\r
dragDirection = -1;\r
}\r
\r
- while ((y != oldSeq) && (oldSeq > 0) && (y < av.alignment.getHeight()))\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
\r
oldSeq += dragDirection;\r
\r
+ if(oldSeq<0)\r
+ break;\r
+\r
Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq);\r
\r
if (stretchGroup.sequences.contains(nextSeq))\r
}\r
}\r
\r
- oldSeq = y;\r
+ if(oldSeq < 0)\r
+ oldSeq = -1;\r
+\r
mouseDragging = true;\r
\r
if (scrollThread != null)\r
seqCanvas.repaint();\r
}\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void doMouseEnteredDefineMode(MouseEvent e)\r
+ void scrollCanvas(MouseEvent evt)\r
{\r
- if (scrollThread != null)\r
+ if(evt==null)\r
+ {\r
+ if(scrollThread!=null)\r
{\r
- scrollThread.running = false;\r
+ scrollThread.running = false;\r
+ scrollThread = null;\r
}\r
- }\r
+ mouseDragging = false;\r
+ }\r
+ else\r
+ {\r
+ if (scrollThread == null)\r
+ scrollThread = new ScrollThread();\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void doMouseExitedDefineMode(MouseEvent e)\r
- {\r
- if (av.getWrapAlignment())\r
- {\r
- return;\r
- }\r
+ mouseDragging = true;\r
+ scrollThread.setEvent(evt);\r
+ }\r
\r
- if (mouseDragging)\r
- {\r
- scrollThread = new ScrollThread();\r
- }\r
}\r
\r
+\r
// this class allows scrolling off the bottom of the visible alignment\r
class ScrollThread extends Thread\r
{\r
\r
if (mouseDragging && (evt.getX() < 0))\r
{\r
- running = ap.scrollRight(true);\r
+ running = ap.scrollRight(false);\r
}\r
else if (mouseDragging && (evt.getX() >= getWidth()))\r
{\r
- running = ap.scrollRight(false);\r
+ running = ap.scrollRight(true);\r
}\r
}\r
\r
try\r
{\r
- Thread.sleep(75);\r
+ Thread.sleep(20);\r
}\r
catch (Exception ex)\r
{\r