ColumnSelection moved to datamodel
[jalview.git] / src / jalview / gui / IdCanvas.java
index 9581ccc..7734f9a 100755 (executable)
@@ -18,8 +18,6 @@
  */\r
 package jalview.gui;\r
 \r
-import jalview.analysis.*;\r
-\r
 import jalview.datamodel.*;\r
 \r
 import java.awt.*;\r
@@ -67,8 +65,7 @@ public class IdCanvas extends JPanel
      * @param starty DOCUMENT ME!\r
      * @param ypos DOCUMENT ME!\r
      */\r
-    public void drawIdString(Graphics2D gg, SequenceI s, int i, int starty,\r
-        int ypos)\r
+    public void drawIdString(Graphics2D gg, SequenceI s, int i, int starty, int ypos)\r
     {\r
         int charHeight = av.charHeight;\r
 \r
@@ -80,7 +77,7 @@ public class IdCanvas extends JPanel
             gg.setColor(Color.white);\r
         }\r
         else if ((av.getSelectionGroup() != null) &&\r
-                av.getSelectionGroup().sequences.contains(s))\r
+                av.getSelectionGroup().getSequences(false).contains(s))\r
         {\r
             gg.setColor(Color.lightGray);\r
             gg.fillRect(0, ((i - starty) * charHeight) + ypos, getWidth(),\r
@@ -95,15 +92,14 @@ public class IdCanvas extends JPanel
             gg.setColor(Color.black);\r
         }\r
 \r
-        String string = s.getName();\r
 \r
-        if (av.getShowFullId())\r
-        {\r
-            string = s.getDisplayId();\r
-        }\r
+        gg.drawString( s.getDisplayId(av.getShowJVSuffix()),\r
+                      0, (((i - starty + 1) * charHeight) + ypos) - (charHeight / 5));\r
+\r
+        if (av.hasHiddenRows && av.showHiddenMarkers)\r
+          drawMarker(i, starty, ypos);\r
+\r
 \r
-        gg.drawString(string, 0,\r
-            (((i - starty + 1) * charHeight) + ypos) - (charHeight / 5));\r
     }\r
 \r
     /**\r
@@ -177,6 +173,8 @@ public class IdCanvas extends JPanel
             return;\r
         }\r
 \r
+        int oldHeight = imgHeight;\r
+\r
         imgHeight = getHeight();\r
         imgHeight -= (imgHeight % av.charHeight);\r
 \r
@@ -185,19 +183,16 @@ public class IdCanvas extends JPanel
             return;\r
         }\r
 \r
-        image = new BufferedImage(getWidth(), imgHeight,\r
-                BufferedImage.TYPE_INT_RGB);\r
-        gg = (Graphics2D) image.getGraphics();\r
+        if(oldHeight!=imgHeight)\r
+        {\r
+          image = new BufferedImage(getWidth(), imgHeight,\r
+                                    BufferedImage.TYPE_INT_RGB);\r
+        }\r
 \r
+        gg = (Graphics2D) image.getGraphics();\r
         //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,76 +207,180 @@ 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
+\r
+      gg.setFont(italic);\r
+\r
+      if (av.antiAlias)\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 rowSize = av.getEndRes() - av.getStartRes();\r
+          int maxwidth = av.alignment.getWidth();\r
+          int alheight = av.alignment.getHeight();\r
+\r
+          if (av.hasHiddenColumns)\r
+            maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1;\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
+          if (av.scaleAboveWrapped)\r
+            hgap += av.charHeight;\r
+\r
+          int cHeight = alheight * av.charHeight\r
+              + hgap\r
+              + annotationHeight;\r
+\r
+          int rowSize = av.getEndRes() - av.getStartRes();\r
+\r
 \r
             // Draw the rest of the panels\r
-            for (int ypos = 2 * av.charHeight, row = av.startRes;\r
-                    (ypos <= getHeight()) && (row < av.alignment.getWidth());\r
-                    ypos += av.chunkHeight, row += rowSize)\r
+            for (int ypos = hgap, row = av.startRes;\r
+                    (ypos <= getHeight()) && (row < maxwidth);\r
+                    ypos += cHeight, row += rowSize)\r
             {\r
-                for (int i = starty; i < av.alignment.getHeight(); i++)\r
+              for (int i = starty; i < alheight; i++)\r
+              {\r
+                if (av.hasHiddenRows)\r
                 {\r
-                    SequenceI s = av.alignment.getSequenceAt(i);\r
-                    drawIdString(gg, s, i, 0, ypos);\r
+                  setHiddenFont(i);\r
                 }\r
+                else\r
+                  gg.setFont(italic);\r
+\r
+                SequenceI s = av.alignment.getSequenceAt(i);\r
+                drawIdString(gg, s, i, 0, ypos);\r
+              }\r
+\r
+                if(labels!=null)\r
+                {\r
+                  gg.translate(0, ypos+(alheight * av.charHeight));\r
+                  labels.drawComponent(gg, getWidth());\r
+                  gg.translate(0, -ypos-(alheight * av.charHeight));\r
+                }\r
+\r
+\r
             }\r
         }\r
         else\r
         {\r
+          //Now draw the id strings\r
+\r
             //Now draw the id strings\r
             for (int i = starty; i < endy; i++)\r
             {\r
+              if (av.hasHiddenRows)\r
+              {\r
+                setHiddenFont(i);\r
+              }\r
+\r
                 // Selected sequence colours\r
-                if ((searchResults != null) &&\r
-                        searchResults.contains(av.alignment.getSequenceAt(i)))\r
+                if ( (searchResults != null) &&\r
+                    searchResults.contains(av.alignment.getSequenceAt(i)))\r
                 {\r
-                    gg.setColor(Color.black);\r
-                    currentColor = Color.black;\r
-                    currentTextColor = Color.white;\r
+                  currentColor = Color.black;\r
+                  currentTextColor = Color.white;\r
                 }\r
-                else if ((av.getSelectionGroup() != null) &&\r
-                        av.getSelectionGroup().sequences.contains(\r
-                            av.alignment.getSequenceAt(i)))\r
+                else if ( (av.getSelectionGroup() != null) &&\r
+                         av.getSelectionGroup().getSequences(false).contains(\r
+                             av.alignment.getSequenceAt(i)))\r
                 {\r
-                    currentColor = Color.lightGray;\r
-                    currentTextColor = Color.black;\r
+                  currentColor = Color.lightGray;\r
+                  currentTextColor = Color.black;\r
                 }\r
                 else\r
                 {\r
-                    currentColor = av.alignment.getSequenceAt(i).getColor();\r
-                    currentTextColor = Color.black;\r
+                  currentColor = av.alignment.getSequenceAt(i).getColor();\r
+                  currentTextColor = Color.black;\r
                 }\r
 \r
                 gg.setColor(currentColor);\r
 \r
                 gg.fillRect(0, (i - starty) * av.charHeight, getWidth(),\r
-                    av.charHeight);\r
+                            av.charHeight);\r
 \r
                 gg.setColor(currentTextColor);\r
 \r
-                String string = av.alignment.getSequenceAt(i).getName();\r
-\r
-                if (av.getShowFullId())\r
-                {\r
-                    string = av.alignment.getSequenceAt(i).getDisplayId();\r
-                }\r
+                String string = av.alignment.getSequenceAt(i).getDisplayId( av.getShowJVSuffix());\r
 \r
                 gg.drawString(string, 0,\r
                     (((i - starty) * av.charHeight) + av.charHeight) -\r
                     (av.charHeight / 5));\r
+\r
+               if(av.hasHiddenRows && av.showHiddenMarkers)\r
+                 drawMarker(i, starty, 0);\r
+\r
             }\r
 \r
-            // add a border\r
-            gg.setColor(Color.white);\r
-            gg.fillRect(getWidth() - 4, 0, 4, getHeight());\r
         }\r
     }\r
 \r
+    void drawMarker(int i, int starty, int yoffset)\r
+    {\r
+      int hiddenIndex = av.adjustForHiddenSeqs(i);\r
+      int lastIndex = av.adjustForHiddenSeqs(i - 1);\r
+      int nextIndex = av.adjustForHiddenSeqs(i + 1);\r
+\r
+      boolean below = (hiddenIndex > lastIndex + 1);\r
+      boolean above = (nextIndex>hiddenIndex+1);\r
+\r
+        gg.setColor(Color.blue);\r
+        if(below)\r
+        {\r
+          gg.fillPolygon(new int[]\r
+                         {getWidth()- av.charHeight,\r
+                         getWidth()- av.charHeight,\r
+                         getWidth()},\r
+                         new int[]\r
+                         {\r
+                         (i - starty) * av.charHeight +yoffset,\r
+                         (i - starty) * av.charHeight +yoffset+ av.charHeight / 4,\r
+                         (i - starty) * av.charHeight+yoffset\r
+          }, 3);\r
+        }\r
+        if(above)\r
+        {\r
+          gg.fillPolygon(new int[]\r
+                        {getWidth()- av.charHeight,\r
+                        getWidth()- av.charHeight,\r
+                        getWidth() },\r
+                        new int[]\r
+                        {\r
+                        (i - starty+1) * av.charHeight +yoffset,\r
+                        (i - starty+1) * av.charHeight +yoffset- av.charHeight / 4,\r
+                        (i - starty+1) * av.charHeight +yoffset\r
+         }, 3);\r
+\r
+        }\r
+    }\r
+\r
+    void setHiddenFont(int i)\r
+    {\r
+      Font italic = new Font(av.getFont().getName(), Font.ITALIC,\r
+                             av.getFont().getSize());\r
+      Font bold = new Font(av.getFont().getName(), Font.BOLD,\r
+                           av.getFont().getSize());\r
+\r
+      if (av.alignment.getSequenceAt(i).getHiddenSequences() != null)\r
+        gg.setFont(bold);\r
+      else\r
+        gg.setFont(italic);\r
+    }\r
+\r
     /**\r
      * DOCUMENT ME!\r
      *\r