Overview displays features
authoramwaterhouse <Andrew Waterhouse>
Fri, 10 Feb 2006 16:03:03 +0000 (16:03 +0000)
committeramwaterhouse <Andrew Waterhouse>
Fri, 10 Feb 2006 16:03:03 +0000 (16:03 +0000)
src/jalview/appletgui/AlignFrame.java
src/jalview/appletgui/FeatureRenderer.java
src/jalview/appletgui/FeatureSettings.java
src/jalview/appletgui/OverviewPanel.java

index fbe21b5..01bea4d 100755 (executable)
@@ -213,6 +213,7 @@ public class AlignFrame extends Frame implements ActionListener,
     }\r
     catch (Exception ex)\r
     {\r
+      ex.printStackTrace();\r
       System.out.println("Error parsing groups file: " + ex);\r
     }\r
   }\r
index 048df28..091a127 100755 (executable)
@@ -36,7 +36,6 @@ public class FeatureRenderer
     SequenceGroup currentSequenceGroup = null;\r
     SequenceGroup[] allGroups = null;\r
     Graphics graphics;\r
-    float transparency = .4f;\r
 \r
     // The following vector holds the features which are\r
     // to be added, in the correct order or rendering\r
@@ -44,6 +43,10 @@ public class FeatureRenderer
 \r
     Color currentColour = null;\r
 \r
