Merge branch 'develop' into spike/JAL-4047/JAL-4048_columns_in_sequenceID
[jalview.git] / src / jalview / gui / IdCanvas.java
index ab21714..2faea01 100755 (executable)
@@ -37,6 +37,9 @@ import javax.swing.JPanel;
 import jalview.datamodel.SequenceI;
 import jalview.viewmodel.ViewportListenerI;
 import jalview.viewmodel.ViewportRanges;
+import jalview.viewmodel.seqfeatures.IdColumn;
+import jalview.viewmodel.seqfeatures.IdColumns;
+import jalview.viewmodel.seqfeatures.IdColumns.ColumnCell;
 
 /**
  * DOCUMENT ME!
@@ -199,7 +202,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI
 
     gg.translate(0, transY);
 
-    drawIds(gg, av, ss, es, searchResults);
+    drawIds(gg, av, ss, es, searchResults,true);
 
     gg.translate(0, -transY);
 
@@ -256,7 +259,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI
     gg.fillRect(0, 0, getWidth(), imgHeight);
 
     drawIds(gg, av, av.getRanges().getStartSeq(),
-            av.getRanges().getEndSeq(), searchResults);
+            av.getRanges().getEndSeq(), searchResults,true);
 
     gg.dispose();
 
@@ -276,7 +279,7 @@ public class IdCanvas extends JPanel implements ViewportListenerI
    * @param selection
    */
   void drawIds(Graphics2D g, AlignViewport alignViewport,
-          final int startSeq, final int endSeq, List<SequenceI> selection)
+          final int startSeq, final int endSeq, List<SequenceI> selection, boolean forGUI)
   {
     Font font = alignViewport.getFont();
     if (alignViewport.isSeqNameItalics())
@@ -309,19 +312,27 @@ public class IdCanvas extends JPanel implements ViewportListenerI
     }
 
     // Now draw the id strings
-    int panelWidth = getWidth();
-    int xPos = 0;
+    int fullPanelWidth = getWidth();
+
+    IdColumns id_cols = alignViewport.getIdColumns();
+    List<IdColumn> visible = id_cols.getVisible();
+    /**
+     * width of an idColumn
+     */
+    int colWid = 20;
+    int panelWidth = Math.max(fullPanelWidth / 2,
+            fullPanelWidth - (colWid * visible.size()));
 
     // Now draw the id strings
     for (int i = startSeq; i <= endSeq; i++)
     {
+      int xPos = 0;
       SequenceI sequence = alignViewport.getAlignment().getSequenceAt(i);
 
       if (sequence == null)
       {
         continue;
       }
-
       if (hasHiddenRows || alignViewport.isDisplayReferenceSeq())
       {
         g.setFont(getHiddenFont(sequence, alignViewport));
@@ -365,6 +376,37 @@ public class IdCanvas extends JPanel implements ViewportListenerI
               (((i - startSeq) * charHeight) + charHeight)
                       - (charHeight / 5));
 
+      if (visible != null && visible.size() > 0)
+      {
+        try
+        {
+          xPos = panelWidth + 2;
+          for (IdColumn col : visible)
+          {
+            ColumnCell col_cell = id_cols.getCellFor(sequence, col);
+            if (col_cell == null)
+            {
+              g.setColor(Color.gray);
+              g.fillRect(xPos + 1, (i - startSeq) * charHeight,
+                      xPos + colWid - 3, charHeight);
+            }
+            else
+            {
+              g.setColor(col_cell.bg);
+              g.fillRect(xPos + 1, (i - startSeq) * charHeight,
+                      xPos + colWid - 3, charHeight);
+              g.setColor(col_cell.fg);
+              g.drawString(col_cell.label, xPos,
+                      (((i - startSeq) * charHeight) + charHeight)
+                              - (charHeight / 5));
+            }
+            xPos += colWid;
+            g.setColor(currentTextColor);
+          }
+        } catch (Exception q)
+        {
+        }
+      }
       if (hasHiddenRows && av.getShowHiddenMarkers())
       {
         drawMarker(g, alignViewport, i, startSeq, 0);
@@ -383,11 +425,24 @@ public class IdCanvas extends JPanel implements ViewportListenerI
   void drawIdsWrapped(Graphics2D g, AlignViewport alignViewport,
           int startSeq, int pageHeight)
   {
-    drawIdsWrapped(g, alignViewport, startSeq, pageHeight, -1);
+    drawIdsWrapped(g, alignViewport, startSeq, pageHeight, -1, true);
+  }
+
+  /**
+   * render sequence IDs and annotation labels when wrapped - without GUI junk
+   * @param g
+   * @param av2
+   * @param i
+   * @param totalHeight
+   */
+  public void drawIdsWrappedNoGUI(Graphics2D g, AlignViewport av2, int i,
+          int totalHeight)
+  {
+    drawIdsWrapped(g, av2, totalHeight, totalHeight, i,false);
   }
 
   void drawIdsWrapped(Graphics2D g, AlignViewport alignViewport,
-          int startSeq, int pageHeight, int idWidth)
+          int startSeq, int pageHeight, int idWidth, boolean forGUI)
   {
     int alignmentWidth = alignViewport.getAlignment().getWidth();
     final int alheight = alignViewport.getAlignment().getHeight();
@@ -435,21 +490,23 @@ public class IdCanvas extends JPanel implements ViewportListenerI
 
       if (labels != null && alignViewport.isShowAnnotation())
       {
-        int thisIdWidth = getWidth();
+        int getWidth = getWidth();
+        int thisIdWidth = getWidth;
         g.translate(0, ypos + (alheight * charHeight));
         if (!manuallyAdjusted())
         {
-          int getAnnotationsIdWidth = labels.drawLabels(g, false, -1, false,
+          int getAnnotationsIdWidth = labels.drawLabels(g, false, -1, false,forGUI,
                   null);
           thisIdWidth = idWidth < 0 ? getAnnotationsIdWidth : idWidth;
-          if (thisIdWidth > getWidth())
+          if (thisIdWidth > getWidth)
           {
             this.setPreferredSize(
-                    new Dimension(this.getHeight(), thisIdWidth));
+                    new Dimension(thisIdWidth, this.getHeight()));
             this.repaint();
+            alignViewport.setIdWidth(thisIdWidth);
           }
         }
-        labels.drawComponent(g, false, thisIdWidth);
+        labels.drawComponent(g, false, thisIdWidth, forGUI);
         g.translate(0, -ypos - (alheight * charHeight));
       }
 
@@ -617,4 +674,5 @@ public class IdCanvas extends JPanel implements ViewportListenerI
   {
     manuallyAdjusted = b;
   }
+
 }