X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FSeqPanel.java;h=89e2086a1ebbd81a81e2f2286dc7071a3fc7455c;hb=0452450533728e478ef8c893ea2cb3483c740fb3;hp=93bca053a45c70df6f0c8bf681e43668ccc55b72;hpb=5cd5b6e7864fe435ceb3f5c2f339a436ea0aac93;p=jalview.git diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 93bca05..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,7 @@ import java.awt.event.*; import jalview.datamodel.*; import jalview.schemes.*; +import jalview.commands.*; import java.util.Vector; @@ -60,6 +61,8 @@ public class SeqPanel boolean mouseWheelPressed = false; Point lastMousePress; + EditCommand editCommand; + public SeqPanel(AlignViewport avp, AlignmentPanel p) { this.av = avp; @@ -78,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() @@ -128,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(); } @@ -159,13 +187,13 @@ public class SeqPanel { ap.scrollUp(false); } - while (seqCanvas.cursorX < av.startRes) + while (seqCanvas.cursorX < av.colSel.adjustForHiddenColumns(av.startRes)) { if (!ap.scrollRight(false)) break; } - while (seqCanvas.cursorX > av.endRes) + while (seqCanvas.cursorX > av.colSel.adjustForHiddenColumns(av.endRes)) { if (!ap.scrollRight(true)) break; @@ -187,7 +215,7 @@ public class SeqPanel 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) @@ -223,7 +251,7 @@ public class SeqPanel else { // Now add any sequences between min and max - sg.getSequences(false).removeAllElements(); + sg.getSequences(null).removeAllElements(); for (int i = min; i < max; i++) { sg.addSequence(av.alignment.getSequenceAt(i), false); @@ -246,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) @@ -322,17 +346,20 @@ public class SeqPanel { 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) + InputEvent.BUTTON2_MASK && !av.MAC) { mouseWheelPressed = true; return; } - if (evt.isShiftDown() || evt.isAltDown() || - evt.isControlDown()) + if (evt.isShiftDown() + || evt.isControlDown() + || evt.isAltDown()) { - if (evt.isAltDown() || evt.isControlDown()) + if (evt.isControlDown() || evt.isAltDown()) { groupEditing = true; } @@ -351,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())) @@ -383,8 +408,6 @@ public class SeqPanel return; } - editOccurred(); - endEditing(); ap.repaint(); } @@ -412,6 +435,8 @@ public class SeqPanel int cwidth = seqCanvas.getWrappedCanvasWidth(getSize().width); + if(cwidth<1) + return 0; wrappedBlock = y / cHeight; wrappedBlock += av.getStartRes() / cwidth; @@ -467,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); @@ -562,7 +585,9 @@ public class SeqPanel if (sf.getValue("status") != null ) { - featureText.append(" (" + sf.getValue("status") + ")"); + String status = sf.getValue("status").toString(); + if(status.length()>0) + featureText.append(" (" + sf.getValue("status") + ")"); } featureText.append("\n"); @@ -578,6 +603,10 @@ public class SeqPanel tooltip.repaint(); } + else if (tooltip != null) + { + tooltip.setTip(""); + } } Vector getAllFeaturesAtRes(SequenceI seq, int res) @@ -701,29 +730,34 @@ public class SeqPanel boolean fixedColumns = false; SequenceGroup sg = av.getSelectionGroup(); + SequenceI seq = av.alignment.getSequenceAt(startseq); if (!groupEditing && av.hasHiddenRows) { - if (av.alignment.getSequenceAt(startseq).getHiddenSequences() != null) + if (av.hiddenRepSequences!=null + && av.hiddenRepSequences.containsKey(seq)) { + sg = (SequenceGroup)av.hiddenRepSequences.get(seq); groupEditing = true; - } - } - - //No group, but the sequence may represent a group - if (groupEditing - && sg == null - && av.alignment.getSequenceAt(startseq).getHiddenSequences() == null) - { - groupEditing = false; + } } - SequenceI seq = av.alignment.getSequenceAt(startseq); StringBuffer message = new StringBuffer(); if (groupEditing) - message.append("Edit group:"); + { + message.append("Edit group:"); + if (editCommand == null) + editCommand = new EditCommand("Edit Group"); + } else - message.append("Edit sequence: "+seq.getName()); + { + 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 "); @@ -736,7 +770,7 @@ public class SeqPanel //Are we editing within a selection group? if (groupEditing - || (sg != null && sg.getSequences(true).contains(seq))) + || (sg != null && sg.getSequences(av.hiddenRepSequences).contains(seq))) { fixedColumns = true; @@ -744,9 +778,7 @@ public class SeqPanel //but the sequence represents a group if (sg == null) { - sg = new SequenceGroup(null, null, false, false, false, 0, - av.alignment.getWidth()-1); - sg.addSequence(av.alignment.getSequenceAt(startseq), false); + sg = (SequenceGroup) av.hiddenRepSequences.get(seq); } fixedLeft = sg.getStartRes(); @@ -805,6 +837,12 @@ public class SeqPanel 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) { @@ -828,13 +866,13 @@ public class SeqPanel fixedRight--) { blank = true; - for (int s = 0; s < sg.getSize(true); s++) + + for (g = 0; g < groupSize; g++) { - seq = (SequenceI)sg.getSequences(true).elementAt(s); for (int j = 0; j < startres - lastres; j++) { if (!jalview.util.Comparison.isGap( - seq.getCharAt(fixedRight - j))) + groupSeqs[g].getCharAt(fixedRight - j))) { blank = false; break; @@ -847,7 +885,7 @@ public class SeqPanel if (!blank) { - if(sg.getSize(false) == av.alignment.getHeight() ) + if(sg.getSize() == av.alignment.getHeight() ) { if((av.hasHiddenColumns && startres startres; j--) + if (fixedColumns && fixedRight != -1) { - if (fixedColumns && fixedRight != -1) - { - deleteChar(startres, seq, fixedRight); - } - else + for (int j = lastres; j > startres; j--) { - 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/////////// { if (insertGap) { // dragging to the right - for (int j = lastres; j < startres; j++) + if (fixedColumns && fixedRight != -1) { - if (fixedColumns && fixedRight != -1) + for (int j = lastres; j < startres; j++) { - insertChar(j, seq, fixedRight); + insertChar(j, new SequenceI[]{seq}, fixedRight); } - else - insertChar(j, seq); + } + else + { + editCommand.appendEdit(EditCommand.INSERT_GAP, + new SequenceI[] + {seq}, + lastres, startres-lastres, + av.getGapCharacter(), + true); } } else { // dragging to the left - for (int j = lastres; j > startres; j--) + if (fixedColumns && fixedRight != -1) { - if (fixedColumns && fixedRight != -1) + for (int j = lastres; j > startres; j--) { - deleteChar(startres, seq, fixedRight); + if (!jalview.util.Comparison.isGap(seq.getCharAt(startres))) + { + endEditing(); + break; + } + deleteChar(startres, new SequenceI[]{seq}, fixedRight); } - else + } + 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); } } } @@ -977,26 +1045,18 @@ public class SeqPanel } - /** - * 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; @@ -1005,82 +1065,41 @@ 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; - } - - seq.deleteCharAt(j); - seq.insertCharAt(fixedColumn, av.getGapCharacter()); - seqEditOccurred = true; - } + editCommand.appendEdit(EditCommand.DELETE_GAP, + seq, + blankColumn, 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; - } + editCommand.appendEdit(EditCommand.INSERT_GAP, + seq, + j, 1, av.getGapCharacter(), + true); - 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 ////////////////////////////////////////// public void doMousePressedDefineMode(MouseEvent evt) { - - if (scrollThread != null) { scrollThread.running = false; @@ -1118,7 +1137,7 @@ public class SeqPanel } } - else if (!stretchGroup.getSequences(false).contains(sequence) + else if (!stretchGroup.getSequences(null).contains(sequence) || stretchGroup.getStartRes() > res || stretchGroup.getEndRes() < res) { @@ -1141,15 +1160,6 @@ public class SeqPanel av.setSelectionGroup(stretchGroup); } - if (av.cursorMode) - { - seqCanvas.cursorX = findRes(evt); - seqCanvas.cursorY = findSeq(evt); - seqCanvas.repaint(); - return; - } - - // DETECT RIGHT MOUSE BUTTON IN AWT if ( (evt.getModifiers() & InputEvent.BUTTON3_MASK) == @@ -1178,9 +1188,17 @@ public class SeqPanel this.add(popup); popup.show(this, evt.getX(), evt.getY()); ap.repaint(); + return; } - else + + if (av.cursorMode) { + seqCanvas.cursorX = findRes(evt); + seqCanvas.cursorY = findSeq(evt); + seqCanvas.repaint(); + return; + } + //Only if left mouse button do we want to change group sizes if (stretchGroup == null) @@ -1205,19 +1223,6 @@ public class SeqPanel } } - - if (stretchGroup != null && stretchGroup.getEndRes() == res) - { - // Edit end res position of selected group - changeEndRes = true; - } - - else if (stretchGroup != null && stretchGroup.getStartRes() == res) - { - // Edit end res position of selected group - changeStartRes = true; - } - } } public void doMouseReleasedDefineMode(MouseEvent evt) @@ -1232,10 +1237,17 @@ public class SeqPanel if (stretchGroup.cs instanceof ClustalxColourScheme) { ( (ClustalxColourScheme) stretchGroup.cs).resetClustalX( - stretchGroup.getSequences(true), + 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, @@ -1251,7 +1263,7 @@ public class SeqPanel changeEndRes = false; changeStartRes = false; stretchGroup = null; - PaintRefresher.Refresh(av.alignment); + PaintRefresher.Refresh(ap, av.getSequenceSetId()); ap.repaint(); } @@ -1276,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) @@ -1335,7 +1347,7 @@ public class SeqPanel Sequence nextSeq = (Sequence) av.getAlignment().getSequenceAt(oldSeq); - if (stretchGroup.getSequences(false).contains(nextSeq)) + if (stretchGroup.getSequences(null).contains(nextSeq)) { stretchGroup.deleteSequence(seq, false); }