Commented out for compilation
[jalview.git] / src / jalview / appletgui / FeatureRenderer.java
index 0b504be..954a95e 100755 (executable)
@@ -1,6 +1,7 @@
+\r
 /*\r
  * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
  *\r
  * This program is free software; you can redistribute it and/or\r
  * modify it under the terms of the GNU General Public License\r
@@ -34,11 +35,17 @@ public class FeatureRenderer
 {\r
     AlignViewport av;\r
 \r
+    Hashtable featureColours = new Hashtable();\r
 \r
     // A higher level for grouping features of a\r
     // particular type\r
     Hashtable featureGroups = null;\r
 \r
+    // Holds web links for feature groups and feature types\r
+    // in the form label|link\r
+    Hashtable featureLinks = null;\r
+\r
+\r
     // This is actually an Integer held in the hashtable,\r
     // Retrieved using the key feature type\r
     Object currentColour;\r
@@ -48,6 +55,10 @@ public class FeatureRenderer
     FontMetrics fm;\r
     int charOffset;\r
 \r
+    float transparency = 1f;\r
+\r
+    TransparencySetter transparencySetter = null;\r
+\r
     /**\r
      * Creates a new FeatureRenderer object.\r
      *\r
@@ -56,12 +67,24 @@ public class FeatureRenderer
     public FeatureRenderer(AlignViewport av)\r
     {\r
         this.av = av;\r
-        initColours();\r
+\r
+        if(!System.getProperty("java.version").startsWith("1.1"))\r
+             transparencySetter = new TransparencySetter();\r
+    }\r
+\r
+\r
+    public void transferSettings(FeatureRenderer fr)\r
+    {\r
+      renderOrder = fr.renderOrder;\r
+      featureGroups = fr.featureGroups;\r
+      featureColours = fr.featureColours;\r
+      transparency =  fr.transparency;\r
     }\r
 \r
 \r
     public Color findFeatureColour(Color initialCol, SequenceI seq, int i)\r
     {\r
+      overview = true;\r
       if(!av.showSequenceFeatures)\r
         return initialCol;\r
 \r
@@ -77,7 +100,7 @@ public class FeatureRenderer
 \r
       currentColour = null;\r
 \r
-      drawSequence(null, lastSequence, lastSequence.findPosition(i), -1,-1, -1, -1);\r
+      drawSequence(null, lastSequence, lastSequence.findPosition(i), -1,-1);\r
 \r
       if(currentColour==null)\r
         return initialCol;\r
@@ -114,7 +137,7 @@ public class FeatureRenderer
 \r
       currentColour = null;\r
 \r
-      drawSequence(null, lastSequence, lastSequence.findPosition(column), -1,-1, -1, -1);\r
+      drawSequence(null, lastSequence, lastSequence.findPosition(column), -1,-1);\r
 \r
       if(currentColour==null)\r
         return initialCol;\r
@@ -144,12 +167,16 @@ public class FeatureRenderer
     int sfSize, sfindex, spos, epos;\r
 \r
     public void drawSequence(Graphics g, SequenceI seq,\r
-                             int start, int end, int y1, int width, int height)\r
+                             int start, int end, int y1)\r
     {\r
       if (   seq.getSequenceFeatures() == null\r
           || seq.getSequenceFeatures().length==0)\r
         return;\r
 \r
+      if(transparencySetter!=null && g!=null)\r
+      {\r
+        transparencySetter.setTransparency(g, transparency);\r
+      }\r
 \r
       if (av.featuresDisplayed == null || renderOrder==null)\r
        {\r
@@ -187,10 +214,7 @@ public class FeatureRenderer
           if (!sequenceFeatures[sfindex].type.equals(type))\r
             continue;\r
 \r
-          if(sequenceFeatures[sfindex]==null)\r
-          {\r
-          }\r
-          else  if (featureGroups != null\r
+          if (featureGroups != null\r
               && sequenceFeatures[sfindex].featureGroup != null\r
               &&\r
               featureGroups.containsKey(sequenceFeatures[sfindex].featureGroup)\r
@@ -207,9 +231,8 @@ public class FeatureRenderer
 \r
           if (overview)\r
           {\r
-\r
-            if (sequenceFeatures[sfindex].begin - 1 <= start &&\r
-                sequenceFeatures[sfindex].end + 1 >= start)\r
+            if (sequenceFeatures[sfindex].begin <= start &&\r
+                sequenceFeatures[sfindex].end >= start)\r
             {\r
               currentColour = av.featuresDisplayed.get(sequenceFeatures[sfindex].\r
                   type);\r
@@ -224,13 +247,13 @@ public class FeatureRenderer
                           seq.findIndex(sequenceFeatures[sfindex].begin) - 1,\r
                           new Color( ( (Integer) av.featuresDisplayed.get(\r
                 sequenceFeatures[sfindex].type)).intValue()),\r
-                          start, end, y1, width, height);\r
+                          start, end, y1);\r
             renderFeature(g, seq,\r
                           seq.findIndex(sequenceFeatures[sfindex].end) - 1,\r
                           seq.findIndex(sequenceFeatures[sfindex].end) - 1,\r
                           new Color( ( (Integer) av.featuresDisplayed.get(\r
                 sequenceFeatures[sfindex].type)).intValue()),\r
-                          start, end, y1, width, height);\r
+                          start, end, y1);\r
 \r
           }\r
           else\r
@@ -238,11 +261,14 @@ public class FeatureRenderer
                           seq.findIndex(sequenceFeatures[sfindex].begin) - 1,\r
                           seq.findIndex(sequenceFeatures[sfindex].end) - 1,\r
                           getColour(sequenceFeatures[sfindex].type),\r
-                          start, end, y1, width, height);\r
-\r
+                          start, end, y1);\r
 \r
         }\r
+      }\r
 \r
+      if(transparencySetter!=null && g!=null)\r
+      {\r
+        transparencySetter.setTransparency(g, 1.0f);\r
       }\r
     }\r
 \r
@@ -250,7 +276,7 @@ public class FeatureRenderer
     char s;\r
     int i;\r
     void renderFeature(Graphics g, SequenceI seq,\r
-                       int fstart, int fend, Color featureColour, int start, int end,  int y1, int width, int height)\r
+                       int fstart, int fend, Color featureColour, int start, int end,  int y1)\r
     {\r
 \r
       if (((fstart <= end) && (fend >= start)))\r
@@ -276,13 +302,16 @@ public class FeatureRenderer
 \r
             g.setColor(featureColour);\r
 \r
-            g.fillRect( (i - start) * width, y1, width, height);\r
+            g.fillRect( (i - start) * av.charWidth, y1, av.charWidth, av.charHeight);\r
+\r
+            if(!av.validCharWidth)\r
+              continue;\r
 \r
             g.setColor(Color.white);\r
-            charOffset = (width - fm.charWidth(s)) / 2;\r
+            charOffset = (av.charWidth - fm.charWidth(s)) / 2;\r
             g.drawString(String.valueOf(s),\r
-                         charOffset + (width * (i - start)),\r
-                         (y1 + height) - height / 5); //pady = height / 5;\r
+                         charOffset + (av.charWidth * (i - start)),\r
+                         (y1 + av.charHeight) - av.charHeight / 5); //pady = height / 5;\r
 \r
           }\r
       }\r
@@ -290,6 +319,9 @@ public class FeatureRenderer
 \r
     void findAllFeatures()\r
     {\r
+      jalview.schemes.UserColourScheme ucs = new\r
+          jalview.schemes.UserColourScheme();\r
+\r
       av.featuresDisplayed = new Hashtable();\r
       Vector allfeatures = new Vector();\r
       for (int i = 0; i < av.alignment.getHeight(); i++)\r
@@ -304,6 +336,14 @@ public class FeatureRenderer
         {\r
           if (!av.featuresDisplayed.containsKey(features[index].getType()))\r
           {\r
+            if (getColour(features[index].getType()) == null)\r
+            {\r
+              featureColours.put(features[index].getType(),\r
+                                 ucs.createColourFromName(features[index].\r
+                  getType()));\r
+            }\r
+\r
+\r
             av.featuresDisplayed.put(features[index].getType(),\r
                                   new Integer( getColour(features[index].getType()).getRGB()) );\r
             allfeatures.addElement(features[index].getType());\r
@@ -366,52 +406,19 @@ public class FeatureRenderer
             renderOrder[data.length - i - 1] = type;\r
           }\r
     }\r
+}\r
 \r
-    Hashtable featureColours = new Hashtable();\r
-    void initColours()\r
+  class TransparencySetter\r
+  {\r
+    void setTransparency(Graphics g, float value)\r
     {\r
-      featureColours.put("active site", new Color(255, 75, 0));\r
-      featureColours.put("binding site", new Color(245, 85, 0));\r
-      featureColours.put("calcium-binding region", new Color(235, 95, 0));\r
-      featureColours.put("chain", new Color(225, 105, 0));\r
-      featureColours.put("coiled-coil region", new Color(215, 115, 0));\r
-      featureColours.put("compositionally biased region", new Color(205, 125, 0));\r
-      featureColours.put("cross-link", new Color(195, 135, 0));\r
-      featureColours.put("disulfide bond", new Color(185, 145, 0));\r
-      featureColours.put("DNA-binding region", new Color(175, 155, 0));\r
-      featureColours.put("domain", new Color(165, 165, 0));\r
-      featureColours.put("glycosylation site", new Color(155, 175, 0));\r
-      featureColours.put("helix", new Color(145, 185, 0));\r
-      featureColours.put("initiator methionine", new Color(135, 195, 5));\r
-      featureColours.put("lipid moiety-binding region", new Color(125, 205, 15));\r
-      featureColours.put("metal ion-binding site", new Color(115, 215, 25));\r
-      featureColours.put("modified residue", new Color(105, 225, 35));\r
-      featureColours.put("mutagenesis site", new Color(95, 235, 45));\r
-      featureColours.put("non-consecutive residues", new Color(85, 245, 55));\r
-      featureColours.put("non-terminal residue", new Color(75, 255, 65));\r
-      featureColours.put("nucleotide phosphate-binding region",\r
-                         new Color(65, 245, 75));\r
-      featureColours.put("peptide", new Color(55, 235, 85));\r
-      featureColours.put("propeptide", new Color(45, 225, 95));\r
-      featureColours.put("region of interest", new Color(35, 215, 105));\r
-      featureColours.put("repeat", new Color(25, 205, 115));\r
-      featureColours.put("selenocysteine", new Color(15, 195, 125));\r
-      featureColours.put("sequence conflict", new Color(5, 185, 135));\r
-      featureColours.put("sequence variant", new Color(0, 175, 145));\r
-      featureColours.put("short sequence motif", new Color(0, 165, 155));\r
-      featureColours.put("signal peptide", new Color(0, 155, 165));\r
-      featureColours.put("site", new Color(0, 145, 175));\r
-      featureColours.put("splice variant", new Color(0, 135, 185));\r
-      featureColours.put("strand", new Color(0, 125, 195));\r
-      featureColours.put("topological domain", new Color(0, 115, 205));\r
-      featureColours.put("transit peptide", new Color(0, 105, 215));\r
-      featureColours.put("transmembrane region", new Color(0, 95, 225));\r
-      featureColours.put("turn", new Color(0, 85, 235));\r
-      featureColours.put("unsure residue", new Color(0, 75, 245));\r
-      featureColours.put("zinc finger region", new Color(0, 65, 255));\r
+     //Graphics2D g2 = (Graphics2D) g;\r
+    // g2.setComposite(\r
+    //    AlphaComposite.getInstance(\r
+    //         AlphaComposite.SRC_OVER, value));\r
     }\r
+  }\r
 \r
-}\r
 \r
 \r
 \r