From: Ben Soares Date: Thu, 19 Oct 2023 17:33:56 +0000 (+0100) Subject: JAL-4305 Isolate and unify the Jalview object from all the gubbins in jalview.bin... X-Git-Tag: Release_2_11_4_0~131^2~3 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=25e2a6f59681e1e7d9602a451fbcf3a2b414a49a;p=jalview.git JAL-4305 Isolate and unify the Jalview object from all the gubbins in jalview.bin.Jalview or jalview.gui.Desktop with a JalviewObject interface. Adjust/fix some example groovy scripts. --- diff --git a/examples/groovy/ComputePeptideVariants.groovy b/examples/groovy/ComputePeptideVariants.groovy index 6caa69c..e5ece51 100644 --- a/examples/groovy/ComputePeptideVariants.groovy +++ b/examples/groovy/ComputePeptideVariants.groovy @@ -1,6 +1,6 @@ import jalview.datamodel.SequenceFeature import jalview.gui.Desktop -def af = jalview.bin.Jalview.currentAlignFrame +def af = Jalview.getCurrentAlignFrame() def av = af.viewport def fr = Desktop.getAlignFrameFor(av.codingComplement).getFeatureRenderer() def counts = 0 @@ -29,4 +29,4 @@ for (seq in av.alignment.sequences) } af.getFeatureRenderer().featuresAdded() af.alignPanel.paintAlignment(true, true) -println "Added " + countm + " missense and " + counts + " synonymous variants" \ No newline at end of file +println "Added " + countm + " missense and " + counts + " synonymous variants" diff --git a/examples/groovy/JvLoadTester.groovy b/examples/groovy/JvLoadTester.groovy index d844d62..cc92e40 100644 --- a/examples/groovy/JvLoadTester.groovy +++ b/examples/groovy/JvLoadTester.groovy @@ -21,7 +21,7 @@ import jalview.gui.*; import jalview.io.*; -def class JvLoadTest { +class JvLoadTest { FileLoader fl = null; def String safename = null; JvLoadTest(String sname) { @@ -155,4 +155,4 @@ def JvLoadTest newJvLoadTest(String tempFile) { System.gc(); jalview.gui.Desktop.instance.desktop.showMemoryUsage(true); return new JvLoadTest(tempFile) -} \ No newline at end of file +} diff --git a/examples/groovy/PIDmatrix.groovy b/examples/groovy/PIDmatrix.groovy index b97abcc..76b9de7 100644 --- a/examples/groovy/PIDmatrix.groovy +++ b/examples/groovy/PIDmatrix.groovy @@ -56,7 +56,7 @@ printSimilarityMatrix(true,true,SimilarityParams.Jalview) void printSimilarityMatrix(boolean selview=false, boolean includeids=true, SimilarityParams pidMethod) { - def currentAlignFrame = jalview.bin.Jalview.getCurrentAlignFrame() + def currentAlignFrame = Jalview.getCurrentAlignFrame() jalview.gui.AlignViewport av = currentAlignFrame.getCurrentView() @@ -96,4 +96,4 @@ void printSimilarityMatrix(boolean selview=false, boolean includeids=true, Simil print "\n" } -} \ No newline at end of file +} diff --git a/examples/groovy/alignLoadedFile.groovy b/examples/groovy/alignLoadedFile.groovy index 764fdae..df68e2b 100644 --- a/examples/groovy/alignLoadedFile.groovy +++ b/examples/groovy/alignLoadedFile.groovy @@ -20,6 +20,7 @@ */ // run an alignment on the current alignFrame import jalview.ws.jws2.*; +import jalview.ws.jws2.jabaws2.Jws2Instance; import jalview.datamodel.*; // First get the JABA service discoverer and see if there are any services. @@ -33,7 +34,7 @@ if (!disc.isRunning() && !disc.hasServices()) disc.run(); } -for (jalview.ws.jws2.Jws2Discoverer.Jws2Instance service: disc.getServices()) { +for (jalview.ws.jws2.jabaws2.Jws2Instance service: disc.getServices()) { if (service.serviceType.indexOf("uscle")>-1) { // now - go through the services if any, and find a Muscle service diff --git a/examples/groovy/annotationForSelectedSequence.groovy b/examples/groovy/annotationForSelectedSequence.groovy index abfad35..7cb3082 100644 --- a/examples/groovy/annotationForSelectedSequence.groovy +++ b/examples/groovy/annotationForSelectedSequence.groovy @@ -31,7 +31,7 @@ import java.awt.datatransfer.StringSelection import static java.awt.Toolkit.* -def curviewport = Jalview.getAlignFrames()[Jalview.getAlignFrames().length-1].getViewport(); +def curviewport = Jalview.getCurrentAlignFrame().getViewport(); // TSV output by default. // change "\t" to "," to output CSV file diff --git a/examples/groovy/parseproperties.groovy b/examples/groovy/parseproperties.groovy index 879bd49..322d5e2 100644 --- a/examples/groovy/parseproperties.groovy +++ b/examples/groovy/parseproperties.groovy @@ -1,19 +1,19 @@ /* * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) * Copyright (C) $$Year-Rel$$ The Jalview Authors - * + * * This file is part of Jalview. - * + * * Jalview is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License + * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. - * - * Jalview is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. @@ -26,7 +26,7 @@ import jalview.gui.AlignViewport; def af = Jalview.getAlignFrames(); def al = af[0].viewport.alignment; ParseProperties pp = new ParseProperties(al); -pp.getScoresFromDescription("Score", "ScanPS Raw Score", "([-0-9.+]+)"); +pp.getScoresFromDescription("Score", "ScanPS Raw Score", "([-0-9.+]+)", true); def sqs = al.getSequenceAt(0); def annots = sqs.getAnnotation(); diff --git a/examples/groovy/printtitle.groovy b/examples/groovy/printtitle.groovy index b3387ea..a048d65 100644 --- a/examples/groovy/printtitle.groovy +++ b/examples/groovy/printtitle.groovy @@ -1,35 +1,35 @@ /* * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) * Copyright (C) $$Year-Rel$$ The Jalview Authors - * + * * This file is part of Jalview. - * + * * Jalview is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License + * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. - * - * Jalview is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. */ // do something groovy in jalview println "Hello World.\n" -println "First sequence is " + currentAlFrame.viewport.alignment.getSequenceAt(0).getDisplayId(true) +println "First sequence is " + Jalview.getCurrentAlignFrame().viewport.alignment.getSequenceAt(0).getDisplayId(true) def alf = Jalview.getAlignFrames() for (ala in alf) { - // ala is an jalview.gui.AlignFrame object + // ala is an jalview.gui.AlignFrame object println ala.getTitle() // get the parent jalview.datamodel.Alignment from the alignment viewport def alignment = ala.viewport.alignment // get the first sequence from the jalview.datamodel.Alignment object - def seq = alignment.getSequenceAt(0) + def seq = alignment.getSequenceAt(0) } Jalview.quit() diff --git a/examples/groovy/removeFeaturesByGroup.groovy b/examples/groovy/removeFeaturesByGroup.groovy index 341e06f..c947a5b 100644 --- a/examples/groovy/removeFeaturesByGroup.groovy +++ b/examples/groovy/removeFeaturesByGroup.groovy @@ -46,6 +46,7 @@ for (ala in af) } } } + ala.repaint(); } diff --git a/examples/groovy/selectColumnsByFeatureAndGroup.groovy b/examples/groovy/selectColumnsByFeatureAndGroup.groovy index b8edaa7..aaa3405 100644 --- a/examples/groovy/selectColumnsByFeatureAndGroup.groovy +++ b/examples/groovy/selectColumnsByFeatureAndGroup.groovy @@ -23,7 +23,7 @@ import jalview.datamodel.*; import jalview.gui.AlignFrame; import jalview.gui.AlignViewport; import java.util.BitSet; -import javax.swing.JOptionPane; +import jalview.gui.JvOptionPane; import groovy.swing.SwingBuilder; def toselect = getFeatureInput(); // change this to select the desired feature type @@ -81,7 +81,7 @@ for (ala in Jalview.getAlignFrames()) { cs.addElement(i); } ala.viewport.setColumnSelection(cs); - ala.alignPanel.paintAlignment(true); + ala.alignPanel.paintAlignment(true, true); ala.statusBar.setText("Marked "+bs.cardinality()+" columns containing features of type "+toselect) } else { ala.statusBar.setText("No features of type "+toselect+" found."); @@ -96,4 +96,4 @@ String getFeatureInput(){ null, 'Select columns by feature by type','Enter type of feature', JvOptionPane.OK_OPTION) return response - } \ No newline at end of file + } diff --git a/examples/groovy/sitesForSelectedColumns.groovy b/examples/groovy/sitesForSelectedColumns.groovy index 8165373..f775f18 100644 --- a/examples/groovy/sitesForSelectedColumns.groovy +++ b/examples/groovy/sitesForSelectedColumns.groovy @@ -29,7 +29,7 @@ import java.awt.datatransfer.StringSelection import static java.awt.Toolkit.* -def curviewport = Jalview.getAlignFrames()[Jalview.getAlignFrames().length-1].getViewport() +def curviewport = Jalview.getCurrentAlignFrame().getViewport() def debug = false diff --git a/examples/groovy/stripUniprotPrefixes.groovy b/examples/groovy/stripUniprotPrefixes.groovy index 71b3a9f..2792604 100644 --- a/examples/groovy/stripUniprotPrefixes.groovy +++ b/examples/groovy/stripUniprotPrefixes.groovy @@ -29,7 +29,7 @@ def af = Jalview.getAlignFrames(); for (ala in af) { - def al = ala.viewport.alignment; + def al = ala.getViewport().getAlignment(); if (al!=null) { SequenceI[] seqs = al.getSequencesArray(); @@ -48,4 +48,4 @@ for (ala in af) } } } - \ No newline at end of file + diff --git a/examples/groovy/visibleFeaturesCounter.groovy b/examples/groovy/visibleFeaturesCounter.groovy index b3180f8..510f600 100644 --- a/examples/groovy/visibleFeaturesCounter.groovy +++ b/examples/groovy/visibleFeaturesCounter.groovy @@ -1,38 +1,37 @@ /* * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) * Copyright (C) $$Year-Rel$$ The Jalview Authors - * + * * This file is part of Jalview. - * + * * Jalview is free software: you can redistribute it and/or - * modify it under the terms of the GNU General Public License + * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. - * - * Jalview is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. */ -import jalview.bin.Jalview import jalview.workers.FeatureSetCounterI import jalview.workers.AlignmentAnnotationFactory /* * Demonstration of FeatureSetCounterI - * compute annotation tracks counting number of displayed + * compute annotation tracks counting number of displayed * features of each type in each column */ /* * discover features on the current view */ - -def featuresDisp=Jalview.currentAlignFrame.currentView.featuresDisplayed + +def featuresDisp=Jalview.getCurrentAlignFrame().currentView.featuresDisplayed if (featuresDisp == null) { print 'Need at least one feature visible on alignment' } @@ -40,12 +39,12 @@ def visibleFeatures=featuresDisp.visibleFeatures.toList() assert 'java.util.ArrayList' == visibleFeatures.class.name /* - * A closure that returns an array of features present + * A closure that returns an array of features present * for each feature type in visibleFeatures - * Argument 'features' will be a list of SequenceFeature + * Argument 'features' will be a list of SequenceFeature */ -def getCounts = - { features -> +def getCounts = + { features -> int[] obs = new int[visibleFeatures.size] for (sf in features) { @@ -56,9 +55,9 @@ def getCounts = * or sf.getValue(attributeName) for GFF 'column 9' properties */ int pos = 0 - for (type in visibleFeatures) + for (type in visibleFeatures) { - if (type.equals(sf.type)) + if (type.equals(sf.type)) { obs[pos]++ } @@ -67,19 +66,19 @@ def getCounts = } obs } - + /* * Define something that counts each visible feature type */ def columnSetCounter = [ - getNames: { visibleFeatures as String[] }, + getNames: { visibleFeatures as String[] }, getDescriptions: { visibleFeatures as String[] }, getMinColour: { [0, 255, 255] as int[] }, // cyan getMaxColour: { [0, 0, 255] as int[] }, // blue - count: - { res, feats -> - getCounts.call(feats) + count: + { res, feats -> + getCounts.call(feats) } ] as FeatureSetCounterI diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 7518fce..783f533 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -73,6 +73,8 @@ import jalview.bin.argparser.Arg.Opt; import jalview.bin.argparser.Arg.Type; import jalview.bin.argparser.ArgParser; import jalview.bin.argparser.BootstrapArgs; +import jalview.bin.groovy.JalviewObject; +import jalview.bin.groovy.JalviewObjectI; import jalview.ext.so.SequenceOntology; import jalview.gui.AlignFrame; import jalview.gui.Desktop; @@ -118,7 +120,7 @@ import jalview.ws.jws2.Jws2Discoverer; * @author $author$ * @version $Revision$ */ -public class Jalview +public class Jalview implements JalviewObjectI { static { @@ -138,7 +140,7 @@ public class Jalview protected Commands cmds; - public static AlignFrame currentAlignFrame; + public AlignFrame currentAlignFrame = null; private ArgParser argparser = null; @@ -1749,12 +1751,11 @@ public class Jalview } try { + JalviewObjectI j = new JalviewObject(this); Map vbinding = new HashMap<>(); - vbinding.put("Jalview", this); - if (af != null) - { - vbinding.put("currentAlFrame", af); - } + vbinding.put("Jalview", j); + vbinding.put("currentAlFrame", + af != null ? af : getCurrentAlignFrame()); Binding gbinding = new Binding(vbinding); GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile }); gse.run(sfile.toString(), gbinding); @@ -1770,7 +1771,6 @@ public class Jalview .errPrintln("Exception Whilst trying to execute file " + sfile + " as a groovy script."); e.printStackTrace(System.err); - } } @@ -1784,30 +1784,32 @@ public class Jalview return false; } + @Override public AlignFrame[] getAlignFrames() { return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() } - : Desktop.getAlignFrames(); - + : Desktop.getDesktopAlignFrames(); } /** * jalview.bin.Jalview.quit() will just run the non-GUI shutdownHook and exit */ + @Override public void quit() { // System.exit will run the shutdownHook first Jalview.exit("Quitting now. Bye!", ExitCode.OK); } - public static AlignFrame getCurrentAlignFrame() + @Override + public AlignFrame getCurrentAlignFrame() { - return Jalview.currentAlignFrame; + return currentAlignFrame; } - public static void setCurrentAlignFrame(AlignFrame currentAlignFrame) + public void setCurrentAlignFrame(AlignFrame af) { - Jalview.currentAlignFrame = currentAlignFrame; + this.currentAlignFrame = af; } public Commands getCommands() @@ -1859,7 +1861,7 @@ public class Jalview // only add new ones to the end of the list (to preserve ordinal values) OK, FILE_NOT_FOUND, FILE_NOT_READABLE, NO_FILES, INVALID_FORMAT, INVALID_ARGUMENT, INVALID_VALUE, MIXED_CLI_ARGUMENTS, - ERROR_RUNNING_COMMANDS, NO_LOGGING; + ERROR_RUNNING_COMMANDS, NO_LOGGING, GROOVY_ERROR; } /****************************** diff --git a/src/jalview/bin/groovy/JalviewObject.java b/src/jalview/bin/groovy/JalviewObject.java new file mode 100644 index 0000000..e271c3c --- /dev/null +++ b/src/jalview/bin/groovy/JalviewObject.java @@ -0,0 +1,42 @@ +package jalview.bin.groovy; + +import jalview.bin.Jalview.ExitCode; +import jalview.gui.AlignFrame; + +public class JalviewObject implements JalviewObjectI +{ + private JalviewObjectI object = null; + + public JalviewObject(JalviewObjectI j) + { + this.object = j; + } + + @Override + public AlignFrame[] getAlignFrames() + { + return object == null ? null : object.getAlignFrames(); + } + + @Override + public AlignFrame getCurrentAlignFrame() + { + return object == null ? null : object.getCurrentAlignFrame(); + } + + @Override + public void quit() + { + if (object != null) + { + object.quit(); + } + else + { + jalview.bin.Jalview.exit( + "Groovy console quit without Jalview object.", + ExitCode.GROOVY_ERROR); + } + } + +} diff --git a/src/jalview/bin/groovy/JalviewObjectI.java b/src/jalview/bin/groovy/JalviewObjectI.java new file mode 100644 index 0000000..775ab2a --- /dev/null +++ b/src/jalview/bin/groovy/JalviewObjectI.java @@ -0,0 +1,14 @@ +package jalview.bin.groovy; + +import jalview.gui.AlignFrame; + +public interface JalviewObjectI +{ + public AlignFrame[] getAlignFrames(); + + public AlignFrame getCurrentAlignFrame(); + + public static AlignFrame currentAlFrame = null; + + public void quit(); +} diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 00bd4f9..ae14539 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -503,7 +503,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void focusGained(FocusEvent e) { - Jalview.setCurrentAlignFrame(AlignFrame.this); + Jalview.getInstance().setCurrentAlignFrame(AlignFrame.this); } }); @@ -5963,7 +5963,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override protected void runGroovy_actionPerformed() { - Jalview.setCurrentAlignFrame(this); + Jalview.getInstance().setCurrentAlignFrame(this); groovy.console.ui.Console console = Desktop.getGroovyConsole(); if (console != null) { diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index ef9e575..a8bc815 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -997,7 +997,7 @@ public class AlignViewport extends AlignmentViewport */ protected boolean noReferencesTo(AlignedCodonFrame acf) { - AlignFrame[] frames = Desktop.getAlignFrames(); + AlignFrame[] frames = Desktop.getDesktopAlignFrames(); if (frames == null) { return true; diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 0ebc58b..b1f9000 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -114,6 +114,8 @@ import jalview.bin.Cache; import jalview.bin.Jalview; import jalview.bin.Jalview.ExitCode; import jalview.bin.argparser.Arg; +import jalview.bin.groovy.JalviewObject; +import jalview.bin.groovy.JalviewObjectI; import jalview.datamodel.Alignment; import jalview.datamodel.HiddenColumns; import jalview.datamodel.Sequence; @@ -158,7 +160,7 @@ import jalview.ws.utils.UrlDownloadClient; */ public class Desktop extends jalview.jbgui.GDesktop implements DropTargetListener, ClipboardOwner, IProgressIndicator, - jalview.api.StructureSelectionManagerProvider + jalview.api.StructureSelectionManagerProvider, JalviewObjectI { private static final String CITATION; static @@ -1056,7 +1058,7 @@ public class Desktop extends jalview.jbgui.GDesktop { if (itf instanceof AlignFrame) { - Jalview.setCurrentAlignFrame((AlignFrame) itf); + Jalview.getInstance().setCurrentAlignFrame((AlignFrame) itf); } itf.requestFocus(); } @@ -1679,7 +1681,7 @@ public class Desktop extends jalview.jbgui.GDesktop { } } - Jalview.setCurrentAlignFrame(null); + Jalview.getInstance().setCurrentAlignFrame(null); jalview.bin.Console.info("ALL CLOSED"); /* @@ -2138,7 +2140,7 @@ public class Desktop extends jalview.jbgui.GDesktop return null; } List aps = new ArrayList<>(); - AlignFrame[] frames = getAlignFrames(); + AlignFrame[] frames = Desktop.getDesktopAlignFrames(); if (frames == null) { return null; @@ -2175,7 +2177,7 @@ public class Desktop extends jalview.jbgui.GDesktop List viewp = new ArrayList<>(); if (desktop != null) { - AlignFrame[] frames = Desktop.getAlignFrames(); + AlignFrame[] frames = Desktop.getDesktopAlignFrames(); for (AlignFrame afr : frames) { @@ -2536,12 +2538,12 @@ public class Desktop extends jalview.jbgui.GDesktop * * @return an array of AlignFrame, or null if none found */ - public static AlignFrame[] getAlignFrames() + @Override + public AlignFrame[] getAlignFrames() { - if (Jalview.isHeadlessMode()) + if (desktop == null) { - // Desktop.desktop is null in headless mode - return new AlignFrame[] { Jalview.currentAlignFrame }; + return null; } JInternalFrame[] frames = Desktop.desktop.getAllFrames(); @@ -2583,6 +2585,25 @@ public class Desktop extends jalview.jbgui.GDesktop } /** + * static version + */ + public static AlignFrame[] getDesktopAlignFrames() + { + if (Jalview.isHeadlessMode()) + { + // Desktop.desktop is null in headless mode + return Jalview.getInstance().getAlignFrames(); + } + + if (instance != null && desktop != null) + { + return instance.getAlignFrames(); + } + + return null; + } + + /** * Returns an array of any AppJmol frames in the Desktop (or null if none). * * @return @@ -2640,8 +2661,10 @@ public class Desktop extends jalview.jbgui.GDesktop { if (groovyConsole == null) { + JalviewObjectI j = new JalviewObject(this); groovyConsole = new groovy.console.ui.Console(); - groovyConsole.setVariable("Jalview", this); + groovyConsole.setVariable("Jalview", j); + groovyConsole.setVariable("currentAlFrame", getCurrentAlignFrame()); groovyConsole.run(); /* @@ -2714,7 +2737,7 @@ public class Desktop extends jalview.jbgui.GDesktop */ groovyShell.setEnabled(!enabled); - AlignFrame[] alignFrames = getAlignFrames(); + AlignFrame[] alignFrames = getDesktopAlignFrames(); if (alignFrames != null) { for (AlignFrame af : alignFrames) @@ -3845,4 +3868,9 @@ public class Desktop extends jalview.jbgui.GDesktop { button }, button, modal, new JButton[] { jb }, false); } + @Override + public AlignFrame getCurrentAlignFrame() + { + return Jalview.getInstance().getCurrentAlignFrame(); + } } diff --git a/src/jalview/gui/QuitHandler.java b/src/jalview/gui/QuitHandler.java index ad7684e..6020135 100644 --- a/src/jalview/gui/QuitHandler.java +++ b/src/jalview/gui/QuitHandler.java @@ -294,7 +294,7 @@ public class QuitHandler return QResponse.QUIT; int size = 0; - AlignFrame[] afArray = Desktop.getAlignFrames(); + AlignFrame[] afArray = Desktop.getDesktopAlignFrames(); if (!(afArray == null || afArray.length == 0)) { for (int i = 0; i < afArray.length; i++) diff --git a/src/jalview/gui/WsJobParameters.java b/src/jalview/gui/WsJobParameters.java index 196eb32..d8259f9 100644 --- a/src/jalview/gui/WsJobParameters.java +++ b/src/jalview/gui/WsJobParameters.java @@ -1325,7 +1325,7 @@ public class WsJobParameters extends JPanel implements ItemListener, */ protected void updateWebServiceMenus() { - for (AlignFrame alignFrame : Desktop.getAlignFrames()) + for (AlignFrame alignFrame : Desktop.getDesktopAlignFrames()) { alignFrame.BuildWebServiceMenu(); } diff --git a/src/jalview/io/VamsasAppDatastore.java b/src/jalview/io/VamsasAppDatastore.java index c3776d3..46b75c8 100644 --- a/src/jalview/io/VamsasAppDatastore.java +++ b/src/jalview/io/VamsasAppDatastore.java @@ -151,7 +151,7 @@ public class VamsasAppDatastore private void buildSkipList() { skipList = new Hashtable(); - AlignFrame[] al = Desktop.getAlignFrames(); + AlignFrame[] al = Desktop.getDesktopAlignFrames(); for (int f = 0; al != null && f < al.length; f++) { skipList.put(al[f].getViewport().getSequenceSetId(), al[f]); diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index af3b2c8..cc20fce 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -631,7 +631,7 @@ public class Jalview2XML */ public void saveState(JarOutputStream jout) { - AlignFrame[] frames = Desktop.getAlignFrames(); + AlignFrame[] frames = Desktop.getDesktopAlignFrames(); setStateSavedUpToDate(true); @@ -6919,7 +6919,7 @@ public class Jalview2XML if (stateSavedUpToDate()) // nothing happened since last project save return true; - AlignFrame[] frames = Desktop.getAlignFrames(); + AlignFrame[] frames = Desktop.getDesktopAlignFrames(); if (frames != null) { for (int i = 0; i < frames.length; i++) diff --git a/src/jalview/workers/AlignmentAnnotationFactory.java b/src/jalview/workers/AlignmentAnnotationFactory.java index c4e4b04..8b5240c 100644 --- a/src/jalview/workers/AlignmentAnnotationFactory.java +++ b/src/jalview/workers/AlignmentAnnotationFactory.java @@ -20,6 +20,8 @@ */ package jalview.workers; +import java.awt.Color; + import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.bin.Jalview; @@ -27,8 +29,6 @@ import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; import jalview.gui.AlignFrame; -import java.awt.Color; - /** * Factory class with methods which allow clients (including external scripts * such as Groovy) to 'register and forget' an alignment annotation calculator. @@ -52,7 +52,7 @@ public class AlignmentAnnotationFactory */ public static void newCalculator(FeatureSetCounterI counter) { - AlignmentViewPanel currentAlignFrame = Jalview + AlignmentViewPanel currentAlignFrame = Jalview.getInstance() .getCurrentAlignFrame().alignPanel; if (currentAlignFrame == null) { @@ -74,7 +74,8 @@ public class AlignmentAnnotationFactory { // TODO need an interface for AlignFrame by which to access // its AlignViewportI and AlignmentViewPanel - AlignFrame currentAlignFrame = Jalview.getCurrentAlignFrame(); + AlignFrame currentAlignFrame = Jalview.getInstance() + .getCurrentAlignFrame(); if (currentAlignFrame != null) { new AnnotationWorker(currentAlignFrame.getViewport(), diff --git a/test/jalview/bin/CommandsTest.java b/test/jalview/bin/CommandsTest.java index ecec67d..de6185c 100644 --- a/test/jalview/bin/CommandsTest.java +++ b/test/jalview/bin/CommandsTest.java @@ -111,13 +111,13 @@ public class CommandsTest Assert.assertEquals(cmds.argsWereParsed(), cmdArgs, "Overall command parse and operation is false"); - Assert.assertEquals(Desktop.getAlignFrames().length, numFrames, + Assert.assertEquals(Desktop.getDesktopAlignFrames().length, numFrames, "Wrong number of AlignFrames"); if (sequences != null) { Set openedSequenceNames = new HashSet<>(); - AlignFrame[] afs = Desktop.getAlignFrames(); + AlignFrame[] afs = Desktop.getDesktopAlignFrames(); for (AlignFrame af : afs) { openedSequenceNames.addAll( @@ -325,7 +325,7 @@ public class CommandsTest public static boolean lookForSequenceName(String sequenceName) { - AlignFrame[] afs = Desktop.getAlignFrames(); + AlignFrame[] afs = Desktop.getDesktopAlignFrames(); for (AlignFrame af : afs) { for (String name : af.getViewport().getAlignment().getSequenceNames()) diff --git a/test/jalview/bin/CommandsTest2.java b/test/jalview/bin/CommandsTest2.java index ae14c1a..a78ca5a 100644 --- a/test/jalview/bin/CommandsTest2.java +++ b/test/jalview/bin/CommandsTest2.java @@ -79,7 +79,7 @@ public class CommandsTest2 } ; - AlignFrame[] afs = Desktop.getAlignFrames(); + AlignFrame[] afs = Desktop.getDesktopAlignFrames(); Assert.assertNotNull(afs); Assert.assertTrue(afs.length > 0); diff --git a/test/jalview/gui/DesktopTests.java b/test/jalview/gui/DesktopTests.java index 5bf3507..f8fdb63 100644 --- a/test/jalview/gui/DesktopTests.java +++ b/test/jalview/gui/DesktopTests.java @@ -135,7 +135,7 @@ public class DesktopTests { Assert.fail("Unexpected exception " + x); } - AlignFrame[] alfs = Desktop.getAlignFrames(); + AlignFrame[] alfs = Desktop.getDesktopAlignFrames(); Assert.assertEquals("Expect just 2 alignment frames", 2, alfs.length); // internal paste should yield a new alignment window with shared dataset AlignmentI dataset = internalSource.getViewport().getAlignment() diff --git a/test/jalview/io/CrossRef2xmlTests.java b/test/jalview/io/CrossRef2xmlTests.java index c46477a..34cc17f 100644 --- a/test/jalview/io/CrossRef2xmlTests.java +++ b/test/jalview/io/CrossRef2xmlTests.java @@ -186,7 +186,7 @@ public class CrossRef2xmlTests extends Jalview2xmlBase SequenceFetcher sf = new SequenceFetcher(Desktop.instance, forSource, forAccession); sf.run(); - AlignFrame[] afs = Desktop.getAlignFrames(); + AlignFrame[] afs = Desktop.getDesktopAlignFrames(); if (afs.length == 0) { failedDBRetr.add("Didn't retrieve " + first); diff --git a/test/jalview/project/Jalview2xmlTests.java b/test/jalview/project/Jalview2xmlTests.java index c9532cc..aa4be3d 100644 --- a/test/jalview/project/Jalview2xmlTests.java +++ b/test/jalview/project/Jalview2xmlTests.java @@ -287,12 +287,12 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }) public void gatherViewsHere() throws Exception { - int origCount = Desktop.getAlignFrames() == null ? 0 - : Desktop.getAlignFrames().length; + int origCount = Desktop.getDesktopAlignFrames() == null ? 0 + : Desktop.getDesktopAlignFrames().length; AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/exampleFile_2_7.jar", DataSourceType.FILE); assertNotNull(af, "Didn't read in the example file correctly."); - assertTrue(Desktop.getAlignFrames().length == 1 + origCount, + assertTrue(Desktop.getDesktopAlignFrames().length == 1 + origCount, "Didn't gather the views in the example file."); } @@ -430,7 +430,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/exampleFile_2_7.jar", DataSourceType.FILE); - Assert.assertEquals(Desktop.getAlignFrames().length, 1); + Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 1); String afid = af.getViewport().getSequenceSetId(); // check FileLoader returned a reference to the one alignFrame that is @@ -440,8 +440,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase Desktop.explodeViews(af); - int oldviews = Desktop.getAlignFrames().length; - Assert.assertEquals(Desktop.getAlignFrames().length, + int oldviews = Desktop.getDesktopAlignFrames().length; + Assert.assertEquals(Desktop.getDesktopAlignFrames().length, Desktop.getAlignmentPanels(afid).length); File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp"); try @@ -455,14 +455,14 @@ public class Jalview2xmlTests extends Jalview2xmlBase Assert.fail("Didn't save the expanded view state", e); } Desktop.instance.closeAll_actionPerformed(null); - if (Desktop.getAlignFrames() != null) + if (Desktop.getDesktopAlignFrames() != null) { - Assert.assertEquals(Desktop.getAlignFrames().length, 0); + Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 0); } af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(), DataSourceType.FILE); Assert.assertNotNull(af); - Assert.assertEquals(Desktop.getAlignFrames().length, + Assert.assertEquals(Desktop.getDesktopAlignFrames().length, Desktop.getAlignmentPanels( af.getViewport().getSequenceSetId()).length); Assert.assertEquals(Desktop @@ -519,9 +519,9 @@ public class Jalview2xmlTests extends Jalview2xmlBase Assert.fail("Didn't save the expanded view state", e); } Desktop.instance.closeAll_actionPerformed(null); - if (Desktop.getAlignFrames() != null) + if (Desktop.getDesktopAlignFrames() != null) { - Assert.assertEquals(Desktop.getAlignFrames().length, 0); + Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 0); } af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(), @@ -698,9 +698,9 @@ public class Jalview2xmlTests extends Jalview2xmlBase Assert.fail("Didn't save the expanded view state", e); } Desktop.instance.closeAll_actionPerformed(null); - if (Desktop.getAlignFrames() != null) + if (Desktop.getDesktopAlignFrames() != null) { - Assert.assertEquals(Desktop.getAlignFrames().length, 0); + Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 0); } af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(), @@ -792,9 +792,9 @@ public class Jalview2xmlTests extends Jalview2xmlBase Assert.fail("Didn't save the state", e); } Desktop.instance.closeAll_actionPerformed(null); - if (Desktop.getAlignFrames() != null) + if (Desktop.getDesktopAlignFrames() != null) { - Assert.assertEquals(Desktop.getAlignFrames().length, 0); + Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 0); } AlignFrame restoredFrame = new FileLoader().LoadFileWaitTillLoaded( @@ -1217,7 +1217,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase assertNotNull(af); AlignmentI ds = null; - for (AlignFrame alignFrame : Desktop.getAlignFrames()) + for (AlignFrame alignFrame : Desktop.getDesktopAlignFrames()) { if (ds == null) { diff --git a/test/jalview/renderer/seqfeatures/FeatureRendererTest.java b/test/jalview/renderer/seqfeatures/FeatureRendererTest.java index 53f98c3..0472317 100644 --- a/test/jalview/renderer/seqfeatures/FeatureRendererTest.java +++ b/test/jalview/renderer/seqfeatures/FeatureRendererTest.java @@ -638,7 +638,7 @@ public class FeatureRendererTest /* * find the complement frames (ugly) */ - AlignFrame[] frames = Desktop.getAlignFrames(); + AlignFrame[] frames = Desktop.getDesktopAlignFrames(); assertEquals(frames.length, 2); AlignViewport av1 = frames[0].getViewport(); AlignViewport av2 = frames[1].getViewport();