X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FSeqPanel.java;h=89e2086a1ebbd81a81e2f2286dc7071a3fc7455c;hb=7724430e3293cbb862d0c50c5308a3b3b0417cac;hp=55bc65a8c50b63ac899b06287a7a884eb5e19ee4;hpb=94bc21544b9573fdf177c500bdb981e8076a7e7d;p=jalview.git diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 55bc65a..89e2086 100755 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -24,6 +24,9 @@ import java.awt.event.*; import jalview.datamodel.*; import jalview.schemes.*; +import jalview.commands.*; + +import java.util.Vector; public class SeqPanel extends Panel implements MouseMotionListener, MouseListener @@ -55,6 +58,11 @@ public class SeqPanel StringBuffer keyboardNo1; StringBuffer keyboardNo2; + boolean mouseWheelPressed = false; + Point lastMousePress; + + EditCommand editCommand; + public SeqPanel(AlignViewport avp, AlignmentPanel p) { this.av = avp; @@ -73,13 +81,20 @@ public class SeqPanel void endEditing() { + if (editCommand!=null && editCommand.getSize() > 0) + { + ap.alignFrame.addHistoryItem(editCommand); + av.firePropertyChange("alignment", null, + av.getAlignment().getSequences()); + } + startseq = -1; lastres = -1; - seqEditOccurred = false; editingSeqs = false; groupEditing = false; keyboardNo1 = null; keyboardNo2 = null; + editCommand = null; } void setCursorRow() @@ -123,6 +138,24 @@ public class SeqPanel { seqCanvas.cursorX += dx; seqCanvas.cursorY += dy; + if (av.hasHiddenColumns && !av.colSel.isVisible(seqCanvas.cursorX)) + { + int original = seqCanvas.cursorX - dx; + int maxWidth = av.alignment.getWidth(); + + while(!av.colSel.isVisible(seqCanvas.cursorX) + && seqCanvas.cursorX0) + { + seqCanvas.cursorX += dx; + } + + if(seqCanvas.cursorX>=maxWidth + || !av.colSel.isVisible(seqCanvas.cursorX) ) + { + seqCanvas.cursorX = original; + } + } scrollToVisible(); } @@ -140,26 +173,32 @@ public class SeqPanel endEditing(); - while (seqCanvas.cursorY < av.startSeq) - { - ap.scrollUp(true); - } - while (seqCanvas.cursorY + 1 > av.endSeq) + if (av.wrapAlignment) { - ap.scrollUp(false); + ap.scrollToWrappedVisible(seqCanvas.cursorX); } - while (seqCanvas.cursorX < av.startRes) + else { + while (seqCanvas.cursorY < av.startSeq) + { + ap.scrollUp(true); + } + while (seqCanvas.cursorY + 1 > av.endSeq) + { + ap.scrollUp(false); + } + while (seqCanvas.cursorX < av.colSel.adjustForHiddenColumns(av.startRes)) + { - if(!ap.scrollRight(false)) - break; - } - while (seqCanvas.cursorX > av.endRes) - { - if(!ap.scrollRight(true)) - break; + if (!ap.scrollRight(false)) + break; + } + while (seqCanvas.cursorX > av.colSel.adjustForHiddenColumns(av.endRes)) + { + if (!ap.scrollRight(true)) + break; + } } - setStatusMessage(av.alignment.getSequenceAt(seqCanvas.cursorY), seqCanvas.cursorX, seqCanvas.cursorY); @@ -212,7 +251,7 @@ public class SeqPanel else { // Now add any sequences between min and max - sg.sequences.removeAllElements(); + sg.getSequences(null).removeAllElements(); for (int i = min; i < max; i++) { sg.addSequence(av.alignment.getSequenceAt(i), false); @@ -235,24 +274,20 @@ public class SeqPanel 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+getKeyboardNo(keyboardNo1)); - editOccurred(); + endEditing(); } void deleteGapAtCursor(boolean group) { - ap.alignFrame.addHistoryItem(new HistoryItem("Edit Sequence", - av.alignment, HistoryItem.EDIT)); groupEditing = group; startseq = seqCanvas.cursorY; lastres = seqCanvas.cursorX+getKeyboardNo(keyboardNo1); editSequence(false, seqCanvas.cursorX); - editOccurred(); + endEditing(); } void numberPressed(char value) @@ -303,15 +338,28 @@ public class SeqPanel ")"); } } + ap.alignFrame.statusBar.setText(text.toString()); } public void mousePressed(MouseEvent evt) { - if (evt.isShiftDown() || evt.isAltDown() || - evt.isControlDown()) + lastMousePress = evt.getPoint(); + + //For now, ignore the mouseWheel font resizing on Macs + //As the Button2_mask always seems to be true + if ( (evt.getModifiers() & InputEvent.BUTTON2_MASK) == + InputEvent.BUTTON2_MASK && !av.MAC) { - if (evt.isAltDown() || evt.isControlDown()) + mouseWheelPressed = true; + return; + } + + if (evt.isShiftDown() + || evt.isControlDown() + || evt.isAltDown()) + { + if (evt.isControlDown() || evt.isAltDown()) { groupEditing = true; } @@ -330,8 +378,6 @@ public class SeqPanel 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())) @@ -354,6 +400,7 @@ public class SeqPanel public void mouseReleased(MouseEvent evt) { mouseDragging = false; + mouseWheelPressed = false; if (!editingSeqs) { @@ -361,10 +408,8 @@ public class SeqPanel return; } - editOccurred(); - endEditing(); - ap.repaint(); + ap.repaint(); } int startWrapBlock=-1; @@ -390,6 +435,8 @@ public class SeqPanel int cwidth = seqCanvas.getWrappedCanvasWidth(getSize().width); + if(cwidth<1) + return 0; wrappedBlock = y / cHeight; wrappedBlock += av.getStartRes() / cwidth; @@ -402,6 +449,9 @@ public class SeqPanel res = (x / av.getCharWidth()) + av.getStartRes(); } + if(av.hasHiddenColumns) + res = av.getColumnSelection().adjustForHiddenColumns(res); + return res; } @@ -423,11 +473,17 @@ public class SeqPanel y -= hgap; - seq = ( (y % cHeight) / av.getCharHeight()); + seq = Math.min( (y % cHeight) / av.getCharHeight(), + av.alignment.getHeight() -1); + if(seq<0) + seq = 0; } else { - seq = (y / av.getCharHeight()) + av.getStartSeq(); + seq = Math.min( (y / av.getCharHeight()) + av.getStartSeq(), + av.alignment.getHeight() -1); + if(seq<0) + seq = 0; } return seq; @@ -436,8 +492,6 @@ public class SeqPanel public void doMousePressed(MouseEvent evt) { - ap.alignFrame.addHistoryItem(new HistoryItem( - "Edit Sequence", av.alignment, HistoryItem.EDIT)); int seq = findSeq(evt); int res = findRes(evt); @@ -497,11 +551,9 @@ public class SeqPanel if (obj != null) { - if (obj != "") { - text.append(obj + " (" + - av.getAlignment().getSequenceAt(seq).findPosition(res) + ")"); + text.append(obj + " (" + sequence.findPosition(res) + ")"); } } @@ -510,61 +562,140 @@ public class SeqPanel seqCanvas.pdbCanvas.highlightRes(sequence.findPosition(res)); } + ap.alignFrame.statusBar.setText(text.toString()); + // use aa to see if the mouse pointer is on a if (av.showSequenceFeatures && sequence.getSequenceFeatures()!=null && av.featuresDisplayed!=null) { + StringBuffer featureText = new StringBuffer(); + Vector allFeatures = getAllFeaturesAtRes(sequence, sequence.findPosition(res)); + int index = 0; - sequence.getSequenceFeatures(); - boolean first = true; - while (index < sequence.getSequenceFeatures().length) + while (index < allFeatures.size()) { - SequenceFeature sf = sequence.getSequenceFeatures()[index]; - if (sf.getBegin() <= sequence.findPosition(res) && - sf.getEnd() >= sequence.findPosition(res)) + SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(index); + + featureText.append(sf.getType()+" "+sf.begin+":"+sf.end); + + if (sf.getDescription() != null) + featureText.append(" " + sf.getDescription()); + + if (sf.getValue("status") != null ) { - if(!av.featuresDisplayed.containsKey(sf.getType())) - { - index++; - continue; - } + String status = sf.getValue("status").toString(); + if(status.length()>0) + featureText.append(" (" + sf.getValue("status") + ")"); + } + featureText.append("\n"); - if(first) - { - text.append(" Sequence Feature:"); - first = false; - } + index++; + } + + + if (tooltip == null) + tooltip = new Tooltip(featureText.toString(), seqCanvas); + else + tooltip.setTip(featureText.toString()); - text.append(" "+sf.getType()); + tooltip.repaint(); - if(sf.getDescription()!=null) - text.append(" "+sf.getDescription()); + } + else if (tooltip != null) + { + tooltip.setTip(""); + } + } - if (sf.getStatus()!=null && sf.getStatus().length() > 0) + Vector getAllFeaturesAtRes(SequenceI seq, int res) + { + Vector allFeatures = new Vector(); + int index = 0; + if(seq.getSequenceFeatures()!=null) + { + while (index < seq.getSequenceFeatures().length) + { + SequenceFeature sf = seq.getSequenceFeatures()[index]; + if (sf.getBegin() <= res && + sf.getEnd() >= res) + { + if (av.featuresDisplayed.containsKey(sf.getType())) { - text.append(" (" + sf.getStatus() + ")"); + allFeatures.addElement(sf); } - text.append("; "); } - index++; - } } - - ap.alignFrame.statusBar.setText(text.toString()); - + return allFeatures; } + Tooltip tooltip; + public void mouseDragged(MouseEvent evt) { - if (!editingSeqs) -{ - doMouseDraggedDefineMode(evt); - return; -} + if (mouseWheelPressed) + { + int oldWidth = av.charWidth; + + //Which is bigger, left-right or up-down? + if (Math.abs(evt.getY() - lastMousePress.y) + > Math.abs(evt.getX() - lastMousePress.x)) + { + int fontSize = av.font.getSize(); + + if (evt.getY() < lastMousePress.y && av.charHeight > 1) + { + fontSize--; + } + else if (evt.getY() > lastMousePress.y) + { + fontSize++; + } + + + if(fontSize<1) + fontSize = 1; + + av.setFont(new Font(av.font.getName(), av.font.getStyle(), fontSize)); + av.charWidth = oldWidth; + } + else + { + if (evt.getX() < lastMousePress.x && av.charWidth > 1) + { + av.charWidth--; + } + else if (evt.getX() > lastMousePress.x) + { + av.charWidth++; + } + + if(av.charWidth<1) + { + av.charWidth = 1; + } + } + + ap.fontChanged(); + + FontMetrics fm = getFontMetrics(av.getFont()); + av.validCharWidth = fm.charWidth('M') <= av.charWidth; + + lastMousePress = evt.getPoint(); + + ap.repaint(); + ap.annotationPanel.image = null; + return; + } + + if (!editingSeqs) + { + doMouseDraggedDefineMode(evt); + return; + } int res = findRes(evt); @@ -593,250 +724,339 @@ public class SeqPanel } synchronized void editSequence(boolean insertGap, int startres) - { - int fixedLeft = -1; - int fixedRight = -1; - boolean fixedColumns = false; - SequenceGroup sg = av.getSelectionGroup(); + { + int fixedLeft = -1; + int fixedRight = -1; + boolean fixedColumns = false; + SequenceGroup sg = av.getSelectionGroup(); - if(groupEditing && sg==null) - return; + SequenceI seq = av.alignment.getSequenceAt(startseq); - SequenceI seq = av.alignment.getSequenceAt(startseq); - StringBuffer message = new StringBuffer(); - if (groupEditing) - message.append("Edit group:"); - else - message.append("Edit sequence: "+seq.getName()); + if (!groupEditing && av.hasHiddenRows) + { + if (av.hiddenRepSequences!=null + && av.hiddenRepSequences.containsKey(seq)) + { + sg = (SequenceGroup)av.hiddenRepSequences.get(seq); + groupEditing = true; + } + } + + StringBuffer message = new StringBuffer(); + if (groupEditing) + { + message.append("Edit group:"); + if (editCommand == null) + editCommand = new EditCommand("Edit Group"); + } + else + { + message.append("Edit sequence: " + seq.getName()); + String label = seq.getName(); + if(label.length()>10) + label = label.substring(0,10); + if(editCommand==null) + editCommand = new EditCommand("Edit "+label); + } + + if(insertGap) + message.append(" insert "); + else + message.append(" delete "); + + message.append(Math.abs(startres-lastres)+" gaps."); + ap.alignFrame.statusBar.setText(message.toString()); - if(insertGap) - message.append(" insert "); - else - message.append(" delete "); - message.append(Math.abs(startres-lastres)+" gaps."); - ap.alignFrame.statusBar.setText(message.toString()); + //Are we editing within a selection group? + if (groupEditing + || (sg != null && sg.getSequences(av.hiddenRepSequences).contains(seq))) + { + fixedColumns = true; + //sg might be null as the user may only see 1 sequence, + //but the sequence represents a group + if (sg == null) + { + sg = (SequenceGroup) av.hiddenRepSequences.get(seq); + } - //Are we editing within a selection group? - if (groupEditing - || (sg != null && sg.sequences.contains(seq))) + fixedLeft = sg.getStartRes(); + fixedRight = sg.getEndRes(); + + if ( (startres < fixedLeft && lastres >= fixedLeft) + || (startres >= fixedLeft && lastres < fixedLeft) + || (startres > fixedRight && lastres <=fixedRight) + || (startres <= fixedRight && lastres > fixedRight)) { - fixedColumns = true; + endEditing(); + return; + } + + if (fixedLeft > startres) + { + fixedRight = fixedLeft - 1; + fixedLeft = 0; + } + else if (fixedRight < startres) + { + fixedLeft = fixedRight; + fixedRight = -1; + } + } + - fixedLeft = sg.getStartRes(); - fixedRight = sg.getEndRes(); + if(av.hasHiddenColumns ) + { + fixedColumns = true; + int y1 = av.getColumnSelection().getHiddenBoundaryLeft(startres); + int y2 = av.getColumnSelection().getHiddenBoundaryRight(startres); - if ( (startres < fixedLeft && lastres >= fixedLeft) - || (startres >= fixedLeft && lastres < fixedLeft) - || (startres > fixedRight && lastres <=fixedRight) - || (startres <= fixedRight && lastres > fixedRight)) + if ( (insertGap && startres > y1 && lastres < y1) + || (!insertGap && startres < y2 && lastres > y2)) { endEditing(); return; } - if (fixedLeft > startres) + //System.out.print(y1+" "+y2+" "+fixedLeft+" "+fixedRight+"~~"); + //Selection spans a hidden region + if(fixedLefty2 || fixedRight==-1)) { - fixedRight = fixedLeft - 1; - fixedLeft = 0; - } - else if (fixedRight < startres) - { - fixedLeft = fixedRight; - fixedRight = -1; + if(startres>=y2) + { + fixedLeft = y2; + } + else + { + fixedRight = y2 - 1; + } } - } + } - if (groupEditing) + if (groupEditing) + { + Vector vseqs = sg.getSequences(av.hiddenRepSequences); + int g, groupSize = vseqs.size(); + SequenceI[] groupSeqs = new SequenceI[groupSize]; + for (g = 0; g < groupSeqs.length; g++) + groupSeqs[g] = (SequenceI) vseqs.elementAt(g); + + // drag to right + if (insertGap) { - // drag to right - if (insertGap) + //If the user has selected the whole sequence, and is dragging to + // the right, we can still extend the alignment and selectionGroup + if( sg.getStartRes() == 0 + && sg.getEndRes() == fixedRight + && sg.getEndRes() == av.alignment.getWidth()-1 + ) + { + sg.setEndRes(av.alignment.getWidth() + startres - lastres); + fixedRight = sg.getEndRes(); + } + + // Is it valid with fixed columns?? + // Find the next gap before the end + // of the visible region boundary + boolean blank = false; + for (fixedRight = fixedRight; + fixedRight > lastres; + fixedRight--) { - //If the user has selected the whole sequence, and is dragging to - // the right, we can still extend the alignment and selectionGroup - if(sg.getStartRes() == 0 && sg.getEndRes() + 1 == av.alignment.getWidth()) - { - sg.setEndRes(av.alignment.getWidth() + startres - lastres); - fixedRight = sg.getEndRes(); - } + blank = true; - // Is it valid with fixed columns?? - // Find the next gap before the end - // of the visible region boundary - boolean blank = false; - for (fixedRight = fixedRight; - fixedRight > lastres; - fixedRight--) + for (g = 0; g < groupSize; g++) { - blank = true; - for (int s = 0; s < sg.getSize(); s++) + for (int j = 0; j < startres - lastres; j++) { - seq = sg.getSequenceAt(s); - for (int j = 0; j < startres - lastres; j++) + if (!jalview.util.Comparison.isGap( + groupSeqs[g].getCharAt(fixedRight - j))) { - if (!jalview.util.Comparison.isGap( - seq.getCharAt(fixedRight - j))) - { - blank = false; - break; - } + blank = false; + break; } } - if (blank) - break; } + if (blank) + break; + } - if (!blank) + if (!blank) + { + if(sg.getSize() == av.alignment.getHeight() ) { - if(sg.getSize() == av.alignment.getHeight()) - { - //We can still insert gaps if the selectionGroup - //contains all the sequences - sg.setEndRes(sg.getEndRes()+startres-lastres); - fixedRight = av.alignment.getWidth()+startres-lastres; - } - else + if((av.hasHiddenColumns + && startresalWidth) + alWidth = hwidth; + } + //We can still insert gaps if the selectionGroup + //contains all the sequences + sg.setEndRes(sg.getEndRes()+startres-lastres); + fixedRight = alWidth+startres-lastres; + } + else + { + endEditing(); + return; } } + } - // drag to left - else if(!insertGap) - { - /// Are we able to delete? - // ie are all columns blank? + // drag to left + else if(!insertGap) + { + /// Are we able to delete? + // ie are all columns blank? - for (int s = 0; s < sg.getSize(); s++) + for (g = 0; g < groupSize; g++) + { + for (int j = startres; j < lastres; j++) { - seq = sg.getSequenceAt(s); - - for (int j = startres; j < lastres; j++) + if (groupSeqs[g].getLength() <= j) { - if (seq.getSequence().length() <= j) - { - continue; - } + continue; + } - if (!jalview.util.Comparison.isGap( - seq.getSequence().charAt(j))) - { - // Not a gap, block edit not valid - endEditing(); - return; - } + if (!jalview.util.Comparison.isGap( + groupSeqs[g].getCharAt(j))) + { + // Not a gap, block edit not valid + endEditing(); + return; } } } + } - - for (int i = 0; i < sg.getSize(); i++) + if (insertGap) { - seq = sg.getSequenceAt(i); - - if (insertGap) + // dragging to the right + if (fixedColumns && fixedRight != -1) { - // dragging to the right for (int j = lastres; j < startres; j++) { - if (fixedColumns && fixedRight != -1) - { - insertChar(j, seq, fixedRight); - } - else - insertChar(j, seq); + insertChar(j, groupSeqs, fixedRight); } } else { - // dragging to the left + editCommand.appendEdit(EditCommand.INSERT_GAP, + groupSeqs, + startres, startres-lastres, + av.getGapCharacter(), + true); + } + } + else + { + // dragging to the left + if (fixedColumns && fixedRight != -1) + { for (int j = lastres; j > startres; j--) { - if (fixedColumns && fixedRight != -1) - { - deleteChar(startres, seq, fixedRight); - } - else - { - deleteChar(startres, seq); - } + deleteChar(startres, groupSeqs, fixedRight); } } + else + editCommand.appendEdit(EditCommand.DELETE_GAP, + groupSeqs, + startres, lastres - startres, + av.getGapCharacter(), + true); + } - } - else /////Editing a single sequence/////////// + } + else /////Editing a single sequence/////////// + { + if (insertGap) { - if (insertGap) + // dragging to the right + if (fixedColumns && fixedRight != -1) { - // dragging to the right for (int j = lastres; j < startres; j++) { - if (fixedColumns && fixedRight != -1) - { - if (sg.getStartRes() == 0 - && sg.getEndRes() + 1 == av.alignment.getWidth() - && !jalview.util.Comparison.isGap(seq.getCharAt(fixedRight))) - { - //Single sequence edit, whole sequence selected, - //extend the selection group - sg.setEndRes(av.alignment.getWidth() -1 + startres - lastres); - fixedColumns = false; - insertChar(j, seq); - } - else - insertChar(j, seq, fixedRight); - } - else - insertChar(j, seq); + insertChar(j, new SequenceI[]{seq}, fixedRight); } } else { - // dragging to the left + editCommand.appendEdit(EditCommand.INSERT_GAP, + new SequenceI[] + {seq}, + lastres, startres-lastres, + av.getGapCharacter(), + true); + } + } + else + { + // dragging to the left + if (fixedColumns && fixedRight != -1) + { for (int j = lastres; j > startres; j--) { - if (fixedColumns && fixedRight != -1) - { - deleteChar(startres, seq, fixedRight); - } - else + if (!jalview.util.Comparison.isGap(seq.getCharAt(startres))) { - deleteChar(startres, seq); + endEditing(); + break; } + deleteChar(startres, new SequenceI[]{seq}, fixedRight); + } + } + else + { + //could be a keyboard edit trying to delete none gaps + int max=0; + for(int m = startres; m0) + { + editCommand.appendEdit(EditCommand.DELETE_GAP, + new SequenceI[] + {seq}, + startres, max, + av.getGapCharacter(), + true); } } } + } - lastres = startres; - seqCanvas.repaint(); - } + 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) + void insertChar(int j, SequenceI [] seq, int fixedColumn) + { + int blankColumn = fixedColumn; + for(int s=0; s 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))) + if (jalview.util.Comparison.isGap(seq[s].getCharAt(blankColumn))) { //Theres a space, so break and insert the gap break; @@ -845,74 +1065,35 @@ public class SeqPanel if (blankColumn <= j) { + blankColumn = fixedColumn; 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; - } + editCommand.appendEdit(EditCommand.DELETE_GAP, + seq, + blankColumn, 1, av.getGapCharacter(), true); - seq.deleteCharAt(j); - seq.insertCharAt(fixedColumn, av.getGapCharacter()); - seqEditOccurred = true; - } + editCommand.appendEdit(EditCommand.INSERT_GAP, + seq, + j, 1, av.getGapCharacter(), + 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! - * - * @param i DOCUMENT ME! - */ - void editOccurred() - { - if (!seqEditOccurred) - { - ap.alignFrame.historyList.pop(); - ap.alignFrame.updateEditMenuBar(); - } + void deleteChar(int j, SequenceI [] seq, int fixedColumn) + { - endEditing(); + editCommand.appendEdit(EditCommand.DELETE_GAP, + seq, + j, 1, av.getGapCharacter(), true); - av.firePropertyChange("alignment", null,av.getAlignment().getSequences()); + editCommand.appendEdit(EditCommand.INSERT_GAP, + seq, + fixedColumn, 1, av.getGapCharacter(), true); + } - } ////////////////////////////////////////// /////Everything below this is for defining the boundary of the rubberband @@ -956,7 +1137,7 @@ public class SeqPanel } } - else if (!stretchGroup.sequences.contains(sequence) + else if (!stretchGroup.getSequences(null).contains(sequence) || stretchGroup.getStartRes() > res || stretchGroup.getEndRes() < res) { @@ -972,57 +1153,76 @@ public class SeqPanel allGroups[i].getEndRes() >= res) { stretchGroup = allGroups[i]; - av.setSelectionGroup(stretchGroup); break; } } } + av.setSelectionGroup(stretchGroup); } - if (stretchGroup == null) - { - // define a new group here - SequenceGroup sg = new SequenceGroup(); - sg.setStartRes(res); - sg.setEndRes(res); - sg.addSequence(sequence, false); - av.setSelectionGroup(sg); - stretchGroup = sg; - - if (av.getConservationSelected()) - { - SliderPanel.setConservationSlider(ap, av.getGlobalColourScheme(), - "Background"); - } - if (av.getAbovePIDThreshold()) - { - SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(), - "Background"); - } - - } // DETECT RIGHT MOUSE BUTTON IN AWT - else if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK) == + if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { - APopupMenu popup = new APopupMenu(ap, null, null); + Vector allFeatures = getAllFeaturesAtRes(sequence, + sequence.findPosition(res)); + + Vector links = null; + if(allFeatures!=null) + { + for (int i = 0; i < allFeatures.size(); i++) + { + SequenceFeature sf = (SequenceFeature) allFeatures.elementAt(i); + if (sf.links != null) + { + links = new Vector(); + for (int j = 0; j < sf.links.size(); j++) + { + links.addElement(sf.links.elementAt(j)); + } + } + } + } + APopupMenu popup = new APopupMenu(ap, null, links); this.add(popup); popup.show(this, evt.getX(), evt.getY()); + ap.repaint(); + return; } - if (stretchGroup != null && stretchGroup.getEndRes() == res) + if (av.cursorMode) { - // Edit end res position of selected group - changeEndRes = true; + seqCanvas.cursorX = findRes(evt); + seqCanvas.cursorY = findSeq(evt); + seqCanvas.repaint(); + return; } - else if (stretchGroup != null && stretchGroup.getStartRes() == res) - { - // Edit end res position of selected group - changeStartRes = true; - } + //Only if left mouse button do we want to change group sizes + if (stretchGroup == null) + { + // define a new group here + SequenceGroup sg = new SequenceGroup(); + sg.setStartRes(res); + sg.setEndRes(res); + sg.addSequence(sequence, false); + av.setSelectionGroup(sg); + stretchGroup = sg; + + if (av.getConservationSelected()) + { + SliderPanel.setConservationSlider(ap, av.getGlobalColourScheme(), + "Background"); + } + if (av.getAbovePIDThreshold()) + { + SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(), + "Background"); + } + + } } public void doMouseReleasedDefineMode(MouseEvent evt) @@ -1036,11 +1236,18 @@ public class SeqPanel { if (stretchGroup.cs instanceof ClustalxColourScheme) { - ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX(stretchGroup. - sequences, + ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX( + stretchGroup.getSequences(av.hiddenRepSequences), stretchGroup.getWidth()); } + if (stretchGroup.cs instanceof Blosum62ColourScheme + || stretchGroup.cs instanceof PIDColourScheme + || stretchGroup.cs.conservationApplied() + || stretchGroup.cs.getThreshold() > 0) + stretchGroup.recalcConservation(); + + if (stretchGroup.cs.conservationApplied()) { SliderPanel.setConservationSlider(ap, stretchGroup.cs, @@ -1056,7 +1263,7 @@ public class SeqPanel changeEndRes = false; changeStartRes = false; stretchGroup = null; - PaintRefresher.Refresh(av.alignment); + PaintRefresher.Refresh(ap, av.getSequenceSetId()); ap.repaint(); } @@ -1081,7 +1288,7 @@ public class SeqPanel y = av.alignment.getHeight() -1; } - if(res>av.alignment.getWidth()) + if(res>=av.alignment.getWidth()) res = av.alignment.getWidth()-1; if (stretchGroup.getEndRes() == res) @@ -1140,7 +1347,7 @@ public class SeqPanel Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq); - if (stretchGroup.sequences.contains(nextSeq)) + if (stretchGroup.getSequences(null).contains(nextSeq)) { stretchGroup.deleteSequence(seq, false); } @@ -1198,6 +1405,28 @@ public class SeqPanel } } + void scrollCanvas(MouseEvent evt) + { + if(evt==null) + { + if(scrollThread!=null) + { + scrollThread.running = false; + scrollThread = null; + } + mouseDragging = false; + } + else + { + if (scrollThread == null) + scrollThread = new ScrollThread(); + + mouseDragging = true; + scrollThread.setEvent(evt); + } + + } + // this class allows scrolling off the bottom of the visible alignment class ScrollThread extends Thread @@ -1241,12 +1470,12 @@ public class SeqPanel if (mouseDragging && evt.getX() < 0) { - running = ap.scrollRight(true); + running = ap.scrollRight(false); } else if (mouseDragging && evt.getX() >= getSize().width) { - running = ap.scrollRight(false); + running = ap.scrollRight(true); } }