From 208f2c3de82e3327c4f930ab7d04f5b812ccd277 Mon Sep 17 00:00:00 2001 From: hansonr Date: Wed, 8 May 2019 22:35:47 -0500 Subject: [PATCH] JAL-3253 preliminary static fixes for JavaScript part 3 of 3 More succinct singleton class instances stored in jalview.bin.Jalview. All 2200 instances of "static" checked. --- src/jalview/analysis/AlignmentSorter.java | 39 +- src/jalview/analysis/scoremodels/ScoreModels.java | 36 +- src/jalview/bin/Cache.java | 62 +-- src/jalview/bin/Jalview.java | 61 +++ src/jalview/ext/ensembl/EnsemblInfo.java | 47 +- src/jalview/fts/service/pdb/PDBFTSRestClient.java | 38 +- .../fts/service/uniprot/UniProtFTSRestClient.java | 37 +- src/jalview/gui/AlignFrame.java | 11 +- src/jalview/gui/Desktop.java | 6 +- src/jalview/gui/IdPanel.java | 3 +- src/jalview/gui/PopupMenu.java | 31 +- src/jalview/gui/Preferences.java | 27 +- src/jalview/gui/SliderPanel.java | 48 +- src/jalview/gui/StructureChooser.java | 47 +- src/jalview/gui/UserQuestionnaireCheck.java | 6 +- src/jalview/httpserver/HttpServer.java | 38 +- src/jalview/io/HTMLOutput.java | 4 +- src/jalview/io/JalviewFileFilter.java | 3 +- src/jalview/io/PIRFile.java | 9 +- src/jalview/io/TCoffeeScoreFile.java | 10 +- src/jalview/io/VamsasAppDatastore.java | 12 +- src/jalview/io/gff/SequenceOntologyFactory.java | 14 +- src/jalview/jbgui/GSliderPanel.java | 5 +- src/jalview/jbgui/GStructureChooser.java | 26 +- src/jalview/rest/RestHandler.java | 14 +- src/jalview/schemes/AnnotationColourGradient.java | 3 +- src/jalview/schemes/ColourSchemeProperty.java | 25 +- src/jalview/schemes/RNAHelicesColour.java | 3 +- src/jalview/schemes/ResidueProperties.java | 31 +- src/jalview/structure/StructureImportSettings.java | 57 +- .../structure/StructureSelectionManager.java | 37 +- src/jalview/urls/IdOrgSettings.java | 20 +- src/jalview/util/BrowserLauncher.java | 86 +-- src/jalview/util/GroupUrlLink.java | 556 +++++++++++--------- src/jalview/util/MessageManager.java | 10 +- src/jalview/util/Platform.java | 3 +- src/jalview/ws/SequenceFetcher.java | 15 +- src/jalview/ws/SequenceFetcherFactory.java | 10 +- src/jalview/ws/jws1/Discoverer.java | 64 ++- src/jalview/ws/jws2/AAConClient.java | 2 +- src/jalview/ws/jws2/AADisorderClient.java | 75 +-- src/jalview/ws/jws2/Jws2Discoverer.java | 19 +- .../ws/jws2/jabaws2/Jws2InstanceFactory.java | 28 +- src/jalview/ws/rest/RestClient.java | 58 +- src/jalview/ws/sifts/SiftsClient.java | 23 +- src/jalview/ws/sifts/SiftsSettings.java | 36 +- src/mc_view/PDBfile.java | 8 +- 47 files changed, 916 insertions(+), 887 deletions(-) diff --git a/src/jalview/analysis/AlignmentSorter.java b/src/jalview/analysis/AlignmentSorter.java index 427db84..b764787 100755 --- a/src/jalview/analysis/AlignmentSorter.java +++ b/src/jalview/analysis/AlignmentSorter.java @@ -22,6 +22,7 @@ package jalview.analysis; import jalview.analysis.scoremodels.PIDModel; import jalview.analysis.scoremodels.SimilarityParams; +import jalview.bin.Jalview; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentOrder; @@ -29,7 +30,6 @@ import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.datamodel.SequenceNode; -import jalview.util.Platform; import jalview.util.QuickSort; import java.util.ArrayList; @@ -67,41 +67,12 @@ public class AlignmentSorter public static final String FEATURE_DENSITY = "density"; - static AlignmentSorter instance; - public static AlignmentSorter getInstance() { - - // BH 2019.05.08 need to isolate static fields in JavaScript - - AlignmentSorter i = instance; - @SuppressWarnings("unused") - ThreadGroup g = null; - if (Platform.isJS()) - { - g = Thread.currentThread().getThreadGroup(); - /** - * @j2sNative i = g._jalviewAlignmentSorterInstance; - * - */ - } - if (i == null) - { - i = new AlignmentSorter(); - - if (Platform.isJS()) - { - /** - * @j2sNative g._jalviewAlignmentSorterInstance = i; - * - */ - } - else - { - instance = i; - } - } - return i; + Jalview j = Jalview.getInstance(); + return (j.alignmentSorter == null + ? j.alignmentSorter = new AlignmentSorter() + : j.alignmentSorter); } /* diff --git a/src/jalview/analysis/scoremodels/ScoreModels.java b/src/jalview/analysis/scoremodels/ScoreModels.java index fd579dc..0041245 100644 --- a/src/jalview/analysis/scoremodels/ScoreModels.java +++ b/src/jalview/analysis/scoremodels/ScoreModels.java @@ -22,10 +22,10 @@ package jalview.analysis.scoremodels; import jalview.api.AlignmentViewPanel; import jalview.api.analysis.ScoreModelI; +import jalview.bin.Jalview; import jalview.io.DataSourceType; import jalview.io.FileParse; import jalview.io.ScoreMatrixFile; -import jalview.util.Platform; import java.io.IOException; import java.util.LinkedHashMap; @@ -42,8 +42,6 @@ public class ScoreModels private final ScoreMatrix DNA; - private static ScoreModels instance; - /** * Answers the singleton instance of this class, with lazy initialisation * (built-in score models are loaded on the first call to this method) @@ -52,33 +50,9 @@ public class ScoreModels */ public static ScoreModels getInstance() { - ScoreModels m = instance; - @SuppressWarnings("unused") - ThreadGroup g = null; - if (Platform.isJS()) - { - g = Thread.currentThread().getThreadGroup(); - /** - * @j2sNative m = g._jalviewScoreModelsInstance; - * - */ - } - if (m == null) - { - m = new ScoreModels(); - if (Platform.isJS()) - { - /** - * @j2sNative g._jalviewScoreModelsInstance = m; - * - */ - } - else - { - instance = m; - } - } - return m; + Jalview j = Jalview.getInstance(); + return (j.scoreModels == null ? j.scoreModels = new ScoreModels() + : j.scoreModels); } private Map models; @@ -176,7 +150,7 @@ public class ScoreModels */ public void reset() { - instance = new ScoreModels(); + Jalview.getInstance().scoreModels = new ScoreModels(); } /** diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index b2f6e95..d7542b8 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -221,36 +221,8 @@ public class Cache */ public static Cache getInstance() { - - // BH 2019.05.08 need to isolate static fields in JavaScript - - Cache i = instance; - @SuppressWarnings("unused") - ThreadGroup g = null; - if (Platform.isJS()) - { - g = Thread.currentThread().getThreadGroup(); - /** - * @j2sNative i = g._jalviewCacheInstance; - * - */ - } - if (i == null) - { - i = new Cache(); - if (Platform.isJS()) - { - /** - * @j2sNative g._jalviewCacheInstance = i; - * - */ - } - else - { - instance = i; - } - } - return i; + Jalview j = Jalview.getInstance(); + return (j.cache == null ? j.cache = new Cache() : j.cache); } /** @@ -358,14 +330,14 @@ public class Cache jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview"); laxis.setLevel(Level.toLevel( - Cache.getDefault("logs.Axis.Level", Level.INFO.toString()))); - lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level", - Level.INFO.toString()))); + getDefault("logs.Axis.Level", Level.INFO.toString()))); + lcastor.setLevel(Level.toLevel( + getDefault("logs.Castor.Level", Level.INFO.toString()))); lcastor = Logger.getLogger("org.exolab.castor.xml"); - lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level", - Level.INFO.toString()))); + lcastor.setLevel(Level.toLevel( + getDefault("logs.Castor.Level", Level.INFO.toString()))); // lcastor = Logger.getLogger("org.exolab.castor.xml.Marshaller"); - // lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level", + // lcastor.setLevel(Level.toLevel(getDefault("logs.Castor.Level", // Level.INFO.toString()))); jalview.bin.Cache.log.setLevel(Level.toLevel(Cache .getDefault("logs.Jalview.level", Level.INFO.toString()))); @@ -528,18 +500,17 @@ public class Cache } new BuildDetails(codeVersion, null, codeInstallation); - SiftsSettings - .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false)); + SiftsSettings.setMapWithSifts(getDefault("MAP_WITH_SIFTS", false)); SiftsSettings.setSiftDownloadDirectory(jalview.bin.Cache .getDefault("sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR)); SiftsSettings.setFailSafePIDThreshold( - jalview.bin.Cache.getDefault("sifts_fail_safe_pid_threshold", + getDefault("sifts_fail_safe_pid_threshold", DEFAULT_FAIL_SAFE_PID_THRESHOLD)); SiftsSettings.setCacheThresholdInDays( - jalview.bin.Cache.getDefault("sifts_cache_threshold_in_days", + getDefault("sifts_cache_threshold_in_days", DEFAULT_CACHE_THRESHOLD_IN_DAYS)); IdOrgSettings.setUrl(getDefault("ID_ORG_HOSTURL", @@ -554,7 +525,7 @@ public class Cache StructureImportSettings .setDefaultPDBFileParser(DEFAULT_PDB_FILE_PARSER); // StructureImportSettings - // .setDefaultPDBFileParser(jalview.bin.Cache.getDefault( + // .setDefaultPDBFileParser(jalview.bin.getDefault( // "DEFAULT_PDB_FILE_PARSER", DEFAULT_PDB_FILE_PARSER)); // jnlpVersion will be null if we're using InstallAnywhere // Dont do this check if running in headless mode @@ -630,13 +601,9 @@ public class Cache setProperty("VERSION", codeVersion); // LOAD USERDEFINED COLOURS - jalview.bin.Cache - .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS")); - jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER", - false); + initUserColourSchemes(getProperty("USER_DEFINED_COLOURS")); } - private void deleteBuildProperties() { applicationProperties.remove("LATEST_VERSION"); @@ -947,8 +914,7 @@ public class Cache .newInstance(new Object[] { "Jalview Desktop", (vrs = jalview.bin.Cache.getProperty("VERSION") + "_" - + jalview.bin.Cache.getDefault("BUILD_DATE", - "unknown")), + + getDefault("BUILD_DATE", "unknown")), "UA-9060947-1" }); jgoogleanalyticstracker .getMethod("trackAsynchronously", new Class[] diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 9740423..9e3382a 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -20,10 +20,17 @@ */ package jalview.bin; +import jalview.analysis.AlignmentSorter; +import jalview.analysis.scoremodels.ScoreModels; +import jalview.api.StructureSelectionManagerProvider; +import jalview.ext.ensembl.EnsemblInfo; import jalview.ext.so.SequenceOntology; +import jalview.fts.service.pdb.PDBFTSRestClient; +import jalview.fts.service.uniprot.UniProtFTSRestClient; import jalview.gui.AlignFrame; import jalview.gui.Desktop; import jalview.gui.PromptUserConfig; +import jalview.httpserver.HttpServer; import jalview.io.AppletFormatAdapter; import jalview.io.BioJsHTMLOutput; import jalview.io.DataSourceType; @@ -35,12 +42,23 @@ import jalview.io.HtmlSvgOutput; import jalview.io.IdentifyFile; import jalview.io.NewickFile; import jalview.io.gff.SequenceOntologyFactory; +import jalview.io.gff.SequenceOntologyI; +import jalview.rest.RestHandler; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; +import jalview.structure.StructureImportSettings; +import jalview.structure.StructureSelectionManager; +import jalview.urls.IdOrgSettings; import jalview.util.MessageManager; import jalview.util.Platform; +import jalview.ws.SequenceFetcher; +import jalview.ws.jws1.Discoverer; import jalview.ws.jws2.Jws2Discoverer; +import jalview.ws.jws2.jabaws2.Jws2InstanceFactory; +import jalview.ws.rest.RestClient; +import jalview.ws.sifts.SiftsSettings; +import java.awt.Color; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; @@ -58,6 +76,7 @@ import java.security.PermissionCollection; import java.security.Permissions; import java.security.Policy; import java.util.HashMap; +import java.util.IdentityHashMap; import java.util.Map; import java.util.Vector; import java.util.logging.ConsoleHandler; @@ -1150,4 +1169,46 @@ public class Jalview } } + // singleton instances + + public Cache cache; + + public AlignmentSorter alignmentSorter; + + public EnsemblInfo ensemblInfo; + + public HttpServer httpServer; + + public IdentityHashMap structureSelections; + + public PDBFTSRestClient pdbFTSRestClient; + + public RestHandler restHandler; + + public ScoreModels scoreModels; + + public SequenceFetcher sequenceFetcher; + + public SequenceOntologyI sequenceOntology; + + public UniProtFTSRestClient uniprotFTSRestClient; + + public StructureSelectionManager nullProvider; + + public Color[] rnaHelices = null; + + public StructureImportSettings structureImportSettings; + + public IdOrgSettings idOrgSettings; + + public SiftsSettings siftsSettings; + + public RestClient restClient; + + public Jws2Discoverer j2s2discoverer; + + public Jws2InstanceFactory jws2InstanceFactory; + + public Discoverer discoverer; + } diff --git a/src/jalview/ext/ensembl/EnsemblInfo.java b/src/jalview/ext/ensembl/EnsemblInfo.java index 7bc4139..2187e68 100644 --- a/src/jalview/ext/ensembl/EnsemblInfo.java +++ b/src/jalview/ext/ensembl/EnsemblInfo.java @@ -1,5 +1,6 @@ package jalview.ext.ensembl; +import jalview.bin.Jalview; import jalview.datamodel.AlignmentI; import jalview.datamodel.DBRefSource; @@ -17,17 +18,6 @@ import org.json.simple.parser.ParseException; public class EnsemblInfo extends EnsemblRestClient { - private static EnsemblInfo instance; - - /** - * Some question as to whether it is necessary to do this for each applet. IN - * PRINCIPLE, applets could set different properties for the origin of Ensembl - * data. But I suggest this is unlikely. If we DO care about that possibility, - * then we need to set doICare to Platform.isJS(); - * - */ - private final static boolean doICare = false;// Platform.isJS(); - /** * On first request only, populate the lookup map by fetching the list of * divisions known to EnsemblGenomes. @@ -35,38 +25,9 @@ public class EnsemblInfo extends EnsemblRestClient */ private static EnsemblInfo getInstance() { - - // BH 2019.05.08 need to isolate static fields in JavaScript - - EnsemblInfo i = instance; - @SuppressWarnings("unused") - ThreadGroup g = null; - - if (doICare) - { - g = Thread.currentThread().getThreadGroup(); - /** - * @j2sNative i = g._jalviewEnsemblInstance; - * - */ - } - if (i == null) - { - i = new EnsemblInfo(); - - if (doICare) - { - /** - * @j2sNative g._jalviewEnsemblInstance = i; - * - */ - } - else - { - instance = i; - } - } - return i; + Jalview j = Jalview.getInstance(); + return (j.ensemblInfo == null ? j.ensemblInfo = new EnsemblInfo() + : j.ensemblInfo); } /* diff --git a/src/jalview/fts/service/pdb/PDBFTSRestClient.java b/src/jalview/fts/service/pdb/PDBFTSRestClient.java index 3bb3f77..75bfd1b 100644 --- a/src/jalview/fts/service/pdb/PDBFTSRestClient.java +++ b/src/jalview/fts/service/pdb/PDBFTSRestClient.java @@ -20,6 +20,7 @@ */ package jalview.fts.service.pdb; +import jalview.bin.Jalview; import jalview.datamodel.SequenceI; import jalview.fts.api.FTSData; import jalview.fts.api.FTSDataColumnI; @@ -56,41 +57,12 @@ import com.sun.jersey.api.client.config.DefaultClientConfig; public class PDBFTSRestClient extends FTSRestClient { - private static FTSRestClientI instance = null; - public static FTSRestClientI getInstance() { - - // BH 2019.05.08 need to isolate static fields in JavaScript - - FTSRestClientI i = instance; - @SuppressWarnings("unused") - ThreadGroup g = null; - if (Platform.isJS()) - { - g = Thread.currentThread().getThreadGroup(); - /** - * @j2sNative i = g._jalviewPDBFTSRestClientInstance; - * - */ - } - if (i == null) - { - i = new PDBFTSRestClient(); - - if (Platform.isJS()) - { - /** - * @j2sNative g._jalviewPDBFTSRestClientInstance = i; - * - */ - } - else - { - instance = i; - } - } - return i; + Jalview j = Jalview.getInstance(); + return (j.pdbFTSRestClient == null + ? j.pdbFTSRestClient = new PDBFTSRestClient() + : j.pdbFTSRestClient); } public static final String PDB_SEARCH_ENDPOINT = "https://www.ebi.ac.uk/pdbe/search/pdb/select?"; diff --git a/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java b/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java index 715b842..9501930 100644 --- a/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java +++ b/src/jalview/fts/service/uniprot/UniProtFTSRestClient.java @@ -22,6 +22,7 @@ package jalview.fts.service.uniprot; import jalview.bin.Cache; +import jalview.bin.Jalview; import jalview.fts.api.FTSData; import jalview.fts.api.FTSDataColumnI; import jalview.fts.api.FTSRestClientI; @@ -52,41 +53,11 @@ public class UniProtFTSRestClient extends FTSRestClient Platform.addJ2SDirectDatabaseCall(DEFAULT_UNIPROT_DOMAIN); } - private static FTSRestClientI instance = null; - public static FTSRestClientI getInstance() { - - // BH 2019.05.08 need to isolate static fields in JavaScript - - FTSRestClientI i = instance; - @SuppressWarnings("unused") - ThreadGroup g = null; - if (Platform.isJS()) - { - g = Thread.currentThread().getThreadGroup(); - /** - * @j2sNative i = g._jalviewUniProtFTSRestClientInstance; - * - */ - } - if (i == null) - { - i = new UniProtFTSRestClient(); - - if (Platform.isJS()) - { - /** - * @j2sNative g._jalviewUniProtFTSRestClientInstance = i; - * - */ - } - else - { - instance = i; - } - } - return i; + Jalview j = Jalview.getInstance(); + return (j.uniprotFTSRestClient == null ? j.uniprotFTSRestClient = new UniProtFTSRestClient() + : j.uniprotFTSRestClient); } public final String uniprotSearchEndpoint; diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index f949ef7..d182d89 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -4151,9 +4151,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, final JMenu dismenu = new JMenu("Protein Disorder"); // JAL-940 - only show secondary structure prediction services from // the legacy server + Hashtable> services = Discoverer + .getInstance().getServices(); if (// Cache.getDefault("SHOW_JWS1_SERVICES", true) - // && - Discoverer.services != null && (Discoverer.services.size() > 0)) + // && + services != null && (services.size() > 0)) { // TODO: refactor to allow list of AbstractName/Handler bindings to // be @@ -4161,8 +4163,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // No MSAWS used any more: // Vector msaws = null; // (Vector) // Discoverer.services.get("MsaWS"); - Vector secstrpr = Discoverer.services - .get("SecStrPred"); + Vector secstrpr = services.get("SecStrPred"); if (secstrpr != null) { // Add any secondary structure prediction services @@ -4213,7 +4214,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, webService.add(me.webServiceNoServices); } // TODO: move into separate menu builder class. - boolean new_sspred = false; + // boolean new_sspred = false; if (Cache.getDefault("SHOW_JWS2_SERVICES", true)) { Jws2Discoverer jws2servs = Jws2Discoverer.getDiscoverer(); diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index bdb6de9..88835c6 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -248,6 +248,8 @@ public class Desktop extends jalview.jbgui.GDesktop private static int fileLoadingCount = 0; + public JInternalFrame conservationSlider, PIDSlider; + class MyDesktopManager implements DesktopManager { @@ -3168,7 +3170,7 @@ public class Desktop extends jalview.jbgui.GDesktop .formatMessage("status.opening_params", new Object[] { url }), this.hashCode()); } - jalview.util.BrowserLauncher.openURL(url); + BrowserLauncher.openURL(url); } catch (Exception ex) { JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(), @@ -3250,6 +3252,8 @@ public class Desktop extends jalview.jbgui.GDesktop private groovy.ui.Console groovyConsole; + public StructureViewer lastTargetedView; + /** * add another dialog thread to the queue * diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index dc94dee..dadf25a 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -456,7 +456,8 @@ public class IdPanel extends JPanel } PopupMenu pop = new PopupMenu(alignPanel, sq, features, - Preferences.getGroupURLLinks()); + Preferences.getGroupURLLinks() // empty list; not implemented + ); pop.show(this, e.getX(), e.getY()); } diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index a356def..3145f7c 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -304,7 +304,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener { try { - jalview.util.BrowserLauncher.openURL(url); + Platform.openURL(url); } catch (Exception ex) { JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(), @@ -317,7 +317,9 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } /** - * add a late bound groupURL item to the given linkMenu + * For the popup menu on the idPanel. + * + * Add a late bound groupURL item to the given linkMenu * * @param linkMenu * @param label @@ -349,6 +351,15 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener { try { + // Object[] { int[] { number of matches seqs }, + // boolean[] { which matched }, + // StringBuffer[] { segment generated from inputs }, + // String[] { url } + // } + + // TODO bug: urlstub is { int[], boolean[] } but constructFrom + // requires something else. + showLink(urlgenerator.constructFrom(urlstub)); } catch (UrlStringTooLongException e2) { @@ -388,6 +399,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener * non-positional features if in the Id panel, features at the * clicked residue if in the sequence panel * @param groupLinks + * not implemented -- empty list */ public PopupMenu(final AlignmentPanel alignPanel, final SequenceI seq, List features, List groupLinks) @@ -658,6 +670,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener // add any groupURLs to the groupURL submenu and make it visible if (groupLinks != null && groupLinks.size() > 0) { + // not implemented -- empty list buildGroupURLMenu(sg, groupLinks); } // Add a 'show all structures' for the current selection @@ -983,6 +996,12 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener showOrHideMenu.add(item); } + /** + * + * @param sg + * @param groupLinks + * not implemented -- empty list + */ private void buildGroupURLMenu(SequenceGroup sg, List groupLinks) { @@ -1044,9 +1063,15 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } } } + if (groupLinks.size() == 0) + { + return; + } // now create group links for all distinct ID/sequence sets. boolean addMenu = false; // indicates if there are any group links to give // to user + + // not implmeented -- empty list for (String link : groupLinks) { GroupUrlLink urlLink = null; @@ -1099,6 +1124,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener { urlset = urlLink.makeUrlStubs(ids, seqstr, "FromJalview" + System.currentTimeMillis(), false); + // { int[], boolean[] } only here } catch (UrlStringTooLongException e) { } @@ -1127,7 +1153,6 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener groupLinksMenu.add(linkMenus[m]); } } - groupMenu.add(groupLinksMenu); } } diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 8765b37..facc826 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -37,6 +37,7 @@ import jalview.urls.UrlLinkTableModel; import jalview.urls.api.UrlProviderFactoryI; import jalview.urls.api.UrlProviderI; import jalview.urls.desktop.DesktopUrlProviderFactory; +import jalview.util.BrowserLauncher; import jalview.util.MessageManager; import jalview.util.Platform; import jalview.util.UrlConstants; @@ -139,7 +140,8 @@ public class Preferences extends GPreferences * (TODO: proper escape for using | to separate ids or sequences */ - public static final List groupURLLinks; + public static final List groupURLLinks; // not implemented + static { // get links selected to be in the menu (SEQUENCE_LINKS) @@ -165,7 +167,7 @@ public class Preferences extends GPreferences * .properties file as '|' separated strings */ - groupURLLinks = new ArrayList<>(); + groupURLLinks = new ArrayList<>(); // not implemented } JInternalFrame frame; @@ -724,12 +726,16 @@ public class Preferences extends GPreferences Cache.setPropertyNoSave("SVG_RENDERING", ((OptionsParam) svgRendering.getSelectedItem()).getCode()); - /* - * Save Connections settings + if (!Platform.isJS()) + /** + * @j2sNative */ - Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText()); - - jalview.util.BrowserLauncher.resetBrowser(); + { + // Java only + // Save Connections settings + Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText()); + BrowserLauncher.resetBrowser(); + } // save user-defined and selected links String menuLinks = sequenceUrlLinks.writeUrlsAsString(true); @@ -814,8 +820,6 @@ public class Preferences extends GPreferences Boolean.toString(modellerOutput.isSelected())); Cache.setPropertyNoSave("EXPORT_EMBBED_BIOJSON", Boolean.toString(embbedBioJSON.isSelected())); - jalview.io.PIRFile.useModellerOutput = modellerOutput.isSelected(); - Cache.setPropertyNoSave("FIGURE_AUTOIDWIDTH", Boolean.toString(autoIdWidth.isSelected())); userIdWidth_actionPerformed(); @@ -1108,6 +1112,11 @@ public class Preferences extends GPreferences super.showunconserved_actionPerformed(e); } + /** + * not implemented -- returns empty list + * + * @return + */ public static List getGroupURLLinks() { return groupURLLinks; diff --git a/src/jalview/gui/SliderPanel.java b/src/jalview/gui/SliderPanel.java index 46b47a2..31ad083 100755 --- a/src/jalview/gui/SliderPanel.java +++ b/src/jalview/gui/SliderPanel.java @@ -26,7 +26,6 @@ import jalview.jbgui.GSliderPanel; import jalview.renderer.ResidueShaderI; import jalview.util.MessageManager; -import java.awt.event.ActionEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.beans.PropertyVetoException; @@ -45,14 +44,11 @@ import javax.swing.event.InternalFrameEvent; * @author $author$ * @version $Revision$ */ +@SuppressWarnings("serial") public class SliderPanel extends GSliderPanel { private static final String BACKGROUND = "Background"; - static JInternalFrame conservationSlider; - - static JInternalFrame PIDSlider; - AlignmentPanel ap; boolean forConservation = true; @@ -66,6 +62,12 @@ public class SliderPanel extends GSliderPanel */ public static SliderPanel getSliderPanel() { + + JInternalFrame conservationSlider = Desktop + .getInstance().conservationSlider; + + JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; + if (conservationSlider != null && conservationSlider.isVisible()) { return (SliderPanel) conservationSlider.getContentPane(); @@ -153,10 +155,14 @@ public class SliderPanel extends GSliderPanel { SliderPanel sliderPanel = null; + JInternalFrame conservationSlider = Desktop + .getInstance().conservationSlider; + if (conservationSlider == null) { sliderPanel = new SliderPanel(ap, rs.getConservationInc(), true, rs); - conservationSlider = new JInternalFrame(); + conservationSlider = Desktop + .getInstance().conservationSlider = new JInternalFrame(); conservationSlider.setContentPane(sliderPanel); conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER); } @@ -192,12 +198,14 @@ public class SliderPanel extends GSliderPanel */ public static void hidePIDSlider() { + JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; + if (PIDSlider != null) { try { PIDSlider.setClosed(true); - PIDSlider = null; + Desktop.getInstance().PIDSlider = null; } catch (PropertyVetoException ex) { } @@ -209,12 +217,15 @@ public class SliderPanel extends GSliderPanel */ public static void hideConservationSlider() { + JInternalFrame conservationSlider = Desktop + .getInstance().conservationSlider; + if (conservationSlider != null) { try { conservationSlider.setClosed(true); - conservationSlider = null; + Desktop.getInstance().conservationSlider = null; } catch (PropertyVetoException ex) { } @@ -228,6 +239,9 @@ public class SliderPanel extends GSliderPanel { hidePIDSlider(); + JInternalFrame conservationSlider = Desktop + .getInstance().conservationSlider; + if (!conservationSlider.isVisible()) { Desktop.addInternalFrame(conservationSlider, @@ -238,7 +252,7 @@ public class SliderPanel extends GSliderPanel @Override public void internalFrameClosed(InternalFrameEvent e) { - conservationSlider = null; + Desktop.getInstance().conservationSlider = null; } }); conservationSlider.setLayer(JLayeredPane.PALETTE_LAYER); @@ -264,10 +278,12 @@ public class SliderPanel extends GSliderPanel SliderPanel sliderPanel = null; + JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; + if (PIDSlider == null) { sliderPanel = new SliderPanel(ap, threshold, false, rs); - PIDSlider = new JInternalFrame(); + PIDSlider = Desktop.getInstance().PIDSlider = new JInternalFrame(); PIDSlider.setContentPane(sliderPanel); PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER); } @@ -305,6 +321,8 @@ public class SliderPanel extends GSliderPanel { hideConservationSlider(); + JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; + if (!PIDSlider.isVisible()) { Desktop.addInternalFrame(PIDSlider, PIDSlider.getTitle(), true, @@ -315,7 +333,7 @@ public class SliderPanel extends GSliderPanel @Override public void internalFrameClosed(InternalFrameEvent e) { - PIDSlider = null; + Desktop.getInstance().PIDSlider = null; } }); PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER); @@ -451,7 +469,7 @@ public class SliderPanel extends GSliderPanel public static int getConservationValue() { - return getValue(conservationSlider); + return getValue(Desktop.getInstance().conservationSlider); } static int getValue(JInternalFrame slider) @@ -462,7 +480,7 @@ public class SliderPanel extends GSliderPanel public static int getPIDValue() { - return getValue(PIDSlider); + return getValue(Desktop.getInstance().PIDSlider); } /** @@ -485,6 +503,10 @@ public class SliderPanel extends GSliderPanel public String getTitle() { String title = null; + JInternalFrame conservationSlider = Desktop + .getInstance().conservationSlider; + JInternalFrame PIDSlider = Desktop.getInstance().PIDSlider; + if (isForConservation()) { if (conservationSlider != null) diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 5b15ef1..620db5a 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -71,27 +71,25 @@ public class StructureChooser extends GStructureChooser { private static final String AUTOSUPERIMPOSE = "AUTOSUPERIMPOSE"; - private static int MAX_QLENGTH = 7820; + private static final int MAX_QLENGTH = 7820; - private SequenceI selectedSequence; + protected SequenceI selectedSequence; - private SequenceI[] selectedSequences; + public SequenceI[] selectedSequences; private IProgressIndicator progressIndicator; - private Collection discoveredStructuresSet; + protected Collection discoveredStructuresSet; - private FTSRestRequest lastPdbRequest; + protected FTSRestRequest lastPdbRequest; - private FTSRestClientI pdbRestClient; + protected FTSRestClientI pdbRestClient; - private String selectedPdbFileName; + protected String selectedPdbFileName; - private boolean isValidPBDEntry; + protected boolean isValidPBDEntry; - private boolean cachedPDBExists; - - private static StructureViewer lastTargetedView = null; + protected boolean cachedPDBExists; public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq, AlignmentPanel ap) @@ -146,21 +144,22 @@ public class StructureChooser extends GStructureChooser * structures may be added. If this list is empty then it, and the 'Add' * button, are hidden. */ - private void discoverStructureViews() + protected void discoverStructureViews() { if (Desktop.getInstance() != null) { targetView.removeAllItems(); - if (lastTargetedView != null && !lastTargetedView.isVisible()) + Desktop d = Desktop.getInstance(); + if (d.lastTargetedView != null && !d.lastTargetedView.isVisible()) { - lastTargetedView = null; + d.lastTargetedView = null; } int linkedViewsAt = 0; for (StructureViewerBase view : Desktop.getInstance() .getStructureViewers(null, null)) { - StructureViewer viewHandler = (lastTargetedView != null - && lastTargetedView.sview == view) ? lastTargetedView + StructureViewer viewHandler = (d.lastTargetedView != null + && d.lastTargetedView.sview == view) ? d.lastTargetedView : StructureViewer.reconfigure(view); if (view.isLinkedWith(ap)) @@ -181,9 +180,9 @@ public class StructureChooser extends GStructureChooser if (targetView.getItemCount() > 0) { targetView.setVisible(true); - if (lastTargetedView != null) + if (d.lastTargetedView != null) { - targetView.setSelectedItem(lastTargetedView); + targetView.setSelectedItem(d.lastTargetedView); } else { @@ -874,7 +873,7 @@ public class StructureChooser extends GStructureChooser /** * structure viewer opened by this dialog, or null */ - private StructureViewer sViewer = null; + protected StructureViewer sViewer = null; public void showStructures(boolean waitUntilFinished) { @@ -1036,7 +1035,7 @@ public class StructureChooser extends GStructureChooser } } - private PDBEntry getFindEntry(String id, Vector pdbEntries) + protected PDBEntry getFindEntry(String id, Vector pdbEntries) { Objects.requireNonNull(id); Objects.requireNonNull(pdbEntries); @@ -1075,7 +1074,7 @@ public class StructureChooser extends GStructureChooser * @param sequences * @return */ - private StructureViewer launchStructureViewer( + protected StructureViewer launchStructureViewer( StructureSelectionManager ssm, final PDBEntry[] pdbEntriesToView, final AlignmentPanel alignPanel, SequenceI[] sequences) @@ -1154,7 +1153,7 @@ public class StructureChooser extends GStructureChooser } setProgressBar(null, progressId); // remember the last viewer we used... - lastTargetedView = theViewer; + Desktop.getInstance().lastTargetedView = theViewer; return theViewer; } @@ -1202,7 +1201,8 @@ public class StructureChooser extends GStructureChooser protected void txt_search_ActionPerformed() { String text = txt_search.getText().trim(); - if (text.length() >= PDB_ID_MIN) + if (text.length() >= PDB_ID_MIN) + { new Thread() { @@ -1248,6 +1248,7 @@ public class StructureChooser extends GStructureChooser } }.start(); } + } @Override protected void tabRefresh() diff --git a/src/jalview/gui/UserQuestionnaireCheck.java b/src/jalview/gui/UserQuestionnaireCheck.java index e12586a..156f072 100644 --- a/src/jalview/gui/UserQuestionnaireCheck.java +++ b/src/jalview/gui/UserQuestionnaireCheck.java @@ -21,13 +21,12 @@ package jalview.gui; import jalview.util.MessageManager; +import jalview.util.Platform; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; -import javax.swing.JOptionPane; - public class UserQuestionnaireCheck implements Runnable { /** @@ -91,6 +90,7 @@ public class UserQuestionnaireCheck implements Runnable return prompt; } + @Override public void run() { if (url == null) @@ -149,7 +149,7 @@ public class UserQuestionnaireCheck implements Runnable if (reply == JvOptionPane.YES_OPTION) { jalview.bin.Cache.log.debug("Opening " + qurl); - jalview.util.BrowserLauncher.openURL(qurl); + Platform.openURL(qurl); } } } catch (Exception e) diff --git a/src/jalview/httpserver/HttpServer.java b/src/jalview/httpserver/HttpServer.java index a18d38d..58e792d 100644 --- a/src/jalview/httpserver/HttpServer.java +++ b/src/jalview/httpserver/HttpServer.java @@ -20,6 +20,7 @@ */ package jalview.httpserver; +import jalview.bin.Jalview; import jalview.rest.RestHandler; import java.net.BindException; @@ -57,10 +58,21 @@ public class HttpServer */ private static final String JALVIEW_PATH = "jalview"; - /* - * Singleton instance of this server + /** + * Returns the singleton instance of this class. + * + * @return + * @throws BindException */ - private static HttpServer instance; + public static HttpServer getInstance() throws BindException + { + synchronized (HttpServer.class) + { + Jalview j = Jalview.getInstance(); + return (j.httpServer == null ? j.httpServer = new HttpServer() + : j.httpServer); + } + } /* * The Http server @@ -75,7 +87,7 @@ public class HttpServer /* * Lookup of ContextHandler by its wrapped handler */ - Map myHandlers = new HashMap(); + Map myHandlers = new HashMap<>(); /* * The context root for the server @@ -83,24 +95,6 @@ public class HttpServer private URI contextRoot; /** - * Returns the singleton instance of this class. - * - * @return - * @throws BindException - */ - public static HttpServer getInstance() throws BindException - { - synchronized (HttpServer.class) - { - if (instance == null) - { - instance = new HttpServer(); - } - return instance; - } - } - - /** * Private constructor to enforce use of singleton * * @throws BindException diff --git a/src/jalview/io/HTMLOutput.java b/src/jalview/io/HTMLOutput.java index 6b6dc24..9729ec8 100644 --- a/src/jalview/io/HTMLOutput.java +++ b/src/jalview/io/HTMLOutput.java @@ -28,6 +28,7 @@ import jalview.datamodel.AlignmentExportData; import jalview.gui.AlignmentPanel; import jalview.gui.IProgressIndicator; import jalview.util.MessageManager; +import jalview.util.Platform; import java.io.BufferedReader; import java.io.File; @@ -264,8 +265,7 @@ public abstract class HTMLOutput implements Runnable { try { - jalview.util.BrowserLauncher - .openURL("file:///" + getExportedFile()); + Platform.openURL("file:///" + getExportedFile()); } catch (IOException e) { e.printStackTrace(); diff --git a/src/jalview/io/JalviewFileFilter.java b/src/jalview/io/JalviewFileFilter.java index bc20342..a702aae 100755 --- a/src/jalview/io/JalviewFileFilter.java +++ b/src/jalview/io/JalviewFileFilter.java @@ -21,7 +21,6 @@ package jalview.io; import java.io.File; -import java.util.Hashtable; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; @@ -31,7 +30,7 @@ import javax.swing.filechooser.FileFilter; public class JalviewFileFilter extends FileFilter { - public static Hashtable suffixHash = new Hashtable(); + // public static Hashtable suffixHash = new Hashtable(); private Map filters = null; diff --git a/src/jalview/io/PIRFile.java b/src/jalview/io/PIRFile.java index d9ed516..3f0fea0 100755 --- a/src/jalview/io/PIRFile.java +++ b/src/jalview/io/PIRFile.java @@ -20,18 +20,16 @@ */ package jalview.io; +import jalview.bin.Cache; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; import jalview.util.Comparison; import java.io.IOException; -import java.util.Vector; public class PIRFile extends AlignFile { - public static boolean useModellerOutput = false; - - Vector words = new Vector(); // Stores the words in a line after splitting + // Vector words = new Vector(); // Stores the words in a line after splitting public PIRFile() { @@ -111,7 +109,7 @@ public class PIRFile extends AlignFile StringBuffer out = new StringBuffer(); int i = 0; ModellerDescription md; - + boolean useModellerOutput = Cache.getDefault("PIR_MODELLER", false); while ((i < s.length) && (s[i] != null)) { String seq = s[i].getSequenceAsString(); @@ -147,7 +145,6 @@ public class PIRFile extends AlignFile } else { - if (useModellerOutput) { out.append(">P1;" + s[i].getName()); diff --git a/src/jalview/io/TCoffeeScoreFile.java b/src/jalview/io/TCoffeeScoreFile.java index 7e963d5..d069e5e 100644 --- a/src/jalview/io/TCoffeeScoreFile.java +++ b/src/jalview/io/TCoffeeScoreFile.java @@ -109,7 +109,7 @@ public class TCoffeeScoreFile extends AlignFile public final static String TCOFFEE_SCORE = "TCoffeeScore"; - static Pattern SCORES_WITH_RESIDUE_NUMS = Pattern + private final static Pattern SCORES_WITH_RESIDUE_NUMS = Pattern .compile("^\\d+\\s([^\\s]+)\\s+\\d+$"); /** The {@link Header} structure holder */ @@ -198,7 +198,7 @@ public class TCoffeeScoreFile extends AlignFile { return null; } - List result = new ArrayList(scores.size()); + List result = new ArrayList<>(scores.size()); for (Map.Entry it : scores.entrySet()) { result.add(it.getValue().toString()); @@ -250,7 +250,7 @@ public class TCoffeeScoreFile extends AlignFile error = true; return; } - scores = new LinkedHashMap(); + scores = new LinkedHashMap<>(); /* * initilize the structure @@ -503,7 +503,7 @@ public class TCoffeeScoreFile extends AlignFile int score; - LinkedHashMap scores = new LinkedHashMap(); + LinkedHashMap scores = new LinkedHashMap<>(); public int getScoreAvg() { @@ -530,7 +530,7 @@ public class TCoffeeScoreFile extends AlignFile public Block(int size) { this.size = size; - this.items = new HashMap(size); + this.items = new HashMap<>(size); } String getScoresFor(String id) diff --git a/src/jalview/io/VamsasAppDatastore.java b/src/jalview/io/VamsasAppDatastore.java index c2954f0..a7d901a 100644 --- a/src/jalview/io/VamsasAppDatastore.java +++ b/src/jalview/io/VamsasAppDatastore.java @@ -2020,17 +2020,17 @@ public class VamsasAppDatastore } // bitfields - should be a template in j1.5 - private static int HASSECSTR = 0; + private static final int HASSECSTR = 0; - private static int HASVALS = 1; + private static final int HASVALS = 1; - private static int HASHPHOB = 2; + private static final int HASHPHOB = 2; - private static int HASDC = 3; + private static final int HASDC = 3; - private static int HASDESCSTR = 4; + private static final int HASDESCSTR = 4; - private static int HASTWOSTATE = 5; // not used yet. + private static final int HASTWOSTATE = 5; // not used yet. /** * parses the AnnotationElements - if they exist - into diff --git a/src/jalview/io/gff/SequenceOntologyFactory.java b/src/jalview/io/gff/SequenceOntologyFactory.java index 90cae7a..cd5a22c 100644 --- a/src/jalview/io/gff/SequenceOntologyFactory.java +++ b/src/jalview/io/gff/SequenceOntologyFactory.java @@ -20,6 +20,8 @@ */ package jalview.io.gff; +import jalview.bin.Jalview; + /** * 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 @@ -30,19 +32,21 @@ package jalview.io.gff; */ public class SequenceOntologyFactory { - private static SequenceOntologyI instance; + // private static SequenceOntologyI instance; // moved to Jalview.instance for + // JavaScript public static synchronized SequenceOntologyI getInstance() { - if (instance == null) + Jalview j = Jalview.getInstance(); + if (j.sequenceOntology == null) { - instance = new SequenceOntologyLite(); + j.sequenceOntology = new SequenceOntologyLite(); } - return instance; + return j.sequenceOntology; } public static void setInstance(SequenceOntologyI so) { - instance = so; + Jalview.getInstance().sequenceOntology = so; } } diff --git a/src/jalview/jbgui/GSliderPanel.java b/src/jalview/jbgui/GSliderPanel.java index d841be5..452ba61 100755 --- a/src/jalview/jbgui/GSliderPanel.java +++ b/src/jalview/jbgui/GSliderPanel.java @@ -49,6 +49,7 @@ import javax.swing.SwingConstants; * @author $author$ * @version $Revision$ */ +@SuppressWarnings("serial") public class GSliderPanel extends JPanel { private static final Font VERDANA_11 = new java.awt.Font("Verdana", 0, 11); @@ -58,9 +59,9 @@ public class GSliderPanel extends JPanel protected static final int FRAME_HEIGHT = 120; // this is used for conservation colours, PID colours and redundancy threshold - protected JSlider slider = new JSlider(); + public JSlider slider = new JSlider(); - protected JTextField valueField = new JTextField(); + public JTextField valueField = new JTextField(); protected JLabel label = new JLabel(); diff --git a/src/jalview/jbgui/GStructureChooser.java b/src/jalview/jbgui/GStructureChooser.java index b9c9267..4261d67 100644 --- a/src/jalview/jbgui/GStructureChooser.java +++ b/src/jalview/jbgui/GStructureChooser.java @@ -106,13 +106,13 @@ public abstract class GStructureChooser extends JPanel protected String frameTitle = MessageManager .getString("label.structure_chooser"); - protected JInternalFrame mainFrame = new JInternalFrame(frameTitle); + public JInternalFrame mainFrame = new JInternalFrame(frameTitle); - protected JComboBox cmb_filterOption = new JComboBox<>(); + public JComboBox cmb_filterOption = new JComboBox<>(); - protected AlignmentPanel ap; + public AlignmentPanel ap; - protected StringBuilder errorWarning = new StringBuilder(); + public StringBuilder errorWarning = new StringBuilder(); protected JButton btn_add; @@ -123,14 +123,14 @@ public abstract class GStructureChooser extends JPanel protected JCheckBox chk_superpose = new JCheckBox( MessageManager.getString("label.superpose_structures")); - protected JTextField txt_search = new JTextField(14); + public JTextField txt_search = new JTextField(14); protected JPanel pnl_switchableViews = new JPanel(new CardLayout()); protected CardLayout layout_switchableViews = (CardLayout) (pnl_switchableViews .getLayout()); - protected JCheckBox chk_invertFilter = new JCheckBox( + public JCheckBox chk_invertFilter = new JCheckBox( MessageManager.getString("label.invert")); protected ImageIcon loadingImage = new ImageIcon( @@ -145,29 +145,29 @@ public abstract class GStructureChooser extends JPanel protected ImageIcon warningImage = new ImageIcon( getClass().getResource("/images/warning.gif")); - protected JLabel lbl_loading = new JLabel(loadingImage); + public JLabel lbl_loading = new JLabel(loadingImage); protected JLabel lbl_pdbManualFetchStatus = new JLabel(errorImage); protected JLabel lbl_fromFileStatus = new JLabel(errorImage); - protected AssociateSeqPanel idInputAssSeqPanel = new AssociateSeqPanel(); + public AssociateSeqPanel idInputAssSeqPanel = new AssociateSeqPanel(); - protected AssociateSeqPanel fileChooserAssSeqPanel = new AssociateSeqPanel(); + public AssociateSeqPanel fileChooserAssSeqPanel = new AssociateSeqPanel(); protected JComboBox targetView = new JComboBox<>(); - protected JTable tbl_local_pdb = new JTable(); + public JTable tbl_local_pdb = new JTable(); protected JTabbedPane pnl_filter = new JTabbedPane(); - protected FTSDataColumnPreferences pdbDocFieldPrefs = new FTSDataColumnPreferences( + public FTSDataColumnPreferences pdbDocFieldPrefs = new FTSDataColumnPreferences( PreferenceSource.STRUCTURE_CHOOSER, PDBFTSRestClient.getInstance()); protected FTSDataColumnI[] previousWantedFields; - protected static Map tempUserPrefs = new HashMap<>(); + public static Map tempUserPrefs = new HashMap<>(); private JTable tbl_summary = new JTable() { @@ -662,7 +662,7 @@ public abstract class GStructureChooser extends JPanel } -protected void closeAction(int preferredHeight) + public void closeAction(int preferredHeight) { // System.out.println(">>>>>>>>>> closing internal frame!!!"); // System.out.println("width : " + mainFrame.getWidth()); diff --git a/src/jalview/rest/RestHandler.java b/src/jalview/rest/RestHandler.java index a37882f..b897eaa 100644 --- a/src/jalview/rest/RestHandler.java +++ b/src/jalview/rest/RestHandler.java @@ -20,6 +20,7 @@ */ package jalview.rest; +import jalview.bin.Jalview; import jalview.httpserver.AbstractRequestHandler; import java.io.IOException; @@ -39,11 +40,6 @@ public class RestHandler extends AbstractRequestHandler private static final String MY_NAME = "Rest"; /** - * Singleton instance of this class - */ - private static RestHandler instance = null; - - /** * Returns the singleton instance of this class * * @return @@ -53,12 +49,10 @@ public class RestHandler extends AbstractRequestHandler { synchronized (RestHandler.class) { - if (instance == null) - { - instance = new RestHandler(); - } + Jalview j = Jalview.getInstance(); + return (j.restHandler == null ? j.restHandler = new RestHandler() + : j.restHandler); } - return instance; } /** diff --git a/src/jalview/schemes/AnnotationColourGradient.java b/src/jalview/schemes/AnnotationColourGradient.java index 75a07b9..7bb294a 100755 --- a/src/jalview/schemes/AnnotationColourGradient.java +++ b/src/jalview/schemes/AnnotationColourGradient.java @@ -21,6 +21,7 @@ package jalview.schemes; import jalview.api.AlignViewportI; +import jalview.bin.Jalview; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AnnotatedCollectionI; @@ -355,7 +356,7 @@ public class AnnotationColourGradient extends FollowerColourScheme { if (ann.isRNA()) { - result = ColourSchemeProperty.rnaHelices[(int) aj.value]; + result = Jalview.getInstance().rnaHelices[(int) aj.value]; } else { diff --git a/src/jalview/schemes/ColourSchemeProperty.java b/src/jalview/schemes/ColourSchemeProperty.java index 2d5b23d..90386e5 100755 --- a/src/jalview/schemes/ColourSchemeProperty.java +++ b/src/jalview/schemes/ColourSchemeProperty.java @@ -21,6 +21,7 @@ package jalview.schemes; import jalview.api.AlignViewportI; +import jalview.bin.Jalview; import jalview.datamodel.AnnotatedCollectionI; import jalview.util.ColorUtils; @@ -109,30 +110,30 @@ public class ColourSchemeProperty return ucs; } - public static Color rnaHelices[] = null; - public static void initRnaHelicesShading(int n) { - int j = 0; - if (rnaHelices == null) + int i = 0; + Jalview j = Jalview.getInstance(); + + if (j.rnaHelices == null) { - rnaHelices = new Color[n + 1]; + j.rnaHelices = new Color[n + 1]; } - else if (rnaHelices != null && rnaHelices.length <= n) + else if (j.rnaHelices != null && j.rnaHelices.length <= n) { Color[] t = new Color[n + 1]; - System.arraycopy(rnaHelices, 0, t, 0, rnaHelices.length); - j = rnaHelices.length; - rnaHelices = t; + 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 (; j <= n; j++) + for (; i <= n; i++) { - rnaHelices[j] = ColorUtils.generateRandomColor(Color.white); + j.rnaHelices[i] = ColorUtils.generateRandomColor(Color.white); } } @@ -141,7 +142,7 @@ public class ColourSchemeProperty */ public static void resetRnaHelicesShading() { - rnaHelices = null; + Jalview.getInstance().rnaHelices = null; } /** diff --git a/src/jalview/schemes/RNAHelicesColour.java b/src/jalview/schemes/RNAHelicesColour.java index 33b275d..041823f 100644 --- a/src/jalview/schemes/RNAHelicesColour.java +++ b/src/jalview/schemes/RNAHelicesColour.java @@ -21,6 +21,7 @@ package jalview.schemes; import jalview.api.AlignViewportI; +import jalview.bin.Jalview; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AnnotatedCollectionI; @@ -200,7 +201,7 @@ public class RNAHelicesColour extends ResidueColourScheme currentHelix = positionsToHelix.get(j); if (currentHelix != null) { - currentColour = ColourSchemeProperty.rnaHelices[Integer + currentColour = Jalview.getInstance().rnaHelices[Integer .parseInt(currentHelix)]; } return currentColour; diff --git a/src/jalview/schemes/ResidueProperties.java b/src/jalview/schemes/ResidueProperties.java index 5bbe46d..df6610a 100755 --- a/src/jalview/schemes/ResidueProperties.java +++ b/src/jalview/schemes/ResidueProperties.java @@ -498,34 +498,35 @@ public class ResidueProperties * Color.white, // R Color.white, // Y Color.white, // N Color.white, // Gap */ - public static String STOP = "STOP"; + public static final String STOP = "STOP"; - public static List STOP_CODONS = Arrays.asList("TGA", "TAA", "TAG"); + public static final List STOP_CODONS = Arrays.asList("TGA", "TAA", + "TAG"); - public static String START = "ATG"; + public static final String START = "ATG"; // Stores residue codes/names and colours and other things - public static Map> propHash = new Hashtable<>(); + public static final Map> propHash = new Hashtable<>(); - public static Map hydrophobic = new Hashtable<>(); + public static final Map hydrophobic = new Hashtable<>(); - public static Map polar = new Hashtable<>(); + public static final Map polar = new Hashtable<>(); - public static Map small = new Hashtable<>(); + public static final Map small = new Hashtable<>(); - public static Map positive = new Hashtable<>(); + public static final Map positive = new Hashtable<>(); - public static Map negative = new Hashtable<>(); + public static final Map negative = new Hashtable<>(); - public static Map charged = new Hashtable<>(); + public static final Map charged = new Hashtable<>(); - public static Map aromatic = new Hashtable<>(); + public static final Map aromatic = new Hashtable<>(); - public static Map aliphatic = new Hashtable<>(); + public static final Map aliphatic = new Hashtable<>(); - public static Map tiny = new Hashtable<>(); + public static final Map tiny = new Hashtable<>(); - public static Map proline = new Hashtable<>(); + public static final Map proline = new Hashtable<>(); static { @@ -908,7 +909,7 @@ public class ResidueProperties * lookup of (A-Z) alternative secondary structure symbols' * equivalents in DSSP3 notation */ - private static char[] toDssp3State; + private final static char[] toDssp3State; static { toDssp3State = new char[9]; // for 'A'-'I'; extend if needed diff --git a/src/jalview/structure/StructureImportSettings.java b/src/jalview/structure/StructureImportSettings.java index 9662fee..a6adac6 100644 --- a/src/jalview/structure/StructureImportSettings.java +++ b/src/jalview/structure/StructureImportSettings.java @@ -20,6 +20,7 @@ */ package jalview.structure; +import jalview.bin.Jalview; import jalview.datamodel.PDBEntry; import jalview.datamodel.PDBEntry.Type; @@ -32,25 +33,34 @@ import jalview.datamodel.PDBEntry.Type; */ public class StructureImportSettings { + + private static StructureImportSettings getInstance() + { + Jalview j = Jalview.getInstance(); + return (j.structureImportSettings == null + ? j.structureImportSettings = new StructureImportSettings() + : j.structureImportSettings); + } + /** * set to true to add derived sequence annotations (temp factor read from * file, or computed secondary structure) to the alignment */ - private static boolean visibleChainAnnotation = false; + private boolean visibleChainAnnotation = false; /** * Set true to predict secondary structure (using JMol for protein, Annotate3D * for RNA) */ - private static boolean processSecStr = false; + private boolean processSecStr = false; /** * Set true (with predictSecondaryStructure=true) to predict secondary * structure using an external service (currently Annotate3D for RNA only) */ - private static boolean externalSecondaryStructure = false; + private boolean externalSecondaryStructure = false; - private static boolean showSeqFeatures = true; + private boolean showSeqFeatures = true; public enum StructureParser { @@ -61,92 +71,93 @@ public class StructureImportSettings * Determines the default file format for structure files to be downloaded * from the PDB sequence fetcher. Possible options include: PDB|mmCIF */ - private static PDBEntry.Type defaultStructureFileFormat = Type.PDB; + private PDBEntry.Type defaultStructureFileFormat = Type.PDB; /** * Determines the parser used for parsing PDB format file. Possible options * are : JMolParser|JalveiwParser */ - private static StructureParser defaultPDBFileParser = StructureParser.JMOL_PARSER; + private StructureParser defaultPDBFileParser = StructureParser.JMOL_PARSER; public static void addSettings(boolean addAlignmentAnnotations, boolean processSecStr, boolean externalSecStr) { - StructureImportSettings.visibleChainAnnotation = addAlignmentAnnotations; - StructureImportSettings.processSecStr = processSecStr; - StructureImportSettings.externalSecondaryStructure = externalSecStr; - StructureImportSettings.showSeqFeatures = true; + StructureImportSettings s = getInstance(); + s.visibleChainAnnotation = addAlignmentAnnotations; + s.processSecStr = processSecStr; + s.externalSecondaryStructure = externalSecStr; + s.showSeqFeatures = true; } public static boolean isVisibleChainAnnotation() { - return visibleChainAnnotation; + return getInstance().visibleChainAnnotation; } public static void setVisibleChainAnnotation( boolean visibleChainAnnotation) { - StructureImportSettings.visibleChainAnnotation = visibleChainAnnotation; + getInstance().visibleChainAnnotation = visibleChainAnnotation; } public static boolean isProcessSecondaryStructure() { - return processSecStr; + return getInstance().processSecStr; } public static void setProcessSecondaryStructure( boolean processSecondaryStructure) { - StructureImportSettings.processSecStr = processSecondaryStructure; + getInstance().processSecStr = processSecondaryStructure; } public static boolean isExternalSecondaryStructure() { - return externalSecondaryStructure; + return getInstance().externalSecondaryStructure; } public static void setExternalSecondaryStructure( boolean externalSecondaryStructure) { - StructureImportSettings.externalSecondaryStructure = externalSecondaryStructure; + getInstance().externalSecondaryStructure = externalSecondaryStructure; } public static boolean isShowSeqFeatures() { - return showSeqFeatures; + return getInstance().showSeqFeatures; } public static void setShowSeqFeatures(boolean showSeqFeatures) { - StructureImportSettings.showSeqFeatures = showSeqFeatures; + getInstance().showSeqFeatures = showSeqFeatures; } public static PDBEntry.Type getDefaultStructureFileFormat() { - return defaultStructureFileFormat; + return getInstance().defaultStructureFileFormat; } public static void setDefaultStructureFileFormat( String defaultStructureFileFormat) { - StructureImportSettings.defaultStructureFileFormat = PDBEntry.Type + getInstance().defaultStructureFileFormat = PDBEntry.Type .valueOf(defaultStructureFileFormat.toUpperCase()); } public static String getDefaultPDBFileParser() { - return defaultPDBFileParser.toString(); + return getInstance().defaultPDBFileParser.toString(); } public static void setDefaultPDBFileParser( StructureParser defaultPDBFileParser) { - StructureImportSettings.defaultPDBFileParser = defaultPDBFileParser; + getInstance().defaultPDBFileParser = defaultPDBFileParser; } public static void setDefaultPDBFileParser(String defaultPDBFileParser) { - StructureImportSettings.defaultPDBFileParser = StructureParser + getInstance().defaultPDBFileParser = StructureParser .valueOf(defaultPDBFileParser.toUpperCase()); } diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index 6261e74..c2c66e5 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -22,6 +22,7 @@ package jalview.structure; import jalview.analysis.AlignSeq; import jalview.api.StructureSelectionManagerProvider; +import jalview.bin.Jalview; import jalview.commands.CommandI; import jalview.commands.EditCommand; import jalview.commands.OrderCommand; @@ -51,7 +52,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; -import java.util.IdentityHashMap; import java.util.List; import java.util.Map; import java.util.Vector; @@ -64,8 +64,6 @@ public class StructureSelectionManager { public final static String NEWLINE = System.lineSeparator(); - static IdentityHashMap instances; - private List mappings = new ArrayList<>(); private boolean processSecondaryStructure = false; @@ -197,16 +195,15 @@ public class StructureSelectionManager || pdbIdFileName.containsKey(idOrFile); } - private static StructureSelectionManager nullProvider = null; - public static StructureSelectionManager getStructureSelectionManager( StructureSelectionManagerProvider context) { + Jalview j = Jalview.getInstance(); if (context == null) { - if (nullProvider == null) + if (j.nullProvider == null) { - if (instances != null) + if (j.structureSelections != null) { throw new Error(MessageManager.getString( "error.implementation_error_structure_selection_manager_null"), @@ -215,27 +212,28 @@ public class StructureSelectionManager } else { - nullProvider = new StructureSelectionManager(); + j.nullProvider = new StructureSelectionManager(); } - return nullProvider; + return j.nullProvider; } } - if (instances == null) + if (j.structureSelections == null) { - instances = new java.util.IdentityHashMap<>(); + j.structureSelections = new java.util.IdentityHashMap<>(); } - StructureSelectionManager instance = instances.get(context); + StructureSelectionManager instance = Jalview + .getInstance().structureSelections.get(context); if (instance == null) { - if (nullProvider != null) + if (j.nullProvider != null) { - instance = nullProvider; + instance = j.nullProvider; } else { instance = new StructureSelectionManager(); } - instances.put(context, instance); + j.structureSelections.put(context, instance); } return instance; } @@ -269,7 +267,7 @@ public class StructureSelectionManager return relaySeqMappings; } - Vector listeners = new Vector(); + Vector listeners = new Vector<>(); /** * register a listener for alignment sequence mouseover events @@ -1333,14 +1331,15 @@ public class StructureSelectionManager { // synchronized (instances) { - if (instances == null) + if (Jalview.getInstance().structureSelections == null) { return; } - StructureSelectionManager mnger = (instances.get(jalviewLite)); + StructureSelectionManager mnger = (Jalview + .getInstance().structureSelections.get(jalviewLite)); if (mnger != null) { - instances.remove(jalviewLite); + Jalview.getInstance().structureSelections.remove(jalviewLite); try { mnger.finalize(); diff --git a/src/jalview/urls/IdOrgSettings.java b/src/jalview/urls/IdOrgSettings.java index 7dd1a19..4d42e0b 100644 --- a/src/jalview/urls/IdOrgSettings.java +++ b/src/jalview/urls/IdOrgSettings.java @@ -21,6 +21,8 @@ package jalview.urls; +import jalview.bin.Jalview; + /** * Holds settings for identifiers.org e.g. url, download location * @@ -29,27 +31,33 @@ package jalview.urls; */ public class IdOrgSettings { - private static String url; + private String url; + private String location; - private static String location; + public static IdOrgSettings getInstance() + { + Jalview j = Jalview.getInstance(); + return (j.idOrgSettings == null ? j.idOrgSettings = new IdOrgSettings() + : j.idOrgSettings); + } public static void setUrl(String seturl) { - url = seturl; + getInstance().url = seturl; } public static void setDownloadLocation(String setloc) { - location = setloc; + getInstance().location = setloc; } public static String getUrl() { - return url; + return getInstance().url; } public static String getDownloadLocation() { - return location; + return getInstance().location; } } diff --git a/src/jalview/util/BrowserLauncher.java b/src/jalview/util/BrowserLauncher.java index 8119daa..94d66f4 100755 --- a/src/jalview/util/BrowserLauncher.java +++ b/src/jalview/util/BrowserLauncher.java @@ -28,9 +28,22 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; /** - * BrowserLauncher is a class that provides one static method, openURL, which - * opens the default web browser for the current user of the system to the given - * URL. It may support other protocols depending on the system -- mailto, ftp, + * + * SwingJS note: Do not use methods in this class directly. Use + * + * Platform.openURL(String url) only. + * + * JavaScript does not see this class. + * + * BrowserLauncher is a class that provides two static methods: + * + * openURL(String url), which opens the default web browser for the current user + * of the system to the given URL, and + * + * resetBrowser(), which allows switching browsers in Java. + * + * + * openURL may support other protocols depending on the system -- mailto, ftp, * etc. -- but that has not been rigorously tested and is not guaranteed to * work. *

@@ -101,22 +114,22 @@ public class BrowserLauncher private static boolean loadedWithoutErrors; /** The com.apple.mrj.MRJFileUtils class */ - private static Class mrjFileUtilsClass; + private static Class mrjFileUtilsClass; /** The com.apple.mrj.MRJOSType class */ - private static Class mrjOSTypeClass; + private static Class mrjOSTypeClass; /** The com.apple.MacOS.AEDesc class */ - private static Class aeDescClass; + private static Class aeDescClass; /** The <init>(int) method of com.apple.MacOS.AETarget */ - private static Constructor aeTargetConstructor; + private static Constructor aeTargetConstructor; /** The <init>(int, int, int) method of com.apple.MacOS.AppleEvent */ - private static Constructor appleEventConstructor; + private static Constructor appleEventConstructor; /** The <init>(String) method of com.apple.MacOS.AEDesc */ - private static Constructor aeDescConstructor; + private static Constructor aeDescConstructor; /** The findFolder method of com.apple.mrj.MRJFileUtils */ private static Method findFolder; @@ -236,14 +249,6 @@ public class BrowserLauncher loadedWithoutErrors = true; - if (!Platform.isJS()) - /** - * Java only - * - * @j2sIgnore - * - */ - { String osName = System.getProperty("os.name"); if (osName.startsWith("Mac OS")) @@ -316,7 +321,6 @@ public class BrowserLauncher { // if we haven't hit any errors yet loadedWithoutErrors = loadClasses(); } - } } /** @@ -336,24 +340,17 @@ public class BrowserLauncher private static boolean loadClasses() { - if (!Platform.isJS()) - /** - * Java only - * - * @j2sIgnore - * - */ - { switch (jvm) { case MRJ_2_0: try { - Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget"); - Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils"); - Class appleEventClass = Class.forName("com.apple.MacOS.AppleEvent"); - Class aeClass = Class.forName("com.apple.MacOS.ae"); + Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget"); + Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils"); + Class appleEventClass = Class + .forName("com.apple.MacOS.AppleEvent"); + Class aeClass = Class.forName("com.apple.MacOS.ae"); aeDescClass = Class.forName("com.apple.MacOS.AEDesc"); aeTargetConstructor = aeTargetClass @@ -464,8 +461,8 @@ public class BrowserLauncher try { - Class linker = Class.forName("com.apple.mrj.jdirect.Linker"); - Constructor constructor = linker + Class linker = Class.forName("com.apple.mrj.jdirect.Linker"); + Constructor constructor = linker .getConstructor(new Class[] { Class.class }); linkage = constructor @@ -526,7 +523,6 @@ public class BrowserLauncher break; } - } return true; } @@ -543,14 +539,6 @@ public class BrowserLauncher */ private static Object locateBrowser() { - if (!Platform.isJS()) - /** - * Java only - * - * @j2sIgnore - * - */ - { if (browser != null) { return browser; @@ -716,11 +704,7 @@ public class BrowserLauncher break; } - - } - return browser; - } /** @@ -742,20 +726,11 @@ public class BrowserLauncher */ public static void openURL(String url) throws IOException { - if (Platform.isJS()) { Platform.openURL(url); return; } - else - /** - * Java only - * - * @j2sIgnore - */ - { - if (!loadedWithoutErrors) { throw new IOException(MessageManager @@ -934,14 +909,11 @@ public class BrowserLauncher break; default: - // This should never occur, but if it does, we'll try the simplest thing // possible Runtime.getRuntime().exec(new String[] { (String) browser, url }); - break; } - } } diff --git a/src/jalview/util/GroupUrlLink.java b/src/jalview/util/GroupUrlLink.java index 67309a0..512e046 100644 --- a/src/jalview/util/GroupUrlLink.java +++ b/src/jalview/util/GroupUrlLink.java @@ -20,13 +20,20 @@ */ package jalview.util; -import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; import java.util.Hashtable; +/** + * This class is not implemented because Preferences never puts anything in + * groupURLLinks. + * + * @author hansonr + * + */ public class GroupUrlLink { + @SuppressWarnings("serial") public class UrlStringTooLongException extends Exception { public UrlStringTooLongException(int lng) @@ -66,11 +73,6 @@ public class GroupUrlLink private String invalidMessage = null; /** - * tokens that can be replaced in the URL. - */ - private static String[] tokens; - - /** * position of each token (which can appear once only) in the url */ private int[] segs; @@ -79,32 +81,34 @@ public class GroupUrlLink * contains tokens in the order they appear in the URL template. */ private String[] mtch; - static - { - if (tokens == null) - { - tokens = new String[] { "SEQUENCEIDS", "SEQUENCES", "DATASETID" }; - } - } /** - * test for GroupURLType bitfield (with default tokens) - */ - public static final int SEQUENCEIDS = 1; - - /** - * test for GroupURLType bitfield (with default tokens) - */ - public static final int SEQUENCES = 2; - - /** - * test for GroupURLType bitfield (with default tokens) + * tokens that can be replaced in the URL. */ - public static final int DATASETID = 4; - + private static final String[] tokens = new String[] { "SEQUENCEIDS", + "SEQUENCES", "DATASETID" }; + + // /** + // * test for GroupURLType bitfield (with default tokens) + // */ + // private static final int SEQUENCEIDS = 1; + // + // /** + // * test for GroupURLType bitfield (with default tokens) + // */ + // private static final int SEQUENCES = 2; + // + // /** + // * test for GroupURLType bitfield (with default tokens) + // */ + // private static final int DATASETID = 4; + // // private int idseg = -1, seqseg = -1; /** + * + * called by PopupMenu.buildGroupURLMenu() + * * parse the given linkString of the form '