remove System.out
[jalview.git] / src / jalview / gui / FeatureRenderer.java
index 40a924a..0d701ac 100755 (executable)
@@ -38,6 +38,7 @@ import jalview.datamodel.*;
  */
 public class FeatureRenderer
 {
+  AlignmentPanel ap;
   AlignViewport av;
   Color resBoxColour;
   float transparency = 1.0f;
@@ -48,7 +49,7 @@ public class FeatureRenderer
 
   // A higher level for grouping features of a
   // particular type
-  Hashtable featureGroups = null;
+  Hashtable featureGroups = new Hashtable();
 
   // This is actually an Integer held in the hashtable,
   // Retrieved using the key feature type
@@ -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;
@@ -116,7 +119,7 @@ public class FeatureRenderer
       }
     }
 
-    if (sequenceFeatures == null)
+    if (sequenceFeatures == null || sfSize==0)
     {
       return initialCol;
     }
@@ -193,9 +196,10 @@ public class FeatureRenderer
   SequenceFeature[] sequenceFeatures;
   int sfSize, sfindex, spos, epos;
 
-  public void drawSequence(Graphics g, SequenceI seq,
+  synchronized public void drawSequence(Graphics g, SequenceI seq,
                            int start, int end, int y1)
   {
+
     if (seq.getDatasetSequence().getSequenceFeatures() == null
         || seq.getDatasetSequence().getSequenceFeatures().length == 0)
     {
@@ -218,7 +222,6 @@ public class FeatureRenderer
       }
 
       sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures();
-      sfSize = sequenceFeatures.length;
     }
 
     if (lastSeq == null || seq != lastSeq
@@ -226,7 +229,6 @@ public class FeatureRenderer
     {
       lastSeq = seq;
       sequenceFeatures = seq.getDatasetSequence().getSequenceFeatures();
-      sfSize = sequenceFeatures.length;
     }
 
     if (transparency != 1 && g != null)
@@ -243,6 +245,7 @@ public class FeatureRenderer
       epos = lastSeq.findPosition(end);
     }
 
+    sfSize = sequenceFeatures.length;
     String type;
     for (int renderIndex = 0; renderIndex < renderOrder.length; renderIndex++)
     {
@@ -257,10 +260,6 @@ public class FeatureRenderer
       // current feature to render
       for (sfindex = 0; sfindex < sfSize; sfindex++)
       {
-        if (sequenceFeatures.length <= sfindex)
-        {
-          continue;
-        }
         if (!sequenceFeatures[sfindex].type.equals(type))
         {
           continue;
@@ -269,7 +268,8 @@ public class FeatureRenderer
         if (featureGroups != null
             && sequenceFeatures[sfindex].featureGroup != null
             &&
-            featureGroups.containsKey(sequenceFeatures[sfindex].featureGroup)
+            sequenceFeatures[sfindex].featureGroup.length()!=0
+            && featureGroups.containsKey(sequenceFeatures[sfindex].featureGroup)
             &&
             ! ( (Boolean) featureGroups.get(sequenceFeatures[sfindex].
                                             featureGroup)).
@@ -455,6 +455,20 @@ 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)
+            {
+              index++;
+              continue;
+            }
+          }
+
+
           if (! (features[index].begin == 0 && features[index].end == 0))
           {
             // If beginning and end are 0, the feature is for the whole sequence
@@ -552,7 +566,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();
@@ -568,19 +582,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;
 
@@ -601,10 +608,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);
+
       }
     });
 
@@ -732,12 +741,21 @@ public class FeatureRenderer
       }
     }
 
-    name.setText(lastFeatureAdded);
-    source.setText(lastFeatureGroupAdded);
+    if(newFeatures)
+    {
+      name.setText(lastFeatureAdded);
+      source.setText(lastFeatureGroupAdded);
+    }
+    else
+    {
+      name.setText(features[0].getType());
+      source.setText(features[0].getFeatureGroup());
+    }
+
     start.setValue(new Integer(features[0].getBegin()));
     end.setValue(new Integer(features[0].getEnd()));
-    colour.setBackground( getColour(lastFeatureAdded) );
     description.setText(features[0].getDescription());
+    colour.setBackground(getColour(name.getText()));
 
 
     Object[] options;
@@ -768,16 +786,17 @@ public class FeatureRenderer
 
     jalview.io.FeaturesFile ffile = new jalview.io.FeaturesFile();
 
-    if (reply == JOptionPane.OK_OPTION
-        && name.getText() != null
-        && source.getText() != null)
+    if (reply == JOptionPane.OK_OPTION && name.getText().length()>0)
     {
       // This ensures that the last sequence
       // is refreshed and new features are rendered
       lastSeq = null;
-      lastFeatureAdded = name.getText();
-      lastFeatureGroupAdded = source.getText();
+      lastFeatureAdded = name.getText().trim();
+      lastFeatureGroupAdded = source.getText().trim();
       lastDescriptionAdded = description.getText().replaceAll("\n", " ");
+
+      if(lastFeatureGroupAdded.length()<1)
+        lastFeatureGroupAdded = null;
     }
 
     if (!newFeatures)
@@ -793,7 +812,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();
@@ -805,16 +828,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);
@@ -825,20 +848,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));
         }
 
-        featureGroups.put(lastFeatureGroupAdded, new Boolean(true));
-
         Color col = colour.getBackground();
         setColour(lastFeatureAdded, colour.getBackground());
+        av.featuresDisplayed.put(lastFeatureAdded,
+                                   new Integer(col.getRGB()));
+
+        findAllFeatures(false);
 
-        av.featuresDisplayed.put(lastFeatureGroupAdded,
-                                 new Integer(col.getRGB()));
+        ap.paintAlignment(true);
 
-        findAllFeatures();
 
         return true;
       }
@@ -848,7 +873,7 @@ public class FeatureRenderer
       }
     }
 
-    findAllFeatures();
+    ap.paintAlignment(true);
 
     return true;
   }