From 9811278f9e18ee6cb88470dbae98da046734a0af Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 5 Aug 2019 10:34:22 +0100 Subject: [PATCH] JAL-3390 pull-up refactoring towards functional changes... --- src/jalview/api/AlignmentViewPanel.java | 14 ++++++++ .../api/structures/JalviewStructureDisplayI.java | 2 ++ src/jalview/appletgui/AlignmentPanel.java | 12 +++++++ src/jalview/gui/AlignFrame.java | 16 ++++----- src/jalview/gui/AlignmentPanel.java | 6 ++++ src/jalview/gui/AppJmol.java | 5 +-- src/jalview/gui/AppJmolBinding.java | 15 --------- src/jalview/gui/ChimeraViewFrame.java | 5 +-- src/jalview/gui/JalviewChimeraBindingModel.java | 15 --------- src/jalview/gui/StructureViewerBase.java | 26 +++++++++------ src/jalview/gui/ViewSelectionMenu.java | 13 ++++---- .../structures/models/AAStructureBindingModel.java | 35 +++++++++++++++++--- 12 files changed, 100 insertions(+), 64 deletions(-) diff --git a/src/jalview/api/AlignmentViewPanel.java b/src/jalview/api/AlignmentViewPanel.java index 0b1ca21..ad3fbed 100644 --- a/src/jalview/api/AlignmentViewPanel.java +++ b/src/jalview/api/AlignmentViewPanel.java @@ -63,4 +63,18 @@ public interface AlignmentViewPanel extends OOMHandlerI * @return displayed name for the view */ String getViewName(); + + /** + * Answers the title of the panel + * + * @return + */ + String getTitle(); + + /** + * Make/Unmake this alignment panel the current input focus + * + * @param b + */ + void setSelected(boolean b); } diff --git a/src/jalview/api/structures/JalviewStructureDisplayI.java b/src/jalview/api/structures/JalviewStructureDisplayI.java index 8f778f7..0ca9061 100644 --- a/src/jalview/api/structures/JalviewStructureDisplayI.java +++ b/src/jalview/api/structures/JalviewStructureDisplayI.java @@ -125,4 +125,6 @@ public interface JalviewStructureDisplayI */ void raiseViewer(); + boolean isUsedforcolourby(AlignmentViewPanel ap); + } diff --git a/src/jalview/appletgui/AlignmentPanel.java b/src/jalview/appletgui/AlignmentPanel.java index e9081b0..b848297 100644 --- a/src/jalview/appletgui/AlignmentPanel.java +++ b/src/jalview/appletgui/AlignmentPanel.java @@ -1157,4 +1157,16 @@ public class AlignmentPanel extends Panel } + @Override + public String getTitle() + { + return alignFrame.getTitle(); + } + + @Override + public void setSelected(boolean b) + { + // noop + } + } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index fcb6572..c847260 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -398,8 +398,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, addKeyListener(); - final List selviews = new ArrayList<>(); - final List origview = new ArrayList<>(); + final List selviews = new ArrayList<>(); + final List origview = new ArrayList<>(); final String menuLabel = MessageManager .getString("label.copy_format_from"); ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel, @@ -407,7 +407,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { @Override - public AlignmentPanel[] getAllAlignmentPanels() + public AlignmentViewPanel[] getAllAlignmentPanels() { origview.clear(); origview.add(alignPanel); @@ -425,7 +425,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { if (origview.size() > 0) { - final AlignmentPanel ap = origview.get(0); + final AlignmentViewPanel avp = origview.get(0); /* * Copy the ViewStyle of the selected panel to 'this one'. @@ -438,10 +438,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, .getAlignViewport().getCodingComplement() != null; if (!fromSplitFrame) { - vs.setScaleProteinAsCdna(ap.getAlignViewport() + vs.setScaleProteinAsCdna(avp.getAlignViewport() .getViewStyle().isScaleProteinAsCdna()); } - ap.getAlignViewport().setViewStyle(vs); + avp.getAlignViewport().setViewStyle(vs); /* * Also rescale ViewStyle of SplitFrame complement if there is @@ -449,7 +449,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * the whole ViewStyle (allow cDNA protein to have different * fonts) */ - AlignViewportI complement = ap.getAlignViewport() + AlignViewportI complement = avp.getAlignViewport() .getCodingComplement(); if (complement != null && vs.isScaleProteinAsCdna()) { @@ -459,10 +459,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, af.setMenusForViewport(); } + AlignmentPanel ap = (AlignmentPanel) avp; ap.updateLayout(); ap.setSelected(true); ap.alignFrame.setMenusForViewport(); - } } }); diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index ea8fcdc..3948f6d 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -1774,4 +1774,10 @@ public class AlignmentPanel extends GAlignmentPanel implements { return calculationDialog; } + + @Override + public String getTitle() + { + return alignFrame == null ? null : alignFrame.getTitle(); + } } diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index ea7fb6b..b28b81c 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -20,6 +20,7 @@ */ package jalview.gui; +import jalview.api.AlignmentViewPanel; import jalview.bin.Cache; import jalview.datamodel.AlignmentI; import jalview.datamodel.PDBEntry; @@ -396,9 +397,9 @@ public class AppJmol extends StructureViewerBase } // refresh the sequence colours for the new structure(s) - for (AlignmentPanel ap : _colourwith) + for (AlignmentViewPanel avp : _colourwith) { - jmb.updateColours(ap); + jmb.updateColours(avp); } // do superposition if asked to if (alignAddedStructures) diff --git a/src/jalview/gui/AppJmolBinding.java b/src/jalview/gui/AppJmolBinding.java index 724cec1..69f4c6b 100644 --- a/src/jalview/gui/AppJmolBinding.java +++ b/src/jalview/gui/AppJmolBinding.java @@ -109,21 +109,6 @@ public class AppJmolBinding extends JalviewJmolBinding } @Override - public void updateColours(Object source) - { - AlignmentPanel ap = (AlignmentPanel) source; - // ignore events from panels not used to colour this view - if (!appJmolWindow.isUsedforcolourby(ap)) - { - return; - } - if (!isLoadingFromArchive()) - { - colourBySequence(ap); - } - } - - @Override public void notifyScriptTermination(String strStatus, int msWalltime) { // todo - script termination doesn't happen ? diff --git a/src/jalview/gui/ChimeraViewFrame.java b/src/jalview/gui/ChimeraViewFrame.java index 6c35a9c..fd84b37 100644 --- a/src/jalview/gui/ChimeraViewFrame.java +++ b/src/jalview/gui/ChimeraViewFrame.java @@ -20,6 +20,7 @@ */ package jalview.gui; +import jalview.api.AlignmentViewPanel; import jalview.api.FeatureRenderer; import jalview.bin.Cache; import jalview.datamodel.AlignmentI; @@ -584,9 +585,9 @@ public class ChimeraViewFrame extends StructureViewerBase } // refresh the sequence colours for the new structure(s) - for (AlignmentPanel ap : _colourwith) + for (AlignmentViewPanel avp : _colourwith) { - jmb.updateColours(ap); + jmb.updateColours(avp); } // do superposition if asked to if (alignAddedStructures) diff --git a/src/jalview/gui/JalviewChimeraBindingModel.java b/src/jalview/gui/JalviewChimeraBindingModel.java index 2f11c30..2da93ce 100644 --- a/src/jalview/gui/JalviewChimeraBindingModel.java +++ b/src/jalview/gui/JalviewChimeraBindingModel.java @@ -77,21 +77,6 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding } @Override - public void updateColours(Object source) - { - AlignmentPanel ap = (AlignmentPanel) source; - // ignore events from panels not used to colour this view - if (!cvf.isUsedforcolourby(ap)) - { - return; - } - if (!isLoadingFromArchive()) - { - colourBySequence(ap); - } - } - - @Override public void releaseReferences(Object svl) { } diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index 5c50044..47bc823 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -20,6 +20,7 @@ */ package jalview.gui; +import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.bin.Cache; import jalview.datamodel.Alignment; @@ -90,13 +91,13 @@ public abstract class StructureViewerBase extends GStructureViewer /** * list of alignment panels to use for superposition */ - protected Vector _alignwith = new Vector<>(); + protected Vector _alignwith = new Vector<>(); /** * list of alignment panels that are used for colouring structures by aligned * sequences */ - protected Vector _colourwith = new Vector<>(); + protected Vector _colourwith = new Vector<>(); private String viewId = null; @@ -165,9 +166,10 @@ public abstract class StructureViewerBase extends GStructureViewer return (_alignwith != null) && _alignwith.contains(ap2); } - public boolean isUsedforcolourby(AlignmentPanel ap2) + @Override + public boolean isUsedforcolourby(AlignmentViewPanel avp) { - return (_colourwith != null) && _colourwith.contains(ap2); + return (_colourwith != null) && _colourwith.contains(avp); } /** @@ -796,11 +798,12 @@ public abstract class StructureViewerBase extends GStructureViewer int[] alm = new int[_alignwith.size()]; int a = 0; - for (AlignmentPanel alignPanel : _alignwith) + for (AlignmentViewPanel alignPanel : _alignwith) { - als[a] = alignPanel.av.getAlignment(); + AlignViewportI av = alignPanel.getAlignViewport(); + als[a] = av.getAlignment(); alm[a] = -1; - alc[a++] = alignPanel.av.getAlignment().getHiddenColumns(); + alc[a++] = av.getAlignment().getHiddenColumns(); } reply = getBinding().superposeStructures(als, alm, alc); if (reply != null) @@ -812,9 +815,10 @@ public abstract class StructureViewerBase extends GStructureViewer } catch (Exception e) { StringBuffer sp = new StringBuffer(); - for (AlignmentPanel alignPanel : _alignwith) + for (AlignmentViewPanel avp : _alignwith) { - sp.append("'" + alignPanel.alignFrame.getTitle() + "' "); + sp.append( + "'" + ((AlignmentPanel) avp).alignFrame.getTitle() + "' "); } Cache.log.info("Couldn't align structures with the " + sp.toString() + "associated alignment panels.", e); @@ -878,9 +882,9 @@ public abstract class StructureViewerBase extends GStructureViewer } } // Set the colour using the current view for the associated alignframe - for (AlignmentPanel alignPanel : _colourwith) + for (AlignmentViewPanel avp : _colourwith) { - binding.colourBySequence(alignPanel); + binding.colourBySequence(avp); } seqColoursApplied = true; } diff --git a/src/jalview/gui/ViewSelectionMenu.java b/src/jalview/gui/ViewSelectionMenu.java index 2a7743a..ed9f013 100644 --- a/src/jalview/gui/ViewSelectionMenu.java +++ b/src/jalview/gui/ViewSelectionMenu.java @@ -20,6 +20,7 @@ */ package jalview.gui; +import jalview.api.AlignmentViewPanel; import jalview.util.MessageManager; import java.awt.Component; @@ -51,12 +52,12 @@ public class ViewSelectionMenu extends JMenu { public interface ViewSetProvider { - public AlignmentPanel[] getAllAlignmentPanels(); + public AlignmentViewPanel[] getAllAlignmentPanels(); } private ViewSetProvider _allviews; - private List _selectedviews; + private List _selectedviews; private ItemListener _handler; @@ -79,7 +80,7 @@ public class ViewSelectionMenu extends JMenu * selection/deselection state */ public ViewSelectionMenu(String title, final ViewSetProvider allviews, - final List selectedviews, + final List selectedviews, final ItemListener handler) { super(title); @@ -131,7 +132,7 @@ public class ViewSelectionMenu extends JMenu private void rebuild() { removeAll(); - AlignmentPanel[] allviews = _allviews.getAllAlignmentPanels(); + AlignmentViewPanel[] allviews = _allviews.getAllAlignmentPanels(); if (allviews == null) { setVisible(false); @@ -208,12 +209,12 @@ public class ViewSelectionMenu extends JMenu invertSel.setEnabled(append); selectAll.setEnabled(append); } - for (final AlignmentPanel ap : allviews) + for (final AlignmentViewPanel ap : allviews) { String nm = ((ap.getViewName() == null || ap.getViewName().length() == 0) ? "" : ap.getViewName() + " for ") - + ap.alignFrame.getTitle(); + + ap.getTitle(); final JCheckBoxMenuItem checkBox = new JCheckBoxMenuItem(nm, _selectedviews.contains(ap)); checkBox.addItemListener(new ItemListener() diff --git a/src/jalview/structures/models/AAStructureBindingModel.java b/src/jalview/structures/models/AAStructureBindingModel.java index 21b0e3d..6159757 100644 --- a/src/jalview/structures/models/AAStructureBindingModel.java +++ b/src/jalview/structures/models/AAStructureBindingModel.java @@ -796,13 +796,20 @@ public abstract class AAStructureBindingModel public abstract void colourByCharge(); /** - * colour any structures associated with sequences in the given alignment - * using the getFeatureRenderer() and getSequenceRenderer() renderers but only - * if colourBySequence is enabled. + * Recolours the displayed structures, if they are coloured by sequence, or + * 'show only visible alignment' is selected. This supports updating structure + * colours on either change of alignment colours, or change to the visible + * region of the alignment. */ public void colourBySequence(AlignmentViewPanel alignmentv) { - if (!colourBySequence || !isLoadingFinished()) + if (!isLoadingFinished()) + { + return; + } + // todo: property change event for visibleAlignment + // to avoid unnecessary redraws here + if (!colourBySequence && !isShowAlignmentOnly()) { return; } @@ -856,5 +863,23 @@ public abstract class AAStructureBindingModel * * @param alignViewportI */ - public abstract void showStructures(AlignViewportI alignViewportI); + public void showStructures(AlignViewportI alignViewportI) + { + // override with implementation + } + + @Override + public void updateColours(Object source) + { + AlignmentViewPanel ap = (AlignmentViewPanel) source; + // ignore events from panels not used to colour this view + if (!getViewer().isUsedforcolourby(ap)) + { + return; + } + if (!isLoadingFromArchive()) + { + colourBySequence(ap); + } + } } -- 1.7.10.2