JAL-3253 jalview.bin.Instance handles all singleton instances -
[jalview.git] / src / jalview / bin / Instance.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.bin;
22
23 import jalview.analysis.AlignmentSorter;
24 import jalview.analysis.scoremodels.ScoreModels;
25 import jalview.api.StructureSelectionManagerProvider;
26 import jalview.ext.ensembl.EnsemblInfo;
27 import jalview.fts.service.pdb.PDBFTSRestClient;
28 import jalview.fts.service.uniprot.UniProtFTSRestClient;
29 import jalview.gui.Desktop;
30 import jalview.httpserver.HttpServer;
31 import jalview.io.gff.SequenceOntologyI;
32 import jalview.rest.RestHandler;
33 import jalview.structure.StructureImportSettings;
34 import jalview.structure.StructureSelectionManager;
35 import jalview.urls.IdOrgSettings;
36 import jalview.ws.SequenceFetcher;
37 import jalview.ws.jws1.Discoverer;
38 import jalview.ws.jws2.Jws2Discoverer;
39 import jalview.ws.jws2.jabaws2.Jws2InstanceFactory;
40 import jalview.ws.rest.RestClient;
41 import jalview.ws.sifts.SiftsSettings;
42
43 import java.awt.Color;
44 import java.util.IdentityHashMap;
45
46 /**
47  * a class to hold singleton instances so that they are not shared
48  * 
49  * @author hansonr
50  *
51  */
52 public class Instance {
53
54   private static Instance instance;
55
56   public static Instance getInstance()
57   {
58     Instance i;
59     @SuppressWarnings("unused")
60     ThreadGroup g = Thread.currentThread().getThreadGroup();
61     /**
62      * @j2sNative i = g._instance;
63      */
64     {
65       i = instance;
66     }
67     if (i == null)
68     {
69       i = instance = new Instance();
70       /**
71        * @j2sNative g._instance = i;
72        */
73     }
74     return i;
75   }
76
77   /**
78    * singleton instance of this class in Java only
79    */
80
81   public Jalview jalview;
82
83   public Desktop desktop;
84
85   public static Jalview getJalview()
86   {
87     Instance i = getInstance();
88     if (i.jalview == null)
89     {
90       new Jalview();
91     }
92     return i.jalview;
93   }
94
95   public static void setJalview(Jalview j)
96   {
97     getInstance().jalview = j;
98   }
99
100   public static Desktop getDesktop()
101   {
102     Instance i = getInstance();
103     return (i.desktop == null ? (i.desktop = new Desktop(true))
104             : i.desktop);
105   }
106
107   public static void setDesktop(Desktop d)
108   {
109     getInstance().desktop = d;
110   }
111
112   public Cache cache;
113
114   public AlignmentSorter alignmentSorter;
115
116   public Color[] rnaHelices = null;
117
118   public Discoverer discoverer;
119
120   public EnsemblInfo ensemblInfo;
121
122   public HttpServer httpServer;
123
124   public IdOrgSettings idOrgSettings;
125
126   public Jws2Discoverer j2s2discoverer;
127
128   public Jws2InstanceFactory jws2InstanceFactory;
129
130   public PDBFTSRestClient pdbFTSRestClient;
131
132   public RestClient restClient;
133
134   public RestHandler restHandler;
135
136   public ScoreModels scoreModels;
137
138   public SequenceFetcher sequenceFetcher;
139
140   public SequenceOntologyI sequenceOntology;
141
142   public SiftsSettings siftsSettings;
143
144   public StructureImportSettings structureImportSettings;
145
146   public UniProtFTSRestClient uniprotFTSRestClient;
147
148   public IdentityHashMap<StructureSelectionManagerProvider, StructureSelectionManager> structureSelections;
149
150 }