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