From 8a3c31b03ed98321d1d450b658d26d50a7aa0ae6 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Mon, 7 Oct 2013 17:39:06 +0100 Subject: [PATCH] JAL-1385 refactor logic to AlignmentViewController --- src/jalview/appletgui/AlignFrame.java | 36 ++++++--------------------- src/jalview/gui/AlignFrame.java | 44 +++++++++++---------------------- 2 files changed, 22 insertions(+), 58 deletions(-) diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 0f0ba4e..2cf7602 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -19,6 +19,7 @@ package jalview.appletgui; import jalview.analysis.AlignmentSorter; import jalview.analysis.Conservation; +import jalview.api.AlignViewControllerI; import jalview.api.SequenceStructureBinding; import jalview.bin.JalviewLite; import jalview.commands.CommandI; @@ -92,6 +93,7 @@ import java.util.Vector; public class AlignFrame extends EmbmenuFrame implements ActionListener, ItemListener, KeyListener { + public AlignViewControllerI avc; public AlignmentPanel alignPanel; public AlignViewport viewport; @@ -120,7 +122,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, viewport = new AlignViewport(al, applet); alignPanel = new AlignmentPanel(this, viewport); - + avc = new jalview.controller.AlignViewController(viewport, alignPanel); viewport.updateConservation(alignPanel); viewport.updateConsensus(alignPanel); @@ -1887,28 +1889,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, protected void makeGrpsFromSelection_actionPerformed() { - if (viewport.getSelectionGroup() != null) - { - SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom( - viewport.getSequenceSelection(), - viewport.getAlignmentView(true).getSequenceStrings( - viewport.getGapCharacter()), viewport.getAlignment() - .getGroups()); - viewport.getAlignment().deleteAllGroups(); - viewport.sequenceColours = null; - viewport.setSelectionGroup(null); - // set view properties for each group - for (int g = 0; g < gps.length; g++) - { - // gps[g].setShowunconserved(viewport.getShowUnconserved()); - gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo()); - viewport.getAlignment().addGroup(gps[g]); - Color col = new Color((int) (Math.random() * 255), - (int) (Math.random() * 255), (int) (Math.random() * 255)); - col = col.brighter(); - for (SequenceI sq : gps[g].getSequences(null)) - viewport.setSequenceColour(sq, col); - } + if (avc.makeGroupsFromSelection()) { PaintRefresher.Refresh(this, viewport.getSequenceSetId()); alignPanel.updateAnnotation(); alignPanel.paintAlignment(true); @@ -1917,11 +1898,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, protected void deleteGroups_actionPerformed() { - viewport.getAlignment().deleteAllGroups(); - viewport.sequenceColours = null; - viewport.setSelectionGroup(null); - - alignPanel.paintAlignment(true); + if (avc.deleteGroups()) + { + alignPanel.alignmentChanged(); + } } public void selectAllSequenceMenuItem_actionPerformed() diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 829b9ab..382ccda 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -24,6 +24,7 @@ import jalview.analysis.CrossRef; import jalview.analysis.NJTree; import jalview.analysis.ParseProperties; import jalview.analysis.SequenceIdMatcher; +import jalview.api.AlignViewControllerI; import jalview.bin.Cache; import jalview.commands.CommandI; import jalview.commands.EditCommand; @@ -145,6 +146,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public AlignmentPanel alignPanel; AlignViewport viewport; + + public AlignViewControllerI avc; + Vector alignPanels = new Vector(); @@ -288,6 +292,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, */ void init() { + avc = new jalview.controller.AlignViewController(viewport, alignPanel); if (viewport.getAlignmentConservationAnnotation() == null) { BLOSUM62Colour.setEnabled(false); @@ -330,7 +335,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } addKeyListener(); - + } /** @@ -558,6 +563,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void addAlignmentPanel(final AlignmentPanel ap, boolean newPanel) { ap.alignFrame = this; + avc = new jalview.controller.AlignViewController(viewport, alignPanel); alignPanels.addElement(ap); @@ -735,7 +741,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, rnahelicesColour .setSelected(av.getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour); setShowProductsEnabled(); - updateEditMenuBar(); } @@ -2136,12 +2141,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override protected void deleteGroups_actionPerformed(ActionEvent e) { - viewport.getAlignment().deleteAllGroups(); - viewport.sequenceColours = null; - viewport.setSelectionGroup(null); - PaintRefresher.Refresh(this, viewport.getSequenceSetId()); - alignPanel.updateAnnotation(); - alignPanel.paintAlignment(true); + if (avc.deleteGroups()) { + PaintRefresher.Refresh(this, viewport.getSequenceSetId()); + alignPanel.updateAnnotation(); + alignPanel.paintAlignment(true); + } } /** @@ -5015,6 +5019,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { alignPanel = (AlignmentPanel) alignPanels.elementAt(index); viewport = alignPanel.av; + avc.setViewportAndAlignmentPanel(viewport, alignPanel); setMenusFromViewport(viewport); } } @@ -5455,28 +5460,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override protected void makeGrpsFromSelection_actionPerformed(ActionEvent e) { - if (viewport.getSelectionGroup() != null) - { - SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom( - viewport.getSequenceSelection(), - viewport.getAlignmentView(true).getSequenceStrings( - viewport.getGapCharacter()), viewport.getAlignment() - .getGroups()); - viewport.getAlignment().deleteAllGroups(); - viewport.sequenceColours = null; - viewport.setSelectionGroup(null); - // set view properties for each group - for (int g = 0; g < gps.length; g++) - { - gps[g].setShowNonconserved(viewport.getShowUnconserved()); - gps[g].setshowSequenceLogo(viewport.isShowSequenceLogo()); - viewport.getAlignment().addGroup(gps[g]); - Color col = new Color((int) (Math.random() * 255), - (int) (Math.random() * 255), (int) (Math.random() * 255)); - col = col.brighter(); - for (SequenceI s : gps[g].getSequences()) - viewport.setSequenceColour(s, col); - } + if (avc.makeGroupsFromSelection()) { PaintRefresher.Refresh(this, viewport.getSequenceSetId()); alignPanel.updateAnnotation(); alignPanel.paintAlignment(true); -- 1.7.10.2