GPL license added
[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 \r
20 package jalview.gui;\r
21 \r
22 import jalview.jbgui.*;\r
23 import jalview.schemes.*;\r
24 import jalview.io.*;\r
25 \r
26 import jalview.bin.Cache;\r
27 import javax.swing.*;\r
28 import java.awt.event.ActionEvent;\r
29 import java.awt.*;\r
30 \r
31 \r
32 public class Preferences extends GPreferences\r
33 {\r
34   static boolean preferencesLoaded=false;\r
35 \r
36   public static boolean showFullscreen=false;\r
37   public static boolean showFullId=true;\r
38   public static boolean showAnnotation=true;\r
39   public static boolean showConservation=true;\r
40   public static boolean showQuality=true;\r
41   public static boolean showIdentity=true;\r
42   public static String fontName="SansSerif";\r
43   public static String fontSize="10";\r
44   public static String fontStyle=Font.PLAIN+"";\r
45   public static char gapSymbol='-';\r
46   public static String defaultColour=null;\r
47   public static boolean showStartupFile=true;\r
48   public static String startupFile = "http://www.jalview.org/examples/exampleFile.jar";\r
49 \r
50   JInternalFrame frame;\r
51 \r
52   public static void initPreferences()\r
53   {\r
54   String string = Cache.getProperty("SHOW_FULL_ID");\r
55   if(string!=null)\r
56     showFullId = Boolean.valueOf(string).booleanValue();\r
57 \r
58   string = Cache.getProperty("SHOW_FULLSCREEN");\r
59   if(string!=null)\r
60     showFullscreen = Boolean.valueOf(string).booleanValue();\r
61 \r
62   string = Cache.getProperty("SHOW_ANNOTATIONS");\r
63       if(string!=null)\r
64     showAnnotation = Boolean.valueOf(string).booleanValue();\r
65 \r
66   string = Cache.getProperty("SHOW_CONSERVATION");\r
67       if(string!=null)\r
68     showConservation = Boolean.valueOf(string).booleanValue();\r
69   string = Cache.getProperty("SHOW_QUALITY");\r
70       if(string!=null)\r
71     showQuality = Boolean.valueOf(string).booleanValue();\r
72   string = Cache.getProperty("SHOW_IDENTITY");\r
73       if(string!=null)\r
74     showIdentity = Boolean.valueOf(string).booleanValue();\r
75 \r
76   string = Cache.getProperty("GAP_SYMBOL");\r
77       if(string!=null)\r
78     gapSymbol = string.charAt(0);\r
79 \r
80   string = Cache.getProperty("SHOW_FULL_ID");\r
81     if(string!=null)\r
82       showFullId = Boolean.valueOf(string).booleanValue();\r
83 \r
84     string = Cache.getProperty("FONT_NAME");\r
85     if (string != null)\r
86       fontName = string;\r
87 \r
88     string = Cache.getProperty("FONT_STYLE");\r
89     if (string != null)\r
90       fontStyle = string;\r
91 \r
92     string = Cache.getProperty("FONT_SIZE");\r
93     if (string != null)\r
94       fontSize = string;\r
95 \r
96 \r
97   string = Cache.getProperty("DEFAULT_COLOUR");\r
98   if(string!=null)\r
99       defaultColour = string;\r
100 \r
101   string = Cache.getProperty("STARTUP_FILE");\r
102     if(string!=null)\r
103       startupFile = string;\r
104 \r
105   string = Cache.getProperty("SHOW_STARTUP_FILE");\r
106         if(string!=null)\r
107       showStartupFile = Boolean.valueOf(string).booleanValue();\r
108 \r
109       preferencesLoaded = true;\r
110   }\r
111 \r
112   public Preferences()\r
113   {\r
114     initPreferences();\r
115 \r
116     frame = new JInternalFrame();\r
117     frame.setContentPane(this);\r
118     Desktop.addInternalFrame(frame, "Preferences", 480,390 );\r
119 \r
120     fullID.setSelected(showFullId);\r
121     String string = Cache.getProperty("SHOW_FULLSCREEN");\r
122     boolean value = false;\r
123     if(string!=null)\r
124       value =  Boolean.valueOf(string).booleanValue();\r
125 \r
126     fullScreen.setSelected(value);\r
127     annotations.setSelected(showAnnotation);\r
128 \r
129     conservation.setEnabled(showAnnotation);\r
130     quality.setEnabled(showAnnotation);\r
131     identity.setEnabled(showAnnotation);\r
132 \r
133     conservation.setSelected(showConservation);\r
134     quality.setSelected(showQuality);\r
135     identity.setSelected(showIdentity);\r
136 \r
137     for(int i=0; i<12; i++)\r
138       colour.addItem( ColourSchemeProperty.getColourName(i) );\r
139 \r
140     string = Cache.getProperty("DEFAULT_COLOUR");\r
141     if(string!=null)\r
142       colour.setSelectedItem( string );\r
143     else\r
144       colour.setSelectedIndex( 11 );\r
145 \r
146     String fonts[] = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();\r
147     for(int i=0; i<fonts.length; i++)\r
148       fontNameCB.addItem(fonts[i]);\r
149 \r
150     for(int i=1; i<31; i++)\r
151       fontSizeCB.addItem(i+"");\r
152 \r
153    fontStyleCB.addItem("plain");\r
154    fontStyleCB.addItem("bold");\r
155    fontStyleCB.addItem("italic");\r
156 \r
157    fontNameCB.setSelectedItem(fontName);\r
158    fontSizeCB.setSelectedItem(fontSize);\r
159    fontStyleCB.setSelectedItem(fontStyle);\r
160 \r
161    gapSymbolCB.addItem("-");\r
162    gapSymbolCB.addItem(".");\r
163 \r
164    gapSymbolCB.setSelectedItem( gapSymbol+"" );\r
165 \r
166    startupCheckbox.setSelected(showStartupFile);\r
167    startupFileTextfield.setText(startupFile);\r
168 \r
169   }\r
170 \r
171   public void ok_actionPerformed(ActionEvent e)\r
172   {\r
173     showFullId =  fullID.isSelected() ;\r
174     showFullscreen = fullScreen.isSelected();\r
175     showAnnotation = annotations.isSelected();\r
176     showConservation = conservation.isSelected();\r
177     showQuality = quality.isSelected();\r
178     showIdentity = identity.isSelected();\r
179     defaultColour = colour.getSelectedItem().toString();\r
180     gapSymbol = gapSymbolCB.getSelectedItem().toString().charAt(0);\r
181     fontName = fontNameCB.getSelectedItem().toString();\r
182     fontSize = fontSizeCB.getSelectedItem().toString();\r
183     fontStyle = fontStyleCB.getSelectedItem().toString();\r
184     startupFile = startupFileTextfield.getText();\r
185     showStartupFile = startupCheckbox.isSelected();\r
186 \r
187     Cache.setProperty("SHOW_FULL_ID", Boolean.toString(showFullId));\r
188     Cache.setProperty("SHOW_FULLSCREEN", Boolean.toString( showFullscreen ) );\r
189 \r
190     Cache.setProperty("SHOW_ANNOTATIONS", Boolean.toString( showAnnotation  ));\r
191     Cache.setProperty("SHOW_CONSERVATION", Boolean.toString( showConservation ));\r
192     Cache.setProperty("SHOW_QUALITY", Boolean.toString( showQuality ));\r
193     Cache.setProperty("SHOW_IDENTITY", Boolean.toString( showIdentity ));\r
194 \r
195     Cache.setProperty("DEFAULT_COLOUR", defaultColour);\r
196     Cache.setProperty("GAP_SYMBOL", gapSymbol+"");\r
197 \r
198     Cache.setProperty("FONT_NAME", fontName);\r
199     Cache.setProperty("FONT_STYLE", fontStyle);\r
200     Cache.setProperty("FONT_SIZE", fontSize);\r
201 \r
202     Cache.setProperty("STARTUP_FILE", startupFile);\r
203     Cache.setProperty("SHOW_STARTUP_FILE", Boolean.toString(showStartupFile));\r
204 \r
205 \r
206 \r
207     try    {\r
208       frame.setClosed(true);\r
209     }    catch (Exception ex)  {}\r
210 \r
211   }\r
212 \r
213   public void startupFileTextfield_mouseClicked()\r
214   {\r
215     JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY"),\r
216         new String[]{"fa, fasta, fastq", "aln",  "pfam", "msf", "pir","blc","jar"},\r
217         new String[]{"Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"}\r
218        ,jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));\r
219    chooser.setFileView(new JalviewFileView());\r
220    chooser.setDialogTitle("Select startup file");\r
221    int value = chooser.showOpenDialog(this);\r
222    if(value == JalviewFileChooser.APPROVE_OPTION)\r
223    {\r
224      jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());\r
225      startupFileTextfield.setText( chooser.getSelectedFile().getAbsolutePath() );\r
226    }\r
227   }\r
228 \r
229 \r
230   public void cancel_actionPerformed(ActionEvent e)\r
231   {\r
232     try{\r
233       frame.setClosed(true);\r
234     }catch(Exception ex){}\r
235   }\r
236 \r
237   public void annotations_actionPerformed(ActionEvent e)\r
238   {\r
239     conservation.setEnabled(annotations.isSelected());\r
240     quality.setEnabled(annotations.isSelected());\r
241     identity.setEnabled(annotations.isSelected());\r
242   }\r
243 \r
244 }\r