JAL-1620 version bump and release notes
[jalview.git] / src / jalview / appletgui / FeatureRenderer.java
old mode 100755 (executable)
new mode 100644 (file)
index d2712b8..6024872
@@ -1,19 +1,22 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
- * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1)
+ * Copyright (C) 2014 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
  * Jalview is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License 
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- * 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
  * Jalview is distributed in the hope that it will be useful, but 
  * WITHOUT ANY WARRANTY; without even the implied warranty 
  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
  * PURPOSE.  See the GNU General Public License for more details.
  * 
- * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
  */
 package jalview.appletgui;
 
@@ -23,10 +26,10 @@ import java.awt.*;
 
 import java.awt.event.*;
 
-import jalview.appletgui.FeatureSettings.MyCheckbox;
 import jalview.datamodel.*;
 import jalview.schemes.AnnotationColourGradient;
 import jalview.schemes.GraduatedColor;
+import jalview.util.MessageManager;
 
 /**
  * DOCUMENT ME!
@@ -84,6 +87,25 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
     featureGroups = fr.featureGroups;
     featureColours = fr.featureColours;
     transparency = fr.transparency;
+    if (av != null && fr.av != null && fr.av != av)
+    {
+      if (fr.av.featuresDisplayed != null)
+      {
+        if (av.featuresDisplayed == null)
+        {
+          av.featuresDisplayed = new Hashtable();
+        }
+        else
+        {
+          av.featuresDisplayed.clear();
+        }
+        Enumeration en = fr.av.featuresDisplayed.keys();
+        while (en.hasMoreElements())
+        {
+          av.featuresDisplayed.put(en.nextElement(), Boolean.TRUE);
+        }
+      }
+    }
   }
 
   static String lastFeatureAdded;
@@ -129,7 +151,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
       }
       else
       {
-        throw new Error("Invalid color for MyCheckBox");
+        throw new Error(MessageManager.getString("error.invalid_colour_for_mycheckbox"));
       }
       if (col != null)
       {
@@ -176,7 +198,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
           g.setColor(Color.black);
           Font f = new Font("Verdana", Font.PLAIN, 10);
           g.setFont(f);
-          g.drawString("Label", 0, 0);
+          g.drawString(MessageManager.getString("label.label"), 0, 0);
         }
         else
         {
@@ -331,8 +353,8 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
       }
     }
 
-    String title = newFeatures ? "Create New Sequence Feature(s)"
-            : "Amend/Delete Features for " + sequences[0].getName();
+    String title = newFeatures ? MessageManager.getString("label.create_new_sequence_features")
+            : MessageManager.formatMessage("label.amend_delete_features", new String[]{sequences[0].getName()});
 
     final JVDialog dialog = new JVDialog(ap.alignFrame, title, true, 385,
             240);
@@ -346,7 +368,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
     }
     else
     {
-      dialog.ok.setLabel("Amend");
+      dialog.ok.setLabel(MessageManager.getString("label.amend"));
       dialog.buttonPanel.add(deleteButton, 1);
       deleteButton.addActionListener(new ActionListener()
       {
@@ -661,16 +683,16 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
         else if (sequenceFeatures[sfindex].type.equals("disulfide bond"))
         {
 
-          renderFeature(g, seq, seq
-                  .findIndex(sequenceFeatures[sfindex].begin) - 1, seq
-                  .findIndex(sequenceFeatures[sfindex].begin) - 1,
+          renderFeature(g, seq,
+                  seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
+                  seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
                   getColour(sequenceFeatures[sfindex])
                   // new Color(((Integer) av.featuresDisplayed
                   // .get(sequenceFeatures[sfindex].type)).intValue())
                   , start, end, y1);
-          renderFeature(g, seq, seq
-                  .findIndex(sequenceFeatures[sfindex].end) - 1, seq
-                  .findIndex(sequenceFeatures[sfindex].end) - 1,
+          renderFeature(g, seq,
+                  seq.findIndex(sequenceFeatures[sfindex].end) - 1,
+                  seq.findIndex(sequenceFeatures[sfindex].end) - 1,
                   getColour(sequenceFeatures[sfindex])
                   // new Color(((Integer) av.featuresDisplayed
                   // .get(sequenceFeatures[sfindex].type)).intValue())
@@ -681,9 +703,9 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
         {
           if (showFeature(sequenceFeatures[sfindex]))
           {
-            renderFeature(g, seq, seq
-                    .findIndex(sequenceFeatures[sfindex].begin) - 1, seq
-                    .findIndex(sequenceFeatures[sfindex].end) - 1,
+            renderFeature(g, seq,
+                    seq.findIndex(sequenceFeatures[sfindex].begin) - 1,
+                    seq.findIndex(sequenceFeatures[sfindex].end) - 1,
                     getColour(sequenceFeatures[sfindex]), start, end, y1);
           }
         }
@@ -747,6 +769,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
   }
 
   Hashtable minmax = null;
+
   /**
    * Called when alignment in associated view has new/modified features to
    * discover and display.
@@ -757,6 +780,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
     lastSeq = null;
     findAllFeatures();
   }
+
   /**
    * find all features on the alignment
    */
