Feature Groups added
authoramwaterhouse <Andrew Waterhouse>
Wed, 15 Feb 2006 15:18:21 +0000 (15:18 +0000)
committeramwaterhouse <Andrew Waterhouse>
Wed, 15 Feb 2006 15:18:21 +0000 (15:18 +0000)
src/jalview/appletgui/FeatureRenderer.java
src/jalview/appletgui/FeatureSettings.java

index 091a127..fae19e8 100755 (executable)
@@ -41,6 +41,10 @@ public class FeatureRenderer
     // to be added, in the correct order or rendering\r
     Vector featuresDisplayed;\r
 \r
+    // A higher level for grouping features of a\r
+    // paritcular type\r
+    Hashtable featureGroups = null;\r
+\r
     Color currentColour = null;\r
 \r
     boolean drawText = true;\r
@@ -113,6 +117,14 @@ public class FeatureRenderer
             if(sf==null)\r
               continue;\r
 \r
+            if(featureGroups!=null\r
+               && sf.getFeatureGroup()!=null\r
+               && featureGroups.containsKey(sf.getFeatureGroup())\r
+               && !((Boolean)featureGroups.get(sf.getFeatureGroup())).booleanValue())\r
+            {\r
+              continue;\r
+            }\r
+\r
 \r
             if (sf.getBegin() > seq.getEnd())\r
             {\r
@@ -211,6 +223,15 @@ public class FeatureRenderer
       featureColours.put(featureType, col);\r
     }\r
 \r
