FeatureRenderer takes alignmentPanel
[jalview.git] / src / jalview / gui / FeatureRenderer.java
index 596203b..04324ac 100755 (executable)
@@ -38,6 +38,7 @@ import jalview.datamodel.*;
  */
 public class FeatureRenderer
 {
+  AlignmentPanel ap;
   AlignViewport av;
   Color resBoxColour;
   float transparency = 1.0f;
@@ -65,18 +66,20 @@ public class FeatureRenderer
    * @param av
    *          DOCUMENT ME!
    */
-  public FeatureRenderer(AlignViewport av)
+  public FeatureRenderer(AlignmentPanel ap)
   {
-    this.av = av;
+    this.ap = ap;
+    this.av = ap.av;
   }
 
+
   public void transferSettings(FeatureRenderer fr)
   {
-    renderOrder = fr.renderOrder;
-    featureGroups = fr.featureGroups;
-    featureColours = fr.featureColours;
-    transparency = fr.transparency;
-    featureOrder = fr.featureOrder;
+    this.renderOrder = fr.renderOrder;
+    this.featureGroups = fr.featureGroups;
+    this.featureColours = fr.featureColours;
+    this.transparency = fr.transparency;
+    this.featureOrder = fr.featureOrder;
   }
 
   BufferedImage offscreenImage;
@@ -268,7 +271,7 @@ public class FeatureRenderer
 
         if (featureGroups != null
             && sequenceFeatures[sfindex].featureGroup != null
-            && 
+            &&
             sequenceFeatures[sfindex].featureGroup.length()!=0
             && featureGroups.containsKey(sequenceFeatures[sfindex].featureGroup)
             &&
@@ -456,6 +459,21 @@ public class FeatureRenderer
       {
         if (!av.featuresDisplayed.containsKey(features[index].getType()))
         {
+          if(featureGroups.containsKey(features[index].getType()))
+          {
+            boolean visible = ( (Boolean) featureGroups.get(
+                features[index].featureGroup)).booleanValue();
+
+            if(!visible)
+            {
+              System.out.println(features[index].featureGroup
+                                 +" not visible");
+              index++;
+              continue;
+            }
+          }
+
+
           if (! (features[index].begin == 0 && features[index].end == 0))
           {
             // If beginning and end are 0, the feature is for the whole sequence
@@ -553,7 +571,7 @@ public class FeatureRenderer
   }
   public Color getColour(String featureType)
   {
-    if (featureColours.get(featureType) == null)
+    if (!featureColours.containsKey(featureType))
     {
       jalview.schemes.UserColourScheme ucs = new
           jalview.schemes.UserColourScheme();
@@ -569,19 +587,12 @@ public class FeatureRenderer
   static String lastFeatureGroupAdded;
   static String lastDescriptionAdded;
 
-  public boolean createNewFeatures(SequenceI[] sequences,
-                                   SequenceFeature[] features)
-  {
-    return amendFeatures(sequences, features, true, null);
-  }
-
   int featureIndex = 0;
   boolean amendFeatures(final SequenceI[] sequences,
                         final SequenceFeature[] features,
                         boolean newFeatures,
                         final AlignmentPanel ap)
   {
-    findAllFeatures();
 
     featureIndex = 0;
 
@@ -602,10 +613,12 @@ public class FeatureRenderer
     {
       public void mousePressed(MouseEvent evt)
       {
-        colour.setBackground(
-            JColorChooser.showDialog(Desktop.desktop,
-                                     "Select Feature Colour",
-                                     colour.getBackground()));
+        Color col = JColorChooser.showDialog(Desktop.desktop,
+                                             "Select Feature Colour",
+                                             colour.getBackground());
+        if (col != null)
+          colour.setBackground(col);
+
       }
     });
 
@@ -804,7 +817,11 @@ public class FeatureRenderer
         sf.type = lastFeatureAdded;
         sf.featureGroup = lastFeatureGroupAdded;
         sf.description = lastDescriptionAdded;
+
         setColour(sf.type, colour.getBackground());
+        av.featuresDisplayed.put(sf.type,
+                                 new Integer(colour.getBackground().getRGB()));
+
         try
         {
           sf.begin = ( (Integer) start.getValue()).intValue();
@@ -816,16 +833,16 @@ public class FeatureRenderer
         ffile.parseDescriptionHTML(sf, false);
       }
     }
-    else
+    else //NEW FEATURES ADDED
     {
       if (reply == JOptionPane.OK_OPTION
-          && name.getText() != null
-          && source.getText() != null)
+          && lastFeatureAdded.length()>0)
       {
         for (int i = 0; i < sequences.length; i++)
         {
           features[i].type = lastFeatureAdded;
-          features[i].featureGroup = lastFeatureGroupAdded;
+          if (lastFeatureGroupAdded!=null)
+            features[i].featureGroup = lastFeatureGroupAdded;
           features[i].description = lastDescriptionAdded;
           sequences[i].addSequenceFeature(features[i]);
           ffile.parseDescriptionHTML(features[i], false);
@@ -836,22 +853,22 @@ public class FeatureRenderer
           av.featuresDisplayed = new Hashtable();
         }
 
-        if (featureGroups == null)
+        if (lastFeatureGroupAdded != null)
         {
-          featureGroups = new Hashtable();
+          if (featureGroups == null)
+            featureGroups = new Hashtable();
+          featureGroups.put(lastFeatureGroupAdded, new Boolean(true));
         }
 
-
         Color col = colour.getBackground();
         setColour(lastFeatureAdded, colour.getBackground());
-
-        if(lastFeatureGroupAdded!=null)
-        {
-          featureGroups.put(lastFeatureGroupAdded, new Boolean(true));
-          av.featuresDisplayed.put(lastFeatureGroupAdded,
+        av.featuresDisplayed.put(lastFeatureAdded,
                                    new Integer(col.getRGB()));
-        }
-        findAllFeatures();
+
+        findAllFeatures(false);
+
+        ap.paintAlignment(true);
+
 
         return true;
       }
@@ -861,7 +878,7 @@ public class FeatureRenderer
       }
     }
 
-    findAllFeatures();
+    ap.paintAlignment(true);
 
     return true;
   }