From 53b2ec17b88081e402f60deab2723750bc4867d1 Mon Sep 17 00:00:00 2001 From: hansonr Date: Fri, 10 May 2019 07:03:42 -0500 Subject: [PATCH] JAL-3253 jalview.bin.Instance handles all singleton instances - preliminary --- src/jalview/analysis/AlignmentSorter.java | 8 +- src/jalview/analysis/scoremodels/ScoreModels.java | 6 +- src/jalview/bin/Cache.java | 6 +- src/jalview/bin/Instance.java | 150 ++++++++++++++++++++ src/jalview/bin/Jalview.java | 109 +------------- src/jalview/ext/ensembl/EnsemblInfo.java | 4 +- src/jalview/fts/service/pdb/PDBFTSRestClient.java | 7 +- .../fts/service/uniprot/UniProtFTSRestClient.java | 7 +- src/jalview/gui/AlignFrame.java | 27 ++-- src/jalview/gui/AlignViewport.java | 9 +- src/jalview/gui/AnnotationLabels.java | 5 +- src/jalview/gui/CrossRefAction.java | 3 +- src/jalview/gui/Desktop.java | 120 ++++++---------- src/jalview/gui/JalviewDialog.java | 7 +- src/jalview/gui/Preferences.java | 3 +- src/jalview/gui/SliderPanel.java | 49 +++---- src/jalview/gui/SplashScreen.java | 11 +- src/jalview/gui/SplitFrame.java | 11 +- src/jalview/gui/StructureChooser.java | 11 +- src/jalview/gui/StructureViewerBase.java | 3 +- src/jalview/gui/VamsasApplication.java | 7 +- src/jalview/gui/WsJobParameters.java | 9 +- src/jalview/gui/WsParamSetManager.java | 5 +- src/jalview/gui/WsPreferences.java | 9 +- src/jalview/httpserver/HttpServer.java | 4 +- src/jalview/io/FileLoader.java | 17 +-- src/jalview/io/VamsasAppDatastore.java | 5 +- src/jalview/io/gff/SequenceOntologyFactory.java | 11 +- src/jalview/io/vamsas/Sequencemapping.java | 4 +- src/jalview/project/Jalview2XML.java | 17 +-- src/jalview/rest/RestHandler.java | 4 +- src/jalview/schemes/AnnotationColourGradient.java | 4 +- src/jalview/schemes/ColourSchemeProperty.java | 6 +- src/jalview/schemes/RNAHelicesColour.java | 4 +- src/jalview/structure/StructureImportSettings.java | 9 +- .../structure/StructureSelectionManager.java | 129 ++++++++--------- src/jalview/urls/IdOrgSettings.java | 11 +- src/jalview/ws/SequenceFetcherFactory.java | 6 +- src/jalview/ws/jws1/Discoverer.java | 8 +- src/jalview/ws/jws2/Jws2Discoverer.java | 4 +- .../ws/jws2/SequenceAnnotationWSClient.java | 4 +- src/jalview/ws/jws2/jabaws2/Jws2Instance.java | 3 +- .../ws/jws2/jabaws2/Jws2InstanceFactory.java | 4 +- src/jalview/ws/rest/RestClient.java | 4 +- src/jalview/ws/sifts/SiftsSettings.java | 4 +- test/jalview/ext/jmol/JmolViewerTest.java | 2 +- .../ext/rbvi/chimera/JalviewChimeraView.java | 4 +- test/jalview/gui/AlignFrameTest.java | 3 +- test/jalview/gui/AlignViewportTest.java | 13 +- test/jalview/gui/FreeUpMemoryTest.java | 5 +- test/jalview/gui/SeqPanelTest.java | 3 +- test/jalview/io/AnnotatedPDBFileInputTest.java | 2 +- test/jalview/io/CrossRef2xmlTests.java | 9 +- test/jalview/io/FeaturesFileTest.java | 4 +- test/jalview/io/Jalview2xmlBase.java | 7 +- test/jalview/io/JalviewExportPropertiesTests.java | 2 +- test/jalview/project/Jalview2xmlTests.java | 29 ++-- test/jalview/schemes/ColourSchemesTest.java | 4 +- .../structure/StructureSelectionManagerTest.java | 3 +- 59 files changed, 495 insertions(+), 443 deletions(-) create mode 100644 src/jalview/bin/Instance.java diff --git a/src/jalview/analysis/AlignmentSorter.java b/src/jalview/analysis/AlignmentSorter.java index b764787..459d09d 100755 --- a/src/jalview/analysis/AlignmentSorter.java +++ b/src/jalview/analysis/AlignmentSorter.java @@ -22,7 +22,7 @@ package jalview.analysis; import jalview.analysis.scoremodels.PIDModel; import jalview.analysis.scoremodels.SimilarityParams; -import jalview.bin.Jalview; +import jalview.bin.Instance; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentOrder; @@ -55,6 +55,10 @@ import java.util.List; public class AlignmentSorter { + private AlignmentSorter() + { + // singleton + } /** * types of feature ordering: Sort by score : average score - or total score - * over all features in region Sort by feature label text: (or if null - @@ -69,7 +73,7 @@ public class AlignmentSorter public static AlignmentSorter getInstance() { - Jalview j = Jalview.getInstance(); + Instance j = Instance.getInstance(); return (j.alignmentSorter == null ? j.alignmentSorter = new AlignmentSorter() : j.alignmentSorter); diff --git a/src/jalview/analysis/scoremodels/ScoreModels.java b/src/jalview/analysis/scoremodels/ScoreModels.java index 0041245..8afc4fc 100644 --- a/src/jalview/analysis/scoremodels/ScoreModels.java +++ b/src/jalview/analysis/scoremodels/ScoreModels.java @@ -22,7 +22,7 @@ package jalview.analysis.scoremodels; import jalview.api.AlignmentViewPanel; import jalview.api.analysis.ScoreModelI; -import jalview.bin.Jalview; +import jalview.bin.Instance; import jalview.io.DataSourceType; import jalview.io.FileParse; import jalview.io.ScoreMatrixFile; @@ -50,7 +50,7 @@ public class ScoreModels */ public static ScoreModels getInstance() { - Jalview j = Jalview.getInstance(); + Instance j = Instance.getInstance(); return (j.scoreModels == null ? j.scoreModels = new ScoreModels() : j.scoreModels); } @@ -150,7 +150,7 @@ public class ScoreModels */ public void reset() { - Jalview.getInstance().scoreModels = new ScoreModels(); + Instance.getInstance().scoreModels = new ScoreModels(); } /** diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index ee97b7f..642917f 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -219,8 +219,8 @@ public class Cache */ public static Cache getInstance() { - Jalview j = Jalview.getInstance(); - return (j.cache == null ? j.cache = new Cache() : j.cache); + Instance i = Instance.getInstance(); + return (i.cache == null ? i.cache = new Cache() : i.cache); } /** @@ -280,7 +280,7 @@ public class Cache private Cache() { - // inaccessible + // singleton } /** Jalview Properties */ diff --git a/src/jalview/bin/Instance.java b/src/jalview/bin/Instance.java new file mode 100644 index 0000000..0afe1bd --- /dev/null +++ b/src/jalview/bin/Instance.java @@ -0,0 +1,150 @@ +/* + * 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 + * 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 + * 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. + */ +package jalview.bin; + +import jalview.analysis.AlignmentSorter; +import jalview.analysis.scoremodels.ScoreModels; +import jalview.api.StructureSelectionManagerProvider; +import jalview.ext.ensembl.EnsemblInfo; +import jalview.fts.service.pdb.PDBFTSRestClient; +import jalview.fts.service.uniprot.UniProtFTSRestClient; +import jalview.gui.Desktop; +import jalview.httpserver.HttpServer; +import jalview.io.gff.SequenceOntologyI; +import jalview.rest.RestHandler; +import jalview.structure.StructureImportSettings; +import jalview.structure.StructureSelectionManager; +import jalview.urls.IdOrgSettings; +import jalview.ws.SequenceFetcher; +import jalview.ws.jws1.Discoverer; +import jalview.ws.jws2.Jws2Discoverer; +import jalview.ws.jws2.jabaws2.Jws2InstanceFactory; +import jalview.ws.rest.RestClient; +import jalview.ws.sifts.SiftsSettings; + +import java.awt.Color; +import java.util.IdentityHashMap; + +/** + * a class to hold singleton instances so that they are not shared + * + * @author hansonr + * + */ +public class Instance { + + private static Instance instance; + + public static Instance getInstance() + { + Instance i; + @SuppressWarnings("unused") + ThreadGroup g = Thread.currentThread().getThreadGroup(); + /** + * @j2sNative i = g._instance; + */ + { + i = instance; + } + if (i == null) + { + i = instance = new Instance(); + /** + * @j2sNative g._instance = i; + */ + } + return i; + } + + /** + * singleton instance of this class in Java only + */ + + public Jalview jalview; + + public Desktop desktop; + + public static Jalview getJalview() + { + Instance i = getInstance(); + if (i.jalview == null) + { + new Jalview(); + } + return i.jalview; + } + + public static void setJalview(Jalview j) + { + getInstance().jalview = j; + } + + public static Desktop getDesktop() + { + Instance i = getInstance(); + return (i.desktop == null ? (i.desktop = new Desktop(true)) + : i.desktop); + } + + public static void setDesktop(Desktop d) + { + getInstance().desktop = d; + } + + public Cache cache; + + public AlignmentSorter alignmentSorter; + + public Color[] rnaHelices = null; + + public Discoverer discoverer; + + public EnsemblInfo ensemblInfo; + + public HttpServer httpServer; + + public IdOrgSettings idOrgSettings; + + public Jws2Discoverer j2s2discoverer; + + public Jws2InstanceFactory jws2InstanceFactory; + + public PDBFTSRestClient pdbFTSRestClient; + + public RestClient restClient; + + public RestHandler restHandler; + + public ScoreModels scoreModels; + + public SequenceFetcher sequenceFetcher; + + public SequenceOntologyI sequenceOntology; + + public SiftsSettings siftsSettings; + + public StructureImportSettings structureImportSettings; + + public UniProtFTSRestClient uniprotFTSRestClient; + + public IdentityHashMap structureSelections; + +} diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 9da666b..8af6363 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -20,17 +20,10 @@ */ package jalview.bin; -import jalview.analysis.AlignmentSorter; -import jalview.analysis.scoremodels.ScoreModels; -import jalview.api.StructureSelectionManagerProvider; -import jalview.ext.ensembl.EnsemblInfo; import jalview.ext.so.SequenceOntology; -import jalview.fts.service.pdb.PDBFTSRestClient; -import jalview.fts.service.uniprot.UniProtFTSRestClient; import jalview.gui.AlignFrame; import jalview.gui.Desktop; import jalview.gui.PromptUserConfig; -import jalview.httpserver.HttpServer; import jalview.io.AppletFormatAdapter; import jalview.io.BioJsHTMLOutput; import jalview.io.DataSourceType; @@ -42,23 +35,12 @@ import jalview.io.HtmlSvgOutput; import jalview.io.IdentifyFile; import jalview.io.NewickFile; import jalview.io.gff.SequenceOntologyFactory; -import jalview.io.gff.SequenceOntologyI; -import jalview.rest.RestHandler; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; -import jalview.structure.StructureImportSettings; -import jalview.structure.StructureSelectionManager; -import jalview.urls.IdOrgSettings; import jalview.util.MessageManager; import jalview.util.Platform; -import jalview.ws.SequenceFetcher; -import jalview.ws.jws1.Discoverer; import jalview.ws.jws2.Jws2Discoverer; -import jalview.ws.jws2.jabaws2.Jws2InstanceFactory; -import jalview.ws.rest.RestClient; -import jalview.ws.sifts.SiftsSettings; -import java.awt.Color; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; @@ -76,7 +58,6 @@ import java.security.PermissionCollection; import java.security.Permissions; import java.security.Policy; import java.util.HashMap; -import java.util.IdentityHashMap; import java.util.Map; import java.util.Vector; import java.util.logging.ConsoleHandler; @@ -109,7 +90,7 @@ public class Jalview public Jalview() { - setInstance(this); + Instance.setJalview(this); } static @@ -121,43 +102,7 @@ public class Jalview public static boolean isHeadlessMode() { - return getInstance().headless; - } - - /** - * singleton instance of this class in Java only - */ - - private static Jalview instance; - - public static Jalview getInstance() - { - if (instance == null) - { - instance = new Jalview(); - } - Jalview j; - @SuppressWarnings("unused") - ThreadGroup g = Thread.currentThread().getThreadGroup(); - /** - * @j2sNative j = g._jalviewInstance; - */ - { - j = instance; - } - return j; - } - - private static void setInstance(Jalview j) - { - @SuppressWarnings("unused") - ThreadGroup g = Thread.currentThread().getThreadGroup(); - /** - * @j2sNative g._jalviewInstance = j; - */ - { - instance = j; - } + return Instance.getJalview().headless; } private Desktop desktop; @@ -166,12 +111,12 @@ public class Jalview public static AlignFrame getCurrentAlignFrame() { - return getInstance().currentAlignFrame; + return Instance.getJalview().currentAlignFrame; } public static void setCurrentAlignFrame(AlignFrame currentAlignFrame) { - getInstance().currentAlignFrame = currentAlignFrame; + Instance.getJalview().currentAlignFrame = currentAlignFrame; } static @@ -270,8 +215,7 @@ public class Jalview public static void main(String[] args) { // setLogging(); // BH - for event debugging in JavaScript - new Jalview(); - getInstance().doMain(args); + new Jalview().doMain(args); } private static void logClass(String name) @@ -1179,46 +1123,7 @@ public class Jalview } } - // singleton instances - - public Cache cache; - - public AlignmentSorter alignmentSorter; - - public EnsemblInfo ensemblInfo; - - public HttpServer httpServer; - - public IdentityHashMap structureSelections; - - public PDBFTSRestClient pdbFTSRestClient; - - public RestHandler restHandler; - - public ScoreModels scoreModels; - - public SequenceFetcher sequenceFetcher; - - public SequenceOntologyI sequenceOntology; - - public UniProtFTSRestClient uniprotFTSRestClient; - - public StructureSelectionManager nullProvider; - - public Color[] rnaHelices = null; - - public StructureImportSettings structureImportSettings; - - public IdOrgSettings idOrgSettings; - - public SiftsSettings siftsSettings; - - public RestClient restClient; - - public Jws2Discoverer j2s2discoverer; - - public Jws2InstanceFactory jws2InstanceFactory; - - public Discoverer discoverer; + // BH 2019.05.10 moved here from StructureSelectionManager because this is a + // singleton; allows it to be cleaned up when the application is closed. } diff --git a/src/jalview/ext/ensembl/EnsemblInfo.java b/src/jalview/ext/ensembl/EnsemblInfo.java index 2187e68..1fe92f5 100644 --- a/src/jalview/ext/ensembl/EnsemblInfo.java +++ b/src/jalview/ext/ensembl/EnsemblInfo.java @@ -1,6 +1,6 @@ package jalview.ext.ensembl; -import jalview.bin.Jalview; +import jalview.bin.Instance; import jalview.datamodel.AlignmentI; import jalview.datamodel.DBRefSource; @@ -25,7 +25,7 @@ public class EnsemblInfo extends EnsemblRestClient */ private static EnsemblInfo getInstance() { - Jalview j = Jalview.getInstance(); + Instance j = Instance.getInstance(); return (j.ensemblInfo == null ? j.ensemblInfo = new EnsemblInfo() : j.ensemblInfo); } diff --git a/src/jalview/fts/service/pdb/PDBFTSRestClient.java b/src/jalview/fts/service/pdb/PDBFTSRestClient.java index 75bfd1b..8e929e7 100644 --- a/src/jalview/fts/service/pdb/PDBFTSRestClient.java +++ b/src/jalview/fts/service/pdb/PDBFTSRestClient.java @@ -20,7 +20,7 @@ */ package jalview.fts.service.pdb; -import jalview.bin.Jalview; +import jalview.bin.Instance; import jalview.datamodel.SequenceI; import jalview.fts.api.FTSData; import jalview.fts.api.FTSDataColumnI; @@ -59,7 +59,7 @@ public class PDBFTSRestClient extends FTSRestClient public static FTSRestClientI getInstance() { - Jalview j = Jalview.getInstance(); + Instance j = Instance.getInstance(); return (j.pdbFTSRestClient == null ? j.pdbFTSRestClient = new PDBFTSRestClient() : j.pdbFTSRestClient); @@ -67,8 +67,9 @@ public class PDBFTSRestClient extends FTSRestClient public static final String PDB_SEARCH_ENDPOINT = "https://www.ebi.ac.uk/pdbe/search/pdb/select?"; - protected PDBFTSRestClient() + private PDBFTSRestClient() { + // singleton } /** diff --git a/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java b/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java index 9501930..455ea98 100644 --- a/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java +++ b/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java @@ -22,7 +22,7 @@ package jalview.fts.service.uniprot; import jalview.bin.Cache; -import jalview.bin.Jalview; +import jalview.bin.Instance; import jalview.fts.api.FTSData; import jalview.fts.api.FTSDataColumnI; import jalview.fts.api.FTSRestClientI; @@ -55,16 +55,15 @@ public class UniProtFTSRestClient extends FTSRestClient public static FTSRestClientI getInstance() { - Jalview j = Jalview.getInstance(); + Instance j = Instance.getInstance(); return (j.uniprotFTSRestClient == null ? j.uniprotFTSRestClient = new UniProtFTSRestClient() : j.uniprotFTSRestClient); } public final String uniprotSearchEndpoint; - public UniProtFTSRestClient() + private UniProtFTSRestClient() { - super(); uniprotSearchEndpoint = Cache.getDefault("UNIPROT_DOMAIN", DEFAULT_UNIPROT_DOMAIN) + "/uniprot/"; } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index d182d89..2d7c11b 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -37,6 +37,7 @@ import jalview.api.SplitContainerI; import jalview.api.ViewStyleI; import jalview.api.analysis.SimilarityParamsI; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.bin.Jalview; import jalview.commands.CommandI; import jalview.commands.EditCommand; @@ -815,7 +816,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, private void addServiceListeners() { final java.beans.PropertyChangeListener thisListener; - Desktop.getInstance().addJalviewPropertyChangeListener("services", + Instance.getDesktop().addJalviewPropertyChangeListener("services", thisListener = new java.beans.PropertyChangeListener() { @Override @@ -846,7 +847,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, javax.swing.event.InternalFrameEvent evt) { // System.out.println("deregistering discoverer listener"); - Desktop.getInstance().removeJalviewPropertyChangeListener("services", + Instance.getDesktop().removeJalviewPropertyChangeListener("services", thisListener); closeMenuItem_actionPerformed(true); } @@ -1027,7 +1028,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void addFromFile_actionPerformed(ActionEvent e) { - Desktop.getInstance().inputLocalFileMenuItem_actionPerformed(viewport); + Instance.getDesktop().inputLocalFileMenuItem_actionPerformed(viewport); } @Override @@ -1051,14 +1052,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, try { frames[i].setSelected(true); - Desktop.getInstance().closeAssociatedWindows(); + Instance.getDesktop().closeAssociatedWindows(); } catch (java.beans.PropertyVetoException ex) { } } } - Desktop.getInstance().closeAssociatedWindows(); + Instance.getDesktop().closeAssociatedWindows(); FileLoader loader = new FileLoader(); DataSourceType protocol = fileName.startsWith("http:") @@ -1116,14 +1117,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void addFromText_actionPerformed(ActionEvent e) { - Desktop.getInstance() + Instance.getDesktop() .inputTextboxMenuItem_actionPerformed(viewport.getAlignPanel()); } @Override public void addFromURL_actionPerformed(ActionEvent e) { - Desktop.getInstance().inputURLMenuItem_actionPerformed(viewport); + Instance.getDesktop().inputURLMenuItem_actionPerformed(viewport); } @Override @@ -1930,7 +1931,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, StringSelection ss = new StringSelection(output); - Desktop d = Desktop.getInstance(); + Desktop d = Instance.getDesktop(); try { d.internalCopy = true; @@ -1940,7 +1941,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, .setContents(new StringSelection(""), null); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, - Desktop.getInstance()); + Instance.getDesktop()); } catch (OutOfMemoryError er) { new OOMWarning("copying region", er); @@ -2032,7 +2033,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, boolean annotationAdded = false; AlignmentI alignment = null; - Desktop d = Desktop.getInstance(); + Desktop d = Instance.getDesktop(); if (d.jalviewClipboard != null) { @@ -2341,7 +2342,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, DEFAULT_HEIGHT); String newtitle = new String("Flanking alignment"); - Desktop d = Desktop.getInstance(); + Desktop d = Instance.getDesktop(); if (d.jalviewClipboard != null && d.jalviewClipboard[2] != null) { @@ -2916,7 +2917,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void gatherViews_actionPerformed(ActionEvent e) { - Desktop.getInstance().gatherViews(this); + Instance.getDesktop().gatherViews(this); } /** @@ -4630,7 +4631,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, PDBEntry pe = new AssociatePdbFileWithSeq() .associatePdbWithSeq(fm[0].toString(), (DataSourceType) fm[1], toassoc, false, - Desktop.getInstance()); + Instance.getDesktop()); if (pe != null) { System.err.println("Associated file : " diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 5f56fd9..ff3285c 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -29,6 +29,7 @@ import jalview.api.FeatureSettingsModelI; import jalview.api.FeaturesDisplayedI; import jalview.api.ViewStyleI; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.commands.CommandI; import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.Alignment; @@ -384,7 +385,7 @@ public class AlignViewport extends AlignmentViewport if (align != null) { StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Desktop.getInstance()); + .getStructureSelectionManager(Instance.getDesktop()); ssm.registerMappings(align.getCodonFrames()); } @@ -406,7 +407,7 @@ public class AlignViewport extends AlignmentViewport if (mappings != null) { StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Desktop.getInstance()); + .getStructureSelectionManager(Instance.getDesktop()); for (AlignedCodonFrame acf : mappings) { if (noReferencesTo(acf)) @@ -532,7 +533,7 @@ public class AlignViewport extends AlignmentViewport public void sendSelection() { jalview.structure.StructureSelectionManager - .getStructureSelectionManager(Desktop.getInstance()) + .getStructureSelectionManager(Instance.getDesktop()) .sendSelection(new SequenceGroup(getSelectionGroup()), new ColumnSelection(getColumnSelection()), new HiddenColumns(getAlignment().getHiddenColumns()), @@ -578,7 +579,7 @@ public class AlignViewport extends AlignmentViewport public StructureSelectionManager getStructureSelectionManager() { return StructureSelectionManager - .getStructureSelectionManager(Desktop.getInstance()); + .getStructureSelectionManager(Instance.getDesktop()); } @Override diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 72d75b8..964ffa3 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -22,6 +22,7 @@ package jalview.gui; import jalview.analysis.AlignSeq; import jalview.analysis.AlignmentUtils; +import jalview.bin.Instance; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; @@ -971,7 +972,7 @@ public class AnnotationLabels extends JPanel seqs, omitHidden, alignmentStartEnd); Toolkit.getDefaultToolkit().getSystemClipboard() - .setContents(new StringSelection(output), Desktop.getInstance()); + .setContents(new StringSelection(output), Instance.getDesktop()); HiddenColumns hiddenColumns = null; @@ -981,7 +982,7 @@ public class AnnotationLabels extends JPanel av.getAlignment().getHiddenColumns()); } - Desktop.getInstance().jalviewClipboard = new Object[] { seqs, ds, // what is + Instance.getDesktop().jalviewClipboard = new Object[] { seqs, ds, // what is // the // dataset // of a consensus diff --git a/src/jalview/gui/CrossRefAction.java b/src/jalview/gui/CrossRefAction.java index cc2e0a9..7570858 100644 --- a/src/jalview/gui/CrossRefAction.java +++ b/src/jalview/gui/CrossRefAction.java @@ -25,6 +25,7 @@ import jalview.analysis.CrossRef; import jalview.api.AlignmentViewPanel; import jalview.api.FeatureSettingsModelI; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.DBRefEntry; @@ -437,7 +438,7 @@ public class CrossRefAction implements Runnable .setGapCharacter(alignFrame.viewport.getGapCharacter()); StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Desktop.getInstance()); + .getStructureSelectionManager(Instance.getDesktop()); /* * register any new mappings for sequence mouseover etc diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index c76c396..c835248 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -23,6 +23,7 @@ package jalview.gui; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.bin.Jalview; import jalview.gui.ImageExporter.ImageWriterI; import jalview.io.BackupFiles; @@ -47,6 +48,7 @@ import jalview.util.MessageManager; import jalview.util.Platform; import jalview.util.UrlConstants; import jalview.viewmodel.AlignmentViewport; +import jalview.ws.jws1.Discoverer; import jalview.ws.params.ParamManager; import jalview.ws.utils.UrlDownloadClient; @@ -191,51 +193,9 @@ public class Desktop extends jalview.jbgui.GDesktop listener); } - /** - * Singleton Desktop instance only in Java; - */ - private static Desktop instance; - - public static Desktop getInstance() - { - if (instance == null) - { - new Desktop(true); - } - Desktop d; - @SuppressWarnings("unused") - ThreadGroup g = Thread.currentThread().getThreadGroup(); - /** - * @j2sNative d = g._jalviewDesktopInstance; - */ - { - d = instance; - } - return d; - } - - private static void setInstance(Desktop d) - { - @SuppressWarnings("unused") - ThreadGroup g = Thread.currentThread().getThreadGroup(); - /** - * @j2sNative g._jalviewDesktopInstance = d; - */ - { - instance = d; - } - } - - private MyDesktopPane desktopPane; - public static MyDesktopPane getDesktopPane() { - return getInstance().desktopPane; - } - - private void setDesktopPane(MyDesktopPane pane) - { - getInstance().desktopPane = pane; + return Instance.getDesktop().desktopPane; } static int openFrameCount = 0; @@ -244,7 +204,7 @@ public class Desktop extends jalview.jbgui.GDesktop static final int yOffset = 30; - public jalview.ws.jws1.Discoverer discoverer; + public Discoverer discoverer; public Object[] jalviewClipboard; @@ -254,6 +214,9 @@ public class Desktop extends jalview.jbgui.GDesktop public JInternalFrame conservationSlider, PIDSlider; + /** + * just an instance (for testng, probably); no actual frames + */ private boolean instanceOnly; class MyDesktopManager implements DesktopManager @@ -275,7 +238,7 @@ public class Desktop extends jalview.jbgui.GDesktop } catch (NullPointerException npe) { Point p = getMousePosition(); - getInstance().showPasteMenu(p.x, p.y); + showPasteMenu(p.x, p.y); } } @@ -323,14 +286,14 @@ public class Desktop extends jalview.jbgui.GDesktop public void endDraggingFrame(JComponent f) { delegate.endDraggingFrame(f); - getDesktopPane().repaint(); + desktopPane.repaint(); } @Override public void endResizingFrame(JComponent f) { delegate.endResizingFrame(f); - getDesktopPane().repaint(); + desktopPane.repaint(); } @Override @@ -379,10 +342,11 @@ public class Desktop extends jalview.jbgui.GDesktop } + public MyDesktopPane desktopPane; + public Desktop(boolean forInstance) { instanceOnly = true; - setInstance(this); } /** * Creates a new Desktop object. @@ -394,7 +358,7 @@ public class Desktop extends jalview.jbgui.GDesktop * block are spawned off as threads rather than waited for during this * constructor. */ - setInstance(this); + Instance.setDesktop(this); if (!Platform.isJS()) { doVamsasClientCheck(); @@ -407,10 +371,10 @@ public class Desktop extends jalview.jbgui.GDesktop false); boolean showjconsole = jalview.bin.Cache.getDefault("SHOW_JAVA_CONSOLE", false); - setDesktopPane(new MyDesktopPane(selmemusage)); + desktopPane = new MyDesktopPane(selmemusage); showMemusage.setSelected(selmemusage); - getDesktopPane().setBackground(Color.white); + desktopPane.setBackground(Color.white); getContentPane().setLayout(new BorderLayout()); // alternate config - have scrollbars - see notes in JAL-153 // JScrollPane sp = new JScrollPane(); @@ -423,17 +387,17 @@ public class Desktop extends jalview.jbgui.GDesktop getRootPane().putClientProperty("swingjs.overflow.hidden", "false"); } - getContentPane().add(getDesktopPane(), BorderLayout.CENTER); - getDesktopPane().setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); + getContentPane().add(desktopPane, BorderLayout.CENTER); + desktopPane.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); // This line prevents Windows Look&Feel resizing all new windows to maximum // if previous window was maximised - getDesktopPane().setDesktopManager(new MyDesktopManager( + desktopPane.setDesktopManager(new MyDesktopManager( (Platform.isWindowsAndNotJS() ? new DefaultDesktopManager() : Platform.isAMacAndNotJS() ? new AquaInternalFrameManager( - getDesktopPane().getDesktopManager()) - : getDesktopPane().getDesktopManager()))); + desktopPane.getDesktopManager()) + : desktopPane.getDesktopManager()))); Rectangle dims = getLastKnownDimensions(""); if (dims != null) @@ -522,7 +486,7 @@ public class Desktop extends jalview.jbgui.GDesktop } - this.setDropTarget(new java.awt.dnd.DropTarget(getDesktopPane(), this)); + this.setDropTarget(new java.awt.dnd.DropTarget(desktopPane, this)); this.addWindowListener(new WindowAdapter() { @@ -554,7 +518,7 @@ public class Desktop extends jalview.jbgui.GDesktop } } }); - getDesktopPane().addMouseListener(ma); + desktopPane.addMouseListener(ma); } @@ -652,10 +616,10 @@ public class Desktop extends jalview.jbgui.GDesktop public void run() { long now = System.currentTimeMillis(); - Desktop.getInstance().setProgressBar( + setProgressBar( MessageManager.getString("status.refreshing_news"), now); jvnews.refreshNews(); - Desktop.getInstance().setProgressBar(null, now); + setProgressBar(null, now); jvnews.showNews(); } }).start(); @@ -902,7 +866,7 @@ public class Desktop extends jalview.jbgui.GDesktop // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN // IF JALVIEW IS RUNNING HEADLESS // /////////////////////////////////////////////// - if (getInstance().instanceOnly || Jalview.isHeadlessMode()) + if (Instance.getDesktop().instanceOnly || Jalview.isHeadlessMode()) { return; } @@ -980,7 +944,7 @@ public class Desktop extends jalview.jbgui.GDesktop { menuItem.removeActionListener(menuItem.getActionListeners()[0]); } - getInstance().windowMenu.remove(menuItem); + Instance.getDesktop().windowMenu.remove(menuItem); }; }); @@ -1004,7 +968,7 @@ public class Desktop extends jalview.jbgui.GDesktop getDesktopPane().add(frame); - getInstance().windowMenu.add(menuItem); + Instance.getDesktop().windowMenu.add(menuItem); frame.toFront(); try @@ -1061,7 +1025,7 @@ public class Desktop extends jalview.jbgui.GDesktop { if (!internalCopy) { - Desktop.getInstance().jalviewClipboard = null; + Instance.getDesktop().jalviewClipboard = null; } internalCopy = false; @@ -1514,12 +1478,12 @@ public class Desktop extends jalview.jbgui.GDesktop @Override public void closeAll_actionPerformed(ActionEvent e) { - if (getDesktopPane() == null) + if (desktopPane == null) { return; } // TODO show a progress bar while closing? - JInternalFrame[] frames = getDesktopPane().getAllFrames(); + JInternalFrame[] frames = desktopPane.getAllFrames(); for (int i = 0; i < frames.length; i++) { try @@ -1904,7 +1868,7 @@ public class Desktop extends jalview.jbgui.GDesktop { progressPanel = new JPanel(new GridLayout(1, 1)); totalProgressCount = 0; - getInstance().getContentPane().add(progressPanel, BorderLayout.SOUTH); + getContentPane().add(progressPanel, BorderLayout.SOUTH); } JPanel thisprogress = new JPanel(new BorderLayout(10, 5)); JProgressBar progressBar = new JProgressBar(); @@ -1917,7 +1881,7 @@ public class Desktop extends jalview.jbgui.GDesktop ((GridLayout) progressPanel.getLayout()).setRows( ((GridLayout) progressPanel.getLayout()).getRows() + 1); ++totalProgressCount; - getInstance().validate(); + validate(); return thisprogress; } @@ -2099,7 +2063,7 @@ public class Desktop extends jalview.jbgui.GDesktop { source.viewport.setGatherViewsHere(true); source.viewport.setExplodedGeometry(source.getBounds()); - JInternalFrame[] frames = getDesktopPane().getAllFrames(); + JInternalFrame[] frames = getAllFrames(); String viewId = source.viewport.getSequenceSetId(); for (int t = 0; t < frames.length; t++) @@ -2494,7 +2458,7 @@ public class Desktop extends jalview.jbgui.GDesktop public JInternalFrame[] getAllFrames() { - return getDesktopPane().getAllFrames(); + return desktopPane.getAllFrames(); } /** @@ -2580,7 +2544,7 @@ public class Desktop extends jalview.jbgui.GDesktop }); msgPanel.add(jcb); - JvOptionPane.showMessageDialog(Desktop.getDesktopPane(), msgPanel, + JvOptionPane.showMessageDialog(desktopPane, msgPanel, MessageManager .getString("label.SEQUENCE_ID_no_longer_used"), JvOptionPane.WARNING_MESSAGE); @@ -2780,7 +2744,7 @@ public class Desktop extends jalview.jbgui.GDesktop } catch (Exception ex) { jalview.bin.Cache.log.error("Groovy Shell Creation failed.", ex); - JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(), + JvOptionPane.showInternalMessageDialog(desktopPane, MessageManager.getString("label.couldnt_create_groovy_shell"), MessageManager.getString("label.groovy_support_failed"), @@ -3038,7 +3002,7 @@ public class Desktop extends jalview.jbgui.GDesktop // todo: changesupport handlers need to be transferred if (discoverer == null) { - discoverer = new jalview.ws.jws1.Discoverer(); + discoverer = Discoverer.getInstance(); // register PCS handler for getDesktop(). discoverer.addPropertyChangeListener(changeSupport); } @@ -3158,7 +3122,7 @@ public class Desktop extends jalview.jbgui.GDesktop */ public static void showUrl(final String url) { - showUrl(url, Desktop.getInstance()); + showUrl(url, Instance.getDesktop()); } /** @@ -3207,7 +3171,7 @@ public class Desktop extends jalview.jbgui.GDesktop public static ParamManager getUserParameterStore() { - Desktop d = getInstance(); + Desktop d = Instance.getDesktop(); if (d.wsparamManager == null) { d.wsparamManager = new WsParamSetManager(); @@ -3454,7 +3418,7 @@ public class Desktop extends jalview.jbgui.GDesktop String topViewId = myTopFrame.viewport.getSequenceSetId(); String bottomViewId = myBottomFrame.viewport.getSequenceSetId(); - JInternalFrame[] frames = getDesktopPane().getAllFrames(); + JInternalFrame[] frames = desktopPane.getAllFrames(); for (JInternalFrame frame : frames) { if (frame instanceof SplitFrame && frame != source) @@ -3499,7 +3463,7 @@ public class Desktop extends jalview.jbgui.GDesktop public static groovy.ui.Console getGroovyConsole() { - return getInstance().groovyConsole; + return Instance.getDesktop().groovyConsole; } /** @@ -3752,7 +3716,7 @@ public class Desktop extends jalview.jbgui.GDesktop Class structureViewerClass) { List result = new ArrayList<>(); - JInternalFrame[] frames = Desktop.getInstance().getAllFrames(); + JInternalFrame[] frames = getAllFrames(); for (JInternalFrame frame : frames) { diff --git a/src/jalview/gui/JalviewDialog.java b/src/jalview/gui/JalviewDialog.java index 0ff5606..8ba387e 100644 --- a/src/jalview/gui/JalviewDialog.java +++ b/src/jalview/gui/JalviewDialog.java @@ -20,6 +20,7 @@ */ package jalview.gui; +import jalview.bin.Instance; import jalview.util.MessageManager; import java.awt.Container; @@ -78,11 +79,11 @@ public abstract class JalviewDialog extends JPanel boolean block, String title, int width, int height) { - frame = new JDialog(Desktop.getInstance(), modal); + frame = new JDialog(Instance.getDesktop(), modal); frame.setTitle(title); - if (Desktop.getInstance() != null) + if (Instance.getDesktop() != null) { - Rectangle deskr = Desktop.getInstance().getBounds(); + Rectangle deskr = Instance.getDesktop().getBounds(); frame.setBounds(new Rectangle((int) (deskr.getCenterX() - width / 2), (int) (deskr.getCenterY() - height / 2), width, height)); } diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index facc826..d651e91 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -22,6 +22,7 @@ package jalview.gui; import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.gui.Help.HelpId; import jalview.gui.StructureViewer.ViewerType; import jalview.io.BackupFiles; @@ -862,7 +863,7 @@ public class Preferences extends GPreferences Integer.toString(getComboIntStringKey(backupfilesPresetsCombo))); Cache.saveProperties(); - Desktop.getInstance().doConfigureStructurePrefs(); + Instance.getDesktop().doConfigureStructurePrefs(); try { frame.setClosed(true); diff --git a/src/jalview/gui/SliderPanel.java b/src/jalview/gui/SliderPanel.java index 31ad083..0a80292 100755 --- a/src/jalview/gui/SliderPanel.java +++ b/src/jalview/gui/SliderPanel.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.analysis.Conservation; +import jalview.bin.Instance; import jalview.datamodel.SequenceGroup; import jalview.jbgui.GSliderPanel; import jalview.renderer.ResidueShaderI; @@ -63,10 +64,10 @@ public class SliderPanel extends GSliderPanel public static SliderPanel getSliderPanel() { - JInternalFrame conservationSlider = Desktop - .getInstance().conservationSlider; + JInternalFrame conservationSlider = Instance + .getDesktop().conservationSlider; - JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; + JInternalFrame PIDSlider = Instance.getDesktop().PIDSlider; if (conservationSlider != null && conservationSlider.isVisible()) { @@ -155,14 +156,14 @@ public class SliderPanel extends GSliderPanel { SliderPanel sliderPanel = null; - JInternalFrame conservationSlider = Desktop - .getInstance().conservationSlider; + JInternalFrame conservationSlider = Instance + .getDesktop().conservationSlider; if (conservationSlider == null) { sliderPanel = new SliderPanel(ap, rs.getConservationInc(), true, rs); - conservationSlider = Desktop - .getInstance().conservationSlider = new JInternalFrame(); + conservationSlider = Instance + .getDesktop().conservationSlider = new JInternalFrame(); conservationSlider.setContentPane(sliderPanel); conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER); } @@ -198,14 +199,14 @@ public class SliderPanel extends GSliderPanel */ public static void hidePIDSlider() { - JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; + JInternalFrame PIDSlider = Instance.getDesktop().PIDSlider; if (PIDSlider != null) { try { PIDSlider.setClosed(true); - Desktop.getInstance().PIDSlider = null; + Instance.getDesktop().PIDSlider = null; } catch (PropertyVetoException ex) { } @@ -217,15 +218,15 @@ public class SliderPanel extends GSliderPanel */ public static void hideConservationSlider() { - JInternalFrame conservationSlider = Desktop - .getInstance().conservationSlider; + JInternalFrame conservationSlider = Instance + .getDesktop().conservationSlider; if (conservationSlider != null) { try { conservationSlider.setClosed(true); - Desktop.getInstance().conservationSlider = null; + Instance.getDesktop().conservationSlider = null; } catch (PropertyVetoException ex) { } @@ -239,8 +240,8 @@ public class SliderPanel extends GSliderPanel { hidePIDSlider(); - JInternalFrame conservationSlider = Desktop - .getInstance().conservationSlider; + JInternalFrame conservationSlider = Instance + .getDesktop().conservationSlider; if (!conservationSlider.isVisible()) { @@ -252,7 +253,7 @@ public class SliderPanel extends GSliderPanel @Override public void internalFrameClosed(InternalFrameEvent e) { - Desktop.getInstance().conservationSlider = null; + Instance.getDesktop().conservationSlider = null; } }); conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER); @@ -278,12 +279,12 @@ public class SliderPanel extends GSliderPanel SliderPanel sliderPanel = null; - JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; + JInternalFrame PIDSlider = Instance.getDesktop().PIDSlider; if (PIDSlider == null) { sliderPanel = new SliderPanel(ap, threshold, false, rs); - PIDSlider = Desktop.getInstance().PIDSlider = new JInternalFrame(); + PIDSlider = Instance.getDesktop().PIDSlider = new JInternalFrame(); PIDSlider.setContentPane(sliderPanel); PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER); } @@ -321,7 +322,7 @@ public class SliderPanel extends GSliderPanel { hideConservationSlider(); - JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; + JInternalFrame PIDSlider = Instance.getDesktop().PIDSlider; if (!PIDSlider.isVisible()) { @@ -333,7 +334,7 @@ public class SliderPanel extends GSliderPanel @Override public void internalFrameClosed(InternalFrameEvent e) { - Desktop.getInstance().PIDSlider = null; + Instance.getDesktop().PIDSlider = null; } }); PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER); @@ -469,7 +470,7 @@ public class SliderPanel extends GSliderPanel public static int getConservationValue() { - return getValue(Desktop.getInstance().conservationSlider); + return getValue(Instance.getDesktop().conservationSlider); } static int getValue(JInternalFrame slider) @@ -480,7 +481,7 @@ public class SliderPanel extends GSliderPanel public static int getPIDValue() { - return getValue(Desktop.getInstance().PIDSlider); + return getValue(Instance.getDesktop().PIDSlider); } /** @@ -503,9 +504,9 @@ public class SliderPanel extends GSliderPanel public String getTitle() { String title = null; - JInternalFrame conservationSlider = Desktop - .getInstance().conservationSlider; - JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; + JInternalFrame conservationSlider = Instance + .getDesktop().conservationSlider; + JInternalFrame PIDSlider = Instance.getDesktop().PIDSlider; if (isForConservation()) { diff --git a/src/jalview/gui/SplashScreen.java b/src/jalview/gui/SplashScreen.java index 98b24d1..96f5c8c 100755 --- a/src/jalview/gui/SplashScreen.java +++ b/src/jalview/gui/SplashScreen.java @@ -20,6 +20,7 @@ */ package jalview.gui; +import jalview.bin.Instance; import jalview.util.Platform; import java.awt.BorderLayout; @@ -160,7 +161,7 @@ public class SplashScreen extends JPanel System.err.println("Error when loading images!"); } } while (!mt.checkAll()); - Desktop.getInstance().setIconImage(logo); + Instance.getDesktop().setIconImage(logo); } } catch (Exception ex) { @@ -203,7 +204,7 @@ public class SplashScreen extends JPanel @SuppressWarnings("unused") protected boolean refreshText() { - String newtext = Desktop.getInstance().getAboutMessage(true).toString(); + String newtext = Instance.getDesktop().getAboutMessage(true).toString(); // System.err.println("Text found: \n"+newtext+"\nEnd of newtext."); if (oldtext != newtext.length()) { @@ -236,8 +237,8 @@ public class SplashScreen extends JPanel authlist.setSize(new Dimension(750, 375)); add(authlist, BorderLayout.CENTER); revalidate(); - iframe.setBounds((Desktop.getInstance().getWidth() - 750) / 2, - (Desktop.getInstance().getHeight() - 375) / 2, 750, + iframe.setBounds((Instance.getDesktop().getWidth() - 750) / 2, + (Instance.getDesktop().getHeight() - 375) / 2, 750, authlist.getHeight() + iconimg.getHeight()); iframe.validate(); iframe.setVisible(true); @@ -287,7 +288,7 @@ public class SplashScreen extends JPanel } closeSplash(); - Desktop.getInstance().startDialogQueue(); + Instance.getDesktop().startDialogQueue(); } /** diff --git a/src/jalview/gui/SplitFrame.java b/src/jalview/gui/SplitFrame.java index 55a9c61..8d559ee 100644 --- a/src/jalview/gui/SplitFrame.java +++ b/src/jalview/gui/SplitFrame.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.api.SplitContainerI; +import jalview.bin.Instance; import jalview.datamodel.AlignmentI; import jalview.jbgui.GAlignFrame; import jalview.jbgui.GSplitFrame; @@ -132,7 +133,7 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI // allow about 65 pixels for Desktop decorators on Windows int newHeight = Math.min(height, - Desktop.getInstance().getHeight() - DESKTOP_DECORATORS_HEIGHT); + Instance.getDesktop().getHeight() - DESKTOP_DECORATORS_HEIGHT); if (newHeight != height) { int oldDividerLocation = getDividerLocation(); @@ -150,7 +151,7 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI // TODO if CommandListener is only ever 1:1 for complementary views, // may change broadcast pattern to direct messaging (more efficient) final StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Desktop.getInstance()); + .getStructureSelectionManager(Instance.getDesktop()); ssm.addCommandListener(((AlignFrame) getTopFrame()).getViewport()); ssm.addCommandListener(((AlignFrame) getBottomFrame()).getViewport()); } @@ -556,7 +557,7 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI adjustLayout(); final StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Desktop.getInstance()); + .getStructureSelectionManager(Instance.getDesktop()); ssm.addCommandListener(newTopPanel.av); ssm.addCommandListener(newBottomPanel.av); } @@ -683,7 +684,7 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI */ protected void expandViews_actionPerformed() { - Desktop.getInstance().explodeViews(this); + Instance.getDesktop().explodeViews(this); } /** @@ -692,7 +693,7 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI */ protected void gatherViews_actionPerformed() { - Desktop.getInstance().gatherViews(this); + Instance.getDesktop().gatherViews(this); } /** diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 620db5a..61eea30 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -23,6 +23,7 @@ package jalview.gui; import jalview.api.structures.JalviewStructureDisplayI; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.bin.Jalview; import jalview.datamodel.DBRefEntry; import jalview.datamodel.DBRefSource; @@ -146,16 +147,16 @@ public class StructureChooser extends GStructureChooser */ protected void discoverStructureViews() { - if (Desktop.getInstance() != null) + if (Instance.getDesktop() != null) { targetView.removeAllItems(); - Desktop d = Desktop.getInstance(); + Desktop d = Instance.getDesktop(); if (d.lastTargetedView != null && !d.lastTargetedView.isVisible()) { d.lastTargetedView = null; } int linkedViewsAt = 0; - for (StructureViewerBase view : Desktop.getInstance() + for (StructureViewerBase view : Instance.getDesktop() .getStructureViewers(null, null)) { StructureViewer viewHandler = (d.lastTargetedView != null @@ -997,7 +998,7 @@ public class StructureChooser extends GStructureChooser PDBEntry fileEntry = new AssociatePdbFileWithSeq() .associatePdbWithSeq(selectedPdbFileName, DataSourceType.FILE, selectedSequence, true, - Desktop.getInstance()); + Instance.getDesktop()); sViewer = launchStructureViewer( ssm, new PDBEntry[] @@ -1153,7 +1154,7 @@ public class StructureChooser extends GStructureChooser } setProgressBar(null, progressId); // remember the last viewer we used... - Desktop.getInstance().lastTargetedView = theViewer; + Instance.getDesktop().lastTargetedView = theViewer; return theViewer; } diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index af48093..5d6d729 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -22,6 +22,7 @@ package jalview.gui; import jalview.api.AlignmentViewPanel; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenColumns; @@ -407,7 +408,7 @@ public abstract class StructureViewerBase extends GStructureViewer */ protected List getViewersFor(AlignmentPanel alp) { - return Desktop.getInstance().getStructureViewers(alp, this.getClass()); + return Instance.getDesktop().getStructureViewers(alp, this.getClass()); } @Override diff --git a/src/jalview/gui/VamsasApplication.java b/src/jalview/gui/VamsasApplication.java index 2053fb2..f467b42 100644 --- a/src/jalview/gui/VamsasApplication.java +++ b/src/jalview/gui/VamsasApplication.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.HiddenColumns; @@ -669,7 +670,7 @@ public class VamsasApplication implements SelectionSource, VamsasSource if (reply == JvOptionPane.YES_OPTION) { Cache.log.debug("Prompting for vamsas store filename."); - Desktop.getInstance().vamsasSave_actionPerformed(null); + Instance.getDesktop().vamsasSave_actionPerformed(null); Cache.log .debug("Finished attempt at storing document."); } @@ -688,7 +689,7 @@ public class VamsasApplication implements SelectionSource, VamsasSource public void disableGui(boolean b) { - Desktop.getInstance().setVamsasUpdate(b); + Instance.getDesktop().setVamsasUpdate(b); } Hashtable _backup_vobj2jv; @@ -763,7 +764,7 @@ public class VamsasApplication implements SelectionSource, VamsasSource { final IPickManager pm = vclient.getPickManager(); final StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Desktop.getInstance()); + .getStructureSelectionManager(Instance.getDesktop()); final VamsasApplication me = this; pm.registerMessageHandler(new IMessageHandler() { diff --git a/src/jalview/gui/WsJobParameters.java b/src/jalview/gui/WsJobParameters.java index da00a25..28e7bd6 100644 --- a/src/jalview/gui/WsJobParameters.java +++ b/src/jalview/gui/WsJobParameters.java @@ -20,6 +20,7 @@ */ package jalview.gui; +import jalview.bin.Instance; import jalview.gui.OptsAndParamsPage.OptionBox; import jalview.gui.OptsAndParamsPage.ParamBox; import jalview.util.MessageManager; @@ -215,12 +216,12 @@ public class WsJobParameters extends JPanel implements ItemListener, public boolean showRunDialog() { - frame = new JDialog(Desktop.getInstance(), true); + frame = new JDialog(Instance.getDesktop(), true); frame.setTitle(MessageManager.formatMessage("label.edit_params_for", new String[] { service.getActionText() })); - Rectangle deskr = Desktop.getInstance().getBounds(); + Rectangle deskr = Instance.getDesktop().getBounds(); Dimension pref = this.getPreferredSize(); frame.setBounds( new Rectangle((int) (deskr.getCenterX() - pref.width / 2), @@ -436,8 +437,8 @@ public class WsJobParameters extends JPanel implements ItemListener, dialogpanel.add(canceljob); // JAL-1580: setMaximumSize() doesn't work, so just size for the worst case: // check for null is for JUnit usage - final int windowHeight = Desktop.getInstance() == null ? 540 - : Desktop.getInstance().getHeight(); + final int windowHeight = Instance.getDesktop() == null ? 540 + : Instance.getDesktop().getHeight(); setPreferredSize(new Dimension(540, windowHeight)); add(dialogpanel, BorderLayout.SOUTH); validate(); diff --git a/src/jalview/gui/WsParamSetManager.java b/src/jalview/gui/WsParamSetManager.java index 0f315eb..33b26c9 100644 --- a/src/jalview/gui/WsParamSetManager.java +++ b/src/jalview/gui/WsParamSetManager.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; import jalview.util.MessageManager; @@ -203,7 +204,7 @@ public class WsParamSetManager implements ParamManager chooser.setDialogTitle(MessageManager .getString("label.choose_filename_for_param_file")); chooser.setToolTipText(MessageManager.getString("action.save")); - int value = chooser.showSaveDialog(Desktop.getInstance()); + int value = chooser.showSaveDialog(Instance.getDesktop()); if (value == JalviewFileChooser.APPROVE_OPTION) { outfile = chooser.getSelectedFile(); @@ -311,7 +312,7 @@ public class WsParamSetManager implements ParamManager File pfile = new File(filename); if (pfile.exists() && pfile.canWrite()) { - if (JvOptionPane.showConfirmDialog(Desktop.getInstance(), + if (JvOptionPane.showConfirmDialog(Instance.getDesktop(), "Delete the preset's file, too ?", "Delete User Preset ?", JvOptionPane.OK_CANCEL_OPTION) == JvOptionPane.OK_OPTION) { diff --git a/src/jalview/gui/WsPreferences.java b/src/jalview/gui/WsPreferences.java index 9966c02..c5b27a0 100644 --- a/src/jalview/gui/WsPreferences.java +++ b/src/jalview/gui/WsPreferences.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.jbgui.GWsPreferences; import jalview.util.MessageManager; import jalview.ws.jws2.Jws2Discoverer; @@ -595,7 +596,7 @@ public class WsPreferences extends GWsPreferences if (lastrefresh != update) { lastrefresh = update; - Desktop.getInstance().startServiceDiscovery(true); // wait around for all + Instance.getDesktop().startServiceDiscovery(true); // wait around for all // threads to complete updateList(); @@ -616,15 +617,15 @@ public class WsPreferences extends GWsPreferences public void run() { long ct = System.currentTimeMillis(); - Desktop.getInstance().setProgressBar(MessageManager + Instance.getDesktop().setProgressBar(MessageManager .getString("status.refreshing_web_service_menus"), ct); if (lastrefresh != update) { lastrefresh = update; - Desktop.getInstance().startServiceDiscovery(true); + Instance.getDesktop().startServiceDiscovery(true); updateList(); } - Desktop.getInstance().setProgressBar(null, ct); + Instance.getDesktop().setProgressBar(null, ct); } }).start(); diff --git a/src/jalview/httpserver/HttpServer.java b/src/jalview/httpserver/HttpServer.java index 58e792d..02c8380 100644 --- a/src/jalview/httpserver/HttpServer.java +++ b/src/jalview/httpserver/HttpServer.java @@ -20,7 +20,7 @@ */ package jalview.httpserver; -import jalview.bin.Jalview; +import jalview.bin.Instance; import jalview.rest.RestHandler; import java.net.BindException; @@ -68,7 +68,7 @@ public class HttpServer { synchronized (HttpServer.class) { - Jalview j = Jalview.getInstance(); + Instance j = Instance.getInstance(); return (j.httpServer == null ? j.httpServer = new HttpServer() : j.httpServer); } diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index 38594df..d3bf4e0 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -25,6 +25,7 @@ import jalview.api.FeatureSettingsModelI; import jalview.api.FeaturesDisplayedI; import jalview.api.FeaturesSourceI; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.bin.Jalview; import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenColumns; @@ -278,9 +279,9 @@ public class FileLoader implements Runnable Runtime rt = Runtime.getRuntime(); try { - if (Desktop.getInstance() != null) + if (Instance.getDesktop() != null) { - Desktop.getInstance().startLoading(file); + Instance.getDesktop().startLoading(file); } if (format == null) { @@ -302,7 +303,7 @@ public class FileLoader implements Runnable if (format == null) { - Desktop.getInstance().stopLoading(); + Instance.getDesktop().stopLoading(); System.err.println("The input file \"" + file + "\" has null or unidentifiable data content!"); if (!Jalview.isHeadlessMode()) @@ -411,7 +412,7 @@ public class FileLoader implements Runnable // register PDB entries with desktop's structure selection // manager StructureSelectionManager - .getStructureSelectionManager(Desktop.getInstance()) + .getStructureSelectionManager(Instance.getDesktop()) .registerPDBEntry(pdbe); } } @@ -500,9 +501,9 @@ public class FileLoader implements Runnable } else { - if (Desktop.getInstance() != null) + if (Instance.getDesktop() != null) { - Desktop.getInstance().stopLoading(); + Instance.getDesktop().stopLoading(); } final String errorMessage = MessageManager.getString( @@ -610,9 +611,9 @@ public class FileLoader implements Runnable } } // remove the visual delay indicator - if (Desktop.getInstance() != null) + if (Instance.getDesktop() != null) { - Desktop.getInstance().stopLoading(); + Instance.getDesktop().stopLoading(); } } diff --git a/src/jalview/io/VamsasAppDatastore.java b/src/jalview/io/VamsasAppDatastore.java index a7d901a..3145fe9 100644 --- a/src/jalview/io/VamsasAppDatastore.java +++ b/src/jalview/io/VamsasAppDatastore.java @@ -21,6 +21,7 @@ package jalview.io; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.GraphLine; @@ -722,7 +723,7 @@ public class VamsasAppDatastore // FIND ANY ASSOCIATED TREES if (Desktop.getDesktopPane() != null) { - javax.swing.JInternalFrame[] frames = Desktop.getInstance() + javax.swing.JInternalFrame[] frames = Instance.getDesktop() .getAllFrames(); for (int t = 0; t < frames.length; t++) @@ -1479,7 +1480,7 @@ public class VamsasAppDatastore if (mappings != null) { jalview.structure.StructureSelectionManager - .getStructureSelectionManager(Desktop.getInstance()) + .getStructureSelectionManager(Instance.getDesktop()) .registerMappings(mappings); } } diff --git a/src/jalview/io/gff/SequenceOntologyFactory.java b/src/jalview/io/gff/SequenceOntologyFactory.java index cd5a22c..97ebf2a 100644 --- a/src/jalview/io/gff/SequenceOntologyFactory.java +++ b/src/jalview/io/gff/SequenceOntologyFactory.java @@ -20,7 +20,7 @@ */ package jalview.io.gff; -import jalview.bin.Jalview; +import jalview.bin.Instance; /** * A factory class that returns a model of the Sequence Ontology. By default a @@ -32,12 +32,17 @@ import jalview.bin.Jalview; */ public class SequenceOntologyFactory { + + private SequenceOntologyFactory() + { + // noninstantiable + } // private static SequenceOntologyI instance; // moved to Jalview.instance for // JavaScript public static synchronized SequenceOntologyI getInstance() { - Jalview j = Jalview.getInstance(); + Instance j = Instance.getInstance(); if (j.sequenceOntology == null) { j.sequenceOntology = new SequenceOntologyLite(); @@ -47,6 +52,6 @@ public class SequenceOntologyFactory public static void setInstance(SequenceOntologyI so) { - Jalview.getInstance().sequenceOntology = so; + Instance.getInstance().sequenceOntology = so; } } diff --git a/src/jalview/io/vamsas/Sequencemapping.java b/src/jalview/io/vamsas/Sequencemapping.java index 402ffdf..8bea620 100644 --- a/src/jalview/io/vamsas/Sequencemapping.java +++ b/src/jalview/io/vamsas/Sequencemapping.java @@ -20,12 +20,12 @@ */ package jalview.io.vamsas; +import jalview.bin.Instance; import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.AlignmentI; import jalview.datamodel.DBRefEntry; import jalview.datamodel.Mapping; import jalview.datamodel.SequenceI; -import jalview.gui.Desktop; import jalview.io.VamsasAppDatastore; import java.util.ArrayList; @@ -365,7 +365,7 @@ public class Sequencemapping extends Rangetype } bindjvvobj(mapping, sequenceMapping); jalview.structure.StructureSelectionManager - .getStructureSelectionManager(Desktop.getInstance()) + .getStructureSelectionManager(Instance.getDesktop()) .registerMapping(acf); // Try to link up any conjugate database references in the two sequences // matchConjugateDBRefs(from, to, mapping); diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index 1aac037..7f550ee 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -34,6 +34,7 @@ import jalview.api.analysis.ScoreModelI; import jalview.api.analysis.SimilarityParamsI; import jalview.api.structures.JalviewStructureDisplayI; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; @@ -2915,9 +2916,9 @@ public class Jalview2XML { // used to attempt to parse as V1 castor-generated xml } - if (Desktop.getInstance() != null) + if (Instance.getDesktop() != null) { - Desktop.getInstance().stopLoading(); + Instance.getDesktop().stopLoading(); } if (af != null) { @@ -2945,7 +2946,7 @@ public class Jalview2XML */ for (AlignFrame fr : gatherToThisFrame.values()) { - Desktop.getInstance().gatherViews(fr); + Instance.getDesktop().gatherViews(fr); } restoreSplitFrames(); @@ -2954,7 +2955,7 @@ public class Jalview2XML if (ds.getCodonFrames() != null) { StructureSelectionManager - .getStructureSelectionManager(Desktop.getInstance()) + .getStructureSelectionManager(Instance.getDesktop()) .registerMappings(ds.getCodonFrames()); } } @@ -2963,9 +2964,9 @@ public class Jalview2XML reportErrors(); } - if (Desktop.getInstance() != null) + if (Instance.getDesktop() != null) { - Desktop.getInstance().stopLoading(); + Instance.getDesktop().stopLoading(); } return af; @@ -3046,7 +3047,7 @@ public class Jalview2XML */ for (SplitFrame sf : gatherTo) { - Desktop.getInstance().gatherViews(sf); + Instance.getDesktop().gatherViews(sf); } splitFrameCandidates.clear(); @@ -3576,7 +3577,7 @@ public class Jalview2XML entry.setProperty(prop.getName(), prop.getValue()); } StructureSelectionManager - .getStructureSelectionManager(Desktop.getInstance()) + .getStructureSelectionManager(Instance.getDesktop()) .registerPDBEntry(entry); // adds PDBEntry to datasequence's set (since Jalview 2.10) if (al.getSequenceAt(i).getDatasetSequence() != null) diff --git a/src/jalview/rest/RestHandler.java b/src/jalview/rest/RestHandler.java index b897eaa..bcb344f 100644 --- a/src/jalview/rest/RestHandler.java +++ b/src/jalview/rest/RestHandler.java @@ -20,7 +20,7 @@ */ package jalview.rest; -import jalview.bin.Jalview; +import jalview.bin.Instance; import jalview.httpserver.AbstractRequestHandler; import java.io.IOException; @@ -49,7 +49,7 @@ public class RestHandler extends AbstractRequestHandler { synchronized (RestHandler.class) { - Jalview j = Jalview.getInstance(); + Instance j = Instance.getInstance(); return (j.restHandler == null ? j.restHandler = new RestHandler() : j.restHandler); } diff --git a/src/jalview/schemes/AnnotationColourGradient.java b/src/jalview/schemes/AnnotationColourGradient.java index 7bb294a..ad6947f 100755 --- a/src/jalview/schemes/AnnotationColourGradient.java +++ b/src/jalview/schemes/AnnotationColourGradient.java @@ -21,7 +21,7 @@ package jalview.schemes; import jalview.api.AlignViewportI; -import jalview.bin.Jalview; +import jalview.bin.Instance; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AnnotatedCollectionI; @@ -356,7 +356,7 @@ public class AnnotationColourGradient extends FollowerColourScheme { if (ann.isRNA()) { - result = Jalview.getInstance().rnaHelices[(int) aj.value]; + result = Instance.getInstance().rnaHelices[(int) aj.value]; } else { diff --git a/src/jalview/schemes/ColourSchemeProperty.java b/src/jalview/schemes/ColourSchemeProperty.java index 90386e5..877f375 100755 --- a/src/jalview/schemes/ColourSchemeProperty.java +++ b/src/jalview/schemes/ColourSchemeProperty.java @@ -21,7 +21,7 @@ package jalview.schemes; import jalview.api.AlignViewportI; -import jalview.bin.Jalview; +import jalview.bin.Instance; import jalview.datamodel.AnnotatedCollectionI; import jalview.util.ColorUtils; @@ -113,7 +113,7 @@ public class ColourSchemeProperty public static void initRnaHelicesShading(int n) { int i = 0; - Jalview j = Jalview.getInstance(); + Instance j = Instance.getInstance(); if (j.rnaHelices == null) { @@ -142,7 +142,7 @@ public class ColourSchemeProperty */ public static void resetRnaHelicesShading() { - Jalview.getInstance().rnaHelices = null; + Instance.getInstance().rnaHelices = null; } /** diff --git a/src/jalview/schemes/RNAHelicesColour.java b/src/jalview/schemes/RNAHelicesColour.java index 041823f..c82cd57 100644 --- a/src/jalview/schemes/RNAHelicesColour.java +++ b/src/jalview/schemes/RNAHelicesColour.java @@ -21,7 +21,7 @@ package jalview.schemes; import jalview.api.AlignViewportI; -import jalview.bin.Jalview; +import jalview.bin.Instance; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AnnotatedCollectionI; @@ -201,7 +201,7 @@ public class RNAHelicesColour extends ResidueColourScheme currentHelix = positionsToHelix.get(j); if (currentHelix != null) { - currentColour = Jalview.getInstance().rnaHelices[Integer + currentColour = Instance.getInstance().rnaHelices[Integer .parseInt(currentHelix)]; } return currentColour; diff --git a/src/jalview/structure/StructureImportSettings.java b/src/jalview/structure/StructureImportSettings.java index a6adac6..c439914 100644 --- a/src/jalview/structure/StructureImportSettings.java +++ b/src/jalview/structure/StructureImportSettings.java @@ -20,7 +20,7 @@ */ package jalview.structure; -import jalview.bin.Jalview; +import jalview.bin.Instance; import jalview.datamodel.PDBEntry; import jalview.datamodel.PDBEntry.Type; @@ -34,9 +34,14 @@ import jalview.datamodel.PDBEntry.Type; public class StructureImportSettings { + private StructureImportSettings() + { + // singleton + } + private static StructureImportSettings getInstance() { - Jalview j = Jalview.getInstance(); + Instance j = Instance.getInstance(); return (j.structureImportSettings == null ? j.structureImportSettings = new StructureImportSettings() : j.structureImportSettings); diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index c2c66e5..f0665de 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -22,7 +22,7 @@ package jalview.structure; import jalview.analysis.AlignSeq; import jalview.api.StructureSelectionManagerProvider; -import jalview.bin.Jalview; +import jalview.bin.Instance; import jalview.commands.CommandI; import jalview.commands.EditCommand; import jalview.commands.OrderCommand; @@ -52,6 +52,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; +import java.util.IdentityHashMap; import java.util.List; import java.util.Map; import java.util.Vector; @@ -62,8 +63,16 @@ import mc_view.PDBfile; public class StructureSelectionManager { + + public StructureSelectionManager() + { + } + public final static String NEWLINE = System.lineSeparator(); + // BH unnecessary; IdentityHashMap can handle this + // private static StructureSelectionManager nullProvider; + private List mappings = new ArrayList<>(); private boolean processSecondaryStructure = false; @@ -195,49 +204,6 @@ public class StructureSelectionManager || pdbIdFileName.containsKey(idOrFile); } - public static StructureSelectionManager getStructureSelectionManager( - StructureSelectionManagerProvider context) - { - Jalview j = Jalview.getInstance(); - if (context == null) - { - if (j.nullProvider == null) - { - if (j.structureSelections != null) - { - throw new Error(MessageManager.getString( - "error.implementation_error_structure_selection_manager_null"), - new NullPointerException(MessageManager - .getString("exception.ssm_context_is_null"))); - } - else - { - j.nullProvider = new StructureSelectionManager(); - } - return j.nullProvider; - } - } - if (j.structureSelections == null) - { - j.structureSelections = new java.util.IdentityHashMap<>(); - } - StructureSelectionManager instance = Jalview - .getInstance().structureSelections.get(context); - if (instance == null) - { - if (j.nullProvider != null) - { - instance = j.nullProvider; - } - else - { - instance = new StructureSelectionManager(); - } - j.structureSelections.put(context, instance); - } - return instance; - } - /** * flag controlling whether SeqMappings are relayed from received sequence * mouse over events to other sequences @@ -1321,35 +1287,7 @@ public class StructureSelectionManager } } } - - /** - * release all references associated with this manager provider - * - * @param jalviewLite - */ - public static void release(StructureSelectionManagerProvider jalviewLite) - { - // synchronized (instances) - { - if (Jalview.getInstance().structureSelections == null) - { - return; - } - StructureSelectionManager mnger = (Jalview - .getInstance().structureSelections.get(jalviewLite)); - if (mnger != null) - { - Jalview.getInstance().structureSelections.remove(jalviewLite); - try - { - mnger.finalize(); - } catch (Throwable x) - { - } - } - } - } - + public void registerPDBEntry(PDBEntry pdbentry) { if (pdbentry.getFile() != null @@ -1428,4 +1366,49 @@ public class StructureSelectionManager return seqmappings; } + public static StructureSelectionManager getStructureSelectionManager( + StructureSelectionManagerProvider context) + { + IdentityHashMap map = Instance + .getInstance().structureSelections; + + if (map == null) + { + map = Instance + .getInstance().structureSelections = new IdentityHashMap<>(); + } + StructureSelectionManager instance = map.get(context); + if (instance == null) + { + // BH: actually, not possible except for coding error; this is an attempt + // to discover that. + if (context == null && !map.isEmpty()) + { + throw new Error(MessageManager.getString( + "error.implementation_error_structure_selection_manager_null"), + new NullPointerException(MessageManager + .getString("exception.ssm_context_is_null"))); + } + map.put(context, + instance = new StructureSelectionManager()); + } + return instance; + } + + /** + * release all references associated with this manager provider + * + * @param provider + */ + + public static void release(StructureSelectionManagerProvider provider) + { + IdentityHashMap map = Instance + .getInstance().structureSelections; + if (map != null) + { + map.remove(provider); + } + } + } diff --git a/src/jalview/urls/IdOrgSettings.java b/src/jalview/urls/IdOrgSettings.java index 4d42e0b..5667603 100644 --- a/src/jalview/urls/IdOrgSettings.java +++ b/src/jalview/urls/IdOrgSettings.java @@ -21,7 +21,7 @@ package jalview.urls; -import jalview.bin.Jalview; +import jalview.bin.Instance; /** * Holds settings for identifiers.org e.g. url, download location @@ -34,9 +34,14 @@ public class IdOrgSettings private String url; private String location; - public static IdOrgSettings getInstance() + private IdOrgSettings() { - Jalview j = Jalview.getInstance(); + // singleton + } + + private static IdOrgSettings getInstance() + { + Instance j = Instance.getInstance(); return (j.idOrgSettings == null ? j.idOrgSettings = new IdOrgSettings() : j.idOrgSettings); } diff --git a/src/jalview/ws/SequenceFetcherFactory.java b/src/jalview/ws/SequenceFetcherFactory.java index 64dac0d..63231d5 100644 --- a/src/jalview/ws/SequenceFetcherFactory.java +++ b/src/jalview/ws/SequenceFetcherFactory.java @@ -20,7 +20,7 @@ */ package jalview.ws; -import jalview.bin.Jalview; +import jalview.bin.Instance; import jalview.ws.seqfetcher.ASequenceFetcher; public class SequenceFetcherFactory @@ -33,7 +33,7 @@ public class SequenceFetcherFactory */ public static ASequenceFetcher getSequenceFetcher() { - Jalview j = Jalview.getInstance(); + Instance j = Instance.getInstance(); return (j.sequenceFetcher == null ? j.sequenceFetcher = new SequenceFetcher() : j.sequenceFetcher); @@ -49,6 +49,6 @@ public class SequenceFetcherFactory */ public static void setSequenceFetcher(SequenceFetcher sf) { - Jalview.getInstance().sequenceFetcher = sf; + Instance.getInstance().sequenceFetcher = sf; } } diff --git a/src/jalview/ws/jws1/Discoverer.java b/src/jalview/ws/jws1/Discoverer.java index 25fcc6b..4af342a 100644 --- a/src/jalview/ws/jws1/Discoverer.java +++ b/src/jalview/ws/jws1/Discoverer.java @@ -20,7 +20,7 @@ */ package jalview.ws.jws1; -import jalview.bin.Jalview; +import jalview.bin.Instance; import jalview.gui.JvOptionPane; import jalview.util.MessageManager; @@ -38,9 +38,13 @@ import ext.vamsas.ServiceHandles; public class Discoverer implements Runnable { + private Discoverer() + { + }; + public static Discoverer getInstance() { - Jalview j = Jalview.getInstance(); + Instance j = Instance.getInstance(); return (j.discoverer == null ? j.discoverer = new Discoverer() : j.discoverer); } diff --git a/src/jalview/ws/jws2/Jws2Discoverer.java b/src/jalview/ws/jws2/Jws2Discoverer.java index 1f3d300..0ff9df6 100644 --- a/src/jalview/ws/jws2/Jws2Discoverer.java +++ b/src/jalview/ws/jws2/Jws2Discoverer.java @@ -21,7 +21,7 @@ package jalview.ws.jws2; import jalview.bin.Cache; -import jalview.bin.Jalview; +import jalview.bin.Instance; import jalview.gui.AlignFrame; import jalview.gui.Desktop; import jalview.gui.JvSwingUtils; @@ -633,7 +633,7 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI */ public static Jws2Discoverer getDiscoverer() { - Jalview j = Jalview.getInstance(); + Instance j = Instance.getInstance(); return (j.j2s2discoverer == null ? j.j2s2discoverer = new Jws2Discoverer() : j.j2s2discoverer); diff --git a/src/jalview/ws/jws2/SequenceAnnotationWSClient.java b/src/jalview/ws/jws2/SequenceAnnotationWSClient.java index 9358c76..a9c071a 100644 --- a/src/jalview/ws/jws2/SequenceAnnotationWSClient.java +++ b/src/jalview/ws/jws2/SequenceAnnotationWSClient.java @@ -21,8 +21,8 @@ package jalview.ws.jws2; import jalview.api.AlignCalcWorkerI; +import jalview.bin.Instance; import jalview.gui.AlignFrame; -import jalview.gui.Desktop; import jalview.gui.JvSwingUtils; import jalview.util.MessageManager; import jalview.ws.jws2.dm.AAConSettings; @@ -242,7 +242,7 @@ public class SequenceAnnotationWSClient extends Jws2Client @Override public void actionPerformed(ActionEvent arg0) { - Desktop.getInstance().showUrl(service.docUrl); + Instance.getDesktop().showUrl(service.docUrl); } }); annotservice.setToolTipText( diff --git a/src/jalview/ws/jws2/jabaws2/Jws2Instance.java b/src/jalview/ws/jws2/jabaws2/Jws2Instance.java index a4e2e75..5ea646f 100644 --- a/src/jalview/ws/jws2/jabaws2/Jws2Instance.java +++ b/src/jalview/ws/jws2/jabaws2/Jws2Instance.java @@ -20,6 +20,7 @@ */ package jalview.ws.jws2.jabaws2; +import jalview.bin.Instance; import jalview.gui.AlignFrame; import jalview.gui.Desktop; import jalview.util.MessageManager; @@ -186,7 +187,7 @@ public class Jws2Instance try { paramStore = new JabaParamStore(this, - (Desktop.getInstance() != null ? Desktop.getUserParameterStore() + (Instance.getDesktop() != null ? Desktop.getUserParameterStore() : null)); } catch (Exception ex) { diff --git a/src/jalview/ws/jws2/jabaws2/Jws2InstanceFactory.java b/src/jalview/ws/jws2/jabaws2/Jws2InstanceFactory.java index 1fa9cc9..e227385 100644 --- a/src/jalview/ws/jws2/jabaws2/Jws2InstanceFactory.java +++ b/src/jalview/ws/jws2/jabaws2/Jws2InstanceFactory.java @@ -20,7 +20,7 @@ */ package jalview.ws.jws2.jabaws2; -import jalview.bin.Jalview; +import jalview.bin.Instance; import jalview.ws.jws2.AAConClient; import jalview.ws.jws2.RNAalifoldClient; import jalview.ws.uimodel.AlignAnalysisUIText; @@ -39,7 +39,7 @@ public class Jws2InstanceFactory public static Jws2InstanceFactory getInstance() { - Jalview j = Jalview.getInstance(); + Instance j = Instance.getInstance(); return (j.jws2InstanceFactory == null ? j.jws2InstanceFactory = new Jws2InstanceFactory() : j.jws2InstanceFactory); diff --git a/src/jalview/ws/rest/RestClient.java b/src/jalview/ws/rest/RestClient.java index e5dc4b4..d83ae6f 100644 --- a/src/jalview/ws/rest/RestClient.java +++ b/src/jalview/ws/rest/RestClient.java @@ -21,7 +21,7 @@ package jalview.ws.rest; import jalview.bin.Cache; -import jalview.bin.Jalview; +import jalview.bin.Instance; import jalview.datamodel.AlignmentView; import jalview.gui.AlignFrame; import jalview.gui.AlignViewport; @@ -82,7 +82,7 @@ public class RestClient extends WSClient private static RestClient getInstance() { - Jalview j = Jalview.getInstance(); + Instance j = Instance.getInstance(); return (j.restClient == null ? j.restClient = new RestClient() : j.restClient); } diff --git a/src/jalview/ws/sifts/SiftsSettings.java b/src/jalview/ws/sifts/SiftsSettings.java index 31274d9..51f1175 100644 --- a/src/jalview/ws/sifts/SiftsSettings.java +++ b/src/jalview/ws/sifts/SiftsSettings.java @@ -20,7 +20,7 @@ */ package jalview.ws.sifts; -import jalview.bin.Jalview; +import jalview.bin.Instance; import java.util.Objects; @@ -37,7 +37,7 @@ public class SiftsSettings private static SiftsSettings getInstance() { { - Jalview j = Jalview.getInstance(); + Instance j = Instance.getInstance(); return (j.siftsSettings == null ? j.siftsSettings = new SiftsSettings() : j.siftsSettings); diff --git a/test/jalview/ext/jmol/JmolViewerTest.java b/test/jalview/ext/jmol/JmolViewerTest.java index 7ef0d16..e2feb50 100644 --- a/test/jalview/ext/jmol/JmolViewerTest.java +++ b/test/jalview/ext/jmol/JmolViewerTest.java @@ -74,7 +74,7 @@ public class JmolViewerTest @AfterClass(alwaysRun = true) public static void tearDownAfterClass() throws Exception { - jalview.gui.Desktop.getInstance().closeAll_actionPerformed(null); + jalview.bin.Instance.getDesktop().closeAll_actionPerformed(null); } @Test(groups = { "Functional" }) diff --git a/test/jalview/ext/rbvi/chimera/JalviewChimeraView.java b/test/jalview/ext/rbvi/chimera/JalviewChimeraView.java index 194d34a..771ccb0 100644 --- a/test/jalview/ext/rbvi/chimera/JalviewChimeraView.java +++ b/test/jalview/ext/rbvi/chimera/JalviewChimeraView.java @@ -28,13 +28,13 @@ import static org.testng.Assert.assertTrue; import jalview.api.FeatureRenderer; import jalview.api.structures.JalviewStructureDisplayI; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.bin.Jalview; import jalview.datamodel.DBRefEntry; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; -import jalview.gui.Desktop; import jalview.gui.JvOptionPane; import jalview.gui.Preferences; import jalview.gui.StructureViewer; @@ -95,7 +95,7 @@ public class JalviewChimeraView @AfterClass(alwaysRun = true) public static void tearDownAfterClass() throws Exception { - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); } @AfterMethod(alwaysRun = true) diff --git a/test/jalview/gui/AlignFrameTest.java b/test/jalview/gui/AlignFrameTest.java index 779941b..fd690f3 100644 --- a/test/jalview/gui/AlignFrameTest.java +++ b/test/jalview/gui/AlignFrameTest.java @@ -29,6 +29,7 @@ import static org.testng.Assert.assertTrue; import jalview.api.FeatureColourI; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.bin.Jalview; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; @@ -164,7 +165,7 @@ public class AlignFrameTest @AfterMethod(alwaysRun = true) public void tearDown() { - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); } /** diff --git a/test/jalview/gui/AlignViewportTest.java b/test/jalview/gui/AlignViewportTest.java index 6252cbe..20b4988 100644 --- a/test/jalview/gui/AlignViewportTest.java +++ b/test/jalview/gui/AlignViewportTest.java @@ -28,6 +28,7 @@ import static org.testng.AssertJUnit.assertSame; import static org.testng.AssertJUnit.assertTrue; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.bin.Jalview; import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.Alignment; @@ -80,7 +81,7 @@ public class AlignViewportTest * remove any sequence mappings left lying around by other tests */ StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Desktop.getInstance()); + .getStructureSelectionManager(Instance.getDesktop()); ssm.resetAll(); } @@ -128,7 +129,7 @@ public class AlignViewportTest * mappings */ StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Desktop.getInstance()); + .getStructureSelectionManager(Instance.getDesktop()); List sequenceMappings = ssm.getSequenceMappings(); assertEquals(2, sequenceMappings.size()); assertTrue(sequenceMappings.contains(acf1)); @@ -150,10 +151,10 @@ public class AlignViewportTest @Test(groups = { "Functional" }) public void testDeregisterMapping_withNoReference() { - Desktop d = Desktop.getInstance(); + Desktop d = Instance.getDesktop(); assertNotNull(d); StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Desktop.getInstance()); + .getStructureSelectionManager(Instance.getDesktop()); ssm.resetAll(); AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded( @@ -213,10 +214,10 @@ public class AlignViewportTest @Test(groups = { "Functional" }) public void testDeregisterMapping_withReference() { - Desktop d = Desktop.getInstance(); + Desktop d = Instance.getDesktop(); assertNotNull(d); StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Desktop.getInstance()); + .getStructureSelectionManager(Instance.getDesktop()); ssm.resetAll(); AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded( diff --git a/test/jalview/gui/FreeUpMemoryTest.java b/test/jalview/gui/FreeUpMemoryTest.java index 18ff7f2..8345f81 100644 --- a/test/jalview/gui/FreeUpMemoryTest.java +++ b/test/jalview/gui/FreeUpMemoryTest.java @@ -6,6 +6,7 @@ import static org.testng.Assert.assertTrue; import jalview.analysis.AlignmentGenerator; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.bin.Jalview; import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceGroup; @@ -70,7 +71,7 @@ public class FreeUpMemoryTest doStuffInJalview(f); - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); checkUsedMemory(35L); } @@ -109,7 +110,7 @@ public class FreeUpMemoryTest * sanity check - fails if any frame was added after * closeAll_actionPerformed */ - assertEquals(Desktop.getInstance().getAllFrames().length, 0); + assertEquals(Instance.getDesktop().getAllFrames().length, 0); /* * if this assertion fails diff --git a/test/jalview/gui/SeqPanelTest.java b/test/jalview/gui/SeqPanelTest.java index 17e04bf..8067148 100644 --- a/test/jalview/gui/SeqPanelTest.java +++ b/test/jalview/gui/SeqPanelTest.java @@ -26,6 +26,7 @@ import static org.testng.Assert.assertTrue; import jalview.api.AlignViewportI; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.bin.Jalview; import jalview.commands.EditCommand; import jalview.commands.EditCommand.Action; @@ -252,7 +253,7 @@ public class SeqPanelTest @AfterMethod(alwaysRun = true) public void tearDown() { - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); } @Test(groups = "Functional") diff --git a/test/jalview/io/AnnotatedPDBFileInputTest.java b/test/jalview/io/AnnotatedPDBFileInputTest.java index beeb52f..5cc2345 100644 --- a/test/jalview/io/AnnotatedPDBFileInputTest.java +++ b/test/jalview/io/AnnotatedPDBFileInputTest.java @@ -207,7 +207,7 @@ public class AnnotatedPDBFileInputTest @AfterClass(alwaysRun = true) public static void tearDownAfterClass() throws Exception { - jalview.gui.Desktop.getInstance().closeAll_actionPerformed(null); + jalview.bin.Instance.getDesktop().closeAll_actionPerformed(null); } diff --git a/test/jalview/io/CrossRef2xmlTests.java b/test/jalview/io/CrossRef2xmlTests.java index daadfa5..0b6c83b 100644 --- a/test/jalview/io/CrossRef2xmlTests.java +++ b/test/jalview/io/CrossRef2xmlTests.java @@ -22,6 +22,7 @@ package jalview.io; import jalview.analysis.CrossRef; import jalview.api.AlignmentViewPanel; +import jalview.bin.Instance; import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentTest; @@ -135,7 +136,7 @@ public class CrossRef2xmlTests extends Jalview2xmlBase { // retrieve dbref - SequenceFetcher sf = new SequenceFetcher(Desktop.getInstance(), + SequenceFetcher sf = new SequenceFetcher(Instance.getDesktop(), forSource, forAccession); sf.run(); AlignFrame[] afs = Desktop.getAlignFrames(); @@ -162,7 +163,7 @@ public class CrossRef2xmlTests extends Jalview2xmlBase } else { - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); // recover stored project af = new FileLoader(false).LoadFileWaitTillLoaded( savedProjects.get(first).toString(), DataSourceType.FILE); @@ -229,7 +230,7 @@ public class CrossRef2xmlTests extends Jalview2xmlBase } else { - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); pass3 = 0; // recover stored project File storedProject = savedProjects.get(nextxref); @@ -340,7 +341,7 @@ public class CrossRef2xmlTests extends Jalview2xmlBase } else { - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); // recover stored project File storedProject = savedProjects.get(nextnextxref); if (storedProject == null) diff --git a/test/jalview/io/FeaturesFileTest.java b/test/jalview/io/FeaturesFileTest.java index a56a0de..483ce76 100644 --- a/test/jalview/io/FeaturesFileTest.java +++ b/test/jalview/io/FeaturesFileTest.java @@ -29,6 +29,7 @@ import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals; import jalview.api.FeatureColourI; import jalview.api.FeatureRenderer; +import jalview.bin.Instance; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceDummy; @@ -40,7 +41,6 @@ import jalview.datamodel.features.FeatureMatcherSet; import jalview.datamodel.features.FeatureMatcherSetI; import jalview.datamodel.features.SequenceFeatures; import jalview.gui.AlignFrame; -import jalview.gui.Desktop; import jalview.gui.JvOptionPane; import jalview.schemes.FeatureColour; import jalview.structure.StructureSelectionManager; @@ -71,7 +71,7 @@ public class FeaturesFileTest * remove any sequence mappings created so they don't pollute other tests */ StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Desktop.getInstance()); + .getStructureSelectionManager(Instance.getDesktop()); ssm.resetAll(); } diff --git a/test/jalview/io/Jalview2xmlBase.java b/test/jalview/io/Jalview2xmlBase.java index 3a0560c..38481e5 100644 --- a/test/jalview/io/Jalview2xmlBase.java +++ b/test/jalview/io/Jalview2xmlBase.java @@ -21,6 +21,7 @@ package jalview.io; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.bin.Jalview; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.SequenceI; @@ -70,16 +71,16 @@ public class Jalview2xmlBase @AfterClass(alwaysRun = true) public static void tearDownAfterClass() throws Exception { - jalview.gui.Desktop.getInstance().closeAll_actionPerformed(null); + jalview.bin.Instance.getDesktop().closeAll_actionPerformed(null); } @BeforeTest(alwaysRun = true) public static void clearDesktop() { - if (Desktop.getInstance() != null && Desktop.getFrames() != null + if (Instance.getDesktop() != null && Desktop.getFrames() != null && Desktop.getFrames().length > 0) { - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); } } diff --git a/test/jalview/io/JalviewExportPropertiesTests.java b/test/jalview/io/JalviewExportPropertiesTests.java index 1614453..0eaa36a 100644 --- a/test/jalview/io/JalviewExportPropertiesTests.java +++ b/test/jalview/io/JalviewExportPropertiesTests.java @@ -63,7 +63,7 @@ public class JalviewExportPropertiesTests @AfterClass(alwaysRun = true) public static void tearDownAfterClass() throws Exception { - jalview.gui.Desktop.getInstance().closeAll_actionPerformed(null); + jalview.bin.Instance.getDesktop().closeAll_actionPerformed(null); } diff --git a/test/jalview/project/Jalview2xmlTests.java b/test/jalview/project/Jalview2xmlTests.java index 830a759..9e2f7de 100644 --- a/test/jalview/project/Jalview2xmlTests.java +++ b/test/jalview/project/Jalview2xmlTests.java @@ -32,6 +32,7 @@ import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.api.FeatureColourI; import jalview.api.ViewStyleI; +import jalview.bin.Instance; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenSequences; @@ -405,7 +406,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }, enabled = true) public void testStoreAndRecoverExpandedviews() throws Exception { - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/exampleFile_2_7.jar", DataSourceType.FILE); @@ -433,7 +434,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase { Assert.fail("Didn't save the expanded view state", e); } - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); if (Desktop.getAlignFrames() != null) { Assert.assertEquals(Desktop.getAlignFrames().length, 0); @@ -459,7 +460,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }) public void testStoreAndRecoverReferenceSeqSettings() throws Exception { - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/exampleFile_2_7.jar", DataSourceType.FILE); assertNotNull(af, "Didn't read in the example file correctly."); @@ -498,7 +499,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase { Assert.fail("Didn't save the expanded view state", e); } - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); if (Desktop.getAlignFrames() != null) { Assert.assertEquals(Desktop.getAlignFrames().length, 0); @@ -592,7 +593,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }) public void testStoreAndRecoverGroupRepSeqs() throws Exception { - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/uniref50.fa", DataSourceType.FILE); assertNotNull(af, "Didn't read in the example file correctly."); @@ -667,7 +668,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase { Assert.fail("Didn't save the expanded view state", e); } - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); if (Desktop.getAlignFrames() != null) { Assert.assertEquals(Desktop.getAlignFrames().length, 0); @@ -712,7 +713,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }) public void testStoreAndRecoverPDBEntry() throws Exception { - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); String exampleFile = "examples/3W5V.pdb"; AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile, DataSourceType.FILE); @@ -761,7 +762,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase { Assert.fail("Didn't save the state", e); } - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); if (Desktop.getAlignFrames() != null) { Assert.assertEquals(Desktop.getAlignFrames().length, 0); @@ -812,7 +813,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }) public void testStoreAndRecoverColourThresholds() throws IOException { - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/uniref50.fa", DataSourceType.FILE); @@ -872,7 +873,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase ".jvp"); tfile.deleteOnExit(); new Jalview2XML(false).saveState(tfile); - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(), DataSourceType.FILE); Assert.assertNotNull(af, "Failed to reload project"); @@ -1081,7 +1082,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }) public void testMergeDatasetsforManyViews() throws IOException { - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); // complex project - one dataset, several views on several alignments AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded( @@ -1125,7 +1126,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = "Functional") public void testPcaViewAssociation() throws IOException { - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); final String PCAVIEWNAME = "With PCA"; // create a new tempfile File tempfile = File.createTempFile("jvPCAviewAssoc", "jvp"); @@ -1159,10 +1160,10 @@ public class Jalview2xmlTests extends Jalview2xmlBase } // load again. - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( tempfile.getCanonicalPath(), DataSourceType.FILE); - JInternalFrame[] frames = Desktop.getInstance().getAllFrames(); + JInternalFrame[] frames = Instance.getDesktop().getAllFrames(); // PCA and the tabbed alignment view should be the only two windows on the // desktop assertEquals(frames.length, 2, diff --git a/test/jalview/schemes/ColourSchemesTest.java b/test/jalview/schemes/ColourSchemesTest.java index 06be31e..263073d 100644 --- a/test/jalview/schemes/ColourSchemesTest.java +++ b/test/jalview/schemes/ColourSchemesTest.java @@ -7,12 +7,12 @@ import static org.testng.Assert.assertTrue; import jalview.api.AlignViewportI; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.bin.Jalview; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; -import jalview.gui.Desktop; import jalview.gui.SequenceRenderer; import jalview.io.DataSourceType; import jalview.io.FileLoader; @@ -172,7 +172,7 @@ public class ColourSchemesTest @AfterClass(alwaysRun = true) public static void tearDownAfterClass() throws Exception { - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); } @Test(groups = "Functional") diff --git a/test/jalview/structure/StructureSelectionManagerTest.java b/test/jalview/structure/StructureSelectionManagerTest.java index dab692f..40ce498 100644 --- a/test/jalview/structure/StructureSelectionManagerTest.java +++ b/test/jalview/structure/StructureSelectionManagerTest.java @@ -28,6 +28,7 @@ import static org.testng.AssertJUnit.assertTrue; import jalview.analysis.AlignmentUtils; import jalview.api.structures.JalviewStructureDisplayI; import jalview.bin.Cache; +import jalview.bin.Instance; import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; @@ -199,7 +200,7 @@ public class StructureSelectionManagerTest extends Jalview2xmlBase { // for some reason 'BeforeMethod' (which should be inherited from // Jalview2XmlBase isn't always called)... - Desktop.getInstance().closeAll_actionPerformed(null); + Instance.getDesktop().closeAll_actionPerformed(null); try { Thread.sleep(200); } catch (Exception foo) {}; -- 1.7.10.2