From 99f3f01792321efb671ac7ad946efffc3a3319a4 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Fri, 24 Mar 2006 15:33:20 +0000 Subject: [PATCH] CursoMode added --- src/jalview/gui/AlignViewport.java | 2 + src/jalview/gui/AlignmentPanel.java | 102 ++++- src/jalview/gui/SeqCanvas.java | 83 ++-- src/jalview/gui/SeqPanel.java | 790 ++++++++++++++++++++++------------- 4 files changed, 623 insertions(+), 354 deletions(-) diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 23d7612..a92517c 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -74,6 +74,8 @@ public class AlignViewport boolean hasHiddenColumns = false; boolean hasHiddenRows = false; + boolean cursorMode = false; + // The following vector holds the features which are // currently visible, in the correct order or rendering Hashtable featuresDisplayed = null; diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 7ef6763..a04c5bf 100755 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -106,6 +106,13 @@ public class AlignmentPanel extends GAlignmentPanel { public void keyPressed(KeyEvent evt) { + if(av.cursorMode + && evt.getKeyCode()>=KeyEvent.VK_0 + && evt.getKeyCode()<=KeyEvent.VK_9) + { + seqPanel.numberPressed(evt.getKeyChar()); + } + switch (evt.getKeyCode()) { case 27: // escape key @@ -115,26 +122,101 @@ public class AlignmentPanel extends GAlignmentPanel break; case KeyEvent.VK_DOWN: - alignFrame.moveSelectedSequences(false); - + if(av.cursorMode) + { + seqPanel.moveCursor(0,1); + } + else + alignFrame.moveSelectedSequences(false); break; case KeyEvent.VK_UP: - alignFrame.moveSelectedSequences(true); + if (av.cursorMode) + { + seqPanel.moveCursor(0,-1); + } + else + alignFrame.moveSelectedSequences(true); + break; + case KeyEvent.VK_LEFT: + if(av.cursorMode) + { + seqPanel.moveCursor(-1,0); + } + break; + + case KeyEvent.VK_RIGHT: + if (av.cursorMode) + { + seqPanel.moveCursor(1,0); + } + break; + + case KeyEvent.VK_SPACE: + if(av.cursorMode) + { + seqPanel.insertGapAtCursor(evt.isControlDown()); + } break; - case KeyEvent.VK_BACK_SPACE: case KeyEvent.VK_DELETE: - alignFrame.cut_actionPerformed(null); + if(av.cursorMode) + { + seqPanel.deleteGapAtCursor(evt.isControlDown()); + break; + } + + case KeyEvent.VK_BACK_SPACE: + if(!av.cursorMode) + { + alignFrame.cut_actionPerformed(null); + seqPanel.seqCanvas.repaint(); + } break; - case KeyEvent.VK_P: - seqPanel.seqCanvas.increaseAARatio(); + case KeyEvent.VK_Q: + if(av.cursorMode) + { + seqPanel.setSelectionAreaAtCursor(true); + } break; - case KeyEvent.VK_L: - seqPanel.seqCanvas.decreaseAARation(); + case KeyEvent.VK_M: + if(av.cursorMode) + { + seqPanel.setSelectionAreaAtCursor(false); + } + break; + + case KeyEvent.VK_F2: + av.cursorMode = ! av.cursorMode; + alignFrame.statusBar.setText("Keyboard editing mode is "+ + (av.cursorMode ? "on" : "off")); + if(av.cursorMode) + { + seqPanel.seqCanvas.cursorX = av.startRes; + seqPanel.seqCanvas.cursorY = av.startSeq; + } + seqPanel.seqCanvas.repaint(); + break; + + case KeyEvent.VK_F1: + try + { + ClassLoader cl = jalview.gui.Desktop.class.getClassLoader(); + java.net.URL url = javax.help.HelpSet.findHelpSet(cl, "help/help"); + javax.help.HelpSet hs = new javax.help.HelpSet(cl, url); + + javax.help.HelpBroker hb = hs.createHelpBroker(); + hb.setCurrentID("home"); + hb.setDisplayed(true); + } + catch (Exception ex) + { + ex.printStackTrace(); + } break; + } } }); @@ -373,7 +455,7 @@ public class AlignmentPanel extends GAlignmentPanel */ public boolean scrollRight(boolean right) { - if (right) + if (!right) { if (hscroll.getValue() < 1) { diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 2b5995c..99447a4 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -34,8 +34,8 @@ import javax.swing.*; */ public class SeqCanvas extends JComponent { - FeatureRenderer fr; - SequenceRenderer sr; + final FeatureRenderer fr; + final SequenceRenderer sr; BufferedImage img; Graphics2D gg; int imgWidth; @@ -46,6 +46,11 @@ public class SeqCanvas extends JComponent int LABEL_WEST; int LABEL_EAST; + + int cursorX = 0; + int cursorY = 0; + + /** * Creates a new SeqCanvas object. * @@ -342,7 +347,7 @@ public class SeqCanvas extends JComponent if (pdbCanvas != null) { - pdbCanvas.updateSeqColours(); + pdbCanvas.updateSeqColours(); } } @@ -431,11 +436,18 @@ public class SeqCanvas extends JComponent av.endRes = av.startRes + cWidth; - int endx = (startRes + cWidth) - 1; + int endx; int ypos = hgap; while ((ypos <= canvasHeight) && (startRes < av.alignment.getWidth())) { + endx = startRes + cWidth; + + if (endx > al.getWidth()) + { + endx = al.getWidth(); + } + g.setFont(av.getFont()); g.setColor(Color.black); @@ -472,12 +484,6 @@ public class SeqCanvas extends JComponent cWidth * av.charWidth, (int) clip.getBounds().getHeight()); } - if (av.vconsensus!=null && av.alignment.getWidth() >= av.vconsensus.size()) - { - endx = av.vconsensus.size() - 2; - } - - drawPanel(g, startRes, endx, 0, al.getHeight(), ypos); if(av.showAnnotation) @@ -486,7 +492,7 @@ public class SeqCanvas extends JComponent if(annotations==null) annotations = new AnnotationPanel(av); - annotations.drawComponent( (Graphics2D) g, startRes, endx + 1); + annotations.drawComponent( (Graphics2D) g, startRes, endx); g.translate(0, -cHeight - ypos); } g.setClip(clip); @@ -497,12 +503,6 @@ public class SeqCanvas extends JComponent ypos -= 3; startRes += cWidth; - endx = (startRes + cWidth) - 1; - - if (endx > al.getWidth()) - { - endx = al.getWidth(); - } } } @@ -522,35 +522,12 @@ public class SeqCanvas extends JComponent * DOCUMENT ME! * * @param g1 DOCUMENT ME! - * @param x1 DOCUMENT ME! - * @param x2 DOCUMENT ME! - * @param y1 DOCUMENT ME! - * @param y2 DOCUMENT ME! - * @param startx DOCUMENT ME! - * @param starty DOCUMENT ME! + * @param startRes DOCUMENT ME! + * @param endRes DOCUMENT ME! + * @param startSeq DOCUMENT ME! + * @param endSeq DOCUMENT ME! * @param offset DOCUMENT ME! */ - - float aaRatio = 2f/3f; - public void increaseAARatio() - { - aaRatio += .025; - if(aaRatio>1) - aaRatio = 1; - - repaint(); - } - - public void decreaseAARation() - { - aaRatio -= .025; - if(aaRatio<0) - aaRatio = 0; - - repaint(); - } - - void drawPanel(Graphics g1, int startRes, int endRes, int startSeq, int endSeq, int offset) { @@ -621,9 +598,10 @@ public class SeqCanvas extends JComponent int offset) { - sr.renderGaps(av.renderGaps); + Graphics2D g = (Graphics2D) g1; g.setFont(av.getFont()); + sr.prepare(g, av.renderGaps); SequenceI nextSeq; @@ -633,15 +611,14 @@ public class SeqCanvas extends JComponent { nextSeq = av.alignment.getSequenceAt(i); - sr.drawSequence(g, nextSeq, av.alignment.findAllGroups(nextSeq), + sr.drawSequence(nextSeq, av.alignment.findAllGroups(nextSeq), startRes, endRes, offset + ( (i - startSeq) * av.charHeight)); if (av.showSequenceFeatures) { fr.drawSequence(g1, nextSeq, startRes, endRes, - offset + ((i - startSeq) * av.charHeight), av.charWidth, - av.charHeight); + offset + ((i - startSeq) * av.charHeight)); } /// Highlight search Results once all sequences have been drawn @@ -655,10 +632,16 @@ public class SeqCanvas extends JComponent sr.drawHighlightedText(nextSeq, visibleResults[r], visibleResults[r + 1], (visibleResults[r] - startRes) * av.charWidth, - offset + ( (i - startSeq) * av.charHeight), - av.charWidth, av.charHeight); + offset + ( (i - startSeq) * av.charHeight)); } } + + if(av.cursorMode && cursorY==i + && cursorX>=startRes && cursorX<=endRes) + { + sr.drawCursor(nextSeq, cursorX, (cursorX - startRes) * av.charWidth, + offset + ( (i - startSeq) * av.charHeight)); + } } // diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 2fe27b3..3f49cc4 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -45,8 +45,6 @@ public class SeqPanel extends JPanel implements MouseListener, public AlignmentPanel ap; protected int lastres; protected int startseq; - int startEdit = -1; - int endEdit = -1; protected AlignViewport av; // if character is inserted or deleted, we will need to recalculate the conservation @@ -173,8 +171,145 @@ public class SeqPanel extends JPanel implements MouseListener, seqEditOccurred = false; editingSeqs = false; groupEditing = false; + keyboardGaps = null; } + + void moveCursor(int dx, int dy) + { + seqCanvas.cursorX += dx; + seqCanvas.cursorY += dy; + + if(seqCanvas.cursorX<0) + seqCanvas.cursorX = 0; + else if(seqCanvas.cursorX>av.alignment.getWidth()-1) + seqCanvas.cursorX = av.alignment.getWidth()-1; + if(seqCanvas.cursorXav.endRes) + ap.scrollRight(true); + + if(seqCanvas.cursorY<0) + seqCanvas.cursorY=0; + else if(seqCanvas.cursorY>av.alignment.getHeight()-1) + seqCanvas.cursorY = av.alignment.getHeight()-1; + if(seqCanvas.cursorYav.endSeq) + ap.scrollUp(false); + + setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY), + seqCanvas.cursorX, seqCanvas.cursorY); + seqCanvas.repaint(); + } + + void setSelectionAreaAtCursor(boolean topLeft) + { + SequenceI sequence = + (Sequence) av.getAlignment().getSequenceAt(seqCanvas.cursorY); + + if(av.getSelectionGroup()!=null) + { + SequenceGroup sg = av.selectionGroup; + //Find the top and bottom of this group + int min = av.alignment.getHeight(), max = 0; + for(int i=0; i max) + max = index; + if(index < min) + min = index; + } + + max ++; + + if(topLeft) + { + sg.setStartRes(seqCanvas.cursorX); + if(sg.getEndRes()seqCanvas.cursorX) + sg.setStartRes(seqCanvas.cursorX); + + max = seqCanvas.cursorY+1; + } + + if(min>max) + { + // Only the user can do this + av.setSelectionGroup(null); + } + else + { + // Now add any sequences between min and max + sg.sequences.clear(); + for (int i = min; i < max; i++) + { + sg.addSequence(av.alignment.getSequenceAt(i), false); + } + } + } + + if (av.getSelectionGroup() == null) + { + SequenceGroup sg = new SequenceGroup(); + sg.setStartRes(seqCanvas.cursorX); + sg.setEndRes(seqCanvas.cursorX); + sg.addSequence(sequence, false); + av.setSelectionGroup(sg); + } + + + ap.repaint(); + } + + void insertGapAtCursor(boolean group) + { + ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence", + av.alignment, HistoryItem.EDIT)); + groupEditing = group; + startseq = seqCanvas.cursorY; + lastres = seqCanvas.cursorX; + editSequence(true, seqCanvas.cursorX+getKeyboardGaps()); + editOccurred(); + } + + void deleteGapAtCursor(boolean group) + { + ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence", + av.alignment, HistoryItem.EDIT)); + groupEditing = group; + startseq = seqCanvas.cursorY; + lastres = seqCanvas.cursorX+getKeyboardGaps(); + editSequence(false, seqCanvas.cursorX); + editOccurred(); + } + + void numberPressed(char value) + { + if(keyboardGaps==null) + keyboardGaps = new StringBuffer(); + + keyboardGaps.append(value); + } + + StringBuffer keyboardGaps; + int getKeyboardGaps() + { + if(keyboardGaps==null) + return 1; + else + return Integer.parseInt(keyboardGaps.toString()); + } + + /** * DOCUMENT ME! * @@ -183,6 +318,7 @@ public class SeqPanel extends JPanel implements MouseListener, public void mouseReleased(MouseEvent evt) { mouseDragging = false; + mouseWheelPressed = false; if (!editingSeqs) { @@ -190,13 +326,10 @@ public class SeqPanel extends JPanel implements MouseListener, return; } - if (seqEditOccurred) - { - editOccurred(); - } + editOccurred(); - endEditing(); - ap.repaint(); + endEditing(); + ap.repaint(); } @@ -230,8 +363,6 @@ public class SeqPanel extends JPanel implements MouseListener, } - ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence", - av.alignment, HistoryItem.EDIT)); int seq = findSeq(evt); int res = findRes(evt); @@ -239,6 +370,9 @@ public class SeqPanel extends JPanel implements MouseListener, if(seq<0 || res<0) return; + ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence", + av.alignment, HistoryItem.EDIT)); + if ((seq < av.getAlignment().getHeight()) && (res < av.getAlignment().getSequenceAt(seq).getLength())) { @@ -251,9 +385,6 @@ public class SeqPanel extends JPanel implements MouseListener, lastres = -1; } - startEdit = lastres; - endEdit = lastres; - return; } @@ -274,6 +405,7 @@ public class SeqPanel extends JPanel implements MouseListener, int res = findRes(evt); int seq = findSeq(evt); + if(res<0 || seq<0 || seq >= av.getAlignment().getHeight()) return; @@ -289,36 +421,7 @@ public class SeqPanel extends JPanel implements MouseListener, seqCanvas.pdbCanvas.highlightRes(sequence.findPosition(res)); } - - StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " + - sequence.getName()); - - Object obj = null; - if (av.alignment.isNucleotide()) - { - obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) + - ""); - if(obj!=null) - text.append(" Nucleotide: "); - } - else - { - obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + ""); - if(obj!=null) - text.append(" Residue: "); - } - - if (obj != null) - { - - if (obj != "") - { - text.append( obj + " (" + - av.getAlignment().getSequenceAt(seq).findPosition(res) + ")"); - } - } - - ap.alignFrame.statusBar.setText(text.toString()); + setStatusMessage(sequence, res, seq); // use aa to see if the mouse pointer is on a if (av.showSequenceFeatures) @@ -334,7 +437,8 @@ public class SeqPanel extends JPanel implements MouseListener, if ( (features[i].getBegin() <= sequence.findPosition(res)) && (features[i].getEnd() >= sequence.findPosition(res))) { - if(!av.featuresDisplayed.containsKey(features[i].getType())) + if(av.featuresDisplayed==null + || !av.featuresDisplayed.containsKey(features[i].getType())) continue; @@ -382,6 +486,39 @@ public class SeqPanel extends JPanel implements MouseListener, } } + void setStatusMessage(SequenceI sequence, int res, int seq) + { + StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " + + sequence.getName()); + + Object obj = null; + if (av.alignment.isNucleotide()) + { + obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) + + ""); + if (obj != null) + text.append(" Nucleotide: "); + } + else + { + obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + ""); + if (obj != null) + text.append(" Residue: "); + } + + if (obj != null) + { + + if (obj != "") + { + text.append(obj + " (" + sequence.findPosition(res) + + ")"); + } + } + ap.alignFrame.statusBar.setText(text.toString()); + + } + /** * DOCUMENT ME! * @@ -407,19 +544,33 @@ public class SeqPanel extends JPanel implements MouseListener, return; } - boolean dragRight = true; - - if ((res < av.getAlignment().getWidth()) && (res < lastres)) + if ( (res < av.getAlignment().getWidth()) && (res < lastres)) { - dragRight = false; + // dragLeft, delete gap + editSequence(false, res); } - else if(av.hasHiddenColumns) + else + editSequence(true, res); + + mouseDragging = true; + if(scrollThread!=null) + scrollThread.setEvent(evt); + + } + + void editSequence(boolean insertGap, int startres) + { + int fixedLeft = -1; + int fixedRight = -1; + boolean fixedColumns = false; + + if(insertGap && av.hasHiddenColumns) { //Stop editing if the user has dragged beyond hiddenBoundary - int lastCol = av.getColumnSelection().getHiddenRegionBoundary(lastres); - if( lastCol < res) + fixedRight = av.getColumnSelection().getHiddenRegionBoundary(lastres); + if( fixedRight < lastres) { - if(lastres!=lastCol) + if(lastres!=fixedRight) { endEditing(); return; @@ -427,220 +578,332 @@ public class SeqPanel extends JPanel implements MouseListener, } } - if(!groupEditing && av.hasHiddenRows) + if (!groupEditing && av.hasHiddenRows) { - if(av.alignment.getSequenceAt(startseq).getHiddenSequences()!=null) + if (av.alignment.getSequenceAt(startseq).getHiddenSequences() != null) { groupEditing = true; } } - if (res != lastres) - { - SequenceI seq; - // Group editing - if (groupEditing) - { - SequenceGroup sg = av.getSelectionGroup(); + SequenceI seq = av.alignment.getSequenceAt(startseq); + StringBuffer message = new StringBuffer(); + if (groupEditing) + message.append("Edit group:"); + else + message.append("Edit sequence: "+seq.getName()); - if (av.hasHiddenRows) - { - //sg might be null as the user may only see 1 sequence - if(sg==null) - { - sg = new SequenceGroup(); - sg.addSequence(av.alignment.getSequenceAt(startseq), false); - } + if(insertGap) + message.append(" insert "); + else + message.append(" delete "); - SequenceGroup tmp = new SequenceGroup(); + message.append(Math.abs(startres-lastres)+" gaps."); + ap.alignFrame.statusBar.setText(message.toString()); - //Do any of the sequences have hidden associates? - for (int s = 0; s < sg.getSize(); s++) - { - seq = sg.getSequenceAt(s); - tmp.addSequence(seq, false); - if (seq.getHiddenSequences()!=null) - { - for(int h=0; h= fixedLeft) + || (startres >= fixedLeft && lastres < fixedLeft) + || (startres > fixedRight && lastres <=fixedRight) + || (startres <= fixedRight && lastres > fixedRight)) + { + endEditing(); + return; + } + + if (fixedLeft > startres) + { + fixedRight = fixedLeft - 1; + fixedLeft = 0; + } + else if (fixedRight < startres) + { + fixedLeft = fixedRight; + fixedRight = -1; + } + } - int blankColumn = -1; + if (groupEditing) + { + SequenceGroup sg = av.getSelectionGroup(); + if(fixedLeft>sg.getEndRes() + ||fixedRight 1) - { - res = lastres+1; - } + SequenceGroup tmp = new SequenceGroup(); + //Do any of the sequences have hidden associates? + for (int s = 0; s < sg.getSize(); s++) + { + seq = sg.getSequenceAt(s); + tmp.addSequence(seq, false); + if (seq.getHiddenSequences() != null) + { + for (int h = 0; h < seq.getHiddenSequences().getSize(); h++) + tmp.addSequence(seq.getHiddenSequences().getSequenceAt(h), + false); + } + } - int lastCol = av.getColumnSelection(). - getHiddenRegionBoundary(res); + sg = tmp; + } - if(lastCol!=res) - { - for (blankColumn = lastCol; - blankColumn > lastres; - blankColumn--) - { - boolean blank = true; - for (int s = 0; s < sg.getSize(); s++) - { - seq = sg.getSequenceAt(s); - - if (seq.getSequence().length() <= blankColumn) - { - continue; - } - - if (!jalview.util.Comparison.isGap( - seq.getSequence().charAt(blankColumn))) - { - blank = false; - continue; - } - } - if (blank) - break; - } - - - if (blankColumn <= lastres) - { - endEditing(); - return; - } - } - else - blankColumn = -1; + if (sg == null) + { + endEditing(); + return; + } - } + // int blankColumn = -1; - sg.setEndRes(sg.getEndRes() + (res - lastres)); - } + // drag to right + if (insertGap) + { + // Is it valid?? + // Find the next gap before the end + // of the visible region boundary + if (av.hasHiddenColumns) + { + // int lastCol = av.getColumnSelection(). + // getHiddenRegionBoundary(res); - // drag to left - else + } + + if (fixedRight != startres && fixedRight lastres; + fixedRight --) { - /// Are we able to delete? - // ie are all columns blank? + boolean blank = true; + for (int s = 0; s < sg.getSize(); s++) + { + seq = sg.getSequenceAt(s); - for (int s = 0; s < sg.getSize(); s++) + if (seq.getSequence().length() <= fixedRight) { - seq = sg.getSequenceAt(s); - - for (int j = res; j < lastres; j++) - { - if (seq.getSequence().length() <= j) - { - continue; - } - - if (!jalview.util.Comparison.isGap( - seq.getSequence().charAt(j))) - { - // Not a gap, block edit not valid - endEditing(); - return; - } - } + continue; } - if(res res) - { - deleteChar(res, seq); - } - } - } + + for (int i = 0; i < sg.getSize(); i++) + { + seq = sg.getSequenceAt(i); + + if (insertGap) + { + // dragging to the right + for (int j = lastres; j < startres; j++) + { + if (fixedColumns && fixedRight != -1) + { + insertChar(j, seq, fixedRight); } + else + insertChar(j, seq); + } } - else /////Editing a single sequence/////////// + else { - seq = av.alignment.getSequenceAt(startseq); - if ((res < av.getAlignment().getWidth()) && (res > lastres)) + // dragging to the left + for (int j = lastres; j > startres; j--) + { + if (fixedColumns && fixedRight != -1) { - // dragging to the right - for (int j = lastres; j < res; j++) - { - insertChar(j, seq, j); - } + deleteChar(startres, seq, fixedRight); } - else if ((res < av.getAlignment().getWidth()) && - (res < lastres)) + else { - // dragging to the left - for (int j = lastres; j > res; j--) - { - if (jalview.util.Comparison.isGap( - av.alignment.getSequenceAt(startseq) - .getSequence().charAt(res))) - { - deleteChar(res, seq); - } - else - { - break; - } - } + deleteChar(startres, seq); } + } } + } } + else /////Editing a single sequence/////////// + { - mouseDragging = true; - if(scrollThread!=null) - scrollThread.setEvent(evt); + if (insertGap) + { + // dragging to the right + for (int j = lastres; j < startres; j++) + { + if (fixedColumns && fixedRight != -1) + insertChar(j, seq, fixedRight); + else + insertChar(j, seq); + } + } + else + { + // dragging to the left + for (int j = lastres; j > startres; j--) + { + if (fixedColumns && fixedRight != -1) + { + deleteChar(startres, seq, fixedRight); + } + else + { + deleteChar(startres, seq); + } + } + } + } - endEdit = res; - lastres = res; + lastres = startres; seqCanvas.repaint(); } + + /** + * DOCUMENT ME! + * + * @param j DOCUMENT ME! + * @param seq DOCUMENT ME! + */ + void insertChar(int j, SequenceI seq) + { + seq.insertCharAt(j, av.getGapCharacter()); + seqEditOccurred = true; + } + + void insertChar(int j, SequenceI seq, int fixedColumn) + { + //Find the next gap before the end of the visible region boundary + //If lastCol > j, theres a boundary after the gap insertion + int blankColumn = fixedColumn; + for (blankColumn = fixedColumn; blankColumn > j; blankColumn--) + { + if (jalview.util.Comparison.isGap(seq.getCharAt(blankColumn))) + { + //Theres a space, so break and insert the gap + break; + } + } + + if (blankColumn <= j) + { + endEditing(); + return; + } + + if (!jalview.util.Comparison.isGap(seq.getCharAt(blankColumn))) + { + //Just Checking + System.out.println("Tried removing residue (INSERT)"+seq.getCharAt(fixedColumn)); + return; + } + + seq.deleteCharAt(blankColumn); + seq.insertCharAt(j, av.getGapCharacter()); + seqEditOccurred = true; + } + + void deleteChar(int j, SequenceI seq, int fixedColumn) + { + if (!jalview.util.Comparison.isGap(seq.getCharAt(j))) + { + ap.alignFrame.statusBar.setText( + "End editing: Tried removing residue " + seq.getCharAt(j)); + return; + } + + seq.deleteCharAt(j); + seq.insertCharAt(fixedColumn, av.getGapCharacter()); + seqEditOccurred = true; + } + + /** + * DOCUMENT ME! + * + * @param j DOCUMENT ME! + * @param seq DOCUMENT ME! + */ + void deleteChar(int j, SequenceI seq) + { + if (!jalview.util.Comparison.isGap(seq.getCharAt(j))) + { + ap.alignFrame.statusBar.setText( + "End editing: Tried removing residue " + seq.getCharAt(j)); + return; + } + + seq.deleteCharAt(j); + seqEditOccurred = true; + seqCanvas.repaint(); + } /** * DOCUMENT ME! * @@ -681,6 +944,7 @@ public class SeqPanel extends JPanel implements MouseListener, public void mouseWheelMoved(MouseWheelEvent e) { + e.consume(); if (mouseWheelPressed) { Font font = av.getFont(); @@ -704,78 +968,6 @@ public class SeqPanel extends JPanel implements MouseListener, } - /** - * DOCUMENT ME! - * - * @param j DOCUMENT ME! - * @param seq DOCUMENT ME! - */ - void insertChar(int j, SequenceI seq, int blankColumn) - { - if(av.hasHiddenColumns) - { - //Find the next gap before the end of the visible region boundary - int lastCol = av.getColumnSelection().getHiddenRegionBoundary(j); - if(lastCol != j) - { - if (!groupEditing || lastCol <= j) - { - blankColumn = lastCol; - //If lastCol > j, theres a boundary after the gap insertion - if (lastCol > j) - { - for (blankColumn = lastCol; blankColumn > j; blankColumn--) - { - if (jalview.util.Comparison.isGap(seq.getCharAt(blankColumn))) - { - //Theres a space, so break and insert the gap - break; - } - } - - if (blankColumn <= j) - { - endEditing(); - return; - } - } - - } - - // Editing with hidden regions only!! - seq.deleteCharAt(blankColumn); - } - } - - seq.insertCharAt(j, av.getGapCharacter()); - seqEditOccurred = true; - } - - /** - * DOCUMENT ME! - * - * @param j DOCUMENT ME! - * @param seq DOCUMENT ME! - */ - public void deleteChar(int j, SequenceI seq) - { - if (av.hasHiddenColumns) - { - //Find the next gap before the end of the visible region boundary - int lastCol = av.getColumnSelection().getHiddenRegionBoundary(j); - - //If lastCol > j, theres a boundary after the gap insertion - if (lastCol > j) - { - seq.insertCharAt(lastCol, av.getGapCharacter()); - } - } - - seq.deleteCharAt(j); - seqEditOccurred = true; - - seqCanvas.repaint(); - } /** * DOCUMENT ME! @@ -784,12 +976,14 @@ public class SeqPanel extends JPanel implements MouseListener, */ void editOccurred() { - if (endEdit == startEdit) + if (!seqEditOccurred) { ap.alignFrame.historyList.pop(); ap.alignFrame.updateEditMenuBar(); } + endEditing(); + av.firePropertyChange("alignment", null,av.getAlignment().getSequences()); } @@ -819,7 +1013,6 @@ public class SeqPanel extends JPanel implements MouseListener, if(seq<0 || res<0) return; - SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq); if ((sequence == null) || (res > sequence.getLength())) @@ -867,6 +1060,15 @@ public class SeqPanel extends JPanel implements MouseListener, } } + if (av.cursorMode) + { + seqCanvas.cursorX = findRes(evt); + seqCanvas.cursorY = findSeq(evt); + seqCanvas.repaint(); + return; + } + + if (stretchGroup == null) { // define a new group here @@ -1106,11 +1308,11 @@ public class SeqPanel extends JPanel implements MouseListener, if (mouseDragging && (evt.getX() < 0)) { - running = ap.scrollRight(true); + running = ap.scrollRight(false); } else if (mouseDragging && (evt.getX() >= getWidth())) { - running = ap.scrollRight(false); + running = ap.scrollRight(true); } } -- 1.7.10.2