+    boolean drawText = true;\r
+    FontMetrics fm;\r
+    int charOffset;\r
+\r
     /**\r
      * Creates a new FeatureRenderer object.\r
      *\r
@@ -53,13 +56,9 @@ public class FeatureRenderer
     {\r
         this.av = av;\r
         initColours();\r
-        String version = System.getProperty("java.version");\r
-        if (version.indexOf("1.1") == 0)\r
-          highlightTransparent = false;\r
-\r
     }\r
 \r
-    boolean highlightTransparent = true;\r
+    //boolean highlightTransparent = true;\r
     /**\r
      * DOCUMENT ME!\r
      *\r
@@ -76,6 +75,7 @@ public class FeatureRenderer
     public void drawSequence(Graphics g, SequenceI seq,\r
         int start, int end, int x1, int y1, int width, int height)\r
     {\r
+      fm = g.getFontMetrics();\r
 \r
         if(seq.getSequenceFeatures()==null)\r
           return;\r
@@ -87,11 +87,6 @@ public class FeatureRenderer
         else\r
          e = seq.getSequenceFeatures().elements();\r
 \r
-       if(highlightTransparent)\r
-        {\r
-        //  MyGraphics.SetTransparency(g, transparency);\r
-        }\r
-\r
 \r
         while (e.hasMoreElements())\r
         {\r
@@ -124,72 +119,70 @@ public class FeatureRenderer
                 continue;\r
             }\r
 \r
-            int fstart = seq.findIndex(sf.getBegin()) - 1;\r
-            int fend = seq.findIndex(sf.getEnd()) - 1;\r
-\r
-            if (((fstart <= end) && (fend >= start)))\r
+            if (type.equals("disulfide bond"))\r
             {\r
-                if (fstart < start)\r
-                { // fix for if the feature we have starts before the sequence start,\r
-                    fstart = start; // but the feature end is still valid!!\r
-                }\r
-\r
-                if (fend >= end)\r
-                {\r
-                    fend = end;\r
-                }\r
-\r
-                if (fstart == fend)\r
-                {\r
-                    currentColour = getColour(type);\r
-                    g.setColor(currentColour);\r
-                    g.fillRoundRect((fstart - start) * width, y1, width,\r
-                        height, 4, 4);\r
-                    g.setColor(Color.white);\r
-\r
-                    char s = seq.getSequence().charAt(fstart);\r
-                    FontMetrics fm = g.getFontMetrics();\r
-                    int charOffset = (width - fm.charWidth(s)) / 2;\r
-                    int pady = height / 5;\r
-                    g.drawString(String.valueOf(s),\r
-                        charOffset + x1 + (width * (fstart - start)),\r
-                        (y1 + height) - pady);\r
-                }\r
-                else\r
-                {\r
-                    for (int i = fstart; i <= fend; i++)\r
-                    {\r
-                        char s = seq.getSequence().charAt(i);\r
-\r
-                        if (jalview.util.Comparison.isGap(s))\r
-                        {\r
-                            continue;\r
-                        }\r
-                        currentColour = getColour(type);\r
-                        g.setColor(currentColour);\r
-\r
-                        g.fillRect((i - start) * width, y1, width, height);\r
-\r
-                        g.setColor(Color.white);\r
-\r
-                        FontMetrics fm = g.getFontMetrics();\r
-                        int charOffset = (width - fm.charWidth(s)) / 2;\r
-                        int pady = height / 5;\r
-                        g.drawString(String.valueOf(s),\r
-                            charOffset + x1 + (width * (i - start)),\r
-                            (y1 + height) - pady);\r
-                    }\r
-                }\r
+\r
+              renderFeature(g, seq,\r
+                            seq.findIndex(sf.getBegin()) - 1,\r
+                            seq.findIndex(sf.getBegin()) - 1,\r
+                            type, start, end, x1, y1, width, height);\r
+              renderFeature(g, seq,\r
+                            seq.findIndex(sf.getEnd()) - 1,\r
+                            seq.findIndex(sf.getEnd()) - 1,\r
+                            type, start, end, x1, y1, width, height);\r
+\r
             }\r
+            else\r
+              renderFeature(g, seq,\r
+                            seq.findIndex(sf.getBegin()) - 1,\r
+                            seq.findIndex(sf.getEnd()) - 1,\r
+                          type, start, end, x1, y1, width, height);\r
+\r
+      }\r
+    }\r
+\r
+    void renderFeature(Graphics g, SequenceI seq,\r
+                       int fstart, int fend, String type, int start, int end,\r
+                       int x1, int y1, int width, int height)\r
+    {\r
+      if ( ( (fstart <= end) && (fend >= start)))\r
+      {\r
+        if (fstart < start)\r
+        { // fix for if the feature we have starts before the sequence start,\r
+          fstart = start; // but the feature end is still valid!!\r
+        }\r
+\r
+        if (fend >= end)\r
+        {\r
+          fend = end;\r
+        }\r
+        for (int i = fstart; i <= fend; i++)\r
+        {\r
+          char s = seq.getSequence().charAt(i);\r
+\r
+          if (jalview.util.Comparison.isGap(s))\r
+          {\r
+            continue;\r
           }\r
 \r
-          if (highlightTransparent)\r
+          currentColour = getColour(type);\r
+\r
+          g.setColor(currentColour);\r
+\r
+          g.fillRect( (i - start) * width, y1, width, height);\r
+\r
+          if (drawText)\r
           {\r
-        //    MyGraphics.SetTransparency(g, 1.0f);\r
+            g.setColor(Color.white);\r
+            charOffset = (width - fm.charWidth(s)) / 2;\r
+            g.drawString(String.valueOf(s),\r
+                         charOffset + x1 + (width * (i - start)),\r
+                         (y1 + height) - height / 5);\r
           }\r
+        }\r
+      }\r
     }\r
 \r
-\r
     Image offscreen;\r
     Frame nullframe;\r
     public Color findFeatureColour(Color initialCol, SequenceI seq, int i)\r
@@ -218,7 +211,7 @@ public class FeatureRenderer
       featureColours.put(featureType, col);\r
     }\r
 \r
-    public void setTransparency(float value)\r
+ /*   public void setTransparency(float value)\r
     {\r
       transparency = value;\r
     }\r
@@ -226,14 +219,18 @@ public class FeatureRenderer
     public float getTransparency()\r
     {\r
       return transparency;\r
-    }\r
+    }*/\r
 \r
     public void setFeaturePriority(Object [][] data)\r
     {\r
       // The feature table will display high priority\r
       // features at the top, but theses are the ones\r
       // we need to render last, so invert the data\r
-      featuresDisplayed = new Vector();\r
+      if(featuresDisplayed!=null)\r
+        featuresDisplayed.removeAllElements();\r
+      else\r
+        featuresDisplayed = new Vector();\r
+\r
       for(int i=data.length-1; i>-1; i--)\r
       {\r
        String type = data[i][0].toString();\r
index e01615a..4d0f25e 100755 (executable)
@@ -114,6 +114,8 @@ public class FeatureSettings extends Panel implements ItemListener,
 \r
     fr.setFeaturePriority(data);\r
     ap.seqPanel.seqCanvas.repaint();\r
+    if(ap.overviewPanel!=null)\r
+      ap.overviewPanel.updateOverviewImage();\r
   }\r
 \r
   Checkbox selectedCheck;\r
@@ -167,6 +169,7 @@ public class FeatureSettings extends Panel implements ItemListener,
       this.remove(selectedCheck);\r
       this.add(selectedCheck, targetIndex);\r
       validate();\r
+      itemStateChanged(null);\r
     }\r
   }\r
 \r
