Sort by added to preferences
[jalview.git] / src / jalview / gui / AlignViewport.java
index e8f34d8..f951792 100755 (executable)
@@ -58,7 +58,7 @@ public class AlignViewport
     ColourSchemeI globalColourScheme = null;\r
     boolean conservationColourSelected = false;\r
     boolean abovePIDThreshold = false;\r
-    SequenceGroup selectionGroup = new SequenceGroup();\r
+    SequenceGroup selectionGroup;\r
     int charHeight;\r
     int charWidth;\r
     int chunkWidth;\r
@@ -85,6 +85,8 @@ public class AlignViewport
     // JBPNote Prolly only need this in the applet version.\r
     private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(this);\r
 \r
+    boolean ignoreGapsInConsensusCalculation = false;\r
+\r
     /**\r
      * Creates a new AlignViewport object.\r
      *\r
@@ -106,52 +108,48 @@ public class AlignViewport
      */\r
     public void updateFromPreferences()\r
     {\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
+      showFullId = Cache.getDefault("SHOW_FULL_ID", true);\r
+      showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);\r
+      showConservation = Cache.getDefault("SHOW_CONSERVATION", true);\r
 \r
-        String fontName = Preferences.fontName;\r
-        String fontStyle = Preferences.fontStyle;\r
-        String fontSize = Cache.getProperty("FONT_SIZE");\r
+      showQuality = Cache.getDefault("SHOW_QUALITY", true);\r
+      showIdentity = Cache.getDefault("SHOW_IDENTITY", true);\r
 \r
-        if ((fontName != null) && (fontStyle != null) && (fontSize != null))\r
-        {\r
-            int style = 0;\r
+       String fontName = Cache.getDefault("FONT_NAME", "SansSerif");\r
+       String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "") ;\r
+       String fontSize = Cache.getDefault("FONT_SIZE", "10");\r
 \r
-            if (fontStyle.equals("bold"))\r
-            {\r
-                style = 1;\r
-            }\r
-            else if (fontStyle.equals("italic"))\r
-            {\r
-                style = 2;\r
-            }\r
+       int style = 0;\r
 \r
-            setFont(new Font(fontName, style, Integer.parseInt(fontSize)));\r
-        }\r
-        else\r
-        {\r
-            setFont(font);\r
-        }\r
+       if (fontStyle.equals("bold"))\r
+       {\r
+         style = 1;\r
+       }\r
+       else if (fontStyle.equals("italic"))\r
+       {\r
+         style = 2;\r
+       }\r
+\r
+       setFont(new Font(fontName, style, Integer.parseInt(fontSize)));\r
+\r
+\r
+       alignment.setGapCharacter( Cache.getDefault("GAP_SYMBOL", "-").charAt(0) );\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
 \r
-        if (Preferences.defaultColour != null)\r
+        if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)\r
         {\r
-            globalColourScheme = ColourSchemeProperty.getColour(alignment,\r
-                    Preferences.defaultColour);\r
+          globalColourScheme = ColourSchemeProperty.getColour(alignment,\r
+              jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));\r
 \r
             if (globalColourScheme instanceof UserColourScheme)\r
             {\r
                 globalColourScheme = UserDefinedColours.loadDefaultColours();\r
+                ((UserColourScheme)globalColourScheme).setThreshold(0, getIgnoreGapsConsensus());\r
             }\r
 \r
             if (globalColourScheme != null)\r
@@ -161,6 +159,8 @@ public class AlignViewport
         }\r
     }\r
 \r
+\r
+\r
     /**\r
      * DOCUMENT ME!\r
      *\r
@@ -307,18 +307,19 @@ public class AlignViewport
         {\r
             hash = (Hashtable) vconsensus.elementAt(i);\r
 \r
-            float value = Float.parseFloat(hash.get("maxCount").toString());\r
-            value /= Float.parseFloat(hash.get("size").toString());\r
-\r
-            value *= 100;\r
+            float value = 0;\r
+            if(ignoreGapsInConsensusCalculation)\r
+              value = ((Float)hash.get("pid_nogaps")).floatValue();\r
+            else\r
+              value = ((Float)hash.get("pid_gaps")).floatValue();\r
 \r
-            String maxRes = hash.get("maxResidue") + " ";\r
-            String mouseOver = hash.get("maxResidue") + " ";\r
+            String maxRes = hash.get("maxResidue").toString();\r
+            String mouseOver = hash.get("maxResidue")+" ";\r
 \r
-            if (maxRes.length() > 2)\r
+            if (maxRes.length() > 1)\r
             {\r
                 mouseOver = "[" + maxRes + "] ";\r
-                maxRes = "+ ";\r
+                maxRes = "+";\r
             }\r
 \r
             mouseOver += ((int) value + "%");\r
@@ -339,6 +340,9 @@ public class AlignViewport
         {\r
             consensus.annotations = annotations;\r
         }\r
+\r
+        if(globalColourScheme!=null)\r
+          globalColourScheme.setConsensus(vconsensus);\r
     }\r
 \r
     /**\r
@@ -531,10 +535,9 @@ public class AlignViewport
     {\r
         font = f;\r
 \r
-        javax.swing.JFrame temp = new javax.swing.JFrame();\r
-        temp.addNotify();\r
+        Container c = new Container();\r
 \r
-        java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font);\r
+        java.awt.FontMetrics fm = c.getFontMetrics(font);\r
         setCharHeight(fm.getHeight());\r
         setCharWidth(fm.charWidth('M'));\r
     }\r
@@ -999,7 +1002,7 @@ public class AlignViewport
     }\r
 \r
     /**\r
-     * DOCUMENT ME!\r
+     * Property change listener for changes in alignment\r
      *\r
      * @param listener DOCUMENT ME!\r
      */\r
@@ -1021,7 +1024,7 @@ public class AlignViewport
     }\r
 \r
     /**\r
-     * DOCUMENT ME!\r
+     * Property change listener for changes in alignment\r
      *\r
      * @param prop DOCUMENT ME!\r
      * @param oldvalue DOCUMENT ME!\r
@@ -1031,4 +1034,20 @@ public class AlignViewport
     {\r
         changeSupport.firePropertyChange(prop, oldvalue, newvalue);\r
     }\r
+\r
+    public void setIgnoreGapsConsensus(boolean b)\r
+    {\r
+      ignoreGapsInConsensusCalculation = b;\r
+      updateConsensus();\r
+      if(globalColourScheme!=null)\r
+      {\r
+        globalColourScheme.setThreshold(globalColourScheme.getThreshold(), ignoreGapsInConsensusCalculation);\r
+      }\r
+\r
+    }\r
+\r
+    public boolean getIgnoreGapsConsensus()\r
+    {\r
+     return ignoreGapsInConsensusCalculation;\r
+    }\r
 }\r