JAL-3253 ApplicationSingletonProvider replaces Instance
[jalview.git] / src / jalview / structure / StructureImportSettings.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.structure;
22
23 import jalview.bin.ApplicationSingletonProvider;
24 import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
25 import jalview.datamodel.PDBEntry;
26 import jalview.datamodel.PDBEntry.Type;
27
28 /**
29  * bean holding settings for structure IO. TODO: tests for validation of values
30  * TODO: tests for race conditions (all fields are static, is that correct ?)
31  * 
32  * @author tcofoegbu
33  *
34  */
35 public class StructureImportSettings implements ApplicationSingletonI
36 {
37
38   private StructureImportSettings()
39   {
40     // private singleton
41   }
42
43   private static StructureImportSettings getInstance()
44   {
45     return (StructureImportSettings) ApplicationSingletonProvider
46             .getInstance(StructureImportSettings.class);
47   }
48
49   /**
50    * set to true to add derived sequence annotations (temp factor read from
51    * file, or computed secondary structure) to the alignment
52    */
53   private boolean visibleChainAnnotation = false;
54
55   /**
56    * Set true to predict secondary structure (using JMol for protein, Annotate3D
57    * for RNA)
58    */
59   private boolean processSecStr = false;
60
61   /**
62    * Set true (with predictSecondaryStructure=true) to predict secondary
63    * structure using an external service (currently Annotate3D for RNA only)
64    */
65   private boolean externalSecondaryStructure = false;
66
67   private boolean showSeqFeatures = true;
68
69   public enum StructureParser
70   {
71     JMOL_PARSER, JALVIEW_PARSER
72   }
73
74   /**
75    * Determines the default file format for structure files to be downloaded
76    * from the PDB sequence fetcher. Possible options include: PDB|mmCIF
77    */
78   private PDBEntry.Type defaultStructureFileFormat = Type.PDB;
79
80   /**
81    * Determines the parser used for parsing PDB format file. Possible options
82    * are : JMolParser|JalveiwParser
83    */
84   private StructureParser defaultPDBFileParser = StructureParser.JMOL_PARSER;
85
86   public static void addSettings(boolean addAlignmentAnnotations,
87           boolean processSecStr, boolean externalSecStr)
88   {
89     StructureImportSettings s = getInstance();
90     s.visibleChainAnnotation = addAlignmentAnnotations;
91     s.processSecStr = processSecStr;
92     s.externalSecondaryStructure = externalSecStr;
93     s.showSeqFeatures = true;
94   }
95
96   public static boolean isVisibleChainAnnotation()
97   {
98     return getInstance().visibleChainAnnotation;
99   }
100
101   public static void setVisibleChainAnnotation(
102           boolean visibleChainAnnotation)
103   {
104     getInstance().visibleChainAnnotation = visibleChainAnnotation;
105   }
106
107   public static boolean isProcessSecondaryStructure()
108   {
109     return getInstance().processSecStr;
110   }
111
112   public static void setProcessSecondaryStructure(
113           boolean processSecondaryStructure)
114   {
115     getInstance().processSecStr = processSecondaryStructure;
116   }
117
118   public static boolean isExternalSecondaryStructure()
119   {
120     return getInstance().externalSecondaryStructure;
121   }
122
123   public static void setExternalSecondaryStructure(
124           boolean externalSecondaryStructure)
125   {
126     getInstance().externalSecondaryStructure = externalSecondaryStructure;
127   }
128
129   public static boolean isShowSeqFeatures()
130   {
131     return getInstance().showSeqFeatures;
132   }
133
134   public static void setShowSeqFeatures(boolean showSeqFeatures)
135   {
136     getInstance().showSeqFeatures = showSeqFeatures;
137   }
138
139   public static PDBEntry.Type getDefaultStructureFileFormat()
140   {
141     return getInstance().defaultStructureFileFormat;
142   }
143
144   public static void setDefaultStructureFileFormat(
145           String defaultStructureFileFormat)
146   {
147     getInstance().defaultStructureFileFormat = PDBEntry.Type
148             .valueOf(defaultStructureFileFormat.toUpperCase());
149   }
150
151   public static String getDefaultPDBFileParser()
152   {
153     return getInstance().defaultPDBFileParser.toString();
154   }
155
156   public static void setDefaultPDBFileParser(
157           StructureParser defaultPDBFileParser)
158   {
159     getInstance().defaultPDBFileParser = defaultPDBFileParser;
160   }
161
162   public static void setDefaultPDBFileParser(String defaultPDBFileParser)
163   {
164     getInstance().defaultPDBFileParser = StructureParser
165             .valueOf(defaultPDBFileParser.toUpperCase());
166   }
167
168 }