@@ -767,10 +791,10 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
     av.featuresDisplayed = new Hashtable();
     Vector allfeatures = new Vector();
     minmax = new Hashtable();
-
-    for (int i = 0; i < av.alignment.getHeight(); i++)
+    AlignmentI alignment = av.getAlignment();
+    for (int i = 0; i < alignment.getHeight(); i++)
     {
-      SequenceFeature[] features = av.alignment.getSequenceAt(i)
+      SequenceFeature[] features = alignment.getSequenceAt(i)
               .getSequenceFeatures();
 
       if (features == null)
@@ -790,8 +814,8 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
         {
           if (getColour(features[index].getType()) == null)
           {
-            featureColours.put(features[index].getType(), ucs
-                    .createColourFromName(features[index].getType()));
+            featureColours.put(features[index].getType(),
+                    ucs.createColourFromName(features[index].getType()));
           }
 
           av.featuresDisplayed.put(features[index].getType(), new Integer(
@@ -877,8 +901,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
         return ((GraduatedColor) fc).getMaxColor();
       }
     }
-    throw new Error("Implementation Error: Unrecognised render object "
-            + fc.getClass() + " for features of type " + featureType);
+    throw new Error(MessageManager.formatMessage("error.implementation_error_unrecognised_render_object_for_features_type", new String[]{fc.getClass().getCanonicalName(),featureType}));
   }
 
   /**
@@ -1045,9 +1068,9 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
       for (int i = 0; i < toset.length; i++)
       {
         Object st = featureGroups.get(toset[i]);
+        featureGroups.put(toset[i], new Boolean(visible));
         if (st != null)
         {
-          featureGroups.put(toset[i], new Boolean(visible));
           rdrw = rdrw || (visible != ((Boolean) st).booleanValue());
         }
       }
@@ -1071,6 +1094,8 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
     }
   }
 
+  ArrayList<String> hiddenGroups = new ArrayList<String>();
+
   /**
    * analyse alignment for groups and hash tables (used to be embedded in
    * FeatureSettings.setTableData)
@@ -1084,29 +1109,34 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
     {
       featureGroups = new Hashtable();
     }
-    Vector allFeatures = new Vector();
-    Vector allGroups = new Vector();
+    hiddenGroups = new ArrayList<String>();
+    hiddenGroups.addAll(featureGroups.keySet());
+    ArrayList allFeatures = new ArrayList();
+    ArrayList allGroups = new ArrayList();
     SequenceFeature[] tmpfeatures;
     String group;
-    for (int i = 0; i < av.alignment.getHeight(); i++)
+    AlignmentI alignment = av.getAlignment();
+    for (int i = 0; i < alignment.getHeight(); i++)
     {
-      if (av.alignment.getSequenceAt(i).getSequenceFeatures() == null)
+      if (alignment.getSequenceAt(i).getSequenceFeatures() == null)
       {
         continue;
       }
 
       alignmentHasFeatures = true;
 
-      tmpfeatures = av.alignment.getSequenceAt(i).getSequenceFeatures();
+      tmpfeatures = alignment.getSequenceAt(i).getSequenceFeatures();
       int index = 0;
       while (index < tmpfeatures.length)
       {
         if (tmpfeatures[index].getFeatureGroup() != null)
         {
           group = tmpfeatures[index].featureGroup;
+          // Remove group from the hiddenGroup list
+          hiddenGroups.remove(group);
           if (!allGroups.contains(group))
           {
-            allGroups.addElement(group);
+            allGroups.add(group);
 
             boolean visible = true;
             if (featureGroups.containsKey(group))
@@ -1122,7 +1152,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
 
         if (!allFeatures.contains(tmpfeatures[index].getType()))
         {
-          allFeatures.addElement(tmpfeatures[index].getType());
+          allFeatures.add(tmpfeatures[index].getType());
         }
         index++;
       }
@@ -1151,16 +1181,17 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer
     Vector allFeatures = new Vector();
     SequenceFeature[] tmpfeatures;
     String group;
-    for (int i = 0; i < av.alignment.getHeight(); i++)
+    AlignmentI alignment = av.getAlignment();
+    for (int i = 0; i < alignment.getHeight(); i++)
     {
-      if (av.alignment.getSequenceAt(i).getSequenceFeatures() == null)
+      if (alignment.getSequenceAt(i).getSequenceFeatures() == null)
       {
         continue;
       }
 
       alignmentHasFeatures = true;
 
-      tmpfeatures = av.alignment.getSequenceAt(i).getSequenceFeatures();
+      tmpfeatures = alignment.getSequenceAt(i).getSequenceFeatures();
       int index = 0;
       while (index < tmpfeatures.length)
       {