Show labels in wrapped view
authoramwaterhouse <Andrew Waterhouse>
Tue, 27 Sep 2005 14:16:59 +0000 (14:16 +0000)
committeramwaterhouse <Andrew Waterhouse>
Tue, 27 Sep 2005 14:16:59 +0000 (14:16 +0000)
src/jalview/gui/AlignmentPanel.java
src/jalview/gui/AnnotationLabels.java
src/jalview/gui/AnnotationPanel.java
src/jalview/gui/IdCanvas.java

index ac87ebe..d1187ac 100755 (executable)
@@ -690,7 +690,7 @@ public class AlignmentPanel extends GAlignmentPanel
         if (av.showAnnotation && (endSeq == av.alignment.getHeight()))\r
         {\r
             pg.translate(-idWidth, (endSeq - startSeq) * av.charHeight +3);\r
-            alabels.drawComponent((Graphics2D) pg);\r
+            alabels.drawComponent((Graphics2D) pg, idWidth);\r
             pg.translate(idWidth, 0);\r
             annotationPanel.drawComponent((Graphics2D) pg, startRes, endRes +\r
                 1);\r
@@ -716,8 +716,12 @@ public class AlignmentPanel extends GAlignmentPanel
     {\r
 \r
       int annotationHeight = 0;\r
+      AnnotationLabels labels = null;\r
       if (av.showAnnotation)\r
+      {\r
         annotationHeight = annotationPanel.adjustPanelHeight();\r
+        labels = new AnnotationLabels(av);\r
+      }\r
 \r
       int hgap = av.charHeight;\r
       if (av.scaleAboveWrapped)\r
@@ -749,22 +753,39 @@ public class AlignmentPanel extends GAlignmentPanel
         pg.setClip(0, pi * pheight, pwidth, pheight);\r
 \r
         int ypos = hgap;\r
+        Font italic = new Font(av.getFont().getName(), Font.ITALIC,\r
+                             av.getFont().getSize());\r
+        pg.setFont(italic);\r
+\r
 \r
         do\r
         {\r
-            for (int i = 0; i < av.alignment.getHeight(); i++)\r
-            {\r
-                SequenceI s = av.alignment.getSequenceAt(i);\r
-                String string = s.getName();\r
+          for (int i = 0; i < av.alignment.getHeight(); i++)\r
+          {\r
+            SequenceI s = av.alignment.getSequenceAt(i);\r
+            String string = s.getName();\r
 \r
-                if (av.getShowFullId())\r
-                {\r
-                    string = s.getDisplayId();\r
-                }\r
+            if (av.getShowFullId())\r
+            {\r
+              string = s.getDisplayId();\r
+            }\r
 \r
-                pg.drawString(string, 0,\r
-                    ((i * av.charHeight) + ypos + av.charHeight) -\r
-                    (av.charHeight / 5));\r
+            pg.drawString(string, 0,\r
+                          ( (i * av.charHeight) + ypos + av.charHeight) -\r
+                          (av.charHeight / 5));\r
+          }\r
+            if (labels != null)\r
+            {\r
+              pg.translate(0,\r
+                           ypos +\r
+                           (av.getAlignment().getHeight() * av.charHeight));\r
+\r
+              pg.setFont(av.getFont());\r
+              labels.drawComponent( pg, idWidth );\r
+              pg.setFont(italic);\r
+              pg.translate(0,\r
+                           -ypos -\r
+                           (av.getAlignment().getHeight() * av.charHeight));\r
             }\r
 \r
             ypos += cHeight;\r
index 7c8850d..8561e64 100755 (executable)
@@ -44,12 +44,14 @@ public class AnnotationLabels extends JPanel implements MouseListener,
     boolean active = false;\r
     Image image;\r
     AlignmentPanel ap;\r
+    AlignViewport av;\r
     boolean resizing = false;\r
     int oldY;\r
     int mouseX;\r
     int selectedRow = 0;\r
     int scrollOffset = 0;\r
 \r
+\r
     /**\r
      * Creates a new AnnotationLabels object.\r
      *\r
@@ -58,6 +60,7 @@ public class AnnotationLabels extends JPanel implements MouseListener,
     public AnnotationLabels(AlignmentPanel ap)\r
     {\r
         this.ap = ap;\r
+        av = ap.av;\r
 \r
         java.net.URL url = getClass().getResource("/images/idwidth.gif");\r
         Image temp = null;\r
@@ -88,6 +91,11 @@ public class AnnotationLabels extends JPanel implements MouseListener,
         addMouseMotionListener(this);\r
     }\r
 \r
+    public AnnotationLabels(AlignViewport av)\r
+    {\r
+      this.av = av;\r
+    }\r
+\r
     /**\r
      * DOCUMENT ME!\r
      *\r
@@ -346,13 +354,19 @@ public class AnnotationLabels extends JPanel implements MouseListener,
      *\r
      * @param g1 DOCUMENT ME!\r
      */\r
-    public void paintComponent(Graphics g1)\r
+    public void paintComponent(Graphics g)\r
     {\r
-        Graphics2D g = (Graphics2D) g1;\r
-        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,\r
+\r
+        int width = getWidth();\r
+        if(width==0)\r
+         width = ap.calculateIdWidth().width + 4;\r
+\r
+       Graphics2D g2 = (Graphics2D) g;\r
+        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,\r
             RenderingHints.VALUE_ANTIALIAS_ON);\r
 \r
-        drawComponent(g);\r
+       drawComponent(g2, width);\r
+\r
     }\r
 \r
     /**\r
@@ -360,7 +374,7 @@ public class AnnotationLabels extends JPanel implements MouseListener,
      *\r
      * @param g DOCUMENT ME!\r
      */\r
-    public void drawComponent(Graphics2D g)\r
+    public void drawComponent(Graphics g, int width)\r
     {\r
         FontMetrics fm = g.getFontMetrics(g.getFont());\r
         g.setColor(Color.white);\r
@@ -369,12 +383,10 @@ public class AnnotationLabels extends JPanel implements MouseListener,
         g.translate(0, scrollOffset);\r
         g.setColor(Color.black);\r
 \r
-        AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation();\r
+        AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();\r
         int y = g.getFont().getSize();\r
         int x = 0;\r
-        int width = getWidth();\r
-        if(width==0)\r
-         width = ap.calculateIdWidth().width + 4;\r
+\r
 \r
         if (aa != null)\r
         {\r
index 9bbcc24..d97c80f 100755 (executable)
@@ -614,13 +614,13 @@ public class AnnotationPanel extends JPanel implements MouseListener,
      * @param startRes DOCUMENT ME!\r
      * @param endRes DOCUMENT ME!\r
      */\r
-    public void drawComponent(Graphics2D g, int startRes, int endRes)\r
+    public void drawComponent(Graphics g, int startRes, int endRes)\r
     {\r
+      g.setFont(av.getFont());\r
+\r
       if (fm == null)\r
         fm = g.getFontMetrics();\r
 \r
-               if(fm==null)\r
-                       fm = g.getFontMetrics();\r
 \r
         g.setColor(Color.white);\r
         g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getHeight());\r
index 2951c14..7d283ba 100755 (executable)
@@ -192,12 +192,7 @@ public class IdCanvas extends JPanel
         //Fill in the background\r
         gg.setColor(Color.white);\r
         gg.fillRect(0, 0, getWidth(), imgHeight);\r
-        gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,\r
-            RenderingHints.VALUE_ANTIALIAS_ON);\r
 \r
-        Font italic = new Font(av.getFont().getName(), Font.ITALIC,\r
-                av.getFont().getSize());\r
-        gg.setFont(italic);\r
 \r
         drawIds(av.getStartSeq(), av.endSeq);\r
 \r
@@ -212,17 +207,25 @@ public class IdCanvas extends JPanel
      */\r
     void drawIds(int starty, int endy)\r
     {\r
+      Font italic = new Font(av.getFont().getName(), Font.ITALIC,\r
+                             av.getFont().getSize());\r
+      gg.setFont(italic);\r
+      gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,\r
+            RenderingHints.VALUE_ANTIALIAS_ON);\r
+\r
         Color currentColor = Color.white;\r
         Color currentTextColor = Color.black;\r
 \r
         if (av.getWrapAlignment())\r
         {\r
           int annotationHeight = 0;\r
+          AnnotationLabels labels = null;\r
 \r
           if(av.showAnnotation)\r
           {\r
             AnnotationPanel ap = new AnnotationPanel(av);\r
             annotationHeight = ap.adjustPanelHeight();\r
+            labels = new AnnotationLabels(av);\r
           }\r
 \r
           int hgap = av.charHeight;\r
@@ -245,6 +248,15 @@ public class IdCanvas extends JPanel
                     SequenceI s = av.alignment.getSequenceAt(i);\r
                     drawIdString(gg, s, i, 0, ypos);\r
                 }\r
+\r
+                if(labels!=null)\r
+                {\r
+                  gg.setFont(av.getFont());\r
+                  gg.translate(0, ypos+(av.getAlignment().getHeight() * av.charHeight));\r
+                  labels.drawComponent(gg, getWidth());\r
+                  gg.translate(0, -ypos-(av.getAlignment().getHeight() * av.charHeight));\r
+                  gg.setFont(italic);\r
+                }\r
             }\r
         }\r
         else\r