error.implementation_error_cannot_have_null_alignment = Implementation error: Cannot have null alignment property key
error.implementation_error_null_fileparse = Implementation error. Null FileParse in copy constructor
error.implementation_error_cannot_map_alignment_sequences = IMPLEMENTATION ERROR: Cannot map an alignment of sequences from different datasets into a single alignment in the vamsas document.
-error.implementation_error_structure_selection_manager_null = Implementation error. Structure selection manager's context is 'null'
-exception.ssm_context_is_null = SSM context is null
error.idstring_seqstrings_only_one_per_sequence = idstrings and seqstrings contain one string each per sequence
error.cannot_have_mixed_length_replacement_vectors = Cannot have mixed length replacement vectors. Replacement vector for {0} is {1} strings long, and have already seen a {2} length vector.
error.cannot_have_zero_length_vector_replacement_strings = Cannot have zero length vector of replacement strings - either 1 value or n values.
error.implementation_error_cannot_have_null_alignment = Error de implementación: no es posible tener una clave nula en el alineamiento
error.implementation_error_null_fileparse = Error de implementación. FileParse nulo en el construictor de copia
error.implementation_error_cannot_map_alignment_sequences = Error de implementación: no es posible maper un alineamiento de secuencias desde distintos conjuntos de datos en un único alineamiento en el documento VAMSAS.
-error.implementation_error_structure_selection_manager_null = Error de implementación. El contexto structure selection manager's es nulo
-exception.ssm_context_is_null = El contexto SSM es nulo
error.idstring_seqstrings_only_one_per_sequence = idstrings y seqstrings contienen una cadena por cada secuencia
error.cannot_have_mixed_length_replacement_vectors = No es posible tener vectores de reemplazo de distinta longitud. El vector de reemplazo para {0} es de {1} cadenas de largo, pero se ha considerado ya como un vector de longitud {2}.
error.cannot_have_zero_length_vector_replacement_strings = No es posible tener un vector de cadenas de reemplazo de longitud cero - debe ser uno o n.
import jalview.analysis.scoremodels.PIDModel;
import jalview.analysis.scoremodels.SimilarityParams;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.AlignmentOrder;
* from the first tobesorted position in the alignment. e.g. (a,tb2,b,tb1,c,tb3
* becomes a,tb1,tb2,tb3,b,c)
*/
-public class AlignmentSorter
+public class AlignmentSorter implements ApplicationSingletonI
{
private AlignmentSorter()
private static AlignmentSorter getInstance()
{
- Instance j = Instance.getInstance();
- return (j.alignmentSorter == null
- ? j.alignmentSorter = new AlignmentSorter()
- : j.alignmentSorter);
+ return (AlignmentSorter) ApplicationSingletonProvider
+ .getInstance(AlignmentSorter.class);
}
/**
import jalview.api.AlignmentViewPanel;
import jalview.api.analysis.ScoreModelI;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.io.DataSourceType;
import jalview.io.FileParse;
import jalview.io.ScoreMatrixFile;
/**
* A class that can register and serve instances of ScoreModelI
*/
-public class ScoreModels
+public class ScoreModels implements ApplicationSingletonI
{
/**
* Answers the singleton instance of this class, with lazy initialisation
*/
public static ScoreModels getInstance()
{
- Instance j = Instance.getInstance();
- return (j.scoreModels == null ? j.scoreModels = new ScoreModels()
- : j.scoreModels);
+ return (ScoreModels) ApplicationSingletonProvider.getInstance(ScoreModels.class);
}
/**
*/
public void reset()
{
- Instance.getInstance().scoreModels = new ScoreModels();
+ ApplicationSingletonProvider.removeInstance(this.getClass());
}
/**
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.bin;
+
+import jalview.util.Platform;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A class to hold singleton objects, whose scope (context) is
+ * <ul>
+ * <li>the Java runtime (JVM) when running as Java</li>
+ * <li>one 'applet', when running as JalviewJS</li>
+ * </ul>
+ * This allows separation of multiple JS applets running on the same browser
+ * page, each with their own 'singleton' instances.
+ * <p>
+ * Instance objects are held in a separate Map (keyed by Class) for each
+ * context. For Java, this is just a single static Map. For SwingJS, the map is
+ * stored as a field {@code _swingjsSingletons} of
+ * {@code Thread.currentThread.getThreadGroup()}, as a proxy for the applet.
+ * <p>
+ * Note that when an applet is stopped, its ThreadGroup is removed, allowing any
+ * singleton references to be garbage collected.
+ *
+ * @author hansonr
+ */
+public class ApplicationSingletonProvider
+{
+ /**
+ * A tagging interface to mark classes whose singleton instances may be served
+ * by {@code ApplicationSingletonProvider}, giving a distinct instance per JS
+ * 'applet'.
+ * <p>
+ * A class whose singleton should have global scope (be shared across all
+ * applets on a page) should <em>not</em> use this mechanism, but just provide
+ * a single instance (class static member) in the normal way.
+ */
+ public interface ApplicationSingletonI
+ {
+ }
+
+ /*
+ * Map used to hold singletons in JVM context
+ */
+ private static Map<Class<? extends ApplicationSingletonI>, ApplicationSingletonI> singletons = new HashMap<>();
+
+ /**
+ * private constructor for non-instantiable class
+ */
+ private ApplicationSingletonProvider()
+ {
+ }
+
+ /**
+ * Returns the singletons map for the current context (JVM for Java,
+ * ThreadGroup for JS), creating the map on the first request for each JS
+ * ThreadGroup
+ *
+ * @return
+ */
+ private static Map<Class<? extends ApplicationSingletonI>, ApplicationSingletonI> getContextMap()
+ {
+ @SuppressWarnings("unused")
+ ThreadGroup g = (Platform.isJS()
+ ? Thread.currentThread().getThreadGroup()
+ : null);
+ Map<Class<? extends ApplicationSingletonI>, ApplicationSingletonI> map = singletons;
+ /** @j2sNative map = g._swingjsSingletons; */
+ if (map == null)
+ {
+ map = new HashMap<>();
+ /** @j2sNative g._swingjsSingletons = map; */
+ }
+
+ return map;
+ }
+
+ /**
+ * Answers the singleton instance of the given class for the current context
+ * (JVM or SwingJS 'applet'). If no instance yet exists, one is created, by
+ * calling the class's no-argument constructor. Answers null if any error
+ * occurs (or occurred previously for the same class).
+ *
+ * @param c
+ * @return
+ */
+ public static ApplicationSingletonI getInstance(Class<? extends ApplicationSingletonI> c)
+ {
+ Map<Class<? extends ApplicationSingletonI>, ApplicationSingletonI> map = getContextMap();
+ if (map.containsKey(c))
+ {
+ /*
+ * singleton already created _or_ creation failed (null value stored)
+ */
+ return map.get(c);
+ }
+
+ /*
+ * create and save the singleton
+ */
+ ApplicationSingletonI o = map.get(c);
+ try
+ {
+ Constructor<? extends ApplicationSingletonI> con = c
+ .getDeclaredConstructor();
+ con.setAccessible(true);
+ o = con.newInstance();
+ } catch (IllegalAccessException | InstantiationException
+ | IllegalArgumentException | InvocationTargetException
+ | NoSuchMethodException | SecurityException e)
+ {
+ Cache.log.error("Failed to create singleton for " + c.toString()
+ + ", error was: " + e.toString());
+ e.printStackTrace();
+ }
+
+ /*
+ * store the new singleton; note that a
+ * null value is saved if construction failed
+ */
+ getContextMap().put(c, o);
+
+ return o;
+ }
+
+ /**
+ * Removes the current singleton instance of the given class from the current
+ * application context. This has the effect of ensuring that a new instance is
+ * created the next time one is requested.
+ *
+ * @param c
+ */
+ public static void removeInstance(
+ Class<? extends ApplicationSingletonI> c)
+ {
+ Map<Class<? extends ApplicationSingletonI>, ApplicationSingletonI> map = getContextMap();
+ if (map != null)
+ {
+ map.remove(c);
+ }
+ }
+}
*/
package jalview.bin;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.datamodel.PDBEntry;
import jalview.gui.UserDefinedColours;
import jalview.schemes.ColourSchemeLoader;
* @author $author$
* @version $Revision$
*/
-public class Cache
+public class Cache implements ApplicationSingletonI
{
private Cache()
*/
private static Cache getInstance()
{
- Instance i = Instance.getInstance();
- return (i.cache == null ? i.cache = new Cache() : i.cache);
+ return (Cache) ApplicationSingletonProvider.getInstance(Cache.class);
}
/**
+++ /dev/null
-/*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
- *
- * This file is part of Jalview.
- *
- * Jalview is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3
- * of the License, or (at your option) any later version.
- *
- * Jalview is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package jalview.bin;
-
-import jalview.analysis.AlignmentSorter;
-import jalview.analysis.scoremodels.ScoreModels;
-import jalview.api.StructureSelectionManagerProvider;
-import jalview.datamodel.features.FeatureAttributes;
-import jalview.datamodel.features.FeatureSources;
-import jalview.ext.ensembl.EnsemblInfo;
-import jalview.fts.service.pdb.PDBFTSRestClient;
-import jalview.fts.service.uniprot.UniProtFTSRestClient;
-import jalview.gui.Desktop;
-import jalview.httpserver.HttpServer;
-import jalview.io.FileFormats;
-import jalview.io.cache.AppCache;
-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.util.Platform;
-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.util.IdentityHashMap;
-
-/**
- * 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
-{
-
- 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()
- {
-
- // assign g only if JavaScript and instance only if Java
-
- @SuppressWarnings("unused")
- ThreadGroup g = (Platform.isJS()
- ? Thread.currentThread().getThreadGroup()
- : null);
- Instance i = /** @j2sNative g._jalviewInstance || */
- instance;
- if (i == null)
- {
- i = /**
- * @j2sNative g._jalviewInstance =
- */
- new Instance();
- instance = /** @j2sNative null && */
- i;
- }
- return i;
- }
-
- public Jalview jalview;
-
- public Desktop 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 AppCache appCache;
-
- public ColourSchemes colourSchemes;
-
- public Discoverer discoverer;
-
- public FileFormats fileFormats;
-
- public HttpServer httpServer;
-
- public RestClient restClient;
-
- public RestHandler restHandler;
-
- public ScoreModels scoreModels;
-
- public jalview.ws.SequenceFetcher sequenceFetcher;
-
- public SiftsSettings siftsSettings;
-
-
- // 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 AlignmentSorter alignmentSorter;
-
- public Cache cache;
-
- public EnsemblInfo ensemblInfo;
-
- public FeatureAttributes featureAttributes;
-
- public FeatureSources featureSources;
-
- public IdOrgSettings idOrgSettings;
-
- public Jws2Discoverer j2s2discoverer;
-
- public Jws2InstanceFactory jws2InstanceFactory;
-
- 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<StructureSelectionManagerProvider, StructureSelectionManager> structureSelections;
-
-
-}
import jalview.api.AlignViewportI;
import jalview.api.JalviewApp;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceI;
import jalview.ext.so.SequenceOntology;
* @author $author$
* @version $Revision$
*/
-public class Jalview
+public class Jalview implements ApplicationSingletonI
{
public static Jalview getInstance()
{
- Instance i = Instance.getInstance();
- return (i.jalview == null ? i.jalview = new Jalview() : i.jalview);
+ return (Jalview) ApplicationSingletonProvider
+ .getInstance(Jalview.class);
}
- public Jalview()
+ private Jalview()
{
- Instance.getInstance().jalview = this;
}
static
public static void main(String[] args)
{
// setLogging(); // BH - for event debugging in JavaScript
- new Jalview().doMain(args);
+ getInstance().doMain(args);
}
private static void logClass(String name)
*/
if (Cache.getDefault("USE_FULL_SO", false))
{
- SequenceOntologyFactory.setInstance(new SequenceOntology());
+ SequenceOntologyFactory.setSequenceOntology(new SequenceOntology());
}
if (!headless)
{
- desktop = new Desktop();
+ desktop = Desktop.getInstance();
desktop.setInBatchMode(true); // indicate we are starting up
desktop.setVisible(true);
DataSourceType protocol = resolveFileProtocol(app,
ret);
- result = app.parseFeaturesFile(param, protocol);
+ result = app.parseFeaturesFile(ret[0], protocol);
}
param = app.getParameter("showFeatureSettings");
package jalview.datamodel.features;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import java.util.ArrayList;
import java.util.Collections;
/**
* A singleton class to hold the set of attributes known for each feature type
*/
-public class FeatureAttributes
+public class FeatureAttributes implements ApplicationSingletonI
{
public enum Datatype
{
public static FeatureAttributes getInstance()
{
- Instance i = Instance.getInstance();
- return (i.featureAttributes == null
- ? i.featureAttributes = new FeatureAttributes()
- : i.featureAttributes);
+ return (FeatureAttributes) ApplicationSingletonProvider
+ .getInstance(FeatureAttributes.class);
}
private FeatureAttributes()
package jalview.datamodel.features;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import java.util.HashMap;
import java.util.Map;
-public class FeatureSources
+public class FeatureSources implements ApplicationSingletonI
{
public static FeatureSources getInstance()
{
- Instance i = Instance.getInstance();
- return (i.featureSources == null
- ? i.featureSources = new FeatureSources()
- : i.featureSources);
+ return (FeatureSources) ApplicationSingletonProvider
+ .getInstance(FeatureSources.class);
}
private Map<String, FeatureSourceI> sources;
package jalview.ext.ensembl;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.DBRefSource;
import org.json.simple.parser.ParseException;
-public class EnsemblInfo extends EnsemblRestClient
+public class EnsemblInfo extends EnsemblRestClient implements ApplicationSingletonI
{
/**
* On first request only, populate the lookup map by fetching the list of
- * divisions known to EnsemblGenomes.
+ * divisions known to EnsemblGenomes
*
*/
private static EnsemblInfo getInstance()
{
- Instance j = Instance.getInstance();
- return (j.ensemblInfo == null ? j.ensemblInfo = new EnsemblInfo()
- : j.ensemblInfo);
+ return (EnsemblInfo) ApplicationSingletonProvider.getInstance(EnsemblInfo.class);
}
private EnsemblInfo()
*/
package jalview.fts.service.pdb;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.datamodel.SequenceI;
import jalview.fts.api.FTSData;
import jalview.fts.api.FTSDataColumnI;
*
* @author tcnofoegbu
*/
-public class PDBFTSRestClient extends FTSRestClient
+public class PDBFTSRestClient extends FTSRestClient implements ApplicationSingletonI
{
+ public static final String PDB_SEARCH_ENDPOINT = "https://www.ebi.ac.uk/pdbe/search/pdb/select?";
public static FTSRestClientI getInstance()
{
- Instance j = Instance.getInstance();
- return (j.pdbFTSRestClient == null
- ? j.pdbFTSRestClient = new PDBFTSRestClient()
- : j.pdbFTSRestClient);
+ return (FTSRestClientI) ApplicationSingletonProvider
+ .getInstance(PDBFTSRestClient.class);
}
- public static final String PDB_SEARCH_ENDPOINT = "https://www.ebi.ac.uk/pdbe/search/pdb/select?";
-
private PDBFTSRestClient()
{
// singleton -- use getInstance()
package jalview.fts.service.uniprot;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.bin.Cache;
-import jalview.bin.Instance;
import jalview.fts.api.FTSData;
import jalview.fts.api.FTSDataColumnI;
import jalview.fts.api.FTSRestClientI;
import com.sun.jersey.api.client.config.DefaultClientConfig;
public class UniProtFTSRestClient extends FTSRestClient
+ implements ApplicationSingletonI
{
public static FTSRestClientI getInstance()
{
- Instance j = Instance.getInstance();
- return (j.uniprotFTSRestClient == null ? j.uniprotFTSRestClient = new UniProtFTSRestClient()
- : j.uniprotFTSRestClient);
+ return (FTSRestClientI) ApplicationSingletonProvider
+ .getInstance(UniProtFTSRestClient.class);
}
private UniProtFTSRestClient()
*/
if (align != null)
{
- Desktop.getStructureSelectionManager()
+ Desktop.getInstance().getStructureSelectionManager()
.registerMappings(align.getCodonFrames());
}
List<AlignedCodonFrame> mappings = al.getCodonFrames();
if (mappings != null)
{
- StructureSelectionManager ssm = Desktop
+ StructureSelectionManager ssm = Desktop.getInstance()
.getStructureSelectionManager();
for (AlignedCodonFrame acf : mappings)
{
@Override
public void sendSelection()
{
- Desktop.getStructureSelectionManager().sendSelection(
+ Desktop.getInstance().getStructureSelectionManager().sendSelection(
new SequenceGroup(getSelectionGroup()),
new ColumnSelection(getColumnSelection()),
new HiddenColumns(getAlignment().getHiddenColumns()), this);
@Override
public StructureSelectionManager getStructureSelectionManager()
{
- return Desktop.getStructureSelectionManager();
+ return Desktop.getInstance().getStructureSelectionManager();
}
@Override
{
PDBEntry entry = new PDBEntry();
StructureFile pdbfile = null;
- pdbfile = Desktop.getStructureSelectionManager().setMapping(false,
- new SequenceI[]
+ pdbfile = Desktop.getInstance().getStructureSelectionManager()
+ .setMapping(false, new SequenceI[]
{ sequence }, null, fileName, type);
if (pdbfile == null)
{
entry.setType(PDBEntry.Type.FILE);
entry.setFile(fileName);
sequence.getDatasetSequence().addPDBId(entry);
- Desktop.getStructureSelectionManager().registerPDBEntry(entry);
+ Desktop.getInstance().getStructureSelectionManager()
+ .registerPDBEntry(entry);
return entry;
}
}
* register any new mappings for sequence mouseover etc
* (will not duplicate any previously registered mappings)
*/
- Desktop.getStructureSelectionManager()
+ Desktop.getInstance().getStructureSelectionManager()
.registerMappings(dataset.getCodonFrames());
if (copyAlignment.getHeight() <= 0)
import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
+import jalview.api.StructureSelectionManagerProvider;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.bin.Cache;
-import jalview.bin.Instance;
import jalview.bin.Jalview;
import jalview.gui.ImageExporter.ImageWriterI;
import jalview.io.BackupFiles;
import jalview.io.IdentifyFile;
import jalview.io.JalviewFileChooser;
import jalview.io.JalviewFileView;
+import jalview.jbgui.GDesktop;
import jalview.jbgui.GSplitFrame;
import jalview.jbgui.GStructureViewer;
import jalview.project.Jalview2XML;
* @version $Revision: 1.155 $
*/
@SuppressWarnings("serial")
-public class Desktop extends jalview.jbgui.GDesktop
+public class Desktop extends GDesktop
implements DropTargetListener, ClipboardOwner, IProgressIndicator,
- jalview.api.StructureSelectionManagerProvider
+ StructureSelectionManagerProvider, ApplicationSingletonI
{
private final static int DEFAULT_MIN_WIDTH = 300;
return Desktop.getInstance().desktopPane;
}
- public static StructureSelectionManager getStructureSelectionManager()
+ public StructureSelectionManager getStructureSelectionManager()
{
return StructureSelectionManager
- .getStructureSelectionManager(Desktop.getInstance());
+ .getStructureSelectionManager(this);
}
static int openFrameCount = 0;
public MyDesktopPane desktopPane;
+ /**
+ * Answers an 'application scope' singleton instance of this class. Separate
+ * SwingJS 'applets' running in the same browser page will each have a
+ * distinct instance of Desktop.
+ *
+ * @return
+ */
public static Desktop getInstance()
{
- Instance i = Instance.getInstance();
- return (i.desktop == null ? (i.desktop = new Desktop(true))
- : i.desktop);
+ return (Desktop) ApplicationSingletonProvider
+ .getInstance(Desktop.class);
}
/**
{
instanceOnly = true;
}
+
/**
- * Creates a new Desktop object.
+ * Private constructor enforces singleton pattern. It is called by reflection
+ * from ApplicationSingletonProvider.getInstance().
*/
- public Desktop()
+ @SuppressWarnings("unused")
+ private Desktop()
{
/**
* A note to implementors. It is ESSENTIAL that any activities that might
* block are spawned off as threads rather than waited for during this
* constructor.
*/
- Instance.getInstance().desktop = this;
-
if (!Platform.isJS())
{
doVamsasClientCheck();
}
-
+
doConfigureStructurePrefs();
setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
boolean showjconsole = jalview.bin.Cache.getDefault("SHOW_JAVA_CONSOLE",
false);
desktopPane = new MyDesktopPane(selmemusage);
-
+
showMemusage.setSelected(selmemusage);
desktopPane.setBackground(Color.white);
getContentPane().setLayout(new BorderLayout());
// JScrollPane sp = new JScrollPane();
// sp.getViewport().setView(desktop);
// getContentPane().add(sp, BorderLayout.CENTER);
-
+
// BH 2018 - just an experiment to try unclipped JInternalFrames.
if (Platform.isJS())
{
getRootPane().putClientProperty("swingjs.overflow.hidden", "false");
}
-
+
getContentPane().add(desktopPane, BorderLayout.CENTER);
desktopPane.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
-
+
// This line prevents Windows Look&Feel resizing all new windows to maximum
// if previous window was maximised
desktopPane.setDesktopManager(new MyDesktopManager(
? new AquaInternalFrameManager(
desktopPane.getDesktopManager())
: desktopPane.getDesktopManager())));
-
+
Rectangle dims = getLastKnownDimensions("");
if (dims != null)
{
int yPos = Math.max(5, (screenSize.height - 650) / 2);
setBounds(xPos, yPos, 900, 650);
}
-
+
if (!Platform.isJS())
/**
* Java only
* @j2sIgnore
*/
{
-
+
jconsole = new Console(this, showjconsole);
// add essential build information
jconsole.setHeader("Jalview Version: "
+ System.getProperty("os.arch") + " "
+ System.getProperty("os.name") + " "
+ System.getProperty("os.version"));
-
+
showConsole(showjconsole);
-
+
showNews.setVisible(false);
-
+
experimentalFeatures.setSelected(showExperimental());
-
+
getIdentifiersOrgData();
-
+
checkURLLinks();
-
+
// Spawn a thread that shows the splashscreen
-
+
SwingUtilities.invokeLater(new Runnable()
{
@Override
new SplashScreen();
}
});
-
+
// Thread off a new instance of the file chooser - this reduces the time
// it
// takes to open it later on.
changeSupport.addJalviewPropertyChangeListener("services",
new PropertyChangeListener()
{
-
+
@Override
public void propertyChange(PropertyChangeEvent evt)
{
+ evt.getNewValue());
JalviewServicesChanged(evt);
}
-
+
});
-
+
}
-
+
this.setDropTarget(new java.awt.dnd.DropTarget(desktopPane, this));
-
+
this.addWindowListener(new WindowAdapter()
{
@Override
quit();
}
});
-
+
MouseAdapter ma;
this.addMouseListener(ma = new MouseAdapter()
{
showPasteMenu(evt.getX(), evt.getY());
}
}
-
+
@Override
public void mouseReleased(MouseEvent evt)
{
}
});
desktopPane.addMouseListener(ma);
-
}
/**
}
}
}).start();
- ;
+
}
@Override
menuItem.removeActionListener(menuItem.getActionListeners()[0]);
}
Desktop.getInstance().windowMenu.remove(menuItem);
- };
+ }
});
menuItem.addActionListener(new ActionListener()
});
rthr.start();
}
- };
+ }
});
VamsasStMenu.add(sessit);
}
} catch (InterruptedException x)
{
}
- ;
}
if (instanceOnly)
{
System.err.println(
"Please ignore plist error - occurs due to problem with java 8 on OSX");
}
- ;
}
} catch (Throwable ex)
{
{
// TODO if CommandListener is only ever 1:1 for complementary views,
// may change broadcast pattern to direct messaging (more efficient)
- final StructureSelectionManager ssm = Desktop
+ final StructureSelectionManager ssm = Desktop.getInstance()
.getStructureSelectionManager();
ssm.addCommandListener(((AlignFrame) getTopFrame()).getViewport());
ssm.addCommandListener(((AlignFrame) getBottomFrame()).getViewport());
public void internalFrameClosed(InternalFrameEvent evt)
{
close();
- };
+ }
});
}
*/
adjustLayout();
- final StructureSelectionManager ssm = Desktop
+ final StructureSelectionManager ssm = Desktop.getInstance()
.getStructureSelectionManager();
ssm.addCommandListener(newTopPanel.av);
ssm.addCommandListener(newBottomPanel.av);
try
{
IPickManager pm = vclient.getPickManager();
- StructureSelectionManager ssm = Desktop
+ StructureSelectionManager ssm = Desktop.getInstance()
.getStructureSelectionManager();
VamsasApplication me = this;
pm.registerMessageHandler(new IMessageHandler()
{
type = jvobjs[o].getClass();
}
- ;
if (type != jvobjs[o].getClass())
{
send = false;
{
jvobjs[c] = null;
}
- ;
jvobjs = null;
return;
}
*/
package jalview.httpserver;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.rest.RestHandler;
import java.net.BindException;
* @author gmcarstairs
* @see http://eclipse.org/jetty/documentation/current/embedding-jetty.html
*/
-public class HttpServer
+public class HttpServer implements ApplicationSingletonI
{
/**
{
synchronized (HttpServer.class)
{
- Instance j = Instance.getInstance();
- return (j.httpServer == null ? j.httpServer = new HttpServer()
- : j.httpServer);
+ return (HttpServer) ApplicationSingletonProvider.getInstance(HttpServer.class);
}
}
*/
package jalview.io;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import java.util.ArrayList;
import java.util.HashSet;
* @author gmcarstairs
*
*/
-public class FileFormats
+public class FileFormats implements ApplicationSingletonI
{
public static FileFormats getInstance()
{
- Instance i = Instance.getInstance();
- return (i.fileFormats == null ? i.fileFormats = new FileFormats()
- : i.fileFormats);
+ return (FileFormats) ApplicationSingletonProvider.getInstance(FileFormats.class);
}
/**
{
// register PDB entries with desktop's structure selection
// manager
- Desktop.getStructureSelectionManager()
+ Desktop.getInstance().getStructureSelectionManager()
.registerPDBEntry(pdbe);
}
}
{
dssmods.addElement(sequence);
}
- ;
}
if (dssmods.size() > 0)
{
(AlignmentSequence) alsref, aa[i]);
break;
}
- ;
}
}
}
// active
if (mappings != null)
{
- Desktop.getStructureSelectionManager()
+ Desktop.getInstance().getStructureSelectionManager()
.registerMappings(mappings);
}
}
package jalview.io.cache;
import jalview.bin.Cache;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import java.util.Hashtable;
import java.util.LinkedHashSet;
* @author tcnofoegbu
*
*/
-public class AppCache
+public class AppCache implements ApplicationSingletonI
{
public static AppCache getInstance()
{
- Instance j = Instance.getInstance();
- return (j.appCache == null ? j.appCache = new AppCache() : j.appCache);
+ return (AppCache) ApplicationSingletonProvider.getInstance(AppCache.class);
}
private AppCache()
*/
package jalview.io.gff;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
/**
* A factory class that returns a model of the Sequence Ontology. By default a
- * hard-coded subset is used (for the applet, or testing), or setInstance() can
- * be used to set full Ontology data.
+ * hard-coded subset is used (for the applet, or testing), or
+ * setSequenceOntology() can be used to set full Ontology data.
*
* @author gmcarstairs
*
*/
-public class SequenceOntologyFactory
+public class SequenceOntologyFactory implements ApplicationSingletonI
{
+ /**
+ * Answers an instance of this class for the current application context. Note
+ * that this supports running two JS 'applets' on the same page, one with the
+ * full Sequence Ontology (USE_FULL_SO = true) and one with a hard-coded
+ * subset (USE_FULL_SO = false). If this is overkill, could change this method
+ * to just return a common static instance.
+ *
+ * @return
+ */
+ private static synchronized SequenceOntologyFactory getInstance()
+ {
+ return (SequenceOntologyFactory) ApplicationSingletonProvider
+ .getInstance(SequenceOntologyFactory.class);
+ }
+ /**
+ * Answers the configured model of the Sequence Ontology.
+ *
+ * @return
+ */
public static synchronized SequenceOntologyI getSequenceOntology()
{
- SequenceOntologyFactory j = getInstance();
- return (j.sequenceOntology == null
- ? j.sequenceOntology = new SequenceOntologyLite()
- : j.sequenceOntology);
+ SequenceOntologyFactory f = getInstance();
+ return (f.sequenceOntology == null
+ ? f.sequenceOntology = new SequenceOntologyLite()
+ : f.sequenceOntology);
}
/**
*
* @param so
*/
- public static void setInstance(SequenceOntologyI so)
+ public static void setSequenceOntology(SequenceOntologyI so)
{
getInstance().sequenceOntology = so;
}
// private singleton
}
- private static synchronized SequenceOntologyFactory getInstance()
- {
- Instance j = Instance.getInstance();
- return (j.sequenceOntologyFactory == null
- ? j.sequenceOntologyFactory = new SequenceOntologyFactory()
- : j.sequenceOntologyFactory);
- }
-
}
acf.addMap(from, to, mapping);
}
bindjvvobj(mapping, sequenceMapping);
- Desktop.getStructureSelectionManager().registerMapping(acf);
+ Desktop.getInstance().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.
{
if (ds.getCodonFrames() != null)
{
- Desktop.getStructureSelectionManager()
+ Desktop.getInstance().getStructureSelectionManager()
.registerMappings(ds.getCodonFrames());
}
}
{
entry.setProperty(prop.getName(), prop.getValue());
}
- Desktop.getStructureSelectionManager().registerPDBEntry(entry);
+ Desktop.getInstance().getStructureSelectionManager()
+ .registerPDBEntry(entry);
// adds PDBEntry to datasequence's set (since Jalview 2.10)
if (al.getSequenceAt(i).getDatasetSequence() != null)
{
*/
package jalview.rest;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.httpserver.AbstractRequestHandler;
import java.io.IOException;
* Accessed only by HttpServer.
*/
public class RestHandler extends AbstractRequestHandler
+ implements ApplicationSingletonI
{
private static final String MY_PATH = "rest";
{
synchronized (RestHandler.class)
{
- Instance j = Instance.getInstance();
- return (j.restHandler == null ? j.restHandler = new RestHandler()
- : j.restHandler);
+ return (RestHandler) ApplicationSingletonProvider.getInstance(RestHandler.class);
}
}
package jalview.schemes;
import jalview.api.AlignViewportI;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.datamodel.AnnotatedCollectionI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
import java.util.LinkedHashMap;
import java.util.Map;
-public class ColourSchemes
+public class ColourSchemes implements ApplicationSingletonI
{
/**
*/
public static ColourSchemes getInstance()
{
- Instance j = Instance.getInstance();
- return (j.colourSchemes == null ? j.colourSchemes = new ColourSchemes()
- : j.colourSchemes);
+ return (ColourSchemes) ApplicationSingletonProvider
+ .getInstance(ColourSchemes.class);
}
private ColourSchemes()
*/
package jalview.structure;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.PDBEntry.Type;
* @author tcofoegbu
*
*/
-public class StructureImportSettings
+public class StructureImportSettings implements ApplicationSingletonI
{
private StructureImportSettings()
private static StructureImportSettings getInstance()
{
- Instance j = Instance.getInstance();
- return (j.structureImportSettings == null
- ? j.structureImportSettings = new StructureImportSettings()
- : j.structureImportSettings);
+ return (StructureImportSettings) ApplicationSingletonProvider
+ .getInstance(StructureImportSettings.class);
}
/**
import jalview.analysis.AlignSeq;
import jalview.api.StructureSelectionManagerProvider;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.commands.CommandI;
import jalview.commands.EditCommand;
import jalview.commands.OrderCommand;
import mc_view.PDBChain;
import mc_view.PDBfile;
-public class StructureSelectionManager
+public class StructureSelectionManager implements ApplicationSingletonI
{
+ public final static String NEWLINE = System.lineSeparator();
+
+ private List<StructureMapping> mappings = new ArrayList<>();
+
+ private boolean processSecondaryStructure = false;
+
+ private boolean secStructServices = false;
+
+ private boolean addTempFacAnnot = false;
+
+ /*
+ * Set of any registered mappings between (dataset) sequences.
+ */
+ private List<AlignedCodonFrame> seqmappings = new ArrayList<>();
+
+ private List<CommandListener> commandListeners = new ArrayList<>();
+
+ private List<SelectionListener> sel_listeners = new ArrayList<>();
+ /*
+ * instances of this class scoped by some context class
+ */
+ private IdentityHashMap<StructureSelectionManagerProvider, StructureSelectionManager> structureSelections;
+
+ /**
+ * Answers an instance of this class for the current application (Java or JS
+ * 'applet') scope
+ *
+ * @return
+ */
+ private static StructureSelectionManager getInstance()
+ {
+ return (StructureSelectionManager) ApplicationSingletonProvider
+ .getInstance(StructureSelectionManager.class);
+ }
+
+ /**
+ * Answers an instance of this class for the current application (Java or JS
+ * 'applet') scope, and scoped to the specified context
+ *
+ * @param context
+ * @return
+ */
public static StructureSelectionManager getStructureSelectionManager(
StructureSelectionManagerProvider context)
{
- IdentityHashMap<StructureSelectionManagerProvider, StructureSelectionManager> map = Instance
- .getInstance().structureSelections;
+ return getInstance().getInstanceForContext(context);
+ }
- if (map == null)
- {
- map = Instance
- .getInstance().structureSelections = new IdentityHashMap<>();
- }
- StructureSelectionManager instance = map.get(context);
+ /**
+ * Answers an instance of this class scoped to the given context. The instance
+ * is created on the first request for the context, thereafter the same
+ * instance is returned.
+ *
+ * @param context
+ * @return
+ */
+ StructureSelectionManager getInstanceForContext(
+ StructureSelectionManagerProvider context)
+ {
+ StructureSelectionManager instance = structureSelections.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());
+ instance = new StructureSelectionManager();
+ structureSelections.put(context, instance);
}
return instance;
}
/**
- * release all references associated with this manager provider
+ * Removes the instance associated with this provider
*
* @param provider
*/
public static void release(StructureSelectionManagerProvider provider)
{
- IdentityHashMap<StructureSelectionManagerProvider, StructureSelectionManager> map = Instance
- .getInstance().structureSelections;
- if (map != null)
- {
- map.remove(provider);
- }
+ getInstance().structureSelections.remove(provider);
}
- public StructureSelectionManager()
+ /**
+ * Private constructor as all 'singleton' instances are managed here or by
+ * ApplicationSingletonProvider
+ */
+ private StructureSelectionManager()
{
+ structureSelections = new IdentityHashMap<>();
}
- public final static String NEWLINE = System.lineSeparator();
-
- // BH unnecessary; IdentityHashMap can handle this
- // private static StructureSelectionManager nullProvider;
-
- private List<StructureMapping> mappings = new ArrayList<>();
-
- private boolean processSecondaryStructure = false;
-
- private boolean secStructServices = false;
-
- private boolean addTempFacAnnot = false;
-
- /*
- * Set of any registered mappings between (dataset) sequences.
- */
- private List<AlignedCodonFrame> seqmappings = new ArrayList<>();
-
- private List<CommandListener> commandListeners = new ArrayList<>();
-
- private List<SelectionListener> sel_listeners = new ArrayList<>();
-
/**
* @return true if will try to use external services for processing secondary
* structure
{
ds = ds.getDatasetSequence();
}
- ;
if (ds.getAnnotation() != null)
{
for (AlignmentAnnotation ala : ds.getAnnotation())
{
slis.viewPosition(startRes, endRes, startSeq, endSeq, source);
}
- ;
}
}
}
package jalview.urls;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
/**
* Holds settings for identifiers.org e.g. url, download location
- *
- * @author $author$
- * @version $Revision$
*/
-public class IdOrgSettings
+public class IdOrgSettings implements ApplicationSingletonI
{
private IdOrgSettings()
private static IdOrgSettings getInstance()
{
- Instance j = Instance.getInstance();
- return (j.idOrgSettings == null ? j.idOrgSettings = new IdOrgSettings()
- : j.idOrgSettings);
+ return (IdOrgSettings) ApplicationSingletonProvider
+ .getInstance(IdOrgSettings.class);
}
private String url;
*/
package jalview.ws;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.datamodel.DBRefSource;
import jalview.ext.ensembl.EnsemblGene;
import jalview.ws.dbsources.Uniprot;
* instantiated by reflection and queried for their DbRefSource and version
* association.
*/
-public class SequenceFetcher extends ASequenceFetcher
+public class SequenceFetcher extends ASequenceFetcher implements ApplicationSingletonI
{
+ /*
+ * set a mock fetcher here for testing only - reset to null afterwards
+ */
+ private static SequenceFetcher mockFetcher;
/**
* Returns a new SequenceFetcher singleton, or a mock object if one has been
*/
public static SequenceFetcher getInstance()
{
- Instance j = Instance.getInstance();
- return (j.sequenceFetcher == null
- ? j.sequenceFetcher = new SequenceFetcher()
- : j.sequenceFetcher);
+ return mockFetcher != null ? mockFetcher
+ : (SequenceFetcher) ApplicationSingletonProvider
+ .getInstance(SequenceFetcher.class);
}
/**
*/
public static void setSequenceFetcher(SequenceFetcher sf)
{
- Instance.getInstance().sequenceFetcher = sf;
+ mockFetcher = sf;
}
/**
*/
package jalview.ws.jws1;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.gui.JvOptionPane;
import jalview.util.MessageManager;
import ext.vamsas.ServiceHandle;
import ext.vamsas.ServiceHandles;
-public class Discoverer implements Runnable
+public class Discoverer implements Runnable, ApplicationSingletonI
{
public static Discoverer getInstance()
{
- Instance j = Instance.getInstance();
- return (j.discoverer == null ? j.discoverer = new Discoverer()
- : j.discoverer);
+ return (Discoverer) ApplicationSingletonProvider.getInstance(Discoverer.class);
}
private Discoverer()
package jalview.ws.jws2;
import jalview.bin.Cache;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.gui.AlignFrame;
import jalview.gui.Desktop;
import jalview.gui.JvSwingUtils;
* @author JimP
*
*/
-public class Jws2Discoverer implements Runnable, WSMenuEntryProviderI
+public class Jws2Discoverer
+ implements Runnable, WSMenuEntryProviderI, ApplicationSingletonI
{
/**
*/
public static Jws2Discoverer getInstance()
{
- Instance j = Instance.getInstance();
- return (j.j2s2discoverer == null
- ? j.j2s2discoverer = new Jws2Discoverer()
- : j.j2s2discoverer);
+ return (Jws2Discoverer) ApplicationSingletonProvider
+ .getInstance(Jws2Discoverer.class);
}
/**
*/
package jalview.ws.jws2.jabaws2;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.ws.jws2.AAConClient;
import jalview.ws.jws2.RNAalifoldClient;
import jalview.ws.uimodel.AlignAnalysisUIText;
import compbio.data.msa.JABAService;
-public class Jws2InstanceFactory
+public class Jws2InstanceFactory implements ApplicationSingletonI
{
private Jws2InstanceFactory()
private static Jws2InstanceFactory getInstance()
{
- Instance j = Instance.getInstance();
- return (j.jws2InstanceFactory == null
- ? j.jws2InstanceFactory = new Jws2InstanceFactory()
- : j.jws2InstanceFactory);
+ return (Jws2InstanceFactory) ApplicationSingletonProvider
+ .getInstance(Jws2InstanceFactory.class);
}
private HashMap<String, AlignAnalysisUIText> aaConGUI;
package jalview.ws.rest;
import jalview.bin.Cache;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.datamodel.AlignmentView;
import jalview.gui.AlignFrame;
import jalview.gui.AlignViewport;
*
*/
public class RestClient extends WSClient
- implements WSClientI, WSMenuEntryProviderI
+ implements WSClientI, WSMenuEntryProviderI, ApplicationSingletonI
{
public static final String RSBS_SERVICES = "RSBS_SERVICES";
protected Vector<String> services = null;
+ private static RestClient getInstance()
+ {
+ return (RestClient) ApplicationSingletonProvider.getInstance(RestClient.class);
+ }
+
+ public static RestClient makeShmmrRestClient()
+ {
+ String action = "Analysis",
+ description = "Sequence Harmony and Multi-Relief (Brandt et al. 2010)",
+ name = MessageManager.getString("label.multiharmony");
+ Hashtable<String, InputType> iparams = new Hashtable<>();
+ // jalview.ws.rest.params.JobConstant toolp;
+ // toolp = new jalview.ws.rest.JobConstant("tool","jalview");
+ // iparams.put(toolp.token, toolp);
+ // toolp = new jalview.ws.rest.params.JobConstant("mbjob[method]","shmr");
+ // iparams.put(toolp.token, toolp);
+ // toolp = new
+ // jalview.ws.rest.params.JobConstant("mbjob[description]","step 1");
+ // iparams.put(toolp.token, toolp);
+ // toolp = new jalview.ws.rest.params.JobConstant("start_search","1");
+ // iparams.put(toolp.token, toolp);
+ // toolp = new jalview.ws.rest.params.JobConstant("blast","0");
+ // iparams.put(toolp.token, toolp);
+
+ jalview.ws.rest.params.Alignment aliinput = new jalview.ws.rest.params.Alignment();
+ // SHMR server has a 65K limit for content pasted into the 'ali' parameter,
+ // so we always upload our files.
+ aliinput.token = "ali_file";
+ aliinput.writeAsFile = true;
+ iparams.put(aliinput.token, aliinput);
+ jalview.ws.rest.params.SeqGroupIndexVector sgroups = new jalview.ws.rest.params.SeqGroupIndexVector();
+ sgroups.setMinsize(2);
+ sgroups.min = 2;// need at least two group defined to make a partition
+ iparams.put("groups", sgroups);
+ sgroups.token = "groups";
+ sgroups.sep = " ";
+ RestServiceDescription shmrService = new RestServiceDescription(action,
+ description, name,
+ "http://zeus.few.vu.nl/programs/shmrwww/index.php?tool=jalview", // ?tool=jalview&mbjob[method]=shmr&mbjob[description]=step1",
+ "?tool=jalview", iparams, true, false, '-');
+ // a priori knowledge of the data returned from the service
+ shmrService.addResultDatatype(JvDataType.ANNOTATION);
+ return new RestClient(shmrService);
+ }
+
+ public static RestClient[] getRestClients()
+ {
+ RestClient c = getInstance();
+
+ if (c.services == null)
+ {
+ c.services = new Vector<>();
+ try
+ {
+ for (RestServiceDescription descr : RestServiceDescription
+ .parseDescriptions(
+ jalview.bin.Cache.getDefault(RSBS_SERVICES,
+ makeShmmrRestClient().service.toString())))
+ {
+ c.services.add(descr.toString());
+ }
+ } catch (Exception ex)
+ {
+ System.err.println(
+ "Serious - RSBS descriptions in user preferences are corrupt!");
+ ex.printStackTrace();
+ }
+
+ }
+ RestClient[] lst = new RestClient[c.services.size()];
+ int i = 0;
+ for (String svc : c.services)
+ {
+ lst[i++] = new RestClient(new RestServiceDescription(svc));
+ }
+ return lst;
+ }
+
+ public static Vector<String> getRsbsDescriptions()
+ {
+ Vector<String> rsbsDescrs = new Vector<>();
+ for (RestClient rsbs : getRestClients())
+ {
+ rsbsDescrs.add(rsbs.getRestDescription().toString());
+ }
+ return rsbsDescrs;
+ }
+
+ public static void setRsbsServices(Vector<String> rsbsUrls)
+ {
+ if (rsbsUrls != null)
+ {
+ // TODO: consider validating services ?
+ RestClient c = getInstance();
+ c.services = new Vector<>(rsbsUrls);
+ StringBuffer sprop = new StringBuffer();
+ for (String s : c.services)
+ {
+ sprop.append(s);
+ }
+ Cache.setProperty(RSBS_SERVICES, sprop.toString());
+ }
+ else
+ {
+ Cache.removeProperty(RSBS_SERVICES);
+ }
+ }
+
/**
* get the alignFrame for the associated input data if it exists.
*
return jalview.gui.Desktop.getAlignFrameFor(av);
}
- private static RestClient getInstance()
- {
- Instance j = Instance.getInstance();
- return (j.restClient == null ? j.restClient = new RestClient()
- : j.restClient);
- }
-
private RestClient()
{
}
}
- public static RestClient makeShmmrRestClient()
- {
- String action = "Analysis",
- description = "Sequence Harmony and Multi-Relief (Brandt et al. 2010)",
- name = MessageManager.getString("label.multiharmony");
- Hashtable<String, InputType> iparams = new Hashtable<>();
- // jalview.ws.rest.params.JobConstant toolp;
- // toolp = new jalview.ws.rest.JobConstant("tool","jalview");
- // iparams.put(toolp.token, toolp);
- // toolp = new jalview.ws.rest.params.JobConstant("mbjob[method]","shmr");
- // iparams.put(toolp.token, toolp);
- // toolp = new
- // jalview.ws.rest.params.JobConstant("mbjob[description]","step 1");
- // iparams.put(toolp.token, toolp);
- // toolp = new jalview.ws.rest.params.JobConstant("start_search","1");
- // iparams.put(toolp.token, toolp);
- // toolp = new jalview.ws.rest.params.JobConstant("blast","0");
- // iparams.put(toolp.token, toolp);
-
- jalview.ws.rest.params.Alignment aliinput = new jalview.ws.rest.params.Alignment();
- // SHMR server has a 65K limit for content pasted into the 'ali' parameter,
- // so we always upload our files.
- aliinput.token = "ali_file";
- aliinput.writeAsFile = true;
- iparams.put(aliinput.token, aliinput);
- jalview.ws.rest.params.SeqGroupIndexVector sgroups = new jalview.ws.rest.params.SeqGroupIndexVector();
- sgroups.setMinsize(2);
- sgroups.min = 2;// need at least two group defined to make a partition
- iparams.put("groups", sgroups);
- sgroups.token = "groups";
- sgroups.sep = " ";
- RestServiceDescription shmrService = new RestServiceDescription(action,
- description, name,
- "http://zeus.few.vu.nl/programs/shmrwww/index.php?tool=jalview", // ?tool=jalview&mbjob[method]=shmr&mbjob[description]=step1",
- "?tool=jalview", iparams, true, false, '-');
- // a priori knowledge of the data returned from the service
- shmrService.addResultDatatype(JvDataType.ANNOTATION);
- return new RestClient(shmrService);
- }
-
public AlignmentPanel recoverAlignPanelForView()
{
AlignmentPanel[] aps = Desktop
return true;
}
- public static RestClient[] getRestClients()
- {
- RestClient c = getInstance();
-
- if (c.services == null)
- {
- c.services = new Vector<>();
- try
- {
- for (RestServiceDescription descr : RestServiceDescription
- .parseDescriptions(
- jalview.bin.Cache.getDefault(RSBS_SERVICES,
- makeShmmrRestClient().service.toString())))
- {
- c.services.add(descr.toString());
- }
- } catch (Exception ex)
- {
- System.err.println(
- "Serious - RSBS descriptions in user preferences are corrupt!");
- ex.printStackTrace();
- }
-
- }
- RestClient[] lst = new RestClient[c.services.size()];
- int i = 0;
- for (String svc : c.services)
- {
- lst[i++] = new RestClient(new RestServiceDescription(svc));
- }
- return lst;
- }
-
public String getAction()
{
return service.details.Action;
return service;
}
- public static Vector<String> getRsbsDescriptions()
- {
- Vector<String> rsbsDescrs = new Vector<>();
- for (RestClient rsbs : getRestClients())
- {
- rsbsDescrs.add(rsbs.getRestDescription().toString());
- }
- return rsbsDescrs;
- }
-
- public static void setRsbsServices(Vector<String> rsbsUrls)
- {
- if (rsbsUrls != null)
- {
- // TODO: consider validating services ?
- RestClient c = getInstance();
- c.services = new Vector<>(rsbsUrls);
- StringBuffer sprop = new StringBuffer();
- for (String s : c.services)
- {
- sprop.append(s);
- }
- Cache.setProperty(RSBS_SERVICES, sprop.toString());
- }
- else
- {
- Cache.removeProperty(RSBS_SERVICES);
- }
- }
-
}
*/
package jalview.ws.sifts;
-import jalview.bin.Instance;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import java.util.Objects;
-public class SiftsSettings
+public class SiftsSettings implements ApplicationSingletonI
{
/**
*/
public static SiftsSettings getInstance()
{
- {
- Instance j = Instance.getInstance();
- return (j.siftsSettings == null
- ? j.siftsSettings = new SiftsSettings()
- : j.siftsSettings);
- }
-
+ return (SiftsSettings) ApplicationSingletonProvider
+ .getInstance(SiftsSettings.class);
}
private SiftsSettings()
@BeforeClass(groups = "Functional")
public void setUp()
{
+ Cache.initLogger();
Cache.loadProperties("test/jalview/io/testProps.jvprops");
Cache.setPropertyNoSave("PAD_GAPS",
Boolean.FALSE.toString());
import jalview.api.analysis.PairwiseScoreModelI;
import jalview.api.analysis.ScoreModelI;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
import org.testng.annotations.Test;
}
}
}
+
+ @Test(groups = "Functional")
+ public void testInstantiate()
+ throws InstantiationException, IllegalAccessException,
+ NoSuchMethodException, SecurityException,
+ IllegalArgumentException, InvocationTargetException
+ {
+ Class<? extends Object> c = ScoreModels.class;
+ Constructor<? extends Object> con = c.getDeclaredConstructor();
+ con.setAccessible(true);
+ Object o = con.newInstance();
+ System.out.println(o);
+ }
}
@BeforeClass(alwaysRun = true)
public void setUp()
{
- SequenceOntologyFactory.setInstance(new SequenceOntologyLite());
+ SequenceOntologyFactory.setSequenceOntology(new SequenceOntologyLite());
}
@AfterClass(alwaysRun = true)
public void tearDown()
{
- SequenceOntologyFactory.setInstance(null);
+ SequenceOntologyFactory.setSequenceOntology(null);
}
/**
@BeforeClass(alwaysRun = true)
public void setUp()
{
- SequenceOntologyFactory.setInstance(new SequenceOntologyLite());
+ SequenceOntologyFactory.setSequenceOntology(new SequenceOntologyLite());
}
@AfterClass(alwaysRun = true)
public void tearDown()
{
- SequenceOntologyFactory.setInstance(null);
+ SequenceOntologyFactory.setSequenceOntology(null);
}
/**
public void setUp()
{
Cache.loadProperties("test/jalview/io/testProps.jvprops");
- SequenceOntologyFactory.setInstance(new SequenceOntologyLite());
+ SequenceOntologyFactory.setSequenceOntology(new SequenceOntologyLite());
}
@AfterClass(alwaysRun = true)
public void tearDown()
{
- SequenceOntologyFactory.setInstance(null);
+ SequenceOntologyFactory.setSequenceOntology(null);
}
/**
@BeforeClass(alwaysRun = true)
public void setUp()
{
- SequenceOntologyFactory.setInstance(new SequenceOntologyLite());
+ SequenceOntologyFactory.setSequenceOntology(new SequenceOntologyLite());
}
@AfterClass(alwaysRun = true)
public void tearDown()
{
- SequenceOntologyFactory.setInstance(null);
+ SequenceOntologyFactory.setSequenceOntology(null);
}
/**
@BeforeClass(alwaysRun = true)
public void setUp()
{
- SequenceOntologyFactory.setInstance(new SequenceOntologyLite());
+ SequenceOntologyFactory.setSequenceOntology(new SequenceOntologyLite());
}
@AfterClass(alwaysRun = true)
public void tearDown()
{
- SequenceOntologyFactory.setInstance(null);
+ SequenceOntologyFactory.setSequenceOntology(null);
}
@DataProvider(name = "ens_seqs")
SequenceRenderer sr = new SequenceRenderer(af.getViewport());
SequenceI[][] seqs = new SequenceI[][] { { seq1 }, { seq2 } };
String[] files = new String[] { "seq1.pdb", "seq2.pdb" };
- StructureSelectionManager ssm = new StructureSelectionManager();
+ StructureSelectionManager ssm = StructureSelectionManager
+ .getStructureSelectionManager(null);
// need some mappings!
SequenceRenderer sr = new SequenceRenderer(af.getViewport());
SequenceI[][] seqs = new SequenceI[][] { { seq1 }, { seq2 } };
String[] files = new String[] { "seq1.pdb", "seq2.pdb" };
- StructureSelectionManager ssm = new StructureSelectionManager();
+ StructureSelectionManager ssm = StructureSelectionManager
+ .getStructureSelectionManager(null);
/*
* map residues 1-10 to residues 21-30 (atoms 105-150) in structures
*/
- HashMap<Integer, int[]> map = new HashMap<Integer, int[]>();
+ HashMap<Integer, int[]> map = new HashMap<>();
for (int pos = 1; pos <= seq1.getLength(); pos++)
{
map.put(pos, new int[] { 20 + pos, 5 * (20 + pos) });
public void testBuildColourCommands()
{
- Map<Object, AtomSpecModel> map = new LinkedHashMap<Object, AtomSpecModel>();
+ Map<Object, AtomSpecModel> map = new LinkedHashMap<>();
ChimeraCommands.addColourRange(map, Color.blue, 0, 2, 5, "A");
ChimeraCommands.addColourRange(map, Color.blue, 0, 7, 7, "B");
ChimeraCommands.addColourRange(map, Color.blue, 0, 9, 23, "A");
/*
* make a map of { featureType, {featureValue, {residue range specification } } }
*/
- Map<String, Map<Object, AtomSpecModel>> featuresMap = new LinkedHashMap<String, Map<Object, AtomSpecModel>>();
- Map<Object, AtomSpecModel> featureValues = new HashMap<Object, AtomSpecModel>();
+ Map<String, Map<Object, AtomSpecModel>> featuresMap = new LinkedHashMap<>();
+ Map<Object, AtomSpecModel> featureValues = new HashMap<>();
/*
* start with just one feature/value...
SequenceRenderer sr = new SequenceRenderer(af.getViewport());
SequenceI[][] seqs = new SequenceI[][] { { seq1 }, { seq2 } };
String[] files = new String[] { "seq1.pdb", "seq2.pdb" };
- StructureSelectionManager ssm = new StructureSelectionManager();
+ StructureSelectionManager ssm = StructureSelectionManager
+ .getStructureSelectionManager(null);
/*
* map residues 1-10 to residues 21-30 (atoms 105-150) in structures
*/
- HashMap<Integer, int[]> map = new HashMap<Integer, int[]>();
+ HashMap<Integer, int[]> map = new HashMap<>();
for (int pos = 1; pos <= seq1.getLength(); pos++)
{
map.put(pos, new int[] { 20 + pos, 5 * (20 + pos) });
/*
* remove any sequence mappings left lying around by other tests
*/
- Desktop.getStructureSelectionManager().resetAll();
+ Desktop.getInstance().getStructureSelectionManager().resetAll();
}
@BeforeMethod(alwaysRun = true)
* Verify that creating the alignment for the new View has registered the
* mappings
*/
- List<AlignedCodonFrame> sequenceMappings = Desktop
+ List<AlignedCodonFrame> sequenceMappings = Desktop.getInstance()
.getStructureSelectionManager().getSequenceMappings();
assertEquals(2, sequenceMappings.size());
assertTrue(sequenceMappings.contains(acf1));
{
Desktop d = Desktop.getInstance();
assertNotNull(d);
- StructureSelectionManager ssm = Desktop.getStructureSelectionManager();
+ StructureSelectionManager ssm = Desktop.getInstance()
+ .getStructureSelectionManager();
ssm.resetAll();
AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
{
Desktop d = Desktop.getInstance();
assertNotNull(d);
- StructureSelectionManager ssm = Desktop.getStructureSelectionManager();
+ StructureSelectionManager ssm = Desktop.getInstance()
+ .getStructureSelectionManager();
ssm.resetAll();
AlignFrame af1 = new FileLoader().LoadFileWaitTillLoaded(
{
c++;
}
- ;
Assert.assertEquals(c, 1, "Expected to find one occupancy row.");
}
/*
* remove any sequence mappings created so they don't pollute other tests
*/
- Desktop.getStructureSelectionManager().resetAll();
+ Desktop.getInstance().getStructureSelectionManager().resetAll();
}
@BeforeClass(alwaysRun = true)
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
-import org.testng.annotations.BeforeTest;
+import org.testng.annotations.BeforeMethod;
public class Jalview2xmlBase
{
*/
Cache.loadProperties("test/jalview/io/testProps.jvprops");
+ Cache.initLogger();
+
/*
* set news feed last read to a future time to ensure no
* 'unread' news item is displayed
jalview.gui.Desktop.getInstance().closeAll_actionPerformed(null);
}
- @BeforeTest(alwaysRun = true)
+ @BeforeMethod(alwaysRun = true)
public static void clearDesktop()
{
if (Desktop.getInstance() != null && Desktop.getFrames() != null
import static org.testng.Assert.assertTrue;
import jalview.api.FeatureColourI;
+import jalview.bin.Cache;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
import jalview.gui.AlignFrame;
@BeforeTest(alwaysRun = true)
public void setUp()
{
+ Cache.initLogger();
// aligned column 8 is sequence position 6
String s = ">s1\nABCDE---FGHIJKLMNOPQRSTUVWXYZ\n";
af = new FileLoader().LoadFileWaitTillLoaded(s,
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
+import jalview.bin.Cache;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.Annotation;
import jalview.datamodel.Sequence;
public class Mapping
{
+ @BeforeClass(alwaysRun = true)
+ public void setUp()
+ {
+ Cache.initLogger();
+ }
@BeforeClass(alwaysRun = true)
public void setUpJvOptionPane()
int coils[] = { 266, 275, 278, 287, 289, 298, 302, 316 }, helices[] = new int[]
{ 303, 315 }, sheets[] = new int[] { 267, 268, 269, 270 };
- StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
+ StructureSelectionManager ssm = StructureSelectionManager
+ .getStructureSelectionManager(null);
StructureFile pmap = ssm.setMapping(true, new SequenceI[] { uprot },
new String[] { "A" }, "test/jalview/ext/jmol/1QCF.pdb",
DataSourceType.FILE);
"EIVKGVCSNFLCDLQPGDNVQITGPVGKEMLMPKDPNATIIMLATGTGIAPFRSFLWKMFFEKHDDYKFNGLGWLFLGVPTSSSLLYKEEFGKM");
Sequence sq1 = new Sequence(sq);
String inFile;
- StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
+ StructureSelectionManager ssm = StructureSelectionManager
+ .getStructureSelectionManager(null);
// Associate the 1GAQ pdb file with the subsequence 'imported' from another
// source
StructureFile pde = ssm.setMapping(true, new SequenceI[] { sq },
">FER1_MAIZE/1-150 Ferredoxin-1, chloroplast precursor\nMATVLGSPRAPAFFFSSSSLRAAPAPTAVALPAAKVGIMGRSASSRRRLRAQATYNVKLITPEGEVELQVPD\nDVYILDQAEEDGIDLPYSCRAGSCSSCAGKVVSGSVDQSDQSYLDDGQIADGWVLTCHAYPTSDVVIETHKE\nEELTGA",
DataSourceType.PASTE, FileFormat.Fasta);
SequenceI newseq = seqf.getViewport().getAlignment().getSequenceAt(0);
- StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
+ StructureSelectionManager ssm = StructureSelectionManager
+ .getStructureSelectionManager(null);
StructureFile pmap = ssm.setMapping(true, new SequenceI[] { newseq },
new String[] { null }, "examples/3W5V.pdb",
DataSourceType.FILE);
// make it harder by shifting the copy vs the reference
newseq.setStart(refseq.getStart() + 25);
newseq.setEnd(refseq.getLength() + 25 + refseq.getStart());
- StructureSelectionManager ssm = new jalview.structure.StructureSelectionManager();
+ StructureSelectionManager ssm = StructureSelectionManager
+ .getStructureSelectionManager(null);
ssm.setProcessSecondaryStructure(true);
ssm.setAddTempFacAnnot(true);
StructureFile pmap = ssm.setMapping(true, new SequenceI[] { newseq },
public void setUp()
{
StructureImportSettings.setShowSeqFeatures(true);
- ssm = new StructureSelectionManager();
+ StructureSelectionManager.release(null);
+ ssm = StructureSelectionManager.getStructureSelectionManager(null);
}
@Test(groups = { "Functional" })
acf3.addMap(new Sequence("s3", "ttt"), new Sequence("p3", "p"),
new MapList(new int[] { 1, 3 }, new int[] { 1, 1 }, 1, 1));
- List<AlignedCodonFrame> set1 = new ArrayList<AlignedCodonFrame>();
+ List<AlignedCodonFrame> set1 = new ArrayList<>();
set1.add(acf1);
set1.add(acf2);
- List<AlignedCodonFrame> set2 = new ArrayList<AlignedCodonFrame>();
+ List<AlignedCodonFrame> set2 = new ArrayList<>();
set2.add(acf2);
set2.add(acf3);
SequenceI seq = new Sequence(
"1GAQ|B",
"ATYNVKLITPEGEVELQVPDDVYILDQAEEDGIDLPYSCRAGSCSSCAGKVVSGSVDQSDQSYLDDGQIADGWVLTCHAYPTSDVVIETHKEEELTGA");
- StructureSelectionManager sm = new StructureSelectionManager();
+ StructureSelectionManager sm = StructureSelectionManager
+ .getStructureSelectionManager(null);
sm.setProcessSecondaryStructure(true);
sm.setAddTempFacAnnot(true);
StructureFile pmap = sm.setMapping(true, new SequenceI[] { seq },
Desktop.getInstance().closeAll_actionPerformed(null);
try {
Thread.sleep(200);
- } catch (Exception foo) {};
+ } catch (Exception foo) {}
SequenceI seq = new Sequence("4IM2|A",
"LDFCIRNIEKTVMGEISDIHTKLLRLSSSQGTIE");
String P4IM2_MISSING = "examples/testdata/4IM2_missing.pdb";
- StructureSelectionManager sm = new StructureSelectionManager();
+ StructureSelectionManager sm = StructureSelectionManager
+ .getStructureSelectionManager(null);
sm.setProcessSecondaryStructure(true);
sm.setAddTempFacAnnot(true);
StructureFile pmap = sm.setMapping(true, new SequenceI[] { seq },
">TBK1_HUMAN/470-502 Serine/threonine-protein kinase TBK1\nFCIRNIEKTVKVYEKLMKINLEAAELGEISDIH",
DataSourceType.PASTE);
Desktop.addInternalFrame(alf, "Foo", 800, 600);
- ;
+
AlignmentI al = alf.getViewport().getAlignment();
SequenceI seq = al.getSequenceAt(0);
assertEquals(470, seq.getStart());
Assert.assertNull(subseq,
"Expected no annotation transferred at position " + p);
}
- ;
if (orig != null)
{
Assert.assertNotNull(subseq,
"Expected annotation transfer at position " + p);
assertEquals(orig.value, subseq.value);
}
- ;
}
}
} catch (InterruptedException q)
{
}
- ;
Assert.assertTrue(schoose.selectStructure(pDBID),
"Couldn't select structure via structure chooser: " + pDBID);
schoose.showStructures(true);
PDBEntry importedPDB = new PDBEntry("3A6S", "", Type.PDB,
"Paste");
AAStructureBindingModel binder = new AAStructureBindingModel(
- new StructureSelectionManager(), new PDBEntry[]
+ StructureSelectionManager.getStructureSelectionManager(null),
+ new PDBEntry[]
{ importedPDB },
new SequenceI[][]
{ importedAl.getSequencesArray() }, null)
seqs[0] = new SequenceI[] { seq1a, seq1b };
seqs[1] = new SequenceI[] { seq2 };
seqs[2] = new SequenceI[] { seq3 };
- StructureSelectionManager ssm = new StructureSelectionManager();
+ StructureSelectionManager ssm = StructureSelectionManager
+ .getStructureSelectionManager(null);
ssm.setMapping(new SequenceI[] { seq1a, seq1b }, null, PDB_1,
DataSourceType.PASTE, null);