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