Formatted source
[jalview.git] / src / jalview / gui / Preferences.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer\r
3  * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4  *\r
5  * This program is free software; you can redistribute it and/or\r
6  * modify it under the terms of the GNU General Public License\r
7  * as published by the Free Software Foundation; either version 2\r
8  * of the License, or (at your option) any later version.\r
9  *\r
10  * This program is distributed in the hope that it will be useful,\r
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13  * GNU General Public License for more details.\r
14  *\r
15  * You should have received a copy of the GNU General Public License\r
16  * along with this program; if not, write to the Free Software\r
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18  */\r
19 package jalview.gui;\r
20 \r
21 import java.awt.*;\r
22 import java.awt.event.*;\r
23 import javax.swing.*;\r
24 \r
25 import jalview.bin.*;\r
26 import jalview.io.*;\r
27 import jalview.jbgui.*;\r
28 import jalview.schemes.*;\r
29 \r
30 public class Preferences\r
31     extends GPreferences\r
32 {\r
33   static boolean preferencesLoaded = false;\r
34   public static boolean showFullscreen = false;\r
35   public static boolean showFullId = true;\r
36   public static boolean showAnnotation = true;\r
37   public static boolean showConservation = true;\r
38   public static boolean showQuality = true;\r
39   public static boolean showIdentity = true;\r
40   public static String fontName = "SansSerif";\r
41   public static String fontSize = "10";\r
42   public static String fontStyle = Font.PLAIN + "";\r
43   public static char gapSymbol = '-';\r
44   public static String defaultColour = null;\r
45   public static boolean showStartupFile = true;\r
46   public static String startupFile =\r
47       "http://www.jalview.org/examples/exampleFile.jar";\r
48   JInternalFrame frame;\r
49 \r
50   public Preferences()\r
51   {\r
52     initPreferences();\r
53 \r
54     frame = new JInternalFrame();\r
55     frame.setContentPane(this);\r
56     Desktop.addInternalFrame(frame, "Preferences", 480, 390);\r
57 \r
58     fullID.setSelected(showFullId);\r
59 \r
60     String string = Cache.getProperty("SHOW_FULLSCREEN");\r
61     boolean value = false;\r
62 \r
63     if (string != null)\r
64     {\r
65       value = Boolean.valueOf(string).booleanValue();\r
66     }\r
67 \r
68     fullScreen.setSelected(value);\r
69     annotations.setSelected(showAnnotation);\r
70 \r
71     conservation.setEnabled(showAnnotation);\r
72     quality.setEnabled(showAnnotation);\r
73     identity.setEnabled(showAnnotation);\r
74 \r
75     conservation.setSelected(showConservation);\r
76     quality.setSelected(showQuality);\r
77     identity.setSelected(showIdentity);\r
78 \r
79     for (int i = 0; i < 12; i++)\r
80     {\r
81       colour.addItem(ColourSchemeProperty.getColourName(i));\r
82     }\r
83 \r
84     string = Cache.getProperty("DEFAULT_COLOUR");\r
85 \r
86     if (string != null)\r
87     {\r
88       colour.setSelectedItem(string);\r
89     }\r
90     else\r
91     {\r
92       colour.setSelectedIndex(11);\r
93     }\r
94 \r
95     String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment()\r
96         .getAvailableFontFamilyNames();\r
97 \r
98     for (int i = 0; i < fonts.length; i++)\r
99     {\r
100       fontNameCB.addItem(fonts[i]);\r
101     }\r
102 \r
103     for (int i = 1; i < 31; i++)\r
104     {\r
105       fontSizeCB.addItem(i + "");\r
106     }\r
107 \r
108     fontStyleCB.addItem("plain");\r
109     fontStyleCB.addItem("bold");\r
110     fontStyleCB.addItem("italic");\r
111 \r
112     fontNameCB.setSelectedItem(fontName);\r
113     fontSizeCB.setSelectedItem(fontSize);\r
114     fontStyleCB.setSelectedItem(fontStyle);\r
115 \r
116     gapSymbolCB.addItem("-");\r
117     gapSymbolCB.addItem(".");\r
118 \r
119     gapSymbolCB.setSelectedItem(gapSymbol + "");\r
120 \r
121     startupCheckbox.setSelected(showStartupFile);\r
122     startupFileTextfield.setText(startupFile);\r
123   }\r
124 \r
125   public static void initPreferences()\r
126   {\r
127     String string = Cache.getProperty("SHOW_FULL_ID");\r
128 \r
129     if (string != null)\r
130     {\r
131       showFullId = Boolean.valueOf(string).booleanValue();\r
132     }\r
133 \r
134     string = Cache.getProperty("SHOW_FULLSCREEN");\r
135 \r
136     if (string != null)\r
137     {\r
138       showFullscreen = Boolean.valueOf(string).booleanValue();\r
139     }\r
140 \r
141     string = Cache.getProperty("SHOW_ANNOTATIONS");\r
142 \r
143     if (string != null)\r
144     {\r
145       showAnnotation = Boolean.valueOf(string).booleanValue();\r
146     }\r
147 \r
148     string = Cache.getProperty("SHOW_CONSERVATION");\r
149 \r
150     if (string != null)\r
151     {\r
152       showConservation = Boolean.valueOf(string).booleanValue();\r
153     }\r
154 \r
155     string = Cache.getProperty("SHOW_QUALITY");\r
156 \r
157     if (string != null)\r
158     {\r
159       showQuality = Boolean.valueOf(string).booleanValue();\r
160     }\r
161 \r
162     string = Cache.getProperty("SHOW_IDENTITY");\r
163 \r
164     if (string != null)\r
165     {\r
166       showIdentity = Boolean.valueOf(string).booleanValue();\r
167     }\r
168 \r
169     string = Cache.getProperty("GAP_SYMBOL");\r
170 \r
171     if (string != null)\r
172     {\r
173       gapSymbol = string.charAt(0);\r
174     }\r
175 \r
176     string = Cache.getProperty("SHOW_FULL_ID");\r
177 \r
178     if (string != null)\r
179     {\r
180       showFullId = Boolean.valueOf(string).booleanValue();\r
181     }\r
182 \r
183     string = Cache.getProperty("FONT_NAME");\r
184 \r
185     if (string != null)\r
186     {\r
187       fontName = string;\r
188     }\r
189 \r
190     string = Cache.getProperty("FONT_STYLE");\r
191 \r
192     if (string != null)\r
193     {\r
194       fontStyle = string;\r
195     }\r
196 \r
197     string = Cache.getProperty("FONT_SIZE");\r
198 \r
199     if (string != null)\r
200     {\r
201       fontSize = string;\r
202     }\r
203 \r
204     string = Cache.getProperty("DEFAULT_COLOUR");\r
205 \r
206     if (string != null)\r
207     {\r
208       defaultColour = string;\r
209     }\r
210 \r
211     string = Cache.getProperty("STARTUP_FILE");\r
212 \r
213     if (string != null)\r
214     {\r
215       startupFile = string;\r
216     }\r
217 \r
218     string = Cache.getProperty("SHOW_STARTUP_FILE");\r
219 \r
220     if (string != null)\r
221     {\r
222       showStartupFile = Boolean.valueOf(string).booleanValue();\r
223     }\r
224 \r
225     preferencesLoaded = true;\r
226   }\r
227 \r
228   public void ok_actionPerformed(ActionEvent e)\r
229   {\r
230     showFullId = fullID.isSelected();\r
231     showFullscreen = fullScreen.isSelected();\r
232     showAnnotation = annotations.isSelected();\r
233     showConservation = conservation.isSelected();\r
234     showQuality = quality.isSelected();\r
235     showIdentity = identity.isSelected();\r
236     defaultColour = colour.getSelectedItem().toString();\r
237     gapSymbol = gapSymbolCB.getSelectedItem().toString().charAt(0);\r
238     fontName = fontNameCB.getSelectedItem().toString();\r
239     fontSize = fontSizeCB.getSelectedItem().toString();\r
240     fontStyle = fontStyleCB.getSelectedItem().toString();\r
241     startupFile = startupFileTextfield.getText();\r
242     showStartupFile = startupCheckbox.isSelected();\r
243 \r
244     Cache.setProperty("SHOW_FULL_ID", Boolean.toString(showFullId));\r
245     Cache.setProperty("SHOW_FULLSCREEN", Boolean.toString(showFullscreen));\r
246 \r
247     Cache.setProperty("SHOW_ANNOTATIONS", Boolean.toString(showAnnotation));\r
248     Cache.setProperty("SHOW_CONSERVATION",\r
249                       Boolean.toString(showConservation));\r
250     Cache.setProperty("SHOW_QUALITY", Boolean.toString(showQuality));\r
251     Cache.setProperty("SHOW_IDENTITY", Boolean.toString(showIdentity));\r
252 \r
253     Cache.setProperty("DEFAULT_COLOUR", defaultColour);\r
254     Cache.setProperty("GAP_SYMBOL", gapSymbol + "");\r
255 \r
256     Cache.setProperty("FONT_NAME", fontName);\r
257     Cache.setProperty("FONT_STYLE", fontStyle);\r
258     Cache.setProperty("FONT_SIZE", fontSize);\r
259 \r
260     Cache.setProperty("STARTUP_FILE", startupFile);\r
261     Cache.setProperty("SHOW_STARTUP_FILE", Boolean.toString(showStartupFile));\r
262 \r
263     try\r
264     {\r
265       frame.setClosed(true);\r
266     }\r
267     catch (Exception ex)\r
268     {\r
269     }\r
270   }\r
271 \r
272   public void startupFileTextfield_mouseClicked()\r
273   {\r
274     JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.\r
275         getProperty(\r
276             "LAST_DIRECTORY"),\r
277         new String[]\r
278         {\r
279         "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",\r
280         "jar"\r
281     },\r
282         new String[]\r
283         {\r
284         "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"\r
285     }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));\r
286     chooser.setFileView(new JalviewFileView());\r
287     chooser.setDialogTitle("Select startup file");\r
288 \r
289     int value = chooser.showOpenDialog(this);\r
290 \r
291     if (value == JalviewFileChooser.APPROVE_OPTION)\r
292     {\r
293       jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",\r
294                                     chooser.getSelectedFormat());\r
295       startupFileTextfield.setText(chooser.getSelectedFile()\r
296                                    .getAbsolutePath());\r
297     }\r
298   }\r
299 \r
300   public void cancel_actionPerformed(ActionEvent e)\r
301   {\r
302     try\r
303     {\r
304       frame.setClosed(true);\r
305     }\r
306     catch (Exception ex)\r
307     {\r
308     }\r
309   }\r
310 \r
311   public void annotations_actionPerformed(ActionEvent e)\r
312   {\r
313     conservation.setEnabled(annotations.isSelected());\r
314     quality.setEnabled(annotations.isSelected());\r
315     identity.setEnabled(annotations.isSelected());\r
316   }\r
317 }\r