X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FSeqPanel.java;h=056a602768b5debbb85d18bc5de50ad6c7af523e;hb=a990c2c6facfd04d61d316dcafba31d03747d162;hp=a6fa141fbe476916ee68af74206d6913c0b15649;hpb=80e3c4b6e17a6262ccbc193b9824ea3700a86f87;p=jalview.git diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index a6fa141..056a602 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -62,6 +62,7 @@ import java.awt.event.MouseWheelListener; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.ListIterator; import javax.swing.JPanel; import javax.swing.SwingUtilities; @@ -73,9 +74,9 @@ import javax.swing.ToolTipManager; * @author $author$ * @version $Revision: 1.130 $ */ -public class SeqPanel extends JPanel implements MouseListener, - MouseMotionListener, MouseWheelListener, SequenceListener, - SelectionListener +public class SeqPanel extends JPanel + implements MouseListener, MouseMotionListener, MouseWheelListener, + SequenceListener, SelectionListener { /** DOCUMENT ME!! */ @@ -188,6 +189,7 @@ public class SeqPanel extends JPanel implements MouseListener, int res = 0; int x = evt.getX(); + int startRes = av.getRanges().getStartRes(); if (av.getWrapAlignment()) { @@ -202,7 +204,7 @@ public class SeqPanel extends JPanel implements MouseListener, int y = evt.getY(); y -= hgap; - x -= seqCanvas.LABEL_WEST; + x = Math.max(0, x - seqCanvas.LABEL_WEST); int cwidth = seqCanvas.getWrappedCanvasWidth(this.getWidth()); if (cwidth < 1) @@ -211,10 +213,11 @@ public class SeqPanel extends JPanel implements MouseListener, } wrappedBlock = y / cHeight; - wrappedBlock += av.getRanges().getStartRes() / cwidth; - - res = wrappedBlock * cwidth + x / av.getCharWidth(); - + wrappedBlock += startRes / cwidth; + // allow for wrapped view scrolled right (possible from Overview) + int startOffset = startRes % cwidth; + res = wrappedBlock * cwidth + startOffset + + +Math.min(cwidth - 1, x / av.getCharWidth()); } else { @@ -224,7 +227,7 @@ public class SeqPanel extends JPanel implements MouseListener, // right-hand gutter x = seqCanvas.getX() + seqCanvas.getWidth(); } - res = (x / av.getCharWidth()) + av.getRanges().getStartRes(); + res = (x / av.getCharWidth()) + startRes; if (res > av.getRanges().getEndRes()) { // moused off right @@ -260,15 +263,14 @@ public class SeqPanel extends JPanel implements MouseListener, y -= hgap; - seq = Math.min((y % cHeight) / av.getCharHeight(), av.getAlignment() - .getHeight() - 1); + seq = Math.min((y % cHeight) / av.getCharHeight(), + av.getAlignment().getHeight() - 1); } else { - seq = Math.min((y / av.getCharHeight()) - + av.getRanges().getStartSeq(), - av - .getAlignment().getHeight() - 1); + seq = Math.min( + (y / av.getCharHeight()) + av.getRanges().getStartSeq(), + av.getAlignment().getHeight() - 1); } return seq; @@ -285,8 +287,8 @@ public class SeqPanel extends JPanel implements MouseListener, if (editCommand != null && editCommand.getSize() > 0) { ap.alignFrame.addHistoryItem(editCommand); - av.firePropertyChange("alignment", null, av.getAlignment() - .getSequences()); + av.firePropertyChange("alignment", null, + av.getAlignment().getSequences()); } } finally { @@ -344,8 +346,7 @@ public class SeqPanel extends JPanel implements MouseListener, HiddenColumns hidden = av.getAlignment().getHiddenColumns(); - if (av.hasHiddenColumns() - && !hidden.isVisible(seqCanvas.cursorX)) + if (av.hasHiddenColumns() && !hidden.isVisible(seqCanvas.cursorX)) { int original = seqCanvas.cursorX - dx; int maxWidth = av.getAlignment().getWidth(); @@ -389,38 +390,11 @@ public class SeqPanel extends JPanel implements MouseListener, endEditing(); if (av.getWrapAlignment()) { - ap.scrollToWrappedVisible(seqCanvas.cursorX); + av.getRanges().scrollToWrappedVisible(seqCanvas.cursorX); } else { - while (seqCanvas.cursorY < av.getRanges().getStartSeq()) - { - ap.scrollUp(true); - } - while (seqCanvas.cursorY > av.getRanges().getEndSeq()) - { - ap.scrollUp(false); - } - if (!av.getWrapAlignment()) - { - HiddenColumns hidden = av.getAlignment().getHiddenColumns(); - while (seqCanvas.cursorX < hidden.adjustForHiddenColumns(av - .getRanges().getStartRes())) - { - if (!ap.scrollRight(false)) - { - break; - } - } - while (seqCanvas.cursorX > hidden.adjustForHiddenColumns(av - .getRanges().getEndRes())) - { - if (!ap.scrollRight(true)) - { - break; - } - } - } + av.getRanges().scrollToVisible(seqCanvas.cursorX, seqCanvas.cursorY); } setStatusMessage(av.getAlignment().getSequenceAt(seqCanvas.cursorY), seqCanvas.cursorX, seqCanvas.cursorY); @@ -697,17 +671,16 @@ public class SeqPanel extends JPanel implements MouseListener, if (av.isFollowHighlight()) { - /* - * if scrollToPosition requires a scroll adjustment, this flag prevents - * another scroll event being propagated back to the originator - * - * @see AlignmentPanel#adjustmentValueChanged - */ - ap.setDontScrollComplement(true); + // don't allow highlight of protein/cDNA to also scroll a complementary + // panel,as this sets up a feedback loop (scrolling panel 1 causes moused + // over residue to change abruptly, causing highlighted residue in panel 2 + // to change, causing a scroll in panel 1 etc) + ap.setToScrollComplementPanel(false); if (ap.scrollToPosition(results, false)) { seqCanvas.revalidate(); } + ap.setToScrollComplementPanel(true); } setStatusMessage(results); seqCanvas.highlightSearchResults(results); @@ -759,8 +732,9 @@ public class SeqPanel extends JPanel implements MouseListener, /* * set status bar message, returning residue position in sequence */ + boolean isGapped = Comparison.isGap(sequence.getCharAt(column)); final int pos = setStatusMessage(sequence, column, seq); - if (ssm != null && pos > -1) + if (ssm != null && !isGapped) { mouseOverSequence(sequence, column, pos); } @@ -789,10 +763,19 @@ public class SeqPanel extends JPanel implements MouseListener, } } + /* + * add any features at the position to the tooltip; if over a gap, only + * add features that straddle the gap (pos may be the residue before or + * after the gap) + */ if (av.isShowSequenceFeatures()) { List features = ap.getFeatureRenderer() .findFeaturesAtRes(sequence.getDatasetSequence(), pos); + if (isGapped) + { + removeAdjacentFeatures(features, column + 1, sequence); + } seqARep.appendFeatures(tooltipText, pos, features, this.ap.getSeqPanel().seqCanvas.fr.getMinMax()); } @@ -817,6 +800,35 @@ public class SeqPanel extends JPanel implements MouseListener, } + /** + * Removes from the list of features any that start after, or end before, the + * given column position. This allows us to retain only those features + * adjacent to a gapped position that straddle the position. Contact features + * that 'straddle' the position are also removed, since they are not 'at' the + * position. + * + * @param features + * @param column + * alignment column (1..) + * @param sequence + */ + protected void removeAdjacentFeatures(List features, + final int column, SequenceI sequence) + { + // TODO should this be an AlignViewController method (and reused by applet)? + ListIterator it = features.listIterator(); + while (it.hasNext()) + { + SequenceFeature sf = it.next(); + if (sf.isContactFeature() + || sequence.findIndex(sf.getBegin()) > column + || sequence.findIndex(sf.getEnd()) < column) + { + it.remove(); + } + } + } + private Point lastp = null; /* @@ -833,8 +845,9 @@ public class SeqPanel extends JPanel implements MouseListener, Point p = lastp; if (!event.isShiftDown() || p == null) { - p = (tooltipText != null && tooltipText.length() > 6) ? new Point( - event.getX() + wdth, event.getY() - 20) : null; + p = (tooltipText != null && tooltipText.length() > 6) + ? new Point(event.getX() + wdth, event.getY() - 20) + : null; } /* * TODO: try to modify position region is not obcured by tooltip @@ -861,8 +874,10 @@ public class SeqPanel extends JPanel implements MouseListener, /** * Sets the status message in alignment panel, showing the sequence number - * (index) and id, residue and residue position for the given sequence and - * column position. Returns the calculated residue position in the sequence. + * (index) and id, and residue and residue position if not at a gap, for the + * given sequence and column position. Returns the residue position returned + * by Sequence.findPosition. Note this may be for the nearest adjacent residue + * if at a gapped position. * * @param sequence * aligned sequence object @@ -870,7 +885,8 @@ public class SeqPanel extends JPanel implements MouseListener, * alignment column * @param seq * index of sequence in alignment - * @return position of res in sequence + * @return sequence position of residue at column, or adjacent residue if at a + * gap */ int setStatusMessage(SequenceI sequence, final int column, int seq) { @@ -884,36 +900,34 @@ public class SeqPanel extends JPanel implements MouseListener, .append(sequence.getName()); String residue = null; + /* * Try to translate the display character to residue name (null for gap). */ final String displayChar = String.valueOf(sequence.getCharAt(column)); - if (av.getAlignment().isNucleotide()) + boolean isGapped = Comparison.isGap(sequence.getCharAt(column)); + int pos = sequence.findPosition(column); + + if (!isGapped) { - residue = ResidueProperties.nucleotideName.get(displayChar); - if (residue != null) + boolean nucleotide = av.getAlignment().isNucleotide(); + if (nucleotide) { - text.append(" Nucleotide: ").append(residue); + residue = ResidueProperties.nucleotideName.get(displayChar); } - } - else - { - residue = "X".equalsIgnoreCase(displayChar) ? "X" : ("*" - .equals(displayChar) ? "STOP" : ResidueProperties.aa2Triplet - .get(displayChar)); - if (residue != null) + else { - text.append(" Residue: ").append(residue); + residue = "X".equalsIgnoreCase(displayChar) ? "X" + : ("*".equals(displayChar) ? "STOP" + : ResidueProperties.aa2Triplet.get(displayChar)); } - } + text.append(" ").append(nucleotide ? "Nucleotide" : "Residue") + .append(": ").append(residue == null ? displayChar : residue); - int pos = -1; - pos = sequence.findPosition(column); - if (residue != null) - { text.append(" (").append(Integer.toString(pos)).append(")"); } ap.alignFrame.statusBar.setText(text.toString()); + return pos; } @@ -967,8 +981,8 @@ public class SeqPanel extends JPanel implements MouseListener, int oldWidth = av.getCharWidth(); // Which is bigger, left-right or up-down? - if (Math.abs(evt.getY() - lastMousePress.getY()) > Math.abs(evt - .getX() - lastMousePress.getX())) + if (Math.abs(evt.getY() - lastMousePress.getY()) > Math + .abs(evt.getX() - lastMousePress.getX())) { /* * on drag up or down, decrement or increment font size @@ -1128,8 +1142,9 @@ public class SeqPanel extends JPanel implements MouseListener, } if (editCommand == null) { - editCommand = new EditCommand(MessageManager.formatMessage( - "label.edit_params", new String[] { label })); + editCommand = new EditCommand(MessageManager + .formatMessage("label.edit_params", new String[] + { label })); } } @@ -1146,9 +1161,8 @@ public class SeqPanel extends JPanel implements MouseListener, ap.alignFrame.statusBar.setText(message.toString()); // Are we editing within a selection group? - if (groupEditing - || (sg != null && sg.getSequences(av.getHiddenRepSequences()) - .contains(seq))) + if (groupEditing || (sg != null + && sg.getSequences(av.getHiddenRepSequences()).contains(seq))) { fixedColumns = true; @@ -1336,8 +1350,8 @@ public class SeqPanel extends JPanel implements MouseListener, } else { - appendEdit(Action.INSERT_GAP, groupSeqs, startres, startres - - lastres); + appendEdit(Action.INSERT_GAP, groupSeqs, startres, + startres - lastres); } } else @@ -1352,8 +1366,8 @@ public class SeqPanel extends JPanel implements MouseListener, } else { - appendEdit(Action.DELETE_GAP, groupSeqs, startres, lastres - - startres); + appendEdit(Action.DELETE_GAP, groupSeqs, startres, + lastres - startres); } } @@ -1553,9 +1567,20 @@ public class SeqPanel extends JPanel implements MouseListener, av.setSelectionGroup(null); } + int column = findColumn(evt); + boolean isGapped = Comparison.isGap(sequence.getCharAt(column)); + + /* + * find features at the position (if not gapped), or straddling + * the position (if at a gap) + */ List features = seqCanvas.getFeatureRenderer() .findFeaturesAtRes(sequence.getDatasetSequence(), - sequence.findPosition(findColumn(evt))); + sequence.findPosition(column)); + if (isGapped) + { + removeAdjacentFeatures(features, column, sequence); + } if (!features.isEmpty()) { @@ -1563,8 +1588,8 @@ public class SeqPanel extends JPanel implements MouseListener, * highlight the first feature at the position on the alignment */ SearchResultsI highlight = new SearchResults(); - highlight.addResult(sequence, features.get(0).getBegin(), features - .get(0).getEnd()); + highlight.addResult(sequence, features.get(0).getBegin(), + features.get(0).getEnd()); seqCanvas.highlightSearchResults(highlight); /* @@ -1587,23 +1612,23 @@ public class SeqPanel extends JPanel implements MouseListener, { if (e.isShiftDown()) { - ap.scrollRight(true); + av.getRanges().scrollRight(true); } - else + else if (!av.getWrapAlignment()) { - ap.scrollUp(false); + av.getRanges().scrollUp(false); } } else { if (e.isShiftDown()) { - ap.scrollRight(false); + av.getRanges().scrollRight(false); } - else + else if (!av.getWrapAlignment()) { - ap.scrollUp(true); + av.getRanges().scrollUp(true); } } // TODO Update tooltip for new position. @@ -1626,8 +1651,9 @@ public class SeqPanel extends JPanel implements MouseListener, if (av.getWrapAlignment() && seq > av.getAlignment().getHeight()) { - JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager - .getString("label.cannot_edit_annotations_in_wrapped_view"), + JvOptionPane.showInternalMessageDialog(Desktop.desktop, + MessageManager.getString( + "label.cannot_edit_annotations_in_wrapped_view"), MessageManager.getString("label.wrapped_view_no_edit"), JvOptionPane.WARNING_MESSAGE); return; @@ -1779,7 +1805,8 @@ public class SeqPanel extends JPanel implements MouseListener, stretchGroup.cs.alignmentChanged(stretchGroup, av.getHiddenRepSequences()); - ResidueShaderI groupColourScheme = stretchGroup.getGroupColourScheme(); + ResidueShaderI groupColourScheme = stretchGroup + .getGroupColourScheme(); String name = stretchGroup.getName(); if (stretchGroup.cs.conservationApplied()) { @@ -1975,23 +2002,22 @@ public class SeqPanel extends JPanel implements MouseListener, if (mouseDragging && (evt.getY() < 0) && (av.getRanges().getStartSeq() > 0)) { - running = ap.scrollUp(true); + running = av.getRanges().scrollUp(true); } - if (mouseDragging && (evt.getY() >= getHeight()) - && (av.getAlignment().getHeight() > av.getRanges() - .getEndSeq())) + if (mouseDragging && (evt.getY() >= getHeight()) && (av + .getAlignment().getHeight() > av.getRanges().getEndSeq())) { - running = ap.scrollUp(false); + running = av.getRanges().scrollUp(false); } if (mouseDragging && (evt.getX() < 0)) { - running = ap.scrollRight(false); + running = av.getRanges().scrollRight(false); } else if (mouseDragging && (evt.getX() >= getWidth())) { - running = ap.scrollRight(true); + running = av.getRanges().scrollRight(true); } } @@ -2016,8 +2042,10 @@ public class SeqPanel extends JPanel implements MouseListener, // handles selection messages... // TODO: extend config options to allow user to control if selections may be // shared between viewports. - boolean iSentTheSelection = (av == source || (source instanceof AlignViewport && ((AlignmentViewport) source) - .getSequenceSetId().equals(av.getSequenceSetId()))); + boolean iSentTheSelection = (av == source + || (source instanceof AlignViewport + && ((AlignmentViewport) source).getSequenceSetId() + .equals(av.getSequenceSetId()))); if (iSentTheSelection) { @@ -2119,10 +2147,8 @@ public class SeqPanel extends JPanel implements MouseListener, repaint = true; } - if (copycolsel - && av.hasHiddenColumns() - && (av.getAlignment().getHiddenColumns() == null || av - .getAlignment().getHiddenColumns().getHiddenRegions() == null)) + if (copycolsel && av.hasHiddenColumns() + && (av.getAlignment().getHiddenColumns() == null)) { System.err.println("Bad things"); }