X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FSeqPanel.java;h=41529cd8d91e075eadd2971defd2791afe7f3ee7;hb=424f6f03e8fb5e40cceca09fc8ffd72b41e3a9e4;hp=86dedfc189b079b020877873ce64d63f4d1c4ad4;hpb=ed2283c5f54da377a2a2fdbdb7aec75ed7041714;p=jalview.git diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 86dedfc..41529cd 100644 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -20,24 +20,14 @@ */ package jalview.appletgui; -import java.awt.BorderLayout; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Panel; -import java.awt.Point; -import java.awt.event.InputEvent; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import java.util.List; -import java.util.Vector; - import jalview.api.AlignViewportI; import jalview.commands.EditCommand; import jalview.commands.EditCommand.Action; +import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.SearchResultMatchI; import jalview.datamodel.SearchResults; -import jalview.datamodel.SearchResults.Match; +import jalview.datamodel.SearchResultsI; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; @@ -52,6 +42,17 @@ import jalview.util.MappingUtils; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; +import java.awt.BorderLayout; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Panel; +import java.awt.Point; +import java.awt.event.InputEvent; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.util.Vector; + public class SeqPanel extends Panel implements MouseMotionListener, MouseListener, SequenceListener, SelectionListener { @@ -432,8 +433,9 @@ public class SeqPanel extends Panel implements MouseMotionListener, } else { - residue = "X".equalsIgnoreCase(displayChar) ? "X" - : ResidueProperties.aa2Triplet.get(displayChar); + residue = "X".equalsIgnoreCase(displayChar) ? "X" : ("*" + .equals(displayChar) ? "STOP" : ResidueProperties.aa2Triplet + .get(displayChar)); if (residue != null) { text.append(" Residue: ").append(residue); @@ -446,36 +448,8 @@ public class SeqPanel extends Panel implements MouseMotionListener, pos = sequence.findPosition(res); text.append(" (").append(Integer.toString(pos)).append(")"); } - // Object obj = null; - // if (av.getAlignment().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()); - } /** @@ -483,25 +457,40 @@ public class SeqPanel extends Panel implements MouseMotionListener, * search results. * * @param results + * @return true if results were matched, false if not */ - private void setStatusMessage(SearchResults results) + private boolean setStatusMessage(SearchResultsI results) { - List matches = results.getResults(); - if (!matches.isEmpty()) + AlignmentI al = this.av.getAlignment(); + int sequenceIndex = al.findIndex(results); + if (sequenceIndex == -1) + { + return false; + } + SequenceI ds = al.getSequenceAt(sequenceIndex).getDatasetSequence(); + for (SearchResultMatchI m : results.getResults()) { - Match m = matches.get(0); SequenceI seq = m.getSequence(); - int sequenceIndex = this.av.getAlignment().findIndex(seq); + if (seq.getDatasetSequence() != null) + { + seq = seq.getDatasetSequence(); + } - /* - * Convert position in sequence (base 1) to sequence character array index - * (base 0) - */ - int start = m.getStart() - 1; - setStatusMessage(seq, start, sequenceIndex); + if (seq == ds) + { + /* + * Convert position in sequence (base 1) to sequence character array + * index (base 0) + */ + int start = m.getStart() - m.getSequence().getStart(); + setStatusMessage(seq, start, sequenceIndex); + return true; + } } + return false; } + @Override public void mousePressed(MouseEvent evt) { lastMousePress = evt.getPoint(); @@ -552,6 +541,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, return; } + @Override public void mouseClicked(MouseEvent evt) { SequenceI sequence = av.getAlignment().getSequenceAt(findSeq(evt)); @@ -570,21 +560,22 @@ public class SeqPanel extends Panel implements MouseMotionListener, if (features != null && features.length > 0) { - SearchResults highlight = new SearchResults(); + SearchResultsI highlight = new SearchResults(); highlight.addResult(sequence, features[0].getBegin(), features[0].getEnd()); seqCanvas.highlightSearchResults(highlight); } if (features != null && features.length > 0) { - seqCanvas.getFeatureRenderer().amendFeatures(new SequenceI[] - { sequence }, features, false, ap); + seqCanvas.getFeatureRenderer().amendFeatures( + new SequenceI[] { sequence }, features, false, ap); seqCanvas.highlightSearchResults(null); } } } + @Override public void mouseReleased(MouseEvent evt) { mouseDragging = false; @@ -620,8 +611,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, } int cHeight = av.getAlignment().getHeight() * av.getCharHeight() - + hgap - + seqCanvas.getAnnotationHeight(); + + hgap + seqCanvas.getAnnotationHeight(); int y = evt.getY(); y -= hgap; @@ -678,8 +668,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, } int cHeight = av.getAlignment().getHeight() * av.getCharHeight() - + hgap - + seqCanvas.getAnnotationHeight(); + + hgap + seqCanvas.getAnnotationHeight(); y -= hgap; @@ -730,6 +719,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, String lastMessage; + @Override public void mouseOverSequence(SequenceI sequence, int index, int pos) { String tmp = sequence.hashCode() + index + ""; @@ -741,7 +731,8 @@ public class SeqPanel extends Panel implements MouseMotionListener, lastMessage = tmp; } - public void highlightSequence(SearchResults results) + @Override + public void highlightSequence(SearchResultsI results) { if (av.isFollowHighlight()) { @@ -761,12 +752,14 @@ public class SeqPanel extends Panel implements MouseMotionListener, return this.ap == null ? null : this.ap.av; } + @Override public void updateColours(SequenceI seq, int index) { System.out.println("update the seqPanel colours"); // repaint(); } + @Override public void mouseMoved(MouseEvent evt) { int res = findRes(evt); @@ -813,8 +806,8 @@ public class SeqPanel extends Panel implements MouseMotionListener, } else { - obj = "X".equalsIgnoreCase(ch) ? "X" - : ResidueProperties.aa2Triplet.get(ch); + obj = "X".equalsIgnoreCase(ch) ? "X" : ResidueProperties.aa2Triplet + .get(ch); if (obj != null) { text.append(" Residue: ").append(obj); @@ -898,13 +891,15 @@ public class SeqPanel extends Panel implements MouseMotionListener, for (int i = 0; i < features.length; i++) { if (av.getFeaturesDisplayed() == null - || !av.getFeaturesDisplayed().isVisible(features[i].getType())) + || !av.getFeaturesDisplayed().isVisible( + features[i].getType())) { continue; } if (features[i].featureGroup != null - && !seqCanvas.fr.checkGroupVisibility(features[i].featureGroup,false)) + && !seqCanvas.fr.checkGroupVisibility( + features[i].featureGroup, false)) { continue; } @@ -925,6 +920,15 @@ public class SeqPanel extends Panel implements MouseMotionListener, Tooltip tooltip; + /** + * set when the current UI interaction has resulted in a change that requires + * overview shading to be recalculated. this could be changed to something + * more expressive that indicates what actually has changed, so selective + * redraws can be applied + */ + private boolean needOverviewUpdate; // TODO: refactor to avcontroller + + @Override public void mouseDragged(MouseEvent evt) { if (mouseWheelPressed) @@ -1060,8 +1064,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, if (editCommand == null) { editCommand = new EditCommand(MessageManager.formatMessage( - "label.edit_params", new String[] - { label })); + "label.edit_params", new String[] { label })); } } @@ -1295,14 +1298,14 @@ public class SeqPanel extends Panel implements MouseMotionListener, { for (int j = lastres; j < startres; j++) { - insertChar(j, new SequenceI[] - { seq }, fixedRight); + insertChar(j, new SequenceI[] { seq }, fixedRight); } } else { - editCommand.appendEdit(Action.INSERT_GAP, new SequenceI[] - { seq }, lastres, startres - lastres, av.getAlignment(), true); + editCommand.appendEdit(Action.INSERT_GAP, + new SequenceI[] { seq }, lastres, startres - lastres, + av.getAlignment(), true); } } else @@ -1317,8 +1320,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, endEditing(); break; } - deleteChar(startres, new SequenceI[] - { seq }, fixedRight); + deleteChar(startres, new SequenceI[] { seq }, fixedRight); } } else @@ -1336,8 +1338,9 @@ public class SeqPanel extends Panel implements MouseMotionListener, if (max > 0) { - editCommand.appendEdit(Action.DELETE_GAP, new SequenceI[] - { seq }, startres, max, av.getAlignment(), true); + editCommand.appendEdit(Action.DELETE_GAP, + new SequenceI[] { seq }, startres, max, + av.getAlignment(), true); } } } @@ -1422,19 +1425,12 @@ public class SeqPanel extends Panel implements MouseMotionListener, if (stretchGroup == null) { - stretchGroup = av.getAlignment().findGroup(sequence); - if (stretchGroup != null && res > stretchGroup.getStartRes() - && res < stretchGroup.getEndRes()) - { - av.setSelectionGroup(stretchGroup); - } - else - { - stretchGroup = null; - } + stretchGroup = av.getAlignment().findGroup(sequence, res); + av.setSelectionGroup(stretchGroup); } - else if (!stretchGroup.getSequences(null).contains(sequence) + if (stretchGroup == null + || !stretchGroup.getSequences(null).contains(sequence) || stretchGroup.getStartRes() > res || stretchGroup.getEndRes() < res) { @@ -1509,13 +1505,13 @@ public class SeqPanel extends Panel implements MouseMotionListener, if (av.getConservationSelected()) { - SliderPanel.setConservationSlider(ap, av.getGlobalColourScheme(), - "Background"); + SliderPanel.setConservationSlider(ap, av.getViewportColourScheme(), + ap.getViewName()); } if (av.getAbovePIDThreshold()) { - SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(), - "Background"); + SliderPanel.setPIDSliderSource(ap, av.getViewportColourScheme(), + ap.getViewName()); } } @@ -1527,9 +1523,11 @@ public class SeqPanel extends Panel implements MouseMotionListener, { return; } - - stretchGroup.recalcConservation(); // always do this - annotation has own - // state + // always do this - annotation has own state + // but defer colourscheme update until hidden sequences are passed in + boolean vischange = stretchGroup.recalcConservation(true); + // here we rely on stretchGroup == av.getSelection() + needOverviewUpdate |= vischange && av.isSelectionDefinedGroup(); if (stretchGroup.cs != null) { stretchGroup.cs.alignmentChanged(stretchGroup, @@ -1540,17 +1538,18 @@ public class SeqPanel extends Panel implements MouseMotionListener, SliderPanel.setConservationSlider(ap, stretchGroup.cs, stretchGroup.getName()); } - else + if (stretchGroup.cs.getThreshold() > 0) { SliderPanel.setPIDSliderSource(ap, stretchGroup.cs, stretchGroup.getName()); } } + PaintRefresher.Refresh(ap, av.getSequenceSetId()); + ap.paintAlignment(needOverviewUpdate); + needOverviewUpdate = false; changeEndRes = false; changeStartRes = false; stretchGroup = null; - PaintRefresher.Refresh(ap, av.getSequenceSetId()); - ap.paintAlignment(true); av.sendSelection(); } @@ -1602,6 +1601,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, if (res > (stretchGroup.getStartRes() - 1)) { stretchGroup.setEndRes(res); + needOverviewUpdate |= av.isSelectionDefinedGroup(); } } else if (changeStartRes) @@ -1609,6 +1609,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, if (res < (stretchGroup.getEndRes() + 1)) { stretchGroup.setStartRes(res); + needOverviewUpdate |= av.isSelectionDefinedGroup(); } } @@ -1642,6 +1643,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, if (stretchGroup.getSequences(null).contains(nextSeq)) { stretchGroup.deleteSequence(seq, false); + needOverviewUpdate |= av.isSelectionDefinedGroup(); } else { @@ -1651,6 +1653,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, } stretchGroup.addSequence(nextSeq, false); + needOverviewUpdate |= av.isSelectionDefinedGroup(); } } @@ -1673,6 +1676,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, seqCanvas.repaint(); } + @Override public void mouseEntered(MouseEvent e) { if (oldSeq < 0) @@ -1687,6 +1691,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, } } + @Override public void mouseExited(MouseEvent e) { if (av.getWrapAlignment()) @@ -1746,6 +1751,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, running = false; } + @Override public void run() { running = true; @@ -1790,6 +1796,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, /** * modify current selection according to a received message. */ + @Override public void selection(SequenceGroup seqsel, ColumnSelection colsel, SelectionSource source) { @@ -1815,9 +1822,12 @@ public class SeqPanel extends Panel implements MouseMotionListener, // do we want to thread this ? (contention with seqsel and colsel locks, I // suspect) - // rules are: colsel is copied if there is a real intersection between - // sequence selection - boolean repaint = false, copycolsel = true; + /* + * only copy colsel if there is a real intersection between + * sequence selection and this panel's alignment + */ + boolean repaint = false; + boolean copycolsel = false; if (av.getSelectionGroup() == null || !av.isSelectionGroupChanged(true)) { SequenceGroup sgroup = null; @@ -1834,11 +1844,9 @@ public class SeqPanel extends Panel implements MouseMotionListener, } sgroup = seqsel.intersect(av.getAlignment(), (av.hasHiddenRows()) ? av.getHiddenRepSequences() : null); - if ((sgroup == null || sgroup.getSize() == 0) - && (colsel == null || colsel.size() == 0)) + if ((sgroup != null && sgroup.getSize() > 0)) { - // don't copy columns if the region didn't intersect. - copycolsel = false; + copycolsel = true; } } if (sgroup != null && sgroup.getSize() > 0) @@ -1857,7 +1865,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, { // the current selection is unset or from a previous message // so import the new colsel. - if (colsel == null || colsel.size() == 0) + if (colsel == null || colsel.isEmpty()) { if (av.getColumnSelection() != null) { @@ -1942,33 +1950,34 @@ public class SeqPanel extends Panel implements MouseMotionListener, protected boolean selectionFromTranslation(SequenceGroup seqsel, ColumnSelection colsel, SelectionSource source) { - if (!(source instanceof AlignViewportI)) { + if (!(source instanceof AlignViewportI)) + { return false; } final AlignViewportI sourceAv = (AlignViewportI) source; - if (sourceAv.getCodingComplement() != av && av.getCodingComplement() != sourceAv) + if (sourceAv.getCodingComplement() != av + && av.getCodingComplement() != sourceAv) { return false; } - + /* * Map sequence selection */ SequenceGroup sg = MappingUtils.mapSequenceGroup(seqsel, sourceAv, av); av.setSelectionGroup(sg); av.isSelectionGroupChanged(true); - + /* * Map column selection */ ColumnSelection cs = MappingUtils.mapColumnSelection(colsel, sourceAv, av); av.setColumnSelection(cs); - av.isColSelChanged(true); - + ap.scalePanelHolder.repaint(); ap.repaint(); - + return true; }