From 3a65da0cf59dba22c4e15183db9f336486109538 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 26 Oct 2022 12:37:47 +0100 Subject: [PATCH] JAL-4086 quick and dirty mouseovers on ruler highlighting all positions highlighted on a particular column.. --- src/jalview/gui/ScalePanel.java | 33 +++++--- .../structure/StructureSelectionManager.java | 87 ++++++++++++++++++++ 2 files changed, 109 insertions(+), 11 deletions(-) diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index ca3faf8..4e4a274 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -20,16 +20,6 @@ */ package jalview.gui; -import jalview.datamodel.ColumnSelection; -import jalview.datamodel.HiddenColumns; -import jalview.datamodel.SequenceGroup; -import jalview.renderer.ScaleRenderer; -import jalview.renderer.ScaleRenderer.ScaleMark; -import jalview.util.MessageManager; -import jalview.util.Platform; -import jalview.viewmodel.ViewportListenerI; -import jalview.viewmodel.ViewportRanges; - import java.awt.Color; import java.awt.FontMetrics; import java.awt.Graphics; @@ -50,6 +40,16 @@ import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.ToolTipManager; +import jalview.datamodel.ColumnSelection; +import jalview.datamodel.HiddenColumns; +import jalview.datamodel.SequenceGroup; +import jalview.renderer.ScaleRenderer; +import jalview.renderer.ScaleRenderer.ScaleMark; +import jalview.util.MessageManager; +import jalview.util.Platform; +import jalview.viewmodel.ViewportListenerI; +import jalview.viewmodel.ViewportRanges; + /** * The panel containing the sequence ruler (when not in wrapped mode), and * supports a range of mouse operations to select, hide or reveal columns. @@ -409,6 +409,9 @@ public class ScalePanel extends JPanel reveal = null; if (!av.hasHiddenColumns()) { + int res = (evt.getX() / av.getCharWidth()) + + av.getRanges().getStartRes(); + highlightAllStructPos(res); return; } @@ -419,13 +422,21 @@ public class ScalePanel extends JPanel .getRegionWithEdgeAtRes(res); res = av.getAlignment().getHiddenColumns().visibleToAbsoluteColumn(res); - + highlightAllStructPos(res); ToolTipManager.sharedInstance().registerComponent(this); this.setToolTipText( MessageManager.getString("label.reveal_hidden_columns")); repaint(); } + public void highlightAllStructPos(int col) + { + ap.getStructureSelectionManager().highlightPositionsOnMany( + ap.av.getAlignment().getSequencesArray(), new int[] + { col, col }, ap); + + } + /** * DOCUMENT ME! * diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index ba3ef71..24320b5 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -42,6 +42,7 @@ import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.Annotation; +import jalview.datamodel.ContiguousI; import jalview.datamodel.HiddenColumns; import jalview.datamodel.PDBEntry; import jalview.datamodel.SearchResults; @@ -1129,6 +1130,62 @@ public class StructureSelectionManager sl.highlightAtoms(atoms); } + public void highlightStructureRegionsFor(StructureListener sl, + SequenceI[] seqs, int... columns) + { + List to_highlight = new ArrayList(); + for (SequenceI seq : seqs) + { + if (sl.isListeningFor(seq)) + { + to_highlight.add(seq); + } + } + if (to_highlight.size() == 0) + { + return; + } + List atoms = new ArrayList<>(); + for (SequenceI seq : to_highlight) + { + int atomNo; + for (StructureMapping sm : mappings) + { + if (sm.sequence == seq || sm.sequence == seq.getDatasetSequence() + || (sm.sequence.getDatasetSequence() != null && sm.sequence + .getDatasetSequence() == seq.getDatasetSequence())) + { + + for (int i = 0; i < columns.length; i += 2) + { + ContiguousI positions = seq.findPositions(columns[i] + 1, + columns[i + 1] + 1); + if (positions == null) + { + continue; + } + for (int index = positions.getBegin(); index <= positions + .getEnd(); index++) + { + + atomNo = sm.getAtomNum(index); + + if (atomNo > 0) + { + atoms.add(new AtomSpec(sm.pdbfile, sm.pdbchain, + sm.getPDBResNum(index), atomNo)); + } + } + } + } + } + if (atoms.size() > 0) + { + sl.highlightAtoms(atoms); + } + } + } + /** * true if a mouse over event from an external (ie Vamsas) source is being * handled @@ -1507,4 +1564,34 @@ public class StructureSelectionManager return seqmappings; } + /** + * quick and dirty route to just highlight all structure positions for a range + * of columns + * + * @param sequencesArray + * @param is + * start-end columns on sequencesArray + * @param source + * origin parent AlignmentPanel + */ + public void highlightPositionsOnMany(SequenceI[] sequencesArray, int[] is, + Object source) + { + for (int i = 0; i < listeners.size(); i++) + { + Object listener = listeners.elementAt(i); + if (listener == source) + { + // TODO listener (e.g. SeqPanel) is never == source (AlignViewport) + // Temporary fudge with SequenceListener.getVamsasSource() + continue; + } + if (listener instanceof StructureListener) + { + highlightStructureRegionsFor((StructureListener) listener, + sequencesArray, is); + } + } + } + } -- 1.7.10.2