Formatted source
[jalview.git] / src / jalview / gui / Preferences.java
index 4708ced..b16ae32 100755 (executable)
 /*\r
-* Jalview - A Sequence Alignment Editor and Viewer\r
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
-*\r
-* This program is free software; you can redistribute it and/or\r
-* modify it under the terms of the GNU General Public License\r
-* as published by the Free Software Foundation; either version 2\r
-* of the License, or (at your option) any later version.\r
-*\r
-* This program is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-* GNU General Public License for more details.\r
-*\r
-* You should have received a copy of the GNU General Public License\r
-* along with this program; if not, write to the Free Software\r
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
-*/\r
-\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+ */\r
 package jalview.gui;\r
 \r
-import jalview.jbgui.*;\r
-import jalview.schemes.*;\r
-import jalview.io.*;\r
-\r
-import jalview.bin.Cache;\r
-import javax.swing.*;\r
-import java.awt.event.ActionEvent;\r
 import java.awt.*;\r
+import java.awt.event.*;\r
+import javax.swing.*;\r
 \r
+import jalview.bin.*;\r
+import jalview.io.*;\r
+import jalview.jbgui.*;\r
+import jalview.schemes.*;\r
 \r
-public class Preferences extends GPreferences\r
+public class Preferences\r
+    extends GPreferences\r
 {\r
-  static boolean preferencesLoaded=false;\r
-\r
-  public static boolean showFullscreen=false;\r
-  public static boolean showFullId=true;\r
-  public static boolean showAnnotation=true;\r
-  public static boolean showConservation=true;\r
-  public static boolean showQuality=true;\r
-  public static boolean showIdentity=true;\r
-  public static String fontName="SansSerif";\r
-  public static String fontSize="10";\r
-  public static String fontStyle=Font.PLAIN+"";\r
-  public static char gapSymbol='-';\r
-  public static String defaultColour=null;\r
-  public static boolean showStartupFile=true;\r
-  public static String startupFile = "http://www.jalview.org/examples/exampleFile.jar";\r
-\r
+  static boolean preferencesLoaded = false;\r
+  public static boolean showFullscreen = false;\r
+  public static boolean showFullId = true;\r
+  public static boolean showAnnotation = true;\r
+  public static boolean showConservation = true;\r
+  public static boolean showQuality = true;\r
+  public static boolean showIdentity = true;\r
+  public static String fontName = "SansSerif";\r
+  public static String fontSize = "10";\r
+  public static String fontStyle = Font.PLAIN + "";\r
+  public static char gapSymbol = '-';\r
+  public static String defaultColour = null;\r
+  public static boolean showStartupFile = true;\r
+  public static String startupFile =\r
+      "http://www.jalview.org/examples/exampleFile.jar";\r
   JInternalFrame frame;\r
 \r
-  public static void initPreferences()\r
-  {\r
-  String string = Cache.getProperty("SHOW_FULL_ID");\r
-  if(string!=null)\r
-    showFullId = Boolean.valueOf(string).booleanValue();\r
-\r
-  string = Cache.getProperty("SHOW_FULLSCREEN");\r
-  if(string!=null)\r
-    showFullscreen = Boolean.valueOf(string).booleanValue();\r
-\r
-  string = Cache.getProperty("SHOW_ANNOTATIONS");\r
-      if(string!=null)\r
-    showAnnotation = Boolean.valueOf(string).booleanValue();\r
-\r
-  string = Cache.getProperty("SHOW_CONSERVATION");\r
-      if(string!=null)\r
-    showConservation = Boolean.valueOf(string).booleanValue();\r
-  string = Cache.getProperty("SHOW_QUALITY");\r
-      if(string!=null)\r
-    showQuality = Boolean.valueOf(string).booleanValue();\r
-  string = Cache.getProperty("SHOW_IDENTITY");\r
-      if(string!=null)\r
-    showIdentity = Boolean.valueOf(string).booleanValue();\r
-\r
-  string = Cache.getProperty("GAP_SYMBOL");\r
-      if(string!=null)\r
-    gapSymbol = string.charAt(0);\r
-\r
-  string = Cache.getProperty("SHOW_FULL_ID");\r
-    if(string!=null)\r
-      showFullId = Boolean.valueOf(string).booleanValue();\r
-\r
-    string = Cache.getProperty("FONT_NAME");\r
-    if (string != null)\r
-      fontName = string;\r
-\r
-    string = Cache.getProperty("FONT_STYLE");\r
-    if (string != null)\r
-      fontStyle = string;\r
-\r
-    string = Cache.getProperty("FONT_SIZE");\r
-    if (string != null)\r
-      fontSize = string;\r
-\r
-\r
-  string = Cache.getProperty("DEFAULT_COLOUR");\r
-  if(string!=null)\r
-      defaultColour = string;\r
-\r
-  string = Cache.getProperty("STARTUP_FILE");\r
-    if(string!=null)\r
-      startupFile = string;\r
-\r
-  string = Cache.getProperty("SHOW_STARTUP_FILE");\r
-        if(string!=null)\r
-      showStartupFile = Boolean.valueOf(string).booleanValue();\r
-\r
-      preferencesLoaded = true;\r
-  }\r
-\r
   public Preferences()\r
   {\r
     initPreferences();\r
 \r
     frame = new JInternalFrame();\r
     frame.setContentPane(this);\r
-    Desktop.addInternalFrame(frame, "Preferences", 480,390 );\r
+    Desktop.addInternalFrame(frame, "Preferences", 480, 390);\r
 \r
     fullID.setSelected(showFullId);\r
+\r
     String string = Cache.getProperty("SHOW_FULLSCREEN");\r
     boolean value = false;\r
-    if(string!=null)\r
-      value =  Boolean.valueOf(string).booleanValue();\r
+\r
+    if (string != null)\r
+    {\r
+      value = Boolean.valueOf(string).booleanValue();\r
+    }\r
 \r
     fullScreen.setSelected(value);\r
     annotations.setSelected(showAnnotation);\r
@@ -134,43 +76,158 @@ public class Preferences extends GPreferences
     quality.setSelected(showQuality);\r
     identity.setSelected(showIdentity);\r
 \r
-    for(int i=0; i<12; i++)\r
-      colour.addItem( ColourSchemeProperty.getColourName(i) );\r
+    for (int i = 0; i < 12; i++)\r
+    {\r
+      colour.addItem(ColourSchemeProperty.getColourName(i));\r
+    }\r
 \r
     string = Cache.getProperty("DEFAULT_COLOUR");\r
-    if(string!=null)\r
-      colour.setSelectedItem( string );\r
+\r
+    if (string != null)\r
+    {\r
+      colour.setSelectedItem(string);\r
+    }\r
     else\r
-      colour.setSelectedIndex( 11 );\r
+    {\r
+      colour.setSelectedIndex(11);\r
+    }\r
 \r
-    String fonts[] = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();\r
-    for(int i=0; i<fonts.length; i++)\r
+    String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment()\r
+        .getAvailableFontFamilyNames();\r
+\r
+    for (int i = 0; i < fonts.length; i++)\r
+    {\r
       fontNameCB.addItem(fonts[i]);\r
+    }\r
+\r
+    for (int i = 1; i < 31; i++)\r
+    {\r
+      fontSizeCB.addItem(i + "");\r
+    }\r
+\r
+    fontStyleCB.addItem("plain");\r
+    fontStyleCB.addItem("bold");\r
+    fontStyleCB.addItem("italic");\r
+\r
+    fontNameCB.setSelectedItem(fontName);\r
+    fontSizeCB.setSelectedItem(fontSize);\r
+    fontStyleCB.setSelectedItem(fontStyle);\r
+\r
+    gapSymbolCB.addItem("-");\r
+    gapSymbolCB.addItem(".");\r
+\r
+    gapSymbolCB.setSelectedItem(gapSymbol + "");\r
+\r
+    startupCheckbox.setSelected(showStartupFile);\r
+    startupFileTextfield.setText(startupFile);\r
+  }\r
+\r
+  public static void initPreferences()\r
+  {\r
+    String string = Cache.getProperty("SHOW_FULL_ID");\r
 \r
-    for(int i=1; i<31; i++)\r
-      fontSizeCB.addItem(i+"");\r
+    if (string != null)\r
+    {\r
+      showFullId = Boolean.valueOf(string).booleanValue();\r
+    }\r
+\r
+    string = Cache.getProperty("SHOW_FULLSCREEN");\r
+\r
+    if (string != null)\r
+    {\r
+      showFullscreen = Boolean.valueOf(string).booleanValue();\r
+    }\r
+\r
+    string = Cache.getProperty("SHOW_ANNOTATIONS");\r
+\r
+    if (string != null)\r
+    {\r
+      showAnnotation = Boolean.valueOf(string).booleanValue();\r
+    }\r
+\r
+    string = Cache.getProperty("SHOW_CONSERVATION");\r
+\r
+    if (string != null)\r
+    {\r
+      showConservation = Boolean.valueOf(string).booleanValue();\r
+    }\r
+\r
+    string = Cache.getProperty("SHOW_QUALITY");\r
+\r
+    if (string != null)\r
+    {\r
+      showQuality = Boolean.valueOf(string).booleanValue();\r
+    }\r
+\r
+    string = Cache.getProperty("SHOW_IDENTITY");\r
+\r
+    if (string != null)\r
+    {\r
+      showIdentity = Boolean.valueOf(string).booleanValue();\r
+    }\r
+\r
+    string = Cache.getProperty("GAP_SYMBOL");\r
+\r
+    if (string != null)\r
+    {\r
+      gapSymbol = string.charAt(0);\r
+    }\r
+\r
+    string = Cache.getProperty("SHOW_FULL_ID");\r
+\r
+    if (string != null)\r
+    {\r
+      showFullId = Boolean.valueOf(string).booleanValue();\r
+    }\r
+\r
+    string = Cache.getProperty("FONT_NAME");\r
 \r
-   fontStyleCB.addItem("plain");\r
-   fontStyleCB.addItem("bold");\r
-   fontStyleCB.addItem("italic");\r
+    if (string != null)\r
+    {\r
+      fontName = string;\r
+    }\r
+\r
+    string = Cache.getProperty("FONT_STYLE");\r
+\r
+    if (string != null)\r
+    {\r
+      fontStyle = string;\r
+    }\r
+\r
+    string = Cache.getProperty("FONT_SIZE");\r
+\r
+    if (string != null)\r
+    {\r
+      fontSize = string;\r
+    }\r
+\r
+    string = Cache.getProperty("DEFAULT_COLOUR");\r
 \r
-   fontNameCB.setSelectedItem(fontName);\r
-   fontSizeCB.setSelectedItem(fontSize);\r
-   fontStyleCB.setSelectedItem(fontStyle);\r
+    if (string != null)\r
+    {\r
+      defaultColour = string;\r
+    }\r
 \r
-   gapSymbolCB.addItem("-");\r
-   gapSymbolCB.addItem(".");\r
+    string = Cache.getProperty("STARTUP_FILE");\r
 \r
-   gapSymbolCB.setSelectedItem( gapSymbol+"" );\r
+    if (string != null)\r
+    {\r
+      startupFile = string;\r
+    }\r
 \r
-   startupCheckbox.setSelected(showStartupFile);\r
-   startupFileTextfield.setText(startupFile);\r
+    string = Cache.getProperty("SHOW_STARTUP_FILE");\r
 \r
+    if (string != null)\r
+    {\r
+      showStartupFile = Boolean.valueOf(string).booleanValue();\r
+    }\r
+\r
+    preferencesLoaded = true;\r
   }\r
 \r
   public void ok_actionPerformed(ActionEvent e)\r
   {\r
-    showFullId =  fullID.isSelected() ;\r
+    showFullId = fullID.isSelected();\r
     showFullscreen = fullScreen.isSelected();\r
     showAnnotation = annotations.isSelected();\r
     showConservation = conservation.isSelected();\r
@@ -185,15 +242,16 @@ public class Preferences extends GPreferences
     showStartupFile = startupCheckbox.isSelected();\r
 \r
     Cache.setProperty("SHOW_FULL_ID", Boolean.toString(showFullId));\r
-    Cache.setProperty("SHOW_FULLSCREEN", Boolean.toString( showFullscreen ) );\r
+    Cache.setProperty("SHOW_FULLSCREEN", Boolean.toString(showFullscreen));\r
 \r
-    Cache.setProperty("SHOW_ANNOTATIONS", Boolean.toString( showAnnotation  ));\r
-    Cache.setProperty("SHOW_CONSERVATION", Boolean.toString( showConservation ));\r
-    Cache.setProperty("SHOW_QUALITY", Boolean.toString( showQuality ));\r
-    Cache.setProperty("SHOW_IDENTITY", Boolean.toString( showIdentity ));\r
+    Cache.setProperty("SHOW_ANNOTATIONS", Boolean.toString(showAnnotation));\r
+    Cache.setProperty("SHOW_CONSERVATION",\r
+                      Boolean.toString(showConservation));\r
+    Cache.setProperty("SHOW_QUALITY", Boolean.toString(showQuality));\r
+    Cache.setProperty("SHOW_IDENTITY", Boolean.toString(showIdentity));\r
 \r
     Cache.setProperty("DEFAULT_COLOUR", defaultColour);\r
-    Cache.setProperty("GAP_SYMBOL", gapSymbol+"");\r
+    Cache.setProperty("GAP_SYMBOL", gapSymbol + "");\r
 \r
     Cache.setProperty("FONT_NAME", fontName);\r
     Cache.setProperty("FONT_STYLE", fontStyle);\r
@@ -202,36 +260,52 @@ public class Preferences extends GPreferences
     Cache.setProperty("STARTUP_FILE", startupFile);\r
     Cache.setProperty("SHOW_STARTUP_FILE", Boolean.toString(showStartupFile));\r
 \r
-\r
-\r
-    try    {\r
+    try\r
+    {\r
       frame.setClosed(true);\r
-    }    catch (Exception ex)  {}\r
-\r
+    }\r
+    catch (Exception ex)\r
+    {\r
+    }\r
   }\r
 \r
   public void startupFileTextfield_mouseClicked()\r
   {\r
-    JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty("LAST_DIRECTORY"),\r
-        new String[]{"fa, fasta, fastq", "aln",  "pfam", "msf", "pir","blc","jar"},\r
-        new String[]{"Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"}\r
-       ,jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));\r
-   chooser.setFileView(new JalviewFileView());\r
-   chooser.setDialogTitle("Select startup file");\r
-   int value = chooser.showOpenDialog(this);\r
-   if(value == JalviewFileChooser.APPROVE_OPTION)\r
-   {\r
-     jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT", chooser.getSelectedFormat());\r
-     startupFileTextfield.setText( chooser.getSelectedFile().getAbsolutePath() );\r
-   }\r
+    JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.\r
+        getProperty(\r
+            "LAST_DIRECTORY"),\r
+        new String[]\r
+        {\r
+        "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",\r
+        "jar"\r
+    },\r
+        new String[]\r
+        {\r
+        "Fasta", "Clustal", "PFAM", "MSF", "PIR", "BLC", "Jalview"\r
+    }, jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));\r
+    chooser.setFileView(new JalviewFileView());\r
+    chooser.setDialogTitle("Select startup file");\r
+\r
+    int value = chooser.showOpenDialog(this);\r
+\r
+    if (value == JalviewFileChooser.APPROVE_OPTION)\r
+    {\r
+      jalview.bin.Cache.setProperty("DEFAULT_FILE_FORMAT",\r
+                                    chooser.getSelectedFormat());\r
+      startupFileTextfield.setText(chooser.getSelectedFile()\r
+                                   .getAbsolutePath());\r
+    }\r
   }\r
 \r
-\r
   public void cancel_actionPerformed(ActionEvent e)\r
   {\r
-    try{\r
+    try\r
+    {\r
       frame.setClosed(true);\r
-    }catch(Exception ex){}\r
+    }\r
+    catch (Exception ex)\r
+    {\r
+    }\r
   }\r
 \r
   public void annotations_actionPerformed(ActionEvent e)\r
@@ -240,5 +314,4 @@ public class Preferences extends GPreferences
     quality.setEnabled(annotations.isSelected());\r
     identity.setEnabled(annotations.isSelected());\r
   }\r
-\r
 }\r