index 9c3e908..57150c3 100755 (executable)
@@ -58,8 +58,8 @@ public class OverviewPanel
     sr.graphics = nullFrame.getGraphics();\r
     sr.renderGaps( false );\r
     fr = new FeatureRenderer(av);\r
-    fr.transparency = ap.seqPanel.seqCanvas.getFeatureRenderer().transparency;\r
-    fr.featuresDisplayed = ap.seqPanel.seqCanvas.getFeatureRenderer().featuresDisplayed;\r
+    fr.drawText = false;\r
+\r
 \r
 \r
     // scale the initial size of overviewpanel to shape of alignment\r
@@ -183,6 +183,10 @@ public class OverviewPanel
         return;\r
     }\r
 \r
+    if (av.showSequenceFeatures)\r
+      fr.featuresDisplayed = ap.seqPanel.seqCanvas.getFeatureRenderer().featuresDisplayed;\r
+\r
+\r
     resizing = true;\r
 \r
     if ( (getSize().width > 0) && (getSize().height > 0))\r
@@ -229,18 +233,29 @@ public class OverviewPanel
     float sampleRow = (float) alheight / (float) sequencesHeight;\r
 \r
     int lastcol=-1, lastrow=-1;\r
-    Color color = Color.white;\r
-    for (int col = 0; col < width; col++)\r
+    Color color = Color.yellow;\r
+    int row, col;\r
+    for (col = 0; col < width; col++)\r
     {\r
-      for (int row = 0; row < sequencesHeight; row++)\r
+      for (row = 0; row < sequencesHeight; row++)\r
       {\r
         if((int)(col*sampleCol) == lastcol && (int)(row*sampleRow)==lastrow)\r
         {\r
-          mg.setColor(color);\r
-          mg.fillRect(col,row,1,1);\r
+          mg.drawLine(col, row, col, row);\r
           continue;\r
         }\r
 \r
+        if (av.conservation != null)\r
+        {\r
+          mg.translate(col, sequencesHeight);\r
+          ap.annotationPanel.drawGraph(mg, av.conservation,\r
+                                       (int) (sampleCol) + 1,\r
+                                       graphHeight,\r
+                                       (int) (col * sampleCol),\r
+                                       (int) (col * sampleCol) + 1);\r
+          mg.translate( -col, -sequencesHeight);\r
+        }\r
+\r
         lastrow = (int)(row*sampleRow);\r
         lastcol = (int)(col*sampleCol);\r
 \r
@@ -248,29 +263,20 @@ public class OverviewPanel
         {\r
           color = sr.findSequenceColour(av.alignment.getSequenceAt(lastrow), lastcol);\r
 \r
+\r
           if (av.showSequenceFeatures)\r
             color = fr.findFeatureColour(color,\r
-                                         av.alignment.getSequenceAt(lastrow),\r
+                                        av.alignment.getSequenceAt(lastrow),\r
                                          lastcol);\r
         }\r
 \r
-\r
         mg.setColor(color);\r
-        mg.fillRect(col,row,1,1);\r
+        mg.drawLine(col,row,col,row);\r
 \r
-        if (av.conservation != null)\r
-        {\r
-          mg.translate(col, sequencesHeight);\r
-          ap.annotationPanel.drawGraph(mg, av.conservation,\r
-                                       (int) (sampleCol) + 1,\r
-                                       graphHeight,\r
-                                       (int) (col * sampleCol),\r
-                                       (int) (col * sampleCol) + 1);\r
-          mg.translate(-col, -sequencesHeight);\r
-        }\r
       }\r
     }\r
 \r
+\r
     System.gc();\r
 \r
     resizing = false;\r