From: hansonr Date: Fri, 10 May 2019 18:00:33 +0000 (-0500) Subject: JAL-3253 jalview.bin.Instance streamlining X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=ad1f4306281b0894fa42394b9a68da834cf14af6;p=jalview.git JAL-3253 jalview.bin.Instance streamlining --- diff --git a/src/jalview/analysis/AlignmentSorter.java b/src/jalview/analysis/AlignmentSorter.java index 459d09d..e9eee16 100755 --- a/src/jalview/analysis/AlignmentSorter.java +++ b/src/jalview/analysis/AlignmentSorter.java @@ -57,8 +57,17 @@ public class AlignmentSorter private AlignmentSorter() { - // singleton + // private singleton } + + private static AlignmentSorter getInstance() + { + Instance j = Instance.getInstance(); + return (j.alignmentSorter == null + ? j.alignmentSorter = new AlignmentSorter() + : j.alignmentSorter); + } + /** * 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 - @@ -71,14 +80,6 @@ public class AlignmentSorter public static final String FEATURE_DENSITY = "density"; - public static AlignmentSorter getInstance() - { - Instance j = Instance.getInstance(); - return (j.alignmentSorter == null - ? j.alignmentSorter = new AlignmentSorter() - : j.alignmentSorter); - } - /* * todo: refactor searches to follow a basic pattern: (search property, last * search state, current sort direction) diff --git a/src/jalview/analysis/CrossRef.java b/src/jalview/analysis/CrossRef.java index 00bb63a..c69858f 100644 --- a/src/jalview/analysis/CrossRef.java +++ b/src/jalview/analysis/CrossRef.java @@ -31,8 +31,7 @@ import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.util.DBRefUtils; import jalview.util.MapList; -import jalview.ws.SequenceFetcherFactory; -import jalview.ws.seqfetcher.ASequenceFetcher; +import jalview.ws.SequenceFetcher; import java.util.ArrayList; import java.util.Iterator; @@ -402,7 +401,6 @@ public class CrossRef private void retrieveCrossRef(List sourceRefs, SequenceI seq, List xrfs, boolean fromDna, AlignedCodonFrame cf) { - ASequenceFetcher sftch = SequenceFetcherFactory.getSequenceFetcher(); SequenceI[] retrieved = null; SequenceI dss = seq.getDatasetSequence() == null ? seq : seq.getDatasetSequence(); @@ -418,7 +416,8 @@ public class CrossRef } try { - retrieved = sftch.getSequences(sourceRefs, !fromDna); + retrieved = SequenceFetcher.getInstance() + .getSequences(sourceRefs, !fromDna); } catch (Exception e) { System.err.println( @@ -483,7 +482,7 @@ public class CrossRef private void removeAlreadyRetrievedSeqs(List sourceRefs, boolean fromDna) { - List dbrSourceSet = new ArrayList(sourceRefs); + List dbrSourceSet = new ArrayList<>(sourceRefs); List dsSeqs = dataset.getSequences(); for (int ids = 0, nds = dsSeqs.size(); ids < nds; ids++) { diff --git a/src/jalview/analysis/scoremodels/ScoreModels.java b/src/jalview/analysis/scoremodels/ScoreModels.java index 8afc4fc..7431b86 100644 --- a/src/jalview/analysis/scoremodels/ScoreModels.java +++ b/src/jalview/analysis/scoremodels/ScoreModels.java @@ -36,12 +36,6 @@ import java.util.Map; */ public class ScoreModels { - private final ScoreMatrix BLOSUM62; - - private final ScoreMatrix PAM250; - - private final ScoreMatrix DNA; - /** * Answers the singleton instance of this class, with lazy initialisation * (built-in score models are loaded on the first call to this method) @@ -55,8 +49,6 @@ public class ScoreModels : j.scoreModels); } - private Map models; - /** * Private constructor to enforce use of singleton. Registers Jalview's * "built-in" score models: @@ -81,6 +73,14 @@ public class ScoreModels registerScoreModel(new FeatureDistanceModel()); } + private final ScoreMatrix BLOSUM62; + + private final ScoreMatrix PAM250; + + private final ScoreMatrix DNA; + + private Map models; + /** * Tries to load a score matrix from the given resource file, and if * successful, registers it. diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 642917f..fd382b3 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -210,6 +210,11 @@ import org.apache.log4j.SimpleLayout; public class Cache { + private Cache() + { + // private singleton + } + /** * In Java, this will be a static field instance, which will be * application-specific; in JavaScript it will be an applet-specific instance @@ -217,7 +222,7 @@ public class Cache * * @return */ - public static Cache getInstance() + private static Cache getInstance() { Instance i = Instance.getInstance(); return (i.cache == null ? i.cache = new Cache() : i.cache); @@ -278,11 +283,6 @@ public class Cache */ public static Logger log; - private Cache() - { - // singleton - } - /** Jalview Properties */ // BH 2019.05.08 was static @SuppressWarnings("serial") diff --git a/src/jalview/bin/Instance.java b/src/jalview/bin/Instance.java index 0afe1bd..acb6c84 100644 --- a/src/jalview/bin/Instance.java +++ b/src/jalview/bin/Instance.java @@ -28,38 +28,65 @@ 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.io.gff.SequenceOntologyFactory; import jalview.rest.RestHandler; +import jalview.schemes.ColourSchemes; 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 + * A class to hold singleton instances so that they are not shared among + * multiple JavaScript apps on a page. Fields are all formerly static class or + * object references are preserved in this singleton as "pseudo" static + * references that will be unique for each JavaScript applet or Java + * application. + * + * There are three kinds of references: + * + * Class references for classes with public getInstance() calls and a private + * constructor. + * + * Class references for classes with private getInstance() calls and a private + * constructor. + * + * Object references held here for a class as "pseudo" static field and + * referenced by Instance.getInstance().fieldName. These classes * * @author hansonr * */ -public class Instance { +public class Instance +{ + + private Instance() + { + // singleton -- use getInstance(); + } private static Instance instance; + /** + * + * Creates a static reference to this class, either as a static field (Java) + * or as an element in the applet's ThreadGroup object. + * + * @return new Instance() + */ public static Instance getInstance() { Instance i; @SuppressWarnings("unused") ThreadGroup g = Thread.currentThread().getThreadGroup(); /** - * @j2sNative i = g._instance; + * @j2sNative i = g._jalviewInstance; */ { i = instance; @@ -68,83 +95,70 @@ public class Instance { { i = instance = new Instance(); /** - * @j2sNative g._instance = i; + * @j2sNative g._jalviewInstance = 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); - } + // The following are PUBLIC singletons; their class has a private constructor + // that is assigned by the class as part of a public static getInstance() + // call. - public static void setDesktop(Desktop d) - { - getInstance().desktop = d; - } + public ColourSchemes colourSchemes; - public Cache cache; + public Discoverer discoverer; - public AlignmentSorter alignmentSorter; + public HttpServer httpServer; - public Color[] rnaHelices = null; + public RestClient restClient; - public Discoverer discoverer; + public RestHandler restHandler; - public EnsemblInfo ensemblInfo; + public ScoreModels scoreModels; - public HttpServer httpServer; + public jalview.ws.SequenceFetcher sequenceFetcher; - public IdOrgSettings idOrgSettings; + public SiftsSettings siftsSettings; - public Jws2Discoverer j2s2discoverer; - public Jws2InstanceFactory jws2InstanceFactory; + // The following are PRIVATE singletons; their class has only static public + // methods and a private constructor that is assigned by the class as part of + // a private static getInstance() call. - public PDBFTSRestClient pdbFTSRestClient; + public AlignmentSorter alignmentSorter; - public RestClient restClient; + public Cache cache; - public RestHandler restHandler; + public EnsemblInfo ensemblInfo; - public ScoreModels scoreModels; + public IdOrgSettings idOrgSettings; - public SequenceFetcher sequenceFetcher; + public Jws2Discoverer j2s2discoverer; - public SequenceOntologyI sequenceOntology; + public Jws2InstanceFactory jws2InstanceFactory; - public SiftsSettings siftsSettings; + public PDBFTSRestClient pdbFTSRestClient; + + public SequenceOntologyFactory sequenceOntologyFactory; public StructureImportSettings structureImportSettings; public UniProtFTSRestClient uniprotFTSRestClient; + // The following formerly static Object references are + // preserved in this singleton as "pseudo" static references + // that will be unique for each JavaScript applet or Java application. + + /** + * StructureSelectionManager "static" + */ public IdentityHashMap structureSelections; } diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 8af6363..4167753 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -88,9 +88,15 @@ import groovy.util.GroovyScriptEngine; public class Jalview { + public static Jalview getInstance() + { + Instance i = Instance.getInstance(); + return (i.jalview == null ? i.jalview = new Jalview() : i.jalview); + } + public Jalview() { - Instance.setJalview(this); + Instance.getInstance().jalview = this; } static @@ -102,7 +108,7 @@ public class Jalview public static boolean isHeadlessMode() { - return Instance.getJalview().headless; + return getInstance().headless; } private Desktop desktop; @@ -111,12 +117,12 @@ public class Jalview public static AlignFrame getCurrentAlignFrame() { - return Instance.getJalview().currentAlignFrame; + return getInstance().currentAlignFrame; } public static void setCurrentAlignFrame(AlignFrame currentAlignFrame) { - Instance.getJalview().currentAlignFrame = currentAlignFrame; + getInstance().currentAlignFrame = currentAlignFrame; } static @@ -312,7 +318,7 @@ public class Jalview { try { - Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl); + Jws2Discoverer.getInstance().setPreferredUrl(jabawsUrl); System.out.println( "CMD [-jabaws " + jabawsUrl + "] executed successfully!"); } catch (MalformedURLException e) @@ -1123,7 +1129,4 @@ public class Jalview } } - // 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/datamodel/features/SequenceFeatures.java b/src/jalview/datamodel/features/SequenceFeatures.java index ba8396a..9925f2b 100644 --- a/src/jalview/datamodel/features/SequenceFeatures.java +++ b/src/jalview/datamodel/features/SequenceFeatures.java @@ -373,7 +373,7 @@ public class SequenceFeatures implements SequenceFeaturesI { return true; } - SequenceOntologyI so = SequenceOntologyFactory.getInstance(); + SequenceOntologyI so = SequenceOntologyFactory.getSequenceOntology(); for (String term : soTerm) { if (type.equals(term) || so.isA(type, term)) diff --git a/src/jalview/ext/ensembl/EnsemblCds.java b/src/jalview/ext/ensembl/EnsemblCds.java index 8f13d99..bf37265 100644 --- a/src/jalview/ext/ensembl/EnsemblCds.java +++ b/src/jalview/ext/ensembl/EnsemblCds.java @@ -93,7 +93,7 @@ public class EnsemblCds extends EnsemblSeqProxy @Override protected boolean retainFeature(SequenceFeature sf, String accessionId) { - if (SequenceOntologyFactory.getInstance().isA(sf.getType(), + if (SequenceOntologyFactory.getSequenceOntology().isA(sf.getType(), SequenceOntologyI.CDS)) { return false; diff --git a/src/jalview/ext/ensembl/EnsemblGene.java b/src/jalview/ext/ensembl/EnsemblGene.java index 0d73a47..2d15f7c 100644 --- a/src/jalview/ext/ensembl/EnsemblGene.java +++ b/src/jalview/ext/ensembl/EnsemblGene.java @@ -577,7 +577,7 @@ public class EnsemblGene extends EnsemblSeqProxy @Override protected boolean retainFeature(SequenceFeature sf, String accessionId) { - SequenceOntologyI so = SequenceOntologyFactory.getInstance(); + SequenceOntologyI so = SequenceOntologyFactory.getSequenceOntology(); String type = sf.getType(); if (so.isA(type, SequenceOntologyI.GENE)) { @@ -624,7 +624,7 @@ public class EnsemblGene extends EnsemblSeqProxy { return new FeatureSettingsAdapter() { - SequenceOntologyI so = SequenceOntologyFactory.getInstance(); + SequenceOntologyI so = SequenceOntologyFactory.getSequenceOntology(); @Override public boolean isFeatureDisplayed(String type) diff --git a/src/jalview/ext/ensembl/EnsemblInfo.java b/src/jalview/ext/ensembl/EnsemblInfo.java index 1fe92f5..a91985c 100644 --- a/src/jalview/ext/ensembl/EnsemblInfo.java +++ b/src/jalview/ext/ensembl/EnsemblInfo.java @@ -30,25 +30,9 @@ public class EnsemblInfo extends EnsemblRestClient : j.ensemblInfo); } - /* - * cached results of REST /info/divisions service, currently - *
-   * { 
-   *  { "ENSEMBLFUNGI", "http://rest.ensemblgenomes.org"},
-   *    "ENSEMBLBACTERIA", "http://rest.ensemblgenomes.org"},
-   *    "ENSEMBLPROTISTS", "http://rest.ensemblgenomes.org"},
-   *    "ENSEMBLMETAZOA", "http://rest.ensemblgenomes.org"},
-   *    "ENSEMBLPLANTS",  "http://rest.ensemblgenomes.org"},
-   *    "ENSEMBL", "http://rest.ensembl.org" }
-   *  }
-   * 
- * The values for EnsemblGenomes are retrieved by a REST call, that for - * Ensembl is added programmatically for convenience of lookup - */ - private Map divisions = new HashMap<>(); - private EnsemblInfo() { + // use getInstance() /* * for convenience, pre-fill ensembl.org as the domain for "ENSEMBL" @@ -75,6 +59,23 @@ public class EnsemblInfo extends EnsemblRestClient } } + /* + * cached results of REST /info/divisions service, currently + *
+   * { 
+   *  { "ENSEMBLFUNGI", "http://rest.ensemblgenomes.org"},
+   *    "ENSEMBLBACTERIA", "http://rest.ensemblgenomes.org"},
+   *    "ENSEMBLPROTISTS", "http://rest.ensemblgenomes.org"},
+   *    "ENSEMBLMETAZOA", "http://rest.ensemblgenomes.org"},
+   *    "ENSEMBLPLANTS",  "http://rest.ensemblgenomes.org"},
+   *    "ENSEMBL", "http://rest.ensembl.org" }
+   *  }
+   * 
+ * The values for EnsemblGenomes are retrieved by a REST call, that for + * Ensembl is added programmatically for convenience of lookup + */ + private Map divisions = new HashMap<>(); + @Override public String getDbName() { diff --git a/src/jalview/ext/ensembl/EnsemblSeqProxy.java b/src/jalview/ext/ensembl/EnsemblSeqProxy.java index 49e6341..bdaef0b 100644 --- a/src/jalview/ext/ensembl/EnsemblSeqProxy.java +++ b/src/jalview/ext/ensembl/EnsemblSeqProxy.java @@ -740,7 +740,7 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient * for sequence_variant on reverse strand, have to convert the allele * values to their complements */ - if (!forwardStrand && SequenceOntologyFactory.getInstance() + if (!forwardStrand && SequenceOntologyFactory.getSequenceOntology() .isA(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT)) { reverseComplementAlleles(copy); @@ -988,7 +988,7 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient public static boolean isTranscript(String featureType) { return SequenceOntologyI.NMD_TRANSCRIPT_VARIANT.equals(featureType) - || SequenceOntologyFactory.getInstance().isA(featureType, + || SequenceOntologyFactory.getSequenceOntology().isA(featureType, SequenceOntologyI.TRANSCRIPT); } } diff --git a/src/jalview/ext/so/SequenceOntology.java b/src/jalview/ext/so/SequenceOntology.java index 0d631e6..5a86fa1 100644 --- a/src/jalview/ext/so/SequenceOntology.java +++ b/src/jalview/ext/so/SequenceOntology.java @@ -82,10 +82,10 @@ public class SequenceOntology implements SequenceOntologyI */ public SequenceOntology() { - termsFound = new ArrayList(); - termsNotFound = new ArrayList(); - termsByDescription = new HashMap(); - termIsA = new HashMap>(); + termsFound = new ArrayList<>(); + termsNotFound = new ArrayList<>(); + termsByDescription = new HashMap<>(); + termIsA = new HashMap<>(); loadOntologyZipFile("so-xp-simple.obo"); } @@ -404,7 +404,7 @@ public class SequenceOntology implements SequenceOntologyI */ protected synchronized void findParents(Term childTerm) { - List result = new ArrayList(); + List result = new ArrayList<>(); for (Triple triple : ontology.getTriples(childTerm, null, isA)) { Term parent = triple.getObject(); diff --git a/src/jalview/fts/service/pdb/PDBFTSRestClient.java b/src/jalview/fts/service/pdb/PDBFTSRestClient.java index 8e929e7..340830e 100644 --- a/src/jalview/fts/service/pdb/PDBFTSRestClient.java +++ b/src/jalview/fts/service/pdb/PDBFTSRestClient.java @@ -69,7 +69,7 @@ public class PDBFTSRestClient extends FTSRestClient private PDBFTSRestClient() { - // singleton + // singleton -- use getInstance() } /** diff --git a/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java b/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java index 455ea98..871ba19 100644 --- a/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java +++ b/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java @@ -46,12 +46,6 @@ import com.sun.jersey.api.client.config.DefaultClientConfig; public class UniProtFTSRestClient extends FTSRestClient { - private static final String DEFAULT_UNIPROT_DOMAIN = "https://www.uniprot.org"; - - static - { - Platform.addJ2SDirectDatabaseCall(DEFAULT_UNIPROT_DOMAIN); - } public static FTSRestClientI getInstance() { @@ -60,14 +54,22 @@ public class UniProtFTSRestClient extends FTSRestClient : j.uniprotFTSRestClient); } - public final String uniprotSearchEndpoint; - private UniProtFTSRestClient() { + // singleton -- use getInstance() + uniprotSearchEndpoint = Cache.getDefault("UNIPROT_DOMAIN", DEFAULT_UNIPROT_DOMAIN) + "/uniprot/"; } + private static final String DEFAULT_UNIPROT_DOMAIN = "https://www.uniprot.org"; + + public final String uniprotSearchEndpoint; + + static + { + Platform.addJ2SDirectDatabaseCall(DEFAULT_UNIPROT_DOMAIN); + } @SuppressWarnings("unchecked") @Override public FTSRestResponse executeRequest(FTSRestRequest uniprotRestRequest) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 2d7c11b..343dfbe 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -37,7 +37,6 @@ 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; @@ -816,7 +815,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, private void addServiceListeners() { final java.beans.PropertyChangeListener thisListener; - Instance.getDesktop().addJalviewPropertyChangeListener("services", + Desktop.getInstance().addJalviewPropertyChangeListener("services", thisListener = new java.beans.PropertyChangeListener() { @Override @@ -847,7 +846,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, javax.swing.event.InternalFrameEvent evt) { // System.out.println("deregistering discoverer listener"); - Instance.getDesktop().removeJalviewPropertyChangeListener("services", + Desktop.getInstance().removeJalviewPropertyChangeListener("services", thisListener); closeMenuItem_actionPerformed(true); } @@ -1028,7 +1027,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void addFromFile_actionPerformed(ActionEvent e) { - Instance.getDesktop().inputLocalFileMenuItem_actionPerformed(viewport); + Desktop.getInstance().inputLocalFileMenuItem_actionPerformed(viewport); } @Override @@ -1052,14 +1051,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, try { frames[i].setSelected(true); - Instance.getDesktop().closeAssociatedWindows(); + Desktop.getInstance().closeAssociatedWindows(); } catch (java.beans.PropertyVetoException ex) { } } } - Instance.getDesktop().closeAssociatedWindows(); + Desktop.getInstance().closeAssociatedWindows(); FileLoader loader = new FileLoader(); DataSourceType protocol = fileName.startsWith("http:") @@ -1117,14 +1116,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void addFromText_actionPerformed(ActionEvent e) { - Instance.getDesktop() + Desktop.getInstance() .inputTextboxMenuItem_actionPerformed(viewport.getAlignPanel()); } @Override public void addFromURL_actionPerformed(ActionEvent e) { - Instance.getDesktop().inputURLMenuItem_actionPerformed(viewport); + Desktop.getInstance().inputURLMenuItem_actionPerformed(viewport); } @Override @@ -1931,7 +1930,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, StringSelection ss = new StringSelection(output); - Desktop d = Instance.getDesktop(); + Desktop d = Desktop.getInstance(); try { d.internalCopy = true; @@ -1941,7 +1940,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, .setContents(new StringSelection(""), null); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, - Instance.getDesktop()); + Desktop.getInstance()); } catch (OutOfMemoryError er) { new OOMWarning("copying region", er); @@ -2033,7 +2032,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, boolean annotationAdded = false; AlignmentI alignment = null; - Desktop d = Instance.getDesktop(); + Desktop d = Desktop.getInstance(); if (d.jalviewClipboard != null) { @@ -2342,7 +2341,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, DEFAULT_HEIGHT); String newtitle = new String("Flanking alignment"); - Desktop d = Instance.getDesktop(); + Desktop d = Desktop.getInstance(); if (d.jalviewClipboard != null && d.jalviewClipboard[2] != null) { @@ -2917,7 +2916,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void gatherViews_actionPerformed(ActionEvent e) { - Instance.getDesktop().gatherViews(this); + Desktop.getInstance().gatherViews(this); } /** @@ -4218,7 +4217,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // boolean new_sspred = false; if (Cache.getDefault("SHOW_JWS2_SERVICES", true)) { - Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer(); + Jws2Discoverer jws2servs = Jws2Discoverer.getInstance(); if (jws2servs != null) { if (jws2servs.hasServices()) @@ -4628,10 +4627,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // associating PDB files which have no IDs. for (SequenceI toassoc : (SequenceI[]) fm[2]) { - PDBEntry pe = new AssociatePdbFileWithSeq() + PDBEntry pe = AssociatePdbFileWithSeq .associatePdbWithSeq(fm[0].toString(), - (DataSourceType) fm[1], toassoc, false, - Instance.getDesktop()); + (DataSourceType) fm[1], toassoc, false); if (pe != null) { System.err.println("Associated file : " @@ -5065,14 +5063,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void run() { - final jalview.ws.SequenceFetcher sf = jalview.gui.SequenceFetcher - .getSequenceFetcherSingleton(); javax.swing.SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - String[] dbclasses = sf.getNonAlignmentSources(); + String[] dbclasses = jalview.ws.SequenceFetcher.getInstance() + .getNonAlignmentSources(); List otherdb; JMenu dfetch = new JMenu(); JMenu ifetch = new JMenu(); @@ -5082,7 +5079,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, int dbi = 0; for (String dbclass : dbclasses) { - otherdb = sf.getSourceProxy(dbclass); + otherdb = jalview.ws.SequenceFetcher.getInstance() + .getSourceProxy(dbclass); // add a single entry for this class, or submenu allowing 'fetch // all' or pick one if (otherdb == null || otherdb.size() < 1) diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index ff3285c..ec940b6 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -29,7 +29,6 @@ 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,9 +383,8 @@ public class AlignViewport extends AlignmentViewport */ if (align != null) { - StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Instance.getDesktop()); - ssm.registerMappings(align.getCodonFrames()); + Desktop.getStructureSelectionManager() + .registerMappings(align.getCodonFrames()); } /* @@ -406,8 +404,8 @@ public class AlignViewport extends AlignmentViewport List mappings = al.getCodonFrames(); if (mappings != null) { - StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Instance.getDesktop()); + StructureSelectionManager ssm = Desktop + .getStructureSelectionManager(); for (AlignedCodonFrame acf : mappings) { if (noReferencesTo(acf)) @@ -532,12 +530,10 @@ public class AlignViewport extends AlignmentViewport @Override public void sendSelection() { - jalview.structure.StructureSelectionManager - .getStructureSelectionManager(Instance.getDesktop()) - .sendSelection(new SequenceGroup(getSelectionGroup()), - new ColumnSelection(getColumnSelection()), - new HiddenColumns(getAlignment().getHiddenColumns()), - this); + Desktop.getStructureSelectionManager().sendSelection( + new SequenceGroup(getSelectionGroup()), + new ColumnSelection(getColumnSelection()), + new HiddenColumns(getAlignment().getHiddenColumns()), this); } /** @@ -578,8 +574,7 @@ public class AlignViewport extends AlignmentViewport @Override public StructureSelectionManager getStructureSelectionManager() { - return StructureSelectionManager - .getStructureSelectionManager(Instance.getDesktop()); + return Desktop.getStructureSelectionManager(); } @Override diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 964ffa3..72d75b8 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -22,7 +22,6 @@ 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; @@ -972,7 +971,7 @@ public class AnnotationLabels extends JPanel seqs, omitHidden, alignmentStartEnd); Toolkit.getDefaultToolkit().getSystemClipboard() - .setContents(new StringSelection(output), Instance.getDesktop()); + .setContents(new StringSelection(output), Desktop.getInstance()); HiddenColumns hiddenColumns = null; @@ -982,7 +981,7 @@ public class AnnotationLabels extends JPanel av.getAlignment().getHiddenColumns()); } - Instance.getDesktop().jalviewClipboard = new Object[] { seqs, ds, // what is + Desktop.getInstance().jalviewClipboard = new Object[] { seqs, ds, // what is // the // dataset // of a consensus diff --git a/src/jalview/gui/AssociatePdbFileWithSeq.java b/src/jalview/gui/AssociatePdbFileWithSeq.java index 154582f..08a6802 100644 --- a/src/jalview/gui/AssociatePdbFileWithSeq.java +++ b/src/jalview/gui/AssociatePdbFileWithSeq.java @@ -20,18 +20,15 @@ */ package jalview.gui; -import jalview.api.StructureSelectionManagerProvider; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.io.DataSourceType; import jalview.io.StructureFile; -import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; -import javax.swing.JOptionPane; - /** - * GUI related routines for associating PDB files with sequences + * GUI related routines for associating PDB files with sequences. A single + * static method. * * @author JimP * @@ -39,58 +36,55 @@ import javax.swing.JOptionPane; public class AssociatePdbFileWithSeq { + private AssociatePdbFileWithSeq() + { + // inaccessible + } + /** - * assocate the given PDB file with + * Associate the given PDB file name or URL with a sequence. Do not map + * mouse-over events. * - * @param choice + * @param fileName + * or URL + * @param type + * will be DataType.FILE or DataType.URL * @param sequence + * to associate + * @param prompt + * true if the user should be asked what to do if the specified file + * does not seem to contain PDB information (StructureChooser only) + * @return null if file is not found */ - public PDBEntry associatePdbWithSeq(String choice, DataSourceType file, - SequenceI sequence, boolean prompt, - StructureSelectionManagerProvider ssmp) + public static PDBEntry associatePdbWithSeq(String fileName, + DataSourceType type, SequenceI sequence, boolean prompt) { PDBEntry entry = new PDBEntry(); StructureFile pdbfile = null; - pdbfile = StructureSelectionManager.getStructureSelectionManager(ssmp) - .setMapping(false, new SequenceI[] - { sequence }, null, choice, file); + pdbfile = Desktop.getStructureSelectionManager().setMapping(false, + new SequenceI[] + { sequence }, null, fileName, type); if (pdbfile == null) { // stacktrace already thrown so just return return null; } - if (pdbfile.getId() == null) - { - String reply = null; - - if (prompt) - { - reply = JvOptionPane.showInternalInputDialog(Desktop.getDesktopPane(), - MessageManager - .getString("label.couldnt_find_pdb_id_in_file"), - MessageManager.getString("label.no_pdb_id_in_file"), - JvOptionPane.QUESTION_MESSAGE); - } - if (reply == null) - { - return null; - } - - entry.setId(reply); - } - else + String id = pdbfile.getId(); + if (id == null && (id = (prompt + ? JvOptionPane.showInternalInputDialog(Desktop.getDesktopPane(), + MessageManager + .getString("label.couldnt_find_pdb_id_in_file"), + MessageManager.getString("label.no_pdb_id_in_file"), + JvOptionPane.QUESTION_MESSAGE) + : null)) == null) { - entry.setId(pdbfile.getId()); + return null; } + entry.setId(id); entry.setType(PDBEntry.Type.FILE); - - if (pdbfile != null) - { - entry.setFile(choice); - sequence.getDatasetSequence().addPDBId(entry); - StructureSelectionManager.getStructureSelectionManager(ssmp) - .registerPDBEntry(entry); - } + entry.setFile(fileName); + sequence.getDatasetSequence().addPDBId(entry); + Desktop.getStructureSelectionManager().registerPDBEntry(entry); return entry; } } diff --git a/src/jalview/gui/CrossRefAction.java b/src/jalview/gui/CrossRefAction.java index 7570858..3f3c298 100644 --- a/src/jalview/gui/CrossRefAction.java +++ b/src/jalview/gui/CrossRefAction.java @@ -25,7 +25,6 @@ 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; @@ -35,7 +34,6 @@ import jalview.datamodel.SequenceI; import jalview.ext.ensembl.EnsemblInfo; import jalview.ext.ensembl.EnsemblMap; import jalview.io.gff.SequenceOntologyI; -import jalview.structure.StructureSelectionManager; import jalview.util.DBRefUtils; import jalview.util.MapList; import jalview.util.MappingUtils; @@ -109,7 +107,8 @@ public class CrossRefAction implements Runnable /* * get display scheme (if any) to apply to features */ - FeatureSettingsModelI featureColourScheme = new SequenceFetcher() + FeatureSettingsModelI featureColourScheme = SequenceFetcher + .getInstance() .getFeatureColourScheme(source); AlignmentI xrefsAlignment = makeCrossReferencesAlignment(dataset, @@ -437,14 +436,12 @@ public class CrossRefAction implements Runnable copyAlignment .setGapCharacter(alignFrame.viewport.getGapCharacter()); - StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Instance.getDesktop()); - /* * register any new mappings for sequence mouseover etc * (will not duplicate any previously registered mappings) */ - ssm.registerMappings(dataset.getCodonFrames()); + Desktop.getStructureSelectionManager() + .registerMappings(dataset.getCodonFrames()); if (copyAlignment.getHeight() <= 0) { diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index c835248..826a869 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -139,6 +139,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements DropTargetListener, ClipboardOwner, IProgressIndicator, jalview.api.StructureSelectionManagerProvider { + private final static int DEFAULT_MIN_WIDTH = 300; private final static int DEFAULT_MIN_HEIGHT = 250; @@ -195,7 +196,13 @@ public class Desktop extends jalview.jbgui.GDesktop public static MyDesktopPane getDesktopPane() { - return Instance.getDesktop().desktopPane; + return Desktop.getInstance().desktopPane; + } + + public static StructureSelectionManager getStructureSelectionManager() + { + return StructureSelectionManager + .getStructureSelectionManager(Desktop.getInstance()); } static int openFrameCount = 0; @@ -344,6 +351,18 @@ public class Desktop extends jalview.jbgui.GDesktop public MyDesktopPane desktopPane; + public static Desktop getInstance() + { + Instance i = Instance.getInstance(); + return (i.desktop == null ? (i.desktop = new Desktop(true)) + : i.desktop); + } + + /** + * For testing. + * + * @param forInstance + */ public Desktop(boolean forInstance) { instanceOnly = true; @@ -358,7 +377,8 @@ public class Desktop extends jalview.jbgui.GDesktop * block are spawned off as threads rather than waited for during this * constructor. */ - Instance.setDesktop(this); + Instance.getInstance().desktop = this; + if (!Platform.isJS()) { doVamsasClientCheck(); @@ -538,8 +558,7 @@ public class Desktop extends jalview.jbgui.GDesktop public void doConfigureStructurePrefs() { // configure services - StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(this); + StructureSelectionManager ssm = getStructureSelectionManager(); if (jalview.bin.Cache.getDefault(Preferences.ADD_SS_ANN, true)) { ssm.setAddTempFacAnnot(jalview.bin.Cache @@ -866,7 +885,7 @@ public class Desktop extends jalview.jbgui.GDesktop // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN // IF JALVIEW IS RUNNING HEADLESS // /////////////////////////////////////////////// - if (Instance.getDesktop().instanceOnly || Jalview.isHeadlessMode()) + if (Desktop.getInstance().instanceOnly || Jalview.isHeadlessMode()) { return; } @@ -944,7 +963,7 @@ public class Desktop extends jalview.jbgui.GDesktop { menuItem.removeActionListener(menuItem.getActionListeners()[0]); } - Instance.getDesktop().windowMenu.remove(menuItem); + Desktop.getInstance().windowMenu.remove(menuItem); }; }); @@ -968,7 +987,7 @@ public class Desktop extends jalview.jbgui.GDesktop getDesktopPane().add(frame); - Instance.getDesktop().windowMenu.add(menuItem); + Desktop.getInstance().windowMenu.add(menuItem); frame.toFront(); try @@ -1025,7 +1044,7 @@ public class Desktop extends jalview.jbgui.GDesktop { if (!internalCopy) { - Instance.getDesktop().jalviewClipboard = null; + Desktop.getInstance().jalviewClipboard = null; } internalCopy = false; @@ -1504,12 +1523,7 @@ public class Desktop extends jalview.jbgui.GDesktop * reset state of singleton objects as appropriate (clear down session state * when all windows are closed) */ - StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(this); - if (ssm != null) - { - ssm.resetAll(); - } + getStructureSelectionManager().resetAll(); } @Override @@ -3013,7 +3027,7 @@ public class Desktop extends jalview.jbgui.GDesktop if (Cache.getDefault("SHOW_JWS2_SERVICES", true)) { - t2 = jalview.ws.jws2.Jws2Discoverer.getDiscoverer() + t2 = jalview.ws.jws2.Jws2Discoverer.getInstance() .startDiscoverer(changeSupport); } Thread t3 = null; @@ -3046,7 +3060,7 @@ public class Desktop extends jalview.jbgui.GDesktop { if (evt.getNewValue() == null || evt.getNewValue() instanceof Vector) { - final String ermsg = jalview.ws.jws2.Jws2Discoverer.getDiscoverer() + final String ermsg = jalview.ws.jws2.Jws2Discoverer.getInstance() .getErrorMessages(); if (ermsg != null) { @@ -3122,7 +3136,7 @@ public class Desktop extends jalview.jbgui.GDesktop */ public static void showUrl(final String url) { - showUrl(url, Instance.getDesktop()); + showUrl(url, Desktop.getInstance()); } /** @@ -3171,7 +3185,7 @@ public class Desktop extends jalview.jbgui.GDesktop public static ParamManager getUserParameterStore() { - Desktop d = Instance.getDesktop(); + Desktop d = Desktop.getInstance(); if (d.wsparamManager == null) { d.wsparamManager = new WsParamSetManager(); @@ -3463,7 +3477,7 @@ public class Desktop extends jalview.jbgui.GDesktop public static groovy.ui.Console getGroovyConsole() { - return Instance.getDesktop().groovyConsole; + return Desktop.getInstance().groovyConsole; } /** diff --git a/src/jalview/gui/JalviewDialog.java b/src/jalview/gui/JalviewDialog.java index 8ba387e..0ff5606 100644 --- a/src/jalview/gui/JalviewDialog.java +++ b/src/jalview/gui/JalviewDialog.java @@ -20,7 +20,6 @@ */ package jalview.gui; -import jalview.bin.Instance; import jalview.util.MessageManager; import java.awt.Container; @@ -79,11 +78,11 @@ public abstract class JalviewDialog extends JPanel boolean block, String title, int width, int height) { - frame = new JDialog(Instance.getDesktop(), modal); + frame = new JDialog(Desktop.getInstance(), modal); frame.setTitle(title); - if (Instance.getDesktop() != null) + if (Desktop.getInstance() != null) { - Rectangle deskr = Instance.getDesktop().getBounds(); + Rectangle deskr = Desktop.getInstance().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 d651e91..facc826 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -22,7 +22,6 @@ 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; @@ -863,7 +862,7 @@ public class Preferences extends GPreferences Integer.toString(getComboIntStringKey(backupfilesPresetsCombo))); Cache.saveProperties(); - Instance.getDesktop().doConfigureStructurePrefs(); + Desktop.getInstance().doConfigureStructurePrefs(); try { frame.setClosed(true); diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index 7b408a4..518654e 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -64,9 +64,9 @@ import javax.swing.SwingConstants; * If the selected source is Uniprot or PDB, a free text search panel is opened * instead to perform the search and selection. */ +@SuppressWarnings("serial") public class SequenceFetcher extends JPanel implements Runnable { - private static jalview.ws.SequenceFetcher sfetch = null; JLabel exampleAccession; @@ -97,20 +97,6 @@ public class SequenceFetcher extends JPanel implements Runnable volatile boolean _isConstructing = false; /** - * Returns the shared instance of the SequenceFetcher client - * - * @return - */ - public static jalview.ws.SequenceFetcher getSequenceFetcherSingleton() - { - if (sfetch == null) - { - sfetch = new jalview.ws.SequenceFetcher(); - } - return sfetch; - } - - /** * Constructor given a client to receive any status or progress messages * (currently either the Desktop, or an AlignFrame panel) * @@ -132,7 +118,7 @@ public class SequenceFetcher extends JPanel implements Runnable final String selectedDb, final String queryString) { this.progressIndicator = guiIndic; - getSequenceFetcherSingleton(); + this.guiWindow = progressIndicator; if (progressIndicator instanceof AlignFrame) @@ -164,7 +150,8 @@ public class SequenceFetcher extends JPanel implements Runnable database = new JComboBox<>(); database.setFont(JvSwingUtils.getLabelFont()); database.setPrototypeDisplayValue("ENSEMBLGENOMES "); - String[] sources = new jalview.ws.SequenceFetcher().getSupportedDb(); + String[] sources = jalview.ws.SequenceFetcher.getInstance() + .getSupportedDb(); Arrays.sort(sources, String.CASE_INSENSITIVE_ORDER); database.addItem(MessageManager.getString("action.select_ddbb")); for (String source : sources) @@ -315,7 +302,8 @@ public class SequenceFetcher extends JPanel implements Runnable { StringBuilder sb = new StringBuilder(); HashSet hs = new HashSet<>(); - for (DbSourceProxy dbs : sfetch.getSourceProxy(db)) + for (DbSourceProxy dbs : jalview.ws.SequenceFetcher.getInstance() + .getSourceProxy(db)) { String tq = dbs.getTestQuery(); if (hs.add(tq)) // not a duplicate source @@ -463,7 +451,7 @@ public class SequenceFetcher extends JPanel implements Runnable List presultTitle = new ArrayList<>(); List presult = new ArrayList<>(); List aresult = new ArrayList<>(); - List sources = sfetch + List sources = jalview.ws.SequenceFetcher.getInstance() .getSourceProxy((String) database.getSelectedItem()); Iterator proxies = sources.iterator(); String[] qries = textArea.getText().trim().split(";"); diff --git a/src/jalview/gui/SliderPanel.java b/src/jalview/gui/SliderPanel.java index 0a80292..31ad083 100755 --- a/src/jalview/gui/SliderPanel.java +++ b/src/jalview/gui/SliderPanel.java @@ -21,7 +21,6 @@ package jalview.gui; import jalview.analysis.Conservation; -import jalview.bin.Instance; import jalview.datamodel.SequenceGroup; import jalview.jbgui.GSliderPanel; import jalview.renderer.ResidueShaderI; @@ -64,10 +63,10 @@ public class SliderPanel extends GSliderPanel public static SliderPanel getSliderPanel() { - JInternalFrame conservationSlider = Instance - .getDesktop().conservationSlider; + JInternalFrame conservationSlider = Desktop + .getInstance().conservationSlider; - JInternalFrame PIDSlider = Instance.getDesktop().PIDSlider; + JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; if (conservationSlider != null && conservationSlider.isVisible()) { @@ -156,14 +155,14 @@ public class SliderPanel extends GSliderPanel { SliderPanel sliderPanel = null; - JInternalFrame conservationSlider = Instance - .getDesktop().conservationSlider; + JInternalFrame conservationSlider = Desktop + .getInstance().conservationSlider; if (conservationSlider == null) { sliderPanel = new SliderPanel(ap, rs.getConservationInc(), true, rs); - conservationSlider = Instance - .getDesktop().conservationSlider = new JInternalFrame(); + conservationSlider = Desktop + .getInstance().conservationSlider = new JInternalFrame(); conservationSlider.setContentPane(sliderPanel); conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER); } @@ -199,14 +198,14 @@ public class SliderPanel extends GSliderPanel */ public static void hidePIDSlider() { - JInternalFrame PIDSlider = Instance.getDesktop().PIDSlider; + JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; if (PIDSlider != null) { try { PIDSlider.setClosed(true); - Instance.getDesktop().PIDSlider = null; + Desktop.getInstance().PIDSlider = null; } catch (PropertyVetoException ex) { } @@ -218,15 +217,15 @@ public class SliderPanel extends GSliderPanel */ public static void hideConservationSlider() { - JInternalFrame conservationSlider = Instance - .getDesktop().conservationSlider; + JInternalFrame conservationSlider = Desktop + .getInstance().conservationSlider; if (conservationSlider != null) { try { conservationSlider.setClosed(true); - Instance.getDesktop().conservationSlider = null; + Desktop.getInstance().conservationSlider = null; } catch (PropertyVetoException ex) { } @@ -240,8 +239,8 @@ public class SliderPanel extends GSliderPanel { hidePIDSlider(); - JInternalFrame conservationSlider = Instance - .getDesktop().conservationSlider; + JInternalFrame conservationSlider = Desktop + .getInstance().conservationSlider; if (!conservationSlider.isVisible()) { @@ -253,7 +252,7 @@ public class SliderPanel extends GSliderPanel @Override public void internalFrameClosed(InternalFrameEvent e) { - Instance.getDesktop().conservationSlider = null; + Desktop.getInstance().conservationSlider = null; } }); conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER); @@ -279,12 +278,12 @@ public class SliderPanel extends GSliderPanel SliderPanel sliderPanel = null; - JInternalFrame PIDSlider = Instance.getDesktop().PIDSlider; + JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; if (PIDSlider == null) { sliderPanel = new SliderPanel(ap, threshold, false, rs); - PIDSlider = Instance.getDesktop().PIDSlider = new JInternalFrame(); + PIDSlider = Desktop.getInstance().PIDSlider = new JInternalFrame(); PIDSlider.setContentPane(sliderPanel); PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER); } @@ -322,7 +321,7 @@ public class SliderPanel extends GSliderPanel { hideConservationSlider(); - JInternalFrame PIDSlider = Instance.getDesktop().PIDSlider; + JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; if (!PIDSlider.isVisible()) { @@ -334,7 +333,7 @@ public class SliderPanel extends GSliderPanel @Override public void internalFrameClosed(InternalFrameEvent e) { - Instance.getDesktop().PIDSlider = null; + Desktop.getInstance().PIDSlider = null; } }); PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER); @@ -470,7 +469,7 @@ public class SliderPanel extends GSliderPanel public static int getConservationValue() { - return getValue(Instance.getDesktop().conservationSlider); + return getValue(Desktop.getInstance().conservationSlider); } static int getValue(JInternalFrame slider) @@ -481,7 +480,7 @@ public class SliderPanel extends GSliderPanel public static int getPIDValue() { - return getValue(Instance.getDesktop().PIDSlider); + return getValue(Desktop.getInstance().PIDSlider); } /** @@ -504,9 +503,9 @@ public class SliderPanel extends GSliderPanel public String getTitle() { String title = null; - JInternalFrame conservationSlider = Instance - .getDesktop().conservationSlider; - JInternalFrame PIDSlider = Instance.getDesktop().PIDSlider; + JInternalFrame conservationSlider = Desktop + .getInstance().conservationSlider; + JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; if (isForConservation()) { diff --git a/src/jalview/gui/SplashScreen.java b/src/jalview/gui/SplashScreen.java index 96f5c8c..98b24d1 100755 --- a/src/jalview/gui/SplashScreen.java +++ b/src/jalview/gui/SplashScreen.java @@ -20,7 +20,6 @@ */ package jalview.gui; -import jalview.bin.Instance; import jalview.util.Platform; import java.awt.BorderLayout; @@ -161,7 +160,7 @@ public class SplashScreen extends JPanel System.err.println("Error when loading images!"); } } while (!mt.checkAll()); - Instance.getDesktop().setIconImage(logo); + Desktop.getInstance().setIconImage(logo); } } catch (Exception ex) { @@ -204,7 +203,7 @@ public class SplashScreen extends JPanel @SuppressWarnings("unused") protected boolean refreshText() { - String newtext = Instance.getDesktop().getAboutMessage(true).toString(); + String newtext = Desktop.getInstance().getAboutMessage(true).toString(); // System.err.println("Text found: \n"+newtext+"\nEnd of newtext."); if (oldtext != newtext.length()) { @@ -237,8 +236,8 @@ public class SplashScreen extends JPanel authlist.setSize(new Dimension(750, 375)); add(authlist, BorderLayout.CENTER); revalidate(); - iframe.setBounds((Instance.getDesktop().getWidth() - 750) / 2, - (Instance.getDesktop().getHeight() - 375) / 2, 750, + iframe.setBounds((Desktop.getInstance().getWidth() - 750) / 2, + (Desktop.getInstance().getHeight() - 375) / 2, 750, authlist.getHeight() + iconimg.getHeight()); iframe.validate(); iframe.setVisible(true); @@ -288,7 +287,7 @@ public class SplashScreen extends JPanel } closeSplash(); - Instance.getDesktop().startDialogQueue(); + Desktop.getInstance().startDialogQueue(); } /** diff --git a/src/jalview/gui/SplitFrame.java b/src/jalview/gui/SplitFrame.java index 8d559ee..b801352 100644 --- a/src/jalview/gui/SplitFrame.java +++ b/src/jalview/gui/SplitFrame.java @@ -21,7 +21,6 @@ package jalview.gui; import jalview.api.SplitContainerI; -import jalview.bin.Instance; import jalview.datamodel.AlignmentI; import jalview.jbgui.GAlignFrame; import jalview.jbgui.GSplitFrame; @@ -133,7 +132,7 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI // allow about 65 pixels for Desktop decorators on Windows int newHeight = Math.min(height, - Instance.getDesktop().getHeight() - DESKTOP_DECORATORS_HEIGHT); + Desktop.getInstance().getHeight() - DESKTOP_DECORATORS_HEIGHT); if (newHeight != height) { int oldDividerLocation = getDividerLocation(); @@ -150,8 +149,8 @@ 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(Instance.getDesktop()); + final StructureSelectionManager ssm = Desktop + .getStructureSelectionManager(); ssm.addCommandListener(((AlignFrame) getTopFrame()).getViewport()); ssm.addCommandListener(((AlignFrame) getBottomFrame()).getViewport()); } @@ -556,8 +555,8 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI */ adjustLayout(); - final StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Instance.getDesktop()); + final StructureSelectionManager ssm = Desktop + .getStructureSelectionManager(); ssm.addCommandListener(newTopPanel.av); ssm.addCommandListener(newBottomPanel.av); } @@ -684,7 +683,7 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI */ protected void expandViews_actionPerformed() { - Instance.getDesktop().explodeViews(this); + Desktop.getInstance().explodeViews(this); } /** @@ -693,7 +692,7 @@ public class SplitFrame extends GSplitFrame implements SplitContainerI */ protected void gatherViews_actionPerformed() { - Instance.getDesktop().gatherViews(this); + Desktop.getInstance().gatherViews(this); } /** diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 61eea30..d6f3df1 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -23,7 +23,6 @@ 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; @@ -147,16 +146,16 @@ public class StructureChooser extends GStructureChooser */ protected void discoverStructureViews() { - if (Instance.getDesktop() != null) + if (Desktop.getInstance() != null) { targetView.removeAllItems(); - Desktop d = Instance.getDesktop(); + Desktop d = Desktop.getInstance(); if (d.lastTargetedView != null && !d.lastTargetedView.isVisible()) { d.lastTargetedView = null; } int linkedViewsAt = 0; - for (StructureViewerBase view : Instance.getDesktop() + for (StructureViewerBase view : Desktop.getInstance() .getStructureViewers(null, null)) { StructureViewer viewHandler = (d.lastTargetedView != null @@ -995,10 +994,9 @@ public class StructureChooser extends GStructureChooser { selectedSequence = userSelectedSeq; } - PDBEntry fileEntry = new AssociatePdbFileWithSeq() + PDBEntry fileEntry = AssociatePdbFileWithSeq .associatePdbWithSeq(selectedPdbFileName, - DataSourceType.FILE, selectedSequence, true, - Instance.getDesktop()); + DataSourceType.FILE, selectedSequence, true); sViewer = launchStructureViewer( ssm, new PDBEntry[] @@ -1154,7 +1152,7 @@ public class StructureChooser extends GStructureChooser } setProgressBar(null, progressId); // remember the last viewer we used... - Instance.getDesktop().lastTargetedView = theViewer; + Desktop.getInstance().lastTargetedView = theViewer; return theViewer; } diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index 5d6d729..af48093 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -22,7 +22,6 @@ 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; @@ -408,7 +407,7 @@ public abstract class StructureViewerBase extends GStructureViewer */ protected List getViewersFor(AlignmentPanel alp) { - return Instance.getDesktop().getStructureViewers(alp, this.getClass()); + return Desktop.getInstance().getStructureViewers(alp, this.getClass()); } @Override diff --git a/src/jalview/gui/VamsasApplication.java b/src/jalview/gui/VamsasApplication.java index f467b42..3731102 100644 --- a/src/jalview/gui/VamsasApplication.java +++ b/src/jalview/gui/VamsasApplication.java @@ -21,7 +21,6 @@ package jalview.gui; import jalview.bin.Cache; -import jalview.bin.Instance; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.HiddenColumns; @@ -670,7 +669,7 @@ public class VamsasApplication implements SelectionSource, VamsasSource if (reply == JvOptionPane.YES_OPTION) { Cache.log.debug("Prompting for vamsas store filename."); - Instance.getDesktop().vamsasSave_actionPerformed(null); + Desktop.getInstance().vamsasSave_actionPerformed(null); Cache.log .debug("Finished attempt at storing document."); } @@ -689,7 +688,7 @@ public class VamsasApplication implements SelectionSource, VamsasSource public void disableGui(boolean b) { - Instance.getDesktop().setVamsasUpdate(b); + Desktop.getInstance().setVamsasUpdate(b); } Hashtable _backup_vobj2jv; @@ -762,10 +761,10 @@ public class VamsasApplication implements SelectionSource, VamsasSource } try { - final IPickManager pm = vclient.getPickManager(); - final StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Instance.getDesktop()); - final VamsasApplication me = this; + IPickManager pm = vclient.getPickManager(); + StructureSelectionManager ssm = Desktop + .getStructureSelectionManager(); + VamsasApplication me = this; pm.registerMessageHandler(new IMessageHandler() { String last = null; diff --git a/src/jalview/gui/WsJobParameters.java b/src/jalview/gui/WsJobParameters.java index 28e7bd6..45822a3 100644 --- a/src/jalview/gui/WsJobParameters.java +++ b/src/jalview/gui/WsJobParameters.java @@ -20,7 +20,6 @@ */ package jalview.gui; -import jalview.bin.Instance; import jalview.gui.OptsAndParamsPage.OptionBox; import jalview.gui.OptsAndParamsPage.ParamBox; import jalview.util.MessageManager; @@ -216,12 +215,12 @@ public class WsJobParameters extends JPanel implements ItemListener, public boolean showRunDialog() { - frame = new JDialog(Instance.getDesktop(), true); + frame = new JDialog(Desktop.getInstance(), true); frame.setTitle(MessageManager.formatMessage("label.edit_params_for", new String[] { service.getActionText() })); - Rectangle deskr = Instance.getDesktop().getBounds(); + Rectangle deskr = Desktop.getInstance().getBounds(); Dimension pref = this.getPreferredSize(); frame.setBounds( new Rectangle((int) (deskr.getCenterX() - pref.width / 2), @@ -437,8 +436,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 = Instance.getDesktop() == null ? 540 - : Instance.getDesktop().getHeight(); + final int windowHeight = Desktop.getInstance() == null ? 540 + : Desktop.getInstance().getHeight(); setPreferredSize(new Dimension(540, windowHeight)); add(dialogpanel, BorderLayout.SOUTH); validate(); @@ -964,13 +963,13 @@ public class WsJobParameters extends JPanel implements ItemListener, public static void main(String[] args) { jalview.ws.jws2.Jws2Discoverer disc = jalview.ws.jws2.Jws2Discoverer - .getDiscoverer(); + .getInstance(); int p = 0; if (args.length > 0) { Vector services = new Vector<>(); services.addElement(args[p++]); - Jws2Discoverer.getDiscoverer().setServiceUrls(services); + Jws2Discoverer.getInstance().setServiceUrls(services); } try { diff --git a/src/jalview/gui/WsParamSetManager.java b/src/jalview/gui/WsParamSetManager.java index 33b26c9..0f315eb 100644 --- a/src/jalview/gui/WsParamSetManager.java +++ b/src/jalview/gui/WsParamSetManager.java @@ -21,7 +21,6 @@ package jalview.gui; import jalview.bin.Cache; -import jalview.bin.Instance; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; import jalview.util.MessageManager; @@ -204,7 +203,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(Instance.getDesktop()); + int value = chooser.showSaveDialog(Desktop.getInstance()); if (value == JalviewFileChooser.APPROVE_OPTION) { outfile = chooser.getSelectedFile(); @@ -312,7 +311,7 @@ public class WsParamSetManager implements ParamManager File pfile = new File(filename); if (pfile.exists() && pfile.canWrite()) { - if (JvOptionPane.showConfirmDialog(Instance.getDesktop(), + if (JvOptionPane.showConfirmDialog(Desktop.getInstance(), "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 c5b27a0..01a62e9 100644 --- a/src/jalview/gui/WsPreferences.java +++ b/src/jalview/gui/WsPreferences.java @@ -21,7 +21,6 @@ package jalview.gui; import jalview.bin.Cache; -import jalview.bin.Instance; import jalview.jbgui.GWsPreferences; import jalview.util.MessageManager; import jalview.ws.jws2.Jws2Discoverer; @@ -66,7 +65,7 @@ public class WsPreferences extends GWsPreferences private void initFromPreferences() { - wsUrls = Jws2Discoverer.getDiscoverer().getServiceUrls(); + wsUrls = Jws2Discoverer.getInstance().getServiceUrls(); if (!wsUrls.isEmpty()) { oldUrls = new Vector(wsUrls); @@ -123,7 +122,7 @@ public class WsPreferences extends GWsPreferences int r = 0; for (String url : wsUrls) { - int status = Jws2Discoverer.getDiscoverer().getServerStatusFor(url); + int status = Jws2Discoverer.getInstance().getServerStatusFor(url); tdat[r][1] = new Integer(status); tdat[r++][0] = url; } @@ -242,7 +241,7 @@ public class WsPreferences extends GWsPreferences private void updateServiceList() { - Jws2Discoverer.getDiscoverer().setServiceUrls(wsUrls); + Jws2Discoverer.getInstance().setServiceUrls(wsUrls); } private void updateRsbsServiceList() @@ -596,7 +595,7 @@ public class WsPreferences extends GWsPreferences if (lastrefresh != update) { lastrefresh = update; - Instance.getDesktop().startServiceDiscovery(true); // wait around for all + Desktop.getInstance().startServiceDiscovery(true); // wait around for all // threads to complete updateList(); @@ -617,15 +616,15 @@ public class WsPreferences extends GWsPreferences public void run() { long ct = System.currentTimeMillis(); - Instance.getDesktop().setProgressBar(MessageManager + Desktop.getInstance().setProgressBar(MessageManager .getString("status.refreshing_web_service_menus"), ct); if (lastrefresh != update) { lastrefresh = update; - Instance.getDesktop().startServiceDiscovery(true); + Desktop.getInstance().startServiceDiscovery(true); updateList(); } - Instance.getDesktop().setProgressBar(null, ct); + Desktop.getInstance().setProgressBar(null, ct); } }).start(); @@ -647,8 +646,8 @@ public class WsPreferences extends GWsPreferences @Override protected void resetWs_actionPerformed(ActionEvent e) { - Jws2Discoverer.getDiscoverer().setServiceUrls(null); - List nwsUrls = Jws2Discoverer.getDiscoverer().getServiceUrls(); + Jws2Discoverer.getInstance().setServiceUrls(null); + List nwsUrls = Jws2Discoverer.getInstance().getServiceUrls(); if (!wsUrls.equals(nwsUrls)) { update++; diff --git a/src/jalview/httpserver/HttpServer.java b/src/jalview/httpserver/HttpServer.java index 02c8380..8797f33 100644 --- a/src/jalview/httpserver/HttpServer.java +++ b/src/jalview/httpserver/HttpServer.java @@ -52,11 +52,6 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool; */ public class HttpServer { - /* - * 'context root' - actually just prefixed to the path for each handler for - * now - see registerHandler - */ - private static final String JALVIEW_PATH = "jalview"; /** * Returns the singleton instance of this class. @@ -74,6 +69,30 @@ public class HttpServer } } + /** + * Private constructor to enforce use of singleton; use getInstance(). + * + * @throws BindException + * if no free port can be assigned + */ + private HttpServer() throws BindException + { + // use getInstance() + + startServer(); + + /* + * Provides a REST server by default; add more programmatically as required + */ + registerHandler(RestHandler.getInstance()); + } + + /* + * 'context root' - actually just prefixed to the path for each handler for + * now - see registerHandler + */ + private static final String JALVIEW_PATH = "jalview"; + /* * The Http server */ @@ -95,22 +114,6 @@ public class HttpServer private URI contextRoot; /** - * Private constructor to enforce use of singleton - * - * @throws BindException - * if no free port can be assigned - */ - private HttpServer() throws BindException - { - startServer(); - - /* - * Provides a REST server by default; add more programmatically as required - */ - registerHandler(RestHandler.getInstance()); - } - - /** * Start the http server * * @throws BindException diff --git a/src/jalview/io/FileLoader.java b/src/jalview/io/FileLoader.java index d3bf4e0..9f9e956 100755 --- a/src/jalview/io/FileLoader.java +++ b/src/jalview/io/FileLoader.java @@ -25,7 +25,6 @@ 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; @@ -38,7 +37,6 @@ import jalview.gui.JvOptionPane; import jalview.json.binding.biojson.v1.ColourSchemeMapper; import jalview.project.Jalview2XML; import jalview.schemes.ColourSchemeI; -import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; import jalview.util.Platform; import jalview.ws.utils.UrlDownloadClient; @@ -279,9 +277,9 @@ public class FileLoader implements Runnable Runtime rt = Runtime.getRuntime(); try { - if (Instance.getDesktop() != null) + if (Desktop.getInstance() != null) { - Instance.getDesktop().startLoading(file); + Desktop.getInstance().startLoading(file); } if (format == null) { @@ -303,7 +301,7 @@ public class FileLoader implements Runnable if (format == null) { - Instance.getDesktop().stopLoading(); + Desktop.getInstance().stopLoading(); System.err.println("The input file \"" + file + "\" has null or unidentifiable data content!"); if (!Jalview.isHeadlessMode()) @@ -411,8 +409,7 @@ public class FileLoader implements Runnable { // register PDB entries with desktop's structure selection // manager - StructureSelectionManager - .getStructureSelectionManager(Instance.getDesktop()) + Desktop.getStructureSelectionManager() .registerPDBEntry(pdbe); } } @@ -501,9 +498,9 @@ public class FileLoader implements Runnable } else { - if (Instance.getDesktop() != null) + if (Desktop.getInstance() != null) { - Instance.getDesktop().stopLoading(); + Desktop.getInstance().stopLoading(); } final String errorMessage = MessageManager.getString( @@ -611,9 +608,9 @@ public class FileLoader implements Runnable } } // remove the visual delay indicator - if (Instance.getDesktop() != null) + if (Desktop.getInstance() != null) { - Instance.getDesktop().stopLoading(); + Desktop.getInstance().stopLoading(); } } diff --git a/src/jalview/io/VamsasAppDatastore.java b/src/jalview/io/VamsasAppDatastore.java index 3145fe9..98b5b49 100644 --- a/src/jalview/io/VamsasAppDatastore.java +++ b/src/jalview/io/VamsasAppDatastore.java @@ -21,7 +21,6 @@ package jalview.io; import jalview.bin.Cache; -import jalview.bin.Instance; import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.GraphLine; @@ -723,7 +722,7 @@ public class VamsasAppDatastore // FIND ANY ASSOCIATED TREES if (Desktop.getDesktopPane() != null) { - javax.swing.JInternalFrame[] frames = Instance.getDesktop() + javax.swing.JInternalFrame[] frames = Desktop.getInstance() .getAllFrames(); for (int t = 0; t < frames.length; t++) @@ -1479,8 +1478,7 @@ public class VamsasAppDatastore // active if (mappings != null) { - jalview.structure.StructureSelectionManager - .getStructureSelectionManager(Instance.getDesktop()) + Desktop.getStructureSelectionManager() .registerMappings(mappings); } } diff --git a/src/jalview/io/gff/Gff3Helper.java b/src/jalview/io/gff/Gff3Helper.java index a25a014..28bcf44 100644 --- a/src/jalview/io/gff/Gff3Helper.java +++ b/src/jalview/io/gff/Gff3Helper.java @@ -91,7 +91,7 @@ public class Gff3Helper extends GffHelperBase String atts = gff[ATTRIBUTES_COL]; Map> attributes = parseNameValuePairs(atts); - SequenceOntologyI so = SequenceOntologyFactory.getInstance(); + SequenceOntologyI so = SequenceOntologyFactory.getSequenceOntology(); if (so.isA(soTerm, SequenceOntologyI.PROTEIN_MATCH)) { sf = processProteinMatch(attributes, seq, gff, align, newseqs, @@ -394,7 +394,7 @@ public class Gff3Helper extends GffHelperBase desc = target.split(" ")[0]; } - SequenceOntologyI so = SequenceOntologyFactory.getInstance(); + SequenceOntologyI so = SequenceOntologyFactory.getSequenceOntology(); String type = sf.getType(); if (so.isA(type, SequenceOntologyI.SEQUENCE_VARIANT)) { diff --git a/src/jalview/io/gff/InterProScanHelper.java b/src/jalview/io/gff/InterProScanHelper.java index 948cdd2..141b677 100644 --- a/src/jalview/io/gff/InterProScanHelper.java +++ b/src/jalview/io/gff/InterProScanHelper.java @@ -108,7 +108,7 @@ public class InterProScanHelper extends Gff3Helper */ public static boolean recognises(String[] columns) { - SequenceOntologyI so = SequenceOntologyFactory.getInstance(); + SequenceOntologyI so = SequenceOntologyFactory.getSequenceOntology(); String type = columns[TYPE_COL]; if (so.isA(type, SequenceOntologyI.PROTEIN_MATCH) || (".".equals(columns[SOURCE_COL]) diff --git a/src/jalview/io/gff/SequenceOntologyFactory.java b/src/jalview/io/gff/SequenceOntologyFactory.java index 97ebf2a..258b16a 100644 --- a/src/jalview/io/gff/SequenceOntologyFactory.java +++ b/src/jalview/io/gff/SequenceOntologyFactory.java @@ -33,25 +33,37 @@ import jalview.bin.Instance; public class SequenceOntologyFactory { - private SequenceOntologyFactory() + public static synchronized SequenceOntologyI getSequenceOntology() { - // noninstantiable + SequenceOntologyFactory j = getInstance(); + return (j.sequenceOntology == null + ? j.sequenceOntology = new SequenceOntologyLite() + : j.sequenceOntology); } - // private static SequenceOntologyI instance; // moved to Jalview.instance for - // JavaScript - public static synchronized SequenceOntologyI getInstance() + /** + * For testng only + * + * @param so + */ + public static void setInstance(SequenceOntologyI so) { - Instance j = Instance.getInstance(); - if (j.sequenceOntology == null) - { - j.sequenceOntology = new SequenceOntologyLite(); - } - return j.sequenceOntology; + getInstance().sequenceOntology = so; } - public static void setInstance(SequenceOntologyI so) + private SequenceOntologyI sequenceOntology; + + private SequenceOntologyFactory() { - Instance.getInstance().sequenceOntology = so; + // private singleton } + + private static synchronized SequenceOntologyFactory getInstance() + { + Instance j = Instance.getInstance(); + return (j.sequenceOntologyFactory == null + ? j.sequenceOntologyFactory = new SequenceOntologyFactory() + : j.sequenceOntologyFactory); + } + } diff --git a/src/jalview/io/vamsas/Sequencemapping.java b/src/jalview/io/vamsas/Sequencemapping.java index 8bea620..bacf8dc 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; @@ -110,27 +110,32 @@ public class Sequencemapping extends Rangetype } } + @Override public void addToDocument() { add(mjvmapping, from, ds); } + @Override public void addFromDocument() { add((SequenceMapping) vobj); } + @Override public void conflict() { conflict(mjvmapping, (SequenceMapping) vobj); } + @Override public void updateToDoc() { update(mjvmapping, (SequenceMapping) vobj); } + @Override public void updateFromDoc() { update((SequenceMapping) vobj, (jalview.datamodel.Mapping) jvobj); @@ -364,9 +369,7 @@ public class Sequencemapping extends Rangetype acf.addMap(from, to, mapping); } bindjvvobj(mapping, sequenceMapping); - jalview.structure.StructureSelectionManager - .getStructureSelectionManager(Instance.getDesktop()) - .registerMapping(acf); + Desktop.getStructureSelectionManager().registerMapping(acf); // Try to link up any conjugate database references in the two sequences // matchConjugateDBRefs(from, to, mapping); // Try to propagate any dbrefs across this mapping. @@ -402,7 +405,7 @@ public class Sequencemapping extends Rangetype + from.getName() + " and " + to.getName()); } List fdb = from.getDBRefs(); - List tdb = new ArrayList(to.getDBRefs()); + List tdb = new ArrayList<>(to.getDBRefs()); int tdblen = to.getDBRefs().size(); // // diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index 7f550ee..e293831 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -34,7 +34,6 @@ 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; @@ -83,7 +82,6 @@ import jalview.schemes.ColourSchemeProperty; import jalview.schemes.FeatureColour; import jalview.schemes.ResidueProperties; import jalview.schemes.UserColourScheme; -import jalview.structure.StructureSelectionManager; import jalview.structures.models.AAStructureBindingModel; import jalview.util.Format; import jalview.util.MessageManager; @@ -2380,7 +2378,7 @@ public class Jalview2XML if (calcIdParam.getVersion().equals("1.0")) { final String[] calcIds = calcIdParam.getServiceURL().toArray(new String[0]); - Jws2Instance service = Jws2Discoverer.getDiscoverer() + Jws2Instance service = Jws2Discoverer.getInstance() .getPreferredServiceFor(calcIds); if (service != null) { @@ -2916,9 +2914,9 @@ public class Jalview2XML { // used to attempt to parse as V1 castor-generated xml } - if (Instance.getDesktop() != null) + if (Desktop.getInstance() != null) { - Instance.getDesktop().stopLoading(); + Desktop.getInstance().stopLoading(); } if (af != null) { @@ -2946,7 +2944,7 @@ public class Jalview2XML */ for (AlignFrame fr : gatherToThisFrame.values()) { - Instance.getDesktop().gatherViews(fr); + Desktop.getInstance().gatherViews(fr); } restoreSplitFrames(); @@ -2954,8 +2952,7 @@ public class Jalview2XML { if (ds.getCodonFrames() != null) { - StructureSelectionManager - .getStructureSelectionManager(Instance.getDesktop()) + Desktop.getStructureSelectionManager() .registerMappings(ds.getCodonFrames()); } } @@ -2964,9 +2961,9 @@ public class Jalview2XML reportErrors(); } - if (Instance.getDesktop() != null) + if (Desktop.getInstance() != null) { - Instance.getDesktop().stopLoading(); + Desktop.getInstance().stopLoading(); } return af; @@ -3047,7 +3044,7 @@ public class Jalview2XML */ for (SplitFrame sf : gatherTo) { - Instance.getDesktop().gatherViews(sf); + Desktop.getInstance().gatherViews(sf); } splitFrameCandidates.clear(); @@ -3576,9 +3573,7 @@ public class Jalview2XML { entry.setProperty(prop.getName(), prop.getValue()); } - StructureSelectionManager - .getStructureSelectionManager(Instance.getDesktop()) - .registerPDBEntry(entry); + Desktop.getStructureSelectionManager().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 bcb344f..61d75ee 100644 --- a/src/jalview/rest/RestHandler.java +++ b/src/jalview/rest/RestHandler.java @@ -31,7 +31,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** - * A simple handler to process (or delegate) HTTP requests on /jalview/rest + * A simple handler to process (or delegate) HTTP requests on /jalview/rest. + * Accessed only by HttpServer. */ public class RestHandler extends AbstractRequestHandler { diff --git a/src/jalview/schemes/AnnotationColourGradient.java b/src/jalview/schemes/AnnotationColourGradient.java index ad6947f..5461ec0 100755 --- a/src/jalview/schemes/AnnotationColourGradient.java +++ b/src/jalview/schemes/AnnotationColourGradient.java @@ -21,7 +21,6 @@ package jalview.schemes; import jalview.api.AlignViewportI; -import jalview.bin.Instance; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AnnotatedCollectionI; @@ -168,8 +167,8 @@ public class AnnotationColourGradient extends FollowerColourScheme if (annotation.isRNA()) { // reset colour palette - ColourSchemeProperty.resetRnaHelicesShading(); - ColourSchemeProperty.initRnaHelicesShading(1 + (int) aamax); + ColourSchemes.resetRnaHelicesShading(); + ColourSchemes.initRnaHelicesShading(1 + (int) aamax); } } @@ -219,7 +218,7 @@ public class AnnotationColourGradient extends FollowerColourScheme } if (rna) { - ColourSchemeProperty.initRnaHelicesShading(1 + (int) aamax); + ColourSchemes.initRnaHelicesShading(1 + (int) aamax); } } } @@ -356,7 +355,7 @@ public class AnnotationColourGradient extends FollowerColourScheme { if (ann.isRNA()) { - result = Instance.getInstance().rnaHelices[(int) aj.value]; + result = ColourSchemes.getInstance().rnaHelices[(int) aj.value]; } else { diff --git a/src/jalview/schemes/ColourSchemeProperty.java b/src/jalview/schemes/ColourSchemeProperty.java index 877f375..0123384 100755 --- a/src/jalview/schemes/ColourSchemeProperty.java +++ b/src/jalview/schemes/ColourSchemeProperty.java @@ -21,11 +21,7 @@ package jalview.schemes; import jalview.api.AlignViewportI; -import jalview.bin.Instance; import jalview.datamodel.AnnotatedCollectionI; -import jalview.util.ColorUtils; - -import java.awt.Color; /** * ColourSchemeProperty binds names to hardwired colourschemes and tries to deal @@ -42,6 +38,11 @@ import java.awt.Color; public class ColourSchemeProperty { + private ColourSchemeProperty() + { + // requires static call to getColourScheme(...). + } + /** * Returns a colour scheme for the given name, with which the given data may * be coloured. The name is not case-sensitive, and may be one of @@ -110,41 +111,6 @@ public class ColourSchemeProperty return ucs; } - public static void initRnaHelicesShading(int n) - { - int i = 0; - Instance j = Instance.getInstance(); - - if (j.rnaHelices == null) - { - j.rnaHelices = new Color[n + 1]; - } - else if (j.rnaHelices != null && j.rnaHelices.length <= n) - { - Color[] t = new Color[n + 1]; - System.arraycopy(j.rnaHelices, 0, t, 0, j.rnaHelices.length); - i = j.rnaHelices.length; - j.rnaHelices = t; - } - else - { - return; - } - // Generate random colors and store - for (; i <= n; i++) - { - j.rnaHelices[i] = ColorUtils.generateRandomColor(Color.white); - } - } - - /** - * delete the existing cached RNA helices colours - */ - public static void resetRnaHelicesShading() - { - Instance.getInstance().rnaHelices = null; - } - /** * Returns the name of the colour scheme (or "None" if it is null) * diff --git a/src/jalview/schemes/ColourSchemes.java b/src/jalview/schemes/ColourSchemes.java index 42465f2..b3f94b6 100644 --- a/src/jalview/schemes/ColourSchemes.java +++ b/src/jalview/schemes/ColourSchemes.java @@ -21,24 +21,18 @@ package jalview.schemes; import jalview.api.AlignViewportI; +import jalview.bin.Instance; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; +import jalview.util.ColorUtils; +import java.awt.Color; import java.util.LinkedHashMap; import java.util.Map; public class ColourSchemes { - /* - * singleton instance of this class - */ - private static ColourSchemes instance = new ColourSchemes(); - - /* - * a map from scheme name (lower-cased) to an instance of it - */ - private Map schemes; /** * Returns the singleton instance of this class @@ -47,7 +41,9 @@ public class ColourSchemes */ public static ColourSchemes getInstance() { - return instance; + Instance j = Instance.getInstance(); + return (j.colourSchemes == null ? j.colourSchemes = new ColourSchemes() + : j.colourSchemes); } private ColourSchemes() @@ -56,6 +52,51 @@ public class ColourSchemes } /** + * ColourSchemeProperty "static" + */ + public Color[] rnaHelices = null; + + /** + * delete the existing cached RNA helices colours + */ + public static void resetRnaHelicesShading() + { + getInstance().rnaHelices = null; + } + + public static void initRnaHelicesShading(int n) + { + int i = 0; + ColourSchemes j = getInstance(); + + if (j.rnaHelices == null) + { + j.rnaHelices = new Color[n + 1]; + } + else if (j.rnaHelices != null && j.rnaHelices.length <= n) + { + Color[] t = new Color[n + 1]; + System.arraycopy(j.rnaHelices, 0, t, 0, j.rnaHelices.length); + i = j.rnaHelices.length; + j.rnaHelices = t; + } + else + { + return; + } + // Generate random colors and store + for (; i <= n; i++) + { + j.rnaHelices[i] = ColorUtils.generateRandomColor(Color.white); + } + } + + /** + * a map from scheme name (lower-cased) to an instance of it + */ + private Map schemes; + + /** * Loads an instance of each standard or user-defined colour scheme * * @return diff --git a/src/jalview/schemes/RNAHelicesColour.java b/src/jalview/schemes/RNAHelicesColour.java index c82cd57..c61eeed 100644 --- a/src/jalview/schemes/RNAHelicesColour.java +++ b/src/jalview/schemes/RNAHelicesColour.java @@ -21,7 +21,6 @@ package jalview.schemes; import jalview.api.AlignViewportI; -import jalview.bin.Instance; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AnnotatedCollectionI; @@ -71,14 +70,14 @@ public class RNAHelicesColour extends ResidueColourScheme { super(ResidueProperties.nucleotideIndex); this.annotation = annotation; - ColourSchemeProperty.resetRnaHelicesShading(); + ColourSchemes.resetRnaHelicesShading(); refresh(); } public RNAHelicesColour(AnnotatedCollectionI alignment) { super(ResidueProperties.nucleotideIndex); - ColourSchemeProperty.resetRnaHelicesShading(); + ColourSchemes.resetRnaHelicesShading(); alignmentChanged(alignment, null); } @@ -161,7 +160,7 @@ public class RNAHelicesColour extends ResidueColourScheme } } - ColourSchemeProperty.initRnaHelicesShading(numHelix); + ColourSchemes.initRnaHelicesShading(numHelix); } } @@ -201,7 +200,7 @@ public class RNAHelicesColour extends ResidueColourScheme currentHelix = positionsToHelix.get(j); if (currentHelix != null) { - currentColour = Instance.getInstance().rnaHelices[Integer + currentColour = ColourSchemes.getInstance().rnaHelices[Integer .parseInt(currentHelix)]; } return currentColour; diff --git a/src/jalview/structure/StructureImportSettings.java b/src/jalview/structure/StructureImportSettings.java index c439914..c28f9df 100644 --- a/src/jalview/structure/StructureImportSettings.java +++ b/src/jalview/structure/StructureImportSettings.java @@ -36,7 +36,7 @@ public class StructureImportSettings private StructureImportSettings() { - // singleton + // private singleton } private static StructureImportSettings getInstance() diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index f0665de..e890dce 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -64,6 +64,50 @@ import mc_view.PDBfile; public class StructureSelectionManager { + 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); + } + } + public StructureSelectionManager() { } @@ -271,6 +315,8 @@ public class StructureSelectionManager * Import structure data and register a structure mapping for broadcasting * colouring, mouseovers and selection events (convenience wrapper). * + * This is the standard entry point. + * * @param sequence * - one or more sequences to be mapped to pdbFile * @param targetChains @@ -295,8 +341,11 @@ public class StructureSelectionManager * broadcasting colouring, mouseovers and selection events (convenience * wrapper). * + * + * * @param forStructureView - * when true, record the mapping for use in mouseOvers + * when true (testng only), record the mapping for use in mouseOvers + * (testng only) * @param sequence * - one or more sequences to be mapped to pdbFile * @param targetChains @@ -340,7 +389,7 @@ public class StructureSelectionManager * mapping operation * @return null or the structure data parsed as a pdb file */ - synchronized public StructureFile computeMapping( + synchronized private StructureFile computeMapping( boolean forStructureView, SequenceI[] sequenceArray, String[] targetChainIds, String pdbFile, DataSourceType sourceType, IProgressIndicator progress) @@ -1196,43 +1245,22 @@ public class StructureSelectionManager } /** - * Resets this object to its initial state by removing all registered - * listeners, codon mappings, PDB file mappings + * Reset this object to its initial state by removing all registered + * listeners, codon mappings, PDB file mappings. + * + * Called only by Desktop and testng. + * */ public void resetAll() { - if (mappings != null) - { - mappings.clear(); - } - if (seqmappings != null) - { - seqmappings.clear(); - } - if (sel_listeners != null) - { - sel_listeners.clear(); - } - if (listeners != null) - { - listeners.clear(); - } - if (commandListeners != null) - { - commandListeners.clear(); - } - if (view_listeners != null) - { - view_listeners.clear(); - } - if (pdbFileNameId != null) - { - pdbFileNameId.clear(); - } - if (pdbIdFileName != null) - { - pdbIdFileName.clear(); - } + mappings.clear(); + seqmappings.clear(); + sel_listeners.clear(); + listeners.clear(); + commandListeners.clear(); + view_listeners.clear(); + pdbFileNameId.clear(); + pdbIdFileName.clear(); } public void addSelectionListener(SelectionListener selecter) @@ -1366,49 +1394,4 @@ 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 5667603..d99d16d 100644 --- a/src/jalview/urls/IdOrgSettings.java +++ b/src/jalview/urls/IdOrgSettings.java @@ -31,12 +31,10 @@ import jalview.bin.Instance; */ public class IdOrgSettings { - private String url; - private String location; private IdOrgSettings() { - // singleton + // private singleton } private static IdOrgSettings getInstance() @@ -46,6 +44,10 @@ public class IdOrgSettings : j.idOrgSettings); } + private String url; + + private String location; + public static void setUrl(String seturl) { getInstance().url = seturl; diff --git a/src/jalview/ws/DBRefFetcher.java b/src/jalview/ws/DBRefFetcher.java index b1c987e..6c21941 100644 --- a/src/jalview/ws/DBRefFetcher.java +++ b/src/jalview/ws/DBRefFetcher.java @@ -134,7 +134,7 @@ public class DBRefFetcher implements Runnable } this.dataset = ds; // TODO Jalview 2.5 lots of this code should be in the gui package! - sfetcher = jalview.gui.SequenceFetcher.getSequenceFetcherSingleton(); + sfetcher = SequenceFetcher.getInstance(); // set default behaviour for transferring excess sequence data to the // dataset trimDsSeqs = Cache.getDefault(TRIM_RETRIEVED_SEQUENCES, true); @@ -785,7 +785,9 @@ public class DBRefFetcher implements Runnable { int n; if (sequencesArray == null || (n = sequencesArray.length) == 0) - return sequencesArray; + { + return sequencesArray; + } ArrayList nseq = new ArrayList<>(); for (int i = 0;i < n; i++) { diff --git a/src/jalview/ws/SequenceFetcher.java b/src/jalview/ws/SequenceFetcher.java index 4f82619..2b3b1ee 100644 --- a/src/jalview/ws/SequenceFetcher.java +++ b/src/jalview/ws/SequenceFetcher.java @@ -20,6 +20,7 @@ */ package jalview.ws; +import jalview.bin.Instance; import jalview.datamodel.DBRefSource; import jalview.ext.ensembl.EnsemblGene; import jalview.ws.dbsources.Uniprot; @@ -31,15 +32,35 @@ import java.util.Collections; import java.util.List; /** - * This implements the run-time discovery of sequence database clients. + * Thread safe construction of database proxies. This implements the run-time + * discovery of sequence database clients. * + * TODO: extend to a configurable database plugin mechanism where classes are + * instantiated by reflection and queried for their DbRefSource and version + * association. */ public class SequenceFetcher extends ASequenceFetcher { + + /** + * Returns a new SequenceFetcher singleton, or a mock object if one has been + * set. Used by CrossRef and java.gui.SequenceFetcher. + * + * @return + */ + public static SequenceFetcher getInstance() + { + Instance j = Instance.getInstance(); + return (j.sequenceFetcher == null + ? j.sequenceFetcher = new SequenceFetcher() + : j.sequenceFetcher); + } + /** - * Thread safe construction of database proxies TODO: extend to a configurable - * database plugin mechanism where classes are instantiated by reflection and - * queried for their DbRefSource and version association. + * + * This public constructor is only is for use by testng to anonymously + * subclass SequenceFetcher. + * * */ public SequenceFetcher() @@ -47,6 +68,19 @@ public class SequenceFetcher extends ASequenceFetcher addAllDatabases(); } + /** + * Set the instance object to use (intended for unit testing with mock + * objects). + * + * Be sure to reset to null in the tearDown method of any tests! + * + * @param sf + */ + public static void setSequenceFetcher(SequenceFetcher sf) + { + Instance.getInstance().sequenceFetcher = sf; + } + public void addAllDatabases() { addDBRefSourceImpl(EnsemblGene.class); // includes EnsemblGenomes.class diff --git a/src/jalview/ws/SequenceFetcherFactory.java b/src/jalview/ws/SequenceFetcherFactory.java index 63231d5..7aad74a 100644 --- a/src/jalview/ws/SequenceFetcherFactory.java +++ b/src/jalview/ws/SequenceFetcherFactory.java @@ -20,35 +20,7 @@ */ package jalview.ws; -import jalview.bin.Instance; -import jalview.ws.seqfetcher.ASequenceFetcher; - public class SequenceFetcherFactory { - - /** - * Returns a new SequenceFetcher object, or a mock object if one has been set - * - * @return - */ - public static ASequenceFetcher getSequenceFetcher() - { - Instance j = Instance.getInstance(); - return (j.sequenceFetcher == null - ? j.sequenceFetcher = new SequenceFetcher() - : j.sequenceFetcher); - } - - /** - * Set the instance object to use (intended for unit testing with mock - * objects). - * - * Be sure to reset to null in the tearDown method of any tests! - * - * @param sf - */ - public static void setSequenceFetcher(SequenceFetcher sf) - { - Instance.getInstance().sequenceFetcher = sf; - } + // BH the two methods in this class merged into SequenceFetcher } diff --git a/src/jalview/ws/jws1/Discoverer.java b/src/jalview/ws/jws1/Discoverer.java index 4af342a..ea836f9 100644 --- a/src/jalview/ws/jws1/Discoverer.java +++ b/src/jalview/ws/jws1/Discoverer.java @@ -38,10 +38,6 @@ import ext.vamsas.ServiceHandles; public class Discoverer implements Runnable { - private Discoverer() - { - }; - public static Discoverer getInstance() { Instance j = Instance.getInstance(); @@ -49,6 +45,11 @@ public class Discoverer implements Runnable : j.discoverer); } + private Discoverer() + { + // use getInstance() + } + private java.net.URL RootServiceURL = null; private Vector ServiceURLList = null; diff --git a/src/jalview/ws/jws2/Jws2Client.java b/src/jalview/ws/jws2/Jws2Client.java index 0f1a25e..62f2a03 100644 --- a/src/jalview/ws/jws2/Jws2Client.java +++ b/src/jalview/ws/jws2/Jws2Client.java @@ -398,7 +398,7 @@ public abstract class Jws2Client extends jalview.ws.WSClient { // check service is actually in the list of currently avaialable // services - if (!Jws2Discoverer.getDiscoverer().getServices().contains(service)) + if (!Jws2Discoverer.getInstance().getServices().contains(service)) { // it isn't .. service = null; @@ -408,7 +408,7 @@ public abstract class Jws2Client extends jalview.ws.WSClient if (service == null) { // get the default service for AACon - service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null, + service = Jws2Discoverer.getInstance().getPreferredServiceFor(null, aaui.getServiceType()); } if (service == null) diff --git a/src/jalview/ws/jws2/Jws2Discoverer.java b/src/jalview/ws/jws2/Jws2Discoverer.java index 0ff9df6..6eaaee1 100644 --- a/src/jalview/ws/jws2/Jws2Discoverer.java +++ b/src/jalview/ws/jws2/Jws2Discoverer.java @@ -63,6 +63,28 @@ import compbio.ws.client.Services; */ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI { + + /** + * Returns the singleton instance of this class. + * + * @return + */ + public static Jws2Discoverer getInstance() + { + Instance j = Instance.getInstance(); + return (j.j2s2discoverer == null + ? j.j2s2discoverer = new Jws2Discoverer() + : j.j2s2discoverer); + } + + /** + * Private constructor enforces use of singleton via getDiscoverer() + */ + private Jws2Discoverer() + { + // use getInstance(); + } + public static final String COMPBIO_JABAWS = "http://www.compbio.dundee.ac.uk/jabaws"; /* @@ -99,13 +121,6 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI protected Vector services; /** - * Private constructor enforces use of singleton via getDiscoverer() - */ - private Jws2Discoverer() - { - } - - /** * change listeners are notified of "services" property changes * * @param listener @@ -587,19 +602,19 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI testUrls.add(url); } } - Thread runner = getDiscoverer() + Thread runner = getInstance() .startDiscoverer(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - if (getDiscoverer().services != null) + if (getInstance().services != null) { System.out.println("Changesupport: There are now " - + getDiscoverer().services.size() + " services"); + + getInstance().services.size() + " services"); int i = 1; - for (Jws2Instance instance : getDiscoverer().services) + for (Jws2Instance instance : getInstance().services) { System.out.println("Service " + i++ + " " + instance.getClass() + "@" + instance.getHost() @@ -626,19 +641,6 @@ public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI } } - /** - * Returns the singleton instance of this class. - * - * @return - */ - public static Jws2Discoverer getDiscoverer() - { - Instance j = Instance.getInstance(); - return (j.j2s2discoverer == null - ? j.j2s2discoverer = new Jws2Discoverer() - : j.j2s2discoverer); - } - public boolean hasServices() { return !running && services != null && services.size() > 0; diff --git a/src/jalview/ws/jws2/SequenceAnnotationWSClient.java b/src/jalview/ws/jws2/SequenceAnnotationWSClient.java index a9c071a..9358c76 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) { - Instance.getDesktop().showUrl(service.docUrl); + Desktop.getInstance().showUrl(service.docUrl); } }); annotservice.setToolTipText( diff --git a/src/jalview/ws/jws2/jabaws2/Jws2Instance.java b/src/jalview/ws/jws2/jabaws2/Jws2Instance.java index 5ea646f..a4e2e75 100644 --- a/src/jalview/ws/jws2/jabaws2/Jws2Instance.java +++ b/src/jalview/ws/jws2/jabaws2/Jws2Instance.java @@ -20,7 +20,6 @@ */ package jalview.ws.jws2.jabaws2; -import jalview.bin.Instance; import jalview.gui.AlignFrame; import jalview.gui.Desktop; import jalview.util.MessageManager; @@ -187,7 +186,7 @@ public class Jws2Instance try { paramStore = new JabaParamStore(this, - (Instance.getDesktop() != null ? Desktop.getUserParameterStore() + (Desktop.getInstance() != 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 e227385..159edda 100644 --- a/src/jalview/ws/jws2/jabaws2/Jws2InstanceFactory.java +++ b/src/jalview/ws/jws2/jabaws2/Jws2InstanceFactory.java @@ -33,11 +33,12 @@ import compbio.data.msa.JABAService; public class Jws2InstanceFactory { - private HashMap aaConGUI; - - private HashSet ignoreGUI; + private Jws2InstanceFactory() + { + // private singleton + } - public static Jws2InstanceFactory getInstance() + private static Jws2InstanceFactory getInstance() { Instance j = Instance.getInstance(); return (j.jws2InstanceFactory == null @@ -45,6 +46,10 @@ public class Jws2InstanceFactory : j.jws2InstanceFactory); } + private HashMap aaConGUI; + + private HashSet ignoreGUI; + private static String category_rewrite(String cat_name) { return (cat_name != null && cat_name.equals("Prediction")) diff --git a/src/jalview/ws/seqfetcher/ASequenceFetcher.java b/src/jalview/ws/seqfetcher/ASequenceFetcher.java index dff08ee..e205e76 100644 --- a/src/jalview/ws/seqfetcher/ASequenceFetcher.java +++ b/src/jalview/ws/seqfetcher/ASequenceFetcher.java @@ -58,8 +58,6 @@ public class ASequenceFetcher */ protected ASequenceFetcher() { - super(); - /* * comparator to sort proxies by tier and name */ diff --git a/src/jalview/ws/sifts/SiftsClient.java b/src/jalview/ws/sifts/SiftsClient.java index eb7bd99..bf4d970 100644 --- a/src/jalview/ws/sifts/SiftsClient.java +++ b/src/jalview/ws/sifts/SiftsClient.java @@ -82,6 +82,22 @@ public class SiftsClient implements SiftsClientI */ private static File mockSiftsFile; + private static final int BUFFER_SIZE = 4096; + + public static final int UNASSIGNED = Integer.MIN_VALUE; + + private static final int PDB_RES_POS = 0; + + private static final int PDB_ATOM_POS = 1; + + private static final int PDBE_POS = 2; + + private static final String NOT_OBSERVED = "Not_Observed"; + + protected static final String SIFTS_FTP_BASE_URL = "http://ftp.ebi.ac.uk/pub/databases/msd/sifts/xml/"; + + protected final static String NEWLINE = System.lineSeparator(); + private Entry siftsEntry; private StructureFile pdb; @@ -100,22 +116,6 @@ public class SiftsClient implements SiftsClientI */ private jalview.datamodel.Mapping seqFromPdbMapping; - private static final int BUFFER_SIZE = 4096; - - public static final int UNASSIGNED = Integer.MIN_VALUE; - - private static final int PDB_RES_POS = 0; - - private static final int PDB_ATOM_POS = 1; - - private static final int PDBE_POS = 2; - - private static final String NOT_OBSERVED = "Not_Observed"; - - protected static final String SIFTS_FTP_BASE_URL = "http://ftp.ebi.ac.uk/pub/databases/msd/sifts/xml/"; - - protected final static String NEWLINE = System.lineSeparator(); - private String curSourceDBRef; private HashSet curDBRefAccessionIdsString; diff --git a/src/jalview/ws/sifts/SiftsSettings.java b/src/jalview/ws/sifts/SiftsSettings.java index 51f1175..8fd5300 100644 --- a/src/jalview/ws/sifts/SiftsSettings.java +++ b/src/jalview/ws/sifts/SiftsSettings.java @@ -26,15 +26,13 @@ import java.util.Objects; public class SiftsSettings { - private boolean mapWithSifts = false; - - private String siftDownloadDirectory; - - private int cacheThresholdInDays; - private int failSafePIDThreshold; - - private static SiftsSettings getInstance() + /** + * public only for testng + * + * @return + */ + public static SiftsSettings getInstance() { { Instance j = Instance.getInstance(); @@ -44,6 +42,20 @@ public class SiftsSettings } } + + private SiftsSettings() + { + // singleton; use getInstance() + } + + private boolean mapWithSifts = false; + + private String siftDownloadDirectory; + + private int cacheThresholdInDays; + + private int failSafePIDThreshold; + public static boolean isMapWithSifts() { return getInstance().mapWithSifts; diff --git a/test/jalview/analysis/CrossRefTest.java b/test/jalview/analysis/CrossRefTest.java index 6417c91..d47c2c1 100644 --- a/test/jalview/analysis/CrossRefTest.java +++ b/test/jalview/analysis/CrossRefTest.java @@ -41,8 +41,6 @@ import jalview.gui.JvOptionPane; import jalview.util.DBRefUtils; import jalview.util.MapList; import jalview.ws.SequenceFetcher; -import jalview.ws.SequenceFetcherFactory; -import jalview.ws.params.InvalidArgumentException; import java.util.ArrayList; import java.util.Arrays; @@ -443,7 +441,7 @@ public class CrossRefTest return new SequenceI[] { pep1, pep2 }; } }; - SequenceFetcherFactory.setSequenceFetcher(mockFetcher); + SequenceFetcher.setSequenceFetcher(mockFetcher); /* * find UNIPROT xrefs for nucleotide sequence @@ -459,7 +457,7 @@ public class CrossRefTest @AfterClass(alwaysRun = true) public void tearDown() { - SequenceFetcherFactory.setSequenceFetcher(null); + SequenceFetcher.setSequenceFetcher(null); } /** @@ -521,7 +519,7 @@ public class CrossRefTest return new SequenceI[] { pep1, pep2 }; } }; - SequenceFetcherFactory.setSequenceFetcher(mockFetcher); + SequenceFetcher.setSequenceFetcher(mockFetcher); /* * find UNIPROT xrefs for gene and transcripts @@ -681,7 +679,8 @@ public class CrossRefTest } } }; - SequenceFetcherFactory.setSequenceFetcher(mockFetcher); + + SequenceFetcher.setSequenceFetcher(mockFetcher); /* * find EMBL xrefs for Uniprot seqs and verify that diff --git a/test/jalview/ext/jmol/JmolViewerTest.java b/test/jalview/ext/jmol/JmolViewerTest.java index e2feb50..7ef0d16 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.bin.Instance.getDesktop().closeAll_actionPerformed(null); + jalview.gui.Desktop.getInstance().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 771ccb0..194d34a 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 { - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); } @AfterMethod(alwaysRun = true) diff --git a/test/jalview/gui/AlignFrameTest.java b/test/jalview/gui/AlignFrameTest.java index fd690f3..779941b 100644 --- a/test/jalview/gui/AlignFrameTest.java +++ b/test/jalview/gui/AlignFrameTest.java @@ -29,7 +29,6 @@ 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; @@ -165,7 +164,7 @@ public class AlignFrameTest @AfterMethod(alwaysRun = true) public void tearDown() { - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); } /** diff --git a/test/jalview/gui/AlignViewportTest.java b/test/jalview/gui/AlignViewportTest.java index 20b4988..71378fe 100644 --- a/test/jalview/gui/AlignViewportTest.java +++ b/test/jalview/gui/AlignViewportTest.java @@ -28,7 +28,6 @@ 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,9 +79,7 @@ public class AlignViewportTest /* * remove any sequence mappings left lying around by other tests */ - StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Instance.getDesktop()); - ssm.resetAll(); + Desktop.getStructureSelectionManager().resetAll(); } @BeforeMethod(alwaysRun = true) @@ -128,9 +125,8 @@ public class AlignViewportTest * Verify that creating the alignment for the new View has registered the * mappings */ - StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Instance.getDesktop()); - List sequenceMappings = ssm.getSequenceMappings(); + List sequenceMappings = Desktop + .getStructureSelectionManager().getSequenceMappings(); assertEquals(2, sequenceMappings.size()); assertTrue(sequenceMappings.contains(acf1)); assertTrue(sequenceMappings.contains(acf2)); @@ -151,10 +147,9 @@ public class AlignViewportTest @Test(groups = { "Functional" }) public void testDeregisterMapping_withNoReference() { - Desktop d = Instance.getDesktop(); + Desktop d = Desktop.getInstance(); assertNotNull(d); - StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Instance.getDesktop()); + StructureSelectionManager ssm = Desktop.getStructureSelectionManager(); ssm.resetAll(); AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded( @@ -214,10 +209,9 @@ public class AlignViewportTest @Test(groups = { "Functional" }) public void testDeregisterMapping_withReference() { - Desktop d = Instance.getDesktop(); + Desktop d = Desktop.getInstance(); assertNotNull(d); - StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Instance.getDesktop()); + StructureSelectionManager ssm = Desktop.getStructureSelectionManager(); ssm.resetAll(); AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded( diff --git a/test/jalview/gui/FreeUpMemoryTest.java b/test/jalview/gui/FreeUpMemoryTest.java index 8345f81..18ff7f2 100644 --- a/test/jalview/gui/FreeUpMemoryTest.java +++ b/test/jalview/gui/FreeUpMemoryTest.java @@ -6,7 +6,6 @@ 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; @@ -71,7 +70,7 @@ public class FreeUpMemoryTest doStuffInJalview(f); - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); checkUsedMemory(35L); } @@ -110,7 +109,7 @@ public class FreeUpMemoryTest * sanity check - fails if any frame was added after * closeAll_actionPerformed */ - assertEquals(Instance.getDesktop().getAllFrames().length, 0); + assertEquals(Desktop.getInstance().getAllFrames().length, 0); /* * if this assertion fails diff --git a/test/jalview/gui/SeqPanelTest.java b/test/jalview/gui/SeqPanelTest.java index 8067148..17e04bf 100644 --- a/test/jalview/gui/SeqPanelTest.java +++ b/test/jalview/gui/SeqPanelTest.java @@ -26,7 +26,6 @@ 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; @@ -253,7 +252,7 @@ public class SeqPanelTest @AfterMethod(alwaysRun = true) public void tearDown() { - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); } @Test(groups = "Functional") diff --git a/test/jalview/io/AnnotatedPDBFileInputTest.java b/test/jalview/io/AnnotatedPDBFileInputTest.java index 5cc2345..beeb52f 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.bin.Instance.getDesktop().closeAll_actionPerformed(null); + jalview.gui.Desktop.getInstance().closeAll_actionPerformed(null); } diff --git a/test/jalview/io/CrossRef2xmlTests.java b/test/jalview/io/CrossRef2xmlTests.java index 0b6c83b..daadfa5 100644 --- a/test/jalview/io/CrossRef2xmlTests.java +++ b/test/jalview/io/CrossRef2xmlTests.java @@ -22,7 +22,6 @@ 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; @@ -136,7 +135,7 @@ public class CrossRef2xmlTests extends Jalview2xmlBase { // retrieve dbref - SequenceFetcher sf = new SequenceFetcher(Instance.getDesktop(), + SequenceFetcher sf = new SequenceFetcher(Desktop.getInstance(), forSource, forAccession); sf.run(); AlignFrame[] afs = Desktop.getAlignFrames(); @@ -163,7 +162,7 @@ public class CrossRef2xmlTests extends Jalview2xmlBase } else { - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); // recover stored project af = new FileLoader(false).LoadFileWaitTillLoaded( savedProjects.get(first).toString(), DataSourceType.FILE); @@ -230,7 +229,7 @@ public class CrossRef2xmlTests extends Jalview2xmlBase } else { - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); pass3 = 0; // recover stored project File storedProject = savedProjects.get(nextxref); @@ -341,7 +340,7 @@ public class CrossRef2xmlTests extends Jalview2xmlBase } else { - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().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 483ce76..59ef8ad 100644 --- a/test/jalview/io/FeaturesFileTest.java +++ b/test/jalview/io/FeaturesFileTest.java @@ -29,7 +29,6 @@ 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; @@ -41,9 +40,9 @@ 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; import jalview.util.matcher.Condition; import jalview.viewmodel.seqfeatures.FeatureRendererModel; import jalview.viewmodel.seqfeatures.FeatureRendererModel.FeatureSettingsBean; @@ -70,9 +69,7 @@ public class FeaturesFileTest /* * remove any sequence mappings created so they don't pollute other tests */ - StructureSelectionManager ssm = StructureSelectionManager - .getStructureSelectionManager(Instance.getDesktop()); - ssm.resetAll(); + Desktop.getStructureSelectionManager().resetAll(); } @BeforeClass(alwaysRun = true) diff --git a/test/jalview/io/Jalview2xmlBase.java b/test/jalview/io/Jalview2xmlBase.java index 38481e5..3a0560c 100644 --- a/test/jalview/io/Jalview2xmlBase.java +++ b/test/jalview/io/Jalview2xmlBase.java @@ -21,7 +21,6 @@ package jalview.io; import jalview.bin.Cache; -import jalview.bin.Instance; import jalview.bin.Jalview; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.SequenceI; @@ -71,16 +70,16 @@ public class Jalview2xmlBase @AfterClass(alwaysRun = true) public static void tearDownAfterClass() throws Exception { - jalview.bin.Instance.getDesktop().closeAll_actionPerformed(null); + jalview.gui.Desktop.getInstance().closeAll_actionPerformed(null); } @BeforeTest(alwaysRun = true) public static void clearDesktop() { - if (Instance.getDesktop() != null && Desktop.getFrames() != null + if (Desktop.getInstance() != null && Desktop.getFrames() != null && Desktop.getFrames().length > 0) { - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); } } diff --git a/test/jalview/io/JalviewExportPropertiesTests.java b/test/jalview/io/JalviewExportPropertiesTests.java index 0eaa36a..1614453 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.bin.Instance.getDesktop().closeAll_actionPerformed(null); + jalview.gui.Desktop.getInstance().closeAll_actionPerformed(null); } diff --git a/test/jalview/project/Jalview2xmlTests.java b/test/jalview/project/Jalview2xmlTests.java index 9e2f7de..830a759 100644 --- a/test/jalview/project/Jalview2xmlTests.java +++ b/test/jalview/project/Jalview2xmlTests.java @@ -32,7 +32,6 @@ 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; @@ -406,7 +405,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }, enabled = true) public void testStoreAndRecoverExpandedviews() throws Exception { - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/exampleFile_2_7.jar", DataSourceType.FILE); @@ -434,7 +433,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase { Assert.fail("Didn't save the expanded view state", e); } - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); if (Desktop.getAlignFrames() != null) { Assert.assertEquals(Desktop.getAlignFrames().length, 0); @@ -460,7 +459,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }) public void testStoreAndRecoverReferenceSeqSettings() throws Exception { - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().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."); @@ -499,7 +498,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase { Assert.fail("Didn't save the expanded view state", e); } - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); if (Desktop.getAlignFrames() != null) { Assert.assertEquals(Desktop.getAlignFrames().length, 0); @@ -593,7 +592,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }) public void testStoreAndRecoverGroupRepSeqs() throws Exception { - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/uniref50.fa", DataSourceType.FILE); assertNotNull(af, "Didn't read in the example file correctly."); @@ -668,7 +667,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase { Assert.fail("Didn't save the expanded view state", e); } - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); if (Desktop.getAlignFrames() != null) { Assert.assertEquals(Desktop.getAlignFrames().length, 0); @@ -713,7 +712,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }) public void testStoreAndRecoverPDBEntry() throws Exception { - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); String exampleFile = "examples/3W5V.pdb"; AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(exampleFile, DataSourceType.FILE); @@ -762,7 +761,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase { Assert.fail("Didn't save the state", e); } - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); if (Desktop.getAlignFrames() != null) { Assert.assertEquals(Desktop.getAlignFrames().length, 0); @@ -813,7 +812,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }) public void testStoreAndRecoverColourThresholds() throws IOException { - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( "examples/uniref50.fa", DataSourceType.FILE); @@ -873,7 +872,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase ".jvp"); tfile.deleteOnExit(); new Jalview2XML(false).saveState(tfile); - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(), DataSourceType.FILE); Assert.assertNotNull(af, "Failed to reload project"); @@ -1082,7 +1081,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = { "Functional" }) public void testMergeDatasetsforManyViews() throws IOException { - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); // complex project - one dataset, several views on several alignments AlignFrame af = new FileLoader(false).LoadFileWaitTillLoaded( @@ -1126,7 +1125,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase @Test(groups = "Functional") public void testPcaViewAssociation() throws IOException { - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); final String PCAVIEWNAME = "With PCA"; // create a new tempfile File tempfile = File.createTempFile("jvPCAviewAssoc", "jvp"); @@ -1160,10 +1159,10 @@ public class Jalview2xmlTests extends Jalview2xmlBase } // load again. - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( tempfile.getCanonicalPath(), DataSourceType.FILE); - JInternalFrame[] frames = Instance.getDesktop().getAllFrames(); + JInternalFrame[] frames = Desktop.getInstance().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 263073d..06be31e 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 { - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); } @Test(groups = "Functional") diff --git a/test/jalview/structure/StructureSelectionManagerTest.java b/test/jalview/structure/StructureSelectionManagerTest.java index 40ce498..dab692f 100644 --- a/test/jalview/structure/StructureSelectionManagerTest.java +++ b/test/jalview/structure/StructureSelectionManagerTest.java @@ -28,7 +28,6 @@ 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; @@ -200,7 +199,7 @@ public class StructureSelectionManagerTest extends Jalview2xmlBase { // for some reason 'BeforeMethod' (which should be inherited from // Jalview2XmlBase isn't always called)... - Instance.getDesktop().closeAll_actionPerformed(null); + Desktop.getInstance().closeAll_actionPerformed(null); try { Thread.sleep(200); } catch (Exception foo) {}; diff --git a/test/jalview/ws/PDBSequenceFetcherTest.java b/test/jalview/ws/PDBSequenceFetcherTest.java index 9992137..a5bca34 100644 --- a/test/jalview/ws/PDBSequenceFetcherTest.java +++ b/test/jalview/ws/PDBSequenceFetcherTest.java @@ -62,7 +62,7 @@ public class PDBSequenceFetcherTest Cache.setPropertyNoSave("ADD_SS_ANN", Boolean.TRUE.toString()); - sf = new SequenceFetcher(); + sf = SequenceFetcher.getInstance(); } /** diff --git a/test/jalview/ws/SequenceFetcherTest.java b/test/jalview/ws/SequenceFetcherTest.java index 6683d6c..8e18cc0 100644 --- a/test/jalview/ws/SequenceFetcherTest.java +++ b/test/jalview/ws/SequenceFetcherTest.java @@ -70,14 +70,14 @@ public class SequenceFetcherTest } if (argv != null && argv.length > 0) { - List sps = new SequenceFetcher() + List sps = SequenceFetcher.getInstance() .getSourceProxy(argv[0]); if (sps != null) { for (DbSourceProxy sp : sps) { - AlignmentI al = null; + // AlignmentI al = null; try { testRetrieval(argv[0], sp, @@ -96,12 +96,12 @@ public class SequenceFetcherTest { System.err.println("Can't resolve " + argv[0] + " as a database name. Allowed values are :\n" - + new SequenceFetcher().getSupportedDb()); + + SequenceFetcher.getInstance().getSupportedDb()); } System.out.println(usage); return; } - ASequenceFetcher sfetcher = new SequenceFetcher(); + ASequenceFetcher sfetcher = SequenceFetcher.getInstance(); String[] dbSources = sfetcher.getSupportedDb(); for (int dbsource = 0; dbsource < dbSources.length; dbsource++) { diff --git a/test/jalview/ws/dbsources/RemoteFormatTest.java b/test/jalview/ws/dbsources/RemoteFormatTest.java index 9d40624..1e4573d 100644 --- a/test/jalview/ws/dbsources/RemoteFormatTest.java +++ b/test/jalview/ws/dbsources/RemoteFormatTest.java @@ -51,7 +51,7 @@ public class RemoteFormatTest Cache.setPropertyNoSave("ADD_SS_ANN", Boolean.TRUE.toString()); - sf = new SequenceFetcher(); + sf = SequenceFetcher.getInstance(); } @DataProvider(name = "AccessionData") diff --git a/test/jalview/ws/jabaws/JalviewJabawsTestUtils.java b/test/jalview/ws/jabaws/JalviewJabawsTestUtils.java index 12f5e1b..9c291c3 100644 --- a/test/jalview/ws/jabaws/JalviewJabawsTestUtils.java +++ b/test/jalview/ws/jabaws/JalviewJabawsTestUtils.java @@ -85,7 +85,7 @@ public class JalviewJabawsTestUtils public static Jws2Discoverer getJabawsDiscoverer(boolean localhost) { jalview.ws.jws2.Jws2Discoverer disc = jalview.ws.jws2.Jws2Discoverer - .getDiscoverer(); + .getInstance(); String svcurls = ""; if (localhost) { @@ -97,7 +97,7 @@ public class JalviewJabawsTestUtils services.add(url); } ; - Jws2Discoverer.getDiscoverer().setServiceUrls(services); + Jws2Discoverer.getInstance().setServiceUrls(services); } try { diff --git a/test/jalview/ws/seqfetcher/DbRefFetcherTest.java b/test/jalview/ws/seqfetcher/DbRefFetcherTest.java index a7e5806..f752235 100644 --- a/test/jalview/ws/seqfetcher/DbRefFetcherTest.java +++ b/test/jalview/ws/seqfetcher/DbRefFetcherTest.java @@ -85,11 +85,11 @@ public class DbRefFetcherTest @Test(groups = { "Functional" }) public void testStandardProtDbs() { - List defdb = new ArrayList(); + List defdb = new ArrayList<>(); defdb.addAll(Arrays.asList(DBRefSource.PROTEINDBS)); defdb.add(DBRefSource.PDB); - List srces = new ArrayList(); - SequenceFetcher sfetcher = new SequenceFetcher(); + List srces = new ArrayList<>(); + SequenceFetcher sfetcher = SequenceFetcher.getInstance(); boolean pdbFound = false; for (String ddb : defdb) @@ -135,7 +135,7 @@ public class DbRefFetcherTest public void testEmblUniprotProductRecovery() throws Exception { String retrievalId = "V00488"; - DbSourceProxy embl = new SequenceFetcher().getSourceProxy( + DbSourceProxy embl = SequenceFetcher.getInstance().getSourceProxy( DBRefSource.EMBL).get(0); assertNotNull("Couldn't find the EMBL retrieval client", embl); verifyProteinNucleotideXref(retrievalId, embl); @@ -151,7 +151,8 @@ public class DbRefFetcherTest public void testEmblCDSUniprotProductRecovery() throws Exception { String retrievalId = "AAH29712"; - DbSourceProxy embl = new SequenceFetcher().getSourceProxy( + DbSourceProxy embl = SequenceFetcher.getInstance() + .getSourceProxy( DBRefSource.EMBLCDS).get(0); assertNotNull("Couldn't find the EMBL retrieval client", embl); verifyProteinNucleotideXref(retrievalId, embl); diff --git a/test/jalview/ws/sifts/SiftsClientTest.java b/test/jalview/ws/sifts/SiftsClientTest.java index 6122d6d..ae6853b 100644 --- a/test/jalview/ws/sifts/SiftsClientTest.java +++ b/test/jalview/ws/sifts/SiftsClientTest.java @@ -78,7 +78,7 @@ public class SiftsClientTest int u = SiftsClient.UNASSIGNED; - HashMap expectedMapping = new HashMap(); + HashMap expectedMapping = new HashMap<>(); @BeforeTest(alwaysRun = true) public void populateExpectedMapping() throws SiftsException @@ -189,7 +189,6 @@ public class SiftsClientTest Cache.loadProperties("test/jalview/io/testProps.jvprops"); // SIFTs entries are updated weekly - so use saved SIFTs file to enforce // test reproducibility - new SiftsSettings(); SiftsSettings.setSiftDownloadDirectory(jalview.bin.Cache.getDefault( "sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR)); SiftsSettings.setMapWithSifts(true); @@ -305,13 +304,13 @@ public class SiftsClientTest @Test(groups = { "Network" }) private void getAtomIndexTest() { - ArrayList atoms = new ArrayList(); + ArrayList atoms = new ArrayList<>(); Atom atom = new Atom(u, u, u); atom.resNumber = 43; atom.atomIndex = 7; atoms.add(atom); int actualAtomIndex = siftsClient.getAtomIndex(1, atoms); - Assert.assertEquals(actualAtomIndex, siftsClient.UNASSIGNED); + Assert.assertEquals(actualAtomIndex, SiftsClient.UNASSIGNED); actualAtomIndex = siftsClient.getAtomIndex(43, atoms); Assert.assertEquals(actualAtomIndex, 7); }