+    public void addNewFeature(String name, Color col)\r
+    {\r
+      setColour(name, col);\r
+      if (featuresDisplayed == null)\r
+        featuresDisplayed = new Vector();\r
+      featuresDisplayed.insertElementAt(name, 0);\r
+    }\r
+\r
+\r
  /*   public void setTransparency(float value)\r
     {\r
       transparency = value;\r
index 4d0f25e..30d57e0 100755 (executable)
@@ -31,6 +31,8 @@ public class FeatureSettings extends Panel implements ItemListener,
   final AlignmentPanel ap;\r
   final AlignViewport av;\r
   final Frame frame;\r
+  Panel groupPanel;\r
+  Panel featurePanel = new Panel();\r
 \r
   public FeatureSettings(AlignViewport av, final AlignmentPanel ap)\r
   {\r
@@ -40,9 +42,22 @@ public class FeatureSettings extends Panel implements ItemListener,
 \r
     setTableData();\r
 \r
+    this.setLayout(new BorderLayout());\r
+    ScrollPane sp = new ScrollPane();\r
+    sp.add(featurePanel);\r
+    add(sp, BorderLayout.CENTER);\r
+    if(groupPanel!=null)\r
+    {\r
+      sp = new ScrollPane();\r
+      sp.add(groupPanel);\r
+\r
+      add(sp, BorderLayout.NORTH);\r
+      sp.validate();\r
+      sp.setSize( 100, 55);\r
+    }\r
     frame = new Frame();\r
     frame.add(this);\r
-    int height = this.getComponentCount()*50;\r
+    int height = featurePanel.getComponentCount()*50 ;\r
     if (height>400)\r
       height = 400;\r
 \r
@@ -52,70 +67,92 @@ public class FeatureSettings extends Panel implements ItemListener,
 \r
   void setTableData()\r
   {\r
+    if(fr.featureGroups==null)\r
+      fr.featureGroups = new Hashtable();\r
+    else\r
+      fr.featureGroups.clear();\r
+\r
     Vector allFeatures = new Vector();\r
-    Vector features;\r
-    Enumeration e;\r
+    Enumeration tmpfeatures;\r
     SequenceFeature sf;\r
 \r
     for (int i = 0; i < av.alignment.getHeight(); i++)\r
     {\r
-      features = av.alignment.getSequenceAt(i).getSequenceFeatures();\r
-      if (features == null)\r
+      if (av.alignment.getSequenceAt(i).getSequenceFeatures() == null)\r
         continue;\r
 \r
-      e = features.elements();\r
-      while (e.hasMoreElements())\r
+      tmpfeatures = av.alignment.getSequenceAt(i).getSequenceFeatures().elements();\r
+      while (tmpfeatures.hasMoreElements())\r
       {\r
-        sf = (SequenceFeature) e.nextElement();\r
+        sf = (SequenceFeature) tmpfeatures.nextElement();\r
         if (!allFeatures.contains(sf.getType()))\r
         {\r
           allFeatures.addElement(sf.getType());\r
+          Color col = fr.getColour(sf.getType());\r
+          boolean displayed = true;\r
+          if (fr.featuresDisplayed != null)\r
+            displayed = fr.featuresDisplayed.contains(sf.getType());\r
+\r
+          Checkbox check = new Checkbox(sf.getType(), displayed);\r
+          check.addMouseListener(this);\r
+          check.addMouseMotionListener(this);\r
+          check.setBackground(col);\r
+          check.addItemListener(this);\r
+          featurePanel.add(check);\r
+        }\r
+        if(sf.getFeatureGroup()!=null\r
+           && !fr.featureGroups.containsKey(sf.getFeatureGroup()))\r
+        {\r
+          fr.featureGroups.put(sf.getFeatureGroup(), new Boolean(true));\r
+          if(groupPanel==null)\r
+            groupPanel = new Panel();\r
+\r
+          Checkbox check = new Checkbox(sf.getFeatureGroup(), true);\r
+          check.setFont(new Font("Serif", Font.BOLD, 12));\r
+          check.addItemListener(this);\r
+          groupPanel.add(check);\r
         }\r
       }\r
     }\r
 \r
-    int fSize = allFeatures.size();\r
-\r
-    String type;\r
-    this.setLayout(new GridLayout(fSize, 2, 10,5));\r
-\r
-    for (int i = 0; i < fSize; i++)\r
-    {\r
-      type = allFeatures.elementAt(i).toString();\r
-      Color col = fr.getColour(type);\r
-      boolean displayed = true;\r
-      if(fr.featuresDisplayed!=null)\r
-        displayed = fr.featuresDisplayed.contains(type);\r
-\r
-      Checkbox check = new Checkbox(type, displayed);\r
-      check.addMouseListener(this);\r
-      check.addMouseMotionListener(this);\r
-      check.setBackground(col);\r
-      check.addItemListener(this);\r
-      add(check);\r
-    }\r
-    validate();\r
+    featurePanel.setLayout(new GridLayout(allFeatures.size(), 2, 10,5));\r
+    featurePanel.validate();\r
   }\r
 \r
   public void itemStateChanged(ItemEvent evt)\r
   {\r
-    Component [] comps = this.getComponents();\r
-    int cSize = comps.length;\r
-\r
-    Object [][] data = new Object[cSize][3];\r
-\r
-    for(int i=0; i<cSize; i++)\r
+    if(evt!=null)\r
     {\r
-      Checkbox check = (Checkbox)comps[i];\r
-      data[i][0] = check.getLabel();\r
-      data[i][1] = fr.getColour(check.getLabel());\r
-      data[i][2] = new Boolean(check.getState());\r
+      //Is the source a top level featureGroup?\r
+      Checkbox source = (Checkbox) evt.getSource();\r
+      if (fr.featureGroups.containsKey(source.getLabel()))\r
+      {\r
+        fr.featureGroups.put(source.getLabel(), new Boolean(source.getState()));\r
+        ap.seqPanel.seqCanvas.repaint();\r
+        if (ap.overviewPanel != null)\r
+          ap.overviewPanel.updateOverviewImage();\r
+\r
+        return;\r
+      }\r
     }\r
 \r
-    fr.setFeaturePriority(data);\r
-    ap.seqPanel.seqCanvas.repaint();\r
-    if(ap.overviewPanel!=null)\r
-      ap.overviewPanel.updateOverviewImage();\r
+      Component[] comps = featurePanel.getComponents();\r
+      int cSize = comps.length;\r
+\r
+      Object[][] data = new Object[cSize][3];\r
+\r
+      for (int i = 0; i < cSize; i++)\r
+      {\r
+        Checkbox check = (Checkbox) comps[i];\r
+        data[i][0] = check.getLabel();\r
+        data[i][1] = fr.getColour(check.getLabel());\r
+        data[i][2] = new Boolean(check.getState());\r
+      }\r
+\r
+      fr.setFeaturePriority(data);\r
+      ap.seqPanel.seqCanvas.repaint();\r
+      if (ap.overviewPanel != null)\r
+        ap.overviewPanel.updateOverviewImage();\r
   }\r
 \r
   Checkbox selectedCheck;\r
@@ -138,17 +175,18 @@ public class FeatureSettings extends Panel implements ItemListener,
 \r
     int height = evt.getY()+evt.getComponent().getLocation().y;\r
 \r
+\r
     if(height > this.getSize().height)\r
      {\r
-       comp = this.getComponent(this.getComponentCount()-1);\r
+       comp = featurePanel.getComponent(featurePanel.getComponentCount()-1);\r
      }\r
      else if(height < 0)\r
      {\r
-       comp = this.getComponent(0);\r
+       comp = featurePanel.getComponent(0);\r
      }\r
      else\r
      {\r
-       comp = this.getComponentAt(evt.getX(),\r
+       comp = featurePanel.getComponentAt(evt.getX(),\r
                                   evt.getY() +\r
                                   evt.getComponent().getLocation().y);\r
      }\r
@@ -159,16 +197,16 @@ public class FeatureSettings extends Panel implements ItemListener,
     if (selectedCheck != null && target != null && selectedCheck != target)\r
     {\r
       int targetIndex = -1;\r
-      for(int i=0; i<this.getComponentCount(); i++)\r
+      for(int i=0; i<featurePanel.getComponentCount(); i++)\r
       {\r
-          if(target==this.getComponent(i))\r
+          if(target==featurePanel.getComponent(i))\r
           { targetIndex = i; break; }\r
       }\r
 \r
 \r
-      this.remove(selectedCheck);\r
-      this.add(selectedCheck, targetIndex);\r
-      validate();\r
+      featurePanel.remove(selectedCheck);\r
+      featurePanel.add(selectedCheck, targetIndex);\r
+      featurePanel.validate();\r
       itemStateChanged(null);\r
     }\r
   }\r