preferences held statically
authoramwaterhouse <Andrew Waterhouse>
Fri, 29 Apr 2005 10:42:48 +0000 (10:42 +0000)
committeramwaterhouse <Andrew Waterhouse>
Fri, 29 Apr 2005 10:42:48 +0000 (10:42 +0000)
src/jalview/gui/AlignViewport.java
src/jalview/gui/Preferences.java

index a135620..98fd229 100755 (executable)
@@ -71,49 +71,36 @@ public class AlignViewport
 \r
   public void updateFromPreferences()\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_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("SHOW_FULL_ID");\r
-      if(string!=null)\r
-        showFullId = Boolean.valueOf(string).booleanValue();\r
-\r
-  String fontName = Cache.getProperty("FONT_NAME");\r
-  String fontStyle= Cache.getProperty("FONT_STYLE");\r
-  String fontSize = Cache.getProperty("FONT_SIZE");\r
-  if(fontName!=null && fontStyle!=null && fontSize!=null)\r
-      setFont( new Font(fontName,Integer.parseInt(fontStyle),Integer.parseInt(fontSize)) );\r
-  else\r
-      setFont( font );\r
-\r
-    string = Cache.getProperty("GAP_SYMBOL");\r
-    if(string!=null)\r
-      alignment.setGapCharacter( string.charAt(0) );\r
+    showFullId = Preferences.showFullId;\r
+    showAnnotation = Preferences.showAnnotation;\r
+    showConservation = Preferences.showConservation;\r
+    showQuality = Preferences.showQuality;\r
+    showIdentity = Preferences.showIdentity;\r
+    showFullId = Preferences.showFullId;\r
+    String fontName = Preferences.fontName;\r
+    String fontStyle = Preferences.fontStyle;\r
+    String fontSize = Cache.getProperty("FONT_SIZE");\r
+    if (fontName != null && fontStyle != null && fontSize != null)\r
+    {\r
+      int style = 0;\r
+      if(fontStyle.equals("bold"))\r
+        style = 1;\r
+      else if(fontStyle.equals("italic"))\r
+        style = 2;\r
+      setFont(new Font(fontName, style, Integer.parseInt(fontSize)));\r
+    }\r
+    else\r
+      setFont(font);\r
 \r
+    alignment.setGapCharacter(Preferences.gapSymbol);\r
 \r
     // We must set conservation and consensus before setting colour,\r
     // as Blosum and Clustal require this to be done\r
     updateConservation();\r
     updateConsensus();\r
-    string = Cache.getProperty("DEFAULT_COLOUR");\r
-    if(string!=null)\r
+    if(Preferences.defaultColour!=null)\r
     {\r
-      globalColourScheme = ColourSchemeProperty.getColour(alignment, string);\r
+      globalColourScheme = ColourSchemeProperty.getColour(alignment, Preferences.defaultColour);\r
       if(globalColourScheme!=null)\r
         globalColourScheme.setConsensus( vconsensus );\r
    }\r
index 6c07d23..264ef03 100755 (executable)
@@ -10,32 +10,83 @@ import java.awt.*;
 \r
 public class Preferences extends GPreferences\r
 {\r
-  AlignViewport av;\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;\r
+  public static String fontSize;\r
+  public static String fontStyle;\r
+  public static char gapSymbol='-';\r
+  public static String defaultColour=null;\r
+\r
   JInternalFrame frame;\r
-  public Preferences(AlignViewport av)\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
+\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("SHOW_FULL_ID");\r
+    if(string!=null)\r
+      showFullId = Boolean.valueOf(string).booleanValue();\r
+\r
+  fontName = Cache.getProperty("FONT_NAME");\r
+  fontStyle = Cache.getProperty("FONT_STYLE");\r
+  fontSize = Cache.getProperty("FONT_SIZE");\r
+\r
+      preferencesLoaded = true;\r
+  }\r
+\r
+  public Preferences()\r
   {\r
-    this.av = av;\r
+    if(!preferencesLoaded)\r
+      initPreferences();\r
+\r
     frame = new JInternalFrame();\r
     frame.setContentPane(this);\r
     Desktop.addInternalFrame(frame, "Preferences", 480,350 );\r
 \r
-\r
-    fullID.setSelected(av.getShowFullId());\r
+    fullID.setSelected(showFullId);\r
     String string = Cache.getProperty("SHOW_FULLSCREEN");\r
     boolean value = false;\r
     if(string!=null)\r
       value =  Boolean.valueOf(string).booleanValue();\r
 \r
     fullScreen.setSelected(value);\r
-    annotations.setSelected(av.getShowAnnotation());\r
+    annotations.setSelected(showAnnotation);\r
 \r
-    conservation.setEnabled(av.getShowAnnotation());\r
-    quality.setEnabled(av.getShowAnnotation());\r
-    identity.setEnabled(av.getShowAnnotation());\r
+    conservation.setEnabled(showAnnotation);\r
+    quality.setEnabled(showAnnotation);\r
+    identity.setEnabled(showAnnotation);\r
 \r
-    conservation.setSelected(av.showConservation);\r
-    quality.setSelected(av.showQuality);\r
-    identity.setSelected(av.showIdentity);\r
+    conservation.setSelected(showConservation);\r
+    quality.setSelected(showQuality);\r
+    identity.setSelected(showIdentity);\r
 \r
     for(int i=0; i<12; i++)\r
       colour.addItem( ColourSchemeProperty.getColourName(i) );\r
@@ -48,52 +99,59 @@ public class Preferences extends GPreferences
 \r
     String fonts[] = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();\r
     for(int i=0; i<fonts.length; i++)\r
-      fontName.addItem(fonts[i]);\r
+      fontNameCB.addItem(fonts[i]);\r
 \r
     for(int i=1; i<31; i++)\r
-      fontSize.addItem(i+"");\r
+      fontSizeCB.addItem(i+"");\r
 \r
-   fontStyle.addItem("plain");\r
-   fontStyle.addItem("bold");\r
-   fontStyle.addItem("italic");\r
+   fontStyleCB.addItem("plain");\r
+   fontStyleCB.addItem("bold");\r
+   fontStyleCB.addItem("italic");\r
 \r
-   Font oldFont = av.getFont();\r
-   fontName.setSelectedItem(oldFont.getName());\r
-   fontSize.setSelectedItem(oldFont.getSize() + "");\r
-   fontStyle.setSelectedIndex(oldFont.getStyle());\r
+   fontNameCB.setSelectedItem(fontName);\r
+   fontSizeCB.setSelectedItem(fontSize);\r
+   fontStyleCB.setSelectedItem(fontStyle);\r
 \r
-   gapSymbol.addItem("-");\r
-   gapSymbol.addItem(".");\r
+   gapSymbolCB.addItem("-");\r
+   gapSymbolCB.addItem(".");\r
 \r
-   gapSymbol.setSelectedItem( av.getGapCharacter()+"" );\r
+   gapSymbolCB.setSelectedItem( gapSymbol+"" );\r
 \r
   }\r
 \r
   public void ok_actionPerformed(ActionEvent e)\r
   {\r
-    Cache.setProperty("SHOW_FULL_ID", Boolean.toString( fullID.isSelected() ));\r
-    Cache.setProperty("SHOW_FULLSCREEN", Boolean.toString( fullScreen.isSelected() ));\r
-\r
-    Cache.setProperty("SHOW_ANNOTATIONS", Boolean.toString( annotations.isSelected() ));\r
-    Cache.setProperty("SHOW_CONSERVATION", Boolean.toString( conservation.isSelected() ));\r
-    Cache.setProperty("SHOW_QUALITY", Boolean.toString( quality.isSelected() ));\r
-    Cache.setProperty("SHOW_IDENTITY", Boolean.toString( identity.isSelected() ));\r
-\r
-    Cache.setProperty("DEFAULT_COLOUR", colour.getSelectedItem().toString() );\r
-    Cache.setProperty("GAP_SYMBOL", gapSymbol.getSelectedItem().toString());\r
-\r
-    Cache.setProperty("FONT_NAME", fontName.getSelectedItem().toString());\r
-    Cache.setProperty("FONT_STYLE", fontStyle.getSelectedIndex()+"");\r
-    Cache.setProperty("FONT_SIZE", fontSize.getSelectedItem().toString());\r
+    showFullId =  fullID.isSelected() ;\r
+    showFullscreen = fullScreen.isSelected();\r
+    showAnnotation = annotations.isSelected();\r
+    showConservation = conservation.isSelected();\r
+    showQuality = quality.isSelected();\r
+    showIdentity = identity.isSelected();\r
+    defaultColour = colour.getSelectedItem().toString();\r
+    gapSymbol = gapSymbolCB.getSelectedItem().toString().charAt(0);\r
+    fontName = fontNameCB.getSelectedItem().toString();\r
+    fontSize = fontSizeCB.getSelectedItem().toString();\r
+    fontStyle = fontStyleCB.getSelectedItem().toString();\r
+\r
+    Cache.setProperty("SHOW_FULL_ID", Boolean.toString(showFullId));\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
+\r
+    Cache.setProperty("DEFAULT_COLOUR", defaultColour);\r
+    Cache.setProperty("GAP_SYMBOL", gapSymbol+"");\r
+\r
+    Cache.setProperty("FONT_NAME", fontName);\r
+    Cache.setProperty("FONT_STYLE", fontStyle);\r
+    Cache.setProperty("FONT_SIZE", fontSize);\r
 \r
     try    {\r
       frame.setClosed(true);\r
     }    catch (Exception ex)  {}\r
 \r
-    av.updateFromPreferences();\r
-\r
-    repaint();\r
-\r
   }\r
 \r
   public void cancel_actionPerformed(ActionEvent